Update web-platform-tests to revision 474923949524b5c05a9e6f28ec082fdca87078de

This commit is contained in:
WPT Sync Bot 2019-10-25 10:23:30 +00:00
parent b7b1b903d3
commit 328d5a4231
91 changed files with 3190 additions and 185 deletions

View file

@ -0,0 +1,82 @@
'use strict';
// This script depends on the following scripts:
// /native-file-system/resources/messaging-helpers.js
// /native-file-system/resources/messaging-serialize-helpers.js
// /native-file-system/resources/test-helpers.js
// /service-workers/service-worker/resources/test-helpers.sub.js
// Sets up a new broadcast channel in |target|. Posts a message instructing
// |target| to open the broadcast channel using |broadcast_channel_name|.
async function create_broadcast_channel(
test, broadcast_channel_name, receiver, target, target_origin) {
target.postMessage(
{ type: 'create-broadcast-channel', broadcast_channel_name },
{ targetOrigin: target_origin });
const event_watcher = new EventWatcher(test, receiver, 'message');
// Wait until |target| is listening to the broad cast channel.
const message_event = await event_watcher.wait_for('message');
assert_equals(message_event.data.type, 'broadcast-channel-created',
'The message target must receive a "broadcast-channel-created" message ' +
'response.');
}
// This test is very similar to 'FileSystemBaseHandle-postMessage.js'. It
// starts by creating three message targets for the broadcast channel:
// an iframe, dedicated worker and a service worker. After setup, an array
// of FileSystemHandles is sent across the broadcast channel. The test
// expects three responses -- one from each message target.
directory_test(async (t, root) => {
const broadcast_channel_name = 'file-system-file-handle-channel';
const broadcast_channel = new BroadcastChannel(broadcast_channel_name);
const broadcast_channel_event_watcher =
new EventWatcher(t, broadcast_channel, 'message');
const iframe = await add_iframe(t, { src: kDocumentMessageTarget });
await create_broadcast_channel(
t, broadcast_channel_name, self, iframe.contentWindow, '*');
const scope = `${kServiceWorkerMessageTarget}` +
'?post-message-to-broadcast-channel-with-file-handle';
const registration = await create_service_worker(
t, kServiceWorkerMessageTarget, scope);
await create_broadcast_channel(
t, broadcast_channel_name,
navigator.serviceWorker, registration.installing);
const dedicated_worker =
create_dedicated_worker(t, kDedicatedWorkerMessageTarget);
await create_broadcast_channel(
t, broadcast_channel_name, dedicated_worker, dedicated_worker);
const handles = await create_file_system_handles(t, root);
broadcast_channel.postMessage(
{ type: 'receive-file-system-handles', cloned_handles: handles });
const expected_response_count = 3;
const responses = [];
for (let i = 0; i < expected_response_count; ++i) {
const message_event =
await broadcast_channel_event_watcher.wait_for('message');
responses.push(message_event.data);
}
const expected_serialized_handles = await serialize_handles(handles);
for (let i = 0; i < responses.length; ++i) {
assert_equals(responses[i].type, 'receive-serialized-file-system-handles',
'The test runner must receive a "serialized-file-system-handles" ' +
`message response. Actual response: ${responses[i]}`);
assert_equals_serialized_handles(
responses[i].serialized_handles, expected_serialized_handles);
await assert_equals_cloned_handles(responses[i].cloned_handles, handles);
}
}, 'Send and receive messages using a broadcast channel in an iframe, ' +
'dedicated worker and service worker.');

View file

