summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/test/browser_inspector_reload_invalid_iframe.js
diff options
context:
space:
mode:
Diffstat (limited to 'devtools/client/inspector/test/browser_inspector_reload_invalid_iframe.js')
-rw-r--r--devtools/client/inspector/test/browser_inspector_reload_invalid_iframe.js63
1 files changed, 63 insertions, 0 deletions
diff --git a/devtools/client/inspector/test/browser_inspector_reload_invalid_iframe.js b/devtools/client/inspector/test/browser_inspector_reload_invalid_iframe.js
new file mode 100644
index 0000000000..2a6bd69e48
--- /dev/null
+++ b/devtools/client/inspector/test/browser_inspector_reload_invalid_iframe.js
@@ -0,0 +1,63 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+// When reselecting the selected node, if an element expected to be an iframe is
+// NOT actually an iframe, we should still fallback on the root body element.
+
+const TEST_URI = "data:text/html;charset=utf-8,<div id='fake-iframe'>";
+
+add_task(async function () {
+ const { inspector } = await openInspectorForURL(TEST_URI);
+
+ info("Replace fake-iframe div with a real iframe");
+ await ContentTask.spawn(gBrowser.selectedBrowser, null, async function () {
+ await new Promise(resolve => {
+ // Remove the fake-iframe div
+ content.document.querySelector("#fake-iframe").remove();
+
+ // Create an iframe element with the same id "fake-iframe".
+ const iframe = content.document.createElement("iframe");
+ content.document.body.appendChild(iframe);
+ iframe.setAttribute("id", "fake-iframe");
+
+ iframe.contentWindow.addEventListener("load", () => {
+ // Create a div element and append it to the iframe
+ const div = content.document.createElement("div");
+ div.id = "in-frame";
+ div.textContent = "div in frame";
+
+ const frameContent =
+ iframe.contentWindow.document.querySelector("body");
+ frameContent.appendChild(div);
+ resolve();
+ });
+ });
+ });
+
+ ok(
+ await hasMatchingElementInContentPage("iframe"),
+ "The iframe has been added to the page"
+ );
+
+ info("Select node inside iframe.");
+ await selectNodeInFrames(["iframe", "#in-frame"], inspector);
+
+ const markupLoaded = inspector.once("markuploaded");
+
+ info("Reloading page.");
+ await navigateTo(TEST_URI);
+
+ info("Waiting for markupview to load after reload.");
+ await markupLoaded;
+
+ const rootNodeFront = await getNodeFront("body", inspector);
+
+ is(
+ inspector.selection.nodeFront,
+ rootNodeFront,
+ "body node selected after reload."
+ );
+});