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

Side by Side Diff: LayoutTests/http/tests/serviceworker/resources/cache-match-worker.js

Issue 704043002: [ServiceWorker] Update cache.match/matchAll tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@cleanup-formatting
Patch Set: Created 6 years, 1 month 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 | « LayoutTests/http/tests/serviceworker/cache-match-expected.txt ('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
1 importScripts('worker-testharness.js'); 1 importScripts('worker-testharness.js');
2 importScripts('/resources/testharness-helpers.js'); 2 importScripts('/resources/testharness-helpers.js');
3 3
4 // A set of Request/Response pairs to be used with prepopulated_cache_test(). 4 // A set of Request/Response pairs to be used with prepopulated_cache_test().
5 var simple_entries = { 5 var simple_entries = {
6 a: { 6 a: {
7 request: new Request('http://example.com/a'), 7 request: new Request('http://example.com/a'),
8 response: new Response('') 8 response: new Response('')
9 }, 9 },
10 10
(...skipping 20 matching lines...) Expand all
31 a_org: { 31 a_org: {
32 request: new Request('http://example.org/a'), 32 request: new Request('http://example.org/a'),
33 response: new Response('') 33 response: new Response('')
34 }, 34 },
35 35
36 cat: { 36 cat: {
37 request: new Request('http://example.com/cat'), 37 request: new Request('http://example.com/cat'),
38 response: new Response('') 38 response: new Response('')
39 }, 39 },
40 40
41 cat_with_fragment: { 41 catmandu: {
42 request: new Request('http://example.com/cat#mouse'), 42 request: new Request('http://example.com/catmandu'),
43 response: new Response('')
44 },
45
46 cat_num_lives: {
47 request: new Request('http://example.com/cat?lives=9'),
43 response: new Response('') 48 response: new Response('')
44 }, 49 },
45 50
46 cat_in_the_hat: { 51 cat_in_the_hat: {
47 request: new Request('http://example.com/cat/in/the/hat'), 52 request: new Request('http://example.com/cat/in/the/hat'),
48 response: new Response('') 53 response: new Response('')
54 },
55
56 secret_cat: {
57 request: new Request('http://tom:jerry@example.com/cat'),
58 response: new Response('')
59 },
60
61 top_secret_cat: {
62 request: new Request('http://tom:j3rry@example.com/cat'),
63 response: new Response('')
49 } 64 }
50 }; 65 };
51 66
52 // A set of Request/Response pairs to be used with prepopulated_cache_test(). 67 // A set of Request/Response pairs to be used with prepopulated_cache_test().
53 // These contain a mix of test cases that use Vary headers. 68 // These contain a mix of test cases that use Vary headers.
54 var vary_entries = { 69 var vary_entries = {
55 no_vary_header: { 70 no_vary_header: {
56 request: new Request('http://example.com/c'), 71 request: new Request('http://example.com/c'),
57 response: new Response('') 72 response: new Response('')
58 }, 73 },
(...skipping 20 matching lines...) Expand all
79 94
80 vary_wildcard: { 95 vary_wildcard: {
81 request: new Request('http://example.com/c', 96 request: new Request('http://example.com/c',
82 {headers: {'Cookies': 'x', 'X-Key': '1'}}), 97 {headers: {'Cookies': 'x', 'X-Key': '1'}}),
83 response: new Response('', 98 response: new Response('',
84 {headers: {'Vary': '*'}}) 99 {headers: {'Vary': '*'}})
85 } 100 }
86 }; 101 };
87 102
88 prepopulated_cache_test(simple_entries, function(cache) { 103 prepopulated_cache_test(simple_entries, function(cache) {
104 return cacheAll.match('not-present-in-the-cache')
jsbell 2014/11/07 01:00:56 cacheAll.match -> cache.matchAll ?
asanka 2014/11/07 18:55:40 Oops. Done.
105 .then(function(result) {
106 assert_array_equivalent(
107 result, [],
108 'Cache.matchAll should resolve with an empty array on failure.');
109 });
110 }, 'Cache.matchAll with no matching entries');
111
112 prepopulated_cache_test(simple_entries, function(cache) {
89 return cache.match('not-present-in-the-cache') 113 return cache.match('not-present-in-the-cache')
90 .then(function(result) { 114 .then(function(result) {
91 assert_equals(result, undefined, 115 assert_equals(result, undefined,
92 'Cache.match failures should resolve with undefined.'); 116 'Cache.match failures should resolve with undefined.');
93 }); 117 });
94 }, 'Cache.match failure'); 118 }, 'Cache.match with no matching entries');
95 119
96 prepopulated_cache_test(simple_entries, function(cache) { 120 prepopulated_cache_test(simple_entries, function(cache) {
97 return cache.matchAll(simple_entries.a.request.url) 121 return cache.matchAll(simple_entries.a.request.url)
98 .then(function(result) { 122 .then(function(result) {
99 assert_array_objects_equals(result, [simple_entries.a.response], 123 assert_array_objects_equals(result, [simple_entries.a.response],
100 'Cache.matchAll should match by URL.'); 124 'Cache.matchAll should match by URL.');
101 }); 125 });
102 }, 'Cache.matchAll with URL'); 126 }, 'Cache.matchAll with URL');
103 127
104 prepopulated_cache_test(simple_entries, function(cache) { 128 prepopulated_cache_test(simple_entries, function(cache) {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 simple_entries.a_with_query.response 204 simple_entries.a_with_query.response
181 ], 205 ],
182 'Cache.matchAll with ignoreSearch should ignore the ' + 206 'Cache.matchAll with ignoreSearch should ignore the ' +
183 'search parameters of cached request.'); 207 'search parameters of cached request.');
184 }); 208 });
185 }, 209 },
186 'Cache.matchAll with ignoreSearch option (request with no search ' + 210 'Cache.matchAll with ignoreSearch option (request with no search ' +
187 'parameters)'); 211 'parameters)');
188 212
189 prepopulated_cache_test(simple_entries, function(cache) { 213 prepopulated_cache_test(simple_entries, function(cache) {
214 return cache.match(simple_entries.a.request,
215 {ignoreSearch: true})
216 .then(function(result) {
217 assert_object_in_array(
218 result,
219 [
220 simple_entries.a.response,
221 simple_entries.a_with_query.response
222 ],
223 'Cache.match with ignoreSearch should ignore the ' +
224 'search parameters of cached request.');
225 });
226 },
227 'Cache.match with ignoreSearch option (request with no search ' +
228 'parameters)');
229
230 prepopulated_cache_test(simple_entries, function(cache) {
190 return cache.matchAll(simple_entries.a_with_query.request, 231 return cache.matchAll(simple_entries.a_with_query.request,
191 {ignoreSearch: true}) 232 {ignoreSearch: true})
192 .then(function(result) { 233 .then(function(result) {
193 assert_array_equivalent( 234 assert_array_equivalent(
194 result, 235 result,
195 [ 236 [
196 simple_entries.a.response, 237 simple_entries.a.response,
197 simple_entries.a_with_query.response 238 simple_entries.a_with_query.response
198 ], 239 ],
199 'Cache.matchAll with ignoreSearch should ignore the ' + 240 'Cache.matchAll with ignoreSearch should ignore the ' +
200 'search parameters of request.'); 241 'search parameters of request.');
201 }); 242 });
202 }, 243 },
203 'Cache.matchAll with ignoreSearch option (request with search parameter)'); 244 'Cache.matchAll with ignoreSearch option (request with search parameter)');
204 245
205 prepopulated_cache_test(simple_entries, function(cache) { 246 prepopulated_cache_test(simple_entries, function(cache) {
206 return cache.matchAll(simple_entries.cat.request) 247 return cache.match(simple_entries.a_with_query.request,
248 {ignoreSearch: true})
249 .then(function(result) {
250 assert_object_in_array(
251 result,
252 [
253 simple_entries.a.response,
254 simple_entries.a_with_query.response
255 ],
256 'Cache.match with ignoreSearch should ignore the ' +
257 'search parameters of request.');
258 });
259 },
260 'Cache.match with ignoreSearch option (request with search parameter)');
261
262 prepopulated_cache_test(simple_entries, function(cache) {
263 return cache.matchAll(simple_entries.cat.request.url + '#mouse')
207 .then(function(result) { 264 .then(function(result) {
208 assert_array_equivalent( 265 assert_array_equivalent(
209 result, 266 result,
210 [ 267 [
211 simple_entries.cat.response, 268 simple_entries.cat.response,
212 simple_entries.cat_with_fragment.response
213 ], 269 ],
214 'Cache.matchAll should ignore URL hash.'); 270 'Cache.matchAll should ignore URL fragment.');
215 }); 271 });
216 }, 'Cache.matchAll with request containing hash'); 272 }, 'Cache.matchAll with URL containing fragment');
273
274 prepopulated_cache_test(simple_entries, function(cache) {
275 return cache.match(simple_entries.cat.request.url + '#mouse')
276 .then(function(result) {
277 assert_object_equals(result, simple_entries.cat.response,
278 'Cache.match should ignore URL fragment.');
279 });
280 }, 'Cache.match with URL containing fragment');
217 281
218 prepopulated_cache_test(simple_entries, function(cache) { 282 prepopulated_cache_test(simple_entries, function(cache) {
219 return cache.matchAll('http') 283 return cache.matchAll('http')
220 .then(function(result) { 284 .then(function(result) {
221 assert_array_equivalent( 285 assert_array_equivalent(
222 result, [], 286 result, [],
223 'Cache.matchAll should treat query as a URL and not ' + 287 'Cache.matchAll should treat query as a URL and not ' +
224 'just a string fragment.'); 288 'just a string fragment.');
225 }); 289 });
226 }, 'Cache.matchAll with string fragment "http" as query'); 290 }, 'Cache.matchAll with string fragment "http" as query');
227 291
228 prepopulated_cache_test(simple_entries, function(cache) { 292 prepopulated_cache_test(simple_entries, function(cache) {
293 return cache.match('http')
294 .then(function(result) {
295 assert_equals(
296 result, undefined,
297 'Cache.match should treat query as a URL and not ' +
298 'just a string fragment.');
299 });
300 }, 'Cache.match with string fragment "http" as query');
301
302 prepopulated_cache_test(simple_entries, function(cache) {
229 return cache.matchAll('http://example.com/cat', 303 return cache.matchAll('http://example.com/cat',
230 {prefixMatch: true}) 304 {prefixMatch: true})
231 .then(function(result) { 305 .then(function(result) {
232 assert_array_equivalent( 306 assert_array_equivalent(
233 result, 307 result,
234 [ 308 [
235 simple_entries.cat.response, 309 simple_entries.cat.response,
236 simple_entries.cat_with_fragment.response, 310 simple_entries.catmandu.response,
311 simple_entries.cat_num_lives.response,
237 simple_entries.cat_in_the_hat.response 312 simple_entries.cat_in_the_hat.response
238 ], 313 ],
239 'Cache.matchAll should honor prefixMatch.'); 314 'Cache.matchAll should honor prefixMatch.');
240 }); 315 });
241 }, 'Cache.matchAll with prefixMatch option'); 316 }, 'Cache.matchAll with prefixMatch option');
242 317
243 prepopulated_cache_test(simple_entries, function(cache) { 318 prepopulated_cache_test(simple_entries, function(cache) {
319 return cache.match('http://example.com/cat',
320 {prefixMatch: true})
321 .then(function(result) {
322 assert_object_in_array(
323 result,
324 [
325 simple_entries.cat.response,
326 simple_entries.catmandu.response,
327 simple_entries.cat_num_lives.response,
328 simple_entries.cat_in_the_hat.response
329 ],
330 'Cache.match should honor prefixMatch.');
331 });
332 }, 'Cache.match with prefixMatch option');
333
334 prepopulated_cache_test(simple_entries, function(cache) {
244 return cache.matchAll('http://example.com/cat/', 335 return cache.matchAll('http://example.com/cat/',
245 {prefixMatch: true}) 336 {prefixMatch: true})
246 .then(function(result) { 337 .then(function(result) {
247 assert_array_equivalent( 338 assert_array_equivalent(
248 result, [simple_entries.cat_in_the_hat.response], 339 result, [simple_entries.cat_in_the_hat.response],
249 'Cache.matchAll should honor prefixMatch.'); 340 'Cache.matchAll should honor prefixMatch.');
250 }); 341 });
251 }, 'Cache.matchAll with prefixMatch option'); 342 }, 'Cache.matchAll with prefixMatch option (URL ending with path delimiter)');
343
344 prepopulated_cache_test(simple_entries, function(cache) {
345 return cache.match('http://example.com/cat/',
346 {prefixMatch: true})
347 .then(function(result) {
348 assert_object_equals(
349 result, simple_entries.cat_in_the_hat.response,
350 'Cache.match should honor prefixMatch.');
351 });
352 }, 'Cache.match with prefixMatch option (URL ending with path delimiter)');
353
354 prepopulated_cache_test(simple_entries, function(cache) {
355 return cache.matchAll('http://tom:jerry@example.com', {prefixMatch: true})
356 .then(function(result) {
357 assert_array_equivalent(
358 result,
359 [
360 simple_entries.secret_cat.response,
361 ],
362 'Cache.matchAll should honor prefixMatch.');
363 });
364 }, 'Cache.matchAll with prefixMatch option (URL with embedded credentials)');
365
366 prepopulated_cache_test(simple_entries, function(cache) {
367 return cache.match('http://tom:jerry@example.com', {prefixMatch: true})
368 .then(function(result) {
369 assert_object_equals(
370 result, simple_entries.secret_cat.response,
371 'Cache.match should honor prefixMatch.');
372 });
373 }, 'Cache.match with prefixMatch option (URL with embedded credentials)');
374
375 prepopulated_cache_test(simple_entries, function(cache) {
376 // The string 'http://tom' should be converted to a URL and then serialized
377 // yielding 'http://tom/'. The trailing slash prevents the URL from matching
378 // the embedded credentials in the entries already in the cache.
379 return cache.matchAll('http://tom', {prefixMatch: true})
380 .then(function(result) {
381 assert_array_equivalent(
382 result, [],
383 'Cache.matchAll should honor prefixMatch.');
384 });
385 },
386 'Cache.matchAll with prefixMatch option (URL matching embedded credentials)');
387
388 prepopulated_cache_test(simple_entries, function(cache) {
389 // The string 'http://tom' should be converted to a URL and then serialized
390 // yielding 'http://tom/'. The trailing slash prevents the URL from matching
391 // the embedded credentials in the entries already in the cache.
392 return cache.match('http://tom', {prefixMatch: true})
393 .then(function(result) {
394 assert_equals(result, undefined,
395 'Cache.match should honor prefixMatch.');
396 });
397 },
398 'Cache.match with prefixMatch option (URL matching embedded credentials)');
399
400 prepopulated_cache_test(simple_entries, function(cache) {
401 return cache.matchAll(simple_entries.secret_cat.request.url)
402 .then(function(result) {
403 assert_array_equivalent(
404 result, [simple_entries.secret_cat.response],
405 'Cache.matchAll should not ignore embedded credentials');
406 });
407 }, 'Cache.matchAll with URL containing credentials');
408
409 prepopulated_cache_test(simple_entries, function(cache) {
410 return cache.match(simple_entries.secret_cat.request.url)
411 .then(function(result) {
412 assert_object_equals(
413 result, simple_entries.secret_cat.response,
414 'Cache.match should not ignore embedded credentials');
415 });
416 }, 'Cache.match with URL containing credentials');
252 417
253 prepopulated_cache_test(vary_entries, function(cache) { 418 prepopulated_cache_test(vary_entries, function(cache) {
254 return cache.matchAll('http://example.com/c') 419 return cache.matchAll('http://example.com/c')
255 .then(function(result) { 420 .then(function(result) {
256 assert_array_equivalent( 421 assert_array_equivalent(
257 result, 422 result,
258 [ 423 [
259 vary_entries.no_vary_header.response, 424 vary_entries.no_vary_header.response,
260 vary_entries.vary_wildcard.response, 425 vary_entries.vary_wildcard.response,
261 vary_entries.vary_cookie_absent.response 426 vary_entries.vary_cookie_absent.response
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 return cache.put(entries[k].request, entries[k].response); 566 return cache.put(entries[k].request, entries[k].response);
402 })) 567 }))
403 .catch(function(reason) { 568 .catch(function(reason) {
404 assert_unreached('Test setup failed: ' + reason.message); 569 assert_unreached('Test setup failed: ' + reason.message);
405 }) 570 })
406 .then(function() { 571 .then(function() {
407 return test_function(cache); 572 return test_function(cache);
408 }); 573 });
409 }, description); 574 }, description);
410 } 575 }
OLDNEW
« no previous file with comments | « LayoutTests/http/tests/serviceworker/cache-match-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698