From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- dom/filesystem/tests/filesystem_commons.js | 103 +++++++++++++ dom/filesystem/tests/mochitest.ini | 10 ++ dom/filesystem/tests/moz.build | 7 + dom/filesystem/tests/script_fileList.js | 129 +++++++++++++++++ dom/filesystem/tests/test_basic.html | 167 +++++++++++++++++++++ dom/filesystem/tests/test_bug1319088.html | 66 +++++++++ dom/filesystem/tests/test_webkitdirectory.html | 191 +++++++++++++++++++++++++ dom/filesystem/tests/test_worker_basic.html | 72 ++++++++++ dom/filesystem/tests/worker_basic.js | 41 ++++++ 9 files changed, 786 insertions(+) create mode 100644 dom/filesystem/tests/filesystem_commons.js create mode 100644 dom/filesystem/tests/mochitest.ini create mode 100644 dom/filesystem/tests/moz.build create mode 100644 dom/filesystem/tests/script_fileList.js create mode 100644 dom/filesystem/tests/test_basic.html create mode 100644 dom/filesystem/tests/test_bug1319088.html create mode 100644 dom/filesystem/tests/test_webkitdirectory.html create mode 100644 dom/filesystem/tests/test_worker_basic.html create mode 100644 dom/filesystem/tests/worker_basic.js (limited to 'dom/filesystem/tests') 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 @@ + + + + Test for Directory API + + + + + + + + + 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 @@ + + + + Test for bug 1319088 + + + + + + + + + + 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 @@ + + + + Test for webkitdirectory and webkitRelativePath + + + + + + + + + + + + + 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 @@ + + + + Test for Directory API in workers + + + + + + + + + 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(); +} -- cgit v1.2.3