summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/general/historyframes.html
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/general/historyframes.html
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/general/historyframes.html')
-rw-r--r--dom/tests/mochitest/general/historyframes.html179
1 files changed, 179 insertions, 0 deletions
diff --git a/dom/tests/mochitest/general/historyframes.html b/dom/tests/mochitest/general/historyframes.html
new file mode 100644
index 0000000000..f0f7e934ae
--- /dev/null
+++ b/dom/tests/mochitest/general/historyframes.html
@@ -0,0 +1,179 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=602256
+-->
+<head>
+ <title>Test for Bug 602256</title>
+</head>
+<body onload="SimpleTest.executeSoon(run_test)">
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=602256">Mozilla Bug 602256</a>
+<div id="content">
+ <iframe id="iframe" src="start_historyframe.html"></iframe>
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 602256 **/
+
+var testWin = window.opener ? window.opener : window.parent;
+
+var SimpleTest = testWin.SimpleTest;
+function is() { testWin.is.apply(testWin, arguments); }
+
+var gFrame = null;
+
+var gState = null;
+
+window.addEventListener("popstate", function(aEvent) {
+ gState = aEvent.state;
+});
+
+function waitForLoad() {
+ function listener() {
+ gFrame.removeEventListener("load", listener);
+ SimpleTest.executeSoon(continue_test);
+ }
+
+ gFrame.addEventListener("load", listener);
+}
+
+function loadContent(aURL) {
+ waitForLoad();
+
+ gFrame.src = aURL;
+}
+
+function getURL() {
+ return gFrame.contentDocument.documentURI;
+}
+
+function getContent() {
+ return gFrame.contentDocument.getElementById("text").textContent;
+}
+
+var BASE_URI = "http://mochi.test:8888/tests/dom/tests/mochitest/general/";
+var START = BASE_URI + "start_historyframe.html";
+var URL1 = BASE_URI + "url1_historyframe.html";
+var URL2 = BASE_URI + "url2_historyframe.html";
+
+function run_test() {
+ window.history.pushState("START", window.location);
+
+ gFrame = document.getElementById("iframe");
+
+ continue_test();
+}
+
+function* test_body()
+{
+ yield* test_basic_inner_navigation();
+ yield* test_state_navigation();
+}
+
+var gTestContinuation = null;
+
+function continue_test() {
+ if (!gTestContinuation) {
+ gTestContinuation = test_body();
+ }
+ var ret = gTestContinuation.next();
+ if (ret.done) {
+ testWin.done();
+ }
+}
+
+var gTestContinuation = null;
+function continueAsync() {
+ setTimeout(function() { gTestContinuation.next(); })
+}
+
+function continueOnPopState() {
+ // Use continueAsync to avoid recursion within sync popstate listener.
+ window.addEventListener("popstate", continueAsync, { once: true });
+}
+
+function* test_basic_inner_navigation() {
+ // Navigate the inner frame a few times
+ yield loadContent(URL1);
+ is(getURL(), URL1, "URL should be correct");
+ is(getContent(), "Test1", "Page should be correct");
+
+ yield loadContent(URL2);
+
+ is(getURL(), URL2, "URL should be correct");
+ is(getContent(), "Test2", "Page should be correct");
+
+ // Test that history is working
+ window.history.back();
+ yield waitForLoad();
+ is(getURL(), URL1, "URL should be correct");
+ is(getContent(), "Test1", "Page should be correct");
+
+ window.history.forward();
+ yield waitForLoad();
+ is(getURL(), URL2, "URL should be correct");
+ is(getContent(), "Test2", "Page should be correct");
+}
+
+function* test_state_navigation() {
+ window.history.pushState("STATE1", window.location);
+
+ is(getURL(), URL2, "URL should be correct");
+ is(getContent(), "Test2", "Page should be correct");
+
+ window.history.pushState("STATE2", window.location);
+
+ is(getURL(), URL2, "URL should be correct");
+ is(getContent(), "Test2", "Page should be correct");
+
+ window.history.back();
+ continueOnPopState();
+ yield;
+
+ is(gState, "STATE1", "State should be correct");
+ is(getURL(), URL2, "URL should be correct");
+ is(getContent(), "Test2", "Page should be correct");
+
+ window.history.forward();
+ continueOnPopState();
+ yield;
+
+ is(gState, "STATE2", "State should be correct");
+ is(getURL(), URL2, "URL should be correct");
+ is(getContent(), "Test2", "Page should be correct");
+
+ window.history.back();
+ continueOnPopState();
+ yield;
+ window.history.back();
+ continueOnPopState();
+ yield;
+
+ is(gState, "START", "State should be correct");
+ is(getURL(), URL2, "URL should be correct");
+ is(getContent(), "Test2", "Page should be correct");
+
+ window.history.back();
+ continueAsync();
+ yield;
+ is(gState, "START", "State should be correct");
+ yield waitForLoad();
+
+ is(getURL(), URL1, "URL should be correct");
+ is(getContent(), "Test1", "Page should be correct");
+
+ window.history.back();
+ continueAsync();
+ yield;
+ is(gState, "START", "State should be correct after going back twice");
+ yield waitForLoad();
+
+ is(gState, "START", "State should be correct");
+ is(getURL(), START, "URL should be correct");
+ is(getContent(), "Start", "Page should be correct");
+}
+</script>
+</pre>
+</body>
+</html>