aboutsummaryrefslogtreecommitdiffstats
path: root/tests/wpt/web-platform-tests/native-file-system/script-tests/FileSystemWritableFileStream.js
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2019-12-24 07:32:42 -0500
committerGitHub <noreply@github.com>2019-12-24 07:32:42 -0500
commit8002c6bc53041c55dc1148fed008b9a229df0e9b (patch)
tree124ddcb0a400cb4ff13a23acc57e959009ff6c50 /tests/wpt/web-platform-tests/native-file-system/script-tests/FileSystemWritableFileStream.js
parent10fa5fa68a2244903db35e617b48ce3ccdbdc87a (diff)
parent110ca49f65ea4c20d1e89276e35b9f757c56e35d (diff)
downloadservo-8002c6bc53041c55dc1148fed008b9a229df0e9b.tar.gz
servo-8002c6bc53041c55dc1148fed008b9a229df0e9b.zip
Auto merge of #25375 - servo-wpt-sync:wpt_update_24-12-2019, r=servo-wpt-sync
Sync WPT with upstream (24-12-2019) Automated downstream sync of changes from upstream as of 24-12-2019. [no-wpt-sync] r? @servo-wpt-sync
Diffstat (limited to 'tests/wpt/web-platform-tests/native-file-system/script-tests/FileSystemWritableFileStream.js')
-rw-r--r--tests/wpt/web-platform-tests/native-file-system/script-tests/FileSystemWritableFileStream.js117
1 files changed, 117 insertions, 0 deletions
diff --git a/tests/wpt/web-platform-tests/native-file-system/script-tests/FileSystemWritableFileStream.js b/tests/wpt/web-platform-tests/native-file-system/script-tests/FileSystemWritableFileStream.js
new file mode 100644
index 00000000000..5acf93aec8c
--- /dev/null
+++ b/tests/wpt/web-platform-tests/native-file-system/script-tests/FileSystemWritableFileStream.js
@@ -0,0 +1,117 @@
+directory_test(async (t, root) => {
+ const handle = await createEmptyFile(t, 'trunc_shrink', root);
+ const stream = await handle.createWritable();
+
+ await stream.write('1234567890');
+ await stream.truncate(5);
+ await stream.close();
+
+ assert_equals(await getFileContents(handle), '12345');
+ assert_equals(await getFileSize(handle), 5);
+}, 'truncate() to shrink a file');
+
+directory_test(async (t, root) => {
+ const handle = await createEmptyFile(t, 'trunc_grow', root);
+ const stream = await handle.createWritable();
+
+ await stream.write('abc');
+ await stream.truncate(5);
+ await stream.close();
+
+ assert_equals(await getFileContents(handle), 'abc\0\0');
+ assert_equals(await getFileSize(handle), 5);
+}, 'truncate() to grow a file');
+
+directory_test(async (t, root) => {
+ const dir = await createDirectory(t, 'parent_dir', root);
+ const file_name = 'create_writable_fails_when_dir_removed.txt';
+ const handle = await createEmptyFile(t, file_name, dir);
+
+ await root.removeEntry('parent_dir', {recursive: true});
+ await promise_rejects(t, 'NotFoundError', handle.createWritable());
+}, 'createWritable() fails when parent directory is removed');
+
+directory_test(async (t, root) => {
+ const dir = await createDirectory(t, 'parent_dir', root);
+ const file_name = 'write_fails_when_dir_removed.txt';
+ const handle = await createEmptyFile(t, file_name, dir);
+ const stream = await handle.createWritable();
+
+ await root.removeEntry('parent_dir', {recursive: true});
+ await promise_rejects(t, 'NotFoundError', stream.write('foo'));
+}, 'write() fails when parent directory is removed');
+
+directory_test(async (t, root) => {
+ const dir = await createDirectory(t, 'parent_dir', root);
+ const file_name = 'truncate_fails_when_dir_removed.txt';
+ const handle = await createEmptyFile(t, file_name, dir);
+ const stream = await handle.createWritable();
+
+ await root.removeEntry('parent_dir', {recursive: true});
+ await promise_rejects(t, 'NotFoundError', stream.truncate(0));
+}, 'truncate() fails when parent directory is removed');
+
+directory_test(async (t, root) => {
+ const handle = await createFileWithContents(
+ t, 'atomic_file_is_copied.txt', 'fooks', root);
+ const stream = await handle.createWritable({keepExistingData: true});
+
+ await stream.write('bar');
+ await stream.close();
+ assert_equals(await getFileContents(handle), 'barks');
+ assert_equals(await getFileSize(handle), 5);
+}, 'createWritable({keepExistingData: true}): atomic writable file stream initialized with source contents');
+
+directory_test(async (t, root) => {
+ const handle = await createFileWithContents(
+ t, 'atomic_file_is_not_copied.txt', 'very long string', root);
+ const stream = await handle.createWritable({keepExistingData: false});
+
+ await stream.write('bar');
+ assert_equals(await getFileContents(handle), 'very long string');
+ await stream.close();
+ assert_equals(await getFileContents(handle), 'bar');
+ assert_equals(await getFileSize(handle), 3);
+}, 'createWritable({keepExistingData: false}): atomic writable file stream initialized with empty file');
+
+directory_test(async (t, root) => {
+ const handle = await createFileWithContents(
+ t, 'trunc_smaller_offset.txt', '1234567890', root);
+ const stream = await handle.createWritable({keepExistingData: true});
+
+ await stream.truncate(5);
+ await stream.write('abc');
+ await stream.close();
+
+ assert_equals(await getFileContents(handle), 'abc45');
+ assert_equals(await getFileSize(handle), 5);
+}, 'cursor position: truncate size > offset');
+
+directory_test(async (t, root) => {
+ const handle = await createFileWithContents(
+ t, 'trunc_bigger_offset.txt', '1234567890', root);
+ const stream = await handle.createWritable({keepExistingData: true});
+
+ await stream.seek(6);
+ await stream.truncate(5);
+ await stream.write('abc');
+ await stream.close();
+
+ assert_equals(await getFileContents(handle), '12345abc');
+ assert_equals(await getFileSize(handle), 8);
+}, 'cursor position: truncate size < offset');
+
+directory_test(async (t, root) => {
+ const handle = await createEmptyFile(t, 'contents', root);
+ const stream = await handle.createWritable();
+
+ stream.write('abc');
+ stream.write('def');
+ stream.truncate(9);
+ stream.seek(0);
+ stream.write('xyz');
+ await stream.close();
+
+ assert_equals(await getFileContents(handle), 'xyzdef\0\0\0');
+ assert_equals(await getFileSize(handle), 9);
+}, 'commands are queued');