Bug 1199844 - limit webapp debug logging to webapp tests; r=fabrice
authorMyk Melez <myk@mozilla.org>
Sun, 30 Aug 2015 13:30:21 -0700
changeset 260044 852042d67f3892293b52a0b251173c9dd5cf818f
parent 260043 4ff42aa327c39115013d5ce30a791d9b2fe8f849
child 260045 f2518b8a7b97b5bb477e94bc9131584007aac887
child 260079 4ceab182385ba966deb8ae03fd3b45c8a04468c0
push id29298
push userryanvm@gmail.com
push dateMon, 31 Aug 2015 02:09:10 +0000
treeherdermozilla-central@f2518b8a7b97 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfabrice
bugs1199844
milestone43.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 1199844 - limit webapp debug logging to webapp tests; r=fabrice
dom/apps/Langpacks.jsm
dom/apps/Webapps.jsm
dom/apps/tests/chrome.ini
dom/apps/tests/common.js
dom/apps/tests/mochitest.ini
dom/apps/tests/test_app_addons.html
dom/apps/tests/test_app_enabled.html
dom/apps/tests/test_app_update.html
dom/apps/tests/test_bug_1168300.html
dom/apps/tests/test_bug_795164.html
dom/apps/tests/test_bug_945152.html
dom/apps/tests/test_checkInstalled.html
dom/apps/tests/test_import_export.html
dom/apps/tests/test_install_dev_mode.html
dom/apps/tests/test_install_multiple_apps_origin.html
dom/apps/tests/test_install_receipts.html
dom/apps/tests/test_langpacks.html
dom/apps/tests/test_marketplace_pkg_install.html
dom/apps/tests/test_operator_app_install.js
dom/apps/tests/test_operator_app_install.xul
dom/apps/tests/test_packaged_app_asmjs.html
dom/apps/tests/test_packaged_app_install.html
dom/apps/tests/test_packaged_app_update.html
dom/apps/tests/test_receipt_operations.html
dom/apps/tests/test_signed_pkg_install.html
dom/apps/tests/test_theme_role.html
dom/apps/tests/test_third_party_homescreen.html
dom/apps/tests/test_uninstall_errors.html
dom/apps/tests/test_web_app_install.html
dom/apps/tests/test_widget.html
dom/apps/tests/test_widget_browser.html
dom/apps/tests/unit/head.js
dom/apps/tests/unit/tail.js
dom/apps/tests/unit/test_has_widget_criterion.js
dom/apps/tests/unit/test_inter_app_comm_service.js
dom/apps/tests/unit/test_moziapplication.js
dom/apps/tests/unit/xpcshell.ini
testing/profiles/prefs_general.js
toolkit/webapps/tests/head.js
toolkit/webapps/tests/test_custom_origin.xul
toolkit/webapps/tests/test_custom_origin_uninstall_install.xul
toolkit/webapps/tests/test_hosted.xul
toolkit/webapps/tests/test_hosted_checkforupdates_from_webapp_runtime.xul
toolkit/webapps/tests/test_hosted_icons.xul
toolkit/webapps/tests/test_hosted_launch.xul
toolkit/webapps/tests/test_hosted_launch_no_registry.xul
toolkit/webapps/tests/test_hosted_uninstall.xul
toolkit/webapps/tests/test_hosted_update_from_webapp_runtime.xul
toolkit/webapps/tests/test_install_appcache.xul
toolkit/webapps/tests/test_non_ascii_app_name.xul
toolkit/webapps/tests/test_packaged.xul
toolkit/webapps/tests/test_packaged_checkforupdates_from_webapp_runtime.xul
toolkit/webapps/tests/test_packaged_icons.xul
toolkit/webapps/tests/test_packaged_launch.xul
toolkit/webapps/tests/test_packaged_launch_no_registry.xul
toolkit/webapps/tests/test_packaged_uninstall.xul
toolkit/webapps/tests/test_packaged_update_from_webapp_runtime.xul
toolkit/webapps/tests/test_webapp_runtime_executable_update.xul
--- a/dom/apps/Langpacks.jsm
+++ b/dom/apps/Langpacks.jsm
@@ -13,21 +13,26 @@ Cu.import("resource://gre/modules/Servic
 Cu.import("resource://gre/modules/AppsUtils.jsm");
 
 XPCOMUtils.defineLazyServiceGetter(this, "ppmm",
                                    "@mozilla.org/parentprocessmessagemanager;1",
                                    "nsIMessageBroadcaster");
 
 this.EXPORTED_SYMBOLS = ["Langpacks"];
 
-let debug = Services.prefs.getBoolPref("dom.mozApps.debug")
-  ? (aMsg) => {
-      dump("-*-*- Langpacks: " + aMsg + "\n");
-    }
-  : (aMsg) => {};
+let debug;
+function debugPrefObserver() {
+  debug = Services.prefs.getBoolPref("dom.mozApps.debug")
+            ? (aMsg) => {
+                dump("-*-*- Langpacks: " + aMsg + "\n");
+              }
+            : (aMsg) => {};
+}
+debugPrefObserver();
+Services.prefs.addObserver("dom.mozApps.debug", debugPrefObserver, false);
 
 /**
   * Langpack support
   *
   * Manifest format is:
   *
   * "languages-target" : { "app://*.gaiamobile.org/manifest.webapp": "2.2" },
   * "languages-provided": {
--- a/dom/apps/Webapps.jsm
+++ b/dom/apps/Webapps.jsm
@@ -102,20 +102,24 @@ XPCOMUtils.defineLazyGetter(this, "libcu
 // On Android, define the "debug" function as a binding of the "d" function
 // from the AndroidLog module so it gets the "debug" priority and a log tag.
 // We always report debug messages on Android because it's unnecessary
 // to restrict reporting, per bug 1003469.
 let debug = Cu.import("resource://gre/modules/AndroidLog.jsm", {})
               .AndroidLog.d.bind(null, "Webapps");
 #else
 // Elsewhere, report debug messages only if dom.mozApps.debug is set to true.
-// The pref is only checked once, on startup, so restart after changing it.
-let debug = Services.prefs.getBoolPref("dom.mozApps.debug")
-              ? (aMsg) => dump("-*- Webapps.jsm : " + aMsg + "\n")
-              : (aMsg) => {};
+let debug;
+function debugPrefObserver() {
+  debug = Services.prefs.getBoolPref("dom.mozApps.debug")
+            ? (aMsg) => dump("-*- Webapps.jsm : " + aMsg + "\n")
+            : (aMsg) => {};
+}
+debugPrefObserver();
+Services.prefs.addObserver("dom.mozApps.debug", debugPrefObserver, false);
 #endif
 
 function getNSPRErrorCode(err) {
   return -1 * ((err) & 0xffff);
 }
 
 function supportUseCurrentProfile() {
   return Services.prefs.getBoolPref("dom.webapps.useCurrentProfile");
--- a/dom/apps/tests/chrome.ini
+++ b/dom/apps/tests/chrome.ini
@@ -1,12 +1,13 @@
 [DEFAULT]
 skip-if = buildapp == 'b2g' || os == 'android'
 support-files =
   asmjs/*
+  common.js
   file_bug_945152.html
   file_bug_945152.sjs
 
 [test_apps_service.xul]
 [test_bug_945152.html]
 skip-if = os != 'linux'
 [test_manifest_helper.xul]
 [test_operator_app_install.js]
new file mode 100644
--- /dev/null
+++ b/dom/apps/tests/common.js
@@ -0,0 +1,3 @@
+function prepareEnv(cb) {
+  SpecialPowers.pushPrefEnv({"set":[["dom.mozApps.debug", true]]}, cb);
+}
--- a/dom/apps/tests/mochitest.ini
+++ b/dom/apps/tests/mochitest.ini
@@ -3,16 +3,17 @@ skip-if = e10s
 support-files =
   addons/application.zip
   addons/invalid.webapp
   addons/invalid.webapp^headers^
   addons/update.webapp
   addons/update.webapp^headers^
   addons/index.html
   chromeAddCert.js
+  common.js
   file_app.sjs
   file_app.template.html
   file_script.template.js
   file_cached_app.template.appcache
   file_cached_app.template.webapp
   file_hosted_app.template.webapp
   file_hosted_certified.webapp
   file_hosted_certified.webapp^headers^
--- a/dom/apps/tests/test_app_addons.html
+++ b/dom/apps/tests/test_app_addons.html
@@ -2,16 +2,17 @@
 https://bugzilla.mozilla.org/show_bug.cgi?id=1042881
 -->
 <html>
   <head>
   <meta charset="utf-8">
   <title>Test for Bug 923897 - Test apps as addons</title>
   <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="common.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
   <script type="application/javascript;version=1.7">
 /**
   * Test for Bug 923897
   * This file covers testing addons.
   *
   * The setup is as follows:
   * - app is installed and offers both script and css to inject in
@@ -198,17 +199,17 @@ function runTest() {
   openPage("http://mochi.test:8888/tests/dom/apps/tests/addons/index.html",
     ["Lorem ipsum", "rgb(0, 0, 0)",
      "Uncustomized content", "rgb(0, 0, 0)"]);
   yield undefined;
 }
 
   </script>
   </head>
-<body onload="go()">
+<body onload="prepareEnv(go)">
 <p id="display"></p>
 <div id="content" style="display: none">
 </div>
 <pre id="test">
 </pre>
 <div id="container"></div>
 </body>
 </html>
--- a/dom/apps/tests/test_app_enabled.html
+++ b/dom/apps/tests/test_app_enabled.html
@@ -2,16 +2,17 @@
 <html>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id={1XXXXXX}
 -->
 <head>
   <title>Test for Bug {1072090}</title>
   <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="common.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
 
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id={1072090}">Mozilla Bug {1072090}</a>
 <p id="display"></p>
 <div id="content" style="display: none">
 
@@ -116,14 +117,14 @@ function runTest() {
 
   request = navigator.mozApps.mgmt.getAll();
   request.onerror = cbError;
   request.onsuccess = continueTest;
   yield undefined;
   is(request.result.length, initialAppsCount, "All apps are uninstalled.");
 }
 
-addLoadEvent(go);
+addLoadEvent(() => prepareEnv(go));
 
 </script>
 </pre>
 </body>
 </html>
--- a/dom/apps/tests/test_app_update.html
+++ b/dom/apps/tests/test_app_update.html
@@ -2,16 +2,17 @@
 <html>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=826058
 -->
 <head>
   <meta charset="utf-8">
   <title>Test for Bug 826058</title>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="common.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
   <script type="application/javascript;version=1.7">
 
   /** Test for Bug 826058 **/
 
   SimpleTest.waitForExplicitFinish();
 
   var gBaseURL = 'http://test/tests/dom/apps/tests/';
@@ -273,17 +274,17 @@ https://bugzilla.mozilla.org/show_bug.cg
   }
 
   function doReload() {
     window.location.reload(true);
   }
 
   </script>
 </head>
