diff options
author | kinuko@chromium.org <kinuko@chromium.org@bbb929c8-8fbe-4397-9dbb-9b2b20218538> | 2010-10-07 21:10:07 +0000 |
---|---|---|
committer | kinuko@chromium.org <kinuko@chromium.org@bbb929c8-8fbe-4397-9dbb-9b2b20218538> | 2010-10-07 21:10:07 +0000 |
commit | 55eb5fdce0c07b5265ebb1cbf4891c84041d706a (patch) | |
tree | a916d4b686b9f4938b45019b1091b337d6cfacdb /third_party/WebKit/LayoutTests/fast/filesystem/resources | |
parent | e48dc5a08cdbb8af33ebb611a01fa921b0e6a431 (diff) | |
download | chromium_src-55eb5fdce0c07b5265ebb1cbf4891c84041d706a.zip chromium_src-55eb5fdce0c07b5265ebb1cbf4891c84041d706a.tar.gz chromium_src-55eb5fdce0c07b5265ebb1cbf4891c84041d706a.tar.bz2 |
2010-10-07 Kinuko Yasuda <kinuko@chromium.org>
Reviewed by David Levin.
Add layout tests for FileSystem API
https://bugs.webkit.org/show_bug.cgi?id=44920
Added tests for major Entry operations: copyTo, moveTo, getFile,
getDirectory, remove, createReader.readEntries, getParent.
* fast/filesystem/op-copy-expected.txt: Added.
* fast/filesystem/op-copy.html: Added.
* fast/filesystem/op-get-entry-expected.txt: Added.
* fast/filesystem/op-get-entry.html: Added.
* fast/filesystem/op-get-parent-expected.txt: Added.
* fast/filesystem/op-get-parent.html: Added.
* fast/filesystem/op-move-expected.txt: Added.
* fast/filesystem/op-move.html: Added.
* fast/filesystem/op-read-directory-expected.txt: Added.
* fast/filesystem/op-read-directory.html: Added.
* fast/filesystem/op-remove-expected.txt: Added.
* fast/filesystem/op-remove.html: Added.
* fast/filesystem/op-restricted-chars-expected.txt: Added.
* fast/filesystem/op-restricted-chars.html: Added.
* fast/filesystem/op-restricted-names-expected.txt: Added.
* fast/filesystem/op-restricted-names.html: Added.
* fast/filesystem/resources/fs-test-util.js:
* fast/filesystem/resources/op-copy.js: Added.
* fast/filesystem/resources/op-get-entry.js: Added.
* fast/filesystem/resources/op-get-parent.js: Added.
* fast/filesystem/resources/op-move.js: Added.
* fast/filesystem/resources/op-read-directory.js: Added.
* fast/filesystem/resources/op-remove.js: Added.
* fast/filesystem/resources/op-restricted-chars.js: Added.
* fast/filesystem/resources/op-restricted-names.js: Added.
* fast/filesystem/resources/op-tests-helper.js: Added.
git-svn-id: svn://svn.chromium.org/blink/trunk@69339 bbb929c8-8fbe-4397-9dbb-9b2b20218538
Diffstat (limited to 'third_party/WebKit/LayoutTests/fast/filesystem/resources')
9 files changed, 1003 insertions, 0 deletions
diff --git a/third_party/WebKit/LayoutTests/fast/filesystem/resources/op-copy.js b/third_party/WebKit/LayoutTests/fast/filesystem/resources/op-copy.js new file mode 100644 index 0000000..3bf2a95 --- /dev/null +++ b/third_party/WebKit/LayoutTests/fast/filesystem/resources/op-copy.js @@ -0,0 +1,164 @@ +var testCases = [ + { + name: 'CopyFileSimple', + precondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b'} + ], + tests: [ + function(helper) { helper.copy('/a/b', '/a', 'c'); } + ], + postcondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b'}, + {fullPath:'/a/c'} + ], + }, + { + name: 'CopyDirectorySimple', + precondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b', isDirectory:true} + ], + tests: [ + function(helper) { helper.copy('/a/b', '/a', 'c'); }, + ], + postcondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b', isDirectory:true}, + {fullPath:'/a/c', isDirectory:true} + ], + }, + { + name: 'CopyFileToDifferentDirectory', + precondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b'}, + {fullPath:'/c', isDirectory:true} + ], + tests: [ + function(helper) { helper.copy('/a/b', '/c', 'd'); }, + ], + postcondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b'}, + {fullPath:'/c/d'} + ], + }, + { + name: 'CopyFileWithEmptyName', + precondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b'}, + {fullPath:'/c', isDirectory:true}, + ], + tests: [ + function(helper) { helper.copy('/a/b', '/c', null); }, + ], + postcondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b'}, + {fullPath:'/c/b'} + ], + }, + { + name: 'CopyFileWithEmptyNameToSameDirectory', + precondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b'}, + ], + tests: [ + function(helper) { helper.copy('/a/b', '/a', null, FileError.INVALID_MODIFICATION_ERR); }, + ], + postcondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b'}, + ], + }, + { + name: 'CopyFileWithSameName', + precondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b'}, + ], + tests: [ + function(helper) { helper.copy('/a/b', '/a', 'b', FileError.INVALID_MODIFICATION_ERR); }, + ], + postcondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b'}, + ], + }, + { + name: 'CopyForNonExistentEntry', + precondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b'}, + {fullPath:'/c', isDirectory:true}, + ], + tests: [ + function(helper) { helper.remove('/a/b'); }, + function(helper) { helper.copy('/a/b', '/c', 'b', FileError.NOT_FOUND_ERR); }, + ], + postcondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/c', isDirectory:true}, + ], + }, + { + name: 'CopyEntryToNonExistentDirectory', + precondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b'}, + {fullPath:'/c', isDirectory:true}, + ], + tests: [ + function(helper) { helper.remove('/c'); }, + function(helper) { helper.copy('/a/b', '/c', 'b', FileError.NOT_FOUND_ERR); }, + ], + postcondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b'}, + ], + }, + { + name: 'CopyEntryToItsChild', + precondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b', isDirectory:true}, + {fullPath:'/a/b/c', isDirectory:true}, + ], + tests: [ + function(helper) { helper.copy('/a', '/a/b', 'd', FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.copy('/a/b', '/a/b/c', 'd', FileError.INVALID_MODIFICATION_ERR); }, + ], + postcondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b', isDirectory:true}, + {fullPath:'/a/b/c', isDirectory:true}, + ], + }, + { + name: 'CopyRecursive', + precondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b', isDirectory:true}, + {fullPath:'/a/b/c'}, + {fullPath:'/a/b/d'}, + {fullPath:'/b', isDirectory:true}, + ], + tests: [ + function(helper) { helper.copy('/a', '/b', 'a'); }, + ], + postcondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b', isDirectory:true}, + {fullPath:'/a/b/c'}, + {fullPath:'/a/b/d'}, + {fullPath:'/b/a', isDirectory:true}, + {fullPath:'/b/a/b', isDirectory:true}, + {fullPath:'/b/a/b/c'}, + {fullPath:'/b/a/b/d'}, + ], + }, +]; diff --git a/third_party/WebKit/LayoutTests/fast/filesystem/resources/op-get-entry.js b/third_party/WebKit/LayoutTests/fast/filesystem/resources/op-get-entry.js new file mode 100644 index 0000000..5551a37 --- /dev/null +++ b/third_party/WebKit/LayoutTests/fast/filesystem/resources/op-get-entry.js @@ -0,0 +1,124 @@ +var testCases = [ + { + name: 'CreateSimple', + precondition: [ ], + tests: [ + function(helper) { helper.getDirectory('/', 'a', {create:true}); }, + function(helper) { helper.getFile('/', 'b', {create:true}); } + ], + postcondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/b'}, + ], + }, + { + name: 'CreateNested', + precondition: [ ], + tests: [ + function(helper) { helper.getDirectory('/', 'a', {create:true}); }, + function(helper) { helper.getDirectory('/a', 'b', {create:true}); }, + function(helper) { helper.getDirectory('/a/b', 'c', {create:true}); }, + function(helper) { helper.getDirectory('/a/b/c', 'd', {create:true}); }, + function(helper) { helper.getFile('/a/b/c/d', 'e', {create:true}); }, + ], + postcondition: [ + {fullPath:'/a/b/c/d/e'}, + ], + }, + { + name: 'CreateNestedWithAbsolutePath', + precondition: [ + {fullPath:'/dummy', isDirectory:true}, + ], + tests: [ + function(helper) { helper.getDirectory('/dummy', '/a', {create:true}); }, + function(helper) { helper.getDirectory('/dummy', '/a/b', {create:true}); }, + function(helper) { helper.getDirectory('/dummy', '/a/b/c', {create:true}); }, + function(helper) { helper.getDirectory('/dummy', '/a/b/c/d', {create:true}); }, + function(helper) { helper.getFile('/dummy', '/a/b/c/d/e', {create:true}); } + ], + postcondition: [ + {fullPath:'/dummy', isDirectory:true}, + {fullPath:'/a/b/c/d/e'}, + ], + }, + { + name: 'CreateNestedWithRelativePath', + precondition: [ + {fullPath:'/a', isDirectory:true}, + ], + tests: [ + // FIXME: For now they throw an error because they fail the check for restricted-names: 'a path component should not end with period'. + function(helper) { helper.getDirectory('/a', './b', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getDirectory('/a', '../b', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getDirectory('/a', '/a/../../b', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + ], + postcondition: [ ], + }, + { + name: 'GetExistingEntry', + precondition: [ ], + tests: [ + function(helper) { helper.getDirectory('/', 'a', {create:true}); }, + function(helper) { helper.getFile('/', 'b', {create:true}); }, + function(helper) { helper.getDirectory('/', 'a'); }, + function(helper) { helper.getFile('/', 'b'); } + ], + postcondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/b'}, + ], + }, + { + name: 'GetNonExistent', + precondition: [ ], + tests: [ + function(helper) { helper.getDirectory('/', 'a', {}, FileError.NOT_FOUND_ERR); }, + function(helper) { helper.getFile('/', 'b', {}, FileError.NOT_FOUND_ERR); }, + function(helper) { helper.getDirectory('/', '/nonexistent/a', {create:true}, FileError.NOT_FOUND_ERR); }, + function(helper) { helper.getFile('/', '/nonexistent/b', {create:true}, FileError.NOT_FOUND_ERR); } + ], + postcondition: [ ], + }, + { + name: 'GetFileForDirectory', + precondition: [ + {fullPath:'/a', isDirectory:true} + ], + tests: [ + function(helper) { helper.getFile('/', 'a', {}, FileError.INVALID_STATE_ERR); }, + function(helper) { helper.getFile('/', '/a', {}, FileError.INVALID_STATE_ERR); }, + ], + postcondition: [ + {fullPath:'/a', isDirectory:true} + ], + }, + { + name: 'GetDirectoryForFile', + precondition: [ + {fullPath:'/a'} + ], + tests: [ + function(helper) { helper.getDirectory('/', 'a', {}, FileError.INVALID_STATE_ERR); }, + function(helper) { helper.getDirectory('/', '/a', {}, FileError.INVALID_STATE_ERR); }, + ], + postcondition: [ + {fullPath:'/a'} + ], + }, + { + name: 'CreateWithExclusive', + precondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/b'} + ], + tests: [ + function(helper) { helper.getDirectory('/', 'a', {create:true, exclusive:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'b', {create:true, exclusive:true}, FileError.INVALID_MODIFICATION_ERR); } + ], + postcondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/b'} + ], + }, +]; diff --git a/third_party/WebKit/LayoutTests/fast/filesystem/resources/op-get-parent.js b/third_party/WebKit/LayoutTests/fast/filesystem/resources/op-get-parent.js new file mode 100644 index 0000000..bde953c --- /dev/null +++ b/third_party/WebKit/LayoutTests/fast/filesystem/resources/op-get-parent.js @@ -0,0 +1,21 @@ +var testCases = [ + { + name: 'GetParent', + precondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b', isDirectory:true}, + {fullPath:'/a/b/c'}, + ], + tests: [ + function(helper) { helper.getParent('/'); }, + function(helper) { helper.getParent('/a'); }, + function(helper) { helper.getParent('/a/b'); }, + function(helper) { helper.getParent('/a/b/c'); } + ], + postcondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b', isDirectory:true}, + {fullPath:'/a/b/c'}, + ], + }, +]; diff --git a/third_party/WebKit/LayoutTests/fast/filesystem/resources/op-move.js b/third_party/WebKit/LayoutTests/fast/filesystem/resources/op-move.js new file mode 100644 index 0000000..3e4fa23 --- /dev/null +++ b/third_party/WebKit/LayoutTests/fast/filesystem/resources/op-move.js @@ -0,0 +1,161 @@ +var testCases = [ + { + name: 'MoveFileSimple', + precondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b'} + ], + tests: [ + function(helper) { helper.move('/a/b', '/a', 'c'); } + ], + postcondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b', nonexistent:true}, + {fullPath:'/a/c'} + ], + }, + { + name: 'MoveDirectorySimple', + precondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b', isDirectory:true} + ], + tests: [ + function(helper) { helper.move('/a/b', '/a', 'c'); }, + ], + postcondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b', nonexistent:true}, + {fullPath:'/a/c', isDirectory:true} + ], + }, + { + name: 'MoveFileToDifferentDirectory', + precondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b'}, + {fullPath:'/c', isDirectory:true} + ], + tests: [ + function(helper) { helper.move('/a/b', '/c', 'd'); }, + ], + postcondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b', nonexistent:true}, + {fullPath:'/c/d'} + ], + }, + { + name: 'MoveFileWithEmptyName', + precondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b'}, + {fullPath:'/c', isDirectory:true}, + ], + tests: [ + function(helper) { helper.move('/a/b', '/c', null); }, + ], + postcondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b', nonexistent:true}, + {fullPath:'/c/b'} + ], + }, + { + name: 'MoveFileWithEmptyNameToSameDirectory', + precondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b'}, + ], + tests: [ + function(helper) { helper.move('/a/b', '/a', null, FileError.INVALID_MODIFICATION_ERR); }, + ], + postcondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b'}, + ], + }, + { + name: 'MoveFileWithSameName', + precondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b'}, + ], + tests: [ + function(helper) { helper.move('/a/b', '/a', 'b', FileError.INVALID_MODIFICATION_ERR); }, + ], + postcondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b'}, + ], + }, + { + name: 'MoveForNonExistentEntry', + precondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b'}, + {fullPath:'/c', isDirectory:true}, + ], + tests: [ + function(helper) { helper.remove('/a/b'); }, + function(helper) { helper.move('/a/b', '/c', 'b', FileError.NOT_FOUND_ERR); }, + ], + postcondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/c', isDirectory:true}, + ], + }, + { + name: 'MoveEntryToNonExistentDirectory', + precondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b'}, + {fullPath:'/c', isDirectory:true}, + ], + tests: [ + function(helper) { helper.remove('/c'); }, + function(helper) { helper.move('/a/b', '/c', 'b', FileError.NOT_FOUND_ERR); }, + ], + postcondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b'}, + ], + }, + { + name: 'MoveEntryToItsChild', + precondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b', isDirectory:true}, + {fullPath:'/a/b/c', isDirectory:true}, + ], + tests: [ + function(helper) { helper.move('/a', '/a/b', 'd', FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.move('/a/b', '/a/b/c', 'd', FileError.INVALID_MODIFICATION_ERR); }, + ], + postcondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b', isDirectory:true}, + {fullPath:'/a/b/c', isDirectory:true}, + ], + }, + { + name: 'MoveRecursive', + precondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b', isDirectory:true}, + {fullPath:'/a/b/c'}, + {fullPath:'/a/b/d'}, + {fullPath:'/b', isDirectory:true}, + ], + tests: [ + function(helper) { helper.move('/a', '/b', 'a'); }, + ], + postcondition: [ + {fullPath:'/a', nonexistent:true}, + {fullPath:'/b/a', isDirectory:true}, + {fullPath:'/b/a/b', isDirectory:true}, + {fullPath:'/b/a/b/c'}, + {fullPath:'/b/a/b/d'}, + ], + }, +]; diff --git a/third_party/WebKit/LayoutTests/fast/filesystem/resources/op-read-directory.js b/third_party/WebKit/LayoutTests/fast/filesystem/resources/op-read-directory.js new file mode 100644 index 0000000..bef2a48 --- /dev/null +++ b/third_party/WebKit/LayoutTests/fast/filesystem/resources/op-read-directory.js @@ -0,0 +1,23 @@ +var testCases = [ + { + name: 'ReadDirectory', + precondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/b', isDirectory:true}, + {fullPath:'/c', }, + {fullPath:'/d', }, + {fullPath:'/e', isDirectory:true}, + {fullPath:'/f', }, + {fullPath:'/g', isDirectory:true}, + {fullPath:'/a/b'}, + {fullPath:'/a/c'}, + ], + tests: [ + function(helper) { helper.readDirectory('/'); }, + function(helper) { helper.remove('/c'); }, + function(helper) { helper.remove('/e'); }, + function(helper) { helper.remove('/f'); }, + function(helper) { helper.readDirectory('/'); } + ], + }, +]; diff --git a/third_party/WebKit/LayoutTests/fast/filesystem/resources/op-remove.js b/third_party/WebKit/LayoutTests/fast/filesystem/resources/op-remove.js new file mode 100644 index 0000000..119ac82 --- /dev/null +++ b/third_party/WebKit/LayoutTests/fast/filesystem/resources/op-remove.js @@ -0,0 +1,34 @@ +var testCases = [ + { + name: 'RemoveSimple', + precondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/b'} + ], + tests: [ + function(helper) { helper.remove('/a'); }, + function(helper) { helper.remove('/b'); } + ], + postcondition: [ + {fullPath:'/a', nonexistent:true}, + {fullPath:'/b', nonexistent:true} + ], + }, + { + name: 'RemoveNonRecursiveWithChildren', + precondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b', isDirectory:true}, + {fullPath:'/a/c',} + ], + tests: [ + function(helper) { helper.remove('/a', FileError.INVALID_MODIFICATION_ERR); } + ], + postcondition: [ + {fullPath:'/a', isDirectory:true}, + {fullPath:'/a/b', isDirectory:true}, + {fullPath:'/a/c',} + ], + }, +]; + diff --git a/third_party/WebKit/LayoutTests/fast/filesystem/resources/op-restricted-chars.js b/third_party/WebKit/LayoutTests/fast/filesystem/resources/op-restricted-chars.js new file mode 100644 index 0000000..aa9095e --- /dev/null +++ b/third_party/WebKit/LayoutTests/fast/filesystem/resources/op-restricted-chars.js @@ -0,0 +1,51 @@ +var testCases = [ + { + name: 'RestrictedChars', + precondition: [ ], + tests: [ + // Restricted character in 'path' parameter. + function(helper) { helper.getFile('/', 'a\\b', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'a<b', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'a>b', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'a:b', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'a?b', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'a*b', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'a"b', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'a|b', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + + function(helper) { helper.getFile('/', '\\ab', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', '<ab', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', ':ab', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', '?ab', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', '*ab', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', '"ab', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', '|ab', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + + function(helper) { helper.getFile('/', 'ab\\', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'ab<', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'ab:', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'ab?', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'ab*', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'ab"', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'ab|', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + + // This should succeed. + function(helper) { helper.getFile('/', 'ab', {create:true}); }, + + // Restricted character in 'name' parameters. + function(helper) { helper.copy('/ab', '/', 'a\\b',FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.copy('/ab', '/', 'a<b', FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.copy('/ab', '/', 'a:b', FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.copy('/ab', '/', 'a?b', FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.copy('/ab', '/', 'a*b', FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.copy('/ab', '/', 'a"b', FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.copy('/ab', '/', 'a|b', FileError.INVALID_MODIFICATION_ERR); }, + + // 'Name' parameter cannot contain '/'. + function(helper) { helper.copy('/ab', '/', 'a/b', FileError.INVALID_MODIFICATION_ERR); }, + ], + postcondition: [ + {fullPath:'/ab'}, + ], + }, +]; diff --git a/third_party/WebKit/LayoutTests/fast/filesystem/resources/op-restricted-names.js b/third_party/WebKit/LayoutTests/fast/filesystem/resources/op-restricted-names.js new file mode 100644 index 0000000..e17a1a1 --- /dev/null +++ b/third_party/WebKit/LayoutTests/fast/filesystem/resources/op-restricted-names.js @@ -0,0 +1,59 @@ +var testCases = [ + { + name: 'RestrictedChars', + precondition: [ + {fullPath:'/a', isDirectory:true} + ], + tests: [ + function(helper) { helper.getFile('/', 'con', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'CON', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'Con', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'cOn.txt', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'a/coN', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + + function(helper) { helper.getFile('/', 'prn', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'PRN', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'Prn', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'pRn.txt', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'a/prN', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + + function(helper) { helper.getFile('/', 'aux', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'AUX', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'Aux', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'aUx.txt', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'a/auX', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + + function(helper) { helper.getFile('/', 'nul', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'NUL', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'Nul', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'nUl.txt', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'a/nuL', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + + function(helper) { helper.getFile('/', 'com1', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'COM2', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'Com4', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'cOM7.foo', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'b/coM9', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + + function(helper) { helper.getFile('/', 'lpt1', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'LPT2', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'Lpt4', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'lPT7.foo', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'b/lpT9', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + + // Names should not end with period or whitespace. + function(helper) { helper.getFile('/', 'foo ', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'foo\n', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.getFile('/', 'foo.', {create:true}, FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.copy('/a', '/', 'foo ', FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.copy('/a', '/', 'foo\t', FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.copy('/a', '/', 'foo.', FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.move('/a', '/', 'foo ', FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.move('/a', '/', 'foo\t', FileError.INVALID_MODIFICATION_ERR); }, + function(helper) { helper.move('/a', '/', 'foo.', FileError.INVALID_MODIFICATION_ERR); }, + ], + postcondition: [ + {fullPath:'/a', isDirectory:true} + ], + }, +]; diff --git a/third_party/WebKit/LayoutTests/fast/filesystem/resources/op-tests-helper.js b/third_party/WebKit/LayoutTests/fast/filesystem/resources/op-tests-helper.js new file mode 100644 index 0000000..bfb0729 --- /dev/null +++ b/third_party/WebKit/LayoutTests/fast/filesystem/resources/op-tests-helper.js @@ -0,0 +1,366 @@ +// Helper routine. +function toString(obj) { + if (obj == undefined) { + return "undefined"; + } else if (typeof obj == 'object') { + if (obj.length != undefined) { + var stringArray = []; + for (var i = 0; i < obj.length; ++i) + stringArray.push(toString(obj[i])); + stringArray.sort(); + return '[' + stringArray.join(',\n ') + ']'; + } else if (obj.isDirectory || obj.isFile) { + return 'ENTRY {path:' + obj.fullPath + ' name:' + obj.name + (obj.isDirectory ? ' type:DIRECTORY' : ' type:FILE') + '}'; + } else { + return obj + ""; + } + } else + return obj + ""; +} + +// Creates a test environment for the given entries where entries is an array of {fullPath:String, isDirectory:boolean} object. +// When the world is created successfully, successCallback is called with an object that holds all the created entry objects. +function createTestEnvironment(fileSystem, entries, successCallback, errorCallback) +{ + var Helper = function(fileSystem, entries, successCallback, errorCallback) + { + this.fileSystem = fileSystem; + this.entries = entries; + this.current = 0; + this.successCallback = successCallback; + this.errorCallback = errorCallback; + this.environment = {}; + + this.createSuccessCallback = function(entry) + { + this.environment[entry.fullPath] = entry; + this.createNextEntry(); + } + + this.createErrorCallback = function(error, entry) + { + testFailed('Got unexpected error ' + error.code + ' while creating ' + toString(entry)); + this.errorCallback(error); + } + + this.createNextEntry = function() + { + if (this.current >= this.entries.length) { + this.successCallback(this.environment); + return; + } + var entry = this.entries[this.current++]; + if (entry.isDirectory) + fileSystem.root.getDirectory(entry.fullPath, {create:true}, bindCallback(this, this.createSuccessCallback), bindCallback(this, this.createErrorCallback)); + else + fileSystem.root.getFile(entry.fullPath, {create:true}, bindCallback(this, this.createSuccessCallback), bindCallback(this, this.createErrorCallback)); + }; + }; + + if (!entries || !entries.length) { + successCallback({}); + return; + } + var helper = new Helper(fileSystem, entries, successCallback, errorCallback); + helper.createNextEntry(); +} + +function verifyTestEnvironment(fileSystem, entries, successCallback, errorCallback) +{ + var Helper = function(fileSystem, entries, successCallback, errorCallback) + { + this.fileSystem = fileSystem; + this.entries = entries; + this.current = 0; + this.successCallback = successCallback; + this.errorCallback = errorCallback; + this.expectedNonexistent = false; + + this.verifySuccessCallback = function(entry) + { + if (this.expectedNonexistent) { + testFailed('Found unexpected entry ' + entry.fullPath); + this.errorCallback(); + return; + } + testPassed('Verified entry: ' + toString(entry)); + this.verifyNextEntry(); + } + + this.verifyErrorCallback = function(error, entry) + { + if (this.expectedNonexistent) { + testPassed('Verified entry does NOT exist: ' + entry.fullPath); + this.verifyNextEntry(); + return; + } + if (error == FileError.NOT_FOUND_ERR) + testFailed('Not found: ' + entry.fullPath); + else + testFailed('Got unexpected error ' + error.code + ' for ' + entry.fullPath); + this.errorCallback(error); + } + + this.verifyNextEntry = function() + { + if (this.current >= this.entries.length) { + this.successCallback(); + return; + } + var entry = this.entries[this.current++]; + this.expectedNonexistent = entry.nonexistent; + if (entry.isDirectory) + fileSystem.root.getDirectory(entry.fullPath, {}, bindCallback(this, this.verifySuccessCallback), bindCallback(this, this.verifyErrorCallback, entry)); + else + fileSystem.root.getFile(entry.fullPath, {}, bindCallback(this, this.verifySuccessCallback), bindCallback(this, this.verifyErrorCallback, entry)); + }; + }; + + if (!entries || !entries.length) { + successCallback(); + return; + } + var helper = new Helper(fileSystem, entries, successCallback, errorCallback); + helper.verifyNextEntry(); +} + +// testCase must have precondition, postcondition and test function field. +// (See resources/op-*.js for examples.) +function runOperationTest(fileSystem, testCase, successCallback, errorCallback) +{ + var OperationTestHelper = function(fileSystem, testCase, successCallback, errorCallback) + { + this.fileSystem = fileSystem; + this.testCase = testCase; + this.successCallback = successCallback; + this.errorCallback = errorCallback; + this.stage = ''; + this.environment = {}; + this.currentTest = 0; + + this.currentReader = null; + this.readEntries = []; + + this.testSuccessCallback = function() + { + if (!this.expectedErrorCode) { + testPassed('Succeeded: ' + this.stage); + this.runNextTest(); + } else { + testFailed('Unexpectedly succeeded while ' + this.stage); + this.errorCallback(); + } + }; + + this.entry = null; + this.testGetSuccessCallback = function(entry) + { + if (!this.expectedErrorCode) { + testPassed('Succeeded: ' + this.stage); + this.entry = entry; + shouldBe.apply(this, ['this.environment[this.entry.fullPath].fullPath', '"' + entry.fullPath + '"']); + shouldBe.apply(this, ['this.environment[this.entry.fullPath].isFile + ""', '"' + entry.isFile + '"']); + shouldBe.apply(this, ['this.environment[this.entry.fullPath].isDirectory + ""', '"' + entry.isDirectory + '"']); + this.runNextTest(); + } else { + testFailed('Unexpectedly succeeded while ' + this.stage); + this.errorCallback(error); + } + }; + + this.testCreateSuccessCallback = function(entry) + { + if (!this.expectedErrorCode) { + testPassed('Succeeded: ' + this.stage); + this.environment[entry.fullPath] = entry; + this.runNextTest(); + } else { + testFailed('Unexpectedly succeeded while ' + this.stage); + this.errorCallback(); + } + }; + + this.testGetParentSuccessCallback = function(entry) + { + if (!this.expectedErrorCode) { + testPassed('Succeeded: ' + this.stage); + debug('Parent entry: ' + toString(entry)); + this.runNextTest(); + } else { + testFailed('Unexpectedly succeeded while ' + this.stage); + this.errorCallback(); + } + }; + + this.testReadEntriesSuccessCallback = function(entries) + { + if (this.expectedErrorCode) { + testFailed('Unexpectedly succeeded while ' + this.stage); + this.errorCallback(error); + return; + } + + for (var i = 0; i < entries.length; ++i) + this.readEntries.push(entries[i]); + + if (entries.length) { + this.currentReader.readEntries(bindCallback(this, this.testReadEntriesSuccessCallback), bindCallback(this, this.testErrorCallback)); + return; + } + + testPassed('Succeeded: ' + this.stage); + debug('Entries: ' + toString(this.readEntries)); + this.runNextTest(); + }; + + this.testErrorCallback = function(error) + { + if (this.expectedErrorCode) { + shouldBe.apply(this, ['this.expectedErrorCode + ""', '"' + error.code + '"']); + this.runNextTest(); + } else { + testFailed('Got unexpected error ' + error.code + ' while ' + this.stage); + this.errorCallback(error); + } + }; + + // Operations --------------------------------------------------- + + this.getFile = function(entry, path, flags, expectedErrorCode) + { + this.expectedErrorCode = expectedErrorCode; + this.stage = '"' + entry + '".getFile("' + path + '")'; + var successCallback = (flags && flags.create) ? this.testCreateSuccessCallback : this.testGetSuccessCallback; + this.environment[entry].getFile(path, flags, bindCallback(this, successCallback), bindCallback(this, this.testErrorCallback)); + }; + + this.getDirectory = function(entry, path, flags, expectedErrorCode) + { + this.expectedErrorCode = expectedErrorCode; + this.stage = '"' + entry + '".getDirectory("' + path + '")'; + var successCallback = (flags && flags.create) ? this.testCreateSuccessCallback : this.testGetSuccessCallback; + this.environment[entry].getDirectory(path, flags, bindCallback(this, successCallback), bindCallback(this, this.testErrorCallback)); + }; + + this.getParent = function(entry, expectedErrorCode) + { + this.expectedErrorCode = expectedErrorCode; + this.stage = '"' + entry + '".getParent()'; + this.environment[entry].getParent(bindCallback(this, this.testGetParentSuccessCallback), bindCallback(this, this.testErrorCallback)); + }; + + this.getMetadata = function(entry, expectedErrorCode) + { + this.expectedErrorCode = expectedErrorCode; + this.stage = '"' + entry + '".getMetadata()'; + this.environment[entry].getMetadata(bindCallback(this, this.testSuccessCallback), bindCallback(this, this.testErrorCallback)); + }; + + this.remove = function(entry, expectedErrorCode) + { + this.expectedErrorCode = expectedErrorCode; + this.stage = '"' + entry + '".remove()'; + this.environment[entry].remove(bindCallback(this, this.testSuccessCallback), bindCallback(this, this.testErrorCallback)); + }; + + this.readDirectory = function(entry, expectedErrorCode) + { + this.expectedErrorCode = expectedErrorCode; + this.readEntries = []; + this.stage = '"' + entry + '".createReader().readEntries()'; + this.currentReader = this.environment[entry].createReader(); + this.currentReader.readEntries(bindCallback(this, this.testReadEntriesSuccessCallback), bindCallback(this, this.testErrorCallback)); + }; + + this.copy = function(entry, destinationParent, newName, expectedErrorCode) + { + this.expectedErrorCode = expectedErrorCode; + this.stage = '"' + entry + '".copyTo("' + destinationParent + '", "' + newName + '")'; + this.environment[entry].copyTo(this.environment[destinationParent], newName, bindCallback(this, this.testSuccessCallback), bindCallback(this, this.testErrorCallback)); + }; + + this.move = function(entry, destinationParent, newName, expectedErrorCode) + { + this.expectedErrorCode = expectedErrorCode; + this.stage = '"' + entry + '".moveTo("' + destinationParent + '", "' + newName + '")'; + this.environment[entry].moveTo(this.environment[destinationParent], newName, bindCallback(this, this.testSuccessCallback), bindCallback(this, this.testErrorCallback)); + }; + + //--------------------------------------------------------------- + this.start = function() + { + this.expectedErrorCode = ''; + this.stage = 'resetting filesystem'; + removeRecursively(this.fileSystem.root, bindCallback(this, this.setUp), bindCallback(this, this.testErrorCallback)); + }; + + this.setUp = function() + { + this.expectedErrorCode = ''; + this.stage = 'setting up test precondition'; + createTestEnvironment(this.fileSystem, this.testCase.precondition, bindCallback(this, this.runTests), bindCallback(this, this.testErrorCallback)); + }; + + this.runNextTest = function() + { + if (this.currentTest >= this.testCase.tests.length) { + this.verify(); + return; + } + this.testCase.tests[this.currentTest++](this); + }; + + this.runTests = function(environment) + { + this.environment = environment; + this.environment['/'] = this.fileSystem.root; + this.currentTest = 0; + this.runNextTest(); + }; + + this.verify = function() + { + this.expectedErrorCode = ''; + if (!this.testCase.postcondition) { + this.successCallback(); + return; + } + this.stage = 'verifying test postcondition'; + verifyTestEnvironment(this.fileSystem, this.testCase.postcondition, this.successCallback, bindCallback(this, this.testErrorCallback)); + }; + }; + + var helper = new OperationTestHelper(fileSystem, testCase, successCallback, errorCallback); + helper.start(); +} + +var currentTest = 0; +var fileSystem = null; +function runNextTest() { + if (currentTest >= testCases.length) { + debug('Finished running tests.'); + finishJSTest(); + return; + } + + var testCase = testCases[currentTest++]; + debug('* Running: ' + testCase.name); + runOperationTest(fileSystem, testCase, runNextTest, errorCallback); +} + +function errorCallback(error) { + if (error && error.code) + testFailed('Got error ' + error.code); + finishJSTest(); +} + +function fileSystemCallback(fs) +{ + fileSystem = fs; + runNextTest(); +} + +var jsTestIsAsync = true; +requestFileSystem(TEMPORARY, 100, fileSystemCallback, errorCallback); +var successfullyParsed = true; + |