Automatic update from web-platform-tests Cleanup SharedWorker-extendedLifetime tests resources The previous CL (89f1c5e8fda3) moved the tests out of tentative/ but missed moving the shared-worker-memory.js resource and updating the references in the test files. This CL completes the cleanup. Original CL: https://chromium-review.googlesource.com/c/chromium/src/+/7734182 Bug: 400473072 Change-Id: I5d9fab0a3f0a0135384dd94a99d0064de723b44c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7734485 Reviewed-by: Minoru Chikamune <chikamune@chromium.org> Commit-Queue: Yoshisato Yanagisawa <yyanagisawa@chromium.org> Cr-Commit-Position: refs/heads/main@{#1611273} -- wpt-commits: ec297b25a5cdaddf21df0503726be93f5ce58c11 wpt-pr: 59036
70 lines
2.5 KiB
HTML
70 lines
2.5 KiB
HTML
<!DOCTYPE html>
|
|
<title>SharedWorker extendedLifetime (Named and Module)</title>
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
<script src="/common/utils.js"></script>
|
|
<script src="/common/dispatcher/dispatcher.js"></script>
|
|
<script>
|
|
|
|
const connectToSharedWorker = async (options) => {
|
|
window.worker = new SharedWorker(
|
|
'/workers/resources/shared-worker-memory.js', options);
|
|
worker.port.start();
|
|
};
|
|
|
|
const postAndWait = async (data) => {
|
|
return new Promise(resolve => {
|
|
const listener = event => {
|
|
if (event.data.reqid !== data.reqid) {
|
|
return;
|
|
}
|
|
worker.port.removeEventListener('message', listener);
|
|
resolve(event.data);
|
|
};
|
|
worker.port.addEventListener('message', listener);
|
|
worker.port.postMessage(data);
|
|
});
|
|
};
|
|
|
|
promise_test(async t => {
|
|
const uuid = token();
|
|
const options = {name: 'named-worker', extendedLifetime: true};
|
|
|
|
const ctx = new RemoteContext(token());
|
|
const popup = window.open(remoteExecutorUrl(ctx.context_id));
|
|
await ctx.execute_script(connectToSharedWorker, [options]);
|
|
await ctx.execute_script(postAndWait, [{reqid: 1, op: 'store', data: uuid}]);
|
|
popup.close();
|
|
|
|
// Wait for potential worker teardown (if extendedLifetime were not working)
|
|
await new Promise(resolve => setTimeout(resolve, 100));
|
|
|
|
const ctx2 = new RemoteContext(token());
|
|
const popup2 = window.open(remoteExecutorUrl(ctx2.context_id));
|
|
await ctx2.execute_script(connectToSharedWorker, [options]);
|
|
const response = await ctx2.execute_script(postAndWait, [{reqid: 2, op: 'load'}]);
|
|
assert_equals(response.data, uuid);
|
|
}, "Named SharedWorker should survive across navigations with extendedLifetime");
|
|
|
|
promise_test(async t => {
|
|
const uuid = token();
|
|
const options = {type: 'module', extendedLifetime: true};
|
|
|
|
const ctx = new RemoteContext(token());
|
|
const popup = window.open(remoteExecutorUrl(ctx.context_id));
|
|
await ctx.execute_script(connectToSharedWorker, [options]);
|
|
await ctx.execute_script(postAndWait, [{reqid: 10, op: 'store', data: uuid}]);
|
|
popup.close();
|
|
|
|
// Wait for potential worker teardown
|
|
await new Promise(resolve => setTimeout(resolve, 100));
|
|
|
|
const ctx2 = new RemoteContext(token());
|
|
const popup2 = window.open(remoteExecutorUrl(ctx2.context_id));
|
|
await ctx2.execute_script(connectToSharedWorker, [options]);
|
|
const response = await ctx2.execute_script(postAndWait, [{reqid: 11, op: 'load'}]);
|
|
assert_equals(response.data, uuid);
|
|
}, "Module SharedWorker should survive across navigations with extendedLifetime");
|
|
|
|
</script>
|