summaryrefslogtreecommitdiffstats
path: root/remote/shared/test/browser/browser_NavigationManager_no_navigation.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /remote/shared/test/browser/browser_NavigationManager_no_navigation.js
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'remote/shared/test/browser/browser_NavigationManager_no_navigation.js')
-rw-r--r--remote/shared/test/browser/browser_NavigationManager_no_navigation.js60
1 files changed, 60 insertions, 0 deletions
diff --git a/remote/shared/test/browser/browser_NavigationManager_no_navigation.js b/remote/shared/test/browser/browser_NavigationManager_no_navigation.js
new file mode 100644
index 0000000000..370c09d351
--- /dev/null
+++ b/remote/shared/test/browser/browser_NavigationManager_no_navigation.js
@@ -0,0 +1,60 @@
+/* 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/. */
+
+const { NavigationManager } = ChromeUtils.importESModule(
+ "chrome://remote/content/shared/NavigationManager.sys.mjs"
+);
+const { TabManager } = ChromeUtils.importESModule(
+ "chrome://remote/content/shared/TabManager.sys.mjs"
+);
+
+add_task(async function testDocumentOpenWriteClose() {
+ const events = [];
+ const onEvent = (name, data) => events.push({ name, data });
+
+ const navigationManager = new NavigationManager();
+ navigationManager.on("location-changed", onEvent);
+ navigationManager.on("navigation-started", onEvent);
+ navigationManager.on("navigation-stopped", onEvent);
+
+ const url = "https://example.com/document-builder.sjs?html=test";
+
+ const tab = addTab(gBrowser, url);
+ const browser = tab.linkedBrowser;
+ await BrowserTestUtils.browserLoaded(browser);
+
+ navigationManager.startMonitoring();
+ is(events.length, 0, "No event recorded");
+
+ info("Replace the document");
+ await SpecialPowers.spawn(browser, [], async () => {
+ // Note: we need to use eval here to have reduced permissions and avoid
+ // security errors.
+ content.eval(`
+ document.open();
+ document.write("<h1 class='replaced'>Replaced</h1>");
+ document.close();
+ `);
+
+ await ContentTaskUtils.waitForCondition(() =>
+ content.document.querySelector(".replaced")
+ );
+ });
+
+ // See Bug 1844517.
+ // document.open/write/close is identical to same-url + same-hash navigations.
+ todo_is(events.length, 0, "No event recorded after replacing the document");
+
+ info("Reload the page, which should trigger a navigation");
+ await loadURL(browser, url);
+
+ // See Bug 1844517.
+ // document.open/write/close is identical to same-url + same-hash navigations.
+ todo_is(events.length, 2, "Recorded navigation events");
+
+ navigationManager.off("location-changed", onEvent);
+ navigationManager.off("navigation-started", onEvent);
+ navigationManager.off("navigation-stopped", onEvent);
+ navigationManager.stopMonitoring();
+});