tor-browser

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

browser_394759_behavior.js (2859B)


      1 /**
      2 * Test helper function that opens a series of windows, closes them
      3 * and then checks the closed window data from SessionStore against
      4 * expected results.
      5 *
      6 * @param windowsToOpen (Array)
      7 *        An array of Objects, where each object must define a single
      8 *        property "isPopup" for whether or not the opened window should
      9 *        be a popup.
     10 * @param expectedResults (Array)
     11 *        An Object with two properies: mac and other, where each points
     12 *        at yet another Object, with the following properties:
     13 *
     14 *        popup (int):
     15 *          The number of popup windows we expect to be in the closed window
     16 *          data.
     17 *        normal (int):
     18 *          The number of normal windows we expect to be in the closed window
     19 *          data.
     20 * @returns Promise
     21 */
     22 function testWindows(windowsToOpen, expectedResults) {
     23  return (async function () {
     24    let num = 0;
     25    for (let winData of windowsToOpen) {
     26      let features = "chrome,dialog=no," + (winData.isPopup ? "all=no" : "all");
     27      let url = "http://example.com/?window=" + num;
     28      num = num + 1;
     29 
     30      let openWindowPromise = BrowserTestUtils.waitForNewWindow({ url });
     31      openDialog(AppConstants.BROWSER_CHROME_URL, "", features, url);
     32      let win = await openWindowPromise;
     33      await BrowserTestUtils.closeWindow(win);
     34    }
     35 
     36    let closedWindowData = ss.getClosedWindowData();
     37    let numPopups = closedWindowData.filter(function (el) {
     38      return el.isPopup;
     39    }).length;
     40    let numNormal = ss.getClosedWindowCount() - numPopups;
     41    // #ifdef doesn't work in browser-chrome tests, so do a simple regex on platform
     42    let oResults = navigator.platform.match(/Mac/)
     43      ? expectedResults.mac
     44      : expectedResults.other;
     45    is(
     46      numPopups,
     47      oResults.popup,
     48      "There were " + oResults.popup + " popup windows to reopen"
     49    );
     50    is(
     51      numNormal,
     52      oResults.normal,
     53      "There were " + oResults.normal + " normal windows to reopen"
     54    );
     55  })();
     56 }
     57 
     58 add_task(async function test_closed_window_states() {
     59  // This test takes quite some time, and timeouts frequently, so we require
     60  // more time to run.
     61  // See Bug 518970.
     62  requestLongerTimeout(2);
     63 
     64  let windowsToOpen = [
     65    { isPopup: false },
     66    { isPopup: true },
     67    { isPopup: true },
     68    { isPopup: true },
     69    { isPopup: true },
     70    { isPopup: true },
     71  ];
     72  let expectedResults = {
     73    mac: { popup: 5, normal: 0 },
     74    other: { popup: 5, normal: 1 },
     75  };
     76 
     77  await testWindows(windowsToOpen, expectedResults);
     78 
     79  let windowsToOpen2 = [
     80    { isPopup: false },
     81    { isPopup: false },
     82    { isPopup: false },
     83    { isPopup: false },
     84    { isPopup: false },
     85    { isPopup: false },
     86  ];
     87  let expectedResults2 = {
     88    mac: { popup: 0, normal: 5 },
     89    other: { popup: 0, normal: 5 },
     90  };
     91 
     92  await testWindows(windowsToOpen2, expectedResults2);
     93 });