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

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/navigation-redirect-worker.js

Issue 2872363002: Upstream service worker navigation tests to WPT (Closed)
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/navigation-redirect-to-http-worker.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // TODO(horo): Service worker can be killed at some point during the test. So we
2 // should use storage API instead of this global variable.
3 var urls = [];
4
5 self.addEventListener('message', function(event) {
6 event.data.port.postMessage({urls: urls});
7 urls = [];
8 });
9
10 function get_query_params(url) {
11 var search = (new URL(url)).search;
12 if (!search) {
13 return {};
14 }
15 var ret = {};
16 var params = search.substring(1).split('&');
17 params.forEach(function(param) {
18 var element = param.split('=');
19 ret[decodeURIComponent(element[0])] = decodeURIComponent(element[1]);
20 });
21 return ret;
22 }
23
24 self.addEventListener('fetch', function(event) {
25 urls.push(event.request.url)
26 var params = get_query_params(event.request.url);
27 if (params['sw'] == 'gen') {
28 event.respondWith(Response.redirect(params['url']));
29 } else if (params['sw'] == 'fetch') {
30 event.respondWith(fetch(event.request));
31 } else if (params['sw'] == 'opaque') {
32 event.respondWith(fetch(
33 new Request(event.request.url, {redirect: 'manual'})));
34 } else if (params['sw'] == 'opaqueThroughCache') {
35 var url = event.request.url;
36 var cache;
37 event.respondWith(
38 self.caches.delete(url)
39 .then(function() { return self.caches.open(url); })
40 .then(function(c) {
41 cache = c;
42 return fetch(new Request(url, {redirect: 'manual'}));
43 })
44 .then(function(res) { return cache.put(event.request, res); })
45 .then(function() { return cache.match(url); }));
46 }
47 });
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/navigation-redirect-to-http-worker.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698