Files
sousa-gecko/testing/web-platform/tests/html/document-isolation-policy/shared-workers.tentative.https.html
T
Camille Lamy a14e6720b4 Bug 1959241 [wpt PR 51902] - [DIP] Fix flaky test, a=testonly
Automatic update from web-platform-tests
[DIP] Fix flaky test

This CL updates the DocumentIsolationPolicy shared-workers WPT test,
that was flaky. The test was doing several calls for workers in parallel
with different configurations, and sometimes one would resolve before
the other, with a different result from the baseline. It was
unnecessary to load all those workers in parallel, so now each subset
only loads one worker. In addition, the worker is created from a remote
executor context, which allows to experiment with different values of
DIP for the worker creator. The previous alternative created an iframe
and reached into its DOM directly to create the worker, but this doesn't
work if the iframe and the main frame of the test have different DIP.
Finally, we removed tests that tried to create workers from FileSystem
URLs because SharedWorkers cannot be loaded from FileSystem URLs.

Bug: 333029146
Change-Id: Iaf74a8efb1268d7b44424beda9531b099b62f179
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6440923
Reviewed-by: Mike West <mkwst@chromium.org>
Commit-Queue: Camille Lamy <clamy@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1444604}

--

wpt-commits: 53e76c84f6034d4c60a6fc446b76ef3ae86f7e45
wpt-pr: 51902
2025-04-10 15:20:22 +00:00

131 lines
4.7 KiB
HTML

<!doctype html>
<html>
<meta charset="utf-8">
<meta name="timeout" content="long">
<title>COEP - policy derivation for Shared Workers</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/common/utils.js"></script>
<script src="resources/common.js"></script>
<script src="resources/worker-support.js"></script>
<script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script>
<body>
<p>Verify the Document Isolation Policy for Shared Workers by performing a
cross-origin "fetch" request for a resource that does not specify CORP. Only
Shared Workers with the default DIP should be able to successfully perform
this operation.</p>
<script>
'use strict';
function makeWorkerUrl(options) {
return resolveUrl("resources/shared-worker-fetch.js.py", options);
}
/**
* Create a Shared Worker within an iframe and insrtuct it to fetch from a
* specified URL and report on the success of the operation.
*
* @param {object} t - a testharness.js subtest instance (used to reset global
* state)
* @param {string} url - the URL from which the Shared Worker should be
* created
* @param {string} ownerDip - the Document Isolation Policy of the
iframe
*/
async function fetchFromWorker(t, url, ownerDip) {
const uuid = await createIframeContext(t, get_host_info().HTTPS_ORIGIN, ownerDip);
const ctx = new RemoteContext(uuid[0]);
const resourceUrl =
get_host_info().HTTPS_REMOTE_ORIGIN+"/html/document-isolation-policy/resources/nothing-no-corp.js";
const result = await ctx.execute_script(
async (workerUrl, fetchUrl) => {
try {
const worker = new SharedWorker(workerUrl);
worker.onerror = (event) => {throw new Error("Worker.onerror should not be called");};
await new Promise((resolve) => {
worker.port.addEventListener('message', resolve, { once: true });
worker.port.start();
});
return await new Promise((resolve) => {
worker.port.postMessage(fetchUrl);
worker.port.addEventListener(
'message', (event) => resolve(event.data), { once: true });
});
} catch (error) {
return error;
}
}, [url, resourceUrl]);
return result;
}
promise_test(async (t) => {
const result = await fetchFromWorker(t, makeWorkerUrl(), dip_none);
assert_equals(result, 'success');
}, 'default policy (derived from response)');
promise_test(async (t) => {
const result = await fetchFromWorker(t, makeWorkerUrl({ dip: 'isolate-and-require-corp' }), dip_none);
assert_equals(result, 'failure');
}, '"isolate-and-require-corp" (derived from response)');
promise_test(async (t) => {
const blobUrl = await createLocalUrl(t, {
url: makeWorkerUrl(),
scheme: "blob",
});
const result = await fetchFromWorker(t, blobUrl, dip_none);
assert_equals(result, 'success');
}, 'default policy (derived from owner set due to use of local scheme - blob URL)');
promise_test(async (t) => {
const blobUrl = await createLocalUrl(t, {
url: makeWorkerUrl(),
creatorDip: "isolate-and-require-corp",
scheme: "blob",
});
const result = await fetchFromWorker(t, blobUrl, dip_none);
assert_equals(result, 'failure');
}, 'isolate-and-require-corp (derived from blob URL creator)');
promise_test(async (t) => {
const blobUrl = await createLocalUrl(t, {
url: makeWorkerUrl(),
scheme: "blob",
});
const result = await fetchFromWorker(t, blobUrl, dip_require_corp);
assert_equals(result, 'failure');
}, '"isolate-and-require-corp" (derived from owner set due to use of local scheme - blob URL)');
promise_test(async (t) => {
const dataUrl = await createLocalUrl(t, {
url: makeWorkerUrl(),
scheme: "data",
});
const result = await fetchFromWorker(t, dataUrl, dip_none);
assert_equals(result, 'success');
}, 'default policy (derived from owner set due to use of local scheme - data URL)');
promise_test(async (t) => {
const dataUrl = await createLocalUrl(t, {
url: makeWorkerUrl(),
creatorDip: "isolate-and-require-corp",
scheme: "data",
});
const result = await fetchFromWorker(t, dataUrl, dip_none);
assert_equals(result, 'success');
}, 'default policy (not derived from data URL creator)');
promise_test(async (t) => {
const dataUrl = await createLocalUrl(t, {
url: makeWorkerUrl(),
scheme: "data",
});
const result = await fetchFromWorker(t, dataUrl, dip_require_corp);
assert_equals(result, 'failure');
}, '"isolate-and-require-corp" (derived from owner set due to use of local scheme - data URL)');
</script>
</body>
</html>