tor-browser

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

browser_615394-SSWindowState_events_setWindowState.js (1953B)


      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 test() {
      6  /** Test for Bug 615394 - Session Restore should notify when it is beginning and ending a restore */
      7  waitForExplicitFinish();
      8 
      9  let newState = {
     10    windows: [
     11      {
     12        tabs: [
     13          {
     14            entries: [{ url: "about:mozilla", triggeringPrincipal_base64 }],
     15            extData: { foo: "bar" },
     16          },
     17          {
     18            entries: [
     19              { url: "http://example.org", triggeringPrincipal_base64 },
     20            ],
     21            extData: { baz: "qux" },
     22          },
     23        ],
     24      },
     25    ],
     26  };
     27 
     28  let busyEventCount = 0,
     29    readyEventCount = 0,
     30    tabRestoredCount = 0;
     31 
     32  function onSSWindowStateBusy() {
     33    busyEventCount++;
     34  }
     35 
     36  function onSSWindowStateReady() {
     37    readyEventCount++;
     38    is(ss.getCustomTabValue(gBrowser.tabs[0], "foo"), "bar");
     39    is(ss.getCustomTabValue(gBrowser.tabs[1], "baz"), "qux");
     40  }
     41 
     42  function onSSTabRestored() {
     43    if (++tabRestoredCount < 2) {
     44      return;
     45    }
     46 
     47    is(busyEventCount, 1);
     48    is(readyEventCount, 1);
     49    is(gBrowser.tabs[0].linkedBrowser.currentURI.spec, "about:mozilla");
     50    is(gBrowser.tabs[1].linkedBrowser.currentURI.spec, "http://example.org/");
     51 
     52    window.removeEventListener("SSWindowStateBusy", onSSWindowStateBusy);
     53    window.removeEventListener("SSWindowStateReady", onSSWindowStateReady);
     54    gBrowser.tabContainer.removeEventListener("SSTabRestored", onSSTabRestored);
     55 
     56    gBrowser.removeTab(gBrowser.tabs[1]);
     57    finish();
     58  }
     59 
     60  window.addEventListener("SSWindowStateBusy", onSSWindowStateBusy);
     61  window.addEventListener("SSWindowStateReady", onSSWindowStateReady);
     62  gBrowser.tabContainer.addEventListener("SSTabRestored", onSSTabRestored);
     63 
     64  ss.setWindowState(window, JSON.stringify(newState), true);
     65 }