summaryrefslogtreecommitdiffstats
path: root/browser/components/sessionstore/test/browser_restore_tabless_window.js
blob: cffb2159f5287553a0af6d72142fbf9ccce2b2f3 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * It's possible for us to restore windows without tabs,
 * when on Windows/Linux the user closes the last tab as
 * a means of closing the last window. That last tab
 * would appear as a closed tab in session state for the
 * window, with no open tabs (so the state would be resumed
 * as showing the homepage). See bug 490136 for context.
 * This test checks that in this case, the resulting window
 * is functional and indeed has the required previously
 * closed tabs available.
 */
add_task(async function test_restoring_tabless_window() {
  let newWin = await BrowserTestUtils.openNewBrowserWindow();
  let newState = {
    windows: [
      {
        tabs: [],
        _closedTabs: [
          {
            state: { entries: [{ url: "about:" }] },
            title: "About:",
          },
        ],
      },
    ],
  };

  await setWindowState(newWin, newState, true);
  let tab = await BrowserTestUtils.openNewForegroundTab(
    newWin.gBrowser,
    "https://example.com"
  );
  await TabStateFlusher.flush(tab.linkedBrowser);
  let receivedState = SessionStore.getWindowState(newWin);
  let { tabs, selected } = receivedState.windows[0];
  is(tabs.length, 2, "Should have two tabs");
  is(selected, 2, "Should have selected the new tab");
  ok(
    tabs[1]?.entries.some(e => e.url == "https://example.com/"),
    "Should have found the new URL"
  );

  let closedTabData = SessionStore.getClosedTabDataForWindow(newWin);
  is(closedTabData.length, 1, "Should have found 1 closed tab");
  is(
    closedTabData[0]?.state.entries[0].url,
    "about:",
    "Should have found the right URL for the closed tab"
  );
  await BrowserTestUtils.closeWindow(newWin);
});