tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_bug1375833.html (4708B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1375833
      5 -->
      6 <head>
      7  <meta charset="utf-8">
      8  <title>Test for Bug 1375833</title>
      9  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     11  <script type="application/javascript">
     12 
     13    SimpleTest.waitForExplicitFinish();
     14 
     15    /**
     16     * Test for Bug 1375833. It tests for 2 things in a normal reload -
     17     * 1. Static frame history should not be dropped.
     18     * 2. In a reload, docshell would parse the reloaded root document and
     19     *    genearate new child docshells, and then use the child offset
     20     */
     21 
     22    let testWin = window.open("file_bug1375833.html");
     23    let count = 0;
     24    let webNav, shistory;
     25    let frameDocShellId;
     26    let chromeScript = null;
     27    if (SpecialPowers.Services.appinfo.sessionHistoryInParent) {
     28      chromeScript = SpecialPowers.loadChromeScript(() => {
     29        /* eslint-env mozilla/chrome-script */
     30        function doSend(message, fn) {
     31          try {
     32            sendAsyncMessage(message, {success: true, value: fn()});
     33          } catch(_) {
     34            sendAsyncMessage(message, {success: false});
     35          }
     36        }
     37 
     38        addMessageListener("test1", id => {
     39          doSend("test1", () => {
     40            let sessionHistory = BrowsingContext.get(id).top.sessionHistory;
     41            let entry = sessionHistory.getEntryAtIndex(sessionHistory.index);
     42            let frameEntry = entry.GetChildAt(0);
     43            return String(frameEntry.docshellID);
     44          })
     45        });
     46      });
     47    }
     48 
     49    window.addEventListener("message", async e => {
     50      switch (count++) {
     51        case 0:
     52          ok(e.data.endsWith("file_bug1375833-frame2.html"), "check location");
     53 
     54          webNav = SpecialPowers.wrap(testWin)
     55                                .docShell
     56                                .QueryInterface(SpecialPowers.Ci.nsIWebNavigation);
     57          shistory = webNav.sessionHistory;
     58          is(shistory.count, 2, "check history length");
     59          is(shistory.index, 1, "check history index");
     60 
     61          frameDocShellId = String(getFrameDocShell().historyID);
     62          ok(frameDocShellId, "sanity check for docshell ID");
     63 
     64          testWin.location.reload();
     65          break;
     66        case 1: {
     67          ok(e.data.endsWith("file_bug1375833-frame2.html"), "check location");
     68          is(shistory.count, 4, "check history length");
     69          is(shistory.index, 3, "check history index");
     70 
     71          let newFrameDocShellId = String(getFrameDocShell().historyID);
     72          ok(newFrameDocShellId, "sanity check for docshell ID");
     73          is(newFrameDocShellId, frameDocShellId, "check docshell ID remains after reload");
     74 
     75          if (!SpecialPowers.Services.appinfo.sessionHistoryInParent) {
     76            let entry = shistory.legacySHistory.getEntryAtIndex(shistory.index);
     77            let frameEntry = entry.GetChildAt(0);
     78            is(String(frameEntry.docshellID), frameDocShellId, "check newly added shentry uses the same docshell ID");
     79          } else {
     80            let p = chromeScript.promiseOneMessage("test1");
     81            chromeScript.sendAsyncMessage("test1", SpecialPowers.wrap(testWin).browsingContext.id);
     82            let result = await p;
     83            ok(result.success, "legacySHistory worked around ok");
     84            is(result.value, frameDocShellId, "check newly added shentry uses the same docshell ID");
     85          }
     86 
     87          webNav.goBack();
     88          break;
     89        }
     90        case 2:
     91          ok(e.data.endsWith("file_bug1375833-frame1.html"), "check location");
     92          is(shistory.count, 4, "check history length");
     93          is(shistory.index, 2, "check history index");
     94 
     95          webNav.goBack();
     96          break;
     97        case 3:
     98          ok(e.data.endsWith("file_bug1375833-frame2.html"), "check location");
     99          is(shistory.count, 4, "check history length");
    100          is(shistory.index, 1, "check history index");
    101 
    102          webNav.goBack();
    103          break;
    104        case 4:
    105          ok(e.data.endsWith("file_bug1375833-frame1.html"), "check location");
    106          is(shistory.count, 4, "check history length");
    107          is(shistory.index, 0, "check history index");
    108 
    109          if (chromeScript) {
    110            chromeScript.destroy();
    111          }
    112          testWin.close();
    113          SimpleTest.finish();
    114      }
    115    });
    116 
    117    function getFrameDocShell() {
    118      return SpecialPowers.wrap(testWin.window[0]).docShell;
    119    }
    120 
    121  </script>
    122 </head>
    123 <body>
    124 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1375833">Mozilla Bug 1375833</a>
    125 <p id="display"></p>
    126 <div id="content" style="display: none">
    127 
    128 </div>
    129 <pre id="test">
    130 </pre>
    131 </body>
    132 </html>