Bug 1284742 - Replace profile directory traversal with a generated directory tree in dom/filesystem/test/test_basic.html. r=mystor, a=test-only
authorAndrew Comminos <andrew@comminos.com>
Tue, 02 Aug 2016 15:48:13 -0400
changeset 342521 4e78a1131df04cca842c7bf1fcb6b873f8a0a0e9
parent 342520 009ea36672be7651bcb0223f0112a501fcf82ac6
child 342522 e20dac56cfb260f1fcbd2d6a8f1f9625cecdc201
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmystor, test-only
bugs1284742
milestone49.0
Bug 1284742 - Replace profile directory traversal with a generated directory tree in dom/filesystem/test/test_basic.html. r=mystor, a=test-only MozReview-Commit-ID: HSX9i5KDDEj
dom/filesystem/tests/script_fileList.js
dom/filesystem/tests/test_basic.html
--- a/dom/filesystem/tests/script_fileList.js
+++ b/dom/filesystem/tests/script_fileList.js
@@ -3,16 +3,56 @@ Cu.importGlobalProperties(["File"]);
 
 function createProfDFile() {
   return Cc["@mozilla.org/file/directory_service;1"]
            .getService(Ci.nsIDirectoryService)
            .QueryInterface(Ci.nsIProperties)
            .get('ProfD', Ci.nsIFile);
 }
 
+// Creates a parametric arity directory hierarchy as a function of depth.
+// Each directory contains one leaf file, and subdirectories of depth [1, depth).
+// e.g. for depth 3:
+//
+// subdir3
+// - file.txt
+// - subdir2
+//   - file.txt
+//   - subdir1
+//     - file.txt
+// - subdir1
+//   - file.txt
+//
+// Returns the parent directory of the subtree.
+function createTreeFile(depth, parent) {
+  if (!parent) {
+    parent = Cc["@mozilla.org/file/directory_service;1"]
+                .getService(Ci.nsIDirectoryService)
+                .QueryInterface(Ci.nsIProperties)
+                .get('TmpD', Ci.nsIFile);
+    parent.append('dir-tree-test');
+    parent.createUnique(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0o700);
+  }
+
+  var nextFile = parent.clone();
+  if (depth == 0) {
+    nextFile.append('file.txt');
+    nextFile.create(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0o600);
+  } else {
+    nextFile.append('subdir' + depth);
+    nextFile.createUnique(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0o700);
+    // Decrement the maximal depth by one for each level of nesting.
+    for (i = 0; i < depth; i++) {
+      createTreeFile(i, nextFile);
+    }
+  }
+
+  return parent;
+}
+
 function createRootFile() {
   var testFile = createProfDFile();
 
   // Let's go back to the root of the FileSystem
   while (true) {
     var parent = testFile.parent;
     if (!parent) {
       break;
@@ -47,26 +87,32 @@ function createTestFile() {
   return tmpFile;
 }
 
 addMessageListener("dir.open", function (e) {
   var testFile;
 
   switch (e.path) {
     case 'ProfD':
+      // Note that files in the profile directory are not guaranteed to persist-
+      // see bug 1284742.
       testFile = createProfDFile();
       break;
 
     case 'root':
       testFile = createRootFile();
       break;
 
     case 'test':
       testFile = createTestFile();
       break;
+
+    case 'tree':
+      testFile = createTreeFile(3);
+      break;
   }
 
   sendAsyncMessage("dir.opened", {
     dir: testFile.path
   });
 });
 
 addMessageListener("file.open", function (e) {
--- a/dom/filesystem/tests/test_basic.html
+++ b/dom/filesystem/tests/test_basic.html
@@ -124,17 +124,17 @@ function test_inputGetFiles() {
 
   script.addMessageListener("dir.opened", onOpened);
   script.sendAsyncMessage("dir.open", { path: 'test' });
 }
 
 var tests = [
   function() { setup_tests(next); },
 
-  function() { create_fileList('ProfD') },
+  function() { create_fileList('tree') },
   function() { test_basic(directory, next); },
   function() { test_getFilesAndDirectories(directory, true, next); },
   function() { test_getFiles(directory, false, next); },
   function() { test_getFiles(directory, true, next); },
 
   function() { create_fileList('test') },
   function() { test_getFiles_recursiveComparison(directory, next); },