-<body onload="go()">
+<body onload="prepareEnv(go)">
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=826058">Mozilla Bug 826058</a>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=863337">Mozilla Bug 863337</a>
 <p id="display"></p>
 <div id="content" style="display: none">
 
 </div>
 <pre id="test">
 </pre>
--- a/dom/apps/tests/test_bug_1168300.html
+++ b/dom/apps/tests/test_bug_1168300.html
@@ -2,16 +2,17 @@
 <html>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=1168300
 -->
 <head>
   <meta charset="utf-8">
   <title>Test for Bug 1168300</title>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="common.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
   <script type="application/javascript;version=1.7">
 
   /** Test for Bug 1168300 **/
 
   SimpleTest.waitForExplicitFinish();
 
   var url = "http://test/tests/dom/apps/tests/file_manifest.json";
@@ -106,17 +107,17 @@ https://bugzilla.mozilla.org/show_bug.cg
     set onobserve (callback) {
       this.callback = callback;
     }
   };
 
   SimpleTest.waitForExplicitFinish();
   </script>
 </head>
-<body onload="go()">
+<body onload="prepareEnv(go)">
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1168300">Mozilla Bug 1168300</a>
 <p id="display"></p>
 <div id="content" style="display: none">
 
 </div>
 <pre id="test">
 </pre>
 </body>
