summaryrefslogtreecommitdiffstats
path: root/dom/ipc/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:34:42 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:34:42 +0000
commitda4c7e7ed675c3bf405668739c3012d140856109 (patch)
treecdd868dba063fecba609a1d819de271f0d51b23e /dom/ipc/tests
parentAdding upstream version 125.0.3. (diff)
downloadfirefox-da4c7e7ed675c3bf405668739c3012d140856109.tar.xz
firefox-da4c7e7ed675c3bf405668739c3012d140856109.zip
Adding upstream version 126.0.upstream/126.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/ipc/tests')
-rw-r--r--dom/ipc/tests/JSWindowActor/browser_event_listener.js10
-rw-r--r--dom/ipc/tests/browser.toml2
-rw-r--r--dom/ipc/tests/browser_isactiveintab.js138
3 files changed, 147 insertions, 3 deletions
diff --git a/dom/ipc/tests/JSWindowActor/browser_event_listener.js b/dom/ipc/tests/JSWindowActor/browser_event_listener.js
index 725c2c3753..21cb0c5ee9 100644
--- a/dom/ipc/tests/JSWindowActor/browser_event_listener.js
+++ b/dom/ipc/tests/JSWindowActor/browser_event_listener.js
@@ -144,7 +144,7 @@ declTest("test in-process content events are not processed twice", {
"content",
"Should be a content <browser>"
);
- is(browser.getAttribute("remotetype"), "", "Should not be remote");
+ is(browser.getAttribute("remotetype"), null, "Should not be remote");
await testEventProcessedOnce(browser);
},
});
@@ -160,8 +160,12 @@ declTest("test in-process chrome events are processed correctly", {
"chrome://mochitests/content/browser/dom/ipc/tests/JSWindowActor/file_dummyChromePage.html"
);
let chromeBrowser = dialog._frame;
- is(chromeBrowser.getAttribute("type"), "", "Should be a chrome <browser>");
- is(chromeBrowser.getAttribute("remotetype"), "", "Should not be remote");
+ is(
+ chromeBrowser.getAttribute("type"),
+ null,
+ "Should be a chrome <browser>"
+ );
+ is(chromeBrowser.getAttribute("remotetype"), null, "Should not be remote");
await testEventProcessedOnce(chromeBrowser, "dummyChromePage.html");
diff --git a/dom/ipc/tests/browser.toml b/dom/ipc/tests/browser.toml
index cd2129e9c1..550558ca46 100644
--- a/dom/ipc/tests/browser.toml
+++ b/dom/ipc/tests/browser.toml
@@ -64,6 +64,8 @@ skip-if = [
["browser_hide_tooltip.js"]
+["browser_isactiveintab.js"]
+
["browser_layers_unloaded_while_interruptingJS.js"]
["browser_memory_distribution_telemetry.js"]
diff --git a/dom/ipc/tests/browser_isactiveintab.js b/dom/ipc/tests/browser_isactiveintab.js
new file mode 100644
index 0000000000..bd189f1826
--- /dev/null
+++ b/dom/ipc/tests/browser_isactiveintab.js
@@ -0,0 +1,138 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function documentURL(origin, html) {
+ let params = new URLSearchParams();
+ params.append("html", html.trim());
+ return `${origin}/document-builder.sjs?${params.toString()}`;
+}
+
+add_task(async function checkIsActiveInTab() {
+ // This test creates a few tricky situations with navigation and iframes and
+ // examines the results of various ways you might think to check if a page
+ // is currently visible, and confirms that isActiveInTab works, even if the
+ // others don't.
+
+ // Make a top level page with two nested iframes.
+ const IFRAME2_URL = documentURL("https://example.com", `<h1>iframe2</h1>`);
+ const IFRAME1_URL = documentURL(
+ "https://example.com",
+ `<iframe src=${JSON.stringify(IFRAME2_URL)}></iframe><h1>iframe1</h1>`
+ );
+ const TEST_URL = documentURL(
+ "https://example.com",
+ `<iframe src=${JSON.stringify(IFRAME1_URL)}></iframe><h1>top window</h1>`
+ );
+
+ await BrowserTestUtils.withNewTab(TEST_URL, async browser => {
+ let topBC1 = browser.browsingContext;
+ let topWindowGlobal1 = topBC1.currentWindowGlobal;
+
+ is(
+ browser.browsingContext.children.length,
+ 1,
+ "only one child for top window"
+ );
+ let iframe1 = browser.browsingContext.children[0];
+ let iframeWindowGlobal1a = iframe1.currentWindowGlobal;
+
+ is(iframe1.children.length, 1, "only one child for iframe");
+ let iframe2 = iframe1.children[0];
+ let iframeWindowGlobal2 = iframe2.currentWindowGlobal;
+
+ ok(topWindowGlobal1.isActiveInTab, "top window global is active in tab");
+ ok(iframeWindowGlobal1a.isActiveInTab, "topmost iframe is active in tab");
+ ok(iframeWindowGlobal2.isActiveInTab, "innermost iframe is active in tab");
+
+ // Do a same-origin navigation on the topmost iframe.
+ let iframe1bURI =
+ "https://example.com/browser/dom/ipc/tests/file_dummy.html";
+ let loadedIframe = BrowserTestUtils.browserLoaded(
+ browser,
+ true,
+ iframe1bURI
+ );
+ await SpecialPowers.spawn(
+ iframe1,
+ [iframe1bURI],
+ async function (_iframe1bURI) {
+ content.location = _iframe1bURI;
+ }
+ );
+ await loadedIframe;
+
+ ok(
+ topWindowGlobal1.isActiveInTab,
+ "top window global is still active in tab"
+ );
+
+ let iframeWindowGlobal1b = iframe1.currentWindowGlobal;
+ isnot(
+ iframeWindowGlobal1a,
+ iframeWindowGlobal1b,
+ "navigating changed the iframe's current window"
+ );
+
+ // This tests the !CanSend() case but unfortunately not the
+ // `bc->GetCurrentWindowGlobal() != this` case. Apparently the latter will
+ // only hold temporarily, so that is likely hard to test.
+ ok(
+ !iframeWindowGlobal1a.isActiveInTab,
+ "topmost iframe is not active in tab"
+ );
+
+ ok(iframeWindowGlobal1b.isActiveInTab, "new iframe is active in tab");
+
+ is(
+ iframe2.currentWindowGlobal,
+ iframeWindowGlobal2,
+ "innermost iframe current window global has not changed"
+ );
+
+ ok(
+ iframeWindowGlobal2.isCurrentGlobal,
+ "innermost iframe is still the current global for its BC"
+ );
+
+ // With a same-origin navigation, this hits the !bc->AncestorsAreCurrent()
+ // case. (With a cross-origin navigation, this hits the !CanSend() case.)
+ ok(
+ !iframeWindowGlobal2.isActiveInTab,
+ "innermost iframe is not active in tab"
+ );
+
+ // Load a new page into the tab to test the behavior when a page is in
+ // the BFCache.
+ let newTopURI = "https://example.com/browser/dom/ipc/tests/file_dummy.html";
+ let loadedTop2 = BrowserTestUtils.browserLoaded(browser, false, newTopURI);
+ await BrowserTestUtils.startLoadingURIString(browser, newTopURI);
+ await loadedTop2;
+
+ isnot(browser.browsingContext, topBC1, "Navigated to a new BC");
+
+ is(
+ topBC1.currentWindowGlobal,
+ topWindowGlobal1,
+ "old top window is still the current window global for the old BC"
+ );
+ ok(topWindowGlobal1.isInBFCache, "old top window's BC is in the BFCache");
+ ok(!topWindowGlobal1.isCurrentGlobal, "old top frame isn't current");
+ ok(!topWindowGlobal1.isActiveInTab, "old top frame not active in tab");
+
+ is(
+ iframe1.currentWindowGlobal,
+ iframeWindowGlobal1b,
+ "old iframe is still the current window global for the BC"
+ );
+ ok(!iframeWindowGlobal1b.isCurrentGlobal, "newer top iframe isn't current");
+ ok(
+ iframeWindowGlobal1b.isInBFCache,
+ "old top window's BC is in the BFCache"
+ );
+ ok(iframe1.ancestorsAreCurrent, "ancestors of iframe are current");
+ ok(
+ !iframeWindowGlobal1b.isActiveInTab,
+ "newer top iframe is active in not active in tab after top level navigation"
+ );
+ });
+});