forked from web-platform-tests/wpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WPT] Eligibility: dedicated and shared workers (web-platform-tests#3…
…1228) When there are dedicated workers/shared workers, Chrome: The page is not BFCached. Firefox: The page is BFCached. Safari: The page is BFCached for dedicated workers. Shared workers are not supported. Bug: 1146955 Change-Id: Ia901715436e1a0c64c68ad5b537e99f685825489 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3220944 Reviewed-by: Ben Kelly <[email protected]> Reviewed-by: Fergal Daly <[email protected]> Reviewed-by: Rakina Zata Amni <[email protected]> Commit-Queue: Hiroshige Hayashizaki <[email protected]> Cr-Commit-Position: refs/heads/main@{#968294} Co-authored-by: Hiroshige Hayashizaki <[email protected]>
- Loading branch information
1 parent
cb862e4
commit 6e4a5b0
Showing
5 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
html/browsers/browsing-the-web/back-forward-cache/eligibility/dedicated-worker.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!doctype html> | ||
<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 src="../resources/helper.sub.js"></script> | ||
<script> | ||
// Check whether the page is BFCached when there are dedicated workers that are | ||
// already loaded. | ||
runBfcacheTest({ | ||
funcBeforeNavigation: async () => { | ||
globalThis.worker = new Worker('../resources/echo-worker.js'); | ||
// Make sure the worker starts before navigation. | ||
await WorkerHelper.pingWorker(globalThis.worker); | ||
}, | ||
funcAfterAssertion: async (pageA) => { | ||
// Confirm that the worker is still there. | ||
assert_equals( | ||
await pageA.execute_script(() => WorkerHelper.pingWorker(globalThis.worker)), | ||
'PASS', | ||
'Worker should still work after restored from BFCache'); | ||
} | ||
}, 'Eligibility: dedicated workers'); | ||
</script> |
24 changes: 24 additions & 0 deletions
24
html/browsers/browsing-the-web/back-forward-cache/eligibility/shared-worker.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!doctype html> | ||
<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 src="../resources/helper.sub.js"></script> | ||
<script> | ||
// Check whether the page is BFCached when there are shared workers that are | ||
// already loaded. | ||
runBfcacheTest({ | ||
funcBeforeNavigation: async () => { | ||
globalThis.worker = new SharedWorker('../resources/echo-worker.js'); | ||
// Make sure the worker starts before navigation. | ||
await WorkerHelper.pingWorker(globalThis.worker); | ||
}, | ||
funcAfterAssertion: async (pageA) => { | ||
// Confirm that the worker is still there. | ||
assert_equals( | ||
await pageA.execute_script(() => WorkerHelper.pingWorker(globalThis.worker)), | ||
'PASS', | ||
'SharedWorker should still work after restored from BFCache'); | ||
} | ||
}, 'Eligibility: shared workers'); | ||
</script> |
16 changes: 16 additions & 0 deletions
16
html/browsers/browsing-the-web/back-forward-cache/resources/echo-worker.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// On receiving a message from the parent Document, send back a message to the | ||
// parent Document. This is used to wait for worker initialization and test | ||
// that this worker is alive and working. | ||
|
||
// For dedicated workers. | ||
self.addEventListener('message', event => { | ||
postMessage(event.data); | ||
}); | ||
|
||
// For shared workers. | ||
onconnect = e => { | ||
const port = e.ports[0]; | ||
port.onmessage = event => { | ||
port.postMessage(event.data); | ||
} | ||
}; |
1 change: 1 addition & 0 deletions
1
html/browsers/browsing-the-web/back-forward-cache/resources/executor.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
html/browsers/browsing-the-web/back-forward-cache/resources/worker-helper.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Worker-related helper file to be used from executor.html. | ||
|
||
// The class `WorkerHelper` is exposed to `globalThis` because this should be | ||
// used via `eval()`. | ||
globalThis.WorkerHelper = class { | ||
static pingWorker(worker) { | ||
return new Promise((resolve, reject) => { | ||
const message = 'message ' + Math.random(); | ||
const onmessage = e => { | ||
if (e.data === message) { | ||
resolve('PASS'); | ||
} else { | ||
reject('pingWorker: expected ' + message + ' but got ' + e.data); | ||
} | ||
}; | ||
worker.onerror = reject; | ||
if (worker instanceof Worker) { | ||
worker.addEventListener('message', onmessage, {once: true}); | ||
worker.postMessage(message); | ||
} else if (worker instanceof SharedWorker) { | ||
worker.port.onmessage = onmessage; | ||
worker.port.postMessage(message); | ||
} else { | ||
reject('Unexpected worker type'); | ||
} | ||
}); | ||
} | ||
}; |