Bug 1424373 - Don't set crash reporting prefs when showing about:tabcrashed for a crash without a report. r=Mossop
authorMike Conley <mconley@mozilla.com>
Mon, 18 Dec 2017 11:19:53 -0500
changeset 396740 fb2acbf403de48072409030e72ad61edbed9f803
parent 396739 e3d4a5930118af61fa56b720a190ede07d184462
child 396741 7c4579e705c4a3a3610183fe6f44affff3ad57ef
child 396808 081472be4c0e5885c3365025ada84e98218fcea7
push id33110
push userrgurzau@mozilla.com
push dateMon, 18 Dec 2017 21:58:12 +0000
treeherdermozilla-central@7c4579e705c4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMossop
bugs1424373
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1424373 - Don't set crash reporting prefs when showing about:tabcrashed for a crash without a report. r=Mossop
browser/base/content/aboutTabCrashed.js
browser/base/content/test/tabcrashed/browser_autoSubmitRequest.js
browser/base/content/test/tabcrashed/browser_withoutDump.js
browser/base/content/test/tabcrashed/head.js
browser/modules/ContentCrashHandlers.jsm
--- a/browser/base/content/aboutTabCrashed.js
+++ b/browser/base/content/aboutTabCrashed.js
@@ -298,13 +298,14 @@ var AboutTabCrashed = {
     sendAsyncMessage(messageName, {
       sendReport,
       comments,
       email,
       emailMe,
       includeURL,
       URL,
       autoSubmit,
+      hasReport: this.hasReport,
     });
   },
 };
 
 AboutTabCrashed.init();