--- a/dom/apps/tests/test_bug_795164.html
+++ b/dom/apps/tests/test_bug_795164.html
@@ -2,16 +2,17 @@
 <html>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=795164
 -->
 <head>
   <meta charset="utf-8">
   <title>Test for Bug 795164</title>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="common.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
   <script type="application/javascript;version=1.7">
 
   /** Test for Bug 795164 **/
 
   SimpleTest.waitForExplicitFinish();
 
   var url1 = 'http://test1.example.com/tests/dom/apps/tests/file_app.sjs?apptype=hosted&getmanifest=true';
@@ -91,17 +92,17 @@ https://bugzilla.mozilla.org/show_bug.cg
     yield undefined;
 
     is(uninstallCount, 2, "mgmt.onuninstall got triggered only twice");
 
     navigator.mozApps.mgmt.onuninstall = null;
   }
   </script>
 </head>
-<body onload="go()">
+<body onload="prepareEnv(go)">
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=795164">Mozilla Bug 795164</a>
 <p id="display"></p>
 <div id="content" style="display: none">
 
 </div>
 <pre id="test">
 </pre>
 </body>
--- a/dom/apps/tests/test_bug_945152.html
+++ b/dom/apps/tests/test_bug_945152.html
@@ -2,16 +2,17 @@
 <html>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=945152
 -->
 <head>
   <meta charset="utf-8">
   <title>Test for Bug 945152</title>
   <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="common.js"></script>
   <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
   <script type="application/javascript;version=1.7">
 
   const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
 
   SimpleTest.waitForExplicitFinish();
 
   const gBaseURL = 'http://test/chrome/dom/apps/tests/';
@@ -157,17 +158,17 @@ https://bugzilla.mozilla.org/show_bug.cg
   }
 
   function finish() {
     SimpleTest.finish();
   }
 
   </script>
 </head>
-<body onload="go()">
+<body onload="prepareEnv(go)">
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=945152">Mozilla Bug 945152</a>
 <p id="display"></p>
 <div id="content" style="display: none">
 </div>
 <pre id="test">
 </pre>
 <div id="container"></div>
 </body>
--- a/dom/apps/tests/test_checkInstalled.html
+++ b/dom/apps/tests/test_checkInstalled.html
@@ -2,16 +2,17 @@
 <html>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id={1191516}
 -->
 <head>
   <title>Test for Bug {1191516}</title>
   <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="common.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
 
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id={1191516}">Mozilla Bug {1191516}</a>
 <p id="display"></p>
 <div id="content" style="display: none">
 
@@ -87,14 +88,14 @@ function runTest() {
   yield undefined;
 
   request = navigator.mozApps.mgmt.uninstall(app);
   request.onerror = cbError;
   request.onsuccess = continueTest;
   yield undefined;
 }
 
-addLoadEvent(go);
+addLoadEvent(() => prepareEnv(go));
 
 </script>
 </pre>
 </body>
 </html>
--- a/dom/apps/tests/test_import_export.html
+++ b/dom/apps/tests/test_import_export.html
@@ -2,16 +2,17 @@
 <html>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id={982874}
 -->
 <head>
   <title>Test for Bug {982874}</title>
   <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="common.js"></script>
   <script type="text/javascript" src="test_packaged_app_common.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
 
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id={982874}">Mozilla Bug {982874}</a>
 <p id="display"></p>
 <div id="content" style="display: none">
@@ -317,14 +318,14 @@ function runTest() {
   // Check that we restored the app registry.
   request = navigator.mozApps.mgmt.getAll();
   request.onerror = cbError;
   request.onsuccess = continueTest;
   yield undefined;
   is(request.result.length, initialAppsCount, "All apps are uninstalled.");
 }
 
-addLoadEvent(go);
+addLoadEvent(() => prepareEnv(go));
 
 </script>
 </pre>
 </body>
 </html>
--- a/dom/apps/tests/test_install_dev_mode.html
+++ b/dom/apps/tests/test_install_dev_mode.html
@@ -2,16 +2,17 @@
 <html>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id={1111961}
 -->
 <head>
   <title>Test for Bug {1111961}</title>
   <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="common.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
 
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id={1111961}">Mozilla Bug {1111961}</a>
 <p id="display"></p>
 <div id="content" style="display: none">
 
@@ -109,14 +110,14 @@ function runTest() {
 
   request = navigator.mozApps.mgmt.getAll();
   request.onerror = cbError;
   request.onsuccess = continueTest;
   yield undefined;
   is(request.result.length, initialAppsCount, "All apps are uninstalled.");
 }
 
-addLoadEvent(go);
+addLoadEvent(() => prepareEnv(go));
 
 </script>
 </pre>
 </body>
 </html>
--- a/dom/apps/tests/test_install_multiple_apps_origin.html
+++ b/dom/apps/tests/test_install_multiple_apps_origin.html
@@ -2,16 +2,17 @@
 <html>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id={778277}
 -->
 <head>
   <title>Test for Bug {778277}</title>
   <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="common.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
 
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id={778277}">Mozilla Bug {778277}</a>
 <p id="display"></p>
 <div id="content" style="display: none">
 
@@ -111,14 +112,14 @@ function runTest() {
 
   request = navigator.mozApps.mgmt.getAll();
   request.onerror = cbError;
   request.onsuccess = continueTest;
   yield undefined;
   is(request.result.length, initialAppsCount, "All apps are uninstalled.");
 }
 
-addLoadEvent(go);
+addLoadEvent(() => prepareEnv(go));
 
 </script>
 </pre>
 </body>
 </html>
--- a/dom/apps/tests/test_install_receipts.html
+++ b/dom/apps/tests/test_install_receipts.html
@@ -2,16 +2,17 @@
 <html>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id={960837}
 -->
 <head>
   <title>Test for Bug {960837}</title>
   <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="common.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
 
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id={960837}">Mozilla Bug {960837}</a>
 <p id="display"></p>
 <div id="content" style="display: none">
 
@@ -201,14 +202,14 @@ function runTest() {
   request.onerror = function() {
     ok(this.error.name == "INVALID_SEGMENTS_NUMBER",
        "Less than 3 segments");
     continueTest();
   }
   yield undefined;
 }
 
-addLoadEvent(go);
+addLoadEvent(() => prepareEnv(go));
 
 </script>
 </pre>
 </body>
 </html>
