summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/tabcrashed/browser_shownRestartRequired.js
blob: 9142b54a8ae377fd0e10d21e750ceb1b9d35d8a8 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
"use strict";

const PAGE =
  "data:text/html,<html><body>A%20regular,%20everyday,%20normal%20page.";

async function assertIsAtRestartRequiredPage(browser) {
  let doc = browser.contentDocument;

  // Since about:restartRequired will run in the parent process, we can safely
  // manipulate its DOM nodes directly
  let title = doc.getElementById("title");
  let description = doc.getElementById("errorLongContent");
  let restartButton = doc.getElementById("restart");

  Assert.ok(title, "Title element exists.");
  Assert.ok(description, "Description element exists.");
  Assert.ok(restartButton, "Restart button exists.");
}

/**
 * This function returns a Promise that resolves once the following
 * actions have taken place:
 *
 * 1) A new tab is opened up at PAGE
 * 2) The tab is crashed
 * 3) The about:restartrequired page is displayed
 *
 * @returns Promise
 */
function crashTabTestHelper() {
  return BrowserTestUtils.withNewTab(
    {
      gBrowser,
      url: PAGE,
    },
    async function (browser) {
      // Simulate buildID mismatch.
      TabCrashHandler.testBuildIDMismatch = true;

      let restartRequiredLoaded = BrowserTestUtils.waitForContentEvent(
        browser,
        "AboutRestartRequiredLoad",
        false,
        null,
        true
      );
      await BrowserTestUtils.crashFrame(browser, false);
      await restartRequiredLoaded;
      await assertIsAtRestartRequiredPage(browser);

      // Reset
      TabCrashHandler.testBuildIDMismatch = false;
    }
  );
}

/**
 * Tests that the about:restartrequired page appears when buildID mismatches
 * between parent and child processes are encountered.
 */
add_task(async function test_default() {
  await crashTabTestHelper();
});

/**
 * Tests that if the content process fails to launch in the
 * foreground tab, that we show the restart required page, but do not
 * attempt to wait for a crash dump for it (which will never come).
 */
add_task(async function test_restart_required_foreground() {
  // eslint-disable-next-line @microsoft/sdl/no-insecure-url
  await BrowserTestUtils.withNewTab("http://example.com", async browser => {
    let loaded = BrowserTestUtils.browserLoaded(browser, false, null, true);
    await BrowserTestUtils.simulateProcessLaunchFail(
      browser,
      true /* restart required */
    );
    Assert.equal(
      0,
      TabCrashHandler.queuedCrashedBrowsers,
      "No crashed browsers should be queued."
    );
    await loaded;
    await assertIsAtRestartRequiredPage(browser);
  });
});

/**
 * Tests that if the content process fails to launch in a background
 * tab because a restart is required, that upon choosing that tab, we
 * show the restart required error page, but do not attempt to wait for
 * a crash dump for it (which will never come).
 */
add_task(async function test_launchfail_background() {
  let originalTab = gBrowser.selectedTab;
  // eslint-disable-next-line @microsoft/sdl/no-insecure-url
  await BrowserTestUtils.withNewTab("http://example.com", async browser => {
    let tab = gBrowser.getTabForBrowser(browser);
    await BrowserTestUtils.switchTab(gBrowser, originalTab);
    await BrowserTestUtils.simulateProcessLaunchFail(
      browser,
      true /* restart required */
    );
    Assert.equal(
      0,
      TabCrashHandler.queuedCrashedBrowsers,
      "No crashed browsers should be queued."
    );
    let loaded = BrowserTestUtils.waitForContentEvent(
      browser,
      "AboutRestartRequiredLoad",
      false,
      null,
      true
    );
    await BrowserTestUtils.switchTab(gBrowser, tab);
    await loaded;

    await assertIsAtRestartRequiredPage(browser);
  });
});