| <!DOCTYPE html> |
| <html> |
| <head> |
| <script src="../../../resources/js-test.js"></script> |
| <script src="../../editing.js"></script> |
| </head> |
| <body> |
| <div id="dropzone" style="width: 200px; height: 200px; background-color: grey;"></div> |
| <script> |
| description("Basic test coverage for fileSystemDirectoryEntry.getDirectory()"); |
| jsTestIsAsync = true; |
| |
| function getDirectoryAsPromise(directory, path, flags) |
| { |
| return new Promise((resolve, reject) => { |
| directory.getDirectory(path, flags, resolve, reject); |
| }); |
| } |
| |
| function test1() { |
| debug("* Error case: create flag is set to true"); |
| return getDirectoryAsPromise(directoryEntry, "subfolder1", { create: true }).then(entry => { |
| testFailed("Should fail when create flag is true"); |
| }, e => { |
| ex = e; |
| shouldBeEqualToString("ex.name", "SecurityError"); |
| }); |
| } |
| |
| function test2() { |
| debug("* Regular case: getDirectory('subfolder1')"); |
| return getDirectoryAsPromise(directoryEntry, "subfolder1", {}).then(entry => { |
| subfolder1Entry = entry; |
| shouldBeEqualToString("subfolder1Entry.name", "subfolder1"); |
| shouldBeEqualToString("subfolder1Entry.fullPath", "/testFiles/subfolder1"); |
| shouldBeTrue("subfolder1Entry.isDirectory"); |
| }, e => { |
| testFailed("getDirectory('subfolder1') should succeed"); |
| }); |
| } |
| |
| function test3() { |
| debug("* Error case: calling getDirectory() with path to file"); |
| return getDirectoryAsPromise(directoryEntry, "file1.txt", {}).then(entry => { |
| testFailed("Should fail when path points to a file"); |
| }, e => { |
| ex = e; |
| shouldBeEqualToString("ex.name", "TypeMismatchError"); |
| }); |
| } |
| |
| function test4() { |
| debug("* Error case: calling getDirectory() with path containing backslash"); |
| return getDirectoryAsPromise(directoryEntry, "\\subfolder1", {}).then(entry => { |
| testFailed("Should fail when path is invalid"); |
| }, e => { |
| ex = e; |
| shouldBeEqualToString("ex.name", "TypeMismatchError"); |
| }); |
| } |
| |
| function test5() { |
| debug("* Error case: calling getDirectory() with path which does not exist"); |
| return getDirectoryAsPromise(directoryEntry, "doesnotexist", {}).then(entry => { |
| testFailed("Should fail when path does not exist"); |
| }, e => { |
| ex = e; |
| shouldBeEqualToString("ex.name", "NotFoundError"); |
| }); |
| } |
| |
| function test6() { |
| debug("* Error case: calling getDirectory() with path containing a NUL character"); |
| return getDirectoryAsPromise(directoryEntry, "subfolder1\0", {}).then(entry => { |
| testFailed("Should fail when path is invalid"); |
| }, e => { |
| ex = e; |
| shouldBeEqualToString("ex.name", "TypeMismatchError"); |
| }); |
| } |
| |
| function test7() { |
| debug("* Regular case: calling getDirectory() with path to root"); |
| return getDirectoryAsPromise(directoryEntry, "/", {}).then(entry => { |
| rootEntry = entry; |
| shouldBeEqualToString("rootEntry.name", ""); |
| shouldBeEqualToString("rootEntry.fullPath", "/"); |
| shouldBeTrue("rootEntry.isDirectory"); |
| }, e => { |
| testFailed("getDirectory('/') should succeed"); |
| }); |
| } |
| |
| function test8() { |
| debug("* Regular case: calling getDirectory() with absolute path"); |
| return getDirectoryAsPromise(directoryEntry, "/testFiles/subfolder2/subfolder2a", {}).then(entry => { |
| subfolder2aEntry = entry; |
| shouldBeEqualToString("subfolder2aEntry.name", "subfolder2a"); |
| shouldBeEqualToString("subfolder2aEntry.fullPath", "/testFiles/subfolder2/subfolder2a"); |
| shouldBeTrue("subfolder2aEntry.isDirectory"); |
| }, e => { |
| testFailed("getDirectory('/testFiles/subfolder2/subfolder2a') should succeed"); |
| }); |
| } |
| |
| function test9() { |
| debug("* Edge case: calling getDirectory() with relative path containing '.' and '..'"); |
| return getDirectoryAsPromise(directoryEntry, "../testFiles/././subfolder2/../subfolder2/./subfolder2a", {}).then(entry => { |
| subfolder2aEntry = entry; |
| shouldBeEqualToString("subfolder2aEntry.name", "subfolder2a"); |
| shouldBeEqualToString("subfolder2aEntry.fullPath", "/testFiles/subfolder2/subfolder2a"); |
| shouldBeTrue("subfolder2aEntry.isDirectory"); |
| }, e => { |
| testFailed("getDirectory('../testFiles/././subfolder2/../subfolder2/./subfolder2a') should succeed"); |
| }); |
| } |
| |
| function test10() { |
| debug("* Edge case: calling getDirectory() with relative path containing too many '..'"); |
| return getDirectoryAsPromise(directoryEntry, "../../../../../testFiles/subfolder1", {}).then(entry => { |
| subfolder1Entry = entry; |
| shouldBeEqualToString("subfolder1Entry.name", "subfolder1"); |
| shouldBeEqualToString("subfolder1Entry.fullPath", "/testFiles/subfolder1"); |
| shouldBeTrue("subfolder1Entry.isDirectory"); |
| }, e => { |
| testFailed("getDirectory('../../../../../testFiles/subfolder1') should succeed"); |
| }); |
| } |
| |
| function test11() { |
| debug("* Edge case: calling getDirectory() with absolute path containing '..'"); |
| return getDirectoryAsPromise(directoryEntry, "/testFiles/../testFiles/subfolder1", {}).then(entry => { |
| subfolder1Entry = entry; |
| shouldBeEqualToString("subfolder1Entry.name", "subfolder1"); |
| shouldBeEqualToString("subfolder1Entry.fullPath", "/testFiles/subfolder1"); |
| shouldBeTrue("subfolder1Entry.isDirectory"); |
| }, e => { |
| testFailed("getDirectory('../../../../../testFiles/subfolder1') should succeed"); |
| }); |
| } |
| |
| function test12() { |
| debug("* Edge case: calling getDirectory() with absolute path containing too many '..'"); |
| return getDirectoryAsPromise(directoryEntry, "/../../../../../testFiles/subfolder1", {}).then(entry => { |
| subfolder1Entry = entry; |
| shouldBeEqualToString("subfolder1Entry.name", "subfolder1"); |
| shouldBeEqualToString("subfolder1Entry.fullPath", "/testFiles/subfolder1"); |
| shouldBeTrue("subfolder1Entry.isDirectory"); |
| }, e => { |
| testFailed("getDirectory('../../../../../testFiles/subfolder1') should succeed"); |
| }); |
| } |
| |
| function test13() { |
| debug("* Edge case: calling getDirectory() with empty path"); |
| return getDirectoryAsPromise(directoryEntry, "", {}).then(entry => { |
| testFilesEntry = entry; |
| shouldBeFalse("testFilesEntry.isFile"); |
| shouldBeTrue("testFilesEntry.isDirectory"); |
| shouldBeEqualToString("testFilesEntry.name", "testFiles"); |
| shouldBeEqualToString("testFilesEntry.fullPath", "/testFiles"); |
| }, e => { |
| testFailed("getDirectory('') should succeed"); |
| }); |
| } |
| |
| function test14() { |
| debug("* Edge case: calling getDirectory() with null path"); |
| return getDirectoryAsPromise(directoryEntry, null, {}).then(entry => { |
| testFilesEntry = entry; |
| shouldBeFalse("testFilesEntry.isFile"); |
| shouldBeTrue("testFilesEntry.isDirectory"); |
| shouldBeEqualToString("testFilesEntry.name", "testFiles"); |
| shouldBeEqualToString("testFilesEntry.fullPath", "/testFiles"); |
| }, e => { |
| testFailed("getDirectory(null) should succeed"); |
| }); |
| } |
| |
| function test15() { |
| debug("* Edge case: calling getDirectory() with undefined path"); |
| return getDirectoryAsPromise(directoryEntry, undefined, {}).then(entry => { |
| testFilesEntry = entry; |
| shouldBeFalse("testFilesEntry.isFile"); |
| shouldBeTrue("testFilesEntry.isDirectory"); |
| shouldBeEqualToString("testFilesEntry.name", "testFiles"); |
| shouldBeEqualToString("testFilesEntry.fullPath", "/testFiles"); |
| }, e => { |
| testFailed("getDirectory(undefined) should succeed"); |
| }); |
| } |
| |
| function test16() { |
| debug("* Edge case: calling getDirectory() with path '.'"); |
| return getDirectoryAsPromise(directoryEntry, '.', {}).then(entry => { |
| testFilesEntry = entry; |
| shouldBeFalse("testFilesEntry.isFile"); |
| shouldBeTrue("testFilesEntry.isDirectory"); |
| shouldBeEqualToString("testFilesEntry.name", "testFiles"); |
| shouldBeEqualToString("testFilesEntry.fullPath", "/testFiles"); |
| }, e => { |
| testFailed("getDirectory('.') should succeed"); |
| }); |
| } |
| |
| function test17() { |
| debug("* Edge case: calling getDirectory() with path starting with 2 slashes"); |
| return getDirectoryAsPromise(directoryEntry, '//testFiles/subfolder1', {}).then(entry => { |
| testFilesEntry = entry; |
| shouldBeFalse("testFilesEntry.isFile"); |
| shouldBeTrue("testFilesEntry.isDirectory"); |
| shouldBeEqualToString("testFilesEntry.name", "subfolder1"); |
| shouldBeEqualToString("testFilesEntry.fullPath", "/testFiles/subfolder1"); |
| }, e => { |
| testFailed("getDirectory('//testFiles/subfolder1') should succeed"); |
| }); |
| } |
| |
| function test18() { |
| debug("* Edge case: calling getDirectory() with path starting with 2 slashes and containing 2 following slashes"); |
| return getDirectoryAsPromise(directoryEntry, '//testFiles//subfolder1', {}).then(entry => { |
| testFilesEntry = entry; |
| shouldBeFalse("testFilesEntry.isFile"); |
| shouldBeTrue("testFilesEntry.isDirectory"); |
| shouldBeEqualToString("testFilesEntry.name", "subfolder1"); |
| shouldBeEqualToString("testFilesEntry.fullPath", "/testFiles/subfolder1"); |
| }, e => { |
| testFailed("getDirectory('//testFiles//subfolder1') should succeed"); |
| }); |
| } |
| |
| var dropzone = document.getElementById('dropzone'); |
| dropzone.ondrop = function(e) { |
| e.preventDefault(); |
| dataTransfer = e.dataTransfer; |
| |
| shouldBe("dataTransfer.items.length", "1"); |
| |
| directoryEntry = dataTransfer.items[0].webkitGetAsEntry(); |
| test1() |
| .then(test2) |
| .then(test3) |
| .then(test4) |
| .then(test5) |
| .then(test6) |
| .then(test7) |
| .then(test8) |
| .then(test9) |
| .then(test10) |
| .then(test11) |
| .then(test12) |
| .then(test13) |
| .then(test14) |
| .then(test15) |
| .then(test16) |
| .then(test17) |
| .then(test18) |
| .then(finishJSTest); |
| }; |
| |
| dropzone.ondragover = function(ev) { |
| ev.preventDefault(); |
| } |
| |
| onload = function() { |
| dragFilesOntoElement(dropzone, ['../../../fast/forms/file/entries-api/resources/testFiles']); |
| } |
| </script> |
| </body> |
| </html> |