diff --git a/dom/filesystem/tests/script_fileList.js b/dom/filesystem/tests/script_fileList.js index b21ba3550506..85d279ad70e8 100644 --- a/dom/filesystem/tests/script_fileList.js +++ b/dom/filesystem/tests/script_fileList.js @@ -8,6 +8,46 @@ function createProfDFile() { .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(); @@ -52,6 +92,8 @@ addMessageListener("dir.open", function (e) { switch (e.path) { case 'ProfD': + // Note that files in the profile directory are not guaranteed to persist- + // see bug 1284742. testFile = createProfDFile(); break; @@ -62,6 +104,10 @@ addMessageListener("dir.open", function (e) { case 'test': testFile = createTestFile(); break; + + case 'tree': + testFile = createTreeFile(3); + break; } sendAsyncMessage("dir.opened", { diff --git a/dom/filesystem/tests/test_basic.html b/dom/filesystem/tests/test_basic.html index 0b0fa97ebc6d..d2e40aa720c3 100644 --- a/dom/filesystem/tests/test_basic.html +++ b/dom/filesystem/tests/test_basic.html @@ -129,7 +129,7 @@ function test_inputGetFiles() { 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); },