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

"use strict";

const CRASH_URL = "about:mozilla";
const CRASH_FAVICON = "chrome://branding/content/icon32.png";
const CRASH_SHENTRY = { url: CRASH_URL, triggeringPrincipal_base64 };
const CRASH_TAB = { entries: [CRASH_SHENTRY], image: CRASH_FAVICON };
const CRASH_STATE = { windows: [{ tabs: [CRASH_TAB] }] };

const TAB_URL = "about:sessionrestore";
const TAB_FORMDATA = { url: TAB_URL, id: { sessionData: CRASH_STATE } };
const TAB_SHENTRY = { url: TAB_URL, triggeringPrincipal_base64 };
const TAB_STATE = { entries: [TAB_SHENTRY], formdata: TAB_FORMDATA };

add_task(async function () {
  // Prepare a blank tab.
  let tab = BrowserTestUtils.addTab(gBrowser, "about:blank");
  let browser = tab.linkedBrowser;
  await promiseBrowserLoaded(browser);

  // Fake a post-crash tab.
  ss.setTabState(tab, JSON.stringify(TAB_STATE));
  await promiseTabRestored(tab);

  ok(gBrowser.tabs.length > 1, "we have more than one tab");

  let tabsToggle = browser.contentDocument.getElementById("tabsToggle");
  tabsToggle.click();
  await BrowserTestUtils.waitForCondition(
    () => browser.contentWindow.gTreeInitialized
  );
  let tree = browser.contentDocument.getElementById("tabList");
  let view = tree.view;
  ok(view.isContainer(0), "first entry is the window");
  let titleColumn = tree.columns.title;
  is(
    view.getCellProperties(1, titleColumn),
    "icon",
    "second entry is the tab and has a favicon"
  );

  let newWindowOpened = BrowserTestUtils.waitForNewWindow();

  SpecialPowers.spawn(browser.browsingContext, [], () => {
    content.document.getElementById("errorTryAgain").click();
  });

  // Wait until the new window was restored.
  let win = await newWindowOpened;

  BrowserTestUtils.removeTab(tab);
  await BrowserTestUtils.closeWindow(win);

  let [
    {
      tabs: [
        {
          entries: [{ url }],
        },
      ],
    },
  ] = ss.getClosedWindowData();
  is(url, CRASH_URL, "session was restored correctly");
  ss.forgetClosedWindow(0);
});