Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(212)

Side by Side Diff: content/test/data/browsing_data/worker.js

Issue 2933083002: Revert of Align `clear-site-data` syntax with the spec. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Service worker used in ClearSiteDataThrottleBrowserTest. 5 // Service worker used in ClearSiteDataThrottleBrowserTest.
6 6
7 // Handle all resource requests. 7 // Handle all resource requests.
8 self.addEventListener('fetch', function(event) { 8 self.addEventListener('fetch', function(event) {
9 var url = new URL(event.request.url); 9 var url = new URL(event.request.url);
10 10
11 // If this is a request for 'resource_from_sw', serve that resource 11 // If this is a request for 'resource_from_sw', serve that resource
12 // with a Clear-Site-Data header. 12 // with a Clear-Site-Data header.
13 if (url.pathname.match('resource_from_sw')) { 13 if (url.pathname.match('resource_from_sw')) {
14 event.respondWith(new Response( 14 event.respondWith(new Response(
15 'Response content is not important, only the header is.', { 15 'Response content is not important, only the header is.', {
16 'headers': { 'Clear-Site-Data': '"cookies"' } 16 'headers': { 'Clear-Site-Data': '{ "types" : [ "cookies" ] }' }
17 })); 17 }));
18 return; 18 return;
19 } 19 }
20 20
21 // If this is a request for 'resource', let it through. It will be responded 21 // If this is a request for 'resource', let it through. It will be responded
22 // to by the test server. 22 // to by the test server.
23 if (url.pathname.match('resource')) 23 if (url.pathname.match('resource'))
24 return; 24 return;
25 25
26 // Otherwise, serve the default response - a simple HTML page that will 26 // Otherwise, serve the default response - a simple HTML page that will
(...skipping 10 matching lines...) Expand all
37 var resource_urls = [ 37 var resource_urls = [
38 origins[1] + 'resource', 38 origins[1] + 'resource',
39 origins[2] + 'resource_from_sw', 39 origins[2] + 'resource_from_sw',
40 origins[3] + 'resource_from_sw', 40 origins[3] + 'resource_from_sw',
41 origins[4] + 'resource', 41 origins[4] + 'resource',
42 origins[1] + 'resource_from_sw', 42 origins[1] + 'resource_from_sw',
43 origins[2] + 'resource', 43 origins[2] + 'resource',
44 origins[3] + 'resource_from_sw', 44 origins[3] + 'resource_from_sw',
45 origins[4] + 'another_resource_so_that_the_previous_one_isnt_reused', 45 origins[4] + 'another_resource_so_that_the_previous_one_isnt_reused',
46 ]; 46 ];
47 var header = encodeURIComponent('"cookies"'); 47 var header = encodeURIComponent('{ "types": [ "cookies" ] }');
48 48
49 // Fetch all resources and report back to the C++ side by setting 49 // Fetch all resources and report back to the C++ side by setting
50 // the document title. 50 // the document title.
51 var fetchResource = function(index) { 51 var fetchResource = function(index) {
52 var img = new Image(); 52 var img = new Image();
53 document.body.appendChild(img); 53 document.body.appendChild(img);
54 54
55 img.onload = img.onerror = function() { 55 img.onload = img.onerror = function() {
56 if (index + 1 == resource_urls.length) 56 if (index + 1 == resource_urls.length)
57 document.title = "done"; 57 document.title = "done";
58 else 58 else
59 fetchResource(index + 1); 59 fetchResource(index + 1);
60 } 60 }
61 61
62 img.src = resource_urls[index] + "?header=" + header; 62 img.src = resource_urls[index] + "?header=" + header;
63 } 63 }
64 fetchResource(0); 64 fetchResource(0);
65 } 65 }
66 66
67 // Return the code of |response_script_body| as the response. 67 // Return the code of |response_script_body| as the response.
68 event.respondWith(new Response( 68 event.respondWith(new Response(
69 '<html><head></head><body><script>' + 69 '<html><head></head><body><script>' +
70 '(' + response_script_body.toString() + ')("' + url.search + '")' + 70 '(' + response_script_body.toString() + ')("' + url.search + '")' +
71 '</script></body></html>', 71 '</script></body></html>',
72 { 'headers': { 'Content-Type': 'text/html' } } 72 { 'headers': { 'Content-Type': 'text/html' } }
73 )); 73 ));
74 }); 74 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698