summaryrefslogtreecommitdiffstats
path: root/remote/shared/test/browser/browser_NavigationManager_notify.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_notify.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_notify.js')
-rw-r--r--remote/shared/test/browser/browser_NavigationManager_notify.js170
1 files changed, 170 insertions, 0 deletions
diff --git a/remote/shared/test/browser/browser_NavigationManager_notify.js b/remote/shared/test/browser/browser_NavigationManager_notify.js
new file mode 100644
index 0000000000..4dca0f7b4e
--- /dev/null
+++ b/remote/shared/test/browser/browser_NavigationManager_notify.js
@@ -0,0 +1,170 @@
+/* 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, notifyNavigationStarted, notifyNavigationStopped } =
+ ChromeUtils.importESModule(
+ "chrome://remote/content/shared/NavigationManager.sys.mjs"
+ );
+const { TabManager } = ChromeUtils.importESModule(
+ "chrome://remote/content/shared/TabManager.sys.mjs"
+);
+
+const FIRST_URL = "https://example.com/document-builder.sjs?html=first";
+const SECOND_URL = "https://example.com/document-builder.sjs?html=second";
+
+add_task(async function test_notifyNavigationStartedStopped() {
+ const tab = addTab(gBrowser, FIRST_URL);
+ const browser = tab.linkedBrowser;
+ await BrowserTestUtils.browserLoaded(browser, false, FIRST_URL);
+
+ const events = [];
+ const onEvent = (name, data) => events.push({ name, data });
+
+ const navigationManager = new NavigationManager();
+ navigationManager.on("navigation-started", onEvent);
+ navigationManager.on("navigation-stopped", onEvent);
+
+ navigationManager.startMonitoring();
+
+ const navigableId = TabManager.getIdForBrowser(browser);
+
+ info("Programmatically start a navigation");
+ const startedNavigation = notifyNavigationStarted({
+ contextDetails: {
+ context: browser.browsingContext,
+ },
+ url: SECOND_URL,
+ });
+
+ const navigation = navigationManager.getNavigationForBrowsingContext(
+ browser.browsingContext
+ );
+ assertNavigation(navigation, SECOND_URL);
+
+ is(
+ startedNavigation,
+ navigation,
+ "notifyNavigationStarted returned the expected navigation"
+ );
+ is(events.length, 1, "Only one event recorded");
+
+ info("Attempt to start a navigation while another one is in progress");
+ const alreadyStartedNavigation = notifyNavigationStarted({
+ contextDetails: {
+ context: browser.browsingContext,
+ },
+ url: SECOND_URL,
+ });
+ is(
+ alreadyStartedNavigation,
+ navigation,
+ "notifyNavigationStarted returned the ongoing navigation"
+ );
+ is(events.length, 1, "Still only one event recorded");
+
+ info("Programmatically stop the navigation");
+ const stoppedNavigation = notifyNavigationStopped({
+ contextDetails: {
+ context: browser.browsingContext,
+ },
+ url: SECOND_URL,
+ });
+ is(
+ stoppedNavigation,
+ navigation,
+ "notifyNavigationStopped returned the expected navigation"
+ );
+
+ is(events.length, 2, "Two events recorded");
+ assertNavigationEvents(
+ events,
+ SECOND_URL,
+ navigation.navigationId,
+ navigableId
+ );
+
+ info("Attempt to stop an already stopped navigation");
+ const alreadyStoppedNavigation = notifyNavigationStopped({
+ contextDetails: {
+ context: browser.browsingContext,
+ },
+ url: SECOND_URL,
+ });
+ is(
+ alreadyStoppedNavigation,
+ navigation,
+ "notifyNavigationStopped returned the already stopped navigation"
+ );
+ is(events.length, 2, "Still only two events recorded");
+
+ navigationManager.off("navigation-started", onEvent);
+ navigationManager.off("navigation-stopped", onEvent);
+ navigationManager.stopMonitoring();
+});
+
+add_task(async function test_notifyNavigationWithContextDetails() {
+ const tab = addTab(gBrowser, FIRST_URL);
+ const browser = tab.linkedBrowser;
+ await BrowserTestUtils.browserLoaded(browser, false, FIRST_URL);
+
+ const events = [];
+ const onEvent = (name, data) => events.push({ name, data });
+
+ const navigationManager = new NavigationManager();
+ navigationManager.on("navigation-started", onEvent);
+ navigationManager.on("navigation-stopped", onEvent);
+
+ navigationManager.startMonitoring();
+
+ const navigableId = TabManager.getIdForBrowser(browser);
+
+ info("Programmatically start a navigation using browsing context details");
+ const startedNavigation = notifyNavigationStarted({
+ contextDetails: {
+ browsingContextId: browser.browsingContext.id,
+ browserId: browser.browsingContext.browserId,
+ isTopBrowsingContext: browser.browsingContext.parent === null,
+ },
+ url: SECOND_URL,
+ });
+
+ const navigation = navigationManager.getNavigationForBrowsingContext(
+ browser.browsingContext
+ );
+ assertNavigation(navigation, SECOND_URL);
+
+ is(
+ startedNavigation,
+ navigation,
+ "notifyNavigationStarted returned the expected navigation"
+ );
+ is(events.length, 1, "Only one event recorded");
+
+ info("Programmatically stop the navigation using browsing context details");
+ const stoppedNavigation = notifyNavigationStopped({
+ contextDetails: {
+ browsingContextId: browser.browsingContext.id,
+ browserId: browser.browsingContext.browserId,
+ isTopBrowsingContext: browser.browsingContext.parent === null,
+ },
+ url: SECOND_URL,
+ });
+ is(
+ stoppedNavigation,
+ navigation,
+ "notifyNavigationStopped returned the expected navigation"
+ );
+
+ is(events.length, 2, "Two events recorded");
+ assertNavigationEvents(
+ events,
+ SECOND_URL,
+ navigation.navigationId,
+ navigableId
+ );
+
+ navigationManager.off("navigation-started", onEvent);
+ navigationManager.off("navigation-stopped", onEvent);
+ navigationManager.stopMonitoring();
+});