Bug 1284742 - Replace profile directory traversal with a generated directory tree in dom/filesystem/test/test_basic.html. r?mystor
MozReview-Commit-ID: HSX9i5KDDEj
--- 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); },