Index: content/test/data/browsing_data/worker.js |
diff --git a/content/test/data/browsing_data/worker.js b/content/test/data/browsing_data/worker.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..78e42694eeb9405550595f69cdb4ec960427a6b3 |
--- /dev/null |
+++ b/content/test/data/browsing_data/worker.js |
@@ -0,0 +1,46 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+// Service worker used in ClearSiteDataThrottleBrowserTest. |
+ |
+// Handle all resource requests. |
+self.addEventListener('fetch', function(event) { |
+ var url = new URL(event.request.url); |
+ |
+ var other_origin_param_regex = /other_origin=([^&=?]+)/; |
+ var other_origin = decodeURIComponent( |
+ url.search.match(other_origin_param_regex)[1]); |
+ |
+ // If this is a request for 'resource_from_sw', serve that resource. |
+ var resource_request_regex = /file=resource_from_sw/; |
+ var resource_request = !!url.search.match(resource_request_regex); |
+ |
+ if (resource_request) { |
+ event.respondWith(new Response( |
+ 'Response content is not important, only the header is.', { |
+ 'headers': { 'Clear-Site-Data': '{ "types" : [ "cookies" ] }' } |
+ })); |
+ return; |
+ } |
+ |
+ // Otherwise, serve the default response - a simple HTML page that embeds |
+ // that resource two times. |
+ var header = encodeURIComponent('{ "types": [ "cookies" ] }'); |
+ event.respondWith(new Response( |
+ '<html><head></head><body>' + |
+ |
+ // Load the resource once on this origin and once on a different origin. |
+ // In both cases, the Clear-Site-Data header should be ignored. |
+ '<img src="?file=resource_from_sw&header=' + header + '" />' + |
+ '<img src="' + |
+ other_origin + '/?file=resource_from_sw&header=' + header + '" />' + |
+ |
+ // Confirm to the C++ side of this test that the response really came from |
+ // the service worker. |
+ '<script>window.location.hash = "service-worker-active";</script>' + |
+ |
+ '</body></html>', |
+ { 'headers': { 'Content-Type': 'text/html' } } |
+ )); |
+}); |