1 if (self
.importScripts
) {
2 importScripts('/resources/testharness.js');
3 importScripts('/resources/testharness-helpers.js');
4 importScripts('../resources/test-helpers.js');
7 prepopulated_cache_test(simple_entries
, function(cache
, entries
) {
8 return cache
.matchAll('not-present-in-the-cache')
9 .then(function(result
) {
10 assert_response_array_equivalent(
12 'Cache.matchAll should resolve with an empty array on failure.');
14 }, 'Cache.matchAll with no matching entries');
16 prepopulated_cache_test(simple_entries
, function(cache
, entries
) {
17 return cache
.matchAll(entries
.a
.request
.url
)
18 .then(function(result
) {
19 assert_response_array_equivalent(result
, [entries
.a
.response
],
20 'Cache.matchAll should match by URL.');
22 }, 'Cache.matchAll with URL');
24 prepopulated_cache_test(simple_entries
, function(cache
, entries
) {
25 return cache
.matchAll(entries
.a
.request
)
26 .then(function(result
) {
27 assert_response_array_equivalent(result
, [entries
.a
.response
],
28 'Cache.matchAll should match by Request.');
30 }, 'Cache.matchAll with Request');
32 prepopulated_cache_test(simple_entries
, function(cache
, entries
) {
33 return cache
.matchAll(new Request(entries
.a
.request
.url
))
34 .then(function(result
) {
35 assert_response_array_equivalent(result
, [entries
.a
.response
],
36 'Cache.matchAll should match by Request.');
38 }, 'Cache.matchAll with new Request');
40 prepopulated_cache_test(simple_entries
, function(cache
, entries
) {
41 return cache
.matchAll(entries
.a
.request
,
43 .then(function(result
) {
44 assert_response_array_equivalent(
48 entries
.a_with_query
.response
50 'Cache.matchAll with ignoreSearch should ignore the ' +
51 'search parameters of cached request.');
54 'Cache.matchAll with ignoreSearch option (request with no search ' +
57 prepopulated_cache_test(simple_entries
, function(cache
, entries
) {
58 return cache
.matchAll(entries
.a_with_query
.request
,
60 .then(function(result
) {
61 assert_response_array_equivalent(
65 entries
.a_with_query
.response
67 'Cache.matchAll with ignoreSearch should ignore the ' +
68 'search parameters of request.');
71 'Cache.matchAll with ignoreSearch option (request with search parameter)');
73 prepopulated_cache_test(simple_entries
, function(cache
, entries
) {
74 return cache
.matchAll(entries
.cat
.request
.url
+ '#mouse')
75 .then(function(result
) {
76 assert_response_array_equivalent(
81 'Cache.matchAll should ignore URL fragment.');
83 }, 'Cache.matchAll with URL containing fragment');
85 prepopulated_cache_test(simple_entries
, function(cache
, entries
) {
86 return cache
.matchAll('http')
87 .then(function(result
) {
88 assert_response_array_equivalent(
90 'Cache.matchAll should treat query as a URL and not ' +
91 'just a string fragment.');
93 }, 'Cache.matchAll with string fragment "http" as query');
95 prepopulated_cache_test(simple_entries
, function(cache
, entries
) {
96 return cache
.matchAll(entries
.secret_cat
.request
.url
)
97 .then(function(result
) {
98 assert_response_array_equivalent(
99 result
, [entries
.secret_cat
.response
],
100 'Cache.matchAll should not ignore embedded credentials');
102 }, 'Cache.matchAll with URL containing credentials');
104 prepopulated_cache_test(vary_entries
, function(cache
, entries
) {
105 return cache
.matchAll('http://example.com/c')
106 .then(function(result
) {
107 assert_response_array_equivalent(
110 entries
.vary_wildcard
.response
,
111 entries
.vary_cookie_absent
.response
113 'Cache.matchAll should exclude matches if a vary header is ' +
114 'missing in the query request, but is present in the cached ' +
119 return cache
.matchAll(
120 new Request('http://example.com/c',
121 {headers
: {'Cookies': 'none-of-the-above'}}));
123 .then(function(result
) {
124 assert_response_array_equivalent(
127 entries
.vary_wildcard
.response
129 'Cache.matchAll should exclude matches if a vary header is ' +
130 'missing in the cached request, but is present in the query ' +
135 return cache
.matchAll(
136 new Request('http://example.com/c',
137 {headers
: {'Cookies': 'is-for-cookie'}}));
139 .then(function(result
) {
140 assert_response_array_equivalent(
142 [entries
.vary_cookie_is_cookie
.response
],
143 'Cache.matchAll should match the entire header if a vary header ' +
144 'is present in both the query and cached requests.');
146 }, 'Cache.matchAll with responses containing "Vary" header');
148 prepopulated_cache_test(vary_entries
, function(cache
, entries
) {
149 return cache
.matchAll('http://example.com/c',
151 .then(function(result
) {
152 assert_response_array_equivalent(
155 entries
.vary_cookie_is_cookie
.response
,
156 entries
.vary_cookie_is_good
.response
,
157 entries
.vary_cookie_absent
.response
,
158 entries
.vary_wildcard
.response
160 'Cache.matchAll should honor "ignoreVary" parameter.');
162 }, 'Cache.matchAll with "ignoreVary" parameter');