tor-browser

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

browser_394759_perwindowpb.js (1924B)


      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 "use strict";
      6 
      7 const TESTS = [
      8  { url: "about:config", key: "bug 394759 Non-PB", value: "uniq" + r() },
      9  { url: "about:mozilla", key: "bug 394759 PB", value: "uniq" + r() },
     10 ];
     11 
     12 function promiseTestOpenCloseWindow(aIsPrivate, aTest) {
     13  return (async function () {
     14    let win = await BrowserTestUtils.openNewBrowserWindow({
     15      private: aIsPrivate,
     16    });
     17    BrowserTestUtils.startLoadingURIString(
     18      win.gBrowser.selectedBrowser,
     19      aTest.url
     20    );
     21    await promiseBrowserLoaded(win.gBrowser.selectedBrowser, true, aTest.url);
     22    // Mark the window with some unique data to be restored later on.
     23    ss.setCustomWindowValue(win, aTest.key, aTest.value);
     24    await TabStateFlusher.flushWindow(win);
     25    // Close.
     26    await BrowserTestUtils.closeWindow(win);
     27  })();
     28 }
     29 
     30 function promiseTestOnWindow(aIsPrivate, aValue) {
     31  return (async function () {
     32    let win = await BrowserTestUtils.openNewBrowserWindow({
     33      private: aIsPrivate,
     34    });
     35    await TabStateFlusher.flushWindow(win);
     36    let data = ss.getClosedWindowData()[0];
     37    is(
     38      ss.getClosedWindowCount(),
     39      1,
     40      "Check that the closed window count hasn't changed"
     41    );
     42    Assert.greater(
     43      JSON.stringify(data).indexOf(aValue),
     44      -1,
     45      "Check the closed window data was stored correctly"
     46    );
     47    registerCleanupFunction(() => BrowserTestUtils.closeWindow(win));
     48  })();
     49 }
     50 
     51 add_setup(async function () {
     52  forgetClosedWindows();
     53  forgetClosedTabs(window);
     54 });
     55 
     56 add_task(async function main() {
     57  await promiseTestOpenCloseWindow(false, TESTS[0]);
     58  await promiseTestOpenCloseWindow(true, TESTS[1]);
     59  await promiseTestOnWindow(false, TESTS[0].value);
     60  await promiseTestOnWindow(true, TESTS[0].value);
     61 });