summaryrefslogtreecommitdiffstats
path: root/dom/base/test/browser_messagemanager_unload.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /dom/base/test/browser_messagemanager_unload.js
parentInitial commit. (diff)
downloadfirefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz
firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/base/test/browser_messagemanager_unload.js')
-rw-r--r--dom/base/test/browser_messagemanager_unload.js135
1 files changed, 135 insertions, 0 deletions
diff --git a/dom/base/test/browser_messagemanager_unload.js b/dom/base/test/browser_messagemanager_unload.js
new file mode 100644
index 0000000000..d4d42a9447
--- /dev/null
+++ b/dom/base/test/browser_messagemanager_unload.js
@@ -0,0 +1,135 @@
+function frameScript() {
+ const { Services } = ChromeUtils.import(
+ "resource://gre/modules/Services.jsm"
+ );
+
+ function eventHandler(e) {
+ if (!docShell) {
+ sendAsyncMessage("Test:Fail", "docShell is null");
+ }
+
+ sendAsyncMessage("Test:Event", [
+ e.type,
+ e.target === content.document,
+ e.eventPhase,
+ ]);
+ }
+
+ let outerID = content.docShell.outerWindowID;
+ function onOuterWindowDestroyed(subject, topic, data) {
+ if (docShell) {
+ sendAsyncMessage("Test:Fail", "docShell is non-null");
+ }
+
+ let id = subject.QueryInterface(Ci.nsISupportsPRUint64).data;
+ sendAsyncMessage("Test:Event", ["outer-window-destroyed", id == outerID]);
+ if (id == outerID) {
+ Services.obs.removeObserver(
+ onOuterWindowDestroyed,
+ "outer-window-destroyed"
+ );
+ }
+ }
+
+ let url =
+ "https://example.com/browser/dom/base/test/file_messagemanager_unload.html";
+
+ content.location = url;
+ addEventListener(
+ "load",
+ e => {
+ if (e.target.location != url) {
+ return;
+ }
+
+ addEventListener("unload", eventHandler, false);
+ addEventListener("unload", eventHandler, true);
+ addEventListener("pagehide", eventHandler, false);
+ addEventListener("pagehide", eventHandler, true);
+ Services.obs.addObserver(
+ onOuterWindowDestroyed,
+ "outer-window-destroyed"
+ );
+
+ sendAsyncMessage("Test:Ready");
+ },
+ true
+ );
+}
+
+const EXPECTED = [
+ // Unload events on the BrowserChildGlobal. These come first so that the
+ // docshell is available.
+ ["unload", false, 2],
+ ["unload", false, 2],
+
+ // pagehide and unload events for the top-level page.
+ ["pagehide", true, 1],
+ ["pagehide", true, 3],
+ ["unload", true, 1],
+
+ // pagehide and unload events for the iframe.
+ ["pagehide", false, 1],
+ ["pagehide", false, 3],
+ ["unload", false, 1],
+
+ // outer-window-destroyed for both pages.
+ ["outer-window-destroyed", false],
+ ["outer-window-destroyed", true],
+];
+
+function test() {
+ waitForExplicitFinish();
+
+ var newTab = BrowserTestUtils.addTab(gBrowser, "about:blank");
+ gBrowser.selectedTab = newTab;
+
+ let browser = newTab.linkedBrowser;
+ let frameLoader = browser.frameLoader;
+ ok(frameLoader !== null, "frameLoader looks okay");
+
+ browser.messageManager.loadFrameScript(
+ "data:,(" + frameScript.toString() + ")()",
+ false
+ );
+
+ browser.messageManager.addMessageListener(
+ "Test:Fail",
+ msg => {
+ ok(false, msg.data);
+ },
+ true
+ );
+
+ let index = 0;
+ browser.messageManager.addMessageListener(
+ "Test:Event",
+ msg => {
+ ok(msg.target === browser, "<browser> is correct");
+ ok(msg.targetFrameLoader === frameLoader, "frameLoader is correct");
+ ok(
+ browser.frameLoader === null,
+ "browser frameloader null during teardown"
+ );
+
+ info(JSON.stringify(msg.data));
+
+ is(
+ JSON.stringify(msg.data),
+ JSON.stringify(EXPECTED[index]),
+ "results match"
+ );
+ index++;
+
+ if (index == EXPECTED.length) {
+ finish();
+ }
+ },
+ true
+ );
+
+ browser.messageManager.addMessageListener("Test:Ready", () => {
+ info("Got ready message");
+ gBrowser.removeCurrentTab();
+ });
+}