--- a/dom/apps/tests/test_langpacks.html
+++ b/dom/apps/tests/test_langpacks.html
@@ -2,16 +2,17 @@
 https://bugzilla.mozilla.org/show_bug.cgi?id=1108096
 -->
 <html>
   <head>
   <meta charset="utf-8">
   <title>Test for Bug 1108096 - Langpack support</title>
   <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="common.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
   <script type="application/javascript;version=1.7">
 /**
   * Test for Bug 1108096
   * This file covers testing langpacks.
   *
   * The setup is as follows:
   * - app is the localizable application.
@@ -300,17 +301,17 @@ function runTest() {
     req.onsuccess = continueTest;
     req.onerror = mozAppsError;
     yield undefined;
   }
 }
 
   </script>
   </head>
-<body onload="go()">
+<body onload="prepareEnv(go)">
 <p id="display"></p>
 <div id="content" style="display: none">
 </div>
 <pre id="test">
 </pre>
 <div id="container"></div>
 </body>
 </html>
--- a/dom/apps/tests/test_marketplace_pkg_install.html
+++ b/dom/apps/tests/test_marketplace_pkg_install.html
@@ -4,16 +4,17 @@
 https://bugzilla.mozilla.org/show_bug.cgi?id=989806
 -->
 <head>
   <meta charset="utf-8">
   <title>Test for Bug 989806</title>
   <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <script type="text/javascript" src="test_packaged_app_common.js"></script>
+  <script type="text/javascript" src="common.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
 
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=989806">Mozilla Bug 989806</a>
 <p id="display"></p>
 <div id="content" style="display: none">
 
@@ -336,15 +337,15 @@ PackagedTestHelper.setSteps([
     checkAppOnInstallSuccess(expected);
     installApp(gMarketplaceStageInstallOrigin, miniManifestURL);
   },
   function() {
     PackagedTestHelper.finish();
   }
 ]);
 
-addLoadEvent(PackagedTestHelper.start);
+addLoadEvent(() => prepareEnv(() => PackagedTestHelper.start()));
 
 </script>
 </pre>
 <div id="container"></div>
 </body>
 </html>
--- a/dom/apps/tests/test_operator_app_install.js
+++ b/dom/apps/tests/test_operator_app_install.js
@@ -208,16 +208,19 @@ function checkAppState(aApp,
   if (aCb && typeof aCb === 'function') {
     aCb();
   }
   return;
 }
 
 var steps = [
   function() {
+    prepareEnv(next);
+  },
+  function() {
     setupDataDirs(next);
     ok(true, "Data directory set up to " + singlevariantDir);
   },
   function() {
     ok(true, "autoConfirmAppInstall");
     SpecialPowers.autoConfirmAppInstall(next);
   },
   function() {
--- a/dom/apps/tests/test_operator_app_install.xul
+++ b/dom/apps/tests/test_operator_app_install.xul
@@ -3,16 +3,17 @@
 <?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=893800
 -->
 <window title="Mozilla Bug 893800"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
   <script type="application/javascript"
           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="common.js"/>
 
   <!-- test results are displayed in the html:body -->
   <body xmlns="http://www.w3.org/1999/xhtml">
   <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=893800"
      target="_blank">Mozilla Bug 893800</a>
   </body>
 
   <script type="application/javascript;version=1.7" src="test_operator_app_install.js" />
--- a/dom/apps/tests/test_packaged_app_asmjs.html
+++ b/dom/apps/tests/test_packaged_app_asmjs.html
@@ -5,16 +5,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 -->
 <head>
   <meta charset="utf-8">
   <title>Test for Bug 997886 - Test installing and updating apps with asm.js pre-compiling</title>
   <script type="application/javascript"
           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
   <script type="application/javascript"
           src="chrome://mochikit/content/chrome-harness.js"></script>
+  <script type="application/javascript" src="common.js"></script>
   <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
   <script type="application/javascript;version=1.7">
 
 const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
 
 SimpleTest.waitForExplicitFinish();
 
 const gBaseURL = 'http://test/chrome/dom/apps/tests/asmjs/';
@@ -224,17 +225,17 @@ function runTest() {
   request = navigator.mozApps.mgmt.uninstall(app);
   request.onerror = mozAppsError;
   request.onsuccess = continueTest;
   yield undefined;
 }
 
   </script>
 </head>
-<body onload="go()">
+<body onload="prepareEnv(go)">
 <p id="display"></p>
 <div id="content" style="display: none">
 </div>
 <pre id="test">
 </pre>
 <div id="container"></div>
 </body>
 </html>
--- a/dom/apps/tests/test_packaged_app_install.html
+++ b/dom/apps/tests/test_packaged_app_install.html
@@ -2,16 +2,17 @@
 <html>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id={821589}
 -->
 <head>
   <title>Test for Bug {821589} Packaged apps installation and update</title>
   <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="common.js"></script>
   <script type="text/javascript" src="test_packaged_app_common.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
 
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id={821589}">Mozilla Bug {821589}</a>
 <p id="display"></p>
 <div id="content" style="display: none">
@@ -342,14 +343,14 @@ var steps = [
   function() {
     info("all done!\n");
     PackagedTestHelper.finish();
   }
 ];
 
 PackagedTestHelper.setSteps(steps);
 
-addLoadEvent(PackagedTestHelper.start);
+addLoadEvent(() => prepareEnv(() => PackagedTestHelper.start()));
 
 </script>
 </pre>
 </body>
 </html>
--- a/dom/apps/tests/test_packaged_app_update.html
+++ b/dom/apps/tests/test_packaged_app_update.html
@@ -2,16 +2,17 @@
 <html>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id={900533}
 -->
 <head>
   <title>Test for Bug {900533} Packaged app update tests</title>
   <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="common.js"></script>
   <script type="text/javascript" src="test_packaged_app_common.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
 
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id={900533}">Mozilla Bug {900533}</a>
 <p id="display"></p>
 <div id="content" style="display: none">
@@ -341,14 +342,14 @@ var steps = [
 ];
 
 PackagedTestHelper.setSteps(steps);
 // appToUpdate added to the URL so we get a unique URL for this app.
 // Unique in this case meaning different from the ones used on the
 // install tests
 miniManifestURL = PackagedTestHelper.gSJS + "?getManifest=true&appToUpdate&testNameChange";
 
-addLoadEvent(PackagedTestHelper.start);
+addLoadEvent(() => prepareEnv(() => PackagedTestHelper.start()));
 
 </script>
 </pre>
 </body>
 </html>
--- a/dom/apps/tests/test_receipt_operations.html
+++ b/dom/apps/tests/test_receipt_operations.html
@@ -2,16 +2,17 @@
 <html>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id={757226}
 -->
 <head>
   <title>Test for Bug {757226} Implement mozApps app.replaceReceipt</title>
   <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="common.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
 
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id={757226}">Mozilla Bug {757226}</a>
 <p id="display"></p>
 <div id="content" style="display: none">
 
@@ -226,14 +227,14 @@ function runTest() {
   // Uninstall the app.
   request = navigator.mozApps.mgmt.uninstall(app);
   request.onerror = cbError;
   request.onsuccess = continueTest;
   yield undefined;
   ok(true, "App uninstalled");
 }
 
-addLoadEvent(go);
+addLoadEvent(() => prepareEnv(go));
 
 </script>
 </pre>
 </body>
 </html>
--- a/dom/apps/tests/test_signed_pkg_install.html
+++ b/dom/apps/tests/test_signed_pkg_install.html
@@ -3,16 +3,17 @@
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=880043
 -->
 <head>
   <meta charset="utf-8">
   <title>Test for Bug 880043 Packaged apps installation and update</title>
   <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="common.js"></script>
   <script type="text/javascript" src="test_packaged_app_common.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
 
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=880043">Mozilla Bug 880043</a>
 <p id="display"></p>
 <div id="content" style="display: none">
@@ -264,14 +265,14 @@ var steps = [
     info("all done!");
     PackagedTestHelper.finish();
   }
 ];
 
 PackagedTestHelper.setSteps(steps);
 PackagedTestHelper.gSJSPath = gSJSPath;
 
-addLoadEvent(PackagedTestHelper.start);
+addLoadEvent(() => prepareEnv(() => PackagedTestHelper.start()));
 
 </script>
 </pre>
 </body>
 </html>
--- a/dom/apps/tests/test_theme_role.html
+++ b/dom/apps/tests/test_theme_role.html
@@ -2,16 +2,17 @@
 <html>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id={1011738}
 -->
 <head>
   <title>Test for Bug {1011738}</title>
   <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="common.js"></script>
   <script type="text/javascript" src="test_packaged_app_common.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
 
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id={1011738}">Mozilla Bug {1011738}</a>
 <p id="display"></p>
 <div id="content" style="display: none">
@@ -97,14 +98,14 @@ function runTest() {
         ok(false, "We should not install this app!");
         continueTest();
       }
 
     };
   yield undefined;
 }
 
-addLoadEvent(go);
+addLoadEvent(() => prepareEnv(go));
 
 </script>
 </pre>
 </body>
 </html>
--- a/dom/apps/tests/test_third_party_homescreen.html
+++ b/dom/apps/tests/test_third_party_homescreen.html
@@ -2,16 +2,17 @@
 <html>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id={1097468}
 -->
 <head>
   <title>Test for Bug {1097468}</title>
   <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="common.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
 
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id={1097468}">Mozilla Bug {1097468}</a>
 
 <script class="testbody" type="application/javascript;version=1.7">
 
@@ -187,14 +188,14 @@ function runTest() {
   request.onerror = cbError;
   request.onsuccess = continueTest;
   yield undefined;
   yield undefined;
   is(request.result, gManifestURL, "App uninstalled.");
   navigator.mozApps.mgmt.onuninstall = null;
 }
 
-addLoadEvent(go);
+addLoadEvent(() => prepareEnv(go));
 
 </script>
 </pre>
 </body>
 </html>
--- a/dom/apps/tests/test_uninstall_errors.html
+++ b/dom/apps/tests/test_uninstall_errors.html
@@ -3,16 +3,17 @@
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=830258
 -->
 <head>
   <meta charset="utf-8">
   <title>Test for Bug 830258</title>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="text/javascript" src="common.js"></script>
   <script type="application/javascript;version=1.7">
 
   /** Test for Bug 830258 **/
 
   SimpleTest.waitForExplicitFinish();
 
   var url1 = 'http://test1.example.com/tests/dom/apps/tests/file_app.sjs?apptype=hosted&getmanifest=true';
   var url2 = 'http://test2.example.com/tests/dom/apps/tests/file_app.sjs?apptype=hosted&getmanifest=true';
