| OLD | NEW |
| 1 if (self.importScripts) { | 1 if (self.importScripts) { |
| 2 importScripts('/resources/testharness.js'); | 2 importScripts('/resources/testharness.js'); |
| 3 importScripts('../resources/test-helpers.js'); | 3 importScripts('../resources/test-helpers.js'); |
| 4 } | 4 } |
| 5 | 5 |
| 6 prepopulated_cache_test(simple_entries, function(cache, entries) { | 6 prepopulated_cache_test(simple_entries, function(cache, entries) { |
| 7 return cache.matchAll('not-present-in-the-cache') | 7 return cache.matchAll('not-present-in-the-cache') |
| 8 .then(function(result) { | 8 .then(function(result) { |
| 9 assert_response_array_equivalent( | 9 assert_response_array_equals( |
| 10 result, [], | 10 result, [], |
| 11 'Cache.matchAll should resolve with an empty array on failure.'); | 11 'Cache.matchAll should resolve with an empty array on failure.'); |
| 12 }); | 12 }); |
| 13 }, 'Cache.matchAll with no matching entries'); | 13 }, 'Cache.matchAll with no matching entries'); |
| 14 | 14 |
| 15 prepopulated_cache_test(simple_entries, function(cache, entries) { | 15 prepopulated_cache_test(simple_entries, function(cache, entries) { |
| 16 return cache.matchAll(entries.a.request.url) | 16 return cache.matchAll(entries.a.request.url) |
| 17 .then(function(result) { | 17 .then(function(result) { |
| 18 assert_response_array_equals(result, [entries.a.response], | 18 assert_response_array_equals(result, [entries.a.response], |
| 19 'Cache.matchAll should match by URL.'); | 19 'Cache.matchAll should match by URL.'); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 45 assert_response_array_equals( | 45 assert_response_array_equals( |
| 46 result, [], | 46 result, [], |
| 47 'Cache.matchAll should not match HEAD Request.'); | 47 'Cache.matchAll should not match HEAD Request.'); |
| 48 }); | 48 }); |
| 49 }, 'Cache.matchAll with HEAD'); | 49 }, 'Cache.matchAll with HEAD'); |
| 50 | 50 |
| 51 prepopulated_cache_test(simple_entries, function(cache, entries) { | 51 prepopulated_cache_test(simple_entries, function(cache, entries) { |
| 52 return cache.matchAll(entries.a.request, | 52 return cache.matchAll(entries.a.request, |
| 53 {ignoreSearch: true}) | 53 {ignoreSearch: true}) |
| 54 .then(function(result) { | 54 .then(function(result) { |
| 55 assert_response_array_equivalent( | 55 assert_response_array_equals( |
| 56 result, | 56 result, |
| 57 [ | 57 [ |
| 58 entries.a.response, | 58 entries.a.response, |
| 59 entries.a_with_query.response | 59 entries.a_with_query.response |
| 60 ], | 60 ], |
| 61 'Cache.matchAll with ignoreSearch should ignore the ' + | 61 'Cache.matchAll with ignoreSearch should ignore the ' + |
| 62 'search parameters of cached request.'); | 62 'search parameters of cached request.'); |
| 63 }); | 63 }); |
| 64 }, | 64 }, |
| 65 'Cache.matchAll with ignoreSearch option (request with no search ' + | 65 'Cache.matchAll with ignoreSearch option (request with no search ' + |
| 66 'parameters)'); | 66 'parameters)'); |
| 67 | 67 |
| 68 prepopulated_cache_test(simple_entries, function(cache, entries) { | 68 prepopulated_cache_test(simple_entries, function(cache, entries) { |
| 69 return cache.matchAll(entries.a_with_query.request, | 69 return cache.matchAll(entries.a_with_query.request, |
| 70 {ignoreSearch: true}) | 70 {ignoreSearch: true}) |
| 71 .then(function(result) { | 71 .then(function(result) { |
| 72 assert_response_array_equivalent( | 72 assert_response_array_equals( |
| 73 result, | 73 result, |
| 74 [ | 74 [ |
| 75 entries.a.response, | 75 entries.a.response, |
| 76 entries.a_with_query.response | 76 entries.a_with_query.response |
| 77 ], | 77 ], |
| 78 'Cache.matchAll with ignoreSearch should ignore the ' + | 78 'Cache.matchAll with ignoreSearch should ignore the ' + |
| 79 'search parameters of request.'); | 79 'search parameters of request.'); |
| 80 }); | 80 }); |
| 81 }, | 81 }, |
| 82 'Cache.matchAll with ignoreSearch option (request with search parameter)'); | 82 'Cache.matchAll with ignoreSearch option (request with search parameters)'); |
| 83 |
| 84 cache_test(function(cache) { |
| 85 var request = new Request('http://example.com/'); |
| 86 var head_request = new Request('http://example.com/', {method: 'HEAD'}); |
| 87 var response = new Response('foo'); |
| 88 return cache.put(request.clone(), response.clone()) |
| 89 .then(function() { |
| 90 return cache.matchAll(head_request.clone()); |
| 91 }) |
| 92 .then(function(result) { |
| 93 assert_response_array_equals( |
| 94 result, [], |
| 95 'Cache.matchAll should resolve with empty array for a ' + |
| 96 'mismatched method.'); |
| 97 return cache.matchAll(head_request.clone(), |
| 98 {ignoreMethod: true}); |
| 99 }) |
| 100 .then(function(result) { |
| 101 assert_response_array_equals( |
| 102 result, [response], |
| 103 'Cache.matchAll with ignoreMethod should ignore the ' + |
| 104 'method of request.'); |
| 105 }); |
| 106 }, 'Cache.matchAll supports ignoreMethod'); |
| 107 |
| 108 cache_test(function(cache) { |
| 109 var vary_request = new Request('http://example.com/c', |
| 110 {headers: {'Cookies': 'is-for-cookie'}}); |
| 111 var vary_response = new Response('', {headers: {'Vary': 'Cookies'}}); |
| 112 var mismatched_vary_request = new Request('http://example.com/c'); |
| 113 |
| 114 return cache.put(vary_request.clone(), vary_response.clone()) |
| 115 .then(function() { |
| 116 return cache.matchAll(mismatched_vary_request.clone()); |
| 117 }) |
| 118 .then(function(result) { |
| 119 assert_response_array_equals( |
| 120 result, [], |
| 121 'Cache.matchAll should resolve as undefined with a ' + |
| 122 'mismatched vary.'); |
| 123 return cache.matchAll(mismatched_vary_request.clone(), |
| 124 {ignoreVary: true}); |
| 125 }) |
| 126 .then(function(result) { |
| 127 assert_response_array_equals( |
| 128 result, [vary_response], |
| 129 'Cache.matchAll with ignoreVary should ignore the ' + |
| 130 'vary of request.'); |
| 131 }); |
| 132 }, 'Cache.matchAll supports ignoreVary'); |
| 83 | 133 |
| 84 prepopulated_cache_test(simple_entries, function(cache, entries) { | 134 prepopulated_cache_test(simple_entries, function(cache, entries) { |
| 85 return cache.matchAll(entries.cat.request.url + '#mouse') | 135 return cache.matchAll(entries.cat.request.url + '#mouse') |
| 86 .then(function(result) { | 136 .then(function(result) { |
| 87 assert_response_array_equivalent( | 137 assert_response_array_equals( |
| 88 result, | 138 result, |
| 89 [ | 139 [ |
| 90 entries.cat.response, | 140 entries.cat.response, |
| 91 ], | 141 ], |
| 92 'Cache.matchAll should ignore URL fragment.'); | 142 'Cache.matchAll should ignore URL fragment.'); |
| 93 }); | 143 }); |
| 94 }, 'Cache.matchAll with URL containing fragment'); | 144 }, 'Cache.matchAll with URL containing fragment'); |
| 95 | 145 |
| 96 prepopulated_cache_test(simple_entries, function(cache, entries) { | 146 prepopulated_cache_test(simple_entries, function(cache, entries) { |
| 97 return cache.matchAll('http') | 147 return cache.matchAll('http') |
| 98 .then(function(result) { | 148 .then(function(result) { |
| 99 assert_response_array_equivalent( | 149 assert_response_array_equals( |
| 100 result, [], | 150 result, [], |
| 101 'Cache.matchAll should treat query as a URL and not ' + | 151 'Cache.matchAll should treat query as a URL and not ' + |
| 102 'just a string fragment.'); | 152 'just a string fragment.'); |
| 103 }); | 153 }); |
| 104 }, 'Cache.matchAll with string fragment "http" as query'); | 154 }, 'Cache.matchAll with string fragment "http" as query'); |
| 105 | 155 |
| 156 prepopulated_cache_test(simple_entries, function(cache, entries) { |
| 157 return cache.matchAll() |
| 158 .then(function(result) { |
| 159 assert_response_array_equals( |
| 160 result, |
| 161 [ |
| 162 entries.a.response, |
| 163 entries.b.response, |
| 164 entries.a_with_query.response, |
| 165 entries.A.response, |
| 166 entries.a_https.response, |
| 167 entries.a_org.response, |
| 168 entries.cat.response, |
| 169 entries.catmandu.response, |
| 170 entries.cat_num_lives.response, |
| 171 entries.cat_in_the_hat.response, |
| 172 entries.non_2xx_response.response, |
| 173 entries.error_response.response |
| 174 ], |
| 175 'Cache.matchAll without parameters should match all entries.'); |
| 176 }); |
| 177 }, 'Cache.matchAll without parameters'); |
| 178 |
| 106 prepopulated_cache_test(vary_entries, function(cache, entries) { | 179 prepopulated_cache_test(vary_entries, function(cache, entries) { |
| 107 return cache.matchAll('http://example.com/c') | 180 return cache.matchAll('http://example.com/c') |
| 108 .then(function(result) { | 181 .then(function(result) { |
| 109 assert_response_array_equivalent( | 182 assert_response_array_equals( |
| 110 result, | 183 result, |
| 111 [ | 184 [ |
| 112 entries.vary_cookie_absent.response | 185 entries.vary_cookie_absent.response |
| 113 ], | 186 ], |
| 114 'Cache.matchAll should exclude matches if a vary header is ' + | 187 'Cache.matchAll should exclude matches if a vary header is ' + |
| 115 'missing in the query request, but is present in the cached ' + | 188 'missing in the query request, but is present in the cached ' + |
| 116 'request.'); | 189 'request.'); |
| 117 }) | 190 }) |
| 118 | 191 |
| 119 .then(function() { | 192 .then(function() { |
| 120 return cache.matchAll( | 193 return cache.matchAll( |
| 121 new Request('http://example.com/c', | 194 new Request('http://example.com/c', |
| 122 {headers: {'Cookies': 'none-of-the-above'}})); | 195 {headers: {'Cookies': 'none-of-the-above'}})); |
| 123 }) | 196 }) |
| 124 .then(function(result) { | 197 .then(function(result) { |
| 125 assert_response_array_equivalent( | 198 assert_response_array_equals( |
| 126 result, | 199 result, |
| 127 [ | 200 [ |
| 128 ], | 201 ], |
| 129 'Cache.matchAll should exclude matches if a vary header is ' + | 202 'Cache.matchAll should exclude matches if a vary header is ' + |
| 130 'missing in the cached request, but is present in the query ' + | 203 'missing in the cached request, but is present in the query ' + |
| 131 'request.'); | 204 'request.'); |
| 132 }) | 205 }) |
| 133 | 206 |
| 134 .then(function() { | 207 .then(function() { |
| 135 return cache.matchAll( | 208 return cache.matchAll( |
| 136 new Request('http://example.com/c', | 209 new Request('http://example.com/c', |
| 137 {headers: {'Cookies': 'is-for-cookie'}})); | 210 {headers: {'Cookies': 'is-for-cookie'}})); |
| 138 }) | 211 }) |
| 139 .then(function(result) { | 212 .then(function(result) { |
| 140 assert_response_array_equivalent( | 213 assert_response_array_equals( |
| 141 result, | 214 result, |
| 142 [entries.vary_cookie_is_cookie.response], | 215 [entries.vary_cookie_is_cookie.response], |
| 143 'Cache.matchAll should match the entire header if a vary header ' + | 216 'Cache.matchAll should match the entire header if a vary header ' + |
| 144 'is present in both the query and cached requests.'); | 217 'is present in both the query and cached requests.'); |
| 145 }); | 218 }); |
| 146 }, 'Cache.matchAll with responses containing "Vary" header'); | 219 }, 'Cache.matchAll with responses containing "Vary" header'); |
| 147 | 220 |
| 148 prepopulated_cache_test(vary_entries, function(cache, entries) { | 221 prepopulated_cache_test(vary_entries, function(cache, entries) { |
| 149 return cache.matchAll('http://example.com/c', | 222 return cache.matchAll('http://example.com/c', |
| 150 {ignoreVary: true}) | 223 {ignoreVary: true}) |
| 151 .then(function(result) { | 224 .then(function(result) { |
| 152 assert_response_array_equivalent( | 225 assert_response_array_equals( |
| 153 result, | 226 result, |
| 154 [ | 227 [ |
| 155 entries.vary_cookie_is_cookie.response, | 228 entries.vary_cookie_is_cookie.response, |
| 156 entries.vary_cookie_is_good.response, | 229 entries.vary_cookie_is_good.response, |
| 157 entries.vary_cookie_absent.response | 230 entries.vary_cookie_absent.response |
| 158 ], | 231 ], |
| 159 'Cache.matchAll should honor "ignoreVary" parameter.'); | 232 'Cache.matchAll should support multiple vary request/response ' + |
| 233 'pairs.'); |
| 160 }); | 234 }); |
| 161 }, 'Cache.matchAll with "ignoreVary" parameter'); | 235 }, 'Cache.matchAll with multiple vary pairs'); |
| 162 | 236 |
| 163 done(); | 237 done(); |
| OLD | NEW |