Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / fetch / resources / thorough-worker.js
blob8a4a3872b325541f21c98cf19f6d5bc12599c388
1 importScripts('fetch-test-options.js');
2 importScripts('thorough-util.js');
4 var port = undefined;
5 var isTestTargetFetch = false;
7 self.onmessage = function(e) {
8 var message = e.data;
9 if ('port' in message) {
10 port = message.port;
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.
21 return;
23 isTestTargetFetch = false;
25 event.respondWith(
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);
32 return response;
34 .catch(function(message) {
35 port.postMessage(message);
36 return Promise.reject();
39 });