summaryrefslogtreecommitdiffstats
path: root/dom/filesystem/compat/tests
diff options
context:
space:
mode:
Diffstat (limited to 'dom/filesystem/compat/tests')
-rw-r--r--dom/filesystem/compat/tests/mochitest.ini8
-rw-r--r--dom/filesystem/compat/tests/moz.build7
-rw-r--r--dom/filesystem/compat/tests/script_entries.js47
-rw-r--r--dom/filesystem/compat/tests/test_basic.html494
-rw-r--r--dom/filesystem/compat/tests/test_formSubmission.html267
-rw-r--r--dom/filesystem/compat/tests/test_no_dnd.html85
6 files changed, 908 insertions, 0 deletions
diff --git a/dom/filesystem/compat/tests/mochitest.ini b/dom/filesystem/compat/tests/mochitest.ini
new file mode 100644
index 000000000..2b6eafb55
--- /dev/null
+++ b/dom/filesystem/compat/tests/mochitest.ini
@@ -0,0 +1,8 @@
+[DEFAULT]
+support-files =
+ script_entries.js
+ !/dom/html/test/form_submit_server.sjs
+
+[test_basic.html]
+[test_no_dnd.html]
+[test_formSubmission.html]
diff --git a/dom/filesystem/compat/tests/moz.build b/dom/filesystem/compat/tests/moz.build
new file mode 100644
index 000000000..3b13ba431
--- /dev/null
+++ b/dom/filesystem/compat/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/compat/tests/script_entries.js b/dom/filesystem/compat/tests/script_entries.js
new file mode 100644
index 000000000..8083214c9
--- /dev/null
+++ b/dom/filesystem/compat/tests/script_entries.js
@@ -0,0 +1,47 @@
+var { classes: Cc, interfaces: Ci, utils: Cu } = Components;
+Cu.importGlobalProperties(["File", "Directory"]);
+
+var tmpFile, tmpDir;
+
+addMessageListener("entries.open", function (e) {
+ tmpFile = Cc["@mozilla.org/file/directory_service;1"]
+ .getService(Ci.nsIDirectoryService)
+ .QueryInterface(Ci.nsIProperties)
+ .get('TmpD', Ci.nsIFile)
+ tmpFile.append('file.txt');
+ tmpFile.createUnique(Components.interfaces.nsIFile.FILE_TYPE, 0o600);
+
+ tmpDir = Cc["@mozilla.org/file/directory_service;1"]
+ .getService(Ci.nsIDirectoryService)
+ .QueryInterface(Ci.nsIProperties)
+ .get('TmpD', Ci.nsIFile)
+
+ tmpDir.append('dir-test');
+ tmpDir.createUnique(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0o700);
+
+ var file1 = tmpDir.clone();
+ file1.append('foo.txt');
+ file1.create(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0o600);
+
+ var dir1 = tmpDir.clone();
+ dir1.append('subdir');
+ dir1.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0o700);
+
+ var file2 = dir1.clone();
+ file2.append('bar..txt'); // Note the double ..
+ file2.create(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0o600);
+
+ var dir2 = dir1.clone();
+ dir2.append('subsubdir');
+ dir2.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0o700);
+
+ sendAsyncMessage("entries.opened", {
+ data: [ new Directory(tmpDir.path), File.createFromNsIFile(tmpFile) ]
+ });
+});
+
+addMessageListener("entries.delete", function(e) {
+ tmpFile.remove(true);
+ tmpDir.remove(true);
+ sendAsyncMessage("entries.deleted");
+});
diff --git a/dom/filesystem/compat/tests/test_basic.html b/dom/filesystem/compat/tests/test_basic.html
new file mode 100644
index 000000000..85a7418d5
--- /dev/null
+++ b/dom/filesystem/compat/tests/test_basic.html
@@ -0,0 +1,494 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for Blink FileSystem API - subset</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="entries" type="file"></input>
+<script type="application/javascript;version=1.7">
+
+var fileEntry;
+var directoryEntry;
+var script;
+
+function setup_tests() {
+ SpecialPowers.pushPrefEnv({"set": [["dom.webkitBlink.dirPicker.enabled", true],
+ ["dom.filesystem.pathcheck.disabled", true],
+ ["dom.webkitBlink.filesystem.enabled", true]]}, next);
+}
+
+function populate_entries() {
+ var url = SimpleTest.getTestFileURL("script_entries.js");
+ script = SpecialPowers.loadChromeScript(url);
+
+ function onOpened(message) {
+ var entries = document.getElementById('entries');
+ SpecialPowers.wrap(entries).mozSetDndFilesAndDirectories(message.data);
+ next();
+ }
+
+ script.addMessageListener("entries.opened", onOpened);
+ script.sendAsyncMessage("entries.open");
+}
+
+function test_entries() {
+ var entries = document.getElementById('entries');
+ ok("webkitEntries" in entries, "HTMLInputElement.webkitEntries");
+ is(entries.webkitEntries.length, 2, "HTMLInputElement.webkitEntries.length == 2");
+ is(entries.files.length, 1, "HTMLInputElement.files is still populated");
+
+ for (var i = 0; i < entries.webkitEntries.length; ++i) {
+ if (entries.webkitEntries[i].isFile) {
+ ok(!fileEntry, "We just want 1 fileEntry");
+ fileEntry = entries.webkitEntries[i];
+ } else {
+ ok(entries.webkitEntries[i].isDirectory, "If not a file, we have a directory.");
+ ok(!directoryEntry, "We just want 1 directoryEntry");
+ directoryEntry = entries.webkitEntries[i];
+ }
+ }
+
+ next();
+}
+
+function test_fileEntry() {
+ ok("name" in fileEntry, "We have a name.");
+ ok("fullPath" in fileEntry, "We have a fullPath.");
+ ok("filesystem" in fileEntry, "We have a filesystem.");
+
+ next();
+}
+
+function test_fileEntry_file() {
+ fileEntry.file(function(file) {
+ ok(file, "We have a file here!");
+ is(file.name, fileEntry.name, "Same file name.");
+ next();
+ }, function() {
+ ok(false, "Something when wrong!");
+ });
+}
+
+function test_fileEntry_getParent() {
+ fileEntry.getParent(function(entry) {
+ is(fileEntry.fullPath, entry.fullPath, "Top level FileEntry should return itself as parent.");
+ next();
+ }, function() {
+ ok(false, "This is wrong.");
+ });
+}
+
+function test_directoryEntry() {
+ ok("name" in directoryEntry, "We have a name.");
+ ok("fullPath" in directoryEntry, "We have a fullPath.");
+ ok("filesystem" in directoryEntry, "We have a filesystem.");
+
+ next();
+}
+
+function test_directoryEntry_createReader() {
+ var reader = directoryEntry.createReader();
+ ok(reader, "We have a DirectoryReader");
+
+ reader.readEntries(function(a) {
+ ok(Array.isArray(a), "We want an array.");
+ is(a.length, 2, "reader.readyEntries returns 2 elements.");
+
+ for (var i = 0; i < 2; ++i) {
+ ok(a[i].name == "subdir" || a[i].name == "foo.txt", "Correct names");
+ is(a[i].fullPath, directoryEntry.fullPath + "/" + a[i].name, "FullPath is correct");
+ }
+
+ // Called twice:
+ reader.readEntries(function(a) {
+ ok(Array.isArray(a), "We want an array.");
+ is(a.length, 0, "reader.readyEntries returns 0 elements.");
+ next();
+ }, function() {
+ ok(false, "Something when wrong!");
+ });
+
+ }, function() {
+ ok(false, "Something when wrong!");
+ });
+}
+
+function test_directoryEntry_getParent() {
+ directoryEntry.getParent(function(entry) {
+ is(directoryEntry.fullPath, entry.fullPath, "Top level FileEntry should return itself as parent.");
+ next();
+ }, function() {
+ ok(false, "This is wrong.");
+ });
+}
+
+function test_directoryEntry_getFile_securityError() {
+ directoryEntry.getFile("foo", { create: true },
+ function() {
+ ok(false, "This should not happen.");
+ }, function(e) {
+ is(e.name, "SecurityError", "This must generate a SecurityError.");
+ next();
+ });
+}
+
+function test_directoryEntry_getFile_typeMismatchError() {
+ directoryEntry.getFile("subdir", {},
+ function() {
+ ok(false, "This should not happen.");
+ }, function(e) {
+ is(e.name, "TypeMismatchError", "This must generate a TypeMismatchError.");
+ next();
+ });
+}
+
+function test_directoryEntry_getFile_nonValidPath() {
+ directoryEntry.getFile("../../", {},
+ function() {
+ ok(false, "This should not happen.");
+ }, function(e) {
+ is(e.name, "NotFoundError", "This must generate a NotFoundError.");
+ next();
+ });
+}
+
+function test_directoryEntry_getFile_nonExistingPath() {
+ directoryEntry.getFile("foo_bar.txt", {},
+ function() {
+ ok(false, "This should not happen.");
+ }, function(e) {
+ is(e.name, "NotFoundError", "This must generate a NotFoundError.");
+ next();
+ });
+}
+
+function test_directoryEntry_getFile_simple() {
+ directoryEntry.getFile("foo.txt", {},
+ function(e) {
+ is(e.name, "foo.txt", "We have the right FileEntry.");
+ test_getParent(e, directoryEntry, /* nested */ false);
+ }, function(e) {
+ ok(false, "This should not happen.");
+ });
+}
+
+function test_directoryEntry_getFile_deep() {
+ directoryEntry.getFile("subdir/bar..txt", {},
+ function(e) {
+ is(e.name, "bar..txt", "We have the right FileEntry.");
+ test_getParent(e, directoryEntry, /* nested */ true);
+ }, function(e) {
+ ok(false, "This should not happen.");
+ });
+}
+
+function test_directoryEntry_getDirectory_securityError() {
+ directoryEntry.getDirectory("foo", { create: true },
+ function() {
+ ok(false, "This should not happen.");
+ }, function(e) {
+ is(e.name, "SecurityError", "This must generate a SecurityError.");
+ next();
+ });
+}
+
+function test_directoryEntry_getDirectory_typeMismatchError() {
+ directoryEntry.getDirectory("foo.txt", {},
+ function() {
+ ok(false, "This should not happen.");
+ }, function(e) {
+ is(e.name, "TypeMismatchError", "This must generate a TypeMismatchError.");
+ next();
+ });
+}
+
+function test_directoryEntry_getDirectory_nonValidPath() {
+ directoryEntry.getDirectory("../../", {},
+ function() {
+ ok(false, "This should not happen.");
+ }, function(e) {
+ is(e.name, "NotFoundError", "This must generate a NotFoundError.");
+ next();
+ });
+}
+
+function test_directoryEntry_getDirectory_nonExistingPath() {
+ directoryEntry.getDirectory("non_existing_dir", {},
+ function() {
+ ok(false, "This should not happen.");
+ }, function(e) {
+ is(e.name, "NotFoundError", "This must generate a NotFoundError.");
+ next();
+ });
+}
+
+function test_directoryEntry_getDirectory_simple() {
+ directoryEntry.getDirectory("subdir", {},
+ function(e) {
+ is(e.name, "subdir", "We have the right DirectoryEntry.");
+ test_getParent(e, directoryEntry, /* nested */ false);
+ }, function(e) {
+ ok(false, "This should not happen.");
+ });
+}
+
+function test_directoryEntry_getDirectory_deep() {
+ directoryEntry.getDirectory("subdir/subsubdir", {},
+ function(e) {
+ is(e.name, "subsubdir", "We have the right DirectoryEntry.");
+ test_getParent(e, directoryEntry, /* nested */ true);
+ }, function(e) {
+ ok(false, "This should not happen.");
+ });
+}
+
+function test_filesystem() {
+ is(fileEntry.filesystem, directoryEntry.filesystem, "FileSystem object is shared.");
+
+ var fs = fileEntry.filesystem;
+ ok(fs.name, "FileSystem.name exists.");
+ ok(fs.root, "FileSystem has a root.");
+
+ is(fs.root.name, "", "FileSystem.root.name must be an empty string.");
+ is(fs.root.fullPath, "/", "FileSystem.root.fullPath must be '/'");
+
+ reader = fs.root.createReader();
+ reader.readEntries(function(a) {
+ ok(Array.isArray(a), "We want an array.");
+ is(a.length, 2, "reader.readyEntries returns 2 elements.");
+ next();
+ }, function() {
+ ok(false, "Something when wrong!");
+ });
+}
+
+function test_root_getFile_securityError() {
+ fileEntry.filesystem.root.getFile("foo", { create: true },
+ function() {
+ ok(false, "This should not happen.");
+ }, function(e) {
+ is(e.name, "SecurityError", "This must generate a SecurityError.");
+ next();
+ });
+}
+
+function test_root_getFile_typeMismatchError() {
+ fileEntry.filesystem.root.getFile(directoryEntry.name, {},
+ function() {
+ ok(false, "This should not happen.");
+ }, function(e) {
+ is(e.name, "TypeMismatchError", "This must generate a TypeMismatchError.");
+ next();
+ });
+}
+
+function test_root_getFile_nonValidPath() {
+ fileEntry.filesystem.root.getFile("../../", {},
+ function() {
+ ok(false, "This should not happen.");
+ }, function(e) {
+ is(e.name, "NotFoundError", "This must generate a NotFoundError.");
+ next();
+ });
+}
+
+function test_root_getFile_nonExistingPath() {
+ fileEntry.filesystem.root.getFile("existing.txt", {},
+ function() {
+ ok(false, "This should not happen.");
+ }, function(e) {
+ is(e.name, "NotFoundError", "This must generate a NotFoundError.");
+ next();
+ });
+}
+
+function test_root_getFile_simple() {
+ fileEntry.filesystem.root.getFile(fileEntry.name, {},
+ function(e) {
+ is(e.name, fileEntry.name, "We have the right FileEntry.");
+ next();
+ }, function(e) {
+ ok(false, "This should not happen.");
+ });
+}
+
+function test_root_getFile_deep() {
+ fileEntry.filesystem.root.getFile(directoryEntry.name + "/subdir/bar..txt", {},
+ function(e) {
+ is(e.name, "bar..txt", "We have the right FileEntry.");
+ next();
+ }, function(e) {
+ ok(false, "This should not happen.");
+ });
+}
+
+function test_root_getDirectory_securityError() {
+ fileEntry.filesystem.root.getDirectory("foo", { create: true },
+ function() {
+ ok(false, "This should not happen.");
+ }, function(e) {
+ is(e.name, "SecurityError", "This must generate a SecurityError.");
+ next();
+ });
+}
+
+function test_root_getDirectory_typeMismatchError() {
+ fileEntry.filesystem.root.getDirectory(fileEntry.name, {},
+ function() {
+ ok(false, "This should not happen.");
+ }, function(e) {
+ is(e.name, "TypeMismatchError", "This must generate a TypeMismatchError.");
+ next();
+ });
+}
+
+function test_root_getDirectory_nonValidPath() {
+ fileEntry.filesystem.root.getDirectory("../../", {},
+ function() {
+ ok(false, "This should not happen.");
+ }, function(e) {
+ is(e.name, "NotFoundError", "This must generate a NotFoundError.");
+ next();
+ });
+}
+
+function test_root_getDirectory_nonExistingPath() {
+ fileEntry.filesystem.root.getDirectory("404", {},
+ function() {
+ ok(false, "This should not happen.");
+ }, function(e) {
+ is(e.name, "NotFoundError", "This must generate a NotFoundError.");
+ next();
+ });
+}
+
+function test_root_getDirectory_simple() {
+ fileEntry.filesystem.root.getDirectory(directoryEntry.name, {},
+ function(e) {
+ is(e.name, directoryEntry.name, "We have the right DirectoryEntry.");
+ next();
+ }, function(e) {
+ ok(false, "This should not happen.");
+ });
+}
+
+function test_root_getDirectory_deep() {
+ fileEntry.filesystem.root.getDirectory(directoryEntry.name + "/subdir/subsubdir", {},
+ function(e) {
+ is(e.name, "subsubdir", "We have the right DirectoryEntry.");
+ next();
+ }, function(e) {
+ ok(false, "This should not happen.");
+ });
+}
+
+function cleanUpTestingFiles() {
+ script.addMessageListener("entries.deleted", function onDeleted() {
+ script.removeMessageListener("entries.deleted");
+ script.destroy();
+ next();
+ });
+
+ script.sendAsyncMessage("entries.delete");
+}
+
+function test_getParent(entry, parentEntry, nested) {
+ entry.getParent(function(e) {
+ ok(e, "We have a parent Entry.");
+ if (!nested) {
+ is (e, parentEntry, "Parent entry matches");
+ next();
+ } else {
+ test_getParent(e, parentEntry, false);
+ }
+ }, function(e) {
+ ok(false, "This should not happen.");
+ });
+}
+
+function test_webkitRelativePath() {
+ fileEntry.file(function(file1) {
+ ok(file1, "We have a file here!");
+ ok(!file1.webkitRelativePath, "webkitRelativePath is an empty string");
+
+ fileEntry.file(function(file2) {
+ ok(file2, "We have a file here!");
+ ok(!file2.webkitRelativePath, "webkitRelativePath is an empty string");
+ isnot(file1, file2, "The 2 files are not the same");
+
+ next();
+ }, function() {
+ ok(false, "Something when wrong!");
+ });
+ }, function() {
+ ok(false, "Something when wrong!");
+ });
+}
+
+var tests = [
+ setup_tests,
+ populate_entries,
+
+ test_entries,
+
+ test_fileEntry,
+ test_fileEntry_file,
+ test_fileEntry_getParent,
+
+ test_directoryEntry,
+ test_directoryEntry_createReader,
+ test_directoryEntry_getParent,
+
+ test_directoryEntry_getFile_securityError,
+ test_directoryEntry_getFile_typeMismatchError,
+ test_directoryEntry_getFile_nonValidPath,
+ test_directoryEntry_getFile_nonExistingPath,
+ test_directoryEntry_getFile_simple,
+ test_directoryEntry_getFile_deep,
+
+ test_directoryEntry_getDirectory_securityError,
+ test_directoryEntry_getDirectory_typeMismatchError,
+ test_directoryEntry_getDirectory_nonValidPath,
+ test_directoryEntry_getDirectory_nonExistingPath,
+ test_directoryEntry_getDirectory_simple,
+ test_directoryEntry_getDirectory_deep,
+
+ test_filesystem,
+
+ test_root_getFile_securityError,
+ test_root_getFile_typeMismatchError,
+ test_root_getFile_nonValidPath,
+ test_root_getFile_nonExistingPath,
+ test_root_getFile_simple,
+ test_root_getFile_deep,
+
+ test_root_getDirectory_securityError,
+ test_root_getDirectory_typeMismatchError,
+ test_root_getDirectory_nonValidPath,
+ test_root_getDirectory_nonExistingPath,
+ test_root_getDirectory_simple,
+ test_root_getDirectory_deep,
+
+ test_webkitRelativePath,
+
+ cleanUpTestingFiles,
+];
+
+function next() {
+ if (!tests.length) {
+ SimpleTest.finish();
+ return;
+ }
+
+ var test = tests.shift();
+ test();
+}
+
+SimpleTest.waitForExplicitFinish();
+next();
+</script>
+</body>
+</html>
diff --git a/dom/filesystem/compat/tests/test_formSubmission.html b/dom/filesystem/compat/tests/test_formSubmission.html
new file mode 100644
index 000000000..0c04b8bf1
--- /dev/null
+++ b/dom/filesystem/compat/tests/test_formSubmission.html
@@ -0,0 +1,267 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for Directory form submission</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+ <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
+</head>
+<body onload="return next();">
+
+<iframe name="target_iframe" id="target_iframe"></iframe>
+
+<form action="../../../html/test/form_submit_server.sjs" target="target_iframe" id="form"
+ method="POST" enctype="multipart/form-data">
+</form>
+
+<script class="testbody" type="text/javascript;version=1.8">
+
+var form;
+var iframe;
+var input;
+var xhr;
+
+function setup_tests() {
+ form = document.getElementById("form");
+
+ iframe = document.getElementById("target_iframe");
+ iframe.onload = function() {
+ info("Frame loaded!");
+ next();
+ }
+
+ SpecialPowers.pushPrefEnv({"set": [["dom.input.dirpicker", true],
+ ["dom.webkitBlink.dirPicker.enabled", true],
+ ["dom.filesystem.pathcheck.disabled", true],
+ ["dom.webkitBlink.filesystem.enabled", true]]}, next);
+}
+
+function populate_entries(webkitDirectory) {
+ if (input) {
+ form.removeChild(input);
+ }
+
+ input = document.createElement('input');
+ input.setAttribute('id', 'input');
+ input.setAttribute('type', 'file');
+ input.setAttribute('name', 'input');
+
+ if (webkitDirectory) {
+ input.setAttribute('webkitdirectory', 'true');
+ }
+
+ form.appendChild(input);
+
+ var url = SimpleTest.getTestFileURL("script_entries.js");
+ var script = SpecialPowers.loadChromeScript(url);
+
+ function onOpened(message) {
+ input.addEventListener("change", function onChange() {
+ input.removeEventListener("change", onChange);
+ next();
+ });
+
+ SpecialPowers.wrap(input).mozSetDndFilesAndDirectories([message.data[0]]);
+ script.destroy();
+ }
+
+ script.addMessageListener("entries.opened", onOpened);
+ script.sendAsyncMessage("entries.open");
+}
+
+function setup_plain() {
+ info("Preparing for a plain text submission...");
+ form.action = "../../../html/test/form_submit_server.sjs?plain";
+ form.method = "POST";
+ form.enctype = "text/plain";
+ form.submit();
+}
+
+function test_plain() {
+ var content = iframe.contentDocument.documentElement.textContent;
+ var submission = JSON.parse(content);
+ input.getFilesAndDirectories().then(function(array) {
+ is(submission, array.map(function(v) {
+ return "input=" + v.name + "\r\n";
+ }).join(""), "Data match");
+
+ next();
+ });
+}
+
+function setup_urlencoded() {
+ info("Preparing for a urlencoded submission...");
+ form.action = "../../../html/test/form_submit_server.sjs?url";
+ form.method = "POST";
+ form.enctype = "application/x-www-form-urlencoded";
+ form.submit();
+}
+
+function setup_urlencoded_get() {
+ info("Preparing for a urlencoded+GET submission...");
+ form.action = "../../../html/test/form_submit_server.sjs?xxyy";
+ form.method = "GET";
+ form.enctype = "";
+ form.submit();
+}
+
+function setup_urlencoded_empty() {
+ info("Preparing for a urlencoded+default values submission...");
+ form.action = "../../../html/test/form_submit_server.sjs";
+ form.method = "";
+ form.enctype = "";
+ form.submit();
+}
+
+function test_urlencoded() {
+ var content = iframe.contentDocument.documentElement.textContent;
+ var submission = JSON.parse(content);
+ input.getFilesAndDirectories().then(function(array) {
+ is(submission, array.map(function(v) {
+ return "input=" + v.name;
+ }).join("&"), "Data match");
+
+ next();
+ });
+}
+
+function setup_formData() {
+ info("Preparing for a fromData submission...");
+
+ xhr = new XMLHttpRequest();
+ xhr.onload = next;
+ xhr.open("POST", "../../../html/test/form_submit_server.sjs");
+ xhr.send(new FormData(form));
+}
+
+function test_multipart() {
+ var submission = JSON.parse(xhr.responseText);
+ input.getFilesAndDirectories().then(function(array) {
+ is(submission.length, array.length, "Same length");
+
+ for (var i = 0; i < array.length; ++i) {
+ if (array[i] instanceof Directory) {
+ is(submission[i].headers["Content-Disposition"],
+ "form-data; name=\"input\"; filename=\"/" + array[i].name + "\"",
+ "Correct Content-Disposition");
+ is(submission[i].headers["Content-Type"], "application/octet-stream",
+ "Correct Content-Type");
+ is(submission[i].body, "", "Correct body");
+ } else {
+ ok(array[i] instanceof File);
+ is(submission[i].headers["Content-Disposition"],
+ "form-data; name=\"input\"; filename=\"" + array[i].name + "\"",
+ "Correct Content-Disposition");
+ is(submission[i].headers["Content-Type"], array[i].type,
+ "Correct Content-Type");
+ is(submission[i].body, "", "Correct body");
+ }
+ }
+ next();
+ });
+}
+
+function test_webkit_plain() {
+ var content = iframe.contentDocument.documentElement.textContent;
+ var submission = JSON.parse(content);
+
+ input.getFiles(true).then(function(array) {
+ is(submission, array.map(function(v) {
+ return "input=" + v.name + "\r\n";
+ }).join(""), "Data match");
+
+ next();
+ });
+}
+
+function test_webkit_urlencoded() {
+ var content = iframe.contentDocument.documentElement.textContent;
+ var submission = JSON.parse(content);
+ input.getFiles(true).then(function(array) {
+ is(submission, array.map(function(v) {
+ return "input=" + v.name;
+ }).join("&"), "Data match");
+
+ next();
+ });
+}
+
+function test_webkit_multipart() {
+ var submission = JSON.parse(xhr.responseText);
+ input.getFiles(true).then(function(array) {
+ is(submission.length, array.length, "Same length");
+
+ for (var i = 0; i < array.length; ++i) {
+ if (array[i] instanceof Directory) {
+ is(submission[i].headers["Content-Disposition"],
+ "form-data; name=\"input\"; filename=\"/" + array[i].name + "\"",
+ "Correct Content-Disposition");
+ is(submission[i].headers["Content-Type"], "application/octet-stream",
+ "Correct Content-Type");
+ is(submission[i].body, "", "Correct body");
+ } else {
+ ok(array[i] instanceof File);
+ is(submission[i].headers["Content-Disposition"],
+ "form-data; name=\"input\"; filename=\"" + array[i].webkitRelativePath + "\"",
+ "Correct Content-Disposition");
+ is(submission[i].headers["Content-Type"], array[i].type,
+ "Correct Content-Type");
+ is(submission[i].body, "", "Correct body");
+ }
+ }
+ next();
+ });
+}
+
+var tests = [
+ setup_tests,
+ function() { populate_entries(false); },
+
+ setup_plain,
+ test_plain,
+
+ setup_urlencoded,
+ test_urlencoded,
+
+ setup_urlencoded_get,
+ test_urlencoded,
+
+ setup_urlencoded_empty,
+ test_urlencoded,
+
+ setup_formData,
+ test_multipart,
+
+ function() { populate_entries(true); },
+
+ setup_plain,
+ test_webkit_plain,
+
+ setup_urlencoded,
+ test_webkit_urlencoded,
+
+ setup_urlencoded_get,
+ test_webkit_urlencoded,
+
+ setup_urlencoded_empty,
+ test_webkit_urlencoded,
+
+ setup_formData,
+ test_webkit_multipart,
+];
+
+function next() {
+ if (!tests.length) {
+ SimpleTest.finish();
+ return;
+ }
+
+ var test = tests.shift();
+ test();
+}
+
+SimpleTest.waitForExplicitFinish();
+
+</script>
+</body>
+</html>
diff --git a/dom/filesystem/compat/tests/test_no_dnd.html b/dom/filesystem/compat/tests/test_no_dnd.html
new file mode 100644
index 000000000..a78ac108f
--- /dev/null
+++ b/dom/filesystem/compat/tests/test_no_dnd.html
@@ -0,0 +1,85 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for Blink FileSystem API - no DND == no webkitEntries</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+
+<body>
+<script type="application/javascript;version=1.7">
+
+var fileEntry;
+var directoryEntry;
+var script;
+var entries;
+
+function setup_tests() {
+ SpecialPowers.pushPrefEnv({"set": [["dom.webkitBlink.dirPicker.enabled", true],
+ ["dom.filesystem.pathcheck.disabled", true],
+ ["dom.webkitBlink.filesystem.enabled", true]]}, next);
+}
+
+function populate_entries() {
+ entries = document.createElement('input');
+ entries.setAttribute('type', 'file');
+ document.body.appendChild(entries);
+
+ var url = SimpleTest.getTestFileURL("script_entries.js");
+ script = SpecialPowers.loadChromeScript(url);
+
+ function onOpened(message) {
+ for (var i = 0 ; i < message.data.length; ++i) {
+ if (message.data[i] instanceof File) {
+ SpecialPowers.wrap(entries).mozSetFileArray([message.data[i]]);
+ next();
+ }
+ }
+ }
+
+ script.addMessageListener("entries.opened", onOpened);
+ script.sendAsyncMessage("entries.open");
+}
+
+function test_entries() {
+ ok("webkitEntries" in entries, "HTMLInputElement.webkitEntries");
+ is(entries.webkitEntries.length, 0, "HTMLInputElement.webkitEntries.length == 0");
+ is(entries.files.length, 1, "HTMLInputElement.files is still populated");
+
+ next();
+}
+
+function cleanUpTestingFiles() {
+ script.addMessageListener("entries.deleted", function onDeleted() {
+ script.removeMessageListener("entries.deleted");
+ script.destroy();
+ next();
+ });
+
+ script.sendAsyncMessage("entries.delete");
+}
+
+var tests = [
+ setup_tests,
+ populate_entries,
+
+ test_entries,
+
+ cleanUpTestingFiles,
+];
+
+function next() {
+ if (!tests.length) {
+ SimpleTest.finish();
+ return;
+ }
+
+ var test = tests.shift();
+ test();
+}
+
+SimpleTest.waitForExplicitFinish();
+next();
+</script>
+</body>
+</html>