@@ -91,17 +92,17 @@ https://bugzilla.mozilla.org/show_bug.cg
     request.onerror = function() {
       ok(false, "Fail to uninstall the app2");
       continueTest();
     };
     yield undefined;
   }
   </script>
 </head>
-<body onload="go()">
+<body onload="prepareEnv(go)">
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=830258">Mozilla Bug 830258</a>
 <p id="display"></p>
 <div id="content" style="display: none">
 
 </div>
 <pre id="test">
 </pre>
 </body>
--- a/dom/apps/tests/test_web_app_install.html
+++ b/dom/apps/tests/test_web_app_install.html
@@ -2,16 +2,17 @@
 <html>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id={1075716}
 -->
 <head>
   <title>Install web app from manifest with application/manifest+json MIME type</title>
   <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="common.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
 
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id={1075716}">Mozilla Bug {1075716}</a>
 <p id="display"></p>
 <div id="content" style="display: none">
 
@@ -160,14 +161,14 @@ function runTest() {
 
   request = navigator.mozApps.mgmt.getAll();
   request.onerror = cbError;
   request.onsuccess = continueTest;
   yield undefined;
   is(request.result.length, initialAppsCount, "Correct number of apps.");
 }
 
-addLoadEvent(go);
+addLoadEvent(() => prepareEnv(go));
 
 </script>
 </pre>
 </body>
 </html>
--- a/dom/apps/tests/test_widget.html
+++ b/dom/apps/tests/test_widget.html
@@ -1,18 +1,19 @@
 <!DOCTYPE HTML>
 <html>
 <head>
   <meta charset="utf-8">
   <title>Test for Widget</title>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <script type="application/javascript" src="file_test_widget.js"></script>
