summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/chrome/test_docshell_swap.xhtml
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 /dom/tests/mochitest/chrome/test_docshell_swap.xhtml
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 'dom/tests/mochitest/chrome/test_docshell_swap.xhtml')
-rw-r--r--dom/tests/mochitest/chrome/test_docshell_swap.xhtml71
1 files changed, 71 insertions, 0 deletions
diff --git a/dom/tests/mochitest/chrome/test_docshell_swap.xhtml b/dom/tests/mochitest/chrome/test_docshell_swap.xhtml
new file mode 100644
index 0000000000..15542cab4c
--- /dev/null
+++ b/dom/tests/mochitest/chrome/test_docshell_swap.xhtml
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
+<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
+<window title="Docshell swap test"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+ <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+
+ <!-- test results are displayed in the html:body -->
+ <body xmlns="http://www.w3.org/1999/xhtml">
+
+ </body>
+
+ <!-- test code goes here -->
+ <script type="application/javascript">
+ <![CDATA[
+
+ SimpleTest.waitForExplicitFinish();
+
+ // Create two identical windows, each with a <browser> element.
+ let win1 = window.browsingContext.topChromeWindow.openDialog("window_docshell_swap.xhtml", "_blank","chrome,width=300,height=200");
+ let win2 = window.browsingContext.topChromeWindow.openDialog("window_docshell_swap.xhtml", "_blank","chrome,width=300,height=200");
+
+ let loadCount = 0;
+ function loadHandler() {
+ loadCount++;
+ if (loadCount < 2)
+ return;
+
+ let browser1 = win1.document.getElementById("browser");
+ let browser2 = win2.document.getElementById("browser");
+
+ let pongCount = 0;
+
+ function gotPong(target_ok) {
+ pongCount++;
+ ok(target_ok, "message went to correct target");
+ if (pongCount == 1) {
+ win1.close();
+ win2.close();
+ SimpleTest.finish();
+ }
+ }
+
+ let mm1 = browser1.frameLoader.messageManager;
+ let mm2 = browser2.frameLoader.messageManager;
+
+ // Swap docshells. Everything should be identical to before, since there was nothing to
+ // distinguish these docshells.
+ browser1.swapFrameLoaders(browser2);
+
+ // mm1 shouldn't change here, but we update it in case it does due to a bug.
+ mm1 = browser1.frameLoader.messageManager;
+
+ // Load ping-pong code into first window.
+ mm1.loadFrameScript("data:,addMessageListener('ping', () => sendAsyncMessage('pong'));", false);
+
+ // A pong message received in win1 means success.
+ win1.messageManager.addMessageListener("pong", () => { gotPong(true); });
+
+ // A pong message received in win2 means failure!
+ win2.messageManager.addMessageListener("pong", () => { gotPong(false); });
+
+ // Send the ping to win1.
+ mm1.sendAsyncMessage("ping");
+ }
+
+ win1.addEventListener("load", loadHandler);
+ win2.addEventListener("load", loadHandler);
+ ]]>
+ </script>
+</window>