-
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.
Bug 1783602 [wpt PR 35374] - Fetch: Add tests for AbortSignal's abort…
… reason, a=testonly Automatic update from web-platform-tests Fetch: Add tests for AbortSignal's abort reason (#35374) Add test cases to check the functionality of AbortSignal's abort reason when aborting fetch, including serialization and that the service worker can observe the reason. See whatwg/fetch#1343 for accompanying spec changes. -- wpt-commits: 0e5f85c08e05fb1b9b67fb12c4d7c0de77a4ee9b wpt-pr: 35374
- Loading branch information
1 parent
2ed8f80
commit 77de3ed
Showing
3 changed files
with
142 additions
and
5 deletions.
There are no files selected for viewing
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
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
19 changes: 19 additions & 0 deletions
19
testing/web-platform/tests/fetch/api/resources/sw-intercept-abort.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,19 @@ | ||
async function messageClient(clientId, message) { | ||
const client = await clients.get(clientId); | ||
client.postMessage(message); | ||
} | ||
|
||
addEventListener('fetch', event => { | ||
let resolve; | ||
const promise = new Promise(r => resolve = r); | ||
|
||
function onAborted() { | ||
messageClient(event.clientId, event.request.signal.reason); | ||
resolve(); | ||
} | ||
|
||
messageClient(event.clientId, 'fetch event has arrived'); | ||
|
||
event.respondWith(promise.then(() => new Response('hello'))); | ||
event.request.signal.addEventListener('abort', onAborted); | ||
}); |