browser_inspector_reload_missing-iframe-node.js (1858B)
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 "use strict"; 6 7 // Check that the markup view selection falls back to the document body if an iframe node 8 // becomes missing after a reload. This can happen if the iframe and its contents are 9 // added dynamically to the page before reloading. 10 11 const TEST_URI = "data:text/html;charset=utf-8,"; 12 13 add_task(async function () { 14 const { inspector } = await openInspectorForURL(TEST_URI); 15 16 info("Create new iframe and add it to the page."); 17 await ContentTask.spawn(gBrowser.selectedBrowser, null, async function () { 18 await new Promise(resolve => { 19 const iframe = content.document.createElement("iframe"); 20 21 iframe.addEventListener("load", () => { 22 // Create a div element and append it to the iframe 23 const div = content.document.createElement("div"); 24 div.id = "in-frame"; 25 div.textContent = "div in frame"; 26 27 const frameContent = 28 iframe.contentWindow.document.querySelector("body"); 29 frameContent.appendChild(div); 30 resolve(); 31 }); 32 content.document.body.appendChild(iframe); 33 }); 34 }); 35 ok( 36 await hasMatchingElementInContentPage("iframe"), 37 "The iframe has been added to the page" 38 ); 39 40 info("Select node inside iframe."); 41 await selectNodeInFrames(["iframe", "#in-frame"], inspector); 42 43 const markupLoaded = inspector.once("markuploaded"); 44 45 info("Reloading page."); 46 await navigateTo(TEST_URI); 47 48 info("Waiting for markupview to load after reload."); 49 await markupLoaded; 50 51 const rootNodeFront = await getNodeFront("body", inspector); 52 53 is( 54 inspector.selection.nodeFront, 55 rootNodeFront, 56 "body node selected after reload." 57 ); 58 });