browser_dbg-dom-mutation-breakpoints-fission.js (3653B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */ 4 5 // Tests dom mutation breakpoints with a remote frame. 6 7 "use strict"; 8 9 // Import helpers for the inspector 10 Services.scriptloader.loadSubScript( 11 "chrome://mochitests/content/browser/devtools/client/inspector/test/shared-head.js", 12 this 13 ); 14 15 /** 16 * The test page contains an INPUT and a BUTTON. 17 * 18 * On "click", the button will update the disabled attribute of the input. 19 * Updating the attribute via SpecialPowers.spawn would not trigger the DOM 20 * breakpoint, that's why we need the page itself to have a way of updating 21 * the attribute. 22 */ 23 const TEST_COM_URI = `https://example.com/document-builder.sjs?html=${encodeURI( 24 `<input disabled=""/> 25 <button onclick="document.querySelector('input').toggleAttribute('disabled')"> 26 click me 27 </button>` 28 )}`; 29 30 // Embed the example.com test page in an example.org iframe. 31 const TEST_URI = `https://example.org/document-builder.sjs?html= 32 <iframe src="${encodeURI(TEST_COM_URI)}"></iframe><body>`; 33 34 add_task(async function () { 35 await pushPref("devtools.debugger.dom-mutation-breakpoints-visible", true); 36 37 const { inspector, toolbox } = await openInspectorForURL(TEST_URI); 38 39 await selectNodeInFrames(["iframe", "input"], inspector); 40 info("Adding DOM mutation breakpoints to body"); 41 const allMenuItems = openContextMenuAndGetAllItems(inspector); 42 43 const attributeMenuItem = allMenuItems.find( 44 item => item.id === "node-menu-mutation-breakpoint-attribute" 45 ); 46 attributeMenuItem.click(); 47 48 info("Switches over to the debugger pane"); 49 await toolbox.selectTool("jsdebugger"); 50 51 const dbg = createDebuggerContext(toolbox); 52 53 info("Changing attribute to trigger debugger pause"); 54 const frameBC = await SpecialPowers.spawn( 55 gBrowser.selectedBrowser, 56 [], 57 function () { 58 return content.document.querySelector("iframe").browsingContext; 59 } 60 ); 61 62 info("Confirms that one DOM mutation breakpoint exists"); 63 const mutationItem = await waitForElement(dbg, "domMutationItem"); 64 ok(mutationItem, "A DOM mutation breakpoint exists"); 65 66 mutationItem.scrollIntoView(); 67 68 info("Enabling and disabling the DOM mutation breakpoint works"); 69 const checkbox = mutationItem.querySelector("input"); 70 checkbox.click(); 71 await waitFor(() => !checkbox.checked); 72 73 info("Click the button in the remote iframe, should not hit the breakpoint"); 74 BrowserTestUtils.synthesizeMouseAtCenter("button", {}, frameBC); 75 76 info("Wait until the input is enabled"); 77 await asyncWaitUntil(() => 78 SpecialPowers.spawn( 79 frameBC, 80 [], 81 () => !content.document.querySelector("input").disabled 82 ) 83 ); 84 assertNotPaused(dbg, "DOM breakpoint should not have been hit"); 85 86 info("Restore the disabled attribute"); 87 await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () { 88 return SpecialPowers.spawn( 89 content.document.querySelector("iframe"), 90 [], 91 () => 92 !content.document.querySelector("input").setAttribute("disabled", "") 93 ); 94 }); 95 96 checkbox.click(); 97 await waitFor(() => checkbox.checked); 98 99 info("Click the button in the remote iframe, to trigger the breakpoint"); 100 BrowserTestUtils.synthesizeMouseAtCenter("button", {}, frameBC); 101 102 info("Wait for paused"); 103 await waitForPaused(dbg); 104 info("Resume"); 105 await resume(dbg); 106 107 info("Removing breakpoints works"); 108 dbg.win.document.querySelector(".dom-mutation-list .close-btn").click(); 109 await waitForAllElements(dbg, "domMutationItem", 0, true); 110 });