Bug 1399796 - UnsubmittedCrashHandler should never check for unsubmitted crash reports if disabled or suppressed. r=Felipe
authorMike Conley <mconley@mozilla.com>
Fri, 15 Sep 2017 09:25:04 -0700
changeset 665699 c3c6406d94b5bf317aa0bf35068c6f1aaeb4f45a
parent 665698 e65c63e20f93eda01cee102363f61cc5d50e55f6
child 665700 dd653d5758d5cdbdc22e942eb54468a12400aa5c
push id80148
push userbmo:emilio@crisal.io
push dateFri, 15 Sep 2017 20:59:22 +0000
reviewersFelipe
bugs1399796, 1355492
milestone57.0a1
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
browser/modules/ContentCrashHandlers.jsm
browser/modules/test/browser/browser_UnsubmittedCrashHandler.js
--- 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() {