diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /browser/base/content/test/tabcrashed/browser_shownRestartRequired.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | browser/base/content/test/tabcrashed/browser_shownRestartRequired.js | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/browser/base/content/test/tabcrashed/browser_shownRestartRequired.js b/browser/base/content/test/tabcrashed/browser_shownRestartRequired.js new file mode 100644 index 0000000000..9142b54a8a --- /dev/null +++ b/browser/base/content/test/tabcrashed/browser_shownRestartRequired.js @@ -0,0 +1,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); + }); +}); |