@ -0,0 +1,272 @@
'use strict';
// This script depends on the following scripts:
// /native-file-system/resources/messaging-helpers.js
// /native-file-system/resources/messaging-blob-helpers.js
// /native-file-system/resources/messaging-serialize-helpers.js
// /native-file-system/resources/test-helpers.js
// /common/get-host-info.sub.js
// /service-workers/service-worker/resources/test-helpers.sub.js
// Define URL constants for cross origin windows.
const kRemoteOrigin = get_host_info().HTTPS_REMOTE_ORIGIN;
const kRemoteOriginDocumentMessageTarget = `${kRemoteOrigin}${base_path()}` +
kDocumentMessageTarget;
// Sending a FileSystemHandle to a cross origin |target| through postMessage()
// must dispatch the 'messageerror' event.
//
// This test sends a FileSystemHandle to |target|. |target| responds with a
// serialized MessageEvent from the 'messageerror' event, allowing the test
// runner to verify MessageEvent properties.
async function do_send_message_error_test(
test,
root_dir,
receiver,
target,
target_origin,
// False when the MessageEvent's source is null.
expected_has_source,
// The origin of MessageEvents received by |target|.
expected_origin) {
const message_watcher = new EventWatcher(test, receiver, 'message');
// Send a file to |target|.
const file = await createFileWithContents(
test, 'test-error-file', 'test-error-file-contents', root_dir);
target.postMessage(
{ type: 'receive-file-system-handles', cloned_file_system_handles: [file] },
{ targetOrigin: target_origin });
// Wait for |target| to respond with results.
let message_event = await message_watcher.wait_for('message');
const first_response = message_event.data;
assert_equals(first_response.type, 'serialized-message-error',
'The test runner must receive a "serialized-message-error" message ' +
'in response to a FileSystemFileHandle message.');
// Verify the results.
assert_equals_serialized_message_error_event(
first_response.serialized_message_error_event,
expected_origin, expected_has_source);
// Send a directory to |target|.
const directory = await createDirectory(
test, 'test-error-directory', root_dir);
target.postMessage(
{
type: 'receive-file-system-handles',
cloned_file_system_handles: [directory]
}, { targetOrigin: target_origin });
// Wait for |target| to respond with results.
message_event = await message_watcher.wait_for('message');
const second_response = message_event.data;
assert_equals(second_response.type, 'serialized-message-error',
'The test runner must receive a "serialized-message-error" message ' +
'response to a FileSystemDirectoryHandle message.');
// Verify the results.
assert_equals_serialized_message_error_event(
second_response.serialized_message_error_event,
expected_origin, expected_has_source);
}
// This test receives a FileSystemHandle from |target|. This test runner
// must dispatch the 'messageerror' event after receiving a handle from target.
async function do_receive_message_error_test(
test,
receiver,
target,
target_origin,
// False when the MessageEvent's source is null.
expected_has_source,
// The origin of MessageEvents received by this test runner.
expected_origin) {
const error_watcher = new EventWatcher(test, receiver, 'messageerror');
// Receive a file from |target|.
target.postMessage(
{ type: 'create-file' }, { targetOrigin: target_origin });
const first_error = await error_watcher.wait_for('messageerror');
const serialized_first_error = serialize_message_error_event(first_error);
assert_equals_serialized_message_error_event(
serialized_first_error, expected_origin, expected_has_source);
// Receive a directory from |target|.
target.postMessage(
{ type: 'create-directory' }, { targetOrigin: target_origin });
const second_error = await error_watcher.wait_for('messageerror');
const serialized_second_error = serialize_message_error_event(second_error);
assert_equals_serialized_message_error_event(
serialized_second_error, expected_origin, expected_has_source);
}
// Performs the send message error test followed by the receive message error
// test.
async function do_send_and_receive_message_error_test(
test,
root_dir,
receiver,
target,
target_origin,
// False when the MessageEvent's source is null.
expected_has_source,
// The origin of MessageEvents received by |target|.
expected_origin,
// The origin of MessageEvents received by this test runner.
expected_remote_origin) {
await do_send_message_error_test(
test, root_dir, receiver, target, target_origin, expected_has_source,
expected_origin);
await do_receive_message_error_test(
test, receiver, target, target_origin, expected_has_source,
expected_remote_origin);
}
// Runs the same test as do_send_message_error_test(), but uses a MessagePort.
// This test starts by establishing a message channel between the test runner
// and |target|.
async function do_send_message_port_error_test(
test, root_dir, target, target_origin) {
const message_port = create_message_channel(target, target_origin);
await do_send_message_error_test(
test, root_dir, /*receiver=*/message_port, /*target=*/message_port,
/*target_origin=*/undefined, /*expected_has_source=*/false,
/*expected_origin=*/'', /*expected_remote_origin=*/'');
}
// Runs the same test as do_receive_message_error_test(), but uses a MessagePort.
async function do_receive_message_port_error_test(
test, target, target_origin) {
const message_port = create_message_channel(target, target_origin);
await do_receive_message_error_test(
test, /*receiver=*/message_port, /*target=*/message_port,
/*target_origin=*/undefined, /*expected_has_source=*/false,
/*expected_origin=*/'');
}
// Runs the same test as do_send_and_receive_message_error_test(), but uses a
// MessagePort.
async function do_send_and_receive_message_port_error_test(
test, root_dir, target, target_origin) {
await do_send_message_port_error_test(
test, root_dir, target, target_origin);
await do_receive_message_port_error_test(
test, target, target_origin);
}
directory_test(async (t, root_dir) => {
const iframe = await add_iframe(
t, { src: kRemoteOriginDocumentMessageTarget });
await do_send_and_receive_message_error_test(
t, root_dir, /*receiver=*/self, /*target=*/iframe.contentWindow,
/*target_origin=*/'*', /*expected_has_source=*/true,
/*expected_origin=*/location.origin,
/*expected_remote_origin=*/kRemoteOrigin);
}, 'Fail to send and receive messages using a cross origin iframe.');
directory_test(async (t, root_dir) => {
const iframe = await add_iframe(t, { src: kRemoteOriginDocumentMessageTarget });
await do_send_and_receive_message_port_error_test(
t, root_dir, /*target=*/iframe.contentWindow, /*target_origin=*/'*');
}, 'Fail to send and receive messages using a cross origin message port in ' +
'an iframe.');
directory_test(async (t, root_dir) => {
const iframe = await add_iframe(
t, { src: kDocumentMessageTarget, sandbox: 'allow-scripts' });
await do_send_message_error_test(
t, root_dir, /*receiver=*/self, /*target=*/iframe.contentWindow,
/*target_origin=*/'*', /*expected_has_source*/true,
/*expected_origin=*/location.origin);
// https://crbug.com/1014248 Should sandboxed iframes expose the
// NativeFileSystem?
//
// await do_receive_message_error_test(
// t, /*receiver=*/self, /*target=*/iframe.contentWindow,
// /*target_origin=*/'*', /*expected_has_source=*/true,
// /*expected_origin=*/kRemoteOrigin);
}, 'Fail to send and receive messages using a sandboxed iframe.');
directory_test(async (t, root_dir) => {
const iframe = await add_iframe(
t, { src: kDocumentMessageTarget, sandbox: 'allow-scripts' });
await do_send_message_port_error_test(
t, root_dir, /*target=*/iframe.contentWindow, /*target_origin=*/'*');
// https://crbug.com/1014248 Should sandboxed iframes expose the
// NativeFileSystem?
//
// await do_receive_message_port_error_test(
// t, /*target=*/iframe.contentWindow, /*target_origin=*/'*');
}, 'Fail to send and receive messages using a message port in a sandboxed ' +
'iframe.');
directory_test(async (t, root_dir) => {
const iframe_data_uri = await create_message_target_data_uri(t);
const iframe = await add_iframe(t, { src: iframe_data_uri });
await do_send_message_error_test(t, root_dir, /*receiver=*/self,
/*target=*/iframe.contentWindow, /*target_origin=*/'*',
/*expected_has_source*/true, /*expected_origin=*/location.origin);
// Do not test receiving FileSystemHandles from the data URI iframe.
// Data URI iframes are insecure and do not expose the NativeFileSystem APIs.
}, 'Fail to send messages to a data URI iframe.');
directory_test(async (t, root_dir) => {
const iframe_data_uri = await create_message_target_data_uri(t);
const iframe = await add_iframe(t, { src: iframe_data_uri });
await do_send_message_port_error_test(
t, root_dir, /*target=*/iframe.contentWindow, /*target_origin=*/'*');
}, 'Fail to send messages using a message port in a data URI iframe.');
directory_test(async (t, root_dir) => {
const child_window = await open_window(t, kRemoteOriginDocumentMessageTarget);
await do_send_and_receive_message_error_test(
t, root_dir, /*receiver=*/self, /*target=*/child_window, /*target_origin=*/'*',
/*expected_has_source=*/true, /*expected_origin=*/location.origin,
/*expected_remote_origin=*/kRemoteOrigin);
}, 'Fail to send and receive messages using a cross origin window.');
directory_test(async (t, root_dir) => {
const child_window = await open_window(t, kRemoteOriginDocumentMessageTarget);
await do_send_message_port_error_test(
t, root_dir, /*target=*/child_window, /*target_origin=*/'*');
}, 'Fail to send and receive messages using a cross origin message port in ' +
'a window.');
directory_test(async (t, root_dir) => {
const url = `${kDocumentMessageTarget}?pipe=header(Content-Security-Policy` +
', sandbox allow-scripts)';
const child_window = await open_window(t, url);
await do_send_message_error_test(
t, root_dir, /*receiver=*/self, /*target=*/child_window,
/*target_origin=*/'*', /*expected_has_source*/true,
/*expected_origin=*/location.origin);
// https://crbug.com/1014248 Should sandboxed windows expose the
// NativeFileSystem?
//
// await do_receive_message_error_test(
// t, /*receiver=*/self, /*target=*/child_window,
// /*target_origin=*/'*', /*expected_has_source=*/true,
// /*expected_origin=*/kRemoteOrigin);
}, 'Fail to send and receive messages using a sandboxed window.');
directory_test(async (t, root_dir) => {
const url = `${kDocumentMessageTarget}?pipe=header(Content-Security-Policy` +
', sandbox allow-scripts)';
const child_window = await open_window(t, url);
await do_send_message_port_error_test(
t, root_dir, /*target=*/child_window, /*target_origin=*/'*');
// https://crbug.com/1014248 Should sandboxed windows expose the
// NativeFileSystem?
//
// await do_receive_message_port_error_test(
// t, /*target=*/child_window, /*target_origin=*/'*');
}, 'Fail to send and receive messages using a message port in a sandboxed ' +
'window.');

