mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 15:23:51 +00:00
Bug 1284742 - Replace profile directory traversal with a generated directory tree in dom/filesystem/test/test_basic.html. r=mystor
MozReview-Commit-ID: HSX9i5KDDEj --HG-- extra : rebase_source : 7f95f6e9ca59f839c01be1cd75847aaa60cdf81c
This commit is contained in:
parent
8fa1cdc6fb
commit
395c323784
@ -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", {
|
||||
|
@ -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); },
|
||||
|
Loading…
Reference in New Issue
Block a user