Bug 646306 - file is not defined in DirInstallLocation__readDirectoryFromFile. r=dtownsend
authorBlair McBride <bmcbride@mozilla.com>
Wed, 01 Jun 2011 15:51:25 +1200
changeset 70384 c5e0aaaff9e1e5729e5866e7d71dfc608e4b1e8a
parent 70383 42d996c34679c883d3ad497dc62710535637a3b2
child 70385 c4999efc5a845b1a90fcee8986ac5ff9f14388be
push id20308
push userbmcbride@mozilla.com
push dateWed, 01 Jun 2011 03:53:04 +0000
treeherdermozilla-central@c5e0aaaff9e1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdtownsend
bugs646306
milestone7.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 646306 - file is not defined in DirInstallLocation__readDirectoryFromFile. r=dtownsend
toolkit/mozapps/extensions/XPIProvider.jsm
toolkit/mozapps/extensions/test/xpcshell/test_filepointer.js
--- a/toolkit/mozapps/extensions/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/XPIProvider.jsm
@@ -7212,17 +7212,17 @@ DirectoryInstallLocation.prototype = {
     if (line.value) {
       let linkedDirectory = Cc["@mozilla.org/file/local;1"].
                             createInstance(Ci.nsILocalFile);
 
       try {
         linkedDirectory.initWithPath(line.value);
       }
       catch (e) {
-        linkedDirectory.setRelativeDescriptor(file.parent, line.value);
+        linkedDirectory.setRelativeDescriptor(aFile.parent, line.value);
       }
 
       if (!linkedDirectory.exists()) {
         WARN("File pointer " + aFile.path + " points to " + linkedDirectory.path +
              " which does not exist");
         return null;
       }
 
--- a/toolkit/mozapps/extensions/test/xpcshell/test_filepointer.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_filepointer.js
@@ -59,16 +59,35 @@ function writePointer(aId, aName) {
             createInstance(AM_Ci.nsIFileOutputStream);
   fos.init(file,
            FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE | FileUtils.MODE_TRUNCATE,
            FileUtils.PERMS_FILE, 0);
   fos.write(target.path, target.path.length);
   fos.close();
 }
 
+function writeRelativePointer(aId, aName) {
+  let file = profileDir.clone();
+  file.append(aName ? aName : aId);
+
+  let absTarget = sourceDir.clone();
+  absTarget.append(do_get_expected_addon_name(aId));
+  
+  var relTarget = absTarget.QueryInterface(Ci.nsILocalFile)
+                       .getRelativeDescriptor(profileDir);
+
+  var fos = AM_Cc["@mozilla.org/network/file-output-stream;1"].
+            createInstance(AM_Ci.nsIFileOutputStream);
+  fos.init(file,
+           FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE | FileUtils.MODE_TRUNCATE,
+           FileUtils.PERMS_FILE, 0);
+  fos.write(relTarget, relTarget.length);
+  fos.close();
+}
+
 function run_test() {
   // pointer files only work with unpacked directories
   if (Services.prefs.getBoolPref("extensions.alwaysUnpack") == false)
     return;
 
   do_test_pending();
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1");
 
@@ -347,12 +366,38 @@ function run_test_9() {
 
     AddonManager.getAddonByID(addon1.id, function(a1) {
       do_check_eq(a1, null);
 
       let pointer = profileDir.clone();
       pointer.append(addon1.id);
       do_check_false(pointer.exists());
 
-      end_test();
+      run_test_10();
     });
   });
 }
+
+// Tests that installing a new add-on by pointer with a relative path works
+function run_test_10() {
+  writeInstallRDFForExtension(addon1, sourceDir);
+  writeRelativePointer(addon1.id);
+
+  restartManager();
+
+  AddonManager.getAddonByID(addon1.id, function(a1) {
+    do_check_neq(a1, null);
+    do_check_eq(a1.version, "1.0");
+
+    let file = a1.getResourceURI().QueryInterface(AM_Ci.nsIFileURL).file;
+    do_check_eq(file.parent.path, sourceDir.path);
+
+    let rootUri = do_get_addon_root_uri(sourceDir, addon1.id);
+    let uri = a1.getResourceURI("/");
+    do_check_eq(uri.spec, rootUri);
+    uri = a1.getResourceURI("install.rdf");
+    do_check_eq(uri.spec, rootUri + "install.rdf");
+    
+    // Check that upgrade is disabled for addons installed by file-pointers.
+    do_check_eq(a1.permissions & AddonManager.PERM_CAN_UPGRADE, 0);
+    end_test();
+  });
+}