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

Unified Diff: third_party/WebKit/LayoutTests/imported/wpt/service-workers/cache-storage/resources/test-helpers.js

Issue 2415873002: Import w3c tests for the service workers (Closed)
Patch Set: Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/imported/wpt/service-workers/cache-storage/resources/test-helpers.js
diff --git a/third_party/WebKit/LayoutTests/http/tests/cachestorage/resources/test-helpers.js b/third_party/WebKit/LayoutTests/imported/wpt/service-workers/cache-storage/resources/test-helpers.js
similarity index 69%
copy from third_party/WebKit/LayoutTests/http/tests/cachestorage/resources/test-helpers.js
copy to third_party/WebKit/LayoutTests/imported/wpt/service-workers/cache-storage/resources/test-helpers.js
index a73889773d20e9cb91a042febe6bebaeb59d7bf5..f4145e6217f5fe4d7ce7c1c8124c234838b0c985 100644
--- a/third_party/WebKit/LayoutTests/http/tests/cachestorage/resources/test-helpers.js
+++ b/third_party/WebKit/LayoutTests/imported/wpt/service-workers/cache-storage/resources/test-helpers.js
@@ -32,7 +32,7 @@
function cache_test(test_function, description) {
promise_test(function(test) {
return create_temporary_cache(test)
- .then(cache => test_function(cache, test));
+ .then(test_function);
}, description);
}
@@ -141,47 +141,29 @@ var vary_entries = [
// Run |test_function| with a Cache object and a map of entries. Prior to the
// call, the Cache is populated by cache entries from |entries|. The latter is
// expected to be an Object mapping arbitrary keys to objects of the form
-// {request: <Request object>, response: <Response object>}. The entries are
-// added sequentially so that tests can verify the ordering of the cache
-// methods.
+// {request: <Request object>, response: <Response object>}. There's no
+// guarantee on the order in which entries will be added to the cache.
//
// |test_function| should return a Promise that can be used with promise_test.
function prepopulated_cache_test(entries, test_function, description) {
cache_test(function(cache) {
+ var p = Promise.resolve();
var hash = {};
- var resolveMethod = null;
-
- var promise = new Promise(function(resolve, reject) {
- resolveMethod = resolve;
+ return Promise.all(entries.map(function(entry) {
+ hash[entry.name] = entry;
+ return cache.put(entry.request.clone(),
+ entry.response.clone())
+ .catch(function(e) {
+ assert_unreached(
+ 'Test setup failed for entry ' + entry.name + ': ' + e);
+ });
+ }))
+ .then(function() {
+ assert_equals(Object.keys(hash).length, entries.length);
})
- .then(function() {
- assert_equals(Object.keys(hash).length, entries.length);
- return test_function(cache, hash);
+ .then(function() {
+ return test_function(cache, hash);
});
-
- // Add the entries to the cache sequentially.
- // TODO(jkarlin): Once async/await is available use it to prettify this
- // code.
- var i = 0;
- var processNextEntry = function(i) {
- if (i == entries.length) {
- resolveMethod();
- return;
- }
- entry = entries[i];
- hash[entry.name] = entry;
- cache.put(entry.request.clone(), entry.response.clone())
- .then(function() {
- processNextEntry(i+1);
- })
- .catch(function(e) {
- assert_unreached(
- 'Test setup failed for entry ' + entry.name + ': ' + e);
- })
- }
-
- processNextEntry(0);
- return promise;
}, description);
}
@@ -212,80 +194,41 @@ function assert_response_equals(actual, expected, description) {
assert_header_equals(actual.headers, expected.headers, 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);
-}
-
-// Helper for testing with Request objects. Compares simple
-// attributes defined on the interfaces, as well as the headers.
-function assert_request_equals(actual, expected, description) {
- assert_class_string(actual, "Request", description);
- ["url"].forEach(function(attribute) {
- assert_equals(actual[attribute], expected[attribute],
- description + " Attributes differ: " + attribute + ".");
- });
- assert_header_equals(actual.headers, expected.headers, description);
-}
-
-// TODO(zino): Should remove this function once keys() returns request
-// keys in key insertion order. Please see http://crbug.com/627821.
-//
// Assert that the two arrays |actual| and |expected| contain the same
-// set of Requests as determined by assert_request_equals. The order
+// set of Responses as determined by assert_response_equals. The order
// is not significant.
//
// |expected| is assumed to not contain any duplicates.
-function assert_request_array_equivalent(actual, expected, description) {
+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_request_in_array treats the first argument as being
+ // 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_request_in_array(expected_element, actual, description);
+ assert_response_in_array(expected_element, actual, description);
});
}
// Asserts that two arrays |actual| and |expected| contain the same
-// set of Requests as determined by assert_request_equals(). The
+// set of Responses as determined by assert_response_equals(). The
// corresponding elements must occupy corresponding indices in their
// respective arrays.
-function assert_request_array_equals(actual, expected, description) {
+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_request_equals(value, expected[index],
- description + " : object[" + index + "]");
+ assert_response_equals(value, expected[index],
+ description + " : object[" + index + "]");
});
}
-// Equivalent to assert_in_array, but uses assert_request_equals.
-function assert_request_in_array(actual, expected_array, description) {
+// 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_request_equals(actual, element);
+ assert_response_equals(actual, element);
return true;
} catch (e) {
return false;

Powered by Google App Engine
This is Rietveld 408576698