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 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 function assert_response_in_array(actual, expected_array, description) { | 228 function assert_response_in_array(actual, expected_array, description) { |
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 |
| 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 // Assert that the two arrays |actual| and |expected| contain the same |
| 251 // set of Requests as determined by assert_request_equals. The order |
| 252 // is not significant. |
| 253 // |
| 254 // |expected| is assumed to not contain any duplicates. |
| 255 function assert_request_array_equivalent(actual, expected, description) { |
| 256 assert_true(Array.isArray(actual), description); |
| 257 assert_equals(actual.length, expected.length, description); |
| 258 expected.forEach(function(expected_element) { |
| 259 // assert_request_in_array treats the first argument as being |
| 260 // 'actual', and the second as being 'expected array'. We are |
| 261 // switching them around because we want to be resilient |
| 262 // against the |actual| array containing duplicates. |
| 263 assert_request_in_array(expected_element, actual, description); |
| 264 }); |
| 265 } |
| 266 |
| 267 // Asserts that two arrays |actual| and |expected| contain the same |
| 268 // set of Requests as determined by assert_request_equals(). The |
| 269 // corresponding elements must occupy corresponding indices in their |
| 270 // respective arrays. |
| 271 function assert_request_array_equals(actual, expected, description) { |
| 272 assert_true(Array.isArray(actual), description); |
| 273 assert_equals(actual.length, expected.length, description); |
| 274 actual.forEach(function(value, index) { |
| 275 assert_request_equals(value, expected[index], |
| 276 description + " : object[" + index + "]"); |
| 277 }); |
| 278 } |
| 279 |
| 280 // Equivalent to assert_in_array, but uses assert_request_equals. |
| 281 function assert_request_in_array(actual, expected_array, description) { |
| 282 assert_true(expected_array.some(function(element) { |
| 283 try { |
| 284 assert_request_equals(actual, element); |
| 285 return true; |
| 286 } catch (e) { |
| 287 return false; |
| 288 } |
| 289 }), description); |
| 290 } |
OLD | NEW |