Bug 1314912 - Part 2: Add a few test cases. r?bz draft
authorSamael Wang <freesamael@gmail.com>
Wed, 06 Dec 2017 19:05:27 +0800
changeset 708810 f98c381819a9fb6314b557f806e48462400743be
parent 708781 4ad2959899240b97b38a78b6b6371dced7a0d5c6
child 743253 c2f6f43e8ccdab82d81f291b69447af65dcd635b
push id92455
push userbmo:sawang@mozilla.com
push dateThu, 07 Dec 2017 06:58:38 +0000
reviewersbz
bugs1314912
milestone59.0a1
Bug 1314912 - Part 2: Add a few test cases. r?bz MozReview-Commit-ID: KX3ILhY8Fpy
docshell/test/navigation/mochitest.ini
docshell/test/navigation/test_bug1314912_back_forward.html
docshell/test/navigation/test_bug1314912_hash_change.html
docshell/test/navigation/test_bug1314912_pushState.html
--- a/docshell/test/navigation/mochitest.ini
+++ b/docshell/test/navigation/mochitest.ini
@@ -62,16 +62,19 @@ support-files =
 [test_bug344861.html]
 skip-if = toolkit == "android" || toolkit == "windows" # disabled on Windows because of bug 1234520
 [test_bug386782.html]
 [test_bug430624.html]
 [test_bug430723.html]
 skip-if = (toolkit == 'android') || (!debug && (os == 'mac' || os == 'win')) # Bug 874423
 [test_bug1364364.html]
 [test_bug1375833.html]
+[test_bug1314912_pushState.html]
+[test_bug1314912_hash_change.html]
+[test_bug1314912_back_forward.html]
 [test_child.html]
 [test_grandchild.html]
 [test_not-opener.html]
 [test_opener.html]
 [test_popup-navigates-children.html]
 [test_reserved.html]
 skip-if = (toolkit == 'android') || (debug && e10s) #too slow on Android 4.3 aws only; bug 1030403; bug 1263213 for debug e10s
 [test_sessionhistory.html]
new file mode 100644
--- /dev/null
+++ b/docshell/test/navigation/test_bug1314912_back_forward.html
@@ -0,0 +1,67 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1314912
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 1314912</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="application/javascript">
+
+  /** Test for Bug 1314912 **/
+  SimpleTest.waitForExplicitFinish();
+
+  async function setup() {
+    await SpecialPowers.pushPrefEnv({set: [
+      ["dom.navigation.same_doc.limit", 90],
+      ["dom.navigation.same_doc.limit.timespan", 3]]});
+  }
+
+  let hasSetup = false;
+  let hasRepeated = false;
+  async function test() {
+    if (!hasSetup) {
+      await setup();
+      hasSetup = true;
+    }
+
+    // Call pushState, history.back, history.forward 30 times, respectively.
+    let ref = "ref";
+    for (let i = 0; i < 30; i++) {
+      history.pushState(null, "test", location.href + "#" + ref);
+      ref += i;
+    }
+    for (let i = 0; i < 30; i++) {
+      history.back();
+    }
+    for (let i = 0; i < 30; i++) {
+      history.forward();
+    }
+
+    // The next history navigation should throw.
+    SimpleTest.doesThrow(
+      () => history.back(), "check history.back does throw");
+
+    if (hasRepeated) {
+      // Repeat the test again after 5 seconds.
+      setTimeout(test, 5000);
+      hasRepeated = true;
+    } else {
+      SimpleTest.finish();
+    }
+  }
+
+  </script>
+</head>
+<body onload="setTimeout(test, 0);">
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1314912">Mozilla Bug 1314912</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+</pre>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/docshell/test/navigation/test_bug1314912_hash_change.html
@@ -0,0 +1,62 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1314912
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 1314912</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="application/javascript">
+
+  /** Test for Bug 1314912 **/
+  SimpleTest.waitForExplicitFinish();
+
+  async function setup() {
+    await SpecialPowers.pushPrefEnv({set: [
+      ["dom.navigation.same_doc.limit", 100],
+      ["dom.navigation.same_doc.limit.timespan", 3]]});
+  }
+
+  let hasSetup = false;
+  let hasRepeated = false;
+  async function test() {
+    if (!hasSetup) {
+      await setup();
+      hasSetup = true;
+    }
+
+    // Change hash 100 times in a short time.
+    let ref = "ref";
+    for (let i = 0; i < 100; i++) {
+      location.hash = ref;
+      ref += i;
+    }
+
+    // The next hash change should throw.
+    SimpleTest.doesThrow(
+      () => location.hash = ref,
+      "check setting location.hash does throw");
+
+    if (hasRepeated) {
+      // Repeat the test again after 5 seconds.
+      setTimeout(test, 5000);
+      hasRepeated = true;
+    } else {
+      SimpleTest.finish();
+    }
+  }
+
+  </script>
+</head>
+<body onload="setTimeout(test, 0);">
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1314912">Mozilla Bug 1314912</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+</pre>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/docshell/test/navigation/test_bug1314912_pushState.html
@@ -0,0 +1,62 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1314912
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 1314912</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="application/javascript">
+
+  /** Test for Bug 1314912 **/
+  SimpleTest.waitForExplicitFinish();
+
+  async function setup() {
+    await SpecialPowers.pushPrefEnv({set: [
+      ["dom.navigation.same_doc.limit", 100],
+      ["dom.navigation.same_doc.limit.timespan", 3]]});
+  }
+
+  let hasSetup = false;
+  let hasRepeated = false;
+  async function test() {
+    if (!hasSetup) {
+      await setup();
+      hasSetup = true;
+    }
+
+    // Push 100 states in a short time.
+    let ref = "ref";
+    for (let i = 0; i < 100; i++) {
+      history.pushState(null, "test", location.href + "#" + ref);
+      ref += i;
+    }
+
+    // The next pushState should throw.
+    SimpleTest.doesThrow(
+      () => history.pushState(null, "test", location.href + "#" + ref),
+      "check history.pushState does throw");
+
+    if (hasRepeated) {
+      // Repeat the test again after 5 seconds.
+      setTimeout(test, 5000);
+      hasRepeated = true;
+    } else {
+      SimpleTest.finish();
+    }
+  }
+
+  </script>
+</head>
+<body onload="setTimeout(test, 0);">
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1314912">Mozilla Bug 1314912</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+</pre>
+</body>
+</html>