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

Unified Diff: LayoutTests/http/tests/serviceworker/resources/cache-match-worker.js

Issue 705343002: [ServiceWorker] Serialize Cache.put() calls in Cache.match tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@no-fragments
Patch Set: Update test expectations Created 6 years, 1 month 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
« no previous file with comments | « LayoutTests/http/tests/serviceworker/cache-match-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: LayoutTests/http/tests/serviceworker/resources/cache-match-worker.js
diff --git a/LayoutTests/http/tests/serviceworker/resources/cache-match-worker.js b/LayoutTests/http/tests/serviceworker/resources/cache-match-worker.js
index 654706a9aa853544d92db8fe50e6a4da00b687f0..3b7cd65bdbe8b2d7a9ebafddbc4567e20e0638fc 100644
--- a/LayoutTests/http/tests/serviceworker/resources/cache-match-worker.js
+++ b/LayoutTests/http/tests/serviceworker/resources/cache-match-worker.js
@@ -2,105 +2,116 @@ importScripts('worker-testharness.js');
importScripts('/resources/testharness-helpers.js');
// A set of Request/Response pairs to be used with prepopulated_cache_test().
-var simple_entries = {
- a: {
+var simple_entries = [
+ {
+ name: 'a',
request: new Request('http://example.com/a'),
response: new Response('')
},
- b: {
+ {
+ name: 'b',
request: new Request('http://example.com/b'),
response: new Response('')
},
- a_with_query: {
+ {
+ name: 'a_with_query',
request: new Request('http://example.com/a?q=r'),
response: new Response('')
},
- A: {
+ {
+ name: 'A',
request: new Request('http://example.com/A'),
response: new Response('')
},
- a_https: {
+ {
+ name: 'a_https',
request: new Request('https://example.com/a'),
response: new Response('')
},
- a_org: {
+ {
+ name: 'a_org',
request: new Request('http://example.org/a'),
response: new Response('')
},
- cat: {
+ {
+ name: 'cat',
request: new Request('http://example.com/cat'),
response: new Response('')
},
- catmandu: {
+ {
+ name: 'catmandu',
request: new Request('http://example.com/catmandu'),
response: new Response('')
},
- cat_num_lives: {
+ {
+ name: 'cat_num_lives',
request: new Request('http://example.com/cat?lives=9'),
response: new Response('')
},
- cat_in_the_hat: {
+ {
+ name: 'cat_in_the_hat',
request: new Request('http://example.com/cat/in/the/hat'),
response: new Response('')
},
- secret_cat: {
+ {
+ name: 'secret_cat',
request: new Request('http://tom:jerry@example.com/cat'),
response: new Response('')
},
- top_secret_cat: {
+ {
+ name: 'top_secret_cat',
request: new Request('http://tom:j3rry@example.com/cat'),
response: new Response('')
}
-};
+];
// A set of Request/Response pairs to be used with prepopulated_cache_test().
// These contain a mix of test cases that use Vary headers.
-var vary_entries = {
- no_vary_header: {
- request: new Request('http://example.com/c'),
- response: new Response('')
- },
-
- vary_cookie_is_cookie: {
+var vary_entries = [
+ {
+ name: 'vary_cookie_is_cookie',
request: new Request('http://example.com/c',
{headers: {'Cookies': 'is-for-cookie'}}),
response: new Response('',
{headers: {'Vary': 'Cookies'}})
},
- vary_cookie_is_good: {
+ {
+ name: 'vary_cookie_is_good',
request: new Request('http://example.com/c',
{headers: {'Cookies': 'is-good-enough-for-me'}}),
response: new Response('',
{headers: {'Vary': 'Cookies'}})
},
- vary_cookie_absent: {
+ {
+ name: 'vary_cookie_absent',
request: new Request('http://example.com/c'),
response: new Response('',
{headers: {'Vary': 'Cookies'}})
},
- vary_wildcard: {
+ {
+ name: 'vary_wildcard',
request: new Request('http://example.com/c',
{headers: {'Cookies': 'x', 'X-Key': '1'}}),
response: new Response('',
{headers: {'Vary': '*'}})
}
-};
+];
-prepopulated_cache_test(simple_entries, function(cache) {
+prepopulated_cache_test(simple_entries, function(cache, entries) {
return cache.matchAll('not-present-in-the-cache')
.then(function(result) {
assert_array_equivalent(
@@ -109,7 +120,7 @@ prepopulated_cache_test(simple_entries, function(cache) {
});
}, 'Cache.matchAll with no matching entries');
-prepopulated_cache_test(simple_entries, function(cache) {
+prepopulated_cache_test(simple_entries, function(cache, entries) {
return cache.match('not-present-in-the-cache')
.then(function(result) {
assert_equals(result, undefined,
@@ -117,52 +128,52 @@ prepopulated_cache_test(simple_entries, function(cache) {
});
}, 'Cache.match with no matching entries');
-prepopulated_cache_test(simple_entries, function(cache) {
- return cache.matchAll(simple_entries.a.request.url)
+prepopulated_cache_test(simple_entries, function(cache, entries) {
+ return cache.matchAll(entries.a.request.url)
.then(function(result) {
- assert_array_objects_equals(result, [simple_entries.a.response],
+ assert_array_objects_equals(result, [entries.a.response],
'Cache.matchAll should match by URL.');
});
}, 'Cache.matchAll with URL');
-prepopulated_cache_test(simple_entries, function(cache) {
- return cache.match(simple_entries.a.request.url)
+prepopulated_cache_test(simple_entries, function(cache, entries) {
+ return cache.match(entries.a.request.url)
.then(function(result) {
- assert_object_equals(result, simple_entries.a.response,
+ assert_object_equals(result, entries.a.response,
'Cache.match should match by URL.');
});
}, 'Cache.match with URL');
-prepopulated_cache_test(simple_entries, function(cache) {
- return cache.matchAll(simple_entries.a.request)
+prepopulated_cache_test(simple_entries, function(cache, entries) {
+ return cache.matchAll(entries.a.request)
.then(function(result) {
assert_array_objects_equals(
- result, [simple_entries.a.response],
+ result, [entries.a.response],
'Cache.matchAll should match by Request.');
});
}, 'Cache.matchAll with Request');
-prepopulated_cache_test(simple_entries, function(cache) {
- return cache.match(simple_entries.a.request)
+prepopulated_cache_test(simple_entries, function(cache, entries) {
+ return cache.match(entries.a.request)
.then(function(result) {
- assert_object_equals(result, simple_entries.a.response,
+ assert_object_equals(result, entries.a.response,
'Cache.match should match by Request.');
});
}, 'Cache.match with Request');
-prepopulated_cache_test(simple_entries, function(cache) {
- return cache.matchAll(new Request(simple_entries.a.request.url))
+prepopulated_cache_test(simple_entries, function(cache, entries) {
+ return cache.matchAll(new Request(entries.a.request.url))
.then(function(result) {
assert_array_objects_equals(
- result, [simple_entries.a.response],
+ result, [entries.a.response],
'Cache.matchAll should match by Request.');
});
}, 'Cache.matchAll with new Request');
-prepopulated_cache_test(simple_entries, function(cache) {
- return cache.match(new Request(simple_entries.a.request.url))
+prepopulated_cache_test(simple_entries, function(cache, entries) {
+ return cache.match(new Request(entries.a.request.url))
.then(function(result) {
- assert_object_equals(result, simple_entries.a.response,
+ assert_object_equals(result, entries.a.response,
'Cache.match should match by Request.');
});
}, 'Cache.match with new Request');
@@ -193,15 +204,15 @@ cache_test(function(cache) {
});
}, 'Cache.match with Request containing non-empty body');
-prepopulated_cache_test(simple_entries, function(cache) {
- return cache.matchAll(simple_entries.a.request,
+prepopulated_cache_test(simple_entries, function(cache, entries) {
+ return cache.matchAll(entries.a.request,
{ignoreSearch: true})
.then(function(result) {
assert_array_equivalent(
result,
[
- simple_entries.a.response,
- simple_entries.a_with_query.response
+ entries.a.response,
+ entries.a_with_query.response
],
'Cache.matchAll with ignoreSearch should ignore the ' +
'search parameters of cached request.');
@@ -210,15 +221,15 @@ prepopulated_cache_test(simple_entries, function(cache) {
'Cache.matchAll with ignoreSearch option (request with no search ' +
'parameters)');
-prepopulated_cache_test(simple_entries, function(cache) {
- return cache.match(simple_entries.a.request,
+prepopulated_cache_test(simple_entries, function(cache, entries) {
+ return cache.match(entries.a.request,
{ignoreSearch: true})
.then(function(result) {
assert_object_in_array(
result,
[
- simple_entries.a.response,
- simple_entries.a_with_query.response
+ entries.a.response,
+ entries.a_with_query.response
],
'Cache.match with ignoreSearch should ignore the ' +
'search parameters of cached request.');
@@ -227,15 +238,15 @@ prepopulated_cache_test(simple_entries, function(cache) {
'Cache.match with ignoreSearch option (request with no search ' +
'parameters)');
-prepopulated_cache_test(simple_entries, function(cache) {
- return cache.matchAll(simple_entries.a_with_query.request,
+prepopulated_cache_test(simple_entries, function(cache, entries) {
+ return cache.matchAll(entries.a_with_query.request,
{ignoreSearch: true})
.then(function(result) {
assert_array_equivalent(
result,
[
- simple_entries.a.response,
- simple_entries.a_with_query.response
+ entries.a.response,
+ entries.a_with_query.response
],
'Cache.matchAll with ignoreSearch should ignore the ' +
'search parameters of request.');
@@ -243,15 +254,15 @@ prepopulated_cache_test(simple_entries, function(cache) {
},
'Cache.matchAll with ignoreSearch option (request with search parameter)');
-prepopulated_cache_test(simple_entries, function(cache) {
- return cache.match(simple_entries.a_with_query.request,
+prepopulated_cache_test(simple_entries, function(cache, entries) {
+ return cache.match(entries.a_with_query.request,
{ignoreSearch: true})
.then(function(result) {
assert_object_in_array(
result,
[
- simple_entries.a.response,
- simple_entries.a_with_query.response
+ entries.a.response,
+ entries.a_with_query.response
],
'Cache.match with ignoreSearch should ignore the ' +
'search parameters of request.');
@@ -259,27 +270,27 @@ prepopulated_cache_test(simple_entries, function(cache) {
},
'Cache.match with ignoreSearch option (request with search parameter)');
-prepopulated_cache_test(simple_entries, function(cache) {
- return cache.matchAll(simple_entries.cat.request.url + '#mouse')
+prepopulated_cache_test(simple_entries, function(cache, entries) {
+ return cache.matchAll(entries.cat.request.url + '#mouse')
.then(function(result) {
assert_array_equivalent(
result,
[
- simple_entries.cat.response,
+ entries.cat.response,
],
'Cache.matchAll should ignore URL fragment.');
});
}, 'Cache.matchAll with URL containing fragment');
-prepopulated_cache_test(simple_entries, function(cache) {
- return cache.match(simple_entries.cat.request.url + '#mouse')
+prepopulated_cache_test(simple_entries, function(cache, entries) {
+ return cache.match(entries.cat.request.url + '#mouse')
.then(function(result) {
- assert_object_equals(result, simple_entries.cat.response,
+ assert_object_equals(result, entries.cat.response,
'Cache.match should ignore URL fragment.');
});
}, 'Cache.match with URL containing fragment');
-prepopulated_cache_test(simple_entries, function(cache) {
+prepopulated_cache_test(simple_entries, function(cache, entries) {
return cache.matchAll('http')
.then(function(result) {
assert_array_equivalent(
@@ -289,7 +300,7 @@ prepopulated_cache_test(simple_entries, function(cache) {
});
}, 'Cache.matchAll with string fragment "http" as query');
-prepopulated_cache_test(simple_entries, function(cache) {
+prepopulated_cache_test(simple_entries, function(cache, entries) {
return cache.match('http')
.then(function(result) {
assert_equals(
@@ -299,80 +310,80 @@ prepopulated_cache_test(simple_entries, function(cache) {
});
}, 'Cache.match with string fragment "http" as query');
-prepopulated_cache_test(simple_entries, function(cache) {
+prepopulated_cache_test(simple_entries, function(cache, entries) {
return cache.matchAll('http://example.com/cat',
{prefixMatch: true})
.then(function(result) {
assert_array_equivalent(
result,
[
- simple_entries.cat.response,
- simple_entries.catmandu.response,
- simple_entries.cat_num_lives.response,
- simple_entries.cat_in_the_hat.response
+ entries.cat.response,
+ entries.catmandu.response,
+ entries.cat_num_lives.response,
+ entries.cat_in_the_hat.response
],
'Cache.matchAll should honor prefixMatch.');
});
}, 'Cache.matchAll with prefixMatch option');
-prepopulated_cache_test(simple_entries, function(cache) {
+prepopulated_cache_test(simple_entries, function(cache, entries) {
return cache.match('http://example.com/cat',
{prefixMatch: true})
.then(function(result) {
assert_object_in_array(
result,
[
- simple_entries.cat.response,
- simple_entries.catmandu.response,
- simple_entries.cat_num_lives.response,
- simple_entries.cat_in_the_hat.response
+ entries.cat.response,
+ entries.catmandu.response,
+ entries.cat_num_lives.response,
+ entries.cat_in_the_hat.response
],
'Cache.match should honor prefixMatch.');
});
}, 'Cache.match with prefixMatch option');
-prepopulated_cache_test(simple_entries, function(cache) {
+prepopulated_cache_test(simple_entries, function(cache, entries) {
return cache.matchAll('http://example.com/cat/',
{prefixMatch: true})
.then(function(result) {
assert_array_equivalent(
- result, [simple_entries.cat_in_the_hat.response],
+ result, [entries.cat_in_the_hat.response],
'Cache.matchAll should honor prefixMatch.');
});
}, 'Cache.matchAll with prefixMatch option (URL ending with path delimiter)');
-prepopulated_cache_test(simple_entries, function(cache) {
+prepopulated_cache_test(simple_entries, function(cache, entries) {
return cache.match('http://example.com/cat/',
{prefixMatch: true})
.then(function(result) {
assert_object_equals(
- result, simple_entries.cat_in_the_hat.response,
+ result, entries.cat_in_the_hat.response,
'Cache.match should honor prefixMatch.');
});
}, 'Cache.match with prefixMatch option (URL ending with path delimiter)');
-prepopulated_cache_test(simple_entries, function(cache) {
+prepopulated_cache_test(simple_entries, function(cache, entries) {
return cache.matchAll('http://tom:jerry@example.com', {prefixMatch: true})
.then(function(result) {
assert_array_equivalent(
result,
[
- simple_entries.secret_cat.response,
+ entries.secret_cat.response,
],
'Cache.matchAll should honor prefixMatch.');
});
}, 'Cache.matchAll with prefixMatch option (URL with embedded credentials)');
-prepopulated_cache_test(simple_entries, function(cache) {
+prepopulated_cache_test(simple_entries, function(cache, entries) {
return cache.match('http://tom:jerry@example.com', {prefixMatch: true})
.then(function(result) {
assert_object_equals(
- result, simple_entries.secret_cat.response,
+ result, entries.secret_cat.response,
'Cache.match should honor prefixMatch.');
});
}, 'Cache.match with prefixMatch option (URL with embedded credentials)');
-prepopulated_cache_test(simple_entries, function(cache) {
+prepopulated_cache_test(simple_entries, function(cache, entries) {
// The string 'http://tom' should be converted to a URL and then serialized
// yielding 'http://tom/'. The trailing slash prevents the URL from matching
// the embedded credentials in the entries already in the cache.
@@ -385,7 +396,7 @@ prepopulated_cache_test(simple_entries, function(cache) {
},
'Cache.matchAll with prefixMatch option (URL matching embedded credentials)');
-prepopulated_cache_test(simple_entries, function(cache) {
+prepopulated_cache_test(simple_entries, function(cache, entries) {
// The string 'http://tom' should be converted to a URL and then serialized
// yielding 'http://tom/'. The trailing slash prevents the URL from matching
// the embedded credentials in the entries already in the cache.
@@ -397,33 +408,32 @@ prepopulated_cache_test(simple_entries, function(cache) {
},
'Cache.match with prefixMatch option (URL matching embedded credentials)');
-prepopulated_cache_test(simple_entries, function(cache) {
- return cache.matchAll(simple_entries.secret_cat.request.url)
+prepopulated_cache_test(simple_entries, function(cache, entries) {
+ return cache.matchAll(entries.secret_cat.request.url)
.then(function(result) {
assert_array_equivalent(
- result, [simple_entries.secret_cat.response],
+ result, [entries.secret_cat.response],
'Cache.matchAll should not ignore embedded credentials');
});
}, 'Cache.matchAll with URL containing credentials');
-prepopulated_cache_test(simple_entries, function(cache) {
- return cache.match(simple_entries.secret_cat.request.url)
+prepopulated_cache_test(simple_entries, function(cache, entries) {
+ return cache.match(entries.secret_cat.request.url)
.then(function(result) {
assert_object_equals(
- result, simple_entries.secret_cat.response,
+ result, entries.secret_cat.response,
'Cache.match should not ignore embedded credentials');
});
}, 'Cache.match with URL containing credentials');
-prepopulated_cache_test(vary_entries, function(cache) {
+prepopulated_cache_test(vary_entries, function(cache, entries) {
return cache.matchAll('http://example.com/c')
.then(function(result) {
assert_array_equivalent(
result,
[
- vary_entries.no_vary_header.response,
- vary_entries.vary_wildcard.response,
- vary_entries.vary_cookie_absent.response
+ entries.vary_wildcard.response,
+ entries.vary_cookie_absent.response
],
'Cache.matchAll should exclude matches if a vary header is ' +
'missing in the query request, but is present in the cached ' +
@@ -439,8 +449,7 @@ prepopulated_cache_test(vary_entries, function(cache) {
assert_array_equivalent(
result,
[
- vary_entries.no_vary_header.response,
- vary_entries.vary_wildcard.response
+ entries.vary_wildcard.response
],
'Cache.matchAll should exclude matches if a vary header is ' +
'missing in the cached request, but is present in the query ' +
@@ -455,38 +464,36 @@ prepopulated_cache_test(vary_entries, function(cache) {
.then(function(result) {
assert_array_equivalent(
result,
- [vary_entries.vary_cookie_is_cookie.response],
+ [entries.vary_cookie_is_cookie.response],
'Cache.matchAll should match the entire header if a vary header ' +
'is present in both the query and cached requests.');
});
}, 'Cache.matchAll with responses containing "Vary" header');
-prepopulated_cache_test(vary_entries, function(cache) {
+prepopulated_cache_test(vary_entries, function(cache, entries) {
return cache.match('http://example.com/c')
.then(function(result) {
assert_object_in_array(
result,
[
- vary_entries.no_vary_header.response,
- vary_entries.vary_wildcard.response,
- vary_entries.vary_cookie_absent.response
+ entries.vary_wildcard.response,
+ entries.vary_cookie_absent.response
],
'Cache.match should honor "Vary" header.');
});
}, 'Cache.match with responses containing "Vary" header');
-prepopulated_cache_test(vary_entries, function(cache) {
+prepopulated_cache_test(vary_entries, function(cache, entries) {
return cache.matchAll('http://example.com/c',
{ignoreVary: true})
.then(function(result) {
assert_array_equivalent(
result,
[
- vary_entries.no_vary_header.response,
- vary_entries.vary_cookie_is_cookie.response,
- vary_entries.vary_cookie_is_good.response,
- vary_entries.vary_cookie_absent.response,
- vary_entries.vary_wildcard.response
+ entries.vary_cookie_is_cookie.response,
+ entries.vary_cookie_is_good.response,
+ entries.vary_cookie_absent.response,
+ entries.vary_wildcard.response
],
'Cache.matchAll should honor "ignoreVary" parameter.');
});
@@ -557,19 +564,30 @@ cache_test(function(cache) {
// Run |test_function| with a Cache object as its only parameter. 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>}.
+// {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) {
- return Promise.all(Object.keys(entries).map(function(k) {
- return cache.put(entries[k].request, entries[k].response)
- .catch(function(e) {
- assert_unreached('Test setup failed for entry ' + k + ' : ' + e);
- });
- }))
- .then(function() {
- return test_function(cache);
- });
+ var p = Promise.resolve();
+ var hash = {};
+ entries.forEach(function(entry) {
+ p = p.then(function() {
+ return cache.put(entry.request, entry.response)
+ .catch(function(e) {
+ assert_unreached('Test setup failed for entry ' +
+ entry.name + ': ' + e);
+ });
+ });
+ hash[entry.name] = entry;
+ });
+ p = p.then(function() {
+ assert_equals(Object.keys(hash).length, entries.length);
+ });
+
+ return p.then(function() {
+ return test_function(cache, hash);
+ });
}, description);
}
« no previous file with comments | « LayoutTests/http/tests/serviceworker/cache-match-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698