Bug 1258490 - patch 3 - Fix Android error failures for root paths, r=me
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 13 May 2016 17:20:26 +0200
changeset 297407 dba45e1c4bf12036ff56042b125e8b5d63202bf5
parent 297406 f243def779e3ff3431dc98ad2bef3ae1f37f92e9
child 297408 28b2e46097e6214d06a4044823961fc59453dc3b
push id19218
push userkwierso@gmail.com
push dateFri, 13 May 2016 23:46:15 +0000
treeherderfx-team@93d60e9db618 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersme
bugs1258490
milestone49.0a1
Bug 1258490 - patch 3 - Fix Android error failures for root paths, r=me
dom/filesystem/FileSystemBase.cpp
dom/filesystem/tests/filesystem_commons.js
--- a/dom/filesystem/FileSystemBase.cpp
+++ b/dom/filesystem/FileSystemBase.cpp
@@ -148,17 +148,19 @@ FileSystemBase::GetDOMPath(nsIFile* aFil
 
   while (true) {
     nsAutoString leafName;
     aRv = path->GetLeafName(leafName);
     if (NS_WARN_IF(aRv.Failed())) {
       return;
     }
 
-    parts.AppendElement(leafName);
+    if (!leafName.IsEmpty()) {
+      parts.AppendElement(leafName);
+    }
 
     bool equal = false;
     aRv = fileSystemPath->Equals(path, &equal);
     if (NS_WARN_IF(aRv.Failed())) {
       return;
     }
 
     if (equal) {
@@ -174,17 +176,20 @@ FileSystemBase::GetDOMPath(nsIFile* aFil
     MOZ_ASSERT(parentPath);
 
     aRv = parentPath->Clone(getter_AddRefs(path));
     if (NS_WARN_IF(aRv.Failed())) {
       return;
     }
   }
 
-  MOZ_ASSERT(!parts.IsEmpty());
+  if (parts.IsEmpty()) {
+    aRetval.AppendLiteral(FILESYSTEM_DOM_PATH_SEPARATOR_LITERAL);
+    return;
+  }
 
   for (int32_t i = parts.Length() - 1; i >= 0; --i) {
     aRetval.AppendLiteral(FILESYSTEM_DOM_PATH_SEPARATOR_LITERAL);
     aRetval.Append(parts[i]);
   }
 }
 
 void
--- a/dom/filesystem/tests/filesystem_commons.js
+++ b/dom/filesystem/tests/filesystem_commons.js
@@ -1,8 +1,12 @@
+function createPath(parentDir, dirOrFile) {
+  return parentDir.path + (parentDir.path == '/' ? '' : '/') + dirOrFile.name;
+}
+
 function setup_tests(aNext) {
   SpecialPowers.pushPrefEnv({"set": [["dom.input.dirpicker", true],
                                      ["dom.webkitBlink.dirPicker.enabled", true]]}, aNext);
 }
 
 function test_basic(aDirectory, aNext) {
   ok(aDirectory, "Directory exists.");
   ok(aDirectory instanceof Directory, "We have a directory.");
@@ -15,43 +19,43 @@ function test_getFilesAndDirectories(aDi
     return dir.getFilesAndDirectories().then(
       function(data) {
         for (var i = 0; i < data.length; ++i) {
           ok (data[i] instanceof File || data[i] instanceof Directory, "Just Files or Directories");
           if (data[i] instanceof Directory) {
             isnot(data[i].name, '/', "Subdirectory should be called with the leafname");
             isnot(data[i].path, '/', "Subdirectory path should be called with the leafname");
             isnot(data[i].path, dir.path, "Subdirectory path should contain the parent path.");
-            is(data[i].path, dir.path + '/' + data[i].name, "Subdirectory path should be called parentdir.path + '/' + leafname");
+            is(data[i].path, createPath(dir, data[i]), "Subdirectory path should be called parentdir.path + '/' + leafname: " + data[i].path);
           }
 
           if (data[i] instanceof File) {
-            is(data[i].webkitRelativePath, dir.path + '/' + data[i].name, "File.webkitRelativePath should be called: parentdir.path + '/' + file.name");
+            is(data[i].webkitRelativePath, createPath(dir, data[i]), "File.webkitRelativePath should be called: parentdir.path + '/' + file.name: " + data[i].webkitRelativePath);
           }
         }
       }
     );
   }
 
   aDirectory.getFilesAndDirectories().then(
     function(data) {
       ok(data.length, "We should have some data.");
       var promises = [];
       for (var i = 0; i < data.length; ++i) {
         ok (data[i] instanceof File || data[i] instanceof Directory, "Just Files or Directories: " + data[i].name);
         if (data[i] instanceof Directory) {
           isnot(data[i].name, '/', "Subdirectory should be called with the leafname");
-          is(data[i].path, aDirectory.path + '/' + data[i].name, "Subdirectory path should be called parentdir.path + '/' + leafname");
+          is(data[i].path, createPath(aDirectory, data[i]), "Subdirectory path should be called parentdir.path + '/' + leafname: " + data[i].path);
           if (aRecursive) {
             promises.push(checkSubDir(data[i]));
           }
         }
 
         if (data[i] instanceof File) {
-          is(data[i].webkitRelativePath, aDirectory.path + '/' + data[i].name, "File.webkitRelativePath should be called '/' + file.name");
+          is(data[i].webkitRelativePath, createPath(aDirectory, data[i]), "File.webkitRelativePath should be called '/' + file.name: " + data[i].webkitRelativePath);
         }
       }
 
       return Promise.all(promises);
     },
     function() {
       ok(false, "Something when wrong");
     }