tor-browser

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

browser_580512.js (3211B)


      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 const URIS_PINNED = ["about:license", "about:about"];
      6 const URIS_NORMAL_A = ["about:mozilla"];
      7 const URIS_NORMAL_B = ["about:buildconfig"];
      8 
      9 function test() {
     10  waitForExplicitFinish();
     11 
     12  isnot(
     13    Services.prefs.getIntPref("browser.startup.page"),
     14    3,
     15    "pref to save session must not be set for this test"
     16  );
     17  ok(
     18    !Services.prefs.getBoolPref("browser.sessionstore.resume_session_once"),
     19    "pref to save session once must not be set for this test"
     20  );
     21 
     22  document.documentElement.setAttribute(
     23    "windowtype",
     24    "navigator:browsertestdummy"
     25  );
     26 
     27  openWinWithCb(closeFirstWin, URIS_PINNED.concat(URIS_NORMAL_A));
     28 }
     29 
     30 function closeFirstWin(win) {
     31  win.gBrowser.pinTab(win.gBrowser.tabs[0]);
     32  win.gBrowser.pinTab(win.gBrowser.tabs[1]);
     33 
     34  let winClosed = BrowserTestUtils.windowClosed(win);
     35  // We need to call BrowserCommands.tryToCloseWindow in order to trigger
     36  // the machinery that chooses whether or not to save the session
     37  // for the last window.
     38  win.BrowserCommands.tryToCloseWindow();
     39  ok(win.closed, "window closed");
     40 
     41  winClosed.then(() => {
     42    openWinWithCb(
     43      checkSecondWin,
     44      URIS_NORMAL_B,
     45      URIS_PINNED.concat(URIS_NORMAL_B)
     46    );
     47  });
     48 }
     49 
     50 function checkSecondWin(win) {
     51  is(
     52    win.gBrowser.browsers[0].currentURI.spec,
     53    URIS_PINNED[0],
     54    "first pinned tab restored"
     55  );
     56  is(
     57    win.gBrowser.browsers[1].currentURI.spec,
     58    URIS_PINNED[1],
     59    "second pinned tab restored"
     60  );
     61  ok(win.gBrowser.tabs[0].pinned, "first pinned tab is still pinned");
     62  ok(win.gBrowser.tabs[1].pinned, "second pinned tab is still pinned");
     63 
     64  BrowserTestUtils.closeWindow(win).then(() => {
     65    // cleanup
     66    document.documentElement.setAttribute("windowtype", "navigator:browser");
     67    finish();
     68  });
     69 }
     70 
     71 function openWinWithCb(cb, argURIs, expectedURIs) {
     72  if (!expectedURIs) {
     73    expectedURIs = argURIs;
     74  }
     75 
     76  var win = openDialog(
     77    AppConstants.BROWSER_CHROME_URL,
     78    "_blank",
     79    "chrome,all,dialog=no",
     80    argURIs.join("|")
     81  );
     82 
     83  win.addEventListener(
     84    "load",
     85    function () {
     86      info("the window loaded");
     87 
     88      var expectedLoads = expectedURIs.length;
     89 
     90      win.gBrowser.addTabsProgressListener({
     91        onStateChange(aBrowser, aWebProgress, aRequest, aStateFlags, _aStatus) {
     92          if (
     93            aRequest &&
     94            aStateFlags & Ci.nsIWebProgressListener.STATE_STOP &&
     95            aStateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK &&
     96            expectedURIs.indexOf(
     97              aRequest.QueryInterface(Ci.nsIChannel).originalURI.spec
     98            ) > -1 &&
     99            --expectedLoads <= 0
    100          ) {
    101            win.gBrowser.removeTabsProgressListener(this);
    102            info("all tabs loaded");
    103            is(
    104              win.gBrowser.tabs.length,
    105              expectedURIs.length,
    106              "didn't load any unexpected tabs"
    107            );
    108            executeSoon(function () {
    109              cb(win);
    110            });
    111          }
    112        },
    113      });
    114    },
    115    { once: true }
    116  );
    117 }