Skip to content

Commit

Permalink
FS: Split FSA WPTs
Browse files Browse the repository at this point in the history
Align our WPTs with the spec split by moving OPFS tests into a new
fs/ directory.

All Access Handle tests and most tests using a sandboxed file system
backend have been moved to fs/. file-system-access/ contains all
file picker tests and tests using a local file system backend, as
well as tests which have not yet shipped
(BaseHandle::remove() and DirHandle::move()).

Bug: N/A
Change-Id: I95ab81c7f19774d69bf72e8140d609e7f4abb32a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3550030
Commit-Queue: Austin Sullivan <asully@chromium.org>
Reviewed-by: Marijn Kruisselbrink <mek@chromium.org>
Cr-Commit-Position: refs/heads/main@{#999773}
  • Loading branch information
a-sully authored and chromium-wpt-export-bot committed May 5, 2022
1 parent b98b119 commit 5798ab0
Show file tree
Hide file tree
Showing 90 changed files with 938 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
<script src="resources/messaging-helpers.js"></script>
<script src="resources/messaging-serialize-helpers.js"></script>
<script src="/IndexedDB/support-promises.js"></script>
<script src="script-tests/FileSystemBaseHandle-IndexedDB.js"></script>
<script src="../fs/script-tests/FileSystemBaseHandle-IndexedDB.js"></script>
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
<script src="/resources/testdriver-vendor.js"></script>
<script src="resources/test-helpers.js"></script>
<script src="resources/local-fs-test-helpers.js"></script>
<script src="script-tests/FileSystemBaseHandle-isSameEntry.js"></script>
<script src="../fs/script-tests/FileSystemBaseHandle-isSameEntry.js"></script>
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
<script src="resources/local-fs-test-helpers.js"></script>
<script src="resources/messaging-helpers.js"></script>
<script src="resources/messaging-serialize-helpers.js"></script>
<script src="script-tests/FileSystemBaseHandle-postMessage-BroadcastChannel.js"></script>
<script src="../fs/script-tests/FileSystemBaseHandle-postMessage-BroadcastChannel.js"></script>
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
<script src="resources/messaging-helpers.js"></script>
<script src="resources/messaging-blob-helpers.js"></script>
<script src="resources/messaging-serialize-helpers.js"></script>
<script src="script-tests/FileSystemBaseHandle-postMessage-Error.js"></script>
<script src="../fs/script-tests/FileSystemBaseHandle-postMessage-Error.js"></script>
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
<script src="resources/messaging-helpers.js"></script>
<script src="resources/messaging-blob-helpers.js"></script>
<script src="resources/messaging-serialize-helpers.js"></script>
<script src="script-tests/FileSystemBaseHandle-postMessage-MessagePort-frames.js"></script>
<script src="../fs/script-tests/FileSystemBaseHandle-postMessage-MessagePort-frames.js"></script>
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
<script src="resources/messaging-helpers.js"></script>
<script src="resources/messaging-blob-helpers.js"></script>
<script src="resources/messaging-serialize-helpers.js"></script>
<script src="script-tests/FileSystemBaseHandle-postMessage-MessagePort-windows.js"></script>
<script src="../fs/script-tests/FileSystemBaseHandle-postMessage-MessagePort-windows.js"></script>
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
<script src="resources/messaging-helpers.js"></script>
<script src="resources/messaging-blob-helpers.js"></script>
<script src="resources/messaging-serialize-helpers.js"></script>
<script src="script-tests/FileSystemBaseHandle-postMessage-MessagePort-workers.js"></script>
<script src="../fs/script-tests/FileSystemBaseHandle-postMessage-MessagePort-workers.js"></script>
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
<script src="resources/messaging-helpers.js"></script>
<script src="resources/messaging-blob-helpers.js"></script>
<script src="resources/messaging-serialize-helpers.js"></script>
<script src="script-tests/FileSystemBaseHandle-postMessage-frames.js"></script>
<script src="../fs/script-tests/FileSystemBaseHandle-postMessage-frames.js"></script>
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
<script src="resources/messaging-helpers.js"></script>
<script src="resources/messaging-blob-helpers.js"></script>
<script src="resources/messaging-serialize-helpers.js"></script>
<script src="script-tests/FileSystemBaseHandle-postMessage-windows.js"></script>
<script src="../fs/script-tests/FileSystemBaseHandle-postMessage-windows.js"></script>
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
<script src="resources/messaging-helpers.js"></script>
<script src="resources/messaging-blob-helpers.js"></script>
<script src="resources/messaging-serialize-helpers.js"></script>
<script src="script-tests/FileSystemBaseHandle-postMessage-workers.js"></script>
<script src="../fs/script-tests/FileSystemBaseHandle-postMessage-workers.js"></script>
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
<script src="/resources/testdriver-vendor.js"></script>
<script src="resources/test-helpers.js"></script>
<script src="resources/local-fs-test-helpers.js"></script>
<script src="script-tests/FileSystemDirectoryHandle-getDirectoryHandle.js"></script>
<script src="../fs/script-tests/FileSystemDirectoryHandle-getDirectoryHandle.js"></script>
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
<script src="/resources/testdriver-vendor.js"></script>
<script src="resources/test-helpers.js"></script>
<script src="resources/local-fs-test-helpers.js"></script>
<script src="script-tests/FileSystemDirectoryHandle-getFileHandle.js"></script>
<script src="../fs/script-tests/FileSystemDirectoryHandle-getFileHandle.js"></script>
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
<script src="/resources/testdriver-vendor.js"></script>
<script src="resources/test-helpers.js"></script>
<script src="resources/local-fs-test-helpers.js"></script>
<script src="script-tests/FileSystemDirectoryHandle-iteration.js"></script>
<script src="../fs/script-tests/FileSystemDirectoryHandle-iteration.js"></script>
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
<script src="/resources/testdriver-vendor.js"></script>
<script src="resources/test-helpers.js"></script>
<script src="resources/local-fs-test-helpers.js"></script>
<script src="script-tests/FileSystemDirectoryHandle-removeEntry.js"></script>
<script src="../fs/script-tests/FileSystemDirectoryHandle-removeEntry.js"></script>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
<script src="/resources/testdriver-vendor.js"></script>
<script src="resources/test-helpers.js"></script>
<script src="resources/local-fs-test-helpers.js"></script>
<script src="script-tests/FileSystemDirectoryHandle-resolve.js"></script>
<script src="../fs/script-tests/FileSystemDirectoryHandle-resolve.js"></script>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<script src="resources/test-helpers.js"></script>
<script src="resources/local-fs-test-helpers.js"></script>
<script src="resources/messaging-helpers.js"></script>
<script src="script-tests/FileSystemFileHandle-create-sync-access-handle.js"></script>
<script src="../fs/script-tests/FileSystemFileHandle-create-sync-access-handle.js"></script>

<script>
//This variable allows the test to differentiate between local and sandboxed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
<script src="/resources/testdriver-vendor.js"></script>
<script src="resources/test-helpers.js"></script>
<script src="resources/local-fs-test-helpers.js"></script>
<script src="script-tests/FileSystemFileHandle-getFile.js"></script>
<script src="../fs/script-tests/FileSystemFileHandle-getFile.js"></script>
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
<script src="/resources/testdriver-vendor.js"></script>
<script src="resources/test-helpers.js"></script>
<script src="resources/local-fs-test-helpers.js"></script>
<script src="script-tests/FileSystemFileHandle-move.js"></script>
<script src="../fs/script-tests/FileSystemFileHandle-move.js"></script>
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
<script src="/resources/testdriver-vendor.js"></script>
<script src="resources/test-helpers.js"></script>
<script src="resources/local-fs-test-helpers.js"></script>
<script src="script-tests/FileSystemWritableFileStream.js"></script>
<script src="../fs/script-tests/FileSystemWritableFileStream.js"></script>
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
<script src="resources/test-helpers.js"></script>
<script src="resources/local-fs-test-helpers.js"></script>
<script src="../streams/resources/recording-streams.js"></script>
<script src="script-tests/FileSystemWritableFileStream-piped.js"></script>
<script src="../fs/script-tests/FileSystemWritableFileStream-piped.js"></script>
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
<script src="/resources/testdriver-vendor.js"></script>
<script src="resources/test-helpers.js"></script>
<script src="resources/local-fs-test-helpers.js"></script>
<script src="script-tests/FileSystemWritableFileStream-write.js"></script>
<script src="../fs/script-tests/FileSystemWritableFileStream-write.js"></script>
8 changes: 4 additions & 4 deletions file-system-access/resources/local-fs-test-helpers.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// This file defines a directory_test() function that can be used to define
// tests that require a FileSystemDirectoryHandle. The implementation of that
// function in this file will ask the user to select an empty directory and
// uses that directory.
// function in this file will ask the user to select an empty directory and uses
// that directory.
//
// Another implementation of this function exists in
// sandboxed-fs-test-helpers.js, where that version uses the sandboxed file
// system instead.
// fs/resources/sandboxed-fs-test-helpers.js, where that version uses the
// sandboxed file system instead.

const directory_promise = (async () => {
await new Promise(resolve => {
Expand Down
2 changes: 1 addition & 1 deletion file-system-access/resources/opaque-origin-sandbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@
} catch (error) {
post_message(`navigator.storage.getDirectory(): EXCEPTION: ${error.name}`);
}
</script>
</script>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// META: script=resources/test-helpers.js
// META: script=resources/sandboxed-fs-test-helpers.js
// META: script=../fs/resources/sandboxed-fs-test-helpers.js
// META: script=script-tests/FileSystemBaseHandle-remove.js

directory_test(async (t, root) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// META: script=resources/test-helpers.js
// META: script=resources/sandboxed-fs-test-helpers.js
// META: script=../fs/resources/sandboxed-fs-test-helpers.js
// META: script=script-tests/FileSystemDirectoryHandle-move.js
File renamed without changes.
2 changes: 1 addition & 1 deletion fs/META.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
spec: https://fs.spec.whatwg.org/
suggested_reviewers:
- mkruisselbrink
- mkruisselbrink
2 changes: 2 additions & 0 deletions fs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This directory contains tests for the
[File System](https://fs.spec.whatwg.org/) specification.
75 changes: 75 additions & 0 deletions fs/opaque-origin.https.window.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
'use strict';

const kSandboxWindowUrl = 'resources/opaque-origin-sandbox.html';

function add_iframe(test, src, sandbox) {
const iframe = document.createElement('iframe');
iframe.src = src;
if (sandbox !== undefined) {
iframe.sandbox = sandbox;
}
document.body.appendChild(iframe);
test.add_cleanup(() => {
iframe.remove();
});
}

// Creates a data URI iframe that uses postMessage() to provide its parent
// with the test result. The iframe checks for the existence of
// |property_name| on the window.
async function verify_does_not_exist_in_data_uri_iframe(
test, property_name) {
const iframe_content =
'<script>' +
' const is_property_name_defined = ' +
` (self.${property_name} !== undefined);` +
' parent.postMessage({is_property_name_defined}, "*")' +
'</script>';

const data_uri = `data:text/html,${encodeURIComponent(iframe_content)}`;
add_iframe(test, data_uri);

const event_watcher = new EventWatcher(test, self, 'message');
const message_event = await event_watcher.wait_for('message')

assert_false(message_event.data.is_property_name_defined,
`Data URI iframes must not define '${property_name}'.`);
}

// |kSandboxWindowUrl| sends the result of navigator.storage.getDirectory() to
// this window. For windows using sandbox='allow-scripts', this must produce a
// rejected promise.
async function verify_results_from_sandboxed_child_window(test) {
const event_watcher = new EventWatcher(test, self, 'message');

const message_event = await event_watcher.wait_for('message');
assert_equals(message_event.data,
'navigator.storage.getDirectory(): REJECTED: SecurityError');
}

promise_test(async test => {
await verify_does_not_exist_in_data_uri_iframe(
test, 'FileSystemDirectoryHandle');
}, 'FileSystemDirectoryHandle must be undefined for data URI iframes.');

promise_test(
async test => {
add_iframe(test, kSandboxWindowUrl, /*sandbox=*/ 'allow-scripts');
await verify_results_from_sandboxed_child_window(test);
},
'navigator.storage.getDirectory() must reject in a sandboxed iframe.');

promise_test(
async test => {
const child_window_url = kSandboxWindowUrl +
'?pipe=header(Content-Security-Policy, sandbox allow-scripts)';

const child_window = window.open(child_window_url);
test.add_cleanup(() => {
child_window.close();
});

await verify_results_from_sandboxed_child_window(test);
},
'navigator.storage.getDirectory() ' +
'must reject in a sandboxed opened window.');
9 changes: 9 additions & 0 deletions fs/resources/message-target-dedicated-worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

importScripts(
'test-helpers.js',
'messaging-serialize-helpers.js',
'message-target.js'
);

add_message_event_handlers(/*receiver=*/self, /*target=*/self);
9 changes: 9 additions & 0 deletions fs/resources/message-target-service-worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

importScripts(
'test-helpers.js',
'messaging-serialize-helpers.js',
'message-target.js'
);

add_message_event_handlers(/*receiver=*/self);
14 changes: 14 additions & 0 deletions fs/resources/message-target-shared-worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

importScripts(
'test-helpers.js',
'messaging-serialize-helpers.js',
'message-target.js'
);

self.addEventListener('connect', connect_event => {
const message_port = connect_event.ports[0];
add_message_event_handlers(
/*receiver=*/message_port, /*target=*/message_port);
message_port.start();
});
22 changes: 22 additions & 0 deletions fs/resources/message-target.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<script src='test-helpers.js'></script>
<script src='messaging-serialize-helpers.js'></script>
<script src='message-target.js'></script>
<script id="inline_script">
'use strict'

if (window.parent !== null) {
window.parent.postMessage('LOADED', { targetOrigin: '*' });
}

if (window.opener !== null) {
window.opener.postMessage('LOADED', { targetOrigin: '*' });
}

// Use an undefined message target to send responses to
// MessageEvent::source instead.
const target = undefined;

add_message_event_handlers(
/*receiver=*/self, target, /*target_origin=*/'*');
</script>

0 comments on commit 5798ab0

Please sign in to comment.