Bug 1424373 - Don't set crash reporting prefs when showing about:tabcrashed for a crash without a report. r=Mossop, a=jcristau
authorMike Conley <mconley@mozilla.com>
Mon, 18 Dec 2017 11:19:53 -0500
changeset 445432 0ef7163b1248c561490ae595c8ee7a9d997c5a7f
parent 445431 13b3ee92ee381296b05ff6a0c66ad153558cf3c0
child 445433 e7e0bfcbc0404e00ceb94b8533943aec518a60b8
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMossop, jcristau
bugs1424373
milestone58.0
Bug 1424373 - Don't set crash reporting prefs when showing about:tabcrashed for a crash without a report. r=Mossop, a=jcristau
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 {