| Index: LayoutTests/http/tests/cachestorage/resources/test-helpers.js
|
| diff --git a/LayoutTests/http/tests/cachestorage/resources/test-helpers.js b/LayoutTests/http/tests/cachestorage/resources/test-helpers.js
|
| index 179b02e769b44a1a15116f2c168a2be8d4ca46be..77925a0c14fef9c4d38b69344e9d228d065214dc 100644
|
| --- a/LayoutTests/http/tests/cachestorage/resources/test-helpers.js
|
| +++ b/LayoutTests/http/tests/cachestorage/resources/test-helpers.js
|
| @@ -185,3 +185,72 @@ function prepopulated_cache_test(entries, test_function, description) {
|
| });
|
| }, description);
|
| }
|
| +
|
| +// Helper for testing with Headers objects. Compares Headers instances
|
| +// by serializing |expected| and |actual| to arrays and comparing.
|
| +function assert_header_equals(actual, expected, description) {
|
| + assert_class_string(actual, "Headers", description);
|
| + var header;
|
| + var actual_headers = [];
|
| + var expected_headers = [];
|
| + for (header of actual)
|
| + actual_headers.push(header[0] + ": " + header[1]);
|
| + for (header of expected)
|
| + expected_headers.push(header[0] + ": " + header[1]);
|
| + assert_array_equals(actual_headers, expected_headers,
|
| + description + " Headers differ.");
|
| +}
|
| +
|
| +// Helper for testing with Response objects. Compares simple
|
| +// attributes defined on the interfaces, as well as the headers. It
|
| +// does not compare the response bodies.
|
| +function assert_response_equals(actual, expected, description) {
|
| + assert_class_string(actual, "Response", description);
|
| + ["type", "url", "status", "ok", "statusText"].forEach(function(attribute) {
|
| + assert_equals(actual[attribute], expected[attribute],
|
| + description + " Attributes differ: " + attribute + ".");
|
| + });
|
| + assert_header_equals(actual.headers, expected.headers, description);
|
| +}
|
| +
|
| +// Assert that the two arrays |actual| and |expected| contain the same
|
| +// set of Responses as determined by assert_response_equals. The order
|
| +// is not significant.
|
| +//
|
| +// |expected| is assumed to not contain any duplicates.
|
| +function assert_response_array_equivalent(actual, expected, description) {
|
| + assert_true(Array.isArray(actual), description);
|
| + assert_equals(actual.length, expected.length, description);
|
| + expected.forEach(function(expected_element) {
|
| + // assert_response_in_array treats the first argument as being
|
| + // 'actual', and the second as being 'expected array'. We are
|
| + // switching them around because we want to be resilient
|
| + // against the |actual| array containing duplicates.
|
| + assert_response_in_array(expected_element, actual, description);
|
| + });
|
| +}
|
| +
|
| +// Asserts that two arrays |actual| and |expected| contain the same
|
| +// set of Responses as determined by assert_response_equals(). The
|
| +// corresponding elements must occupy corresponding indices in their
|
| +// respective arrays.
|
| +function assert_response_array_equals(actual, expected, description) {
|
| + assert_true(Array.isArray(actual), description);
|
| + assert_equals(actual.length, expected.length, description);
|
| + actual.forEach(function(value, index) {
|
| + assert_response_equals(value, expected[index],
|
| + description + " : object[" + index + "]");
|
| + });
|
| +}
|
| +
|
| +// Equivalent to assert_in_array, but uses assert_response_equals.
|
| +function assert_response_in_array(actual, expected_array, description) {
|
| + assert_true(expected_array.some(function(element) {
|
| + try {
|
| + assert_response_equals(actual, element);
|
| + return true;
|
| + } catch (e) {
|
| + return false;
|
| + }
|
| + }), description);
|
| +}
|
|
|