diff --git a/browser/base/content/test/tabcrashed/browser_clearEmail.js b/browser/base/content/test/tabcrashed/browser_clearEmail.js index 2c8c9ba02e6e..0aa89881b586 100644 --- a/browser/base/content/test/tabcrashed/browser_clearEmail.js +++ b/browser/base/content/test/tabcrashed/browser_clearEmail.js @@ -1,36 +1,15 @@ "use strict"; -const SERVER_URL = "http://example.com/browser/toolkit/crashreporter/test/browser/crashreport.sjs"; const PAGE = "data:text/html,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); - }); }); /** diff --git a/browser/base/content/test/tabcrashed/browser_shown.js b/browser/base/content/test/tabcrashed/browser_shown.js index 1c71b76e4fb6..3ccb4a9512f4 100644 --- a/browser/base/content/test/tabcrashed/browser_shown.js +++ b/browser/base/content/test/tabcrashed/browser_shown.js @@ -1,36 +1,11 @@ "use strict"; -const SERVER_URL = "http://example.com/browser/toolkit/crashreporter/test/browser/crashreport.sjs"; const PAGE = "data:text/html,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(); }); /** diff --git a/browser/base/content/test/tabcrashed/head.js b/browser/base/content/test/tabcrashed/head.js index 87e32b41a96a..5718591b6c69 100644 --- a/browser/base/content/test/tabcrashed/head.js +++ b/browser/base/content/test/tabcrashed/head.js @@ -96,3 +96,28 @@ function getPropertyBagValue(bag, key) { 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); + }); +}