Skip to content

Commit ac39068

Browse files
a-sullychromium-wpt-export-bot
authored andcommitted
FSA: Add web tests for FileSystemHandle::rename()
These tests were accidentally lost while iterating on https://crrev.com/c/2984739. They have been recovered from https://crrev.com/c/2984739/28. Bug: 1140805 Change-Id: I3aeef4ad1094931f9ce07bec3c261da9741d45bd Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3160902 Reviewed-by: Marijn Kruisselbrink <[email protected]> Commit-Queue: Austin Sullivan <[email protected]> Cr-Commit-Position: refs/heads/main@{#922261}
1 parent 56d2b34 commit ac39068

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!doctype html>
2+
<meta charset=utf-8>
3+
4+
<script src="/resources/testharness.js"></script>
5+
<script src="/resources/testharnessreport.js"></script>
6+
<script src="/resources/testdriver.js"></script>
7+
<script src="/resources/testdriver-vendor.js"></script>
8+
<script src="resources/test-helpers.js"></script>
9+
<script src="resources/local-fs-test-helpers.js"></script>
10+
<script src="script-tests/FileSystemBaseHandle-rename.js"></script>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// META: script=resources/test-helpers.js
2+
// META: script=resources/sandboxed-fs-test-helpers.js
3+
// META: script=script-tests/FileSystemBaseHandle-rename.js
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// META: script=resources/test-helpers.js
2+
3+
'use strict';
4+
5+
directory_test(async (t, root) => {
6+
const handle = await createFileWithContents(t, 'file-before', 'foo', root);
7+
await handle.rename('file-after');
8+
9+
assert_array_equals(await getSortedDirectoryEntries(root), ['file-after']);
10+
assert_equals(await getFileContents(handle), 'foo');
11+
assert_equals(await getFileSize(handle), 3);
12+
}, 'rename(name) to rename a file');
13+
14+
directory_test(async (t, root) => {
15+
const handle = await createFileWithContents(t, 'file-before', 'foo', root);
16+
await handle.rename('file-before');
17+
18+
assert_array_equals(await getSortedDirectoryEntries(root), ['file-before']);
19+
assert_equals(await getFileContents(handle), 'foo');
20+
assert_equals(await getFileSize(handle), 3);
21+
}, 'rename(name) to rename a file the same name');
22+
23+
directory_test(async (t, root) => {
24+
const handle = await createFileWithContents(t, 'file-before', 'foo', root);
25+
await promise_rejects_js(t, TypeError, handle.rename(''));
26+
27+
assert_array_equals(await getSortedDirectoryEntries(root), ['file-before']);
28+
assert_equals(await getFileContents(handle), 'foo');
29+
assert_equals(await getFileSize(handle), 3);
30+
}, 'rename("") to rename a file fails');
31+
32+
directory_test(async (t, root) => {
33+
const dir = await root.getDirectoryHandle('dir-before', {create: true});
34+
await dir.rename('dir-after');
35+
36+
assert_array_equals(await getSortedDirectoryEntries(root), ['dir-after/']);
37+
assert_array_equals(await getSortedDirectoryEntries(dir), []);
38+
}, 'rename(name) to rename an empty directory');
39+
40+
directory_test(async (t, root) => {
41+
const dir = await root.getDirectoryHandle('dir-before', {create: true});
42+
await promise_rejects_js(t, TypeError, dir.rename(''));
43+
44+
assert_array_equals(await getSortedDirectoryEntries(root), ['dir-before/']);
45+
assert_array_equals(await getSortedDirectoryEntries(dir), []);
46+
}, 'rename("") to rename an empty directory fails');
47+
48+
directory_test(async (t, root) => {
49+
const dir = await root.getDirectoryHandle('dir-before', {create: true});
50+
await createFileWithContents(t, 'file-in-dir', 'abc', dir);
51+
await dir.rename('dir-after');
52+
53+
assert_array_equals(await getSortedDirectoryEntries(root), ['dir-after/']);
54+
assert_array_equals(await getSortedDirectoryEntries(dir), ['file-in-dir']);
55+
}, 'rename(name) to rename a non-empty directory');
56+
57+
directory_test(async (t, root) => {
58+
const handle = await createFileWithContents(t, 'file-1', 'foo', root);
59+
60+
await handle.rename('file-2');
61+
assert_array_equals(await getSortedDirectoryEntries(root), ['file-2']);
62+
63+
await handle.rename('file-3');
64+
assert_array_equals(await getSortedDirectoryEntries(root), ['file-3']);
65+
66+
await handle.rename('file-1');
67+
assert_array_equals(await getSortedDirectoryEntries(root), ['file-1']);
68+
}, 'rename(name) can be called multiple times');
69+
70+
directory_test(async (t, root) => {
71+
const dir = await root.getDirectoryHandle('dir', {create: true});
72+
const handle = await createFileWithContents(t, 'file-before', 'foo', dir);
73+
await handle.rename(root);
74+
75+
assert_array_equals(await getSortedDirectoryEntries(root), ['dir/']);
76+
assert_array_equals(
77+
await getSortedDirectoryEntries(dir),
78+
['[object FileSystemDirectoryHandle]']);
79+
assert_equals(await getFileContents(handle), 'foo');
80+
assert_equals(await getFileSize(handle), 3);
81+
}, 'rename(dir) should rename to stringified dir object');
82+
83+
directory_test(async (t, root) => {
84+
const dir = await root.getDirectoryHandle('dir', {create: true});
85+
const handle = await createFileWithContents(t, 'file-before', 'foo', dir);
86+
await promise_rejects_js(t, TypeError, handle.rename('Lorem.'));
87+
88+
assert_array_equals(await getSortedDirectoryEntries(root), ['dir/']);
89+
assert_array_equals(await getSortedDirectoryEntries(dir), ['file-before']);
90+
assert_equals(await getFileContents(handle), 'foo');
91+
assert_equals(await getFileSize(handle), 3);
92+
}, 'rename(name) with a name with a trailing period should fail');
93+
94+
directory_test(async (t, root) => {
95+
const handle = await createFileWithContents(t, 'file-before', 'foo', root);
96+
await promise_rejects_js(t, TypeError, handle.rename('#$23423@352^*3243'));
97+
98+
assert_array_equals(await getSortedDirectoryEntries(root), ['file-before']);
99+
assert_equals(await getFileContents(handle), 'foo');
100+
assert_equals(await getFileSize(handle), 3);
101+
}, 'rename(name) with a name with invalid characters should fail');

0 commit comments

Comments
 (0)