"use strict";
// Copyright 2022 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 });
const chai_1 = require("chai");
const settings_helpers_js_1 = require("../helpers/settings-helpers.js");
const sources_helpers_js_1 = require("../helpers/sources-helpers.js");
describe('Ignore list', function () {
    it('can be toggled on and off in call stack', async ({ devToolsPage, inspectedPage }) => {
        await (0, settings_helpers_js_1.setIgnoreListPattern)('thirdparty', devToolsPage);
        await (0, sources_helpers_js_1.openSourceCodeEditorForFile)('multi-files-mycode.js', 'multi-files.html', devToolsPage, inspectedPage);
        await (0, sources_helpers_js_1.addBreakpointForLine)(4, devToolsPage);
        const scriptEvaluation = inspectedPage.evaluate('f();');
        await devToolsPage.waitFor(sources_helpers_js_1.RESUME_BUTTON);
        await devToolsPage.waitFor('.ignore-listed-call-frame.hidden');
        chai_1.assert.deepEqual(await (0, sources_helpers_js_1.getCallFrameNames)(devToolsPage), ['inner', 'outer', '(anonymous)']);
        // Toggle to show ignore-listed frames
        await devToolsPage.click('.ignore-listed-message-label');
        await devToolsPage.waitFor('.ignore-listed-call-frame:not(.hidden)');
        chai_1.assert.deepEqual(await (0, sources_helpers_js_1.getCallFrameNames)(devToolsPage), ['inner', 'innercall', 'callfunc', 'outer', '(anonymous)']);
        // Toggle back off
        await devToolsPage.click('.ignore-listed-message-label');
        await devToolsPage.waitFor('.ignore-listed-call-frame.hidden');
        chai_1.assert.deepEqual(await (0, sources_helpers_js_1.getCallFrameNames)(devToolsPage), ['inner', 'outer', '(anonymous)']);
        await devToolsPage.click(sources_helpers_js_1.RESUME_BUTTON);
        await scriptEvaluation;
    });
    it('shows no toggle when everything is ignore-listed', async ({ devToolsPage, inspectedPage }) => {
        await (0, settings_helpers_js_1.setIgnoreListPattern)('multi|pptr', devToolsPage);
        await (0, sources_helpers_js_1.openSourceCodeEditorForFile)('multi-files-mycode.js', 'multi-files.html', devToolsPage, inspectedPage);
        await (0, sources_helpers_js_1.addBreakpointForLine)(4, devToolsPage);
        const scriptEvaluation = inspectedPage.evaluate('f();');
        await devToolsPage.waitFor(sources_helpers_js_1.RESUME_BUTTON);
        // Toggle is not shown
        await devToolsPage.waitFor('.ignore-listed-message.hidden');
        // There are visible ignore-listed frames
        await devToolsPage.waitFor('.ignore-listed-call-frame:not(.hidden)');
        // All frames are shown
        chai_1.assert.deepEqual(await (0, sources_helpers_js_1.getCallFrameNames)(devToolsPage), ['inner', 'innercall', 'callfunc', 'outer', '(anonymous)']);
        await devToolsPage.click(sources_helpers_js_1.RESUME_BUTTON);
        await scriptEvaluation;
    });
    it('skips frames when stepping in and out', async ({ devToolsPage, inspectedPage }) => {
        await (0, settings_helpers_js_1.setIgnoreListPattern)('thirdparty', devToolsPage);
        await devToolsPage.installEventListener(sources_helpers_js_1.DEBUGGER_PAUSED_EVENT);
        await (0, sources_helpers_js_1.openSourceCodeEditorForFile)('multi-files-mycode.js', 'multi-files.html', devToolsPage, inspectedPage);
        await (0, sources_helpers_js_1.addBreakpointForLine)(8, devToolsPage);
        const scriptEvaluation = inspectedPage.evaluate('f();');
        await devToolsPage.waitFor(sources_helpers_js_1.RESUME_BUTTON);
        await devToolsPage.waitFor(sources_helpers_js_1.PAUSE_INDICATOR_SELECTOR);
        await devToolsPage.waitForFunction(async () => await devToolsPage.getPendingEvents(sources_helpers_js_1.DEBUGGER_PAUSED_EVENT));
        chai_1.assert.deepEqual(await (0, sources_helpers_js_1.getCallFrameNames)(devToolsPage), ['outer', '(anonymous)']);
        await (0, sources_helpers_js_1.stepIn)(devToolsPage);
        await devToolsPage.waitFor('.call-frame-title-text[title="inner"]');
        await devToolsPage.waitFor('.ignore-listed-call-frame.hidden');
        chai_1.assert.deepEqual(await (0, sources_helpers_js_1.getCallFrameNames)(devToolsPage), ['inner', 'outer', '(anonymous)']);
        await (0, sources_helpers_js_1.stepOut)(devToolsPage);
        await devToolsPage.waitForNone('.call-frame-title-text[title="inner"]');
        chai_1.assert.deepEqual(await (0, sources_helpers_js_1.getCallFrameNames)(devToolsPage), ['outer', '(anonymous)']);
        await devToolsPage.click(sources_helpers_js_1.RESUME_BUTTON);
        await scriptEvaluation;
    });
    it('skips instrumentation breakpoints', async ({ devToolsPage, inspectedPage }) => {
        await (0, settings_helpers_js_1.setIgnoreListPattern)('thirdparty', devToolsPage);
        await devToolsPage.installEventListener(sources_helpers_js_1.DEBUGGER_PAUSED_EVENT);
        await (0, sources_helpers_js_1.openSourceCodeEditorForFile)('multi-files-mycode.js', 'multi-files.html', devToolsPage, inspectedPage);
        await (0, sources_helpers_js_1.setEventListenerBreakpoint)('Timer', 'setTimeout', devToolsPage);
        const scriptEvaluation = inspectedPage.evaluate('debugger; timeoutTestCase();');
        await devToolsPage.waitFor(sources_helpers_js_1.RESUME_BUTTON);
        await devToolsPage.waitFor(sources_helpers_js_1.PAUSE_INDICATOR_SELECTOR);
        await devToolsPage.waitForFunction(async () => await devToolsPage.getPendingEvents(sources_helpers_js_1.DEBUGGER_PAUSED_EVENT));
        chai_1.assert.deepEqual(await (0, sources_helpers_js_1.getCallFrameNames)(devToolsPage), ['(anonymous)']);
        await devToolsPage.click(sources_helpers_js_1.RESUME_BUTTON);
        await devToolsPage.waitFor('.call-frame-title-text[title="userTimeout"]');
        await devToolsPage.waitFor(sources_helpers_js_1.RESUME_BUTTON);
        await devToolsPage.waitFor(sources_helpers_js_1.PAUSE_INDICATOR_SELECTOR);
        await devToolsPage.waitForFunction(async () => await devToolsPage.getPendingEvents(sources_helpers_js_1.DEBUGGER_PAUSED_EVENT));
        chai_1.assert.deepEqual(await (0, sources_helpers_js_1.getCallFrameNames)(devToolsPage), ['userTimeout', 'Promise.then', '(anonymous)']);
        await devToolsPage.click(sources_helpers_js_1.RESUME_BUTTON);
        await scriptEvaluation;
    });
    it('indicates ignored sources in page source tree', async ({ devToolsPage, inspectedPage }) => {
        await (0, settings_helpers_js_1.setIgnoreListPattern)('/sources/', devToolsPage);
        await inspectedPage.goToResource('sources/multi-files.html');
        await (0, sources_helpers_js_1.openSourcesPanel)(devToolsPage);
        chai_1.assert.deepEqual(await (0, sources_helpers_js_1.readIgnoreListedSources)(devToolsPage), [
            'test/e2e/resources/sources',
            'multi-files.html',
            'multi-files-mycode.js',
            'multi-files-thirdparty.js',
        ]);
        await (0, settings_helpers_js_1.toggleIgnoreListing)(false, devToolsPage);
        chai_1.assert.deepEqual(await (0, sources_helpers_js_1.readIgnoreListedSources)(devToolsPage), []);
        await (0, settings_helpers_js_1.toggleIgnoreListing)(true, devToolsPage);
        chai_1.assert.deepEqual(await (0, sources_helpers_js_1.readIgnoreListedSources)(devToolsPage), [
            'test/e2e/resources/sources',
            'multi-files.html',
            'multi-files-mycode.js',
            'multi-files-thirdparty.js',
        ]);
    });
    describe('with just-my-code setting', () => {
        setup({
            devToolsSettings: { 'navigator-just-my-code': true },
        });
        it('removes ignored sources from page source tree', async ({ devToolsPage, inspectedPage }) => {
            await (0, settings_helpers_js_1.setIgnoreListPattern)('thirdparty', devToolsPage);
            await inspectedPage.goToResource('sources/multi-files.html');
            await (0, sources_helpers_js_1.openSourcesPanel)(devToolsPage);
            chai_1.assert.deepEqual(await (0, sources_helpers_js_1.readSourcesTreeView)(devToolsPage), ['top', 'localhost:XXXX', 'test/e2e/resources/sources', 'multi-files.html', 'multi-files-mycode.js']);
            await (0, settings_helpers_js_1.toggleIgnoreListing)(false, devToolsPage);
            chai_1.assert.deepEqual(await (0, sources_helpers_js_1.readSourcesTreeView)(devToolsPage), [
                'top',
                'localhost:XXXX',
                'test/e2e/resources/sources',
                'multi-files.html',
                'multi-files-mycode.js',
                'multi-files-thirdparty.js',
            ]);
            await (0, settings_helpers_js_1.toggleIgnoreListing)(true, devToolsPage);
            chai_1.assert.deepEqual(await (0, sources_helpers_js_1.readSourcesTreeView)(devToolsPage), ['top', 'localhost:XXXX', 'test/e2e/resources/sources', 'multi-files.html', 'multi-files-mycode.js']);
        });
    });
});
//# sourceMappingURL=ignore-list.test.js.map