tor-browser

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

bug215405_window.xhtml (6455B)


      1 <?xml version="1.0"?>
      2 
      3 <!-- This Source Code Form is subject to the terms of the Mozilla Public
      4   - License, v. 2.0. If a copy of the MPL was not distributed with this
      5   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
      6 
      7 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
      8 
      9 <window id="215405Test"
     10        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
     11        width="600"
     12        height="600"
     13        onload="onLoad();"
     14        title="215405 test">
     15 
     16  <script type="application/javascript"><![CDATA[
     17    const {BrowserTestUtils} = ChromeUtils.importESModule(
     18      "resource://testing-common/BrowserTestUtils.sys.mjs"
     19    );
     20    Services.prefs.setBoolPref("browser.navigation.requireUserInteraction", false);
     21 
     22    /* globals SimpleTest, is, isnot, ok */
     23    var imports = [ "SimpleTest", "is", "isnot", "ok"];
     24    for (var name of imports) {
     25      window[name] = window.arguments[0][name];
     26    }
     27 
     28    const text="MOZILLA";
     29    const nostoreURI = "http://mochi.test:8888/tests/docshell/test/chrome/" +
     30                       "215405_nostore.html";
     31    const nocacheURI = "https://example.com:443/tests/docshell/test/chrome/" +
     32                       "215405_nocache.html";
     33 
     34    var gBrowser;
     35    var gTestsIterator;
     36    var currScrollX = 0;
     37    var currScrollY = 0;
     38 
     39    function finish() {
     40      gBrowser.removeEventListener("pageshow", eventListener, true);
     41      // Work around bug 467960
     42      let historyPurged;
     43      if (SpecialPowers.Services.appinfo.sessionHistoryInParent) {
     44        let history = gBrowser.browsingContext.sessionHistory;
     45        history.purgeHistory(history.count);
     46        historyPurged = Promise.resolve();
     47      } else {
     48        historyPurged = SpecialPowers.spawn(gBrowser, [], () => {
     49          let history = docShell.QueryInterface(Ci.nsIWebNavigation).sessionHistory
     50            .legacySHistory;
     51          history.purgeHistory(history.count);
     52        });
     53      }
     54 
     55      historyPurged.then(_ => {
     56        window.close();
     57        window.arguments[0].SimpleTest.finish();
     58      });
     59    }
     60 
     61    function onLoad() {
     62      gBrowser = document.getElementById("content");
     63      gBrowser.addEventListener("pageshow", eventListener, true);
     64 
     65      gTestsIterator = testsIterator();
     66      nextTest();
     67    }
     68 
     69    function eventListener() {
     70      setTimeout(nextTest, 0);
     71    }
     72 
     73    function nextTest() {
     74      gTestsIterator.next();
     75    }
     76 
     77    function* testsIterator() {
     78      // No-store tests
     79      var testName = "[nostore]";
     80 
     81      // Load a page with a no-store header
     82      BrowserTestUtils.startLoadingURIString(gBrowser, nostoreURI);
     83      yield undefined;
     84 
     85 
     86      // Now that the page has loaded, amend the form contents
     87      var form = gBrowser.contentDocument.getElementById("inp");
     88      form.value = text;
     89 
     90      // Attempt to scroll the page
     91      var originalXPosition = gBrowser.contentWindow.scrollX;
     92      var originalYPosition = gBrowser.contentWindow.scrollY;
     93      var scrollToX = gBrowser.contentWindow.scrollMaxX;
     94      var scrollToY = gBrowser.contentWindow.scrollMaxY;
     95      gBrowser.contentWindow.scrollBy(scrollToX, scrollToY);
     96 
     97      // Save the scroll position for future comparison
     98      currScrollX = gBrowser.contentWindow.scrollX;
     99      currScrollY = gBrowser.contentWindow.scrollY;
    100      isnot(currScrollX, originalXPosition,
    101            testName + " failed to scroll window horizontally");
    102      isnot(currScrollY, originalYPosition,
    103            testName + " failed to scroll window vertically");
    104 
    105      // Load a new document into the browser
    106      var simple = "data:text/html,<html><head><title>test2</title></head>" +
    107                     "<body>test2</body></html>";
    108      BrowserTestUtils.startLoadingURIString(gBrowser, simple);
    109      yield undefined;
    110 
    111 
    112      // Now go back in history. First page should not have been cached.
    113      gBrowser.goBack();
    114      yield undefined;
    115 
    116 
    117      // First uncacheable page will now be reloaded. Check scroll position
    118      // restored, and form contents not
    119      is(gBrowser.contentWindow.scrollX, currScrollX, testName +
    120         " horizontal axis scroll position not correctly restored");
    121      is(gBrowser.contentWindow.scrollY, currScrollY, testName +
    122         " vertical axis scroll position not correctly restored");
    123      var formValue = gBrowser.contentDocument.getElementById("inp").value;
    124      isnot(formValue, text, testName + " form value incorrectly restored");
    125 
    126 
    127      // https no-cache
    128      testName = "[nocache]";
    129 
    130      // Load a page with a no-cache header. This should not be
    131      // restricted like no-store (bug 567365)
    132      BrowserTestUtils.startLoadingURIString(gBrowser, nocacheURI);
    133      yield undefined;
    134 
    135 
    136      // Now that the page has loaded, amend the form contents
    137      form = gBrowser.contentDocument.getElementById("inp");
    138      form.value = text;
    139 
    140      // Attempt to scroll the page
    141      originalXPosition = gBrowser.contentWindow.scrollX;
    142      originalYPosition = gBrowser.contentWindow.scrollY;
    143      scrollToX = gBrowser.contentWindow.scrollMaxX;
    144      scrollToY = gBrowser.contentWindow.scrollMaxY;
    145      gBrowser.contentWindow.scrollBy(scrollToX, scrollToY);
    146 
    147      // Save the scroll position for future comparison
    148      currScrollX = gBrowser.contentWindow.scrollX;
    149      currScrollY = gBrowser.contentWindow.scrollY;
    150      isnot(currScrollX, originalXPosition,
    151            testName + " failed to scroll window horizontally");
    152      isnot(currScrollY, originalYPosition,
    153            testName + " failed to scroll window vertically");
    154 
    155      BrowserTestUtils.startLoadingURIString(gBrowser, simple);
    156      yield undefined;
    157 
    158 
    159      // Now go back in history to the cached page.
    160      gBrowser.goBack();
    161      yield undefined;
    162 
    163 
    164      // First page will now be reloaded. Check scroll position
    165      // and form contents are restored
    166      is(gBrowser.contentWindow.scrollX, currScrollX, testName +
    167         " horizontal axis scroll position not correctly restored");
    168      is(gBrowser.contentWindow.scrollY, currScrollY, testName +
    169         " vertical axis scroll position not correctly restored");
    170      formValue = gBrowser.contentDocument.getElementById("inp").value;
    171      is(formValue, text, testName + " form value not correctly restored");
    172 
    173      Services.prefs.clearUserPref("browser.navigation.requireUserInteraction");
    174      finish();
    175    }
    176  ]]></script>
    177 
    178  <browser type="content" primary="true" flex="1" id="content" src="about:blank"/>
    179 </window>