1 importScripts('fetch-test-options.js');
2 importScripts('thorough-util.js');
5 var isTestTargetFetch
= false;
7 self
.onmessage = function(e
) {
9 if ('port' in message
) {
11 } else if (message
.msg
=== 'START TEST CASE') {
12 isTestTargetFetch
= true;
13 port
.postMessage({msg
: 'READY'});
17 self
.addEventListener('fetch', function(event
) {
18 if (!isTestTargetFetch
) {
19 // Don't handle the event when it is not the test target fetch such as a
20 // redirected fetch or for the iframe html.
23 isTestTargetFetch
= false;
26 doFetch(event
.request
)
27 .then(function(message
) {
28 var response
= message
.response
;
29 message
.response
= undefined;
30 // Send the result to thorough-control-util.js.
31 port
.postMessage(message
);
34 .catch(function(message
) {
35 port
.postMessage(message
);
36 return Promise
.reject();