1 function createPath(parentDir, dirOrFile) {
2 return parentDir.path + (parentDir.path == "/" ? "" : "/") + dirOrFile.name;
5 function createRelativePath(parentDir, dirOrFile) {
6 let path = createPath(parentDir, dirOrFile);
7 is(path[0], "/", "The full path should start with '/'");
8 return path.substring(1);
11 function setup_tests(aNext) {
12 SimpleTest.requestLongerTimeout(2);
13 SpecialPowers.pushPrefEnv(
16 ["dom.filesystem.pathcheck.disabled", true],
17 ["dom.webkitBlink.dirPicker.enabled", true],
24 function test_basic(aDirectory, aNext) {
25 ok(aDirectory, "Directory exists.");
26 ok(aDirectory instanceof Directory, "We have a directory.");
27 is(aDirectory.path, "/" + aDirectory.name, "directory.path must be '/'+name");
31 function test_getFilesAndDirectories(aDirectory, aRecursive, aNext) {
32 function checkSubDir(dir) {
33 return dir.getFilesAndDirectories().then(function (data) {
34 for (var i = 0; i < data.length; ++i) {
36 data[i] instanceof File || data[i] instanceof Directory,
37 "Just Files or Directories"
39 if (data[i] instanceof Directory) {
43 "Subdirectory should be called with the leafname"
48 "Subdirectory path should be called with the leafname"
53 "Subdirectory path should contain the parent path."
57 createPath(dir, data[i]),
58 "Subdirectory path should be called parentdir.path + '/' + leafname: " +
63 if (data[i] instanceof File) {
65 data[i].webkitRelativePath,
66 createRelativePath(dir, data[i]),
67 "File.webkitRelativePath should be called: parentdir.path + '/' + file.name: " +
68 data[i].webkitRelativePath
71 !data[i].webkitRelativePath.endsWith("symlink.txt"),
72 "We should never see a path ending with symlink.txt, our symlink sentinel."
80 .getFilesAndDirectories()
83 ok(data.length, "We should have some data.");
85 for (var i = 0; i < data.length; ++i) {
87 data[i] instanceof File || data[i] instanceof Directory,
88 "Just Files or Directories: " + data[i].name
90 if (data[i] instanceof Directory) {
94 "Subdirectory should be called with the leafname"
98 createPath(aDirectory, data[i]),
99 "Subdirectory path should be called parentdir.path + '/' + leafname: " +
103 promises.push(checkSubDir(data[i]));
107 if (data[i] instanceof File) {
109 data[i].webkitRelativePath,
110 createRelativePath(aDirectory, data[i]),
111 "File.webkitRelativePath should be called file.name: " +
112 data[i].webkitRelativePath
117 return Promise.all(promises);
120 ok(false, "Something when wrong");
126 function test_getFiles(aDirectory, aRecursive, aNext) {
128 .getFiles(aRecursive)
131 for (var i = 0; i < data.length; ++i) {
132 ok(data[i] instanceof File, "File: " + data[i].name);
133 is(aDirectory.path[0], "/", "Directory path must start with '/'");
135 data[i].webkitRelativePath.indexOf(aDirectory.path.substring(1)) ==
137 data[i].webkitRelativePath.indexOf("/" + data[i].name) +
138 ("/" + data[i].name).length ==
139 data[i].webkitRelativePath.length,
140 "File.webkitRelativePath should be called dir.path + '/' + file.name: " +
141 data[i].webkitRelativePath
146 ok(false, "Something when wrong");
152 function test_getFiles_recursiveComparison(aDirectory, aNext) {
155 .then(function (data) {
156 is(data.length, 2, "Only 2 files for this test.");
158 data[0].name == "foo.txt" || data[0].name == "bar.txt",
159 "First filename matches"
162 data[1].name == "foo.txt" || data[1].name == "bar.txt",
163 "Second filename matches"
167 return aDirectory.getFiles(false);
169 .then(function (data) {
170 is(data.length, 1, "Only 1 file for this test.");
172 data[0].name == "foo.txt" || data[0].name == "bar.txt",
173 "First filename matches"
177 ok(false, "Something when wrong");