--- a/browser/base/content/test/tabcrashed/browser_autoSubmitRequest.js
+++ b/browser/base/content/test/tabcrashed/browser_autoSubmitRequest.js
@@ -16,17 +16,17 @@ requestLongerTimeout(2);
  * backlogged crash reports, that we offer to do that, and
  * that the user can accept that offer.
  */
 add_task(async function test_show_form() {
   await SpecialPowers.pushPrefEnv({
     set: [[AUTOSUBMIT_PREF, false]],
   });
 
-  return BrowserTestUtils.withNewTab({
+  await BrowserTestUtils.withNewTab({
     gBrowser,
     url: PAGE,
   }, async function(browser) {
     // Make sure we've flushed the browser messages so that
     // we can restore it.
     await TabStateFlusher.flush(browser);
 
     // Now crash the browser.
@@ -64,17 +64,17 @@ add_task(async function test_show_form()
  * Tests that if the user is autosubmitting backlogged crash reports
  * that we don't make the offer again.
  */
 add_task(async function test_show_form() {
   await SpecialPowers.pushPrefEnv({
     set: [[AUTOSUBMIT_PREF, true]],
   });
 
-  return BrowserTestUtils.withNewTab({
+  await BrowserTestUtils.withNewTab({
     gBrowser,
     url: PAGE,
   }, async function(browser) {
     await TabStateFlusher.flush(browser);
     // Now crash the browser.
     await BrowserTestUtils.crashBrowser(browser);
 
     // eslint-disable-next-line mozilla/no-cpows-in-tests
@@ -92,8 +92,63 @@ add_task(async function test_show_form()
 
     await BrowserTestUtils.browserLoaded(browser, false, PAGE);
 
     // The autosubmission pref should still be set to true.
     Assert.ok(Services.prefs.getBoolPref(AUTOSUBMIT_PREF),
               "Autosubmission pref should have been set.");
   });
 });
+
+/**
+ * Tests that we properly set the autoSubmit preference if the user is
+ * presented with a tabcrashed page without a crash report.
+ */
+add_task(async function test_no_offer() {
+  // We should default to sending the report.
+  Assert.ok(TabCrashHandler.prefs.getBoolPref("sendReport"));
+
+  await SpecialPowers.pushPrefEnv({
+    set: [[AUTOSUBMIT_PREF, false]],
+  });
+
+  await BrowserTestUtils.withNewTab({
+    gBrowser,
+    url: PAGE,
+  }, async function(browser) {
+    await TabStateFlusher.flush(browser);
+
+    // Make it so that it seems like no dump is available for the next crash.
+    prepareNoDump();
+
+    // Now crash the browser.
+    await BrowserTestUtils.crashBrowser(browser);
+
+    // eslint-disable-next-line mozilla/no-cpows-in-tests
+    let doc = browser.contentDocument;
+
+    // Ensure the request to autosubmit is invisible, since there's no report.
+    let requestRect = doc.getElementById("requestAutoSubmit")
+                         .getBoundingClientRect();
+    Assert.equal(0, requestRect.height,
+                 "Request for autosubmission has no height");
+    Assert.equal(0, requestRect.width,
+                 "Request for autosubmission has no width");
+
+    // Since the pref is set to false, the checkbox should be
+    // unchecked.
+    let autoSubmit = doc.getElementById("autoSubmit");
+    Assert.ok(!autoSubmit.checked,
+              "Checkbox for autosubmission is not checked.");
+
+    let restoreButton = doc.getElementById("restoreTab");
+    restoreButton.click();
+
+    await BrowserTestUtils.browserLoaded(browser, false, PAGE);
+
+    // The autosubmission pref should now be set.
+    Assert.ok(!Services.prefs.getBoolPref(AUTOSUBMIT_PREF),
+              "Autosubmission pref should not have changed.");
+  });
+
+  // We should not have changed the default value for sending the report.
+  Assert.ok(TabCrashHandler.prefs.getBoolPref("sendReport"));
+});
--- a/browser/base/content/test/tabcrashed/browser_withoutDump.js
+++ b/browser/base/content/test/tabcrashed/browser_withoutDump.js
@@ -1,22 +1,14 @@
 "use strict";
 
 const PAGE = "data:text/html,<html><body>A%20regular,%20everyday,%20normal%20page.";
 
-/**
- * Monkey patches TabCrashHandler.getDumpID to return null in order to test
- * about:tabcrashed when a dump is not available.
- */
 add_task(async function setup() {
-  let originalGetDumpID = TabCrashHandler.getDumpID;
-  TabCrashHandler.getDumpID = function(browser) { return null; };
-  registerCleanupFunction(() => {
-    TabCrashHandler.getDumpID = originalGetDumpID;
-  });
+  prepareNoDump();
 });
 
 /**
  * Tests tab crash page when a dump is not available.
  */
 add_task(async function test_without_dump() {
   return BrowserTestUtils.withNewTab({
     gBrowser,
--- a/browser/base/content/test/tabcrashed/head.js
+++ b/browser/base/content/test/tabcrashed/head.js
@@ -116,8 +116,20 @@ async function setupLocalCrashReportServ
   env.set("MOZ_CRASHREPORTER_NO_REPORT", "");
   env.set("MOZ_CRASHREPORTER_URL", SERVER_URL);
 
   registerCleanupFunction(function() {
     env.set("MOZ_CRASHREPORTER_NO_REPORT", noReport);
     env.set("MOZ_CRASHREPORTER_URL", serverUrl);
   });
 }
+
+/**
+ * Monkey patches TabCrashHandler.getDumpID to return null in order to test
+ * about:tabcrashed when a dump is not available.
+ */
+function prepareNoDump() {
+  let originalGetDumpID = TabCrashHandler.getDumpID;
+  TabCrashHandler.getDumpID = function(browser) { return null; };
+  registerCleanupFunction(() => {
+    TabCrashHandler.getDumpID = originalGetDumpID;
+  });
+}
--- a/browser/modules/ContentCrashHandlers.jsm
+++ b/browser/modules/ContentCrashHandlers.jsm
@@ -363,31 +363,38 @@ this.TabCrashHandler = {
    *          The email address of the user.
    *        comments (String):
    *          Any additional comments from the user.
    *
    *        Note that it is expected that all properties are set,
    *        even if they are empty.
    */
   maybeSendCrashReport(message) {
-    if (!AppConstants.MOZ_CRASHREPORTER)
+    if (!AppConstants.MOZ_CRASHREPORTER) {
       return;
+    }
+
+    if (!message.data.hasReport) {
+      // There was no report, so nothing to do.
+      return;
+    }
 
     let browser = message.target.browser;
 
     if (message.data.autoSubmit) {
       // The user has opted in to autosubmitted backlogged
       // crash reports in the future.
       UnsubmittedCrashHandler.autoSubmit = true;
     }
 
     let childID = this.browserMap.get(browser);
     let dumpID = this.childMap.get(childID);
-    if (!dumpID)
+    if (!dumpID) {
       return;
+    }
 
     if (!message.data.sendReport) {
       Services.telemetry.getHistogramById("FX_CONTENT_CRASH_NOT_SUBMITTED").add(1);
       this.prefs.setBoolPref("sendReport", false);
       return;
     }
 
     let {