summaryrefslogtreecommitdiffstats
path: root/browser/components/sessionstore/test/browser_aboutSessionRestore.js
blob: 8ab91e4dfe0f42692bf24328b5b2079a18352d0a (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
/* 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};
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};
const TAB_STATE = {entries: [TAB_SHENTRY], formdata: TAB_FORMDATA};

const FRAME_SCRIPT = "data:," +
                     "content.document.getElementById('errorTryAgain').click()";

add_task(function* () {
  // Prepare a blank tab.
  let tab = gBrowser.addTab("about:blank");
  let browser = tab.linkedBrowser;
  yield promiseBrowserLoaded(browser);

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

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

  let view = browser.contentDocument.getElementById("tabList").view;
  ok(view.isContainer(0), "first entry is the window");
  is(view.getCellProperties(1, { id: "title" }), "icon",
    "second entry is the tab and has a favicon");

  browser.messageManager.loadFrameScript(FRAME_SCRIPT, true);

  // Wait until the new window was restored.
  let win = yield waitForNewWindow();
  yield BrowserTestUtils.closeWindow(win);

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

function waitForNewWindow() {
  return new Promise(resolve => {
    Services.obs.addObserver(function observe(win, topic) {
      Services.obs.removeObserver(observe, topic);
      resolve(win);
    }, "browser-delayed-startup-finished", false);
  });
}