Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(743)

Side by Side Diff: LayoutTests/http/tests/cachestorage/resources/test-helpers.js

Issue 1295633003: Cache Storage: replace assert_object_equals w/ assert_response_equals (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 17 matching lines...) Expand all
28 // E.g.: 28 // E.g.:
29 // cache_test(function(cache) { 29 // cache_test(function(cache) {
30 // // Do something with |cache|, which is a Cache object. 30 // // Do something with |cache|, which is a Cache object.
31 // }, "Some Cache test"); 31 // }, "Some Cache test");
32 function cache_test(test_function, description) { 32 function cache_test(test_function, description) {
33 promise_test(function(test) { 33 promise_test(function(test) {
34 return create_temporary_cache(test) 34 return create_temporary_cache(test)
35 .then(test_function); 35 .then(test_function);
36 }, description); 36 }, description);
37 } 37 }
38
39 // Helper for testing with Headers objects. Compares Headers instances
40 // by serializing |expected| and |actual| to arrays and comparing.
41 function assert_header_equals(actual, expected, description) {
42 assert_class_string(actual, "Headers", description);
43 var header, actual_headers = [], expected_headers = [];
jkarlin 2015/08/21 14:50:44 Should these be on separate lines?
jsbell 2015/08/21 18:05:50 Done. (I'll try to remember to tweak that upstream
44 for (header of actual)
45 actual_headers.push(header[0] + ": " + header[1]);
46 for (header of expected)
47 expected_headers.push(header[0] + ": " + header[1]);
48 assert_array_equals(actual_headers, expected_headers,
49 description + " Headers differ.");
50 }
51
52 // Helper for testing with Response objects. Compares simple
53 // attributes defined on the interfaces, as well as the headers. It
54 // does not compare the response bodies.
55 function assert_response_equals(actual, expected, description) {
56 assert_class_string(actual, "Response", description);
57 ["type", "url", "status", "ok", "statusText"].forEach(function(attribute) {
58 assert_equals(actual[attribute], expected[attribute],
59 description + " Attributes differ: " + attribute + ".");
60 });
61 assert_header_equals(actual.headers, expected.headers, description);
62 }
63
64 // Assert that the two arrays |actual| and |expected| contain the same
65 // set of Responses as determined by assert_response_equals. The order
66 // is not significant.
67 //
68 // |expected| is assumed to not contain any duplicates.
69 function assert_response_array_equivalent(actual, expected, description) {
70 assert_true(Array.isArray(actual), description);
71 assert_equals(actual.length, expected.length, description);
72 expected.forEach(function(expected_element) {
73 // assert_response_in_array treats the first argument as being
74 // 'actual', and the second as being 'expected array'. We are
75 // switching them around because we want to be resilient
76 // against the |actual| array containing duplicates.
77 assert_response_in_array(expected_element, actual, description);
78 });
79 }
80
81 // Asserts that two arrays |actual| and |expected| contain the same
82 // set of Responses as determined by assert_response_equals(). The
83 // corresponding elements must occupy corresponding indices in their
84 // respective arrays.
85 function assert_response_array_equals(actual, expected, description) {
86 assert_true(Array.isArray(actual), description);
87 assert_equals(actual.length, expected.length, description);
88 actual.forEach(function(value, index) {
89 assert_response_equals(value, expected[index],
90 description + " : object[" + index + "]");
91 });
92 }
93
94 // Equivalent to assert_in_array, but uses assert_response_equals.
95 function assert_response_in_array(actual, expected_array, description) {
96 assert_true(expected_array.some(function(element) {
97 try {
98 assert_response_equals(actual, element);
99 return true;
100 } catch (e) {
101 return false;
102 }
103 }), description);
104 }
OLDNEW
« no previous file with comments | « LayoutTests/PRESUBMIT.py ('k') | LayoutTests/http/tests/cachestorage/script-tests/cache-match.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698