tor-browser

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

browser_607016.js (5071B)


      1 "use strict";
      2 
      3 var stateBackup = ss.getBrowserState();
      4 
      5 add_task(async function () {
      6  /** Bug 607016 - If a tab is never restored, attributes (eg. hidden) aren't updated correctly */
      7  ignoreAllUncaughtExceptions();
      8 
      9  // Set the pref to true so we know exactly how many tabs should be restoring at
     10  // any given time. This guarantees that a finishing load won't start another.
     11  Services.prefs.setBoolPref("browser.sessionstore.restore_on_demand", true);
     12  // Don't restore tabs lazily.
     13  Services.prefs.setBoolPref("browser.sessionstore.restore_tabs_lazily", false);
     14 
     15  let state = {
     16    windows: [
     17      {
     18        tabs: [
     19          {
     20            entries: [
     21              { url: "http://example.org#1", triggeringPrincipal_base64 },
     22            ],
     23            extData: { uniq: r() },
     24          },
     25          {
     26            entries: [
     27              { url: "http://example.org#2", triggeringPrincipal_base64 },
     28            ],
     29            extData: { uniq: r() },
     30          }, // overwriting
     31          {
     32            entries: [
     33              { url: "http://example.org#3", triggeringPrincipal_base64 },
     34            ],
     35            extData: { uniq: r() },
     36          }, // hiding
     37          {
     38            entries: [
     39              { url: "http://example.org#4", triggeringPrincipal_base64 },
     40            ],
     41            extData: { uniq: r() },
     42          }, // adding
     43          {
     44            entries: [
     45              { url: "http://example.org#5", triggeringPrincipal_base64 },
     46            ],
     47            extData: { uniq: r() },
     48          }, // deleting
     49          {
     50            entries: [
     51              { url: "http://example.org#6", triggeringPrincipal_base64 },
     52            ],
     53          }, // creating
     54        ],
     55        selected: 1,
     56      },
     57    ],
     58  };
     59 
     60  async function progressCallback() {
     61    let curState = JSON.parse(ss.getBrowserState());
     62    for (let i = 0; i < curState.windows[0].tabs.length; i++) {
     63      let tabState = state.windows[0].tabs[i];
     64      let tabCurState = curState.windows[0].tabs[i];
     65      if (tabState.extData) {
     66        is(
     67          tabCurState.extData.uniq,
     68          tabState.extData.uniq,
     69          "sanity check that tab has correct extData"
     70        );
     71      } else {
     72        // We aren't expecting there to be any data on extData, but panorama
     73        // may be setting something, so we need to make sure that if we do have
     74        // data, we just don't have anything for "uniq".
     75        ok(
     76          !("extData" in tabCurState) || !("uniq" in tabCurState.extData),
     77          "sanity check that tab doesn't have extData or extData doesn't have 'uniq'"
     78        );
     79      }
     80    }
     81 
     82    // Now we'll set a new unique value on 1 of the tabs
     83    let newUniq = r();
     84    ss.setCustomTabValue(gBrowser.tabs[1], "uniq", newUniq);
     85    let tabState = JSON.parse(ss.getTabState(gBrowser.tabs[1]));
     86    is(
     87      tabState.extData.uniq,
     88      newUniq,
     89      "(overwriting) new data is stored in extData"
     90    );
     91 
     92    // hide the next tab before closing it
     93    gBrowser.hideTab(gBrowser.tabs[2]);
     94    tabState = JSON.parse(ss.getTabState(gBrowser.tabs[2]));
     95    ok(tabState.hidden, "(hiding) tab data has hidden == true");
     96 
     97    // set data that's not in a conflicting key
     98    let stillUniq = r();
     99    ss.setCustomTabValue(gBrowser.tabs[3], "stillUniq", stillUniq);
    100    tabState = JSON.parse(ss.getTabState(gBrowser.tabs[3]));
    101    is(
    102      tabState.extData.stillUniq,
    103      stillUniq,
    104      "(adding) new data is stored in extData"
    105    );
    106 
    107    // remove the uniq value and make sure it's not there in the closed data
    108    ss.deleteCustomTabValue(gBrowser.tabs[4], "uniq");
    109    tabState = JSON.parse(ss.getTabState(gBrowser.tabs[4]));
    110    // Since Panorama might have put data in, first check if there is extData.
    111    // If there is explicitly check that "uniq" isn't in it. Otherwise, we're ok
    112    if ("extData" in tabState) {
    113      ok(
    114        !("uniq" in tabState.extData),
    115        "(deleting) uniq not in existing extData"
    116      );
    117    } else {
    118      ok(true, "(deleting) no data is stored in extData");
    119    }
    120 
    121    // set unique data on the tab that never had any set, make sure that's saved
    122    let newUniq2 = r();
    123    ss.setCustomTabValue(gBrowser.tabs[5], "uniq", newUniq2);
    124    tabState = JSON.parse(ss.getTabState(gBrowser.tabs[5]));
    125    is(
    126      tabState.extData.uniq,
    127      newUniq2,
    128      "(creating) new data is stored in extData where there was none"
    129    );
    130 
    131    while (gBrowser.tabs.length > 1) {
    132      BrowserTestUtils.removeTab(gBrowser.tabs[1]);
    133    }
    134  }
    135 
    136  // Set the test state.
    137  await setBrowserState(state);
    138 
    139  // Wait until the selected tab is restored and all others are pending.
    140  await Promise.all(
    141    Array.from(gBrowser.tabs, tab => {
    142      return tab == gBrowser.selectedTab
    143        ? promiseTabRestored(tab)
    144        : promiseTabRestoring(tab);
    145    })
    146  );
    147 
    148  // Kick off the actual tests.
    149  await progressCallback();
    150 
    151  // Cleanup.
    152  Services.prefs.clearUserPref("browser.sessionstore.restore_on_demand");
    153  Services.prefs.clearUserPref("browser.sessionstore.restore_tabs_lazily");
    154  await promiseBrowserState(stateBackup);
    155 });