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

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/fetch-event-test-worker.js

Issue 1816473002: Add layout tests to check that a FetchEvent includes the right headers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use const Created 4 years, 5 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 function handleString(event) { 1 function handleString(event) {
2 event.respondWith(new Response('Test string')); 2 event.respondWith(new Response('Test string'));
3 } 3 }
4 4
5 function handleBlob(event) { 5 function handleBlob(event) {
6 event.respondWith(new Response(new Blob(['Test blob']))); 6 event.respondWith(new Response(new Blob(['Test blob'])));
7 } 7 }
8 8
9 function handleReferrer(event) { 9 function handleReferrer(event) {
10 event.respondWith(new Response(new Blob( 10 event.respondWith(new Response(new Blob(
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 event.respondWith(fetch('other.html').then(function(response) { 63 event.respondWith(fetch('other.html').then(function(response) {
64 lastResponseForUsedCheck = response; 64 lastResponseForUsedCheck = response;
65 return response; 65 return response;
66 })); 66 }));
67 } else { 67 } else {
68 event.respondWith(new Response( 68 event.respondWith(new Response(
69 'bodyUsed: ' + lastResponseForUsedCheck.bodyUsed)); 69 'bodyUsed: ' + lastResponseForUsedCheck.bodyUsed));
70 } 70 }
71 } 71 }
72 72
73 function handleHeaders(event) {
74 const headers = Array.from(event.request.headers);
75 event.respondWith(new Response(JSON.stringify(headers)));
76 }
77
73 self.addEventListener('fetch', function(event) { 78 self.addEventListener('fetch', function(event) {
74 var url = event.request.url; 79 var url = event.request.url;
75 var handlers = [ 80 var handlers = [
76 { pattern: '?string', fn: handleString }, 81 { pattern: '?string', fn: handleString },
77 { pattern: '?blob', fn: handleBlob }, 82 { pattern: '?blob', fn: handleBlob },
78 { pattern: '?referrer', fn: handleReferrer }, 83 { pattern: '?referrer', fn: handleReferrer },
79 { pattern: '?clientId', fn: handleClientId }, 84 { pattern: '?clientId', fn: handleClientId },
80 { pattern: '?ignore', fn: function() {} }, 85 { pattern: '?ignore', fn: function() {} },
81 { pattern: '?null', fn: handleNullBody }, 86 { pattern: '?null', fn: handleNullBody },
82 { pattern: '?fetch', fn: handleFetch }, 87 { pattern: '?fetch', fn: handleFetch },
83 { pattern: '?form-post', fn: handleFormPost }, 88 { pattern: '?form-post', fn: handleFormPost },
84 { pattern: '?multiple-respond-with', fn: handleMultipleRespondWith }, 89 { pattern: '?multiple-respond-with', fn: handleMultipleRespondWith },
85 { pattern: '?used-check', fn: handleUsedCheck } 90 { pattern: '?used-check', fn: handleUsedCheck },
91 { pattern: '?headers', fn: handleHeaders }
86 ]; 92 ];
87 93
88 var handler = null; 94 var handler = null;
89 for (var i = 0; i < handlers.length; ++i) { 95 for (var i = 0; i < handlers.length; ++i) {
90 if (url.indexOf(handlers[i].pattern) != -1) { 96 if (url.indexOf(handlers[i].pattern) != -1) {
91 handler = handlers[i]; 97 handler = handlers[i];
92 break; 98 break;
93 } 99 }
94 } 100 }
95 101
96 if (handler) { 102 if (handler) {
97 handler.fn(event); 103 handler.fn(event);
98 } else { 104 } else {
99 event.respondWith(new Response(new Blob( 105 event.respondWith(new Response(new Blob(
100 ['Service Worker got an unexpected request: ' + url]))); 106 ['Service Worker got an unexpected request: ' + url])));
101 } 107 }
102 }); 108 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698