Files
sousa-gecko/testing/web-platform/tests/workers/SharedWorker-extendedLifetime.html
T
Yoshisto Yanagisawa c512286760 Bug 2033546 [wpt PR 59346] - [WPT] Fix timeout in SharedWorker-extendedLifetime.html, a=testonly
Automatic update from web-platform-tests
[WPT] Fix timeout in SharedWorker-extendedLifetime.html

Intermittent timeouts on wpt.fyi were likely caused by SharedWorker
URL conflicts and communication overhead. This change:
1. Uses a unique URL (with token) for the SharedWorker to prevent
   interference with other tests.
2. Consolidates logic into a single execute_script call to reduce
   communication overhead and ensure a clean helper-based structure.
3. Properly verifies the reqid in message responses.

Bug: 400473072
Change-Id: Idc2107be2cebd386f5912f624f97cded025f1252
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7771649
Reviewed-by: Minoru Chikamune <chikamune@chromium.org>
Commit-Queue: Yoshisato Yanagisawa <yyanagisawa@chromium.org>
Commit-Queue: Minoru Chikamune <chikamune@chromium.org>
Auto-Submit: Yoshisato Yanagisawa <yyanagisawa@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1617373}

--

wpt-commits: 3c6014685ff2ce48eb09b532151c12129c5ff494
wpt-pr: 59346
2026-04-28 18:11:42 +00:00

52 lines
1.8 KiB
HTML

<!DOCTYPE html>
<title>SharedWorker extendedLifetime</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>
/**
* Connects to a SharedWorker and performs a single message exchange.
* Used both in the main window and in the popup via execute_script.
*/
const connectAndOperate = async (url, data) => {
const worker = new SharedWorker(url, {extendedLifetime: true});
worker.port.start();
return new Promise(resolve => {
const listener = event => {
if (event.data.reqid === data.reqid) {
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 worker_url = '/workers/resources/shared-worker-memory.js?' + token();
const ctx = new RemoteContext(token());
const popup = window.open(remoteExecutorUrl(ctx.context_id));
t.add_cleanup(() => popup.close());
// 1. Store data from the popup side.
const popup_response = await ctx.execute_script(connectAndOperate, [
worker_url, {op: 'store', data: uuid, reqid: 1}
]);
assert_equals(popup_response.status, 'OK');
popup.close();
// Wait to ensure the worker survives across the client's disappearance.
await new Promise(resolve => setTimeout(resolve, 1000));
// 2. Load data from the main window side.
const response = await connectAndOperate(worker_url, {op: 'load', reqid: 2});
assert_equals(response.status, 'OK');
assert_equals(response.data, uuid);
}, "SharedWorker lifetime should be extended with extendedLifetime");
</script>