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

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/resources/fetch-event-test-worker.js

Issue 2836233002: Upstream service worker `fetch` tests to WPT (Closed)
Patch Set: Extend "-expected.txt" file with reference to new sub-test 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
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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 event.respondWith(new Response(body, { 106 event.respondWith(new Response(body, {
107 headers: { 'Content-Type': 'text/event-stream' } 107 headers: { 'Content-Type': 'text/event-stream' }
108 } 108 }
109 )); 109 ));
110 } 110 }
111 111
112 function handleIntegrity(event) { 112 function handleIntegrity(event) {
113 event.respondWith(new Response(event.request.integrity)); 113 event.respondWith(new Response(event.request.integrity));
114 } 114 }
115 115
116 function handleHeaders(event) {
117 const headers = Array.from(event.request.headers);
118 event.respondWith(new Response(JSON.stringify(headers)));
119 }
120
116 self.addEventListener('fetch', function(event) { 121 self.addEventListener('fetch', function(event) {
117 var url = event.request.url; 122 var url = event.request.url;
118 var handlers = [ 123 var handlers = [
119 { pattern: '?string', fn: handleString }, 124 { pattern: '?string', fn: handleString },
120 { pattern: '?blob', fn: handleBlob }, 125 { pattern: '?blob', fn: handleBlob },
121 { pattern: '?referrerFull', fn: handleReferrerFull }, 126 { pattern: '?referrerFull', fn: handleReferrerFull },
122 { pattern: '?referrerPolicy', fn: handleReferrerPolicy }, 127 { pattern: '?referrerPolicy', fn: handleReferrerPolicy },
123 { pattern: '?referrer', fn: handleReferrer }, 128 { pattern: '?referrer', fn: handleReferrer },
124 { pattern: '?clientId', fn: handleClientId }, 129 { pattern: '?clientId', fn: handleClientId },
125 { pattern: '?ignore', fn: function() {} }, 130 { pattern: '?ignore', fn: function() {} },
126 { pattern: '?null', fn: handleNullBody }, 131 { pattern: '?null', fn: handleNullBody },
127 { pattern: '?fetch', fn: handleFetch }, 132 { pattern: '?fetch', fn: handleFetch },
128 { pattern: '?form-post', fn: handleFormPost }, 133 { pattern: '?form-post', fn: handleFormPost },
129 { pattern: '?multiple-respond-with', fn: handleMultipleRespondWith }, 134 { pattern: '?multiple-respond-with', fn: handleMultipleRespondWith },
130 { pattern: '?used-check', fn: handleUsedCheck }, 135 { pattern: '?used-check', fn: handleUsedCheck },
131 { pattern: '?fragment-check', fn: handleFragmentCheck }, 136 { pattern: '?fragment-check', fn: handleFragmentCheck },
132 { pattern: '?cache', fn: handleCache }, 137 { pattern: '?cache', fn: handleCache },
133 { pattern: '?eventsource', fn: handleEventSource }, 138 { pattern: '?eventsource', fn: handleEventSource },
134 { pattern: '?integrity', fn: handleIntegrity }, 139 { pattern: '?integrity', fn: handleIntegrity },
140 { pattern: '?headers', fn: handleHeaders },
135 ]; 141 ];
136 142
137 var handler = null; 143 var handler = null;
138 for (var i = 0; i < handlers.length; ++i) { 144 for (var i = 0; i < handlers.length; ++i) {
139 if (url.indexOf(handlers[i].pattern) != -1) { 145 if (url.indexOf(handlers[i].pattern) != -1) {
140 handler = handlers[i]; 146 handler = handlers[i];
141 break; 147 break;
142 } 148 }
143 } 149 }
144 150
145 if (handler) { 151 if (handler) {
146 handler.fn(event); 152 handler.fn(event);
147 } else { 153 } else {
148 event.respondWith(new Response(new Blob( 154 event.respondWith(new Response(new Blob(
149 ['Service Worker got an unexpected request: ' + url]))); 155 ['Service Worker got an unexpected request: ' + url])));
150 } 156 }
151 }); 157 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698