"use strict";
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
Object.defineProperty(exports, "__esModule", { value: true });
exports.SidebarItem = exports.Level = exports.CONSOLE_SIDEBAR_SELECTOR = exports.CONSOLE_CREATE_LIVE_EXPRESSION_SELECTOR = exports.LOG_XML_HTTP_REQUESTS_SELECTOR = exports.SHOW_CORS_ERRORS_SELECTOR = exports.AUTOCOMPLETE_FROM_HISTORY_SELECTOR = exports.CONSOLE_SETTINGS_SELECTOR = exports.CONSOLE_SELECTOR = exports.CONSOLE_MESSAGE_WRAPPER_SELECTOR = exports.STACK_PREVIEW_CONTAINER = exports.CONSOLE_COMPLETION_HINT_SELECTOR = exports.CONSOLE_TOOLTIP_SELECTOR = exports.CONSOLE_VIEW_SELECTOR = exports.CONSOLE_VIEW_IN_DRAWER_SELECTOR = exports.CONSOLE_PROMPT_SELECTOR = exports.LOG_LEVELS_VERBOSE_OPTION_SELECTOR = exports.LOG_LEVELS_SELECTOR = exports.CONSOLE_MESSAGE_TEXT_AND_ANCHOR_SELECTOR = exports.CONSOLE_ERROR_MESSAGES_SELECTOR = exports.CONSOLE_INFO_MESSAGES_SELECTOR = exports.CONSOLE_ALL_MESSAGES_SELECTOR = exports.CONSOLE_MESSAGES_TEXT_SELECTOR = exports.CONSOLE_MESSAGES_SELECTOR = exports.CONSOLE_TAB_SELECTOR = void 0;
exports.deleteConsoleMessagesFilter = deleteConsoleMessagesFilter;
exports.filterConsoleMessages = filterConsoleMessages;
exports.waitForConsoleMessagesToBeNonEmpty = waitForConsoleMessagesToBeNonEmpty;
exports.waitForExactConsoleMessageCount = waitForExactConsoleMessageCount;
exports.waitForLastConsoleMessageToHaveContent = waitForLastConsoleMessageToHaveContent;
exports.getConsoleMessages = getConsoleMessages;
exports.getCurrentConsoleMessages = getCurrentConsoleMessages;
exports.getLastConsoleMessages = getLastConsoleMessages;
exports.maybeGetCurrentConsoleMessages = maybeGetCurrentConsoleMessages;
exports.getStructuredConsoleMessages = getStructuredConsoleMessages;
exports.focusConsolePrompt = focusConsolePrompt;
exports.showVerboseMessages = showVerboseMessages;
exports.typeIntoConsole = typeIntoConsole;
exports.typeIntoConsoleAndWaitForResult = typeIntoConsoleAndWaitForResult;
exports.unifyLogVM = unifyLogVM;
exports.navigateToConsoleTab = navigateToConsoleTab;
exports.openConsoleSidebar = openConsoleSidebar;
exports.closeConsoleSidebar = closeConsoleSidebar;
exports.selectConsoleSidebarItem = selectConsoleSidebarItem;
exports.waitForConsoleInfoMessageAndClickOnLink = waitForConsoleInfoMessageAndClickOnLink;
exports.turnOffHistoryAutocomplete = turnOffHistoryAutocomplete;
exports.toggleShowCorsErrors = toggleShowCorsErrors;
exports.toggleShowLogXmlHttpRequests = toggleShowLogXmlHttpRequests;
exports.waitForIssueButtonLabel = waitForIssueButtonLabel;
exports.clickOnContextMenu = clickOnContextMenu;
exports.checkCommandResultFunction = checkCommandResultFunction;
exports.getLastConsoleStacktrace = getLastConsoleStacktrace;
exports.checkCommandStacktrace = checkCommandStacktrace;
exports.veImpressionForConsolePanel = veImpressionForConsolePanel;
const chai_1 = require("chai");
const async_scope_js_1 = require("../../conductor/async-scope.js");
const visual_logging_helpers_js_1 = require("./visual-logging-helpers.js");
exports.CONSOLE_TAB_SELECTOR = '#tab-console';
exports.CONSOLE_MESSAGES_SELECTOR = '.console-group-messages';
exports.CONSOLE_MESSAGES_TEXT_SELECTOR = '.source-code .console-message-text';
exports.CONSOLE_ALL_MESSAGES_SELECTOR = `${exports.CONSOLE_MESSAGES_SELECTOR} ${exports.CONSOLE_MESSAGES_TEXT_SELECTOR}`;
exports.CONSOLE_INFO_MESSAGES_SELECTOR = `${exports.CONSOLE_MESSAGES_SELECTOR} .console-info-level ${exports.CONSOLE_MESSAGES_TEXT_SELECTOR}`;
exports.CONSOLE_ERROR_MESSAGES_SELECTOR = `${exports.CONSOLE_MESSAGES_SELECTOR} .console-error-level ${exports.CONSOLE_MESSAGES_TEXT_SELECTOR}`;
exports.CONSOLE_MESSAGE_TEXT_AND_ANCHOR_SELECTOR = '.console-group-messages .source-code';
exports.LOG_LEVELS_SELECTOR = '[aria-label^="Log level: "]';
exports.LOG_LEVELS_VERBOSE_OPTION_SELECTOR = '[aria-label^="Verbose"]';
exports.CONSOLE_PROMPT_SELECTOR = '.console-prompt-editor-container';
exports.CONSOLE_VIEW_IN_DRAWER_SELECTOR = '.drawer-tabbed-pane .console-view';
exports.CONSOLE_VIEW_SELECTOR = '.console-view';
exports.CONSOLE_TOOLTIP_SELECTOR = '.cm-tooltip';
exports.CONSOLE_COMPLETION_HINT_SELECTOR = '.cm-completionHint';
exports.STACK_PREVIEW_CONTAINER = '.stack-preview-container';
exports.CONSOLE_MESSAGE_WRAPPER_SELECTOR = '.console-group-messages .console-message-wrapper';
exports.CONSOLE_SELECTOR = '.console-user-command-result';
exports.CONSOLE_SETTINGS_SELECTOR = '[aria-label^="Console settings"]';
exports.AUTOCOMPLETE_FROM_HISTORY_SELECTOR = '[title="Autocomplete from history"]';
exports.SHOW_CORS_ERRORS_SELECTOR = '[title="CORS errors in console"]';
exports.LOG_XML_HTTP_REQUESTS_SELECTOR = '[title="Log XMLHttpRequests"]';
exports.CONSOLE_CREATE_LIVE_EXPRESSION_SELECTOR = '[aria-label^="Create live expression"]';
exports.CONSOLE_SIDEBAR_SELECTOR = 'div[slot="sidebar"]';
exports.Level = {
    All: exports.CONSOLE_ALL_MESSAGES_SELECTOR,
    Info: exports.CONSOLE_INFO_MESSAGES_SELECTOR,
    Error: exports.CONSOLE_ERROR_MESSAGES_SELECTOR,
};
exports.SidebarItem = {
    Messages: 1,
    UserMessages: 2,
    Errors: 3,
    Warnings: 4,
    Info: 5,
    Verbose: 6,
};
async function deleteConsoleMessagesFilter(devToolsPage) {
    const main = await devToolsPage.waitFor('.console-main-toolbar');
    await devToolsPage.click('.toolbar-input-clear-button', {
        root: main,
    });
    await (0, visual_logging_helpers_js_1.expectVeEvents)([(0, visual_logging_helpers_js_1.veClick)('Toolbar > TextField: filter > Action: clear')], await veRoot(devToolsPage), devToolsPage);
}
async function filterConsoleMessages(filter, devToolsPage) {
    const main = await devToolsPage.waitFor('.console-main-toolbar');
    await devToolsPage.evaluate(toolbar => {
        const prompt = toolbar.querySelector('.toolbar-input-prompt.text-prompt');
        prompt.focus();
    }, main);
    await devToolsPage.pasteText(filter);
    await devToolsPage.drainTaskQueue();
    await devToolsPage.pressKey('Tab');
    if (filter.length) {
        await (0, visual_logging_helpers_js_1.expectVeEvents)([(0, visual_logging_helpers_js_1.veChange)('Toolbar > TextField: filter')], await veRoot(devToolsPage), devToolsPage);
    }
}
async function waitForConsoleMessagesToBeNonEmpty(numberOfMessages, devToolsPage) {
    await devToolsPage.waitForFunction(async () => {
        const messages = await devToolsPage.$$(exports.CONSOLE_ALL_MESSAGES_SELECTOR);
        if (messages.length < numberOfMessages) {
            return false;
        }
        const textContents = await Promise.all(messages.map(message => message.evaluate(message => message.textContent || '')));
        return textContents.every(text => text !== '');
    });
    await (0, visual_logging_helpers_js_1.expectVeEvents)([veImpressionForConsoleMessage()], await veRoot(devToolsPage), devToolsPage);
}
async function waitForExactConsoleMessageCount(expectedCount, devToolsPage) {
    const messageCount = await devToolsPage.waitForFunction(async () => {
        const selected = await devToolsPage.$$(exports.CONSOLE_ALL_MESSAGES_SELECTOR);
        const messageTexts = await Promise.all(selected.map(message => message.evaluate(message => message.textContent || '')));
        const validMessages = messageTexts.filter(text => text !== '');
        return validMessages.length;
    });
    chai_1.assert.strictEqual(messageCount, expectedCount);
    await (0, visual_logging_helpers_js_1.expectVeEvents)([veImpressionForConsoleMessage()], await veRoot(devToolsPage), devToolsPage);
}
async function waitForLastConsoleMessageToHaveContent(expectedTextContent, devToolsPage) {
    await devToolsPage.waitForFunction(async () => {
        const messages = await devToolsPage.$$(exports.CONSOLE_ALL_MESSAGES_SELECTOR);
        if (messages.length === 0) {
            return false;
        }
        const lastMessageContent = await messages[messages.length - 1].evaluate(message => message.textContent);
        return lastMessageContent === expectedTextContent;
    });
    await (0, visual_logging_helpers_js_1.expectVeEvents)([veImpressionForConsoleMessage()], await veRoot(devToolsPage), devToolsPage);
}
async function getConsoleMessages(testName, withAnchor = false, callback, devToolsPage, inspectedPage) {
    // Ensure Console is loaded before the page is loaded to avoid a race condition.
    await navigateToConsoleTab(devToolsPage);
    // Have the target load the page.
    await inspectedPage.goToResource(`console/${testName}.html`);
    return await getCurrentConsoleMessages(withAnchor, exports.Level.All, callback, devToolsPage);
}
async function getCurrentConsoleMessages(withAnchor = false, level = exports.Level.All, callback, devToolsPage) {
    const asyncScope = new async_scope_js_1.AsyncScope();
    await navigateToConsoleTab(devToolsPage);
    // Get console messages that were logged.
    await devToolsPage.waitFor(exports.CONSOLE_MESSAGES_SELECTOR, undefined, asyncScope);
    if (callback) {
        await callback();
    }
    // Ensure all messages are populated.
    await asyncScope.exec(() => devToolsPage.page.waitForFunction((selector) => {
        const messages = document.querySelectorAll(selector);
        if (messages.length === 0) {
            return false;
        }
        return Array.from(messages).every(message => message.childNodes.length > 0);
    }, { timeout: 0, polling: 'mutation' }, exports.CONSOLE_ALL_MESSAGES_SELECTOR));
    const selector = withAnchor ? exports.CONSOLE_MESSAGE_TEXT_AND_ANCHOR_SELECTOR : level;
    // FIXME(crbug/1112692): Refactor test to remove the timeout.
    await devToolsPage.timeout(100);
    await (0, visual_logging_helpers_js_1.expectVeEvents)([veImpressionForConsoleMessage()], await veRoot(devToolsPage), devToolsPage);
    // Get the messages from the console.
    return await devToolsPage.page.evaluate(selector => {
        return Array.from(document.querySelectorAll(selector)).map(message => message.textContent);
    }, selector);
}
async function getLastConsoleMessages(offset = 0, devToolsPage) {
    return (await getCurrentConsoleMessages(false, exports.Level.All, undefined, devToolsPage)).at(-1 - offset);
}
async function maybeGetCurrentConsoleMessages(withAnchor = false, callback, devToolsPage) {
    const asyncScope = new async_scope_js_1.AsyncScope();
    await navigateToConsoleTab(devToolsPage);
    // Get console messages that were logged.
    await devToolsPage.waitFor(exports.CONSOLE_MESSAGES_SELECTOR, undefined, asyncScope);
    if (callback) {
        await callback();
    }
    const selector = withAnchor ? exports.CONSOLE_MESSAGE_TEXT_AND_ANCHOR_SELECTOR : exports.CONSOLE_ALL_MESSAGES_SELECTOR;
    // FIXME(crbug/1112692): Refactor test to remove the timeout.
    await devToolsPage.timeout(100);
    // Get the messages from the console.
    const result = await devToolsPage.evaluate(selector => {
        return Array.from(document.querySelectorAll(selector)).map(message => message.textContent);
    }, selector);
    if (result.length) {
        await (0, visual_logging_helpers_js_1.expectVeEvents)([veImpressionForConsoleMessage()], await veRoot(devToolsPage), devToolsPage);
    }
    return result;
}
async function getStructuredConsoleMessages(devToolsPage) {
    const asyncScope = new async_scope_js_1.AsyncScope();
    await navigateToConsoleTab(devToolsPage);
    // Get console messages that were logged.
    await devToolsPage.waitFor(exports.CONSOLE_MESSAGES_SELECTOR, undefined, asyncScope);
    // Ensure all messages are populated.
    await asyncScope.exec(() => devToolsPage.page.waitForFunction((selector) => {
        return Array.from(document.querySelectorAll(selector)).every(message => {
            // Messages with a stack trace need to wait for the stack trace to show up.
            const stackTrace = message.querySelector('.hidden-stack-trace > div');
            if (stackTrace) {
                return Boolean(stackTrace.shadowRoot?.querySelector('tbody'));
            }
            return message.childNodes.length > 0;
        });
    }, { timeout: 0 }, exports.CONSOLE_ALL_MESSAGES_SELECTOR));
    await (0, visual_logging_helpers_js_1.expectVeEvents)([veImpressionForConsoleMessage()], await veRoot(devToolsPage), devToolsPage);
    return await devToolsPage.evaluate(selector => {
        return Array.from(document.querySelectorAll(selector)).map(wrapper => {
            const message = wrapper.querySelector('.console-message-text')?.textContent;
            const source = wrapper.querySelector('.devtools-link')?.textContent;
            const consoleMessage = wrapper.querySelector('.console-message');
            const repeatCount = wrapper.querySelector('.console-message-repeat-count');
            const stackPreviewRoot = wrapper.querySelector('.hidden-stack-trace > div');
            const stackPreview = stackPreviewRoot?.shadowRoot?.querySelectorAll('tbody') ?? null;
            return {
                message,
                messageClasses: consoleMessage?.className,
                repeatCount: repeatCount?.textContent ?? null,
                source,
                stackPreview: stackPreview?.length ? Array.from(stackPreview).map(x => x.textContent).join('') : null,
                wrapperClasses: wrapper?.className,
            };
        });
    }, exports.CONSOLE_MESSAGE_WRAPPER_SELECTOR);
}
async function focusConsolePrompt(devToolsPage) {
    await devToolsPage.click(exports.CONSOLE_PROMPT_SELECTOR);
    await devToolsPage.waitFor('[aria-label="Console prompt"]');
}
async function showVerboseMessages(devToolsPage) {
    await devToolsPage.click(exports.LOG_LEVELS_SELECTOR);
    await devToolsPage.click(exports.LOG_LEVELS_VERBOSE_OPTION_SELECTOR);
}
async function typeIntoConsole(message, devToolsPage) {
    const asyncScope = new async_scope_js_1.AsyncScope();
    const consoleElement = await devToolsPage.waitFor(exports.CONSOLE_PROMPT_SELECTOR, undefined, asyncScope);
    await consoleElement.click();
    await devToolsPage.typeText(message);
    // Wait for autocomplete text to catch up.
    const line = await devToolsPage.waitFor('[aria-label="Console prompt"]', consoleElement, asyncScope);
    const autocomplete = await devToolsPage.$(exports.CONSOLE_TOOLTIP_SELECTOR);
    // The autocomplete element doesn't exist until the first autocomplete suggestion
    // is actually given.
    // Sometimes the autocomplete suggests `assert` when typing `console.clear()` which made a test flake.
    // The following checks if there is any autocomplete text and dismisses it by pressing escape.
    if (autocomplete && await autocomplete.evaluate(e => e.textContent)) {
        await devToolsPage.pressKey('Escape');
    }
    await asyncScope.exec(() => devToolsPage.page.waitForFunction((msg, ln) => ln.textContent === msg, { timeout: 0 }, message, line));
    await devToolsPage.pressKey('Enter');
}
async function typeIntoConsoleAndWaitForResult(message, leastExpectedMessages = 1, selector = exports.Level.All, devToolsPage) {
    // Get the current number of console results so we can check we increased it.
    const originalLength = await devToolsPage.evaluate(selector => {
        return document.querySelectorAll(selector).length;
    }, selector);
    await typeIntoConsole(message, devToolsPage);
    await new async_scope_js_1.AsyncScope().exec(() => devToolsPage.page.waitForFunction((originalLength, leastExpectedMessages, selector) => {
        return document.querySelectorAll(selector).length >= originalLength + leastExpectedMessages;
    }, { timeout: 0 }, originalLength, leastExpectedMessages, selector));
}
async function unifyLogVM(actualLog, expectedLog) {
    const actualLogArray = actualLog.trim().split('\n').map(s => s.trim());
    const expectedLogArray = expectedLog.trim().split('\n').map(s => s.trim());
    chai_1.assert.strictEqual(actualLogArray.length, expectedLogArray.length, 'logs are not the same length');
    for (let index = 0; index < actualLogArray.length; index++) {
        const repl = actualLogArray[index].match(/VM\d+:/g);
        if (repl) {
            expectedLogArray[index] = expectedLogArray[index].replace(/VM\d+:/g, repl[0]);
        }
    }
    return expectedLogArray.join('\n');
}
async function navigateToConsoleTab(devToolsPage) {
    // Locate the button for switching to the console tab.
    if ((await devToolsPage.$$(exports.CONSOLE_VIEW_SELECTOR)).length) {
        return;
    }
    await devToolsPage.click(exports.CONSOLE_TAB_SELECTOR);
    await devToolsPage.waitFor(exports.CONSOLE_PROMPT_SELECTOR);
    await (0, visual_logging_helpers_js_1.expectVeEvents)([veImpressionForConsolePanel()], undefined, devToolsPage);
}
async function openConsoleSidebar(devToolsPage) {
    await devToolsPage.click('[aria-label="Show console sidebar"]');
    await devToolsPage.waitFor(exports.CONSOLE_SIDEBAR_SELECTOR);
}
async function closeConsoleSidebar(devToolsPage) {
    await devToolsPage.click('[aria-label="Hide console sidebar"]');
}
async function selectConsoleSidebarItem(devToolsPage, itemPosition = exports.SidebarItem.Info) {
    const sidebar = await devToolsPage.waitFor(exports.CONSOLE_SIDEBAR_SELECTOR);
    const itemSelector = `[role="tree"]>[role="treeitem"]:nth-of-type(${itemPosition})`;
    await devToolsPage.click(itemSelector, { root: sidebar });
}
async function waitForConsoleInfoMessageAndClickOnLink(devToolsPage) {
    const consoleMessage = await devToolsPage.waitFor('div.console-group-messages .console-info-level span.source-code');
    await devToolsPage.click('button.devtools-link', { root: consoleMessage });
    await (0, visual_logging_helpers_js_1.expectVeEvents)([(0, visual_logging_helpers_js_1.veClick)('Item: console-message > Link: script-location')], await veRoot(devToolsPage), devToolsPage);
}
async function turnOffHistoryAutocomplete(devToolsPage) {
    await devToolsPage.click(exports.CONSOLE_SETTINGS_SELECTOR);
    await devToolsPage.click(exports.AUTOCOMPLETE_FROM_HISTORY_SELECTOR);
    await (0, visual_logging_helpers_js_1.expectVeEvents)([
        (0, visual_logging_helpers_js_1.veClick)('Toolbar > ToggleSubpane: console-settings'),
        ...veImpressionsForConsoleSettings(),
        (0, visual_logging_helpers_js_1.veChange)('Toggle: console-history-autocomplete'),
    ], await veRoot(devToolsPage), devToolsPage);
}
async function toggleShowCorsErrors(devToolsPage) {
    await devToolsPage.click(exports.CONSOLE_SETTINGS_SELECTOR);
    await devToolsPage.click(exports.SHOW_CORS_ERRORS_SELECTOR);
    await (0, visual_logging_helpers_js_1.expectVeEvents)([
        (0, visual_logging_helpers_js_1.veClick)('Toolbar > ToggleSubpane: console-settings'),
        ...veImpressionsForConsoleSettings(),
        (0, visual_logging_helpers_js_1.veChange)('Toggle: console-shows-cors-errors'),
    ], await veRoot(devToolsPage), devToolsPage);
}
async function toggleShowLogXmlHttpRequests(devToolsPage) {
    await devToolsPage.click(exports.CONSOLE_SETTINGS_SELECTOR);
    await devToolsPage.click(exports.LOG_XML_HTTP_REQUESTS_SELECTOR);
    await (0, visual_logging_helpers_js_1.expectVeEvents)([
        (0, visual_logging_helpers_js_1.veClick)('Toolbar > ToggleSubpane: console-settings'),
        ...veImpressionsForConsoleSettings(),
        (0, visual_logging_helpers_js_1.veChange)('Toggle: monitoring-xhr-enabled'),
    ], await veRoot(devToolsPage), devToolsPage);
}
async function getIssueButtonLabel(devToolsPage) {
    const infobarButton = await devToolsPage.waitFor('#console-issues-counter');
    const iconButton = await devToolsPage.waitFor('icon-button', infobarButton);
    const titleElement = await devToolsPage.waitFor('.icon-button-title', iconButton);
    const infobarButtonText = await titleElement.evaluate(node => node.textContent);
    await (0, visual_logging_helpers_js_1.expectVeEvents)([(0, visual_logging_helpers_js_1.veImpression)('Counter', 'issues')], `${await veRoot(devToolsPage)} > Toolbar`, devToolsPage);
    return infobarButtonText;
}
async function waitForIssueButtonLabel(expectedLabel, devToolsPage) {
    await devToolsPage.waitForFunction(async () => {
        const label = await getIssueButtonLabel(devToolsPage);
        return expectedLabel === label;
    });
}
async function clickOnContextMenu(selectorForNode, jslogContext, devToolsPage) {
    await devToolsPage.click(selectorForNode, { clickOptions: { button: 'right' } });
    const menuItem = await devToolsPage.waitFor(`[jslog*="context: ${jslogContext}"]`);
    await menuItem.click();
    const isObject = ['copy-object', 'expand-recursively'].includes(jslogContext);
    await (0, visual_logging_helpers_js_1.expectVeEvents)([
        (0, visual_logging_helpers_js_1.veClick)(isObject ? 'Tree > TreeItem' : ''),
        veImpressionForConsoleMessageContextMenu(jslogContext),
        (0, visual_logging_helpers_js_1.veClick)(`Menu > Action: ${jslogContext}`),
        (0, visual_logging_helpers_js_1.veResize)('Menu'),
    ], `${await veRoot(devToolsPage)} > Item: console-message`, devToolsPage);
}
/**
 * Creates a function that runs a command and checks the nth output from the
 * bottom (checks last message by default)
 */
