tor-browser

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

browser_615394-SSWindowState_events_undoCloseTab.js (1912B)


      1 "use strict";
      2 
      3 const testState = {
      4  windows: [
      5    {
      6      tabs: [
      7        { entries: [{ url: "about:blank", triggeringPrincipal_base64 }] },
      8        { entries: [{ url: "about:robots", triggeringPrincipal_base64 }] },
      9      ],
     10    },
     11  ],
     12 };
     13 
     14 // Test for Bug 615394 - Session Restore should notify when it is beginning and
     15 // ending a restore.
     16 add_task(async function test_undoCloseTab() {
     17  await promiseBrowserState(testState);
     18 
     19  let tab = gBrowser.tabs[1];
     20  let busyEventCount = 0;
     21  let readyEventCount = 0;
     22  // This will be set inside the `onSSWindowStateReady` method.
     23  let lastTab;
     24 
     25  ss.setCustomTabValue(tab, "foo", "bar");
     26 
     27  function onSSWindowStateBusy() {
     28    busyEventCount++;
     29  }
     30 
     31  function onSSWindowStateReady() {
     32    Assert.equal(gBrowser.tabs.length, 2, "Should only have 2 tabs");
     33    lastTab = gBrowser.tabs[1];
     34    readyEventCount++;
     35    Assert.equal(ss.getCustomTabValue(lastTab, "foo"), "bar");
     36    ss.setCustomTabValue(lastTab, "baz", "qux");
     37  }
     38 
     39  window.addEventListener("SSWindowStateBusy", onSSWindowStateBusy);
     40  window.addEventListener("SSWindowStateReady", onSSWindowStateReady);
     41 
     42  let restoredPromise = BrowserTestUtils.waitForEvent(
     43    gBrowser.tabContainer,
     44    "SSTabRestored"
     45  );
     46 
     47  await promiseRemoveTabAndSessionState(tab);
     48  let reopenedTab = ss.undoCloseTab(window, 0);
     49 
     50  await Promise.all([
     51    restoredPromise,
     52    BrowserTestUtils.browserLoaded(reopenedTab.linkedBrowser),
     53  ]);
     54 
     55  Assert.equal(reopenedTab, lastTab, "Tabs should be the same one.");
     56  Assert.equal(busyEventCount, 1);
     57  Assert.equal(readyEventCount, 1);
     58  Assert.equal(ss.getCustomTabValue(reopenedTab, "baz"), "qux");
     59  Assert.equal(reopenedTab.linkedBrowser.currentURI.spec, "about:robots");
     60 
     61  window.removeEventListener("SSWindowStateBusy", onSSWindowStateBusy);
     62  window.removeEventListener("SSWindowStateReady", onSSWindowStateReady);
     63 
     64  BrowserTestUtils.removeTab(reopenedTab);
     65 });