Bug 999653 - Don't manually set allAppsLaunchable but use SpecialPowers.setAllAppsLaunchable. r=fabrice
authorMarco Castelluccio <mar.castelluccio@studenti.unina.it>
Thu, 24 Apr 2014 04:06:00 +0200
changeset 180332 50175efb3a5bdab540dbbad400603b7a18b562ce
parent 180331 b589de6c10843bddf9802104d16e170df486a123
child 180333 b755e9ea6293cbee0adcee56159b4329efb897ad
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersfabrice
bugs999653
milestone31.0a1
Bug 999653 - Don't manually set allAppsLaunchable but use SpecialPowers.setAllAppsLaunchable. r=fabrice
dom/tests/mochitest/webapps/head.js
dom/tests/mochitest/webapps/test_bug_765063.xul
dom/tests/mochitest/webapps/test_bug_771294.xul
webapprt/content/mochitest-shared.js
webapprt/content/mochitest.js
webapprt/test/content/webapprt_sample.html
--- a/dom/tests/mochitest/webapps/head.js
+++ b/dom/tests/mochitest/webapps/head.js
@@ -1,40 +1,26 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
-/**
- * DOMApplicationRegistry._isLaunchable() sometimes returns false right after
- * installation on Mac, perhaps because of a race condition between
- * WebappsInstaller and nsIMacWebAppUtils::pathForAppWithIdentifier().
- * That causes methods like mgmt.getAll() to exclude the app from their results,
- * even though the app is registered and installed.
- *
- * To work around this problem, set DOMApplicationRegistry.allAppsLaunchable
- * to true, which makes _isLaunchable() return true for all registered apps.
- */
-function makeAllAppsLaunchable() {
-  var Webapps = {};
-  Components.utils.import("resource://gre/modules/Webapps.jsm", Webapps);
-  var originalValue = Webapps.DOMApplicationRegistry.allAppsLaunchable;
-  Webapps.DOMApplicationRegistry.allAppsLaunchable = true;
-
-  // Clean up after ourselves once tests are done so the test page is unloaded.
-  window.addEventListener("unload", function restoreAllAppsLaunchable(event) {
-    if (event.target == window.document) {
-      window.removeEventListener("unload", restoreAllAppsLaunchable, false);
-      Webapps.DOMApplicationRegistry.allAppsLaunchable = originalValue;
-    }
-  }, false);
-}
-
 function runAll(steps) {
   SimpleTest.waitForExplicitFinish();
 
-  makeAllAppsLaunchable();
+  /**
+   * On Mac, apps aren't considered launchable right after they've been
+   * installed because the OS takes some time to detect them (so
+   * nsIMacWebAppUtils::pathForAppWithIdentifier() returns null).
+   * That causes methods like mgmt.getAll() to exclude the app from their
+   * results, even though the app is installed and is in the registry.
+   * See the tests under toolkit/webapps for a viable solution.
+   *
+   * To work around this problem, set allAppsLaunchable to true, which makes
+   * all apps considered as launchable.
+   */
+  SpecialPowers.setAllAppsLaunchable(true);
 
   // Clone the array so we don't modify the original.
   steps = steps.concat();
   function next() {
     if (steps.length) {
       steps.shift()(next);
     }
     else {
--- a/dom/tests/mochitest/webapps/test_bug_765063.xul
+++ b/dom/tests/mochitest/webapps/test_bug_765063.xul
@@ -15,17 +15,17 @@
   <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=741549"
      target="_blank">Mozilla Bug 765063</a>
   </body>
 
 <script> 
 
 SimpleTest.waitForExplicitFinish();
 
-makeAllAppsLaunchable();
+SpecialPowers.setAllAppsLaunchable(true);
 
 var mmListener = {
   receiveMessage: function(aMessage) {
     ppmm.removeMessageListener("Webapps:Install", mmListener);
 
     var msg = aMessage.json;
     var ioService = Components.classes["@mozilla.org/network/io-service;1"]
                                       .getService(Components.interfaces.nsIIOService);
--- a/dom/tests/mochitest/webapps/test_bug_771294.xul
+++ b/dom/tests/mochitest/webapps/test_bug_771294.xul
@@ -17,17 +17,17 @@
   </body>
 
 <script>
 const Ci = Components.interfaces;
 const Cu = Components.utils;
 
 SimpleTest.waitForExplicitFinish();
 
-makeAllAppsLaunchable();
+SpecialPowers.setAllAppsLaunchable(true);
 
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/PopupNotifications.jsm");
 
 let blocked = true;
 
 function blockedListener() {
   blocked = false;
--- a/webapprt/content/mochitest-shared.js
+++ b/webapprt/content/mochitest-shared.js
@@ -80,11 +80,10 @@ function becomeWebapp(manifestURL, param
     // gets loaded, so we do that now.
     Services.obs.notifyObservers(this, "webapps-registry-start", null);
 
     promise.then(onBecome);
   }
   Services.obs.addObserver(observeInstall, "webapps-ask-install", false);
 
   // Step 1: Install the app at the URL specified by the manifest.
-  let url = Services.io.newURI(manifestURL, null, null);
-  navigator.mozApps.install(url.spec, parameters);
+  navigator.mozApps.install(manifestURL, parameters);
 }
--- a/webapprt/content/mochitest.js
+++ b/webapprt/content/mochitest.js
@@ -13,21 +13,18 @@ Services.scriptloader
 // In test mode, the runtime isn't configured until we tell it to become
 // an app, which requires us to use DOMApplicationRegistry to install one.
 // But DOMApplicationRegistry needs to know the location of its registry dir,
 // so we need to configure the runtime with at least that information.
 WebappRT.config = {
   registryDir: Services.dirsvc.get("ProfD", Ci.nsIFile).path,
 };
 
-
 Cu.import("resource://gre/modules/Webapps.jsm");
 
-DOMApplicationRegistry.allAppsLaunchable = true;
-
 becomeWebapp("http://mochi.test:8888/tests/webapprt/test/content/test.webapp",
              undefined, function onBecome() {
   if (window.arguments && window.arguments[0]) {
     let testUrl = window.arguments[0].QueryInterface(Ci.nsIPropertyBag2).get("url");
 
     if (testUrl) {
       let win = Services.wm.getMostRecentWindow("webapprt:webapp");
       win.document.getElementById("content").setAttribute("src", testUrl);
--- a/webapprt/test/content/webapprt_sample.html
+++ b/webapprt/test/content/webapprt_sample.html
@@ -17,16 +17,18 @@
       This is the sample WebappRT content mochitest.
     </p>
     <div id="content" style="display: none"></div>
     <pre id="test">
       <script>
 
 SimpleTest.waitForExplicitFinish();
 
+SpecialPowers.setAllAppsLaunchable(true);
+
 ok(true, "true is true!");
 
 var self = navigator.mozApps.getSelf();
 self.onsuccess = function () {
   ok(true, "onsuccess should be called");
   ok(self.result, "result should be nonnull");
   ok(self.result.manifest, "manifest should be nonnull");
   is(self.result.manifest.name, "WebappRT Mochitest Webapp",