Bug 1378036 - Factor out a utility method for about:tabcrashed tests. r?felipe draft
authorMike Conley <mconley@mozilla.com>
Mon, 17 Jul 2017 18:25:58 -0400
changeset 611504 d7db44ea97f74305ea64b0fdbca966152fca92bd
parent 611503 f5df2dde956c87e08d76e8fed15f1815141afcae
child 611505 6578361532cbbd12c8dbb27984b18a3b8cf50d6c
push id69247
push usermconley@mozilla.com
push dateWed, 19 Jul 2017 20:41:46 +0000
reviewersfelipe
bugs1378036
milestone56.0a1
Bug 1378036 - Factor out a utility method for about:tabcrashed tests. r?felipe MozReview-Commit-ID: 6JAicvHdFlV
browser/base/content/test/tabcrashed/browser_clearEmail.js
browser/base/content/test/tabcrashed/browser_shown.js
browser/base/content/test/tabcrashed/head.js
--- a/browser/base/content/test/tabcrashed/browser_clearEmail.js
+++ b/browser/base/content/test/tabcrashed/browser_clearEmail.js
@@ -1,41 +1,20 @@
 "use strict";
 
-const SERVER_URL = "http://example.com/browser/toolkit/crashreporter/test/browser/crashreport.sjs";
 const PAGE = "data:text/html,<html><body>A%20regular,%20everyday,%20normal%20page.";
 const EMAIL = "foo@privacy.com";
 
-/**
- * Sets up the browser to send crash reports to the local crash report
- * testing server.
- */
 add_task(async function setup() {
-  // The test harness sets MOZ_CRASHREPORTER_NO_REPORT, which disables crash
-  // reports.  This test needs them enabled.  The test also needs a mock
-  // report server, and fortunately one is already set up by toolkit/
-  // crashreporter/test/Makefile.in.  Assign its URL to MOZ_CRASHREPORTER_URL,
-  // which CrashSubmit.jsm uses as a server override.
-  let env = Cc["@mozilla.org/process/environment;1"]
-              .getService(Components.interfaces.nsIEnvironment);
-  let noReport = env.get("MOZ_CRASHREPORTER_NO_REPORT");
-  let serverUrl = env.get("MOZ_CRASHREPORTER_URL");
-  env.set("MOZ_CRASHREPORTER_NO_REPORT", "");
-  env.set("MOZ_CRASHREPORTER_URL", SERVER_URL);
-
+  await setupLocalCrashReportServer();
   // By default, requesting the email address of the user is disabled.
   // For the purposes of this test, we turn it back on.
   await SpecialPowers.pushPrefEnv({
     set: [["browser.tabs.crashReporting.requestEmail", true]],
   });
-
-  registerCleanupFunction(function() {
-    env.set("MOZ_CRASHREPORTER_NO_REPORT", noReport);
-    env.set("MOZ_CRASHREPORTER_URL", serverUrl);
-  });
 });
 
 /**
  * Test that if we have an email address stored in prefs, and we decide
  * not to submit the email address in the next crash report, that we
  * clear the email address.
  */
 add_task(async function test_clear_email() {
--- a/browser/base/content/test/tabcrashed/browser_shown.js
+++ b/browser/base/content/test/tabcrashed/browser_shown.js
@@ -1,41 +1,16 @@
 "use strict";
 
-const SERVER_URL = "http://example.com/browser/toolkit/crashreporter/test/browser/crashreport.sjs";
 const PAGE = "data:text/html,<html><body>A%20regular,%20everyday,%20normal%20page.";
 const COMMENTS = "Here's my test comment!";
 const EMAIL = "foo@privacy.com";
 
-/**
- * Sets up the browser to send crash reports to the local crash report
- * testing server.
- */
 add_task(async function setup() {
-  // The test harness sets MOZ_CRASHREPORTER_NO_REPORT, which disables crash
-  // reports.  This test needs them enabled.  The test also needs a mock
-  // report server, and fortunately one is already set up by toolkit/
-  // crashreporter/test/Makefile.in.  Assign its URL to MOZ_CRASHREPORTER_URL,
-  // which CrashSubmit.jsm uses as a server override.
-  let env = Cc["@mozilla.org/process/environment;1"]
-              .getService(Components.interfaces.nsIEnvironment);
-  let noReport = env.get("MOZ_CRASHREPORTER_NO_REPORT");
-  let serverUrl = env.get("MOZ_CRASHREPORTER_URL");
-  env.set("MOZ_CRASHREPORTER_NO_REPORT", "");
-  env.set("MOZ_CRASHREPORTER_URL", SERVER_URL);
-
-  // On debug builds, crashing tabs results in much thinking, which
-  // slows down the test and results in intermittent test timeouts,
-  // so we'll pump up the expected timeout for this test.
-  requestLongerTimeout(2);
-
-  registerCleanupFunction(function() {
-    env.set("MOZ_CRASHREPORTER_NO_REPORT", noReport);
-    env.set("MOZ_CRASHREPORTER_URL", serverUrl);
-  });
+  await setupLocalCrashReportServer();
 });
 
 /**
  * This function returns a Promise that resolves once the following
  * actions have taken place:
  *
  * 1) A new tab is opened up at PAGE
  * 2) The tab is crashed
--- a/browser/base/content/test/tabcrashed/head.js
+++ b/browser/base/content/test/tabcrashed/head.js
@@ -91,8 +91,33 @@ function getPropertyBagValue(bag, key) {
   } catch (e) {
     if (e.result != Cr.NS_ERROR_FAILURE) {
       throw e;
     }
   }
 
   return null;
 }
+
+/**
+ * Sets up the browser to send crash reports to the local crash report
+ * testing server.
+ */
+async function setupLocalCrashReportServer() {
+  const SERVER_URL = "http://example.com/browser/toolkit/crashreporter/test/browser/crashreport.sjs";
+
+  // The test harness sets MOZ_CRASHREPORTER_NO_REPORT, which disables crash
+  // reports.  This test needs them enabled.  The test also needs a mock
+  // report server, and fortunately one is already set up by toolkit/
+  // crashreporter/test/Makefile.in.  Assign its URL to MOZ_CRASHREPORTER_URL,
+  // which CrashSubmit.jsm uses as a server override.
+  let env = Cc["@mozilla.org/process/environment;1"]
+              .getService(Components.interfaces.nsIEnvironment);
+  let noReport = env.get("MOZ_CRASHREPORTER_NO_REPORT");
+  let serverUrl = env.get("MOZ_CRASHREPORTER_URL");
+  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);
+  });
+}