blob: 53ee1493743d79768908a3ac4c47ca0b84243f4e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
// This worker reports back the final state of FetchEvent.handled (RESOLVED or
// REJECTED) to the test.
self.addEventListener('message', function(event) {
self.port = event.data.port;
});
self.addEventListener('fetch', function(event) {
try {
event.handled.then(() => {
self.port.postMessage('RESOLVED');
}, () => {
self.port.postMessage('REJECTED');
});
} catch (e) {
self.port.postMessage('FAILED');
return;
}
const search = new URL(event.request.url).search;
switch (search) {
case '?respondWith-not-called':
break;
case '?respondWith-not-called-and-event-canceled':
event.preventDefault();
break;
case '?respondWith-called-and-promise-resolved':
event.respondWith(Promise.resolve(new Response('body')));
break;
case '?respondWith-called-and-promise-resolved-to-invalid-response':
event.respondWith(Promise.resolve('invalid response'));
break;
case '?respondWith-called-and-promise-rejected':
event.respondWith(Promise.reject(new Error('respondWith rejected')));
break;
}
});
|