| OLD | NEW |
| 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 { |
| 7 name: 'a', |
| 7 request: new Request('http://example.com/a'), | 8 request: new Request('http://example.com/a'), |
| 8 response: new Response('') | 9 response: new Response('') |
| 9 }, | 10 }, |
| 10 | 11 |
| 11 b: { | 12 { |
| 13 name: 'b', |
| 12 request: new Request('http://example.com/b'), | 14 request: new Request('http://example.com/b'), |
| 13 response: new Response('') | 15 response: new Response('') |
| 14 }, | 16 }, |
| 15 | 17 |
| 16 a_with_query: { | 18 { |
| 19 name: 'a_with_query', |
| 17 request: new Request('http://example.com/a?q=r'), | 20 request: new Request('http://example.com/a?q=r'), |
| 18 response: new Response('') | 21 response: new Response('') |
| 19 }, | 22 }, |
| 20 | 23 |
| 21 A: { | 24 { |
| 25 name: 'A', |
| 22 request: new Request('http://example.com/A'), | 26 request: new Request('http://example.com/A'), |
| 23 response: new Response('') | 27 response: new Response('') |
| 24 }, | 28 }, |
| 25 | 29 |
| 26 a_https: { | 30 { |
| 31 name: 'a_https', |
| 27 request: new Request('https://example.com/a'), | 32 request: new Request('https://example.com/a'), |
| 28 response: new Response('') | 33 response: new Response('') |
| 29 }, | 34 }, |
| 30 | 35 |
| 31 a_org: { | 36 { |
| 37 name: 'a_org', |
| 32 request: new Request('http://example.org/a'), | 38 request: new Request('http://example.org/a'), |
| 33 response: new Response('') | 39 response: new Response('') |
| 34 }, | 40 }, |
| 35 | 41 |
| 36 cat: { | 42 { |
| 43 name: 'cat', |
| 37 request: new Request('http://example.com/cat'), | 44 request: new Request('http://example.com/cat'), |
| 38 response: new Response('') | 45 response: new Response('') |
| 39 }, | 46 }, |
| 40 | 47 |
| 41 catmandu: { | 48 { |
| 49 name: 'catmandu', |
| 42 request: new Request('http://example.com/catmandu'), | 50 request: new Request('http://example.com/catmandu'), |
| 43 response: new Response('') | 51 response: new Response('') |
| 44 }, | 52 }, |
| 45 | 53 |
| 46 cat_num_lives: { | 54 { |
| 55 name: 'cat_num_lives', |
| 47 request: new Request('http://example.com/cat?lives=9'), | 56 request: new Request('http://example.com/cat?lives=9'), |
| 48 response: new Response('') | 57 response: new Response('') |
| 49 }, | 58 }, |
| 50 | 59 |
| 51 cat_in_the_hat: { | 60 { |
| 61 name: 'cat_in_the_hat', |
| 52 request: new Request('http://example.com/cat/in/the/hat'), | 62 request: new Request('http://example.com/cat/in/the/hat'), |
| 53 response: new Response('') | 63 response: new Response('') |
| 54 }, | 64 }, |
| 55 | 65 |
| 56 secret_cat: { | 66 { |
| 67 name: 'secret_cat', |
| 57 request: new Request('http://tom:jerry@example.com/cat'), | 68 request: new Request('http://tom:jerry@example.com/cat'), |
| 58 response: new Response('') | 69 response: new Response('') |
| 59 }, | 70 }, |
| 60 | 71 |
| 61 top_secret_cat: { | 72 { |
| 73 name: 'top_secret_cat', |
| 62 request: new Request('http://tom:j3rry@example.com/cat'), | 74 request: new Request('http://tom:j3rry@example.com/cat'), |
| 63 response: new Response('') | 75 response: new Response('') |
| 64 } | 76 } |
| 65 }; | 77 ]; |
| 66 | 78 |
| 67 // A set of Request/Response pairs to be used with prepopulated_cache_test(). | 79 // A set of Request/Response pairs to be used with prepopulated_cache_test(). |
| 68 // These contain a mix of test cases that use Vary headers. | 80 // These contain a mix of test cases that use Vary headers. |
| 69 var vary_entries = { | 81 var vary_entries = [ |
| 70 no_vary_header: { | 82 { |
| 71 request: new Request('http://example.com/c'), | 83 name: 'vary_cookie_is_cookie', |
| 72 response: new Response('') | |
| 73 }, | |
| 74 | |
| 75 vary_cookie_is_cookie: { | |
| 76 request: new Request('http://example.com/c', | 84 request: new Request('http://example.com/c', |
| 77 {headers: {'Cookies': 'is-for-cookie'}}), | 85 {headers: {'Cookies': 'is-for-cookie'}}), |
| 78 response: new Response('', | 86 response: new Response('', |
| 79 {headers: {'Vary': 'Cookies'}}) | 87 {headers: {'Vary': 'Cookies'}}) |
| 80 }, | 88 }, |
| 81 | 89 |
| 82 vary_cookie_is_good: { | 90 { |
| 91 name: 'vary_cookie_is_good', |
| 83 request: new Request('http://example.com/c', | 92 request: new Request('http://example.com/c', |
| 84 {headers: {'Cookies': 'is-good-enough-for-me'}}), | 93 {headers: {'Cookies': 'is-good-enough-for-me'}}), |
| 85 response: new Response('', | 94 response: new Response('', |
| 86 {headers: {'Vary': 'Cookies'}}) | 95 {headers: {'Vary': 'Cookies'}}) |
| 87 }, | 96 }, |
| 88 | 97 |
| 89 vary_cookie_absent: { | 98 { |
| 99 name: 'vary_cookie_absent', |
| 90 request: new Request('http://example.com/c'), | 100 request: new Request('http://example.com/c'), |
| 91 response: new Response('', | 101 response: new Response('', |
| 92 {headers: {'Vary': 'Cookies'}}) | 102 {headers: {'Vary': 'Cookies'}}) |
| 93 }, | 103 }, |
| 94 | 104 |
| 95 vary_wildcard: { | 105 { |
| 106 name: 'vary_wildcard', |
| 96 request: new Request('http://example.com/c', | 107 request: new Request('http://example.com/c', |
| 97 {headers: {'Cookies': 'x', 'X-Key': '1'}}), | 108 {headers: {'Cookies': 'x', 'X-Key': '1'}}), |
| 98 response: new Response('', | 109 response: new Response('', |
| 99 {headers: {'Vary': '*'}}) | 110 {headers: {'Vary': '*'}}) |
| 100 } | 111 } |
| 101 }; | 112 ]; |
| 102 | 113 |
| 103 prepopulated_cache_test(simple_entries, function(cache) { | 114 prepopulated_cache_test(simple_entries, function(cache, entries) { |
| 104 return cache.matchAll('not-present-in-the-cache') | 115 return cache.matchAll('not-present-in-the-cache') |
| 105 .then(function(result) { | 116 .then(function(result) { |
| 106 assert_array_equivalent( | 117 assert_array_equivalent( |
| 107 result, [], | 118 result, [], |
| 108 'Cache.matchAll should resolve with an empty array on failure.'); | 119 'Cache.matchAll should resolve with an empty array on failure.'); |
| 109 }); | 120 }); |
| 110 }, 'Cache.matchAll with no matching entries'); | 121 }, 'Cache.matchAll with no matching entries'); |
| 111 | 122 |
| 112 prepopulated_cache_test(simple_entries, function(cache) { | 123 prepopulated_cache_test(simple_entries, function(cache, entries) { |
| 113 return cache.match('not-present-in-the-cache') | 124 return cache.match('not-present-in-the-cache') |
| 114 .then(function(result) { | 125 .then(function(result) { |
| 115 assert_equals(result, undefined, | 126 assert_equals(result, undefined, |
| 116 'Cache.match failures should resolve with undefined.'); | 127 'Cache.match failures should resolve with undefined.'); |
| 117 }); | 128 }); |
| 118 }, 'Cache.match with no matching entries'); | 129 }, 'Cache.match with no matching entries'); |
| 119 | 130 |
| 120 prepopulated_cache_test(simple_entries, function(cache) { | 131 prepopulated_cache_test(simple_entries, function(cache, entries) { |
| 121 return cache.matchAll(simple_entries.a.request.url) | 132 return cache.matchAll(entries.a.request.url) |
| 122 .then(function(result) { | 133 .then(function(result) { |
| 123 assert_array_objects_equals(result, [simple_entries.a.response], | 134 assert_array_objects_equals(result, [entries.a.response], |
| 124 'Cache.matchAll should match by URL.'); | 135 'Cache.matchAll should match by URL.'); |
| 125 }); | 136 }); |
| 126 }, 'Cache.matchAll with URL'); | 137 }, 'Cache.matchAll with URL'); |
| 127 | 138 |
| 128 prepopulated_cache_test(simple_entries, function(cache) { | 139 prepopulated_cache_test(simple_entries, function(cache, entries) { |
| 129 return cache.match(simple_entries.a.request.url) | 140 return cache.match(entries.a.request.url) |
| 130 .then(function(result) { | 141 .then(function(result) { |
| 131 assert_object_equals(result, simple_entries.a.response, | 142 assert_object_equals(result, entries.a.response, |
| 132 'Cache.match should match by URL.'); | 143 'Cache.match should match by URL.'); |
| 133 }); | 144 }); |
| 134 }, 'Cache.match with URL'); | 145 }, 'Cache.match with URL'); |
| 135 | 146 |
| 136 prepopulated_cache_test(simple_entries, function(cache) { | 147 prepopulated_cache_test(simple_entries, function(cache, entries) { |
| 137 return cache.matchAll(simple_entries.a.request) | 148 return cache.matchAll(entries.a.request) |
| 138 .then(function(result) { | 149 .then(function(result) { |
| 139 assert_array_objects_equals( | 150 assert_array_objects_equals( |
| 140 result, [simple_entries.a.response], | 151 result, [entries.a.response], |
| 141 'Cache.matchAll should match by Request.'); | 152 'Cache.matchAll should match by Request.'); |
| 142 }); | 153 }); |
| 143 }, 'Cache.matchAll with Request'); | 154 }, 'Cache.matchAll with Request'); |
| 144 | 155 |
| 145 prepopulated_cache_test(simple_entries, function(cache) { | 156 prepopulated_cache_test(simple_entries, function(cache, entries) { |
| 146 return cache.match(simple_entries.a.request) | 157 return cache.match(entries.a.request) |
| 147 .then(function(result) { | 158 .then(function(result) { |
| 148 assert_object_equals(result, simple_entries.a.response, | 159 assert_object_equals(result, entries.a.response, |
| 149 'Cache.match should match by Request.'); | 160 'Cache.match should match by Request.'); |
| 150 }); | 161 }); |
| 151 }, 'Cache.match with Request'); | 162 }, 'Cache.match with Request'); |
| 152 | 163 |
| 153 prepopulated_cache_test(simple_entries, function(cache) { | 164 prepopulated_cache_test(simple_entries, function(cache, entries) { |
| 154 return cache.matchAll(new Request(simple_entries.a.request.url)) | 165 return cache.matchAll(new Request(entries.a.request.url)) |
| 155 .then(function(result) { | 166 .then(function(result) { |
| 156 assert_array_objects_equals( | 167 assert_array_objects_equals( |
| 157 result, [simple_entries.a.response], | 168 result, [entries.a.response], |
| 158 'Cache.matchAll should match by Request.'); | 169 'Cache.matchAll should match by Request.'); |
| 159 }); | 170 }); |
| 160 }, 'Cache.matchAll with new Request'); | 171 }, 'Cache.matchAll with new Request'); |
| 161 | 172 |
| 162 prepopulated_cache_test(simple_entries, function(cache) { | 173 prepopulated_cache_test(simple_entries, function(cache, entries) { |
| 163 return cache.match(new Request(simple_entries.a.request.url)) | 174 return cache.match(new Request(entries.a.request.url)) |
| 164 .then(function(result) { | 175 .then(function(result) { |
| 165 assert_object_equals(result, simple_entries.a.response, | 176 assert_object_equals(result, entries.a.response, |
| 166 'Cache.match should match by Request.'); | 177 'Cache.match should match by Request.'); |
| 167 }); | 178 }); |
| 168 }, 'Cache.match with new Request'); | 179 }, 'Cache.match with new Request'); |
| 169 | 180 |
| 170 cache_test(function(cache) { | 181 cache_test(function(cache) { |
| 171 var request = new Request('https://example.com/foo', { | 182 var request = new Request('https://example.com/foo', { |
| 172 method: 'GET', | 183 method: 'GET', |
| 173 body: 'Hello world!' | 184 body: 'Hello world!' |
| 174 }); | 185 }); |
| 175 var response = new Response('Booyah!', { | 186 var response = new Response('Booyah!', { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 186 }) | 197 }) |
| 187 .then(function() { | 198 .then(function() { |
| 188 return cache.match(request); | 199 return cache.match(request); |
| 189 }) | 200 }) |
| 190 .then(function(result) { | 201 .then(function(result) { |
| 191 assert_false(request.bodyUsed, | 202 assert_false(request.bodyUsed, |
| 192 'Cache.match should not consume Request body.'); | 203 'Cache.match should not consume Request body.'); |
| 193 }); | 204 }); |
| 194 }, 'Cache.match with Request containing non-empty body'); | 205 }, 'Cache.match with Request containing non-empty body'); |
| 195 | 206 |
| 196 prepopulated_cache_test(simple_entries, function(cache) { | 207 prepopulated_cache_test(simple_entries, function(cache, entries) { |
| 197 return cache.matchAll(simple_entries.a.request, | 208 return cache.matchAll(entries.a.request, |
| 198 {ignoreSearch: true}) | 209 {ignoreSearch: true}) |
| 199 .then(function(result) { | 210 .then(function(result) { |
| 200 assert_array_equivalent( | 211 assert_array_equivalent( |
| 201 result, | 212 result, |
| 202 [ | 213 [ |
| 203 simple_entries.a.response, | 214 entries.a.response, |
| 204 simple_entries.a_with_query.response | 215 entries.a_with_query.response |
| 205 ], | 216 ], |
| 206 'Cache.matchAll with ignoreSearch should ignore the ' + | 217 'Cache.matchAll with ignoreSearch should ignore the ' + |
| 207 'search parameters of cached request.'); | 218 'search parameters of cached request.'); |
| 208 }); | 219 }); |
| 209 }, | 220 }, |
| 210 'Cache.matchAll with ignoreSearch option (request with no search ' + | 221 'Cache.matchAll with ignoreSearch option (request with no search ' + |
| 211 'parameters)'); | 222 'parameters)'); |
| 212 | 223 |
| 213 prepopulated_cache_test(simple_entries, function(cache) { | 224 prepopulated_cache_test(simple_entries, function(cache, entries) { |
| 214 return cache.match(simple_entries.a.request, | 225 return cache.match(entries.a.request, |
| 215 {ignoreSearch: true}) | 226 {ignoreSearch: true}) |
| 216 .then(function(result) { | 227 .then(function(result) { |
| 217 assert_object_in_array( | 228 assert_object_in_array( |
| 218 result, | 229 result, |
| 219 [ | 230 [ |
| 220 simple_entries.a.response, | 231 entries.a.response, |
| 221 simple_entries.a_with_query.response | 232 entries.a_with_query.response |
| 222 ], | 233 ], |
| 223 'Cache.match with ignoreSearch should ignore the ' + | 234 'Cache.match with ignoreSearch should ignore the ' + |
| 224 'search parameters of cached request.'); | 235 'search parameters of cached request.'); |
| 225 }); | 236 }); |
| 226 }, | 237 }, |
| 227 'Cache.match with ignoreSearch option (request with no search ' + | 238 'Cache.match with ignoreSearch option (request with no search ' + |
| 228 'parameters)'); | 239 'parameters)'); |
| 229 | 240 |
| 230 prepopulated_cache_test(simple_entries, function(cache) { | 241 prepopulated_cache_test(simple_entries, function(cache, entries) { |
| 231 return cache.matchAll(simple_entries.a_with_query.request, | 242 return cache.matchAll(entries.a_with_query.request, |
| 232 {ignoreSearch: true}) | 243 {ignoreSearch: true}) |
| 233 .then(function(result) { | 244 .then(function(result) { |
| 234 assert_array_equivalent( | 245 assert_array_equivalent( |
| 235 result, | 246 result, |
| 236 [ | 247 [ |
| 237 simple_entries.a.response, | 248 entries.a.response, |
| 238 simple_entries.a_with_query.response | 249 entries.a_with_query.response |
| 239 ], | 250 ], |
| 240 'Cache.matchAll with ignoreSearch should ignore the ' + | 251 'Cache.matchAll with ignoreSearch should ignore the ' + |
| 241 'search parameters of request.'); | 252 'search parameters of request.'); |
| 242 }); | 253 }); |
| 243 }, | 254 }, |
| 244 'Cache.matchAll with ignoreSearch option (request with search parameter)'); | 255 'Cache.matchAll with ignoreSearch option (request with search parameter)'); |
| 245 | 256 |
| 246 prepopulated_cache_test(simple_entries, function(cache) { | 257 prepopulated_cache_test(simple_entries, function(cache, entries) { |
| 247 return cache.match(simple_entries.a_with_query.request, | 258 return cache.match(entries.a_with_query.request, |
| 248 {ignoreSearch: true}) | 259 {ignoreSearch: true}) |
| 249 .then(function(result) { | 260 .then(function(result) { |
| 250 assert_object_in_array( | 261 assert_object_in_array( |
| 251 result, | 262 result, |
| 252 [ | 263 [ |
| 253 simple_entries.a.response, | 264 entries.a.response, |
| 254 simple_entries.a_with_query.response | 265 entries.a_with_query.response |
| 255 ], | 266 ], |
| 256 'Cache.match with ignoreSearch should ignore the ' + | 267 'Cache.match with ignoreSearch should ignore the ' + |
| 257 'search parameters of request.'); | 268 'search parameters of request.'); |
| 258 }); | 269 }); |
| 259 }, | 270 }, |
| 260 'Cache.match with ignoreSearch option (request with search parameter)'); | 271 'Cache.match with ignoreSearch option (request with search parameter)'); |
| 261 | 272 |
| 262 prepopulated_cache_test(simple_entries, function(cache) { | 273 prepopulated_cache_test(simple_entries, function(cache, entries) { |
| 263 return cache.matchAll(simple_entries.cat.request.url + '#mouse') | 274 return cache.matchAll(entries.cat.request.url + '#mouse') |
| 264 .then(function(result) { | 275 .then(function(result) { |
| 265 assert_array_equivalent( | 276 assert_array_equivalent( |
| 266 result, | 277 result, |
| 267 [ | 278 [ |
| 268 simple_entries.cat.response, | 279 entries.cat.response, |
| 269 ], | 280 ], |
| 270 'Cache.matchAll should ignore URL fragment.'); | 281 'Cache.matchAll should ignore URL fragment.'); |
| 271 }); | 282 }); |
| 272 }, 'Cache.matchAll with URL containing fragment'); | 283 }, 'Cache.matchAll with URL containing fragment'); |
| 273 | 284 |
| 274 prepopulated_cache_test(simple_entries, function(cache) { | 285 prepopulated_cache_test(simple_entries, function(cache, entries) { |
| 275 return cache.match(simple_entries.cat.request.url + '#mouse') | 286 return cache.match(entries.cat.request.url + '#mouse') |
| 276 .then(function(result) { | 287 .then(function(result) { |
| 277 assert_object_equals(result, simple_entries.cat.response, | 288 assert_object_equals(result, entries.cat.response, |
| 278 'Cache.match should ignore URL fragment.'); | 289 'Cache.match should ignore URL fragment.'); |
| 279 }); | 290 }); |
| 280 }, 'Cache.match with URL containing fragment'); | 291 }, 'Cache.match with URL containing fragment'); |
| 281 | 292 |
| 282 prepopulated_cache_test(simple_entries, function(cache) { | 293 prepopulated_cache_test(simple_entries, function(cache, entries) { |
| 283 return cache.matchAll('http') | 294 return cache.matchAll('http') |
| 284 .then(function(result) { | 295 .then(function(result) { |
| 285 assert_array_equivalent( | 296 assert_array_equivalent( |
| 286 result, [], | 297 result, [], |
| 287 'Cache.matchAll should treat query as a URL and not ' + | 298 'Cache.matchAll should treat query as a URL and not ' + |
| 288 'just a string fragment.'); | 299 'just a string fragment.'); |
| 289 }); | 300 }); |
| 290 }, 'Cache.matchAll with string fragment "http" as query'); | 301 }, 'Cache.matchAll with string fragment "http" as query'); |
| 291 | 302 |
| 292 prepopulated_cache_test(simple_entries, function(cache) { | 303 prepopulated_cache_test(simple_entries, function(cache, entries) { |
| 293 return cache.match('http') | 304 return cache.match('http') |
| 294 .then(function(result) { | 305 .then(function(result) { |
| 295 assert_equals( | 306 assert_equals( |
| 296 result, undefined, | 307 result, undefined, |
| 297 'Cache.match should treat query as a URL and not ' + | 308 'Cache.match should treat query as a URL and not ' + |
| 298 'just a string fragment.'); | 309 'just a string fragment.'); |
| 299 }); | 310 }); |
| 300 }, 'Cache.match with string fragment "http" as query'); | 311 }, 'Cache.match with string fragment "http" as query'); |
| 301 | 312 |
| 302 prepopulated_cache_test(simple_entries, function(cache) { | 313 prepopulated_cache_test(simple_entries, function(cache, entries) { |
| 303 return cache.matchAll('http://example.com/cat', | 314 return cache.matchAll('http://example.com/cat', |
| 304 {prefixMatch: true}) | 315 {prefixMatch: true}) |
| 305 .then(function(result) { | 316 .then(function(result) { |
| 306 assert_array_equivalent( | 317 assert_array_equivalent( |
| 307 result, | 318 result, |
| 308 [ | 319 [ |
| 309 simple_entries.cat.response, | 320 entries.cat.response, |
| 310 simple_entries.catmandu.response, | 321 entries.catmandu.response, |
| 311 simple_entries.cat_num_lives.response, | 322 entries.cat_num_lives.response, |
| 312 simple_entries.cat_in_the_hat.response | 323 entries.cat_in_the_hat.response |
| 313 ], | 324 ], |
| 314 'Cache.matchAll should honor prefixMatch.'); | 325 'Cache.matchAll should honor prefixMatch.'); |
| 315 }); | 326 }); |
| 316 }, 'Cache.matchAll with prefixMatch option'); | 327 }, 'Cache.matchAll with prefixMatch option'); |
| 317 | 328 |
| 318 prepopulated_cache_test(simple_entries, function(cache) { | 329 prepopulated_cache_test(simple_entries, function(cache, entries) { |
| 319 return cache.match('http://example.com/cat', | 330 return cache.match('http://example.com/cat', |
| 320 {prefixMatch: true}) | 331 {prefixMatch: true}) |
| 321 .then(function(result) { | 332 .then(function(result) { |
| 322 assert_object_in_array( | 333 assert_object_in_array( |
| 323 result, | 334 result, |
| 324 [ | 335 [ |
| 325 simple_entries.cat.response, | 336 entries.cat.response, |
| 326 simple_entries.catmandu.response, | 337 entries.catmandu.response, |
| 327 simple_entries.cat_num_lives.response, | 338 entries.cat_num_lives.response, |
| 328 simple_entries.cat_in_the_hat.response | 339 entries.cat_in_the_hat.response |
| 329 ], | 340 ], |
| 330 'Cache.match should honor prefixMatch.'); | 341 'Cache.match should honor prefixMatch.'); |
| 331 }); | 342 }); |
| 332 }, 'Cache.match with prefixMatch option'); | 343 }, 'Cache.match with prefixMatch option'); |
| 333 | 344 |
| 334 prepopulated_cache_test(simple_entries, function(cache) { | 345 prepopulated_cache_test(simple_entries, function(cache, entries) { |
| 335 return cache.matchAll('http://example.com/cat/', | 346 return cache.matchAll('http://example.com/cat/', |
| 336 {prefixMatch: true}) | 347 {prefixMatch: true}) |
| 337 .then(function(result) { | 348 .then(function(result) { |
| 338 assert_array_equivalent( | 349 assert_array_equivalent( |
| 339 result, [simple_entries.cat_in_the_hat.response], | 350 result, [entries.cat_in_the_hat.response], |
| 340 'Cache.matchAll should honor prefixMatch.'); | 351 'Cache.matchAll should honor prefixMatch.'); |
| 341 }); | 352 }); |
| 342 }, 'Cache.matchAll with prefixMatch option (URL ending with path delimiter)'); | 353 }, 'Cache.matchAll with prefixMatch option (URL ending with path delimiter)'); |
| 343 | 354 |
| 344 prepopulated_cache_test(simple_entries, function(cache) { | 355 prepopulated_cache_test(simple_entries, function(cache, entries) { |
| 345 return cache.match('http://example.com/cat/', | 356 return cache.match('http://example.com/cat/', |
| 346 {prefixMatch: true}) | 357 {prefixMatch: true}) |
| 347 .then(function(result) { | 358 .then(function(result) { |
| 348 assert_object_equals( | 359 assert_object_equals( |
| 349 result, simple_entries.cat_in_the_hat.response, | 360 result, entries.cat_in_the_hat.response, |
| 350 'Cache.match should honor prefixMatch.'); | 361 'Cache.match should honor prefixMatch.'); |
| 351 }); | 362 }); |
| 352 }, 'Cache.match with prefixMatch option (URL ending with path delimiter)'); | 363 }, 'Cache.match with prefixMatch option (URL ending with path delimiter)'); |
| 353 | 364 |
| 354 prepopulated_cache_test(simple_entries, function(cache) { | 365 prepopulated_cache_test(simple_entries, function(cache, entries) { |
| 355 return cache.matchAll('http://tom:jerry@example.com', {prefixMatch: true}) | 366 return cache.matchAll('http://tom:jerry@example.com', {prefixMatch: true}) |
| 356 .then(function(result) { | 367 .then(function(result) { |
| 357 assert_array_equivalent( | 368 assert_array_equivalent( |
| 358 result, | 369 result, |
| 359 [ | 370 [ |
| 360 simple_entries.secret_cat.response, | 371 entries.secret_cat.response, |
| 361 ], | 372 ], |
| 362 'Cache.matchAll should honor prefixMatch.'); | 373 'Cache.matchAll should honor prefixMatch.'); |
| 363 }); | 374 }); |
| 364 }, 'Cache.matchAll with prefixMatch option (URL with embedded credentials)'); | 375 }, 'Cache.matchAll with prefixMatch option (URL with embedded credentials)'); |
| 365 | 376 |
| 366 prepopulated_cache_test(simple_entries, function(cache) { | 377 prepopulated_cache_test(simple_entries, function(cache, entries) { |
| 367 return cache.match('http://tom:jerry@example.com', {prefixMatch: true}) | 378 return cache.match('http://tom:jerry@example.com', {prefixMatch: true}) |
| 368 .then(function(result) { | 379 .then(function(result) { |
| 369 assert_object_equals( | 380 assert_object_equals( |
| 370 result, simple_entries.secret_cat.response, | 381 result, entries.secret_cat.response, |
| 371 'Cache.match should honor prefixMatch.'); | 382 'Cache.match should honor prefixMatch.'); |
| 372 }); | 383 }); |
| 373 }, 'Cache.match with prefixMatch option (URL with embedded credentials)'); | 384 }, 'Cache.match with prefixMatch option (URL with embedded credentials)'); |
| 374 | 385 |
| 375 prepopulated_cache_test(simple_entries, function(cache) { | 386 prepopulated_cache_test(simple_entries, function(cache, entries) { |
| 376 // The string 'http://tom' should be converted to a URL and then serialized | 387 // 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 | 388 // yielding 'http://tom/'. The trailing slash prevents the URL from matching |
| 378 // the embedded credentials in the entries already in the cache. | 389 // the embedded credentials in the entries already in the cache. |
| 379 return cache.matchAll('http://tom', {prefixMatch: true}) | 390 return cache.matchAll('http://tom', {prefixMatch: true}) |
| 380 .then(function(result) { | 391 .then(function(result) { |
| 381 assert_array_equivalent( | 392 assert_array_equivalent( |
| 382 result, [], | 393 result, [], |
| 383 'Cache.matchAll should honor prefixMatch.'); | 394 'Cache.matchAll should honor prefixMatch.'); |
| 384 }); | 395 }); |
| 385 }, | 396 }, |
| 386 'Cache.matchAll with prefixMatch option (URL matching embedded credentials)'); | 397 'Cache.matchAll with prefixMatch option (URL matching embedded credentials)'); |
| 387 | 398 |
| 388 prepopulated_cache_test(simple_entries, function(cache) { | 399 prepopulated_cache_test(simple_entries, function(cache, entries) { |
| 389 // The string 'http://tom' should be converted to a URL and then serialized | 400 // 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 | 401 // yielding 'http://tom/'. The trailing slash prevents the URL from matching |
| 391 // the embedded credentials in the entries already in the cache. | 402 // the embedded credentials in the entries already in the cache. |
| 392 return cache.match('http://tom', {prefixMatch: true}) | 403 return cache.match('http://tom', {prefixMatch: true}) |
| 393 .then(function(result) { | 404 .then(function(result) { |
| 394 assert_equals(result, undefined, | 405 assert_equals(result, undefined, |
| 395 'Cache.match should honor prefixMatch.'); | 406 'Cache.match should honor prefixMatch.'); |
| 396 }); | 407 }); |
| 397 }, | 408 }, |
| 398 'Cache.match with prefixMatch option (URL matching embedded credentials)'); | 409 'Cache.match with prefixMatch option (URL matching embedded credentials)'); |
| 399 | 410 |
| 400 prepopulated_cache_test(simple_entries, function(cache) { | 411 prepopulated_cache_test(simple_entries, function(cache, entries) { |
| 401 return cache.matchAll(simple_entries.secret_cat.request.url) | 412 return cache.matchAll(entries.secret_cat.request.url) |
| 402 .then(function(result) { | 413 .then(function(result) { |
| 403 assert_array_equivalent( | 414 assert_array_equivalent( |
| 404 result, [simple_entries.secret_cat.response], | 415 result, [entries.secret_cat.response], |
| 405 'Cache.matchAll should not ignore embedded credentials'); | 416 'Cache.matchAll should not ignore embedded credentials'); |
| 406 }); | 417 }); |
| 407 }, 'Cache.matchAll with URL containing credentials'); | 418 }, 'Cache.matchAll with URL containing credentials'); |
| 408 | 419 |
| 409 prepopulated_cache_test(simple_entries, function(cache) { | 420 prepopulated_cache_test(simple_entries, function(cache, entries) { |
| 410 return cache.match(simple_entries.secret_cat.request.url) | 421 return cache.match(entries.secret_cat.request.url) |
| 411 .then(function(result) { | 422 .then(function(result) { |
| 412 assert_object_equals( | 423 assert_object_equals( |
| 413 result, simple_entries.secret_cat.response, | 424 result, entries.secret_cat.response, |
| 414 'Cache.match should not ignore embedded credentials'); | 425 'Cache.match should not ignore embedded credentials'); |
| 415 }); | 426 }); |
| 416 }, 'Cache.match with URL containing credentials'); | 427 }, 'Cache.match with URL containing credentials'); |
| 417 | 428 |
| 418 prepopulated_cache_test(vary_entries, function(cache) { | 429 prepopulated_cache_test(vary_entries, function(cache, entries) { |
| 419 return cache.matchAll('http://example.com/c') | 430 return cache.matchAll('http://example.com/c') |
| 420 .then(function(result) { | 431 .then(function(result) { |
| 421 assert_array_equivalent( | 432 assert_array_equivalent( |
| 422 result, | 433 result, |
| 423 [ | 434 [ |
| 424 vary_entries.no_vary_header.response, | 435 entries.vary_wildcard.response, |
| 425 vary_entries.vary_wildcard.response, | 436 entries.vary_cookie_absent.response |
| 426 vary_entries.vary_cookie_absent.response | |
| 427 ], | 437 ], |
| 428 'Cache.matchAll should exclude matches if a vary header is ' + | 438 'Cache.matchAll should exclude matches if a vary header is ' + |
| 429 'missing in the query request, but is present in the cached ' + | 439 'missing in the query request, but is present in the cached ' + |
| 430 'request.'); | 440 'request.'); |
| 431 }) | 441 }) |
| 432 | 442 |
| 433 .then(function() { | 443 .then(function() { |
| 434 return cache.matchAll( | 444 return cache.matchAll( |
| 435 new Request('http://example.com/c', | 445 new Request('http://example.com/c', |
| 436 {headers: {'Cookies': 'none-of-the-above'}})); | 446 {headers: {'Cookies': 'none-of-the-above'}})); |
| 437 }) | 447 }) |
| 438 .then(function(result) { | 448 .then(function(result) { |
| 439 assert_array_equivalent( | 449 assert_array_equivalent( |
| 440 result, | 450 result, |
| 441 [ | 451 [ |
| 442 vary_entries.no_vary_header.response, | 452 entries.vary_wildcard.response |
| 443 vary_entries.vary_wildcard.response | |
| 444 ], | 453 ], |
| 445 'Cache.matchAll should exclude matches if a vary header is ' + | 454 'Cache.matchAll should exclude matches if a vary header is ' + |
| 446 'missing in the cached request, but is present in the query ' + | 455 'missing in the cached request, but is present in the query ' + |
| 447 'request.'); | 456 'request.'); |
| 448 }) | 457 }) |
| 449 | 458 |
| 450 .then(function() { | 459 .then(function() { |
| 451 return cache.matchAll( | 460 return cache.matchAll( |
| 452 new Request('http://example.com/c', | 461 new Request('http://example.com/c', |
| 453 {headers: {'Cookies': 'is-for-cookie'}})); | 462 {headers: {'Cookies': 'is-for-cookie'}})); |
| 454 }) | 463 }) |
| 455 .then(function(result) { | 464 .then(function(result) { |
| 456 assert_array_equivalent( | 465 assert_array_equivalent( |
| 457 result, | 466 result, |
| 458 [vary_entries.vary_cookie_is_cookie.response], | 467 [entries.vary_cookie_is_cookie.response], |
| 459 'Cache.matchAll should match the entire header if a vary header ' + | 468 'Cache.matchAll should match the entire header if a vary header ' + |
| 460 'is present in both the query and cached requests.'); | 469 'is present in both the query and cached requests.'); |
| 461 }); | 470 }); |
| 462 }, 'Cache.matchAll with responses containing "Vary" header'); | 471 }, 'Cache.matchAll with responses containing "Vary" header'); |
| 463 | 472 |
| 464 prepopulated_cache_test(vary_entries, function(cache) { | 473 prepopulated_cache_test(vary_entries, function(cache, entries) { |
| 465 return cache.match('http://example.com/c') | 474 return cache.match('http://example.com/c') |
| 466 .then(function(result) { | 475 .then(function(result) { |
| 467 assert_object_in_array( | 476 assert_object_in_array( |
| 468 result, | 477 result, |
| 469 [ | 478 [ |
| 470 vary_entries.no_vary_header.response, | 479 entries.vary_wildcard.response, |
| 471 vary_entries.vary_wildcard.response, | 480 entries.vary_cookie_absent.response |
| 472 vary_entries.vary_cookie_absent.response | |
| 473 ], | 481 ], |
| 474 'Cache.match should honor "Vary" header.'); | 482 'Cache.match should honor "Vary" header.'); |
| 475 }); | 483 }); |
| 476 }, 'Cache.match with responses containing "Vary" header'); | 484 }, 'Cache.match with responses containing "Vary" header'); |
| 477 | 485 |
| 478 prepopulated_cache_test(vary_entries, function(cache) { | 486 prepopulated_cache_test(vary_entries, function(cache, entries) { |
| 479 return cache.matchAll('http://example.com/c', | 487 return cache.matchAll('http://example.com/c', |
| 480 {ignoreVary: true}) | 488 {ignoreVary: true}) |
| 481 .then(function(result) { | 489 .then(function(result) { |
| 482 assert_array_equivalent( | 490 assert_array_equivalent( |
| 483 result, | 491 result, |
| 484 [ | 492 [ |
| 485 vary_entries.no_vary_header.response, | 493 entries.vary_cookie_is_cookie.response, |
| 486 vary_entries.vary_cookie_is_cookie.response, | 494 entries.vary_cookie_is_good.response, |
| 487 vary_entries.vary_cookie_is_good.response, | 495 entries.vary_cookie_absent.response, |
| 488 vary_entries.vary_cookie_absent.response, | 496 entries.vary_wildcard.response |
| 489 vary_entries.vary_wildcard.response | |
| 490 ], | 497 ], |
| 491 'Cache.matchAll should honor "ignoreVary" parameter.'); | 498 'Cache.matchAll should honor "ignoreVary" parameter.'); |
| 492 }); | 499 }); |
| 493 }, 'Cache.matchAll with "ignoreVary" parameter'); | 500 }, 'Cache.matchAll with "ignoreVary" parameter'); |
| 494 | 501 |
| 495 cache_test(function(cache) { | 502 cache_test(function(cache) { |
| 496 var request = new Request('http://example.com'); | 503 var request = new Request('http://example.com'); |
| 497 var response; | 504 var response; |
| 498 var request_url = new URL('simple.txt', location.href).href; | 505 var request_url = new URL('simple.txt', location.href).href; |
| 499 return fetch(request_url) | 506 return fetch(request_url) |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 'Cache.match should return a Response object with a ' + | 557 'Cache.match should return a Response object with a ' + |
| 551 'valid body each time it is called.'); | 558 'valid body each time it is called.'); |
| 552 }); | 559 }); |
| 553 }, 'Cache.match invoked multiple times for the same Request/Response'); | 560 }, 'Cache.match invoked multiple times for the same Request/Response'); |
| 554 | 561 |
| 555 // Helpers --- | 562 // Helpers --- |
| 556 | 563 |
| 557 // Run |test_function| with a Cache object as its only parameter. Prior to the | 564 // Run |test_function| with a Cache object as its only parameter. Prior to the |
| 558 // call, the Cache is populated by cache entries from |entries|. The latter is | 565 // call, the Cache is populated by cache entries from |entries|. The latter is |
| 559 // expected to be an Object mapping arbitrary keys to objects of the form | 566 // expected to be an Object mapping arbitrary keys to objects of the form |
| 560 // {request: <Request object>, response: <Response object>}. | 567 // {request: <Request object>, response: <Response object>}. There's no |
| 568 // guarantee on the order in which entries will be added to the cache. |
| 561 // | 569 // |
| 562 // |test_function| should return a Promise that can be used with promise_test. | 570 // |test_function| should return a Promise that can be used with promise_test. |
| 563 function prepopulated_cache_test(entries, test_function, description) { | 571 function prepopulated_cache_test(entries, test_function, description) { |
| 564 cache_test(function(cache) { | 572 cache_test(function(cache) { |
| 565 return Promise.all(Object.keys(entries).map(function(k) { | 573 var p = Promise.resolve(); |
| 566 return cache.put(entries[k].request, entries[k].response) | 574 var hash = {}; |
| 567 .catch(function(e) { | 575 entries.forEach(function(entry) { |
| 568 assert_unreached('Test setup failed for entry ' + k + ' : ' + e)
; | 576 p = p.then(function() { |
| 569 }); | 577 return cache.put(entry.request, entry.response) |
| 570 })) | 578 .catch(function(e) { |
| 571 .then(function() { | 579 assert_unreached('Test setup failed for entry ' + |
| 572 return test_function(cache); | 580 entry.name + ': ' + e); |
| 573 }); | 581 }); |
| 582 }); |
| 583 hash[entry.name] = entry; |
| 584 }); |
| 585 p = p.then(function() { |
| 586 assert_equals(Object.keys(hash).length, entries.length); |
| 587 }); |
| 588 |
| 589 return p.then(function() { |
| 590 return test_function(cache, hash); |
| 591 }); |
| 574 }, description); | 592 }, description); |
| 575 } | 593 } |
| OLD | NEW |