Commit 36842bb4 authored by Asami Doi's avatar Asami Doi Committed by Chromium LUCI CQ

PlzDedicatedWorker: WPT for clients.matchAll() with a blob URL worker

The new test checks if `clients.matchAll()` can detect a blob URL worker
client. The test passed when the PlzDedicatedWorker feature is enabled
and fails when it is disabled.

Bug: 1017034
Change-Id: Ib5b0916c2b9a4068b379769236bd0da2c6285a5a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2629330
Commit-Queue: Asami Doi <asamidoi@chromium.org>
Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#844025}
parent 39e3d279
This is a testharness.js-based test.
FAIL Test Clients.matchAll() with a blob URL worker client. assert_equals: expected 1 but got 0
FAIL Test Clients.matchAll() with an uncontrolled blob URL worker client. assert_equals: expected 1 but got 0
Harness: the test ran to completion.
<!DOCTYPE html>
<title>Service Worker: Clients.matchAll with a blob URL worker client</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<script>
const SCRIPT = 'resources/clients-matchall-worker.js';
promise_test(async (t) => {
const scope = 'resources/clients-matchall-blob-url-worker.html';
const reg = await service_worker_unregister_and_register(t, SCRIPT, scope);
t.add_cleanup(_ => reg.unregister());
await wait_for_state(t, reg.installing, 'activated');
const frame = await with_iframe(scope);
t.add_cleanup(_ => frame.remove());
{
const message = await frame.contentWindow.waitForWorker();
assert_equals(message.data, 'Worker is ready.',
'Worker should reply to the message.');
}
const channel = new MessageChannel();
const message = await new Promise(resolve => {
channel.port1.onmessage = resolve;
frame.contentWindow.navigator.serviceWorker.controller.postMessage(
{port: channel.port2, options: {type: 'worker'}}, [channel.port2]);
});
checkMessageEvent(message);
}, 'Test Clients.matchAll() with a blob URL worker client.');
promise_test(async (t) => {
const scope = 'resources/blank.html';
const reg = await service_worker_unregister_and_register(t, SCRIPT, scope);
t.add_cleanup(_ => reg.unregister());
await wait_for_state(t, reg.installing, 'activated');
const workerScript = `
self.onmessage = (e) => {
self.postMessage("Worker is ready.");
};
`;
const blob = new Blob([workerScript], { type: 'text/javascript' });
const blobUrl = URL.createObjectURL(blob);
const worker = new Worker(blobUrl);
{
const message = await new Promise(resolve => {
worker.onmessage = resolve;
worker.postMessage("Ping to worker.");
});
assert_equals(message.data, 'Worker is ready.',
'Worker should reply to the message.');
}
const channel = new MessageChannel();
const message = await new Promise(resolve => {
channel.port1.onmessage = resolve;
reg.active.postMessage(
{port: channel.port2,
options: {includeUncontrolled: true, type: 'worker'}},
[channel.port2]
);
});
checkMessageEvent(message);
}, 'Test Clients.matchAll() with an uncontrolled blob URL worker client.');
function checkMessageEvent(e) {
assert_equals(e.data.length, 1);
const workerClient = e.data[0];
assert_equals(workerClient[0], undefined); // visibilityState
assert_equals(workerClient[1], undefined); // focused
assert_true(workerClient[2].includes('blob:')); // url
assert_equals(workerClient[3], 'worker'); // type
assert_equals(workerClient[4], 'none'); // frameType
}
</script>
<!DOCTYPE html>
<html>
<script>
const workerScript = `
self.onmessage = (e) => {
self.postMessage("Worker is ready.");
};
`;
const blob = new Blob([workerScript], { type: 'text/javascript' });
const blobUrl = URL.createObjectURL(blob);
const worker = new Worker(blobUrl);
function waitForWorker() {
return new Promise(resolve => {
worker.onmessage = resolve;
worker.postMessage("Ping to worker.");
});
}
</script>
</html>
This is a testharness.js-based test.
PASS Test Clients.matchAll() with a blob URL worker client.
PASS Test Clients.matchAll() with an uncontrolled blob URL worker client.
Harness: the test ran to completion.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment