browser_shownRestartRequired.js (3648B)
1 "use strict"; 2 3 const PAGE = 4 "data:text/html,<html><body>A%20regular,%20everyday,%20normal%20page."; 5 6 async function assertIsAtRestartRequiredPage(browser) { 7 let doc = browser.contentDocument; 8 9 // Since about:restartRequired will run in the parent process, we can safely 10 // manipulate its DOM nodes directly 11 let title = doc.getElementById("title"); 12 let description = doc.getElementById("errorLongContent"); 13 let restartButton = doc.getElementById("restart"); 14 15 Assert.ok(title, "Title element exists."); 16 Assert.ok(description, "Description element exists."); 17 Assert.ok(restartButton, "Restart button exists."); 18 } 19 20 /** 21 * This function returns a Promise that resolves once the following 22 * actions have taken place: 23 * 24 * 1) A new tab is opened up at PAGE 25 * 2) The tab is crashed 26 * 3) The about:restartrequired page is displayed 27 * 28 * @returns Promise 29 */ 30 function crashTabTestHelper() { 31 return BrowserTestUtils.withNewTab( 32 { 33 gBrowser, 34 url: PAGE, 35 }, 36 async function (browser) { 37 // Simulate buildID mismatch. 38 TabCrashHandler.testBuildIDMismatch = true; 39 40 let restartRequiredLoaded = BrowserTestUtils.waitForContentEvent( 41 browser, 42 "AboutRestartRequiredLoad", 43 false, 44 null, 45 true 46 ); 47 await BrowserTestUtils.crashFrame(browser, false); 48 await restartRequiredLoaded; 49 await assertIsAtRestartRequiredPage(browser); 50 51 // Reset 52 TabCrashHandler.testBuildIDMismatch = false; 53 } 54 ); 55 } 56 57 /** 58 * Tests that the about:restartrequired page appears when buildID mismatches 59 * between parent and child processes are encountered. 60 */ 61 add_task(async function test_default() { 62 await crashTabTestHelper(); 63 }); 64 65 /** 66 * Tests that if the content process fails to launch in the 67 * foreground tab, that we show the restart required page, but do not 68 * attempt to wait for a crash dump for it (which will never come). 69 */ 70 add_task(async function test_restart_required_foreground() { 71 // eslint-disable-next-line @microsoft/sdl/no-insecure-url 72 await BrowserTestUtils.withNewTab("http://example.com", async browser => { 73 let loaded = BrowserTestUtils.browserLoaded(browser, false, null, true); 74 await BrowserTestUtils.simulateProcessLaunchFail( 75 browser, 76 true /* restart required */ 77 ); 78 Assert.equal( 79 0, 80 TabCrashHandler.queuedCrashedBrowsers, 81 "No crashed browsers should be queued." 82 ); 83 await loaded; 84 await assertIsAtRestartRequiredPage(browser); 85 }); 86 }); 87 88 /** 89 * Tests that if the content process fails to launch in a background 90 * tab because a restart is required, that upon choosing that tab, we 91 * show the restart required error page, but do not attempt to wait for 92 * a crash dump for it (which will never come). 93 */ 94 add_task(async function test_launchfail_background() { 95 let originalTab = gBrowser.selectedTab; 96 // eslint-disable-next-line @microsoft/sdl/no-insecure-url 97 await BrowserTestUtils.withNewTab("http://example.com", async browser => { 98 let tab = gBrowser.getTabForBrowser(browser); 99 await BrowserTestUtils.switchTab(gBrowser, originalTab); 100 await BrowserTestUtils.simulateProcessLaunchFail( 101 browser, 102 true /* restart required */ 103 ); 104 Assert.equal( 105 0, 106 TabCrashHandler.queuedCrashedBrowsers, 107 "No crashed browsers should be queued." 108 ); 109 let loaded = BrowserTestUtils.waitForContentEvent( 110 browser, 111 "AboutRestartRequiredLoad", 112 false, 113 null, 114 true 115 ); 116 await BrowserTestUtils.switchTab(gBrowser, tab); 117 await loaded; 118 119 await assertIsAtRestartRequiredPage(browser); 120 }); 121 });