OLD | NEW |
| (Empty) |
1 if (self.importScripts) { | |
2 importScripts('/resources/testharness.js'); | |
3 importScripts('../resources/test-helpers.js'); | |
4 } | |
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 [ | |
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 | |
179 prepopulated_cache_test(vary_entries, function(cache, entries) { | |
180 return cache.matchAll('http://example.com/c') | |
181 .then(function(result) { | |
182 assert_response_array_equals( | |
183 result, | |
184 [ | |
185 entries.vary_cookie_absent.response | |
186 ], | |
187 'Cache.matchAll should exclude matches if a vary header is ' + | |
188 'missing in the query request, but is present in the cached ' + | |
189 'request.'); | |
190 }) | |
191 | |
192 .then(function() { | |
193 return cache.matchAll( | |
194 new Request('http://example.com/c', | |
195 {headers: {'Cookies': 'none-of-the-above'}})); | |
196 }) | |
197 .then(function(result) { | |
198 assert_response_array_equals( | |
199 result, | |
200 [ | |
201 ], | |
202 'Cache.matchAll should exclude matches if a vary header is ' + | |
203 'missing in the cached request, but is present in the query ' + | |
204 'request.'); | |
205 }) | |
206 | |
207 .then(function() { | |
208 return cache.matchAll( | |
209 new Request('http://example.com/c', | |
210 {headers: {'Cookies': 'is-for-cookie'}})); | |
211 }) | |
212 .then(function(result) { | |
213 assert_response_array_equals( | |
214 result, | |
215 [entries.vary_cookie_is_cookie.response], | |
216 'Cache.matchAll should match the entire header if a vary header ' + | |
217 'is present in both the query and cached requests.'); | |
218 }); | |
219 }, 'Cache.matchAll with responses containing "Vary" header'); | |
220 | |
221 prepopulated_cache_test(vary_entries, function(cache, entries) { | |
222 return cache.matchAll('http://example.com/c', | |
223 {ignoreVary: true}) | |
224 .then(function(result) { | |
225 assert_response_array_equals( | |
226 result, | |
227 [ | |
228 entries.vary_cookie_is_cookie.response, | |
229 entries.vary_cookie_is_good.response, | |
230 entries.vary_cookie_absent.response | |
231 ], | |
232 'Cache.matchAll should support multiple vary request/response ' + | |
233 'pairs.'); | |
234 }); | |
235 }, 'Cache.matchAll with multiple vary pairs'); | |
236 | |
237 done(); | |
OLD | NEW |