summaryrefslogtreecommitdiffstats
path: root/browser/components/sessionstore/test/browser_615394-SSWindowState_events_undoCloseTab.js
blob: 345bba516ce5bc1817e9fdb6d2e5a096a06e0357 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"use strict";

const testState = {
  windows: [
    {
      tabs: [
        { entries: [{ url: "about:blank", triggeringPrincipal_base64 }] },
        { entries: [{ url: "about:rights", triggeringPrincipal_base64 }] },
      ],
    },
  ],
};

// Test for Bug 615394 - Session Restore should notify when it is beginning and
// ending a restore.
add_task(async function test_undoCloseTab() {
  await promiseBrowserState(testState);

  let tab = gBrowser.tabs[1];
  let busyEventCount = 0;
  let readyEventCount = 0;
  // This will be set inside the `onSSWindowStateReady` method.
  let lastTab;

  ss.setCustomTabValue(tab, "foo", "bar");

  function onSSWindowStateBusy(aEvent) {
    busyEventCount++;
  }

  function onSSWindowStateReady(aEvent) {
    Assert.equal(gBrowser.tabs.length, 2, "Should only have 2 tabs");
    lastTab = gBrowser.tabs[1];
    readyEventCount++;
    Assert.equal(ss.getCustomTabValue(lastTab, "foo"), "bar");
    ss.setCustomTabValue(lastTab, "baz", "qux");
  }

  window.addEventListener("SSWindowStateBusy", onSSWindowStateBusy);
  window.addEventListener("SSWindowStateReady", onSSWindowStateReady);

  let restoredPromise = BrowserTestUtils.waitForEvent(
    gBrowser.tabContainer,
    "SSTabRestored"
  );

  await promiseRemoveTabAndSessionState(tab);
  let reopenedTab = ss.undoCloseTab(window, 0);

  await Promise.all([
    restoredPromise,
    BrowserTestUtils.browserLoaded(reopenedTab.linkedBrowser),
  ]);

  Assert.equal(reopenedTab, lastTab, "Tabs should be the same one.");
  Assert.equal(busyEventCount, 1);
  Assert.equal(readyEventCount, 1);
  Assert.equal(ss.getCustomTabValue(reopenedTab, "baz"), "qux");
  Assert.equal(reopenedTab.linkedBrowser.currentURI.spec, "about:rights");

  window.removeEventListener("SSWindowStateBusy", onSSWindowStateBusy);
  window.removeEventListener("SSWindowStateReady", onSSWindowStateReady);

  BrowserTestUtils.removeTab(reopenedTab);
});