tor-browser

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

browser_600545.js (3652B)


      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 requestLongerTimeout(2);
      6 
      7 var stateBackup = JSON.parse(ss.getBrowserState());
      8 
      9 function test() {
     10  /** Test for Bug 600545 */
     11  waitForExplicitFinish();
     12  testBug600545();
     13 }
     14 
     15 function testBug600545() {
     16  // Set the pref to false to cause non-app tabs to be stripped out on a save
     17  Services.prefs.setBoolPref("browser.sessionstore.resume_from_crash", false);
     18  Services.prefs.setIntPref("browser.sessionstore.interval", 2000);
     19 
     20  registerCleanupFunction(function () {
     21    Services.prefs.clearUserPref("browser.sessionstore.resume_from_crash");
     22    Services.prefs.clearUserPref("browser.sessionstore.interval");
     23  });
     24 
     25  // This tests the following use case: When multiple windows are open
     26  // and browser.sessionstore.resume_from_crash preference is false,
     27  // tab session data for non-active window is stripped for non-pinned
     28  // tabs.  This occurs after "sessionstore-state-write-complete"
     29  // fires which will only fire in this case if there is at least one
     30  // pinned tab.
     31  let state = {
     32    windows: [
     33      {
     34        tabs: [
     35          {
     36            entries: [
     37              { url: "http://example.org#0", triggeringPrincipal_base64 },
     38            ],
     39            pinned: true,
     40          },
     41          {
     42            entries: [
     43              { url: "http://example.com#1", triggeringPrincipal_base64 },
     44            ],
     45          },
     46          {
     47            entries: [
     48              { url: "http://example.com#2", triggeringPrincipal_base64 },
     49            ],
     50          },
     51        ],
     52        selected: 2,
     53      },
     54      {
     55        tabs: [
     56          {
     57            entries: [
     58              { url: "http://example.com#3", triggeringPrincipal_base64 },
     59            ],
     60          },
     61          {
     62            entries: [
     63              { url: "http://example.com#4", triggeringPrincipal_base64 },
     64            ],
     65          },
     66          {
     67            entries: [
     68              { url: "http://example.com#5", triggeringPrincipal_base64 },
     69            ],
     70          },
     71          {
     72            entries: [
     73              { url: "http://example.com#6", triggeringPrincipal_base64 },
     74            ],
     75          },
     76        ],
     77        selected: 3,
     78      },
     79    ],
     80  };
     81 
     82  waitForBrowserState(state, function () {
     83    // Need to wait for SessionStore's saveState function to be called
     84    // so that non-pinned tabs will be stripped from non-active window
     85    waitForSaveState(function () {
     86      let expectedNumberOfTabs = getStateTabCount(state);
     87      let retrievedState = JSON.parse(ss.getBrowserState());
     88      let actualNumberOfTabs = getStateTabCount(retrievedState);
     89 
     90      is(
     91        actualNumberOfTabs,
     92        expectedNumberOfTabs,
     93        "Number of tabs in retreived session data, matches number of tabs set."
     94      );
     95 
     96      done();
     97    });
     98  });
     99 }
    100 
    101 function done() {
    102  // Enumerate windows and close everything but our primary window. We can't
    103  // use waitForFocus() because apparently it's buggy. See bug 599253.
    104  let closeWinPromises = [];
    105  for (let currentWindow of Services.wm.getEnumerator("navigator:browser")) {
    106    if (currentWindow != window) {
    107      closeWinPromises.push(BrowserTestUtils.closeWindow(currentWindow));
    108    }
    109  }
    110 
    111  Promise.all(closeWinPromises).then(() => {
    112    waitForBrowserState(stateBackup, finish);
    113  });
    114 }
    115 
    116 // Count up the number of tabs in the state data
    117 function getStateTabCount(aState) {
    118  let tabCount = 0;
    119  for (let i in aState.windows) {
    120    tabCount += aState.windows[i].tabs.length;
    121  }
    122  return tabCount;
    123 }