+  <script type="application/javascript" src="common.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
 </head>
 <body>
 <div id="container"></div>
   <script type="application/javascript;version=1.7">
   SimpleTest.waitForExplicitFinish();
   gHasBrowserPermission = false;
-  runTest();
+  prepareEnv(runTest);
   </script>
 </body>
 </html>
--- a/dom/apps/tests/test_widget_browser.html
+++ b/dom/apps/tests/test_widget_browser.html
@@ -1,18 +1,19 @@
 <!DOCTYPE HTML>
 <html>
 <head>
   <meta charset="utf-8">
   <title>Test for DataStore - basic operation on a readonly db</title>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <script type="application/javascript" src="file_test_widget.js"></script>
+  <script type="application/javascript" src="common.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
 </head>
 <body>
 <div id="container"></div>
   <script type="application/javascript;version=1.7">
   SimpleTest.waitForExplicitFinish();
   gHasBrowserPermission = true;
-  runTest();
+  prepareEnv(runTest);
   </script>
 </body>
 </html>
new file mode 100644
--- /dev/null
+++ b/dom/apps/tests/unit/head.js
@@ -0,0 +1,4 @@
+const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
+Cu.import("resource:///modules/Services.jsm");
+var dom_mozApps_debug = Services.prefs.getBoolPref("dom.mozApps.debug");
+Services.prefs.setBoolPref("dom.mozApps.debug", true);
new file mode 100644
--- /dev/null
+++ b/dom/apps/tests/unit/tail.js
@@ -0,0 +1,1 @@
+Services.prefs.setBoolPref("dom.mozApps.debug", dom_mozApps_debug);
--- a/dom/apps/tests/unit/test_has_widget_criterion.js
+++ b/dom/apps/tests/unit/test_has_widget_criterion.js
@@ -1,15 +1,12 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
-const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
-
 Cu.import("resource:///modules/AppsUtils.jsm");
-Cu.import("resource:///modules/Services.jsm");
 
 add_test(function test_has_widget_criterion() {
 
   // follow the logic |_saveWidgetsFullPath|
   let baseUri = Services.io.newURI('http://example.com', null, null);
   let resolve = (aPage)=>{
     let filepath = AppsUtils.getFilePath(aPage);
 
--- a/dom/apps/tests/unit/test_inter_app_comm_service.js
+++ b/dom/apps/tests/unit/test_inter_app_comm_service.js
@@ -1,14 +1,11 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
-const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
-
-Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/InterAppCommService.jsm");
 Cu.import("resource://gre/modules/AppConstants.jsm");
 
 let UUIDGenerator = Cc["@mozilla.org/uuid-generator;1"]
                       .getService(Ci.nsIUUIDGenerator);
 
 const MESSAGE_PORT_ID = UUIDGenerator.generateUUID().toString();
 const FAKE_MESSAGE_PORT_ID = UUIDGenerator.generateUUID().toString();
--- a/dom/apps/tests/unit/test_moziapplication.js
+++ b/dom/apps/tests/unit/test_moziapplication.js
@@ -1,13 +1,11 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
-const {interfaces: Ci, utils: Cu} = Components;
-
 Cu.import("resource:///modules/AppsUtils.jsm");
 
 add_test(() => {
   let app = {
     name: "TestApp",
     csp: "aCsp",
     installOrigin: "http://installorigin.com",
     origin: "http://www.example.com",
--- a/dom/apps/tests/unit/xpcshell.ini
+++ b/dom/apps/tests/unit/xpcshell.ini
@@ -1,9 +1,9 @@
 [DEFAULT]
-head =
-tail =
+head = head.js
+tail = tail.js
 
 [test_has_widget_criterion.js]
 [test_inter_app_comm_service.js]
 [test_manifestSanitizer.js]
 [test_manifestHelper.js]
 [test_moziapplication.js]
--- a/testing/profiles/prefs_general.js
+++ b/testing/profiles/prefs_general.js
@@ -266,18 +266,16 @@ user_pref("security.ssl.errorReporting.u
 user_pref("browser.translation.bing.authURL", "http://%(server)s/browser/browser/components/translation/test/bing.sjs");
 user_pref("browser.translation.bing.translateArrayURL", "http://%(server)s/browser/browser/components/translation/test/bing.sjs");
 user_pref("browser.translation.yandex.translateURLOverride", "http://%(server)s/browser/browser/components/translation/test/yandex.sjs");
 user_pref("browser.translation.engine", "bing");
 
 // Make sure we don't try to load snippets from the network.
 user_pref("browser.aboutHomeSnippets.updateUrl", "nonexistent://test");
 
-// Enable debug logging in the mozApps implementation.
-user_pref("dom.mozApps.debug", true);
 // Enable apps customizations
 user_pref("dom.apps.customization.enabled", true);
 
 // Don't fetch or send directory tiles data from real servers
 user_pref("browser.newtabpage.directory.source", 'data:application/json,{"testing":1}');
 user_pref("browser.newtabpage.directory.ping", "");
 
 // Enable Loop
--- a/toolkit/webapps/tests/head.js
+++ b/toolkit/webapps/tests/head.js
@@ -581,8 +581,12 @@ let AlertsService = {
   },
 };
 
 AlertsService.init();
 
 SimpleTest.registerCleanupFunction(() => {
   AlertsService.restore();
 });
+
+function prepareEnv(cb) {
+  SpecialPowers.pushPrefEnv({"set":[["dom.mozApps.debug", true]]}, cb);
+}
--- a/toolkit/webapps/tests/test_custom_origin.xul
+++ b/toolkit/webapps/tests/test_custom_origin.xul
@@ -120,16 +120,16 @@ let runTest = Task.async(function*() {
   while (!(yield wasAppSJSAccessed()) && !appClosed) {
     yield wait(1000);
   }
   ok(!appClosed, "App was launched and is still running");
 
   SimpleTest.finish();
 });
 
-runTest().catch((e) => {
+prepareEnv(() => runTest().catch((e) => {
   ok(false, "Error during test: " + e);
   SimpleTest.finish();
-});
+}));
 
 ]]>
 </script>
 </window>
--- a/toolkit/webapps/tests/test_custom_origin_uninstall_install.xul
+++ b/toolkit/webapps/tests/test_custom_origin_uninstall_install.xul
@@ -156,16 +156,16 @@ let runTest = Task.async(function*() {
   while (!(yield wasAppSJSAccessed()) && !appClosed) {
     yield wait(1000);
   }
   ok(!appClosed, "App was launched and is still running");
 
   SimpleTest.finish();
 });
 
-runTest().catch((e) => {
+prepareEnv(() => runTest().catch((e) => {
   ok(false, "Error during test: " + e);
   SimpleTest.finish();
-});
+}));
 
 ]]>
 </script>
 </window>
--- a/toolkit/webapps/tests/test_hosted.xul
+++ b/toolkit/webapps/tests/test_hosted.xul
@@ -142,16 +142,16 @@ let runTest = Task.async(function*() {
   ok(true, "App launchable");
   ok((yield checkFiles(testAppInfo.installedFiles)), "Installation not corrupted");
   ok(!(yield OS.File.exists(OS.Path.join(testAppInfo.installPath, "update"))), "Update directory removed");
   ok((yield checkDateHigherThan(testAppInfo.updatedFiles, installTime)), "Modification date higher");
 
   SimpleTest.finish();
 });
 
-runTest().catch((e) => {
+prepareEnv(() => runTest().catch((e) => {
   ok(false, "Error during test: " + e);
   SimpleTest.finish();
-});
+}));
 
 ]]>
 </script>
 </window>