function checkCommandResultFunction(offset = 0) {
    return async function (command, expected, message, devToolsPage) {
        await typeIntoConsoleAndWaitForResult(command, 1, undefined, devToolsPage);
        chai_1.assert.strictEqual(await getLastConsoleMessages(offset, devToolsPage), expected, message);
    };
}
async function getLastConsoleStacktrace(offset = 0, devToolsPage) {
    return (await getStructuredConsoleMessages(devToolsPage)).at(-1 - offset)?.stackPreview;
}
async function checkCommandStacktrace(command, expected, leastMessages = 1, offset = 0, devToolsPage) {
    await typeIntoConsoleAndWaitForResult(command, leastMessages, undefined, devToolsPage);
    await unifyLogVM(await getLastConsoleStacktrace(offset, devToolsPage), expected);
}
function veImpressionForConsoleMessage() {
    return (0, visual_logging_helpers_js_1.veImpression)('Item', 'console-message');
}
function veImpressionForConsolePanel() {
    return (0, visual_logging_helpers_js_1.veImpression)('Panel', 'console', [
        (0, visual_logging_helpers_js_1.veImpression)('Toolbar', undefined, [
            (0, visual_logging_helpers_js_1.veImpression)('ToggleSubpane', 'console-sidebar'),
            (0, visual_logging_helpers_js_1.veImpression)('Action', 'console.clear'),
            (0, visual_logging_helpers_js_1.veImpression)('DropDown', 'javascript-context'),
            (0, visual_logging_helpers_js_1.veImpression)('Action', 'console.create-pin'),
            (0, visual_logging_helpers_js_1.veImpression)('DropDown', 'log-level'),
            (0, visual_logging_helpers_js_1.veImpression)('ToggleSubpane', 'console-settings'),
            (0, visual_logging_helpers_js_1.veImpression)('TextField', 'filter'),
        ]),
        (0, visual_logging_helpers_js_1.veImpression)('TextField', 'console-prompt'),
    ]);
}
function veImpressionsForConsoleSettings() {
    return [
        (0, visual_logging_helpers_js_1.veImpression)('Toggle', 'console-eager-eval'),
        (0, visual_logging_helpers_js_1.veImpression)('Toggle', 'console-group-similar'),
        (0, visual_logging_helpers_js_1.veImpression)('Toggle', 'console-history-autocomplete'),
        (0, visual_logging_helpers_js_1.veImpression)('Toggle', 'console-shows-cors-errors'),
        (0, visual_logging_helpers_js_1.veImpression)('Toggle', 'console-user-activation-eval'),
        (0, visual_logging_helpers_js_1.veImpression)('Toggle', 'network-messages'),
        (0, visual_logging_helpers_js_1.veImpression)('Toggle', 'monitoring-xhr-enabled'),
        (0, visual_logging_helpers_js_1.veImpression)('Toggle', 'preserve-console-log'),
        (0, visual_logging_helpers_js_1.veImpression)('Toggle', 'selected-context-filter-enabled'),
    ];
}
function veImpressionForConsoleMessageContextMenu(expectedItem) {
    const isObject = ['copy-object', 'expand-recursively'].includes(expectedItem);
    const isString = expectedItem.startsWith('copy-string');
    const isValue = isObject || expectedItem.startsWith('copy');
    const menuItems = new Set([expectedItem]);
    if (isValue) {
        menuItems.add('store-as-global-variable');
    }
    if (isObject) {
        menuItems.add('copy-object').add('collapse-children').add('expand-recursively');
    }
    if (isString) {
        menuItems.add('copy-string-as-js-literal').add('copy-string-as-json-literal').add('copy-string-contents');
    }
    return (0, visual_logging_helpers_js_1.veImpression)('Menu', undefined, [...menuItems].map(i => (0, visual_logging_helpers_js_1.veImpression)('Action', i)));
}
async function veRoot(devToolsPage) {
    return (await devToolsPage.$$(exports.CONSOLE_VIEW_IN_DRAWER_SELECTOR)).length ? 'Drawer > Panel: console' : 'Panel: console';
}
//# sourceMappingURL=console-helpers.js.map