"use strict";
// Copyright 2026 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 elements_helpers_js_1 = require("../helpers/elements-helpers.js");
const sources_helpers_js_1 = require("../helpers/sources-helpers.js");
async function waitForDOMBreakpointCount(expectedCount, devToolsPage) {
    await devToolsPage.waitForFunction(async () => {
        const breakpoints = await devToolsPage.$$('.breakpoint-entry');
        return breakpoints.length === expectedCount;
    });
}
describe('DOM Breakpoints', () => {
    it('persists subtree modifications DOM breakpoint state between page reloads', async ({ devToolsPage, inspectedPage }) => {
        await (0, elements_helpers_js_1.goToResourceAndWaitForStyleSection)('sources/dom-breakpoints.html', devToolsPage, inspectedPage);
        await (0, elements_helpers_js_1.findElementById)('rootElement', devToolsPage);
        await (0, elements_helpers_js_1.setDOMBreakpointOnSelectedNode)('subtree modifications', devToolsPage);
        await (0, elements_helpers_js_1.waitForElementsDOMBreakpointsSection)(devToolsPage);
        await waitForDOMBreakpointCount(1, devToolsPage);
        const breakpoints = await devToolsPage.$$('.breakpoint-entry');
        chai_1.assert.isTrue(await (0, elements_helpers_js_1.isDOMBreakpointEnabled)(breakpoints[0], devToolsPage));
        await inspectedPage.reload();
        await (0, elements_helpers_js_1.waitForElementsDOMBreakpointsSection)(devToolsPage);
        const scriptPromise = inspectedPage.evaluate(() => {
            appendElement('rootElement', 'childElement');
        });
        const status = await (0, sources_helpers_js_1.getPausedMessages)(devToolsPage);
        chai_1.assert.strictEqual(status.statusMain, 'Paused on subtree modifications');
        chai_1.assert.strictEqual(status.statusSub, 'Child  added');
        const callFrames = await (0, sources_helpers_js_1.getCallFrameNames)(devToolsPage);
        chai_1.assert.deepEqual(callFrames, ['appendElement', '(anonymous)']);
        await devToolsPage.click(sources_helpers_js_1.RESUME_BUTTON);
        await scriptPromise;
    });
    it('pauses on subtree modifications DOM breakpoint set on shadow root when a child is appended', async ({ devToolsPage, inspectedPage }) => {
        await (0, elements_helpers_js_1.goToResourceAndWaitForStyleSection)('sources/dom-breakpoints.html', devToolsPage, inspectedPage);
        await (0, elements_helpers_js_1.findElementById)('outerElement', devToolsPage);
        await devToolsPage.pressKey('ArrowUp');
        await (0, elements_helpers_js_1.setDOMBreakpointOnSelectedNode)('subtree modifications', devToolsPage);
        await (0, elements_helpers_js_1.waitForElementsDOMBreakpointsSection)(devToolsPage);
        await waitForDOMBreakpointCount(1, devToolsPage);
        const breakpoints = await devToolsPage.$$('.breakpoint-entry');
        chai_1.assert.isTrue(await (0, elements_helpers_js_1.isDOMBreakpointEnabled)(breakpoints[0], devToolsPage));
        const scriptPromise = inspectedPage.evaluate(() => {
            appendElementToOpenShadowRoot('childElement');
        });
        const status = await (0, sources_helpers_js_1.getPausedMessages)(devToolsPage);
        chai_1.assert.strictEqual(status.statusMain, 'Paused on subtree modifications');
        chai_1.assert.strictEqual(status.statusSub, 'Child  added');
        const callFrames = await (0, sources_helpers_js_1.getCallFrameNames)(devToolsPage);
        chai_1.assert.deepEqual(callFrames, ['appendElementToOpenShadowRoot', '(anonymous)']);
        await devToolsPage.click(sources_helpers_js_1.RESUME_BUTTON);
        await scriptPromise;
    });
    it('persists shadow DOM breakpoints between page reloads', async ({ devToolsPage, inspectedPage }) => {
        await (0, elements_helpers_js_1.goToResourceAndWaitForStyleSection)('sources/dom-breakpoints.html', devToolsPage, inspectedPage);
        await (0, elements_helpers_js_1.findElementById)('outerElement', devToolsPage);
        await (0, elements_helpers_js_1.setDOMBreakpointOnSelectedNode)('subtree modifications', devToolsPage);
        await (0, elements_helpers_js_1.waitForElementsDOMBreakpointsSection)(devToolsPage);
        await waitForDOMBreakpointCount(1, devToolsPage);
        const breakpoints = await devToolsPage.$$('.breakpoint-entry');
        chai_1.assert.isTrue(await (0, elements_helpers_js_1.isDOMBreakpointEnabled)(breakpoints[0], devToolsPage));
        await inspectedPage.reload();
        await (0, elements_helpers_js_1.waitForElementsDOMBreakpointsSection)(devToolsPage);
        const scriptPromise = inspectedPage.evaluate(() => {
            appendElementToAuthorShadowTree('outerElement', 'childElement');
        });
        const status = await (0, sources_helpers_js_1.getPausedMessages)(devToolsPage);
        chai_1.assert.strictEqual(status.statusMain, 'Paused on subtree modifications');
        chai_1.assert.strictEqual(status.statusSub, 'Child  added');
        const callFrames = await (0, sources_helpers_js_1.getCallFrameNames)(devToolsPage);
        chai_1.assert.deepEqual(callFrames, ['appendElementToAuthorShadowTree', '(anonymous)']);
        await devToolsPage.click(sources_helpers_js_1.RESUME_BUTTON);
        await scriptPromise;
    });
});
//# sourceMappingURL=dom-breakpoints.test.js.map