--- a/toolkit/webapps/tests/test_hosted_checkforupdates_from_webapp_runtime.xul
+++ b/toolkit/webapps/tests/test_hosted_checkforupdates_from_webapp_runtime.xul
@@ -101,16 +101,16 @@ let runTest = Task.async(function*() {
     yield wait(1000);
   }
   ok(!appClosed, "App was launched and is still running");
   ok(Number(yield getState("ManifestQueries")) >= 2, "Two manifest requests");
 
   SimpleTest.finish();
 });
 
-runTest().catch((e) => {
+prepareEnv(() => runTest().catch((e) => {
   ok(false, "Error during test: " + e);
   SimpleTest.finish();
-});
+}));
 
 ]]>
 </script>
 </window>
--- a/toolkit/webapps/tests/test_hosted_icons.xul
+++ b/toolkit/webapps/tests/test_hosted_icons.xul
@@ -142,16 +142,16 @@ let runTest = Task.async(function*() {
     let stat = yield OS.File.stat(testAppInfo.iconFile);
     isfuzzy(stat.size, iconSizes[curTest][0], iconSizes[curTest][1],
             "Icon size correct");
   }
 
   SimpleTest.finish();
 });
 
-runTest().catch((e) => {
+prepareEnv(() => runTest().catch((e) => {
   ok(false, "Error during test: " + e);
   SimpleTest.finish();
-});
+}));
 
 ]]>
 </script>
 </window>
--- a/toolkit/webapps/tests/test_hosted_launch.xul
+++ b/toolkit/webapps/tests/test_hosted_launch.xul
@@ -88,16 +88,16 @@ let runTest = Task.async(function*() {
   while (!(yield wasAppSJSAccessed()) && !appClosed) {
     yield wait(1000);
   }
   ok(!appClosed, "App was launched and is still running");
 
   SimpleTest.finish();
 });
 
-runTest().catch((e) => {
+prepareEnv(() => runTest().catch((e) => {
   ok(false, "Error during test: " + e);
   SimpleTest.finish();
-});
+}));
 
 ]]>
 </script>
 </window>
--- a/toolkit/webapps/tests/test_hosted_launch_no_registry.xul
+++ b/toolkit/webapps/tests/test_hosted_launch_no_registry.xul
@@ -88,16 +88,16 @@ let runTest = Task.async(function*() {
   while (!(yield wasAppSJSAccessed()) && !appClosed) {
     yield wait(1000);
   }
   ok(!appClosed, "App was launched and is still running");
 
   SimpleTest.finish();
 });
 
-runTest().catch((e) => {
+prepareEnv(() => runTest().catch((e) => {
   ok(false, "Error during test: " + e);
   SimpleTest.finish();
-});
+}));
 
 ]]>
 </script>
 </window>
--- a/toolkit/webapps/tests/test_hosted_uninstall.xul
+++ b/toolkit/webapps/tests/test_hosted_uninstall.xul
@@ -130,16 +130,16 @@ let runTest = Task.async(function*() {
   } catch (e) {
     exc = e;
   }
   ok(!!exc, "Re-uninstalling failed");
 
   SimpleTest.finish();
 });
 
-runTest().catch((e) => {
+prepareEnv(() => runTest().catch((e) => {
   ok(false, "Error during test: " + e);
   SimpleTest.finish();
-});
+}));
 
 ]]>
 </script>
 </window>
--- a/toolkit/webapps/tests/test_hosted_update_from_webapp_runtime.xul
+++ b/toolkit/webapps/tests/test_hosted_update_from_webapp_runtime.xul
@@ -105,16 +105,16 @@ let runTest = Task.async(function*() {
   while (!(yield wasAppSJSAccessed()) && !appClosed) {
     yield wait(1000);
   }
   ok(!appClosed, "App was launched and is still running");
 
   SimpleTest.finish();
 });
 
-runTest().catch((e) => {
+prepareEnv(() => runTest().catch((e) => {
   ok(false, "Error during test: " + e);
   SimpleTest.finish();
-});
+}));
 
 ]]>
 </script>
 </window>
--- a/toolkit/webapps/tests/test_install_appcache.xul
+++ b/toolkit/webapps/tests/test_install_appcache.xul
@@ -111,16 +111,16 @@ let runTest = Task.async(function*() {
       }
     } while (size == 0);
     ok(size > 100000, "There are some files in the OfflineCache directory");
   }
 
   SimpleTest.finish();
 });
 
-runTest().catch((e) => {
+prepareEnv(() => runTest().catch((e) => {
   ok(false, "Error during test: " + e);
   SimpleTest.finish();
-});
+}));
 
 ]]>
 </script>
 </window>
