docshell/test/navigation/test_bug1375833.html
author Daisuke Akatsuka <dakatsuka@mozilla.com>
Tue, 26 Feb 2019 10:21:29 +0000
changeset 518943 383b6665578306219dd34b178353e100ca2848eb
parent 490498 f451bd99a45ea7f264ed112b07698499e05f318c
child 528457 c9c0c6f2eed54a187e124942e53c3660b4cf17d8
permissions -rw-r--r--
Bug 1525615: Introduce 'card' style. r=jdescottes,ladybenko Depends on D20295 Differential Revision: https://phabricator.services.mozilla.com/D20640

<!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)
               .docShell
               .QueryInterface(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.legacySHistory.getEntryAtIndex(shistory.index);
      let frameEntry = entry.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]).docShell;
  }

  </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>