Bug 1375833 - Part 3: Add test case. r?smaug draft
authorSamael Wang <freesamael@gmail.com>
Fri, 11 Aug 2017 18:30:49 +0800
changeset 647204 b4e171efb5be126461be78bdd3d1ae1a916a8dac
parent 645844 0b5fa59ef4b1a8ce4bc27ef1687ef1adbe83457a
child 649814 aa4606b181f647efcc295551ad5dc1aea43e6b5e
child 649817 fe1eb783520ff4dc7b8caeb6b88bcbdfe161a9b9
push id74319
push userbmo:sawang@mozilla.com
push dateWed, 16 Aug 2017 03:09:44 +0000
reviewerssmaug
bugs1375833
milestone57.0a1
Bug 1375833 - Part 3: Add test case. r?smaug MozReview-Commit-ID: L86sMEzfU4h
docshell/test/navigation/file_bug1375833-frame1.html
docshell/test/navigation/file_bug1375833-frame2.html
docshell/test/navigation/file_bug1375833.html
docshell/test/navigation/mochitest.ini
docshell/test/navigation/test_bug1375833.html
new file mode 100644
--- /dev/null
+++ b/docshell/test/navigation/file_bug1375833-frame1.html
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="utf-8">
+    <title>iframe test page 1</title>
+  </head>
+  <body>iframe test page 1</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/docshell/test/navigation/file_bug1375833-frame2.html
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="utf-8">
+    <title>iframe test page 2</title>
+  </head>
+  <body>iframe test page 2</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/docshell/test/navigation/file_bug1375833.html
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="utf-8">
+    <title>Test for bug 1375833</title>
+  </head>
+  <body onload="test();">
+    <iframe id="testFrame" src="file_bug1375833-frame1.html"></iframe>
+    <script type="application/javascript">
+    function test() {
+      let iframe = document.querySelector("#testFrame");
+      setTimeout(function() { iframe.src = "file_bug1375833-frame1.html"; }, 0);
+      iframe.onload = function(e) {
+        setTimeout(function() { iframe.src = "file_bug1375833-frame2.html"; }, 0);
+        iframe.onload = function() {
+          opener.postMessage(iframe.contentWindow.location.href, "*");
+        };
+      }
+    }
+    </script>
+  </body>
+</html>
--- a/docshell/test/navigation/mochitest.ini
+++ b/docshell/test/navigation/mochitest.ini
@@ -42,27 +42,31 @@ support-files =
   file_triggeringprincipal_iframe_iframe_window_open_frame_a_nav.html
   file_bug1300461.html
   file_bug1300461_redirect.html
   file_bug1300461_redirect.html^headers^
   file_bug1300461_back.html
   file_contentpolicy_block_window.html
   file_bug1326251.html
   file_bug1326251_evict_cache.html
+  file_bug1375833.html
+  file_bug1375833-frame1.html
+  file_bug1375833-frame2.html
 
 [test_bug13871.html]
 [test_bug270414.html]
 [test_bug278916.html]
 [test_bug279495.html]
 [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_bug1375833.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_bug1375833.html
@@ -0,0 +1,101 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1375833
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 1375833</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">
+
+  SimpleTest.waitForExplicitFinish();
+
+  /**
+   * Test for Bug 1375833. It tests for 2 things in a normal reload -
+   * 1. Static frame history should not be dropped.
+   * 2. In a reload, docshell would parse the reloaded root document and
+   *    genearate new child docshells, and then use the child offset
+   */
+
+  let testWin = window.open("file_bug1375833.html");
+  let count = 0;
+  let webNav, shistory;
+  let frameDocShellId;
+  window.addEventListener("message", e => {
+    switch (count++) {
+    case 0:
+      ok(e.data.endsWith("file_bug1375833-frame2.html"), "check location");
+
+      webNav = SpecialPowers.wrap(testWin)
+               .QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
+               .getInterface(SpecialPowers.Ci.nsIWebNavigation);
+      shistory = webNav.sessionHistory;
+      is(shistory.count, 2, "check history length");
+      is(shistory.index, 1, "check history index");
+
+      frameDocShellId = String(getFrameDocShell().historyID);
+      ok(frameDocShellId, "sanity check for docshell ID");
+
+      testWin.location.reload();
+      break;
+    case 1:
+      ok(e.data.endsWith("file_bug1375833-frame2.html"), "check location");
+      is(shistory.count, 4, "check history length");
+      is(shistory.index, 3, "check history index");
+
+      let newFrameDocShellId = String(getFrameDocShell().historyID);
+      ok(newFrameDocShellId, "sanity check for docshell ID");
+      is(newFrameDocShellId, frameDocShellId, "check docshell ID remains after reload");
+
+      let entry = shistory.getEntryAtIndex(shistory.index, false);
+      let frameEntry = SpecialPowers.wrap(entry)
+                       .QueryInterface(SpecialPowers.Ci.nsISHContainer)
+                       .GetChildAt(0);
+      is(String(frameEntry.docshellID), frameDocShellId, "check newly added shentry uses the same docshell ID");
+
+      webNav.goBack();
+      break;
+    case 2:
+      ok(e.data.endsWith("file_bug1375833-frame1.html"), "check location");
+      is(shistory.count, 4, "check history length");
+      is(shistory.index, 2, "check history index");
+
+      webNav.goBack();
+      break;
+    case 3:
+      ok(e.data.endsWith("file_bug1375833-frame2.html"), "check location");
+      is(shistory.count, 4, "check history length");
+      is(shistory.index, 1, "check history index");
+
+      webNav.goBack();
+      break;
+    case 4:
+      ok(e.data.endsWith("file_bug1375833-frame1.html"), "check location");
+      is(shistory.count, 4, "check history length");
+      is(shistory.index, 0, "check history index");
+
+      testWin.close();
+      SimpleTest.finish();
+    }
+  });
+
+  function getFrameDocShell() {
+    return SpecialPowers.wrap(testWin.window[0])
+           .QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
+           .getInterface(SpecialPowers.Ci.nsIDocShell)
+  }
+
+  </script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1375833">Mozilla Bug 1375833</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+</pre>
+</body>
+</html>