--- a/toolkit/webapps/tests/test_non_ascii_app_name.xul
+++ b/toolkit/webapps/tests/test_non_ascii_app_name.xul
@@ -143,16 +143,16 @@ let runTest = Task.async(function*() {
   ok(true, "App launchable");
   ok((yield checkFiles(testAppInfo.installedFiles)), "Installation not corrupted");
   ok(!(yield OS.File.exists(OS.Path.join(testAppInfo.installPath, "update"))), "Update directory removed");
   ok((yield checkDateHigherThan(testAppInfo.updatedFiles, installTime)), "Modification date higher");
 
   SimpleTest.finish();
 });
 
-runTest().catch((e) => {
+prepareEnv(() => runTest().catch((e) => {
   ok(false, "Error during test: " + e);
   SimpleTest.finish();
-});
+}));
 
 ]]>
 </script>
 </window>
--- a/toolkit/webapps/tests/test_packaged.xul
+++ b/toolkit/webapps/tests/test_packaged.xul
@@ -159,16 +159,16 @@ let runTest = Task.async(function*() {
   ok(true, "App launchable");
   ok((yield checkFiles(testAppInfo.installedFiles)), "Installation not corrupted");
   ok(!(yield OS.File.exists(OS.Path.join(testAppInfo.installPath, "update"))), "Update directory removed");
   ok((yield checkDateHigherThan(testAppInfo.updatedFiles, installTime)), "Modification date higher");
 
   SimpleTest.finish();
 });
 
-runTest().catch((e) => {
+prepareEnv(() => runTest().catch((e) => {
   ok(false, "Error during test: " + e);
   SimpleTest.finish();
-});
+}));
 
 ]]>
 </script>
 </window>
--- a/toolkit/webapps/tests/test_packaged_checkforupdates_from_webapp_runtime.xul
+++ b/toolkit/webapps/tests/test_packaged_checkforupdates_from_webapp_runtime.xul
@@ -113,16 +113,16 @@ let runTest = Task.async(function*() {
   }
   ok(!appClosed, "App was launched and is still running");
   ok(Number(yield getState("ManifestQueries")) >= 2, "Two manifest requests");
   ok(Number(yield getState("PackageQueries")) >= 2, "Two package requests");
 
   SimpleTest.finish();
 });
 
-runTest().catch((e) => {
+prepareEnv(() => runTest().catch((e) => {
   ok(false, "Error during test: " + e);
   SimpleTest.finish();
-});
+}));
 
 ]]>
 </script>
 </window>
--- a/toolkit/webapps/tests/test_packaged_icons.xul
+++ b/toolkit/webapps/tests/test_packaged_icons.xul
@@ -155,16 +155,16 @@ let runTest = Task.async(function*() {
 
     // Flush the ZipReaderCache (so that the application.zip file gets closed)
     Services.obs.notifyObservers(null, "chrome-flush-caches", null);
   }
 
   SimpleTest.finish();
 });
 
-runTest().catch((e) => {
+prepareEnv(() => runTest().catch((e) => {
   ok(false, "Error during test: " + e);
   SimpleTest.finish();
-});
+}));
 
 ]]>
 </script>
 </window>
--- a/toolkit/webapps/tests/test_packaged_launch.xul
+++ b/toolkit/webapps/tests/test_packaged_launch.xul
@@ -96,16 +96,16 @@ let runTest = Task.async(function*() {
   while (!(yield wasAppSJSAccessed()) && !appClosed) {
     yield wait(1000);
   }
   ok(!appClosed, "App was launched and is still running");
 
   SimpleTest.finish();
 });
 
-runTest().catch((e) => {
+prepareEnv(() => runTest().catch((e) => {
   ok(false, "Error during test: " + e);
   SimpleTest.finish();
-});
+}));
 
 ]]>
 </script>
 </window>
--- a/toolkit/webapps/tests/test_packaged_launch_no_registry.xul
+++ b/toolkit/webapps/tests/test_packaged_launch_no_registry.xul
@@ -96,16 +96,16 @@ let runTest = Task.async(function*() {
   while (!(yield wasAppSJSAccessed()) && !appClosed) {
     yield wait(1000);
   }
   ok(!appClosed, "App was launched and is still running");
 
   SimpleTest.finish();
 });
 
-runTest().catch((e) => {
+prepareEnv(() => runTest().catch((e) => {
   ok(false, "Error during test: " + e);
   SimpleTest.finish();
-});
+}));
 
 ]]>
 </script>
 </window>
--- a/toolkit/webapps/tests/test_packaged_uninstall.xul
+++ b/toolkit/webapps/tests/test_packaged_uninstall.xul
@@ -139,16 +139,16 @@ let runTest = Task.async(function*() {
   } catch (e) {
     exc = e;
   }
   ok(!!exc, "Re-uninstalling failed");
 
   SimpleTest.finish();
 });
 
-runTest().catch((e) => {
+prepareEnv(() => runTest().catch((e) => {
   ok(false, "Error during test: " + e);
   SimpleTest.finish();
-});
+}));
 
 ]]>
 </script>
 </window>
--- a/toolkit/webapps/tests/test_packaged_update_from_webapp_runtime.xul
+++ b/toolkit/webapps/tests/test_packaged_update_from_webapp_runtime.xul
@@ -119,16 +119,16 @@ let runTest = Task.async(function*() {
   while (!(yield wasAppSJSAccessed()) && !appClosed) {
     yield wait(1000);
   }
   ok(!appClosed, "App was launched and is still running");
 
   SimpleTest.finish();
 });
 
-runTest().catch((e) => {
+prepareEnv(() => runTest().catch((e) => {
   ok(false, "Error during test: " + e);
   SimpleTest.finish();
-});
+}));
 
 ]]>
 </script>
 </window>
--- a/toolkit/webapps/tests/test_webapp_runtime_executable_update.xul
+++ b/toolkit/webapps/tests/test_webapp_runtime_executable_update.xul
@@ -147,16 +147,16 @@ let runTest = Task.async(function*() {
   if (WIN) {
     is((yield runProcess()), 0, "Webapp runtime executable has been replaced");
   }
   is((yield runProcess()), 42, "Webapp runtime executable has been replaced");
 
   SimpleTest.finish();
 });
 
-runTest().catch((e) => {
+prepareEnv(() => runTest().catch((e) => {
   ok(false, "Error during test: " + e);
   SimpleTest.finish();
-});
+}));
 
 ]]>
 </script>
 </window>