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

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/service-workers/cache-storage/script-tests/cache-match.js

Issue 2790143003: Cache Storage API tests: Fix WPT test bugs, remove redundant local copies (Closed)
Patch Set: Created 3 years, 8 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
OLDNEW
1 if (self.importScripts) { 1 if (self.importScripts) {
2 importScripts('/resources/testharness.js'); 2 importScripts('/resources/testharness.js');
3 importScripts('../resources/test-helpers.js'); 3 importScripts('../resources/test-helpers.js');
4 } 4 }
5 5
6 prepopulated_cache_test(simple_entries, function(cache, entries) { 6 prepopulated_cache_test(simple_entries, function(cache, entries) {
7 return cache.match('not-present-in-the-cache') 7 return cache.match('not-present-in-the-cache')
8 .then(function(result) { 8 .then(function(result) {
9 assert_equals(result, undefined, 9 assert_equals(result, undefined,
10 'Cache.match failures should resolve with undefined.'); 10 'Cache.match failures should resolve with undefined.');
(...skipping 10 matching lines...) Expand all
21 21
22 prepopulated_cache_test(simple_entries, function(cache, entries) { 22 prepopulated_cache_test(simple_entries, function(cache, entries) {
23 return cache.match(entries.a.request) 23 return cache.match(entries.a.request)
24 .then(function(result) { 24 .then(function(result) {
25 assert_response_equals(result, entries.a.response, 25 assert_response_equals(result, entries.a.response,
26 'Cache.match should match by Request.'); 26 'Cache.match should match by Request.');
27 }); 27 });
28 }, 'Cache.match with Request'); 28 }, 'Cache.match with Request');
29 29
30 prepopulated_cache_test(simple_entries, function(cache, entries) { 30 prepopulated_cache_test(simple_entries, function(cache, entries) {
31 var alt_response = new Response('', {status: 201});
32
33 return self.caches.open('second_matching_cache')
34 .then(function(cache) {
35 return cache.put(entries.a.request, alt_response.clone());
36 })
37 .then(function() {
38 return cache.match(entries.a.request);
39 })
40 .then(function(result) {
41 assert_response_equals(
42 result, entries.a.response,
43 'Cache.match should match the first cache.');
44 });
45 }, 'Cache.match with multiple cache hits');
46
47 prepopulated_cache_test(simple_entries, function(cache, entries) {
31 return cache.match(new Request(entries.a.request.url)) 48 return cache.match(new Request(entries.a.request.url))
32 .then(function(result) { 49 .then(function(result) {
33 assert_response_equals(result, entries.a.response, 50 assert_response_equals(result, entries.a.response,
34 'Cache.match should match by Request.'); 51 'Cache.match should match by Request.');
35 }); 52 });
36 }, 'Cache.match with new Request'); 53 }, 'Cache.match with new Request');
37 54
38 prepopulated_cache_test(simple_entries, function(cache, entries) { 55 prepopulated_cache_test(simple_entries, function(cache, entries) {
39 return cache.match(new Request(entries.a.request.url, {method: 'HEAD'})) 56 return cache.match(new Request(entries.a.request.url, {method: 'HEAD'}))
40 .then(function(result) { 57 .then(function(result) {
(...skipping 28 matching lines...) Expand all
69 [ 86 [
70 entries.a.response, 87 entries.a.response,
71 entries.a_with_query.response 88 entries.a_with_query.response
72 ], 89 ],
73 'Cache.match with ignoreSearch should ignore the ' + 90 'Cache.match with ignoreSearch should ignore the ' +
74 'search parameters of request.'); 91 'search parameters of request.');
75 }); 92 });
76 }, 93 },
77 'Cache.match with ignoreSearch option (request with search parameter)'); 94 'Cache.match with ignoreSearch option (request with search parameter)');
78 95
96 cache_test(function(cache) {
97 var request = new Request('http://example.com/');
98 var head_request = new Request('http://example.com/', {method: 'HEAD'});
99 var response = new Response('foo');
100 return cache.put(request.clone(), response.clone())
101 .then(function() {
102 return cache.match(head_request.clone());
103 })
104 .then(function(result) {
105 assert_equals(
106 result, undefined,
107 'Cache.match should resolve as undefined with a ' +
108 'mismatched method.');
109 return cache.match(head_request.clone(),
110 {ignoreMethod: true});
111 })
112 .then(function(result) {
113 assert_response_equals(
114 result, response,
115 'Cache.match with ignoreMethod should ignore the ' +
116 'method of request.');
117 });
118 }, 'Cache.match supports ignoreMethod');
119
120 cache_test(function(cache) {
121 var vary_request = new Request('http://example.com/c',
122 {headers: {'Cookies': 'is-for-cookie'}});
123 var vary_response = new Response('', {headers: {'Vary': 'Cookies'}});
124 var mismatched_vary_request = new Request('http://example.com/c');
125
126 return cache.put(vary_request.clone(), vary_response.clone())
127 .then(function() {
128 return cache.match(mismatched_vary_request.clone());
129 })
130 .then(function(result) {
131 assert_equals(
132 result, undefined,
133 'Cache.match should resolve as undefined with a ' +
134 'mismatched vary.');
135 return cache.match(mismatched_vary_request.clone(),
136 {ignoreVary: true});
137 })
138 .then(function(result) {
139 assert_response_equals(
140 result, vary_response,
141 'Cache.match with ignoreVary should ignore the ' +
142 'vary of request.');
143 });
144 }, 'Cache.match supports ignoreVary');
145
79 prepopulated_cache_test(simple_entries, function(cache, entries) { 146 prepopulated_cache_test(simple_entries, function(cache, entries) {
80 return cache.match(entries.cat.request.url + '#mouse') 147 return cache.match(entries.cat.request.url + '#mouse')
81 .then(function(result) { 148 .then(function(result) {
82 assert_response_equals(result, entries.cat.response, 149 assert_response_equals(result, entries.cat.response,
83 'Cache.match should ignore URL fragment.'); 150 'Cache.match should ignore URL fragment.');
84 }); 151 });
85 }, 'Cache.match with URL containing fragment'); 152 }, 'Cache.match with URL containing fragment');
86 153
87 prepopulated_cache_test(simple_entries, function(cache, entries) { 154 prepopulated_cache_test(simple_entries, function(cache, entries) {
88 return cache.match('http') 155 return cache.match('http')
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 .then(function(result) { 226 .then(function(result) {
160 return result.text(); 227 return result.text();
161 }) 228 })
162 .then(function(body_text) { 229 .then(function(body_text) {
163 assert_equals(body_text, 'a simple text file\n', 230 assert_equals(body_text, 'a simple text file\n',
164 'Cache.match should return a Response object with a ' + 231 'Cache.match should return a Response object with a ' +
165 'valid body each time it is called.'); 232 'valid body each time it is called.');
166 }); 233 });
167 }, 'Cache.match invoked multiple times for the same Request/Response'); 234 }, 'Cache.match invoked multiple times for the same Request/Response');
168 235
236 cache_test(function(cache) {
237 var request_url = new URL('../resources/simple.txt', location.href).href;
238 return fetch(request_url)
239 .then(function(fetch_result) {
240 return cache.put(new Request(request_url), fetch_result);
241 })
242 .then(function() {
243 return cache.match(request_url);
244 })
245 .then(function(result) {
246 return result.blob();
247 })
248 .then(function(blob) {
249 var sliced = blob.slice(2,8);
250
251 return new Promise(function (resolve, reject) {
252 var reader = new FileReader();
253 reader.onloadend = function(event) {
254 resolve(event.target.result);
255 };
256 reader.readAsText(sliced);
257 });
258 })
259 .then(function(text) {
260 assert_equals(text, 'simple',
261 'A Response blob returned by Cache.match should be ' +
262 'sliceable.' );
263 });
264 }, 'Cache.match blob should be sliceable');
265
169 prepopulated_cache_test(simple_entries, function(cache, entries) { 266 prepopulated_cache_test(simple_entries, function(cache, entries) {
170 var request = new Request(entries.a.request.clone(), {method: 'POST'}); 267 var request = new Request(entries.a.request.clone(), {method: 'POST'});
171 return cache.match(request) 268 return cache.match(request)
172 .then(function(result) { 269 .then(function(result) {
173 assert_equals(result, undefined, 270 assert_equals(result, undefined,
174 'Cache.match should not find a match'); 271 'Cache.match should not find a match');
175 }); 272 });
176 }, 'Cache.match with POST Request'); 273 }, 'Cache.match with POST Request');
177 274
178 prepopulated_cache_test(simple_entries, function(cache, entries) { 275 prepopulated_cache_test(simple_entries, function(cache, entries) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 }) 308 })
212 .then(function(r) { 309 .then(function(r) {
213 // Make sure the original response is not GC'd. 310 // Make sure the original response is not GC'd.
214 response = r; 311 response = r;
215 // Return only the clone. We purposefully test that the other 312 // Return only the clone. We purposefully test that the other
216 // half of the clone does not need to be read here. 313 // half of the clone does not need to be read here.
217 return response.clone().text(); 314 return response.clone().text();
218 }) 315 })
219 .then(function(text) { 316 .then(function(text) {
220 assert_equals(text, data.toString(), 'cloned body text can be read cor rectly'); 317 assert_equals(text, data.toString(), 'cloned body text can be read cor rectly');
221 }) 318 });
222 }, 'Cache produces large Responses that can be cloned and read correctly.'); 319 }, 'Cache produces large Responses that can be cloned and read correctly.');
223 320
224 done(); 321 done();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698