browser_inspector_reload_invalid_iframe.js (2028B)
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 // When reselecting the selected node, if an element expected to be an iframe is 8 // NOT actually an iframe, we should still fallback on the root body element. 9 10 const TEST_URI = "data:text/html;charset=utf-8,<div id='fake-iframe'>"; 11 12 add_task(async function () { 13 const { inspector } = await openInspectorForURL(TEST_URI); 14 15 info("Replace fake-iframe div with a real iframe"); 16 await ContentTask.spawn(gBrowser.selectedBrowser, null, async function () { 17 await new Promise(resolve => { 18 // Remove the fake-iframe div 19 content.document.querySelector("#fake-iframe").remove(); 20 21 // Create an iframe element with the same id "fake-iframe". 22 const iframe = content.document.createElement("iframe"); 23 iframe.setAttribute("id", "fake-iframe"); 24 25 iframe.addEventListener("load", () => { 26 // Create a div element and append it to the iframe 27 const div = content.document.createElement("div"); 28 div.id = "in-frame"; 29 div.textContent = "div in frame"; 30 31 const frameContent = 32 iframe.contentWindow.document.querySelector("body"); 33 frameContent.appendChild(div); 34 resolve(); 35 }); 36 content.document.body.appendChild(iframe); 37 }); 38 }); 39 40 ok( 41 await hasMatchingElementInContentPage("iframe"), 42 "The iframe has been added to the page" 43 ); 44 45 info("Select node inside iframe."); 46 await selectNodeInFrames(["iframe", "#in-frame"], inspector); 47 48 const markupLoaded = inspector.once("markuploaded"); 49 50 info("Reloading page."); 51 await navigateTo(TEST_URI); 52 53 info("Waiting for markupview to load after reload."); 54 await markupLoaded; 55 56 const rootNodeFront = await getNodeFront("body", inspector); 57 58 is( 59 inspector.selection.nodeFront, 60 rootNodeFront, 61 "body node selected after reload." 62 ); 63 });