summaryrefslogtreecommitdiffstats
path: root/dom/filesystem/tests
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /dom/filesystem/tests
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/filesystem/tests')
-rw-r--r--dom/filesystem/tests/filesystem_commons.js103
-rw-r--r--dom/filesystem/tests/mochitest.ini10
-rw-r--r--dom/filesystem/tests/moz.build7
-rw-r--r--dom/filesystem/tests/script_fileList.js129
-rw-r--r--dom/filesystem/tests/test_basic.html167
-rw-r--r--dom/filesystem/tests/test_bug1319088.html66
-rw-r--r--dom/filesystem/tests/test_webkitdirectory.html191
-rw-r--r--dom/filesystem/tests/test_worker_basic.html72
-rw-r--r--dom/filesystem/tests/worker_basic.js41
9 files changed, 786 insertions, 0 deletions
diff --git a/dom/filesystem/tests/filesystem_commons.js b/dom/filesystem/tests/filesystem_commons.js
new file mode 100644
index 000000000..4f7234121
--- /dev/null
+++ b/dom/filesystem/tests/filesystem_commons.js
@@ -0,0 +1,103 @@
+function createPath(parentDir, dirOrFile) {
+ return parentDir.path + (parentDir.path == '/' ? '' : '/') + dirOrFile.name;
+}
+
+function createRelativePath(parentDir, dirOrFile) {
+ let path = createPath(parentDir, dirOrFile);
+ is(path[0], "/", "The full path should start with '/'");
+ return path.substring(1);
+}
+
+function setup_tests(aNext) {
+ SimpleTest.requestLongerTimeout(2);
+ SpecialPowers.pushPrefEnv({"set": [["dom.input.dirpicker", true],
+ ["dom.filesystem.pathcheck.disabled", true],
+ ["dom.webkitBlink.dirPicker.enabled", true]]}, aNext);
+}
+
+function test_basic(aDirectory, aNext) {
+ ok(aDirectory, "Directory exists.");
+ ok(aDirectory instanceof Directory, "We have a directory.");
+ is(aDirectory.path, '/' + aDirectory.name, "directory.path must be '/'+name");
+ aNext();
+}
+
+function test_getFilesAndDirectories(aDirectory, aRecursive, aNext) {
+ function checkSubDir(dir) {
+ return dir.getFilesAndDirectories().then(
+ function(data) {
+ for (var i = 0; i < data.length; ++i) {
+ ok (data[i] instanceof File || data[i] instanceof Directory, "Just Files or Directories");
+ if (data[i] instanceof Directory) {
+ isnot(data[i].name, '/', "Subdirectory should be called with the leafname");
+ isnot(data[i].path, '/', "Subdirectory path should be called with the leafname");
+ isnot(data[i].path, dir.path, "Subdirectory path should contain the parent path.");
+ is(data[i].path, createPath(dir, data[i]), "Subdirectory path should be called parentdir.path + '/' + leafname: " + data[i].path);
+ }
+
+ if (data[i] instanceof File) {
+ is(data[i].webkitRelativePath, createRelativePath(dir, data[i]), "File.webkitRelativePath should be called: parentdir.path + '/' + file.name: " + data[i].webkitRelativePath);
+ }
+ }
+ }
+ );
+ }
+
+ aDirectory.getFilesAndDirectories().then(
+ function(data) {
+ ok(data.length, "We should have some data.");
+ var promises = [];
+ for (var i = 0; i < data.length; ++i) {
+ ok (data[i] instanceof File || data[i] instanceof Directory, "Just Files or Directories: " + data[i].name);
+ if (data[i] instanceof Directory) {
+ isnot(data[i].name, '/', "Subdirectory should be called with the leafname");
+ is(data[i].path, createPath(aDirectory, data[i]), "Subdirectory path should be called parentdir.path + '/' + leafname: " + data[i].path);
+ if (aRecursive) {
+ promises.push(checkSubDir(data[i]));
+ }
+ }
+
+ if (data[i] instanceof File) {
+ is(data[i].webkitRelativePath, createRelativePath(aDirectory, data[i]), "File.webkitRelativePath should be called file.name: " + data[i].webkitRelativePath);
+ }
+ }
+
+ return Promise.all(promises);
+ },
+ function() {
+ ok(false, "Something when wrong");
+ }
+ ).then(aNext);
+}
+
+function test_getFiles(aDirectory, aRecursive, aNext) {
+ aDirectory.getFiles(aRecursive).then(
+ function(data) {
+ for (var i = 0; i < data.length; ++i) {
+ ok(data[i] instanceof File, "File: " + data[i].name);
+ is(aDirectory.path[0], '/', "Directory path must start with '/'");
+ ok(data[i].webkitRelativePath.indexOf(aDirectory.path.substring(1)) == 0 &&
+ data[i].webkitRelativePath.indexOf('/' + data[i].name) + ('/' + data[i].name).length == data[i].webkitRelativePath.length,
+ "File.webkitRelativePath should be called dir.path + '/' + file.name: " + data[i].webkitRelativePath);
+ }
+ },
+ function() {
+ ok(false, "Something when wrong");
+ }
+ ).then(aNext);
+}
+
+function test_getFiles_recursiveComparison(aDirectory, aNext) {
+ aDirectory.getFiles(true).then(function(data) {
+ is(data.length, 2, "Only 2 files for this test.");
+ ok(data[0].name == 'foo.txt' || data[0].name == 'bar.txt', "First filename matches");
+ ok(data[1].name == 'foo.txt' || data[1].name == 'bar.txt', "Second filename matches");
+ }).then(function() {
+ return aDirectory.getFiles(false);
+ }).then(function(data) {
+ is(data.length, 1, "Only 1 file for this test.");
+ ok(data[0].name == 'foo.txt' || data[0].name == 'bar.txt', "First filename matches");
+ }).catch(function() {
+ ok(false, "Something when wrong");
+ }).then(aNext);
+}
diff --git a/dom/filesystem/tests/mochitest.ini b/dom/filesystem/tests/mochitest.ini
new file mode 100644
index 000000000..649016886
--- /dev/null
+++ b/dom/filesystem/tests/mochitest.ini
@@ -0,0 +1,10 @@
+[DEFAULT]
+support-files =
+ filesystem_commons.js
+ script_fileList.js
+ worker_basic.js
+
+[test_basic.html]
+[test_webkitdirectory.html]
+[test_worker_basic.html]
+[test_bug1319088.html]
diff --git a/dom/filesystem/tests/moz.build b/dom/filesystem/tests/moz.build
new file mode 100644
index 000000000..3b13ba431
--- /dev/null
+++ b/dom/filesystem/tests/moz.build
@@ -0,0 +1,7 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+MOCHITEST_MANIFESTS += ['mochitest.ini']
diff --git a/dom/filesystem/tests/script_fileList.js b/dom/filesystem/tests/script_fileList.js
new file mode 100644
index 000000000..89fd04cab
--- /dev/null
+++ b/dom/filesystem/tests/script_fileList.js
@@ -0,0 +1,129 @@
+var { classes: Cc, interfaces: Ci, utils: Cu } = Components;
+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;
+ }
+
+ testFile = parent;
+ }
+
+ return testFile;
+}
+
+function createTestFile() {
+ var tmpFile = Cc["@mozilla.org/file/directory_service;1"]
+ .getService(Ci.nsIDirectoryService)
+ .QueryInterface(Ci.nsIProperties)
+ .get('TmpD', Ci.nsIFile)
+ tmpFile.append('dir-test');
+ tmpFile.createUnique(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0o700);
+
+ var file1 = tmpFile.clone();
+ file1.append('foo.txt');
+ file1.create(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0o600);
+
+ var dir = tmpFile.clone();
+ dir.append('subdir');
+ dir.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0o700);
+
+ var file2 = dir.clone();
+ file2.append('bar.txt');
+ file2.create(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0o600);
+
+ 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,
+ name: testFile.leafName
+ });
+});
+
+addMessageListener("file.open", function (e) {
+ var testFile = Cc["@mozilla.org/file/directory_service;1"]
+ .getService(Ci.nsIDirectoryService)
+ .QueryInterface(Ci.nsIProperties)
+ .get("ProfD", Ci.nsIFile);
+ testFile.append("prefs.js");
+
+ sendAsyncMessage("file.opened", {
+ file: File.createFromNsIFile(testFile)
+ });
+});
diff --git a/dom/filesystem/tests/test_basic.html b/dom/filesystem/tests/test_basic.html
new file mode 100644
index 000000000..1308b9e3c
--- /dev/null
+++ b/dom/filesystem/tests/test_basic.html
@@ -0,0 +1,167 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for Directory API</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="filesystem_commons.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+
+<body>
+<script type="application/javascript;version=1.7">
+
+var directory;
+var fileList;
+
+function create_fileList(aPath) {
+ fileList = document.createElement('input');
+ fileList.setAttribute('type', 'file');
+ document.body.appendChild(fileList);
+
+ var url = SimpleTest.getTestFileURL("script_fileList.js");
+ var script = SpecialPowers.loadChromeScript(url);
+
+ function onOpened(message) {
+ SpecialPowers.wrap(fileList).mozSetDirectory(message.dir);
+ fileList.setAttribute('data-name', message.name);
+
+ fileList.getFilesAndDirectories().then(function(array) {
+ is(array.length, 1, "We want just 1 directory.");
+ ok(array[0] instanceof Directory, "We want just 1 directory.");
+
+ directory = array[0];
+ script.destroy();
+ next();
+ });
+ }
+
+ script.addMessageListener("dir.opened", onOpened);
+ script.sendAsyncMessage("dir.open", { path: aPath });
+}
+
+function test_simpleFilePicker(aPath) {
+ var url = SimpleTest.getTestFileURL("script_fileList.js");
+ var script = SpecialPowers.loadChromeScript(url);
+
+ function onOpened(message) {
+ SpecialPowers.wrap(fileList).mozSetFileArray([message.file]);
+
+ is(fileList.files.length, 1, "we want 1 element");
+ ok(fileList.files[0] instanceof File, "we want 1 file");
+ ok("webkitRelativePath" in fileList.files[0], "we have webkitRelativePath attribute");
+ is(fileList.files[0].webkitRelativePath, "", "No webkit relative path for normal filePicker");
+
+ script.destroy();
+ next();
+ }
+
+ script.addMessageListener("file.opened", onOpened);
+ script.sendAsyncMessage("file.open");
+}
+
+function test_duplicateGetFilesAndDirectories() {
+ var url = SimpleTest.getTestFileURL("script_fileList.js");
+ var script = SpecialPowers.loadChromeScript(url);
+
+ function onOpened(message) {
+ SpecialPowers.wrap(fileList).mozSetDirectory(message.dir);
+
+ var p1 = fileList.getFilesAndDirectories();
+ var p2 = fileList.getFilesAndDirectories();
+
+ isnot(p1, p2, "We create 2 different promises");
+
+ script.destroy();
+ next();
+ }
+
+ script.addMessageListener("dir.opened", onOpened);
+ script.sendAsyncMessage("dir.open", { path: 'test' });
+}
+
+function test_inputGetFiles() {
+ var url = SimpleTest.getTestFileURL("script_fileList.js");
+ var script = SpecialPowers.loadChromeScript(url);
+
+ function onOpened(message) {
+ SpecialPowers.wrap(fileList).mozSetDirectory(message.dir);
+ fileList.setAttribute('data-name', message.name);
+
+ fileList.getFilesAndDirectories()
+ .then(function(result) {
+ is(result.length, 1, "getFilesAndDirectories should return 1 element");
+ ok(result[0] instanceof Directory, "getFilesAndDirectories should return 1 directory");
+
+ return fileList.getFiles(false);
+ })
+ .then(function(result) {
+ is(result.length, 1, "getFiles should return 1 element");
+ ok(result[0] instanceof File, "getFile should return 1 file");
+ is(result[0].name, 'foo.txt', "getFiles()[0].name should be 'foo.txt'");
+ is(result[0].webkitRelativePath, fileList.dataset.name + '/foo.txt', "getFiles()[0].webkitRelativePath should be '/foo.txt'");
+
+ return fileList.getFiles(true);
+ })
+ .then(function(result) {
+ is(result.length, 2, "getFiles should return 2 elements");
+
+ function checkFile(file) {
+ ok(file instanceof File, "getFile[x] should return a file");
+ if (file.name == 'foo.txt') {
+ is(file.webkitRelativePath, fileList.dataset.name + '/foo.txt', "getFiles()[x].webkitRelativePath should be '/foo.txt'");
+ } else {
+ is(file.name, 'bar.txt', "getFiles()[x].name should be 'bar.txt'");
+ is(file.webkitRelativePath, fileList.dataset.name + '/subdir/bar.txt', "getFiles()[x].webkitRelativePath should be '/subdir/bar.txt'");
+ }
+ }
+
+ checkFile(result[0]);
+ checkFile(result[1]);
+ })
+ .then(function() {
+ script.destroy();
+ next();
+ });
+ }
+
+ script.addMessageListener("dir.opened", onOpened);
+ script.sendAsyncMessage("dir.open", { path: 'test' });
+}
+
+var tests = [
+ function() { setup_tests(next); },
+
+ 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); },
+
+ function() { create_fileList('root'); },
+ function() { test_basic(directory, next); },
+ function() { test_getFilesAndDirectories(directory, false, next); },
+ function() { test_getFiles(directory, false, next); },
+
+ test_duplicateGetFilesAndDirectories,
+ test_inputGetFiles,
+ test_simpleFilePicker
+];
+
+function next() {
+ if (!tests.length) {
+ SimpleTest.finish();
+ return;
+ }
+
+ var test = tests.shift();
+ test();
+}
+
+SimpleTest.waitForExplicitFinish();
+next();
+</script>
+</body>
+</html>
diff --git a/dom/filesystem/tests/test_bug1319088.html b/dom/filesystem/tests/test_bug1319088.html
new file mode 100644
index 000000000..e0a53223f
--- /dev/null
+++ b/dom/filesystem/tests/test_bug1319088.html
@@ -0,0 +1,66 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for bug 1319088</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+
+<body>
+<input id="input" type="file"></input>
+
+<script type="application/javascript;version=1.7">
+
+function testSetup() {
+ SpecialPowers.pushPrefEnv({"set": [["dom.input.dirpicker", true],
+ ["dom.webkitBlink.dirPicker.enabled", true]]}, next);
+}
+
+function populateInputFile() {
+ var url = SimpleTest.getTestFileURL("script_fileList.js");
+ var script = SpecialPowers.loadChromeScript(url);
+
+ function onOpened(message) {
+ var input = document.getElementById("input");
+ SpecialPowers.wrap(input).mozSetFileArray([message.file]);
+
+ script.destroy();
+ next();
+ }
+
+ script.addMessageListener("file.opened", onOpened);
+ script.sendAsyncMessage("file.open");
+}
+
+function checkBug() {
+ var input = document.getElementById("input");
+ is(input.files[0].webkitRelativePath, "", "No relative path!");
+
+ let form = document.createElement('form');
+ form.appendChild(input);
+
+ is(input.files[0].webkitRelativePath, "", "No relative path!");
+ SimpleTest.finish();
+}
+
+var tests = [
+ testSetup,
+ populateInputFile,
+ checkBug,
+];
+
+function next() {
+ if (!tests.length) {
+ SimpleTest.finish();
+ return;
+ }
+
+ var test = tests.shift();
+ test();
+}
+
+SimpleTest.waitForExplicitFinish();
+next();
+</script>
+</body>
+</html>
diff --git a/dom/filesystem/tests/test_webkitdirectory.html b/dom/filesystem/tests/test_webkitdirectory.html
new file mode 100644
index 000000000..825f5e8fb
--- /dev/null
+++ b/dom/filesystem/tests/test_webkitdirectory.html
@@ -0,0 +1,191 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for webkitdirectory and webkitRelativePath</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+
+<body>
+<input id="inputFileWebkitDirectory" type="file" webkitdirectory></input>
+<input id="inputFileWebkitDirectoryAndDirectory" type="file" webkitdirectory allowdirs></input>
+<input id="inputFileDirectory" type="file" allowdirs></input>
+<input id="inputFileDirectoryChange" type="file" webkitdirectory></input>
+
+<script type="application/javascript;version=1.7">
+
+function populateInputFile(aInputFile) {
+ var url = SimpleTest.getTestFileURL("script_fileList.js");
+ var script = SpecialPowers.loadChromeScript(url);
+
+ var MockFilePicker = SpecialPowers.MockFilePicker;
+ MockFilePicker.init(window, "A Mock File Picker", SpecialPowers.Ci.nsIFilePicker.modeOpen);
+
+ function onOpened(message) {
+ MockFilePicker.useDirectory(message.dir);
+
+ var input = document.getElementById(aInputFile);
+ input.setAttribute('data-name', message.name);
+ input.addEventListener('change', function change() {
+ input.removeEventListener('change', change);
+ MockFilePicker.cleanup();
+ script.destroy();
+ next();
+ });
+
+ input.click();
+ }
+
+ script.addMessageListener("dir.opened", onOpened);
+ script.sendAsyncMessage("dir.open", { path: 'test' });
+}
+
+function checkFile(file, fileList, dirName) {
+ for (var i = 0; i < fileList.length; ++i) {
+ ok(fileList[i] instanceof File, "We want just files.");
+ if (fileList[i].name == file.name) {
+ is(fileList[i].webkitRelativePath, dirName + file.path, "Path matches");
+ return;
+ }
+ }
+
+ ok(false, "File not found.");
+}
+
+function test_fileList(aInputFile, aWhat) {
+ var input = document.getElementById(aInputFile);
+ var fileList = input.files;
+
+ if (aWhat == null) {
+ is(fileList, null, "We want a null fileList for " + aInputFile);
+ next();
+ return;
+ }
+
+ is(fileList.length, aWhat.length, "We want just " + aWhat.length + " elements for " + aInputFile);
+ for (var i = 0; i < aWhat.length; ++i) {
+ checkFile(aWhat[i], fileList, input.dataset.name);
+ }
+
+ next();
+}
+
+function test_webkitdirectory_attribute() {
+ var a = document.createElement("input");
+ a.setAttribute("type", "file");
+
+ ok("webkitdirectory" in a, "HTMLInputElement.webkitdirectory exists");
+
+ ok(!a.hasAttribute("webkitdirectory"), "No webkitdirectory DOM attribute by default");
+ ok(!a.webkitdirectory, "No webkitdirectory attribute by default");
+
+ a.webkitdirectory = true;
+
+ ok(a.hasAttribute("webkitdirectory"), "Webkitdirectory DOM attribute is set");
+ ok(a.webkitdirectory, "Webkitdirectory attribute is set");
+
+ next();
+}
+
+function test_changeDataWhileWorking() {
+ var url = SimpleTest.getTestFileURL("script_fileList.js");
+ var script = SpecialPowers.loadChromeScript(url);
+
+ var MockFilePicker = SpecialPowers.MockFilePicker;
+ MockFilePicker.init(window, "A Mock File Picker", SpecialPowers.Ci.nsIFilePicker.modeOpen);
+
+ // Let's start retrieving the root nsIFile object
+ new Promise(function(resolve) {
+ function onOpened(message) {
+ script.removeMessageListener("dir.opened", onOpened);
+ resolve(message.dir);
+ }
+
+ script.addMessageListener("dir.opened", onOpened);
+ script.sendAsyncMessage("dir.open", { path: 'root' });
+ })
+
+ // input.click() pointing to the root dir
+ .then(function(aDir) {
+ MockFilePicker.cleanup();
+ MockFilePicker.init(window, "A Mock File Picker", SpecialPowers.Ci.nsIFilePicker.modeOpen);
+ MockFilePicker.useDirectory(aDir);
+ var input = document.getElementById("inputFileDirectoryChange");
+ input.click();
+ })
+
+ // Before onchange, let's take the 'test' directory
+ .then(function() {
+ return new Promise(function(resolve) {
+ function onOpened(message) {
+ script.removeMessageListener("dir.opened", onOpened);
+ script.destroy();
+ resolve(message.dir);
+ }
+
+ script.addMessageListener("dir.opened", onOpened);
+ script.sendAsyncMessage("dir.open", { path: 'test' });
+ });
+ })
+
+ // Now let's click again and wait for onchange.
+ .then(function(aDir) {
+ return new Promise(function(resolve) {
+ MockFilePicker.cleanup();
+ MockFilePicker.init(window, "A Mock File Picker", SpecialPowers.Ci.nsIFilePicker.modeOpen);
+ MockFilePicker.useDirectory(aDir);
+
+ var input = document.getElementById("inputFileDirectoryChange");
+ input.addEventListener('change', function() {
+ MockFilePicker.cleanup();
+ resolve();
+ });
+
+ input.click();
+ })
+ })
+
+ .then(function() {
+ test_fileList('inputFileWebkitDirectory', testDirData);
+ });
+}
+
+function test_setup() {
+ SpecialPowers.pushPrefEnv({"set": [["dom.input.dirpicker", true],
+ ["dom.webkitBlink.dirPicker.enabled", true]]}, next);
+}
+
+var testDirData = [ { name: 'foo.txt', path: '/foo.txt' },
+ { name: 'bar.txt', path: '/subdir/bar.txt' }];
+
+var tests = [
+ test_setup,
+
+ function() { populateInputFile('inputFileWebkitDirectory'); },
+ function() { populateInputFile('inputFileWebkitDirectoryAndDirectory'); },
+ function() { populateInputFile('inputFileDirectory'); },
+
+ function() { test_fileList('inputFileWebkitDirectory', testDirData) },
+ function() { test_fileList('inputFileWebkitDirectoryAndDirectory', testDirData) },
+ function() { test_fileList('inputFileDirectory', null); },
+
+ test_webkitdirectory_attribute,
+
+ test_changeDataWhileWorking,
+];
+
+function next() {
+ if (!tests.length) {
+ SimpleTest.finish();
+ return;
+ }
+
+ var test = tests.shift();
+ test();
+}
+
+SimpleTest.waitForExplicitFinish();
+next();
+</script>
+</body>
+</html>
diff --git a/dom/filesystem/tests/test_worker_basic.html b/dom/filesystem/tests/test_worker_basic.html
new file mode 100644
index 000000000..fd36faeeb
--- /dev/null
+++ b/dom/filesystem/tests/test_worker_basic.html
@@ -0,0 +1,72 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for Directory API in workers</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="filesystem_commons.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+
+<body>
+<script type="application/javascript;version=1.7">
+
+var fileList;
+
+function create_fileList() {
+ fileList = document.createElement('input');
+ fileList.setAttribute('type', 'file');
+ document.body.appendChild(fileList);
+
+ var url = SimpleTest.getTestFileURL("script_fileList.js");
+ var script = SpecialPowers.loadChromeScript(url);
+
+ function onOpened(message) {
+ SpecialPowers.wrap(fileList).mozSetDirectory(message.dir);
+ script.destroy();
+ next();
+ }
+
+ script.addMessageListener("dir.opened", onOpened);
+ script.sendAsyncMessage("dir.open", { path: 'ProfD' });
+}
+
+function test_worker() {
+ fileList.getFilesAndDirectories().then(function(array) {
+ var worker = new Worker('worker_basic.js');
+ worker.onmessage = function(e) {
+ if (e.data.type == 'finish') {
+ next();
+ return;
+ }
+
+ if (e.data.type == 'test') {
+ ok(e.data.test, e.data.message);
+ }
+ }
+
+ worker.postMessage(array[0]);
+ });
+}
+
+var tests = [
+ function() { setup_tests(next); },
+
+ create_fileList,
+ test_worker,
+];
+
+function next() {
+ if (!tests.length) {
+ SimpleTest.finish();
+ return;
+ }
+
+ var test = tests.shift();
+ test();
+}
+
+SimpleTest.waitForExplicitFinish();
+next();
+</script>
+</body>
+</html>
diff --git a/dom/filesystem/tests/worker_basic.js b/dom/filesystem/tests/worker_basic.js
new file mode 100644
index 000000000..01df3fbd1
--- /dev/null
+++ b/dom/filesystem/tests/worker_basic.js
@@ -0,0 +1,41 @@
+importScripts('filesystem_commons.js');
+
+function finish() {
+ postMessage({ type: 'finish' });
+}
+
+function ok(a, msg) {
+ postMessage({ type: 'test', test: !!a, message: msg });
+}
+
+function is(a, b, msg) {
+ ok(a === b, msg);
+}
+
+function isnot(a, b, msg) {
+ ok(a != b, msg);
+}
+
+var tests = [
+ function() { test_basic(directory, next); },
+ function() { test_getFilesAndDirectories(directory, true, next); },
+ function() { test_getFiles(directory, false, next); },
+ function() { test_getFiles(directory, true, next); },
+];
+
+function next() {
+ if (!tests.length) {
+ finish();
+ return;
+ }
+
+ var test = tests.shift();
+ test();
+}
+
+var directory;
+
+onmessage = function(e) {
+ directory = e.data;
+ next();
+}