diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/fs/script-tests/FileSystemDirectoryHandle-iteration.js | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/fs/script-tests/FileSystemDirectoryHandle-iteration.js')
-rw-r--r-- | testing/web-platform/tests/fs/script-tests/FileSystemDirectoryHandle-iteration.js | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/testing/web-platform/tests/fs/script-tests/FileSystemDirectoryHandle-iteration.js b/testing/web-platform/tests/fs/script-tests/FileSystemDirectoryHandle-iteration.js new file mode 100644 index 0000000000..815ae21936 --- /dev/null +++ b/testing/web-platform/tests/fs/script-tests/FileSystemDirectoryHandle-iteration.js @@ -0,0 +1,100 @@ +'use strict'; + +directory_test(async (t, root) => { + const file_name1 = 'foo1.txt'; + const file_name2 = 'foo2.txt'; + await createFileWithContents(t, file_name1, 'contents', /*parent=*/ root); + await createFileWithContents(t, file_name2, 'contents', /*parent=*/ root); + + for await (let entry of root) { + break; + } + +}, 'returning early from an iteration doesn\'t crash'); + +directory_test(async (t, root) => { + const file_name1 = 'foo1.txt'; + const file_name2 = 'foo2.txt'; + await createFileWithContents(t, file_name1, 'contents', /*parent=*/ root); + await createFileWithContents(t, file_name2, 'contents', /*parent=*/ root); + + let names = []; + for await (let entry of root) { + assert_true(Array.isArray(entry)); + assert_equals(entry.length, 2); + assert_equals(typeof entry[0], 'string'); + assert_true(entry[1] instanceof FileSystemFileHandle); + assert_equals(entry[0], entry[1].name); + names.push(entry[0]); + } + names.sort(); + assert_array_equals(names, [file_name1, file_name2]); + +}, '@@asyncIterator: full iteration works'); + +directory_test(async (t, root) => { + const file_name1 = 'foo1.txt'; + const file_name2 = 'foo2.txt'; + await createFileWithContents(t, file_name1, 'contents', /*parent=*/ root); + await createFileWithContents(t, file_name2, 'contents', /*parent=*/ root); + + let names = []; + for await (let entry of root.entries()) { + assert_true(Array.isArray(entry)); + assert_equals(entry.length, 2); + assert_equals(typeof entry[0], 'string'); + assert_true(entry[1] instanceof FileSystemFileHandle); + assert_equals(entry[0], entry[1].name); + names.push(entry[0]); + } + names.sort(); + assert_array_equals(names, [file_name1, file_name2]); +}, 'entries: full iteration works'); + +directory_test(async (t, root) => { + const file_name1 = 'foo1.txt'; + const file_name2 = 'foo2.txt'; + await createFileWithContents(t, file_name1, 'contents', /*parent=*/ root); + await createFileWithContents(t, file_name2, 'contents', /*parent=*/ root); + + let names = []; + for await (let entry of root.values()) { + assert_true(entry instanceof FileSystemFileHandle); + names.push(entry.name); + } + names.sort(); + assert_array_equals(names, [file_name1, file_name2]); +}, 'values: full iteration works'); + +directory_test(async (t, root) => { + const file_name1 = 'foo1.txt'; + const file_name2 = 'foo2.txt'; + await createFileWithContents(t, file_name1, 'contents', /*parent=*/ root); + await createFileWithContents(t, file_name2, 'contents', /*parent=*/ root); + + let names = []; + for await (let entry of root.keys()) { + assert_equals(typeof entry, 'string'); + names.push(entry); + } + names.sort(); + assert_array_equals(names, [file_name1, file_name2]); +}, 'keys: full iteration works'); + +directory_test(async (t, root) => { + const file_name1 = 'foo1.txt'; + await createFileWithContents(t, file_name1, 'contents', /*parent=*/ root); + + const next = (() => { + const iterator = root.entries(); + return iterator.next(); + })(); + garbageCollect(); + let entry = await next; + assert_false(entry.done); + assert_true(Array.isArray(entry.value)); + assert_equals(entry.value.length, 2); + assert_equals(entry.value[0], file_name1); + assert_true(entry.value[1] instanceof FileSystemFileHandle); + assert_equals(entry.value[1].name, file_name1); +}, 'iteration while iterator gets garbage collected'); |