Bug 1399796 - UnsubmittedCrashHandler should never check for unsubmitted crash reports if disabled or suppressed. r?felipe
Bug 1355492 moved the logic for scanning for unsubmitted crash reports out of the initialization
of UnsubmittedCrashHandler, and the initialization is what decided whether or not it was
appropriate to scan in the first place. This was done so that scanning could be deferred
until idle after first paint.
This patch makes it so that the scanning logic first ensures that the UnsubmittedCrashHandler
is actually enabled and not suppressed (which is calculated earlier).
I've also taken the liberty of adding a regression test.
MozReview-Commit-ID: 3Aihom5Q17R
--- a/browser/modules/ContentCrashHandlers.jsm
+++ b/browser/modules/ContentCrashHandlers.jsm
@@ -655,16 +655,20 @@ this.UnsubmittedCrashHandler = {
* bar to prompt the user to submit them.
*
* @returns Promise
* Resolves with the <xul:notification> after it tries to
* show a notification on the most recent browser window.
* If a notification cannot be shown, will resolve with null.
*/
async checkForUnsubmittedCrashReports() {
+ if (!this.enabled || this.suppressed) {
+ return null;
+ }
+
let dateLimit = new Date();
dateLimit.setDate(dateLimit.getDate() - PENDING_CRASH_REPORT_DAYS);
let reportIDs = [];
try {
reportIDs = await CrashSubmit.pendingIDs(dateLimit);
} catch (e) {
Cu.reportError(e);
--- a/browser/modules/test/browser/browser_UnsubmittedCrashHandler.js
+++ b/browser/modules/test/browser/browser_UnsubmittedCrashHandler.js
@@ -201,16 +201,35 @@ add_task(async function setup() {
// nsBrowserGlue starts up UnsubmittedCrashHandler automatically
// so at this point, it is initialized. It's possible that it
// was initialized, but is preffed off, so it's inert, so we
// shut it down, make sure it's preffed on, and then restart it.
// Note that making the component initialize even when it's
// disabled is an intentional choice, as this allows for easier
// simulation of startup and shutdown.
UnsubmittedCrashHandler.uninit();
+
+ // While we're here, let's test that we don't show the notification
+ // if we're disabled and something happens to check for unsubmitted
+ // crash reports.
+ await SpecialPowers.pushPrefEnv({
+ set: [
+ ["browser.crashReports.unsubmittedCheck.enabled", false],
+ ],
+ });
+
+ await createPendingCrashReports(1);
+
+ notification =
+ await UnsubmittedCrashHandler.checkForUnsubmittedCrashReports();
+ Assert.ok(!notification, "There should not be a notification");
+
+ clearPendingCrashReports();
+ await SpecialPowers.popPrefEnv();
+
await SpecialPowers.pushPrefEnv({
set: [
["browser.crashReports.unsubmittedCheck.enabled", true],
],
});
UnsubmittedCrashHandler.init();
registerCleanupFunction(function() {