browser_autoSubmitRequest.js (5348B)
1 "use strict"; 2 3 const PAGE = 4 "data:text/html,<html><body>A%20regular,%20everyday,%20normal%20page."; 5 const AUTOSUBMIT_PREF = "browser.crashReports.unsubmittedCheck.autoSubmit2"; 6 7 const { TabStateFlusher } = ChromeUtils.importESModule( 8 "resource:///modules/sessionstore/TabStateFlusher.sys.mjs" 9 ); 10 11 // On debug builds, crashing tabs results in much thinking, which 12 // slows down the test and results in intermittent test timeouts, 13 // so we'll pump up the expected timeout for this test. 14 requestLongerTimeout(2); 15 16 /** 17 * Tests that if the user is not configured to autosubmit 18 * backlogged crash reports, that we offer to do that, and 19 * that the user can accept that offer. 20 */ 21 add_task(async function test_show_form() { 22 await SpecialPowers.pushPrefEnv({ 23 set: [[AUTOSUBMIT_PREF, false]], 24 }); 25 26 await BrowserTestUtils.withNewTab( 27 { 28 gBrowser, 29 url: PAGE, 30 }, 31 async function (browser) { 32 // Make sure we've flushed the browser messages so that 33 // we can restore it. 34 await TabStateFlusher.flush(browser); 35 36 // Now crash the browser. 37 await BrowserTestUtils.crashFrame(browser); 38 39 let doc = browser.contentDocument; 40 41 // Ensure the request is visible. We can safely reach into 42 // the content since about:tabcrashed is an in-process URL. 43 let requestAutoSubmit = doc.getElementById("requestAutoSubmit"); 44 Assert.ok( 45 !requestAutoSubmit.hidden, 46 "Request for autosubmission is visible." 47 ); 48 49 // Since the pref is set to false, the checkbox should be 50 // unchecked. 51 let autoSubmit = doc.getElementById("autoSubmit"); 52 Assert.ok( 53 !autoSubmit.checked, 54 "Checkbox for autosubmission is not checked." 55 ); 56 57 // Check the checkbox, and then restore the tab. 58 autoSubmit.checked = true; 59 let restoreButton = doc.getElementById("restoreTab"); 60 restoreButton.click(); 61 62 await BrowserTestUtils.browserLoaded(browser, false, PAGE); 63 64 // The autosubmission pref should now be set. 65 Assert.ok( 66 Services.prefs.getBoolPref(AUTOSUBMIT_PREF), 67 "Autosubmission pref should have been set." 68 ); 69 } 70 ); 71 }); 72 73 /** 74 * Tests that if the user is autosubmitting backlogged crash reports 75 * that we don't make the offer again. 76 */ 77 add_task(async function test_show_form() { 78 await SpecialPowers.pushPrefEnv({ 79 set: [[AUTOSUBMIT_PREF, true]], 80 }); 81 82 await BrowserTestUtils.withNewTab( 83 { 84 gBrowser, 85 url: PAGE, 86 }, 87 async function (browser) { 88 await TabStateFlusher.flush(browser); 89 // Now crash the browser. 90 await BrowserTestUtils.crashFrame(browser); 91 92 let doc = browser.contentDocument; 93 94 // Ensure the request is NOT visible. We can safely reach into 95 // the content since about:tabcrashed is an in-process URL. 96 let requestAutoSubmit = doc.getElementById("requestAutoSubmit"); 97 Assert.ok( 98 requestAutoSubmit.hidden, 99 "Request for autosubmission is not visible." 100 ); 101 102 // Restore the tab. 103 let restoreButton = doc.getElementById("restoreTab"); 104 restoreButton.click(); 105 106 await BrowserTestUtils.browserLoaded(browser, false, PAGE); 107 108 // The autosubmission pref should still be set to true. 109 Assert.ok( 110 Services.prefs.getBoolPref(AUTOSUBMIT_PREF), 111 "Autosubmission pref should have been set." 112 ); 113 } 114 ); 115 }); 116 117 /** 118 * Tests that we properly set the autoSubmit preference if the user is 119 * presented with a tabcrashed page without a crash report. 120 */ 121 add_task(async function test_no_offer() { 122 // We should default to sending the report. 123 Assert.ok(TabCrashHandler.prefs.getBoolPref("sendReport")); 124 125 await SpecialPowers.pushPrefEnv({ 126 set: [[AUTOSUBMIT_PREF, false]], 127 }); 128 129 await BrowserTestUtils.withNewTab( 130 { 131 gBrowser, 132 url: PAGE, 133 }, 134 async function (browser) { 135 await TabStateFlusher.flush(browser); 136 137 // Make it so that it seems like no dump is available for the next crash. 138 prepareNoDump(); 139 140 // Now crash the browser. 141 await BrowserTestUtils.crashFrame(browser); 142 143 let doc = browser.contentDocument; 144 145 // Ensure the request to autosubmit is invisible, since there's no report. 146 let requestRect = doc 147 .getElementById("requestAutoSubmit") 148 .getBoundingClientRect(); 149 Assert.equal( 150 0, 151 requestRect.height, 152 "Request for autosubmission has no height" 153 ); 154 Assert.equal( 155 0, 156 requestRect.width, 157 "Request for autosubmission has no width" 158 ); 159 160 // Since the pref is set to false, the checkbox should be 161 // unchecked. 162 let autoSubmit = doc.getElementById("autoSubmit"); 163 Assert.ok( 164 !autoSubmit.checked, 165 "Checkbox for autosubmission is not checked." 166 ); 167 168 let restoreButton = doc.getElementById("restoreTab"); 169 restoreButton.click(); 170 171 await BrowserTestUtils.browserLoaded(browser, false, PAGE); 172 173 // The autosubmission pref should now be set. 174 Assert.ok( 175 !Services.prefs.getBoolPref(AUTOSUBMIT_PREF), 176 "Autosubmission pref should not have changed." 177 ); 178 } 179 ); 180 181 // We should not have changed the default value for sending the report. 182 Assert.ok(TabCrashHandler.prefs.getBoolPref("sendReport")); 183 });