View file

@ -0,0 +1,97 @@
'use strict';
// This script depends on the following scripts:
// /native-file-system/resources/messaging-helpers.js
// /native-file-system/resources/messaging-blob-helpers.js
// /native-file-system/resources/messaging-serialize-helpers.js
// /native-file-system/resources/test-helpers.js
// /service-workers/service-worker/resources/test-helpers.sub.js
// Runs the same test as do_post_message_test(), but uses a MessagePort.
// This test starts by establishing a message channel between the test runner
// and |target|. Afterwards, the test sends FileSystemHandles through the
// message port channel.
async function do_message_port_test(test, root_dir, target, target_origin) {
const message_port = create_message_channel(target, target_origin);
await do_post_message_test(
test, root_dir, /*receiver=*/message_port, /*target=*/message_port);
}
directory_test(async (t, root_dir) => {
const iframe = await add_iframe(t, { src: kDocumentMessageTarget });
await do_message_port_test(
t, root_dir, /*target=*/iframe.contentWindow, /*target_origin=*/'*');
}, 'Send and receive messages using a message port in a same origin ' +
'iframe.');
directory_test(async (t, root_dir) => {
const iframe = await add_iframe(t, {
src: kDocumentMessageTarget,
sandbox: 'allow-scripts allow-same-origin'
});
await do_message_port_test(
t, root_dir, /*target=*/iframe.contentWindow, /*target_origin=*/'*');
}, 'Send and receive messages using a message port in a sandboxed same ' +
'origin iframe.');
directory_test(async (t, root_dir) => {
const blob_url = await create_message_target_blob_url(t);
const iframe = await add_iframe(t, { src: blob_url });
await do_message_port_test(
t, root_dir, /*target=*/iframe.contentWindow, /*target_origin=*/'*');
}, 'Send and receive messages using a message port in a blob iframe.');
directory_test(async (t, root_dir) => {
const iframe_html = await create_message_target_html_without_subresources(t);
const iframe = await add_iframe(t, { srcdoc: iframe_html });
await do_message_port_test(
t, root_dir, /*target=*/iframe.contentWindow, /*target_origin=*/'*');
}, 'Send and receive messages using a message port in an iframe srcdoc.');
directory_test(async (t, root_dir) => {
const child_window = await open_window(t, kDocumentMessageTarget);
await do_message_port_test(
t, root_dir, /*target=*/child_window, /*target_origin=*/'*');
}, 'Send and receive messages using a message port in a same origin ' +
'window.');
directory_test(async (t, root_dir) => {
const blob_url = await create_message_target_blob_url(t);
const child_window = await open_window(t, blob_url);
await do_message_port_test(
t, root_dir, /*target=*/child_window, /*target_origin=*/'*');
}, 'Send and receive messages using a message port in a blob window.');
directory_test(async (t, root_dir) => {
const url = `${kDocumentMessageTarget}?pipe=header(Content-Security-Policy` +
', sandbox allow-scripts allow-same-origin)';
const child_window = await open_window(t, url);
await do_message_port_test(
t, root_dir, /*target=*/child_window, /*target_origin=*/'*');
}, 'Send and receive messages using a message port in a sandboxed same ' +
'origin window.');
directory_test(async (t, root_dir) => {
const dedicated_worker =
create_dedicated_worker(t, kDedicatedWorkerMessageTarget);
await do_message_port_test(t, root_dir, /*target=*/dedicated_worker);
}, 'Send and receive messages using a message port in a dedicated ' +
'worker.');
directory_test(async (t, root_dir) => {
const scope = `${kServiceWorkerMessageTarget}` +
'?post-message-to-message-port-with-file-handle';
const registration = await create_service_worker(
t, kServiceWorkerMessageTarget, scope);
await do_message_port_test(t, root_dir, /*target=*/registration.installing);
}, 'Send and receive messages using a message port in a service ' +
'worker.');
if (self.SharedWorker !== undefined) {
directory_test(async (t, root_dir) => {
const shared_worker = new SharedWorker(kSharedWorkerMessageTarget);
shared_worker.port.start();
await do_message_port_test(t, root_dir, /*target=*/shared_worker.port);
}, 'Send and receive messages using a message port in a shared ' +
' worker.');
}

