OLD | NEW |
---|---|
(Empty) | |
1 <!DOCTYPE html> | |
2 <title>Service Worker: fetch()</title> | |
3 <script src="../resources/testharness.js"></script> | |
4 <script src="../resources/testharnessreport.js"></script> | |
5 <script src="resources/test-helpers.js"></script> | |
6 <script> | |
7 var SCOPE = 'resources/fetch-access-control-iframe.html'; | |
8 var BASE_URL = 'http://127.0.0.1:8000/serviceworker/resources/fetch-access-contr ol.php?'; | |
9 var OTHER_BASE_URL = 'http://localhost:8000/serviceworker/resources/fetch-access -control.php?'; | |
10 var REDIRECT_URL = 'http://127.0.0.1:8000/serviceworker/resources/redirect.php?R edirect='; | |
11 var IFRAME_URL = 'http://127.0.0.1:8000/serviceworker/resources/fetch-access-con trol-iframe.html'; | |
12 var WORKER_URL = 'http://127.0.0.1:8000/serviceworker/resources/fetch-access-con trol-worker.js'; | |
13 | |
14 // Functions to check the result of from the ServiceWorker. | |
15 var checkFetchResult = function (expected, url, data) { | |
16 assert_equals(data.fetchResult, expected, url + ' should be ' + expected); | |
17 }; | |
18 var checkFetchResponseBody = function (hasBody, url, data) { | |
19 assert_equals(data.fetchResult, | |
20 'resolved', | |
21 'fetchResult must be resolved. url: ' + url); | |
22 assert_equals(data.hasBody, | |
23 hasBody, | |
24 'hasBody must match. url: ' + url); | |
25 }; | |
26 var checkFetchResponseHeader = function (name, expected, url, data) { | |
27 assert_equals(data.fetchResult, | |
28 'resolved', | |
29 'fetchResult must be resolved. url: ' + url); | |
30 var exist = false; | |
31 for (var i = 0; i < data.headers.length; ++i) { | |
32 if (data.headers[i][0] == name) { | |
yhirano
2014/07/23 05:17:13
Please use '===' instead of '=='.
horo
2014/07/23 09:05:52
Done.
| |
33 exist = true; | |
34 } | |
35 } | |
36 assert_equals(exist, | |
37 expected, | |
38 'header check failed url: ' + url + ' name: ' + name); | |
39 }; | |
40 var checkFetchResponseType = function (type, url, data) { | |
41 assert_equals(data.fetchResult, | |
42 'resolved', | |
43 'fetchResult must be resolved. url = ' + url); | |
44 assert_equals(data.type, | |
45 type, | |
46 'type must match. url: ' + url); | |
47 }; | |
48 var fetchResolved = checkFetchResult.bind(this, 'resolved'); | |
49 var fetchRejected = checkFetchResult.bind(this, 'rejected'); | |
50 var fetchError = checkFetchResult.bind(this, 'error'); | |
51 var hasBody = checkFetchResponseBody.bind(this, true); | |
52 var noBody = checkFetchResponseBody.bind(this, false); | |
53 var hasContentLength = | |
54 checkFetchResponseHeader.bind(this, 'content-length', true); | |
55 var noContentLength = | |
56 checkFetchResponseHeader.bind(this, 'content-length', false); | |
57 var hasServerHeader = | |
58 checkFetchResponseHeader.bind(this, 'x-serviceworker-serverheader', true); | |
59 var noServerHeader = | |
60 checkFetchResponseHeader.bind(this, 'x-serviceworker-serverheader', false); | |
61 var typeBasic = checkFetchResponseType.bind(this, 'basic'); | |
62 var typeCors = checkFetchResponseType.bind(this, 'cors'); | |
63 var typeOpaque = checkFetchResponseType.bind(this, 'opaque'); | |
64 | |
65 // Functions to check the result of JSONP which is evaluated in | |
66 // fetch-access-control-iframe.html by appending <script> element. | |
67 var checkJsonpResult = function (expected, url, data) { | |
68 assert_equals(data.jsonpResult, | |
69 expected, | |
70 url + ' jsonpResult should match'); | |
71 }; | |
72 var checkJsonpHeader = function (name, value, url, data) { | |
73 assert_equals(data.jsonpResult, | |
74 'success', | |
75 url + ' jsonpResult must be success'); | |
76 assert_equals(data.headers[name], | |
77 value, | |
78 'Request header check failed url:' + url + ' name:' + name); | |
79 }; | |
80 var checkJsonpMethod = function (method, url, data) { | |
81 assert_equals(data.jsonpResult, | |
82 'success', | |
83 url + ' jsonpResult must be success'); | |
84 assert_equals(data.method, | |
85 method, | |
86 'Method must match url:' + url); | |
87 }; | |
88 var checkJsonpAuth = function (username, password, url, data) { | |
89 assert_equals(data.jsonpResult, | |
90 'success', | |
91 url + ' jsonpResult must be success'); | |
92 assert_equals(data.username, | |
93 username, | |
94 'Username must match. url: ' + url); | |
95 assert_equals(data.password, | |
96 password, | |
97 'Password must match. url: ' + url); | |
98 }; | |
99 var checkJsonpError = checkJsonpResult.bind(this, 'error'); | |
100 var checkJsonpSuccess = checkJsonpResult.bind(this, 'success'); | |
101 var hasCustomHeader = | |
102 checkJsonpHeader.bind(this, 'x-serviceworker-test', 'test'); | |
103 var noCustomHeader = | |
104 checkJsonpHeader.bind(this, 'x-serviceworker-test', undefined); | |
105 var methodIsGET = checkJsonpMethod.bind(this, 'GET'); | |
106 var methodIsPOST = checkJsonpMethod.bind(this, 'POST'); | |
107 var methodIsPUT = checkJsonpMethod.bind(this, 'PUT'); | |
108 var methodIsXXX = checkJsonpMethod.bind(this, 'XXX'); | |
109 var authCheck1 = checkJsonpAuth.bind(this, 'username1', 'password1'); | |
110 var authCheck2 = checkJsonpAuth.bind(this, 'username2', 'password2'); | |
111 | |
112 var TEST_TARGETS = [ | |
113 [BASE_URL + 'method=GET', | |
114 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], | |
115 [methodIsGET]], | |
116 [BASE_URL + 'method=GET&headers={}', | |
117 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], | |
118 [methodIsGET]], | |
119 [BASE_URL + 'method=GET&headers=CUSTOM', | |
120 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], | |
121 [methodIsGET, noCustomHeader]], | |
122 [BASE_URL + 'method=POST&headers=CUSTOM', | |
123 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], | |
124 [methodIsPOST, noCustomHeader]], | |
125 [BASE_URL + 'method=PUT', | |
126 [fetchError]], | |
127 [BASE_URL + 'method=XXX', | |
128 [fetchError]], | |
129 | |
130 [BASE_URL + 'mode=same-origin&method=GET', | |
131 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], | |
132 [methodIsGET]], | |
133 [BASE_URL + 'mode=same-origin&method=GET&headers={}', | |
134 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], | |
135 [methodIsGET]], | |
136 [BASE_URL + 'mode=same-origin&method=GET&headers=CUSTOM', | |
137 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], | |
138 [methodIsGET, hasCustomHeader]], | |
139 [BASE_URL + 'mode=same-origin&method=POST&headers=CUSTOM', | |
140 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], | |
141 [methodIsPOST, hasCustomHeader]], | |
142 [BASE_URL + 'mode=same-origin&method=PUT&headers=CUSTOM', | |
143 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], | |
144 [methodIsPUT, hasCustomHeader]], | |
145 [BASE_URL + 'mode=same-origin&method=XXX&headers=CUSTOM', | |
146 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], | |
147 [methodIsXXX, hasCustomHeader]], | |
148 | |
149 [BASE_URL + 'mode=no-cors&method=GET', | |
150 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], | |
151 [methodIsGET]], | |
152 [BASE_URL + 'mode=no-cors&method=GET&headers={}', | |
153 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], | |
154 [methodIsGET]], | |
155 [BASE_URL + 'mode=no-cors&method=GET&headers=CUSTOM', | |
156 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], | |
157 [methodIsGET, noCustomHeader]], | |
158 [BASE_URL + 'mode=no-cors&method=POST&headers=CUSTOM', | |
159 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], | |
160 [methodIsPOST, noCustomHeader]], | |
161 [BASE_URL + 'mode=no-cors&method=PUT', | |
162 [fetchError]], | |
163 [BASE_URL + 'mode=no-cors&method=XXX', | |
164 [fetchError]], | |
165 | |
166 [BASE_URL + 'mode=cors&method=GET', | |
167 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], | |
168 [methodIsGET]], | |
169 [BASE_URL + 'mode=cors&method=GET&headers={}', | |
170 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], | |
171 [methodIsGET]], | |
172 [BASE_URL + 'mode=cors&method=GET&headers=CUSTOM', | |
173 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], | |
174 [methodIsGET, hasCustomHeader]], | |
175 [BASE_URL + 'mode=cors&method=POST&headers=CUSTOM', | |
176 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], | |
177 [methodIsPOST, hasCustomHeader]], | |
178 [BASE_URL + 'mode=cors&method=PUT&headers=CUSTOM', | |
179 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], | |
180 [methodIsPUT, hasCustomHeader]], | |
181 [BASE_URL + 'mode=cors&method=XXX&headers=CUSTOM', | |
182 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], | |
183 [methodIsXXX, hasCustomHeader]], | |
184 | |
185 // CORS test | |
186 [OTHER_BASE_URL + 'method=GET&headers=CUSTOM', | |
187 [fetchResolved, noContentLength, noServerHeader, noBody, typeOpaque], | |
188 [methodIsGET, noCustomHeader]], | |
189 [OTHER_BASE_URL + 'method=POST&headers=CUSTOM', | |
190 [fetchResolved, noContentLength, noServerHeader, noBody, typeOpaque], | |
191 [methodIsPOST, noCustomHeader]], | |
192 [OTHER_BASE_URL + 'method=PUT&headers=CUSTOM', | |
193 [fetchError]], | |
194 [OTHER_BASE_URL + 'method=XXX&headers=CUSTOM', | |
195 [fetchError]], | |
196 | |
197 [OTHER_BASE_URL + 'mode=same-origin&method=GET', [fetchRejected]], | |
198 [OTHER_BASE_URL + 'mode=same-origin&method=POST', [fetchRejected]], | |
199 [OTHER_BASE_URL + 'mode=same-origin&method=PUT', [fetchRejected]], | |
200 [OTHER_BASE_URL + 'mode=same-origin&method=XXX', [fetchRejected]], | |
201 | |
202 [OTHER_BASE_URL + 'mode=no-cors&method=GET&headers=CUSTOM', | |
203 [fetchResolved, noContentLength, noServerHeader, noBody, typeOpaque], | |
204 [methodIsGET, noCustomHeader]], | |
205 [OTHER_BASE_URL + 'mode=no-cors&method=POST&headers=CUSTOM', | |
206 [fetchResolved, noContentLength, noServerHeader, noBody, typeOpaque], | |
207 [methodIsPOST, noCustomHeader]], | |
208 [OTHER_BASE_URL + 'mode=no-cors&method=PUT&headers=CUSTOM', | |
209 [fetchError]], | |
210 [OTHER_BASE_URL + 'mode=no-cors&method=XXX&headers=CUSTOM', | |
211 [fetchError]], | |
212 | |
213 [OTHER_BASE_URL + 'mode=cors&method=GET', | |
214 [fetchRejected]], | |
215 [OTHER_BASE_URL + 'mode=cors&method=GET&ACAOrigin=*', | |
216 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
217 [methodIsGET]], | |
218 [OTHER_BASE_URL + 'mode=cors&method=GET&ACAOrigin=http://127.0.0.1:8000', | |
219 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
220 [methodIsGET]], | |
221 [OTHER_BASE_URL + 'mode=cors&method=GET&ACAOrigin=http://127.0.0.1:8000,http ://www.example.com', | |
222 [fetchRejected]], | |
223 [OTHER_BASE_URL + 'mode=cors&method=GET&ACAOrigin=http://www.example.com', | |
224 [fetchRejected]], | |
225 [OTHER_BASE_URL + 'mode=cors&method=GET&ACAOrigin=*&ACEHeaders=X-ServiceWork er-ServerHeader', | |
226 [fetchResolved, noContentLength, hasServerHeader, hasBody, typeCors], | |
227 [methodIsGET]], | |
228 [OTHER_BASE_URL + 'mode=cors&method=GET&ACAOrigin=http://127.0.0.1:8000&ACEH eaders=X-ServiceWorker-ServerHeader', | |
229 [fetchResolved, noContentLength, hasServerHeader, hasBody, typeCors], | |
230 [methodIsGET]], | |
231 [OTHER_BASE_URL + 'mode=cors&method=GET&ACAOrigin=*&ACEHeaders=Content-Lengt h, X-ServiceWorker-ServerHeader', | |
232 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], | |
233 [methodIsGET]], | |
234 [OTHER_BASE_URL + 'mode=cors&method=GET&ACAOrigin=http://127.0.0.1:8000&ACEH eaders=Content-Length, X-ServiceWorker-ServerHeader', | |
235 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], | |
236 [methodIsGET]], | |
237 [OTHER_BASE_URL + 'mode=cors&method=GET&headers=CUSTOM', | |
238 [fetchRejected]], | |
239 [OTHER_BASE_URL + 'mode=cors&method=GET&headers=CUSTOM&ACAOrigin=*', | |
240 [fetchRejected]], | |
241 [OTHER_BASE_URL + 'mode=cors&method=GET&headers=CUSTOM&ACAOrigin=http://127. 0.0.1:8000', | |
242 [fetchRejected]], | |
243 [OTHER_BASE_URL + 'mode=cors&method=GET&headers=CUSTOM&ACAOrigin=*&ACAHeader s=x-serviceworker-test', | |
244 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
245 [methodIsGET, hasCustomHeader]], | |
246 [OTHER_BASE_URL + 'mode=cors&method=GET&headers=CUSTOM&ACAOrigin=http://127. 0.0.1:8000&ACAHeaders=x-serviceworker-test', | |
247 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
248 [methodIsGET, hasCustomHeader]], | |
249 [OTHER_BASE_URL + 'mode=cors&method=GET&headers=CUSTOM&ACAOrigin=*&ACAHeader s=x-serviceworker-test&ACEHeaders=Content-Length, X-ServiceWorker-ServerHeader', | |
250 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], | |
251 [methodIsGET, hasCustomHeader]], | |
252 [OTHER_BASE_URL + 'mode=cors&method=GET&headers=CUSTOM&ACAOrigin=http://127. 0.0.1:8000&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Length, X-ServiceW orker-ServerHeader', | |
253 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], | |
254 [methodIsGET, hasCustomHeader]], | |
255 | |
256 [OTHER_BASE_URL + 'mode=cors&method=POST', | |
257 [fetchRejected]], | |
258 [OTHER_BASE_URL + 'mode=cors&method=POST&ACAOrigin=*', | |
259 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
260 [methodIsPOST]], | |
261 [OTHER_BASE_URL + 'mode=cors&method=POST&ACAOrigin=http://127.0.0.1:8000', | |
262 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
263 [methodIsPOST]], | |
264 [OTHER_BASE_URL + 'mode=cors&method=POST&ACAOrigin=http://127.0.0.1:8000,htt p://www.example.com', | |
265 [fetchRejected]], | |
266 [OTHER_BASE_URL + 'mode=cors&method=POST&ACAOrigin=http://www.example.com', | |
267 [fetchRejected]], | |
268 [OTHER_BASE_URL + 'mode=cors&method=POST&ACAOrigin=*&ACEHeaders=X-ServiceWor ker-ServerHeader', | |
269 [fetchResolved, noContentLength, hasServerHeader, hasBody, typeCors], | |
270 [methodIsPOST]], | |
271 [OTHER_BASE_URL + 'mode=cors&method=POST&ACAOrigin=http://127.0.0.1:8000&ACE Headers=X-ServiceWorker-ServerHeader', | |
272 [fetchResolved, noContentLength, hasServerHeader, hasBody, typeCors], | |
273 [methodIsPOST]], | |
274 [OTHER_BASE_URL + 'mode=cors&method=POST&ACAOrigin=*&ACEHeaders=Content-Leng th, X-ServiceWorker-ServerHeader', | |
275 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], | |
276 [methodIsPOST]], | |
277 [OTHER_BASE_URL + 'mode=cors&method=POST&ACAOrigin=http://127.0.0.1:8000&ACE Headers=Content-Length, X-ServiceWorker-ServerHeader', | |
278 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], | |
279 [methodIsPOST]], | |
280 [OTHER_BASE_URL + 'mode=cors&method=POST&headers=CUSTOM', | |
281 [fetchRejected]], | |
282 [OTHER_BASE_URL + 'mode=cors&method=POST&headers=CUSTOM&ACAOrigin=*', | |
283 [fetchRejected]], | |
284 [OTHER_BASE_URL + 'mode=cors&method=POST&headers=CUSTOM&ACAOrigin=*&ACAHeade rs=x-serviceworker-test', | |
285 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
286 [methodIsPOST, hasCustomHeader]], | |
287 [OTHER_BASE_URL + 'mode=cors&method=POST&headers=CUSTOM&ACAOrigin=*&ACAHeade rs=x-serviceworker-test&ACEHeaders=Content-Length, X-ServiceWorker-ServerHeader' , | |
288 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], | |
289 [methodIsPOST, hasCustomHeader]], | |
290 [OTHER_BASE_URL + 'mode=cors&method=POST&headers=CUSTOM&ACAOrigin=http://127 .0.0.1:8000', | |
291 [fetchRejected]], | |
292 [OTHER_BASE_URL + 'mode=cors&method=POST&headers=CUSTOM&ACAOrigin=http://127 .0.0.1:8000&ACAHeaders=x-serviceworker-test', | |
293 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
294 [methodIsPOST, hasCustomHeader]], | |
295 [OTHER_BASE_URL + 'mode=cors&method=POST&headers=CUSTOM&ACAOrigin=http://127 .0.0.1:8000&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Length, X-Service Worker-ServerHeader', | |
296 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], | |
297 [methodIsPOST, hasCustomHeader]], | |
298 | |
299 [OTHER_BASE_URL + 'mode=cors&method=PUT', | |
300 [fetchRejected]], | |
301 [OTHER_BASE_URL + 'mode=cors&method=PUT&ACAMethods=PUT', | |
302 [fetchRejected]], | |
303 [OTHER_BASE_URL + 'mode=cors&method=PUT&ACAOrigin=*', | |
304 [fetchRejected]], | |
305 [OTHER_BASE_URL + 'mode=cors&method=PUT&ACAOrigin=*&ACAMethods=PUT', | |
306 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
307 [methodIsPUT]], | |
308 [OTHER_BASE_URL + 'mode=cors&method=PUT&ACAOrigin=*&headers=CUSTOM&ACAMethod s=PUT', | |
309 [fetchRejected]], | |
310 [OTHER_BASE_URL + 'mode=cors&method=PUT&ACAOrigin=*&headers=CUSTOM&ACAMethod s=PUT&ACAHeaders=x-serviceworker-test', | |
311 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
312 [methodIsPUT, hasCustomHeader]], | |
313 [OTHER_BASE_URL + 'mode=cors&method=PUT&ACAOrigin=*&headers=CUSTOM&ACAMethod s=PUT&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Length, X-ServiceWorker -ServerHeader', | |
314 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], | |
315 [methodIsPUT, hasCustomHeader]], | |
316 [OTHER_BASE_URL + 'mode=cors&method=PUT&ACAOrigin=*&headers=CUSTOM&ACAMethod s=PUT, XXX', | |
317 [fetchRejected]], | |
318 [OTHER_BASE_URL + 'mode=cors&method=PUT&ACAOrigin=*&headers=CUSTOM&ACAMethod s=PUT, XXX&ACAHeaders=x-serviceworker-test', | |
319 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
320 [methodIsPUT, hasCustomHeader]], | |
321 [OTHER_BASE_URL + 'mode=cors&method=PUT&ACAOrigin=*&headers=CUSTOM&ACAMethod s=PUT, XXX&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Length, X-ServiceW orker-ServerHeader', | |
322 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], | |
323 [methodIsPUT, hasCustomHeader]], | |
324 [OTHER_BASE_URL + 'mode=cors&method=PUT&ACAOrigin=http://127.0.0.1:8000', | |
325 [fetchRejected]], | |
326 [OTHER_BASE_URL + 'mode=cors&method=PUT&ACAOrigin=http://127.0.0.1:8000&ACAM ethods=PUT', | |
327 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
328 [methodIsPUT]], | |
329 [OTHER_BASE_URL + 'mode=cors&method=PUT&ACAOrigin=http://127.0.0.1:8000&head ers=CUSTOM&ACAMethods=PUT', | |
330 [fetchRejected]], | |
331 [OTHER_BASE_URL + 'mode=cors&method=PUT&ACAOrigin=http://127.0.0.1:8000&head ers=CUSTOM&ACAMethods=PUT&ACAHeaders=x-serviceworker-test', | |
332 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
333 [methodIsPUT, hasCustomHeader]], | |
334 [OTHER_BASE_URL + 'mode=cors&method=PUT&ACAOrigin=http://127.0.0.1:8000&head ers=CUSTOM&ACAMethods=PUT&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Len gth, X-ServiceWorker-ServerHeader', | |
335 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], | |
336 [methodIsPUT, hasCustomHeader]], | |
337 [OTHER_BASE_URL + 'mode=cors&method=PUT&ACAOrigin=http://127.0.0.1:8000&head ers=CUSTOM&ACAMethods=PUT, XXX', | |
338 [fetchRejected]], | |
339 [OTHER_BASE_URL + 'mode=cors&method=PUT&ACAOrigin=http://127.0.0.1:8000&head ers=CUSTOM&ACAMethods=PUT, XXX&ACAHeaders=x-serviceworker-test', | |
340 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
341 [methodIsPUT, hasCustomHeader]], | |
342 [OTHER_BASE_URL + 'mode=cors&method=PUT&ACAOrigin=http://127.0.0.1:8000&head ers=CUSTOM&ACAMethods=PUT, XXX&ACAHeaders=x-serviceworker-test&ACEHeaders=Conten t-Length, X-ServiceWorker-ServerHeader', | |
343 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], | |
344 [methodIsPUT, hasCustomHeader]], | |
345 | |
346 [OTHER_BASE_URL + 'mode=cors&method=XXX', | |
347 [fetchRejected]], | |
348 [OTHER_BASE_URL + 'mode=cors&method=XXX&ACAMethods=XXX', | |
349 [fetchRejected]], | |
350 [OTHER_BASE_URL + 'mode=cors&method=XXX&ACAOrigin=*', | |
351 [fetchRejected]], | |
352 [OTHER_BASE_URL + 'mode=cors&method=XXX&ACAOrigin=*&ACAMethods=XXX', | |
353 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
354 [methodIsXXX]], | |
355 [OTHER_BASE_URL + 'mode=cors&method=XXX&ACAOrigin=*&headers=CUSTOM&ACAMethod s=XXX', | |
356 [fetchRejected]], | |
357 [OTHER_BASE_URL + 'mode=cors&method=XXX&ACAOrigin=*&headers=CUSTOM&ACAMethod s=XXX&ACAHeaders=x-serviceworker-test', | |
358 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
359 [methodIsXXX, hasCustomHeader]], | |
360 [OTHER_BASE_URL + 'mode=cors&method=XXX&ACAOrigin=*&headers=CUSTOM&ACAMethod s=XXX&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Length, X-ServiceWorker -ServerHeader', | |
361 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], | |
362 [methodIsXXX, hasCustomHeader]], | |
363 [OTHER_BASE_URL + 'mode=cors&method=XXX&ACAOrigin=*&headers=CUSTOM&ACAMethod s=PUT, XXX', | |
364 [fetchRejected]], | |
365 [OTHER_BASE_URL + 'mode=cors&method=XXX&ACAOrigin=*&headers=CUSTOM&ACAMethod s=PUT, XXX&ACAHeaders=x-serviceworker-test', | |
366 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
367 [methodIsXXX, hasCustomHeader]], | |
368 [OTHER_BASE_URL + 'mode=cors&method=XXX&ACAOrigin=*&headers=CUSTOM&ACAMethod s=PUT, XXX&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Length, X-ServiceW orker-ServerHeader', | |
369 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], | |
370 [methodIsXXX, hasCustomHeader]], | |
371 [OTHER_BASE_URL + 'mode=cors&method=XXX&ACAOrigin=http://127.0.0.1:8000', | |
372 [fetchRejected]], | |
373 [OTHER_BASE_URL + 'mode=cors&method=XXX&ACAOrigin=http://127.0.0.1:8000&ACAM ethods=XXX', | |
374 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
375 [methodIsXXX]], | |
376 [OTHER_BASE_URL + 'mode=cors&method=XXX&ACAOrigin=http://127.0.0.1:8000&head ers=CUSTOM&ACAMethods=XXX', | |
377 [fetchRejected]], | |
378 [OTHER_BASE_URL + 'mode=cors&method=XXX&ACAOrigin=http://127.0.0.1:8000&head ers=CUSTOM&ACAMethods=XXX&ACAHeaders=x-serviceworker-test', | |
379 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
380 [methodIsXXX, hasCustomHeader]], | |
381 [OTHER_BASE_URL + 'mode=cors&method=XXX&ACAOrigin=http://127.0.0.1:8000&head ers=CUSTOM&ACAMethods=XXX&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Len gth, X-ServiceWorker-ServerHeader', | |
382 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], | |
383 [methodIsXXX, hasCustomHeader]], | |
384 [OTHER_BASE_URL + 'mode=cors&method=XXX&ACAOrigin=http://127.0.0.1:8000&head ers=CUSTOM&ACAMethods=PUT, XXX', | |
385 [fetchRejected]], | |
386 [OTHER_BASE_URL + 'mode=cors&method=XXX&ACAOrigin=http://127.0.0.1:8000&head ers=CUSTOM&ACAMethods=PUT, XXX&ACAHeaders=x-serviceworker-test', | |
387 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
388 [methodIsXXX, hasCustomHeader]], | |
389 [OTHER_BASE_URL + 'mode=cors&method=XXX&ACAOrigin=http://127.0.0.1:8000&head ers=CUSTOM&ACAMethods=PUT, XXX&ACAHeaders=x-serviceworker-test&ACEHeaders=Conten t-Length, X-ServiceWorker-ServerHeader', | |
390 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], | |
391 [methodIsXXX, hasCustomHeader]], | |
392 | |
393 // Referer check | |
394 [BASE_URL + 'ignore=true', | |
395 [], | |
396 [checkJsonpHeader.bind(this, 'Referer', IFRAME_URL)]], | |
397 [BASE_URL + 'noChange=true', | |
398 [fetchResolved], | |
399 [checkJsonpHeader.bind(this, 'Referer', WORKER_URL)]], | |
400 [BASE_URL , | |
401 [fetchResolved], | |
402 [checkJsonpHeader.bind(this, 'Referer', WORKER_URL)]], | |
403 | |
404 // Auth check | |
405 [BASE_URL + 'Auth', | |
406 [fetchResolved, hasBody], [checkJsonpError]], | |
407 [BASE_URL + 'Auth&credentials=ommit', | |
408 [fetchResolved, hasBody], [checkJsonpError]], | |
409 [BASE_URL + 'Auth&credentials=include', | |
410 [fetchResolved, hasBody], [authCheck1]], | |
411 [BASE_URL + 'Auth&credentials=same-origin', | |
412 [fetchResolved, hasBody], [authCheck1]], | |
413 | |
414 [BASE_URL + 'Auth&mode=no-cors&credentials=ommit', | |
415 [fetchResolved, hasBody], [checkJsonpError]], | |
416 [BASE_URL + 'Auth&mode=no-cors&credentials=include', | |
417 [fetchResolved, hasBody], [authCheck1]], | |
418 [BASE_URL + 'Auth&mode=no-cors&credentials=same-origin', | |
419 [fetchResolved, hasBody], [authCheck1]], | |
420 | |
421 [BASE_URL + 'Auth&mode=same-origin&credentials=ommit', | |
422 [fetchResolved, hasBody], [checkJsonpError]], | |
423 [BASE_URL + 'Auth&mode=same-origin&credentials=include', | |
424 [fetchResolved, hasBody], [authCheck1]], | |
425 [BASE_URL + 'Auth&mode=same-origin&credentials=same-origin', | |
426 [fetchResolved, hasBody], [authCheck1]], | |
427 | |
428 [BASE_URL + 'Auth&mode=cors&credentials=ommit', | |
429 [fetchResolved, hasBody], [checkJsonpError]], | |
430 [BASE_URL + 'Auth&mode=cors&credentials=include', | |
431 [fetchResolved, hasBody], [authCheck1]], | |
432 [BASE_URL + 'Auth&mode=cors&credentials=same-origin', | |
433 [fetchResolved, hasBody], [authCheck1]], | |
434 | |
435 [OTHER_BASE_URL + 'Auth', | |
436 [fetchResolved, noBody], [checkJsonpError]], | |
437 [OTHER_BASE_URL + 'Auth&credentials=ommit', | |
438 [fetchResolved, noBody], [checkJsonpError]], | |
439 [OTHER_BASE_URL + 'Auth&credentials=include', | |
440 [fetchResolved, noBody], [authCheck2]], | |
441 [OTHER_BASE_URL + 'Auth&credentials=same-origin', | |
442 [fetchResolved, noBody], [authCheck2]], | |
443 | |
444 [OTHER_BASE_URL + 'Auth&mode=no-cors&credentials=ommit', | |
445 [fetchResolved, noBody], [checkJsonpError]], | |
446 [OTHER_BASE_URL + 'Auth&mode=no-cors&credentials=include', | |
447 [fetchResolved, noBody], [authCheck2]], | |
448 [OTHER_BASE_URL + 'Auth&mode=no-cors&credentials=same-origin', | |
449 [fetchResolved, noBody], [authCheck2]], | |
450 | |
451 [OTHER_BASE_URL + 'Auth&mode=same-origin&credentials=ommit', | |
452 [fetchRejected]], | |
453 [OTHER_BASE_URL + 'Auth&mode=same-origin&credentials=include', | |
454 [fetchRejected]], | |
455 [OTHER_BASE_URL + 'Auth&mode=same-origin&credentials=same-origin', | |
456 [fetchRejected]], | |
457 | |
458 [OTHER_BASE_URL + 'Auth&mode=cors&credentials=ommit', | |
459 [fetchRejected]], | |
460 [OTHER_BASE_URL + 'Auth&mode=cors&credentials=include', | |
461 [fetchRejected]], | |
462 [OTHER_BASE_URL + 'Auth&mode=cors&credentials=same-origin', | |
463 [fetchRejected]], | |
464 [OTHER_BASE_URL + 'Auth&mode=cors&credentials=include&ACAOrigin=*', | |
465 [fetchRejected]], | |
466 [OTHER_BASE_URL + 'Auth&mode=cors&credentials=include&ACAOrigin=http://127.0 .0.1:8000', | |
467 [fetchRejected]], | |
468 [OTHER_BASE_URL + 'Auth&mode=cors&credentials=include&ACAOrigin=*&ACACredent ials=true', | |
469 [fetchRejected]], | |
470 [OTHER_BASE_URL + 'Auth&mode=cors&credentials=include&ACAOrigin=http://127.0 .0.1:8000&ACACredentials=true', | |
471 [fetchResolved, hasBody], [authCheck2]], | |
472 | |
473 // Redirect | |
474 // FIXME: Currently we don't support redirect in Fech() API. | |
475 [REDIRECT_URL + encodeURIComponent(BASE_URL), | |
476 [fetchRejected]], | |
477 [REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL), | |
478 [fetchRejected]] | |
479 ]; | |
480 | |
481 var test = async_test('Verify access control of fetch() in a Service Worker'); | |
482 test.step(function() { | |
483 var frameWindow = {}; | |
484 var counter = 0; | |
485 window.addEventListener('message', test.step_func(onMessage), false); | |
486 service_worker_unregister_and_register( | |
487 test, | |
488 'resources/fetch-access-control-worker.js', | |
489 SCOPE) | |
490 .then(test.step_func(onRegister)); | |
491 | |
492 function onRegister(worker) { | |
493 worker.addEventListener('statechange', test.step_func(onStateChange)); | |
494 var messageChannel = new MessageChannel(); | |
495 messageChannel.port1.onmessage = test.step_func(onWorkerMessage); | |
496 worker.postMessage( | |
497 {port: messageChannel.port2}, [messageChannel.port2]); | |
498 } | |
499 function onStateChange(event) { | |
500 if (event.target.state != 'activated') | |
yhirano
2014/07/23 05:17:13
Please use '!==' instead of '!='.
horo
2014/07/23 09:05:52
Done.
| |
501 return; | |
502 with_iframe('resources/fetch-access-control-iframe.html') | |
503 .then(function(frame) { | |
504 frameWindow = frame.contentWindow; | |
505 login1(); | |
506 }); | |
507 } | |
508 function login1() { | |
509 // Set authentication info of http://127.0.0.1:8000 | |
510 // (username1/password1) | |
511 var xhr = new XMLHttpRequest(); | |
512 xhr.addEventListener('load', test.step_func(login2), false); | |
513 xhr.open('GET', | |
514 'http://127.0.0.1:8000/serviceworker/resources/fetch-access-con trol.php?Auth', | |
515 true, 'username1', 'password1'); | |
516 xhr.send(); | |
517 } | |
518 function login2() { | |
519 // Set authentication info of http://localhost:8000 | |
520 // (username2/password2) | |
521 with_iframe('http://localhost:8000/serviceworker/resources/fetch-access- control-login.html') | |
522 } | |
523 function onMessage(e) { | |
524 if (e.origin == 'http://localhost:8000' && | |
525 e.data.msg == 'LOGIN FINISHED') { | |
526 // The message is sent from fetch-access-control-login.html. | |
527 // Start testing. | |
528 loadNext(); | |
529 return; | |
530 } | |
531 // The message is sent from fetch-access-control-iframe.html. | |
yhirano
2014/07/23 05:17:13
Sorry I don't understand when we reach here. Can y
horo
2014/07/23 09:05:52
Done.
Added comment.
| |
532 var message = e.data; | |
533 if (TEST_TARGETS[counter][2]) { | |
534 TEST_TARGETS[counter][2].forEach(function(checkFunc){ | |
yhirano
2014/07/23 05:17:13
space before '{'
horo
2014/07/23 09:05:52
Done.
| |
535 checkFunc.call(this, TEST_TARGETS[counter][0], message); | |
536 }); | |
537 } | |
538 ++counter; | |
539 if (counter == TEST_TARGETS.length) { | |
540 service_worker_unregister_and_done(test, SCOPE); | |
541 } else { | |
542 loadNext(); | |
543 } | |
544 } | |
545 function onWorkerMessage(e) { | |
yhirano
2014/07/23 05:17:13
What happens if onWorkerMessage is called after th
horo
2014/07/23 09:05:52
Introduced 2 counters(iframeMessageCounter and wor
yhirano
2014/07/24 04:07:38
Managing two counters manually is hard to understa
horo
2014/07/24 06:42:49
Done.
| |
546 // The message is sent from the ServiceWorker. | |
547 var message = e.data; | |
548 if (message.fetchResult == "resolved" && | |
549 message.originalURL != TEST_TARGETS[counter][0]) { | |
550 // Ignores redirected fetch. | |
551 return; | |
552 } | |
553 TEST_TARGETS[counter][1].forEach(function(checkFunc){ | |
yhirano
2014/07/23 05:17:13
space before '{'
horo
2014/07/23 09:05:52
Done.
| |
554 checkFunc.call(this, TEST_TARGETS[counter][0], message); | |
555 }); | |
556 } | |
557 function loadNext() { | |
558 frameWindow.postMessage( | |
559 {url: TEST_TARGETS[counter][0]}, | |
560 IFRAME_URL); | |
yhirano
2014/07/23 05:17:13
Shouldn't this be an origin, not a URL?
horo
2014/07/23 09:05:52
Done.
| |
561 } | |
562 }); | |
563 </script> | |
OLD | NEW |