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