OLD | NEW |
1 (function() { | 1 (function() { |
2 var next_cache_index = 1; | 2 var next_cache_index = 1; |
3 | 3 |
4 // Returns a promise that resolves to a newly created Cache object. The | 4 // Returns a promise that resolves to a newly created Cache object. The |
5 // returned Cache will be destroyed when |test| completes. | 5 // returned Cache will be destroyed when |test| completes. |
6 function create_temporary_cache(test) { | 6 function create_temporary_cache(test) { |
7 var uniquifier = String(++next_cache_index); | 7 var uniquifier = String(++next_cache_index); |
8 var cache_name = self.location.pathname + '/' + uniquifier; | 8 var cache_name = self.location.pathname + '/' + uniquifier; |
9 | 9 |
10 test.add_cleanup(function() { | 10 test.add_cleanup(function() { |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 assert_true(expected_array.some(function(element) { | 229 assert_true(expected_array.some(function(element) { |
230 try { | 230 try { |
231 assert_response_equals(actual, element); | 231 assert_response_equals(actual, element); |
232 return true; | 232 return true; |
233 } catch (e) { | 233 } catch (e) { |
234 return false; | 234 return false; |
235 } | 235 } |
236 }), description); | 236 }), description); |
237 } | 237 } |
238 | 238 |
| 239 // Helper for testing with Request objects. Compares simple |
| 240 // attributes defined on the interfaces, as well as the headers. |
| 241 function assert_request_equals(actual, expected, description) { |
| 242 assert_class_string(actual, "Request", description); |
| 243 ["url"].forEach(function(attribute) { |
| 244 assert_equals(actual[attribute], expected[attribute], |
| 245 description + " Attributes differ: " + attribute + "."); |
| 246 }); |
| 247 assert_header_equals(actual.headers, expected.headers, description); |
| 248 } |
| 249 |
| 250 // Asserts that two arrays |actual| and |expected| contain the same |
| 251 // set of Requests as determined by assert_request_equals(). The |
| 252 // corresponding elements must occupy corresponding indices in their |
| 253 // respective arrays. |
| 254 function assert_request_array_equals(actual, expected, description) { |
| 255 assert_true(Array.isArray(actual), description); |
| 256 assert_equals(actual.length, expected.length, description); |
| 257 actual.forEach(function(value, index) { |
| 258 assert_request_equals(value, expected[index], |
| 259 description + " : object[" + index + "]"); |
| 260 }); |
| 261 } |
| 262 |
239 // Deletes all caches, returning a promise indicating success. | 263 // Deletes all caches, returning a promise indicating success. |
240 function delete_all_caches() { | 264 function delete_all_caches() { |
241 return self.caches.keys() | 265 return self.caches.keys() |
242 .then(function(keys) { | 266 .then(function(keys) { |
243 return Promise.all(keys.map(self.caches.delete.bind(self.caches))); | 267 return Promise.all(keys.map(self.caches.delete.bind(self.caches))); |
244 }); | 268 }); |
245 } | 269 } |
OLD | NEW |