View file

@ -0,0 +1,91 @@
'use strict';
// This script depends on the following scripts:
// /native-file-system/resources/messaging-helpers.js
// /native-file-system/resources/messaging-blob-helpers.js
// /native-file-system/resources/messaging-serialize-helpers.js
// /native-file-system/resources/test-helpers.js
// /service-workers/service-worker/resources/test-helpers.sub.js
directory_test(async (t, root_dir) => {
const iframe = await add_iframe(t, { src: kDocumentMessageTarget });
await do_post_message_test(
t, root_dir, /*receiver=*/self, /*target=*/iframe.contentWindow,
/*target_origin=*/'*');
}, 'Send and receive messages using a same origin iframe.');
directory_test(async (t, root_dir) => {
const iframe = await add_iframe(t, {
src: kDocumentMessageTarget,
sandbox: 'allow-scripts allow-same-origin'
});
await do_post_message_test(
t, root_dir, /*receiver=*/self, /*target=*/iframe.contentWindow,
/*target_origin=*/'*');
}, 'Send and receive messages using a sandboxed same origin iframe.');
directory_test(async (t, root_dir) => {
const blob_url = await create_message_target_blob_url(t);
const iframe = await add_iframe(t, { src: blob_url });
await do_post_message_test(
t, root_dir, /*receiver=*/self, /*target=*/iframe.contentWindow,
/*target_origin=*/'*');
}, 'Send and receive messages using a blob iframe.');
directory_test(async (t, root_dir) => {
const iframe_html = await create_message_target_html_without_subresources(t);
const iframe = await add_iframe(t, { srcdoc: iframe_html });
await do_post_message_test(
t, root_dir, /*receiver=*/self, /*target=*/iframe.contentWindow,
/*target_origin=*/'*');
}, 'Send and receive messages using an iframe srcdoc.');
directory_test(async (t, root_dir) => {
const child_window = await open_window(t, kDocumentMessageTarget);
await do_post_message_test(
t, root_dir, /*receiver=*/self, /*target=*/child_window,
/*target_origin=*/'*');
}, 'Send and receive messages using a same origin window.');
directory_test(async (t, root_dir) => {
const blob_url = await create_message_target_blob_url(t);
const child_window = await open_window(t, blob_url);
await do_post_message_test(
t, root_dir, /*receiver=*/self, /*target=*/child_window,
/*target_origin=*/'*');
}, 'Send and receive messages using a blob window.');
directory_test(async (t, root_dir) => {
const url = `${kDocumentMessageTarget}?pipe=header(Content-Security-Policy` +
', sandbox allow-scripts allow-same-origin)';
const child_window = await open_window(t, url);
await do_post_message_test(
t, root_dir, /*receiver=*/self, /*target=*/child_window,
/*target_origin=*/'*');
}, 'Send and receive messages using a sandboxed same origin window.');
directory_test(async (t, root_dir) => {
const dedicated_worker =
create_dedicated_worker(t, kDedicatedWorkerMessageTarget);
await do_post_message_test(
t, root_dir, /*receiver=*/dedicated_worker, /*target=*/dedicated_worker);
}, 'Send and receive messages using a dedicated worker.');
directory_test(async (t, root_dir) => {
const scope = `${kServiceWorkerMessageTarget}?post-message-with-file-handle`;
const registration = await create_service_worker(
t, kServiceWorkerMessageTarget, scope);
await do_post_message_test(
t, root_dir, /*receiver=*/navigator.serviceWorker,
/*target=*/registration.installing);
}, 'Send and receive messages using a service worker.');
if (self.SharedWorker !== undefined) {
directory_test(async (t, root_dir) => {
const shared_worker = new SharedWorker(kSharedWorkerMessageTarget);
shared_worker.port.start();
await do_post_message_test(
t, root_dir, /*receiver=*/shared_worker.port,
/*target=*/shared_worker.port);
}, 'Send and receive messages using a shared worker.');
}