tor-browser

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

browser_447951.js (2864B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 function test() {
      6  /** Test for Bug 447951 */
      7 
      8  waitForExplicitFinish();
      9  const baseURL =
     10    "http://mochi.test:8888/browser/" +
     11    "browser/components/sessionstore/test/browser_447951_sample.html#";
     12 
     13  // Make sure the functionality added in bug 943339 doesn't affect the results
     14  Services.prefs.setIntPref("browser.sessionstore.max_serialize_back", -1);
     15  Services.prefs.setIntPref("browser.sessionstore.max_serialize_forward", -1);
     16  registerCleanupFunction(function () {
     17    Services.prefs.clearUserPref("browser.sessionstore.max_serialize_back");
     18    Services.prefs.clearUserPref("browser.sessionstore.max_serialize_forward");
     19  });
     20 
     21  let tab = BrowserTestUtils.addTab(gBrowser);
     22  BrowserTestUtils.browserLoaded(tab.linkedBrowser, {
     23    wantLoad: "about:blank",
     24  }).then(() => {
     25    let tabState = { entries: [] };
     26    let max_entries = Services.prefs.getIntPref(
     27      "browser.sessionhistory.max_entries"
     28    );
     29    for (let i = 0; i < max_entries; i++) {
     30      tabState.entries.push({ url: baseURL + i, triggeringPrincipal_base64 });
     31    }
     32 
     33    promiseTabState(tab, tabState)
     34      .then(() => {
     35        return TabStateFlusher.flush(tab.linkedBrowser);
     36      })
     37      .then(() => {
     38        tabState = JSON.parse(ss.getTabState(tab));
     39        is(
     40          tabState.entries.length,
     41          max_entries,
     42          "session history filled to the limit"
     43        );
     44        is(tabState.entries[0].url, baseURL + 0, "... but not more");
     45 
     46        // visit yet another anchor (appending it to session history)
     47        SpecialPowers.spawn(tab.linkedBrowser, [], function () {
     48          content.window.document.querySelector("a").click();
     49        }).then(flushAndCheck);
     50 
     51        function flushAndCheck() {
     52          TabStateFlusher.flush(tab.linkedBrowser).then(check);
     53        }
     54 
     55        function check() {
     56          tabState = JSON.parse(ss.getTabState(tab));
     57          if (tab.linkedBrowser.currentURI.spec != baseURL + "end") {
     58            // It may take a few passes through the event loop before we
     59            // get the right URL.
     60            executeSoon(flushAndCheck);
     61            return;
     62          }
     63 
     64          is(
     65            tab.linkedBrowser.currentURI.spec,
     66            baseURL + "end",
     67            "the new anchor was loaded"
     68          );
     69          is(
     70            tabState.entries[tabState.entries.length - 1].url,
     71            baseURL + "end",
     72            "... and ignored"
     73          );
     74          is(
     75            tabState.entries[0].url,
     76            baseURL + 1,
     77            "... and the first item was removed"
     78          );
     79 
     80          // clean up
     81          gBrowser.removeTab(tab);
     82          finish();
     83        }
     84      });
     85  });
     86 }