cache-matchAll.https.any.js (9173B)
1 // META: title=Cache.matchAll 2 // META: global=window,worker 3 // META: script=./resources/test-helpers.js 4 // META: timeout=long 5 6 prepopulated_cache_test(simple_entries, function(cache, entries) { 7 return cache.matchAll('not-present-in-the-cache') 8 .then(function(result) { 9 assert_response_array_equals( 10 result, [], 11 'Cache.matchAll should resolve with an empty array on failure.'); 12 }); 13 }, 'Cache.matchAll with no matching entries'); 14 15 prepopulated_cache_test(simple_entries, function(cache, entries) { 16 return cache.matchAll(entries.a.request.url) 17 .then(function(result) { 18 assert_response_array_equals(result, [entries.a.response], 19 'Cache.matchAll should match by URL.'); 20 }); 21 }, 'Cache.matchAll with URL'); 22 23 prepopulated_cache_test(simple_entries, function(cache, entries) { 24 return cache.matchAll(entries.a.request) 25 .then(function(result) { 26 assert_response_array_equals( 27 result, [entries.a.response], 28 'Cache.matchAll should match by Request.'); 29 }); 30 }, 'Cache.matchAll with Request'); 31 32 prepopulated_cache_test(simple_entries, function(cache, entries) { 33 return cache.matchAll(new Request(entries.a.request.url)) 34 .then(function(result) { 35 assert_response_array_equals( 36 result, [entries.a.response], 37 'Cache.matchAll should match by Request.'); 38 }); 39 }, 'Cache.matchAll with new Request'); 40 41 prepopulated_cache_test(simple_entries, function(cache, entries) { 42 return cache.matchAll(new Request(entries.a.request.url, {method: 'HEAD'}), 43 {ignoreSearch: true}) 44 .then(function(result) { 45 assert_response_array_equals( 46 result, [], 47 'Cache.matchAll should not match HEAD Request.'); 48 }); 49 }, 'Cache.matchAll with HEAD'); 50 51 prepopulated_cache_test(simple_entries, function(cache, entries) { 52 return cache.matchAll(entries.a.request, 53 {ignoreSearch: true}) 54 .then(function(result) { 55 assert_response_array_equals( 56 result, 57 [ 58 entries.a.response, 59 entries.a_with_query.response 60 ], 61 'Cache.matchAll with ignoreSearch should ignore the ' + 62 'search parameters of cached request.'); 63 }); 64 }, 65 'Cache.matchAll with ignoreSearch option (request with no search ' + 66 'parameters)'); 67 68 prepopulated_cache_test(simple_entries, function(cache, entries) { 69 return cache.matchAll(entries.a_with_query.request, 70 {ignoreSearch: true}) 71 .then(function(result) { 72 assert_response_array_equals( 73 result, 74 [ 75 entries.a.response, 76 entries.a_with_query.response 77 ], 78 'Cache.matchAll with ignoreSearch should ignore the ' + 79 'search parameters of request.'); 80 }); 81 }, 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'); 133 134 prepopulated_cache_test(simple_entries, function(cache, entries) { 135 return cache.matchAll(entries.cat.request.url + '#mouse') 136 .then(function(result) { 137 assert_response_array_equals( 138 result, 139 [ 140 entries.cat.response, 141 ], 142 'Cache.matchAll should ignore URL fragment.'); 143 }); 144 }, 'Cache.matchAll with URL containing fragment'); 145 146 prepopulated_cache_test(simple_entries, function(cache, entries) { 147 return cache.matchAll('http') 148 .then(function(result) { 149 assert_response_array_equals( 150 result, [], 151 'Cache.matchAll should treat query as a URL and not ' + 152 'just a string fragment.'); 153 }); 154 }, 'Cache.matchAll with string fragment "http" as query'); 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 simple_entries.map(entry => entry.response), 162 'Cache.matchAll without parameters should match all entries.'); 163 }); 164 }, 'Cache.matchAll without parameters'); 165 166 prepopulated_cache_test(simple_entries, function(cache, entries) { 167 return cache.matchAll(undefined) 168 .then(result => { 169 assert_response_array_equals( 170 result, 171 simple_entries.map(entry => entry.response), 172 'Cache.matchAll with undefined request should match all entries.'); 173 }); 174 }, 'Cache.matchAll with explicitly undefined request'); 175 176 prepopulated_cache_test(simple_entries, function(cache, entries) { 177 return cache.matchAll(undefined, {}) 178 .then(result => { 179 assert_response_array_equals( 180 result, 181 simple_entries.map(entry => entry.response), 182 'Cache.matchAll with undefined request should match all entries.'); 183 }); 184 }, 'Cache.matchAll with explicitly undefined request and empty options'); 185 186 prepopulated_cache_test(vary_entries, function(cache, entries) { 187 return cache.matchAll('http://example.com/c') 188 .then(function(result) { 189 assert_response_array_equals( 190 result, 191 [ 192 entries.vary_cookie_absent.response 193 ], 194 'Cache.matchAll should exclude matches if a vary header is ' + 195 'missing in the query request, but is present in the cached ' + 196 'request.'); 197 }) 198 199 .then(function() { 200 return cache.matchAll( 201 new Request('http://example.com/c', 202 {headers: {'Cookies': 'none-of-the-above'}})); 203 }) 204 .then(function(result) { 205 assert_response_array_equals( 206 result, 207 [ 208 ], 209 'Cache.matchAll should exclude matches if a vary header is ' + 210 'missing in the cached request, but is present in the query ' + 211 'request.'); 212 }) 213 214 .then(function() { 215 return cache.matchAll( 216 new Request('http://example.com/c', 217 {headers: {'Cookies': 'is-for-cookie'}})); 218 }) 219 .then(function(result) { 220 assert_response_array_equals( 221 result, 222 [entries.vary_cookie_is_cookie.response], 223 'Cache.matchAll should match the entire header if a vary header ' + 224 'is present in both the query and cached requests.'); 225 }); 226 }, 'Cache.matchAll with responses containing "Vary" header'); 227 228 prepopulated_cache_test(vary_entries, function(cache, entries) { 229 return cache.matchAll('http://example.com/c', 230 {ignoreVary: true}) 231 .then(function(result) { 232 assert_response_array_equals( 233 result, 234 [ 235 entries.vary_cookie_is_cookie.response, 236 entries.vary_cookie_is_good.response, 237 entries.vary_cookie_absent.response 238 ], 239 'Cache.matchAll should support multiple vary request/response ' + 240 'pairs.'); 241 }); 242 }, 'Cache.matchAll with multiple vary pairs'); 243 244 done();