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

Unified Diff: content/test/data/browsing_data/worker.js

Issue 2368923003: Support the Clear-Site-Data header on resource requests (Closed)
Patch Set: Fix the compilation error Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
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..84aca73f6456c51a76a0525cdc5580641d50d4f8
--- /dev/null
+++ b/content/test/data/browsing_data/worker.js
@@ -0,0 +1,73 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
falken 2017/05/17 07:37:00 2017 :)
msramek 2017/05/17 13:46:37 Done. Yeah, this normally doesn't happen in May :)
+// 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);
+
+ // If this is a request for 'resource_from_sw', serve that resource
+ // with a Clear-Site-Data header.
+ if (url.pathname.match('resource_from_sw')) {
+ event.respondWith(new Response(
+ 'Response content is not important, only the header is.', {
+ 'headers': { 'Clear-Site-Data': '{ "types" : [ "cookies" ] }' }
+ }));
+ return;
+ }
+
+ // If this is a request for 'resource', let it through. It will be responded
+ // to by the test server.
+ if (url.pathname.match('resource'))
+ return;
+
+ // Otherwise, serve the default response - a simple HTML page that will
+ // execute the following function:
+ var response_script_body = function(url_search) {
+ // Parse the origin[1234] |url| parameters.
+ var origins = {};
+ for (var i = 1; i <= 4; i++) {
+ var origin_param_regex = new RegExp('origin' + i + '=([^&=?]+)');
+ origins[i] = decodeURIComponent(url_search.match(origin_param_regex)[1]);
+ }
+
+ // Prepare the test cases.
+ var resource_urls = [
+ origins[1] + 'resource',
+ origins[1] + 'resource_from_sw',
+ origins[2] + 'resource_from_sw',
+ origins[2] + 'resource',
+ origins[3] + 'resource_from_sw',
+ origins[3] + 'resource_from_sw',
+ origins[4] + 'resource',
+ origins[4] + 'another_resource_so_that_the_previous_one_isnt_reused',
+ ];
+ var header = encodeURIComponent('{ "types": [ "cookies" ] }');
+
+ // When all resources are fetched, this helper method will report it back
+ // to the C++ side by setting the document title.
+ var resources_loaded = 0;
+ function done() {
+ if (++resources_loaded == resource_urls.length)
+ document.title = "done";
+ }
+
+ // Fetch the resources.
+ for (var i = 0; i < resource_urls.length; i++) {
+ var img = new Image();
+ document.body.appendChild(img);
+ img.onload = img.onerror = done;
+ img.src = resource_urls[i] + "?header=" + header;
+ }
+ }
+
+ // Return the code of |response_script_body| as the response.
+ event.respondWith(new Response(
+ '<html><head></head><body><script>' +
+ '(' + response_script_body.toString() + ')("' + url.search + '")' +
+ '</script></body></html>',
+ { 'headers': { 'Content-Type': 'text/html' } }
+ ));
+});

Powered by Google App Engine
This is Rietveld 408576698