Bug 1035282 - Make Webapps.jsm throw DUPLICATE_ORIGIN only if the app with the same origin is natively installed. r=fabrice,myk
authorMarco Castelluccio <mar.castelluccio@studenti.unina.it>
Tue, 15 Jul 2014 03:53:48 +0200
changeset 193971 4ef82665a6e6b049a204d0ebb1355c1a3e926303
parent 193970 800fbf0e4630ae63acafacde6a22c8cc1bd8b12b
child 193972 5a2cd9e13de1fd98850e4826915053b90637699a
push id27136
push usercbook@mozilla.com
push dateTue, 15 Jul 2014 12:59:16 +0000
treeherdermozilla-central@d2d56f9066bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfabrice, myk
bugs1035282
milestone33.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 1035282 - Make Webapps.jsm throw DUPLICATE_ORIGIN only if the app with the same origin is natively installed. r=fabrice,myk
dom/apps/src/Webapps.jsm
toolkit/webapps/tests/chrome.ini
toolkit/webapps/tests/test_custom_origin.xul
toolkit/webapps/tests/test_custom_origin_uninstall_install.xul
--- a/dom/apps/src/Webapps.jsm
+++ b/dom/apps/src/Webapps.jsm
@@ -3394,22 +3394,30 @@ this.DOMApplicationRegistry = {
         }
         // Nothing else to do for an update... since the
         // origin can't change we don't need to move the
         // app nor can we have a duplicated origin
       } else {
         debug("Setting origin to " + uri.prePath +
               " for " + aOldApp.manifestURL);
         let newId = uri.prePath.substring(6); // "app://".length
-        if (newId in this.webapps) {
+        if (newId in this.webapps && this._isLaunchable(this.webapps[newId])) {
           throw "DUPLICATE_ORIGIN";
         }
         aOldApp.origin = uri.prePath;
         // Update the registry.
         let oldId = aOldApp.id;
+
+        if (oldId == newId) {
+          // This could happen when we have an app in the registry
+          // that is not launchable. Since the app already has
+          // the correct id, we don't need to change it.
+          return;
+        }
+
         aOldApp.id = newId;
         this.webapps[newId] = aOldApp;
         delete this.webapps[oldId];
         // Rename the directories where the files are installed.
         [DIRECTORY_NAME, "TmpD"].forEach(function(aDir) {
           let parent = FileUtils.getDir(aDir, ["webapps"], true, true);
           let dir = FileUtils.getDir(aDir, ["webapps", oldId], true, true);
           dir.moveTo(parent, newId);
--- a/toolkit/webapps/tests/chrome.ini
+++ b/toolkit/webapps/tests/chrome.ini
@@ -2,16 +2,18 @@
 skip-if = os == "mac" && os_version == "10.6" # see bug 993690
 support-files =
   head.js
   app.sjs
   data/*
 
 [test_custom_origin.xul]
 skip-if = asan
+[test_custom_origin_uninstall_install.xul]
+skip-if = asan
 [test_install_appcache.xul]
 skip-if = asan
 [test_hosted.xul]
 [test_packaged.xul]
 [test_hosted_launch.xul]
 skip-if = asan
 [test_hosted_launch_no_registry.xul]
 skip-if = asan
--- a/toolkit/webapps/tests/test_custom_origin.xul
+++ b/toolkit/webapps/tests/test_custom_origin.xul
@@ -75,32 +75,32 @@ let runTest = Task.async(function*() {
   // On Mac build servers, we don't have enough privileges to write to /Applications,
   // so we install apps in a user-owned directory.
   if (MAC) {
     yield setMacRootInstallDir(OS.Path.join(OS.Constants.Path.homeDir, "Applications"));
   }
 
   confirmNextInstall();
 
-  let request = navigator.mozApps.installPackage("http://test/chrome/toolkit/webapps/tests/data/custom_origin.webapp");
+  let request = navigator.mozApps.installPackage(app.manifestURL);
 
   let (deferred = Promise.defer()) {
     request.onerror = function() {
       deferred.reject(this.error.name);
     };
     request.onsuccess = deferred.resolve;
     yield deferred.promise;
   }
 
   let appObject = request.result;
   ok(appObject, "app is non-null");
 
   let (deferred = Promise.defer()) {
     appObject.ondownloaderror = function() {
-      deferred.reject(this.error.name);
+      deferred.reject(appObject.downloadError.name);
     };
     appObject.ondownloadapplied = deferred.resolve;
     yield deferred.promise;
   };
 
   while (!WebappOSUtils.isLaunchable(app)) {
     yield wait(1000);
   }
copy from toolkit/webapps/tests/test_custom_origin.xul
copy to toolkit/webapps/tests/test_custom_origin_uninstall_install.xul
--- a/toolkit/webapps/tests/test_custom_origin.xul
+++ b/toolkit/webapps/tests/test_custom_origin_uninstall_install.xul
@@ -1,32 +1,32 @@
 <?xml version="1.0"?>
 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
 <?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?>
 <!--
-https://bugzilla.mozilla.org/show_bug.cgi?id=1029674
+https://bugzilla.mozilla.org/show_bug.cgi?id=1035282
 -->
-<window title="Mozilla Bug 1029674"
+<window title="Mozilla Bug 1035282"
         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="chrome://mochikit/content/chrome-harness.js"></script>
   <script type="application/javascript" src="head.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=1029674"
-     target="_blank">Mozilla Bug 1029674</a>
+  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1035282"
+     target="_blank">Mozilla Bug 1035282</a>
   </body>
 
 <script type="application/javascript">
 <![CDATA[
 
-/** Test for Bug 1029674 **/
+/** Test for Bug 1035282 **/
 
 "use strict";
 
 SimpleTest.waitForExplicitFinish();
 
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/NativeApp.jsm");
 Cu.import("resource://gre/modules/WebappOSUtils.jsm");
@@ -75,35 +75,67 @@ let runTest = Task.async(function*() {
   // On Mac build servers, we don't have enough privileges to write to /Applications,
   // so we install apps in a user-owned directory.
   if (MAC) {
     yield setMacRootInstallDir(OS.Path.join(OS.Constants.Path.homeDir, "Applications"));
   }
 
   confirmNextInstall();
 
-  let request = navigator.mozApps.installPackage("http://test/chrome/toolkit/webapps/tests/data/custom_origin.webapp");
+  let (request = navigator.mozApps.installPackage(app.manifestURL)) {
+    let (deferred = Promise.defer()) {
+      request.onerror = function() {
+        deferred.reject(this.error.name);
+      };
+      request.onsuccess = deferred.resolve;
+      yield deferred.promise;
+    }
+
+    let appObject = request.result;
+    ok(appObject, "app is non-null");
 
-  let (deferred = Promise.defer()) {
-    request.onerror = function() {
-      deferred.reject(this.error.name);
+    let (deferred = Promise.defer()) {
+      appObject.ondownloaderror = function() {
+        deferred.reject(appObject.downloadError.name);
+      };
+      appObject.ondownloadapplied = deferred.resolve;
+      yield deferred.promise;
     };
-    request.onsuccess = deferred.resolve;
-    yield deferred.promise;
+  };
+
+  while (!WebappOSUtils.isLaunchable(app)) {
+    yield wait(1000);
   }
+  ok(true, "App launchable");
 
-  let appObject = request.result;
-  ok(appObject, "app is non-null");
+  yield WebappOSUtils.uninstall(app)
+
+  is(WebappOSUtils.launch(app), false, "Launch fails");
+
+  confirmNextInstall();
 
-  let (deferred = Promise.defer()) {
-    appObject.ondownloaderror = function() {
-      deferred.reject(this.error.name);
+  let (request = navigator.mozApps.installPackage(app.manifestURL)) {
+    let (deferred = Promise.defer()) {
+      request.onerror = function() {
+        deferred.reject(this.error.name);
+      };
+      request.onsuccess = deferred.resolve;
+      yield deferred.promise;
+    }
+
+    let appObject = request.result;
+    ok(appObject, "app is non-null");
+
+    let (deferred = Promise.defer()) {
+      appObject.ondownloaderror = function() {
+        deferred.reject(appObject.downloadError.name);
+      };
+      appObject.ondownloadapplied = deferred.resolve;
+      yield deferred.promise;
     };
-    appObject.ondownloadapplied = deferred.resolve;
-    yield deferred.promise;
   };
 
   while (!WebappOSUtils.isLaunchable(app)) {
     yield wait(1000);
   }
   ok(true, "App launchable");
 
   let exeFile = getFile(testAppInfo.exePath);