OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Service worker used in ClearSiteDataThrottleBrowserTest. |
| 6 |
| 7 // Handle all resource requests. |
| 8 self.addEventListener('fetch', function(event) { |
| 9 var url = new URL(event.request.url); |
| 10 |
| 11 var other_origin_param_regex = /other_origin=([^&=?]+)/; |
| 12 var other_origin = decodeURIComponent( |
| 13 url.search.match(other_origin_param_regex)[1]); |
| 14 |
| 15 // If this is a request for 'resource_from_sw', serve that resource. |
| 16 var resource_request_regex = /file=resource_from_sw/; |
| 17 var resource_request = !!url.search.match(resource_request_regex); |
| 18 |
| 19 if (resource_request) { |
| 20 event.respondWith(new Response( |
| 21 'Response content is not important, only the header is.', { |
| 22 'headers': { 'Clear-Site-Data': '{ "types" : [ "cookies" ] }' } |
| 23 })); |
| 24 return; |
| 25 } |
| 26 |
| 27 // Otherwise, serve the default response - a simple HTML page that embeds |
| 28 // that resource two times. |
| 29 var header = encodeURIComponent('{ "types": [ "cookies" ] }'); |
| 30 event.respondWith(new Response( |
| 31 '<html><head></head><body>' + |
| 32 |
| 33 // Load the resource once on this origin and once on a different origin. |
| 34 // In both cases, the Clear-Site-Data header should be ignored. |
| 35 '<img src="?file=resource_from_sw&header=' + header + '" />' + |
| 36 '<img src="' + |
| 37 other_origin + '/?file=resource_from_sw&header=' + header + '" />' + |
| 38 |
| 39 // Confirm to the C++ side of this test that the response really came from |
| 40 // the service worker. |
| 41 '<script>window.location.hash = "service-worker-active";</script>' + |
| 42 |
| 43 '</body></html>', |
| 44 { 'headers': { 'Content-Type': 'text/html' } } |
| 45 )); |
| 46 }); |
OLD | NEW |