tor-browser

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

browser_586147.js (1872B)


      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 observeOneRestore(callback) {
      6  let topic = "sessionstore-browser-state-restored";
      7  Services.obs.addObserver(function onRestore() {
      8    Services.obs.removeObserver(onRestore, topic);
      9    callback();
     10  }, topic);
     11 }
     12 
     13 function test() {
     14  waitForExplicitFinish();
     15 
     16  // There should be one tab when we start the test
     17  let [origTab] = gBrowser.visibleTabs;
     18  let hiddenTab = BrowserTestUtils.addTab(gBrowser);
     19 
     20  is(gBrowser.visibleTabs.length, 2, "should have 2 tabs before hiding");
     21  BrowserTestUtils.showOnlyTheseTabs(gBrowser, [origTab]);
     22  is(gBrowser.visibleTabs.length, 1, "only 1 after hiding");
     23  ok(hiddenTab.hidden, "sanity check that it's hidden");
     24 
     25  BrowserTestUtils.addTab(gBrowser);
     26  let state = ss.getBrowserState();
     27  let stateObj = JSON.parse(state);
     28  let tabs = stateObj.windows[0].tabs;
     29  is(tabs.length, 3, "just checking that browser state is correct");
     30  ok(!tabs[0].hidden, "first tab is visible");
     31  ok(tabs[1].hidden, "second is hidden");
     32  ok(!tabs[2].hidden, "third is visible");
     33 
     34  // Make the third tab hidden and then restore the modified state object
     35  tabs[2].hidden = true;
     36 
     37  observeOneRestore(function () {
     38    is(gBrowser.visibleTabs.length, 1, "only restored 1 visible tab");
     39    let restoredTabs = gBrowser.tabs;
     40 
     41    ok(!restoredTabs[0].hidden, "first is still visible");
     42    ok(restoredTabs[1].hidden, "second tab is still hidden");
     43    ok(restoredTabs[2].hidden, "third tab is now hidden");
     44 
     45    // Restore the original state and clean up now that we're done
     46    gBrowser.removeTab(gBrowser.tabs[1]);
     47    gBrowser.removeTab(gBrowser.tabs[1]);
     48 
     49    finish();
     50  });
     51  ss.setBrowserState(JSON.stringify(stateObj));
     52 }