tor-browser

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

browser_625016.js (3260B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 add_setup(async function () {
      5  /** Test for Bug 625016 - Restore windows closed in succession to quit (non-OSX only) */
      6 
      7  // We'll test this by opening a new window, waiting for the save
      8  // event, then closing that window. We'll observe the
      9  // "sessionstore-state-write-complete" notification and check that
     10  // the state contains no _closedWindows. We'll then add a new tab
     11  // and make sure that the state following that was reset and the
     12  // closed window is now in _closedWindows.
     13 
     14  requestLongerTimeout(2);
     15 
     16  await forceSaveState();
     17 
     18  // We'll clear all closed windows to make sure our state is clean
     19  // forgetClosedWindow doesn't trigger a delayed save
     20  forgetClosedWindows();
     21  is(ss.getClosedWindowCount(), 0, "starting with no closed windows");
     22 });
     23 
     24 add_task(async function new_window() {
     25  let newWin;
     26  try {
     27    newWin = await promiseNewWindowLoaded();
     28    let tab = BrowserTestUtils.addTab(
     29      newWin.gBrowser,
     30      "http://example.com/browser_625016.js?" + Math.random()
     31    );
     32    await promiseBrowserLoaded(tab.linkedBrowser);
     33 
     34    // Double check that we have no closed windows
     35    is(ss.getClosedWindowCount(), 0, "no closed windows on first save");
     36 
     37    await BrowserTestUtils.closeWindow(newWin);
     38    newWin = null;
     39 
     40    let state = JSON.parse(await promiseRecoveryFileContents());
     41    is(state.windows.length, 1, "observe1: 1 window in data written to disk");
     42    is(
     43      state._closedWindows.length,
     44      0,
     45      "observe1: no closed windows in data written to disk"
     46    );
     47 
     48    // The API still treats the closed window as closed, so ensure that window is there
     49    is(
     50      ss.getClosedWindowCount(),
     51      1,
     52      "observe1: 1 closed window according to API"
     53    );
     54  } finally {
     55    if (newWin) {
     56      await BrowserTestUtils.closeWindow(newWin);
     57    }
     58    await forceSaveState();
     59  }
     60 });
     61 
     62 // We'll open a tab, which should trigger another state save which would wipe
     63 // the _shouldRestore attribute from the closed window
     64 add_task(async function new_tab() {
     65  let newTab;
     66  try {
     67    newTab = BrowserTestUtils.addTab(gBrowser, "about:mozilla");
     68    await promiseBrowserLoaded(newTab.linkedBrowser);
     69    await TabStateFlusher.flush(newTab.linkedBrowser);
     70 
     71    let state = JSON.parse(await promiseRecoveryFileContents());
     72    is(
     73      state.windows.length,
     74      1,
     75      "observe2: 1 window in data being written to disk"
     76    );
     77    is(
     78      state._closedWindows.length,
     79      1,
     80      "observe2: 1 closed window in data being written to disk"
     81    );
     82 
     83    // The API still treats the closed window as closed, so ensure that window is there
     84    is(
     85      ss.getClosedWindowCount(),
     86      1,
     87      "observe2: 1 closed window according to API"
     88    );
     89  } finally {
     90    if (newTab) {
     91      gBrowser.removeTab(newTab);
     92    }
     93  }
     94 });
     95 
     96 add_task(async function done() {
     97  // The API still represents the closed window as closed, so we can clear it
     98  // with the API, but just to make sure...
     99  //  is(ss.getClosedWindowCount(), 1, "1 closed window according to API");
    100  await promiseAllButPrimaryWindowClosed();
    101  forgetClosedWindows();
    102  Services.prefs.clearUserPref("browser.sessionstore.interval");
    103 });