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

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

Issue 2547023002: Import wpt@3c8896ae408c8fd594979da7c99970029e7856a7 (Closed)
Patch Set: Modify TestExpectations or download new baselines for tests. Created 4 years 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/testharness-helpers.js');
4 importScripts('../resources/test-helpers.js'); 3 importScripts('../resources/test-helpers.js');
5 } 4 }
6 5
7 var test_url = 'https://example.com/foo'; 6 var test_url = 'https://example.com/foo';
8 var test_body = 'Hello world!'; 7 var test_body = 'Hello world!';
9 8
10 cache_test(function(cache) { 9 cache_test(function(cache) {
11 var request = new Request(test_url); 10 var request = new Request(test_url);
12 var response = new Response(test_body); 11 var response = new Response(test_body);
13 return cache.put(request, response) 12 return cache.put(request, response)
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 var url = 'http://example.com/foo'; 182 var url = 'http://example.com/foo';
184 return cache.put(url, new Response('some body')) 183 return cache.put(url, new Response('some body'))
185 .then(function() { return cache.match(url); }) 184 .then(function() { return cache.match(url); })
186 .then(function(response) { return response.text(); }) 185 .then(function(response) { return response.text(); })
187 .then(function(body) { 186 .then(function(body) {
188 assert_equals(body, 'some body', 187 assert_equals(body, 'some body',
189 'Cache.put should accept a string as request.'); 188 'Cache.put should accept a string as request.');
190 }); 189 });
191 }, 'Cache.put with a string request'); 190 }, 'Cache.put with a string request');
192 191
193 cache_test(function(cache) { 192 cache_test(function(cache, test) {
194 return assert_promise_rejects( 193 return promise_rejects(
194 test,
195 new TypeError(),
195 cache.put(new Request(test_url), 'Hello world!'), 196 cache.put(new Request(test_url), 'Hello world!'),
196 new TypeError(),
197 'Cache.put should only accept a Response object as the response.'); 197 'Cache.put should only accept a Response object as the response.');
198 }, 'Cache.put with an invalid response'); 198 }, 'Cache.put with an invalid response');
199 199
200 cache_test(function(cache) { 200 cache_test(function(cache, test) {
201 return assert_promise_rejects( 201 return promise_rejects(
202 test,
203 new TypeError(),
202 cache.put(new Request('file:///etc/passwd'), 204 cache.put(new Request('file:///etc/passwd'),
203 new Response(test_body)), 205 new Response(test_body)),
204 new TypeError(),
205 'Cache.put should reject non-HTTP/HTTPS requests with a TypeError.'); 206 'Cache.put should reject non-HTTP/HTTPS requests with a TypeError.');
206 }, 'Cache.put with a non-HTTP/HTTPS request'); 207 }, 'Cache.put with a non-HTTP/HTTPS request');
207 208
208 cache_test(function(cache) { 209 cache_test(function(cache) {
209 var response = new Response(test_body); 210 var response = new Response(test_body);
210 return cache.put(new Request('relative-url'), response.clone()) 211 return cache.put(new Request('relative-url'), response.clone())
211 .then(function() { 212 .then(function() {
212 return cache.match(new URL('relative-url', location.href).href); 213 return cache.match(new URL('relative-url', location.href).href);
213 }) 214 })
214 .then(function(result) { 215 .then(function(result) {
215 assert_response_equals(result, response, 216 assert_response_equals(result, response,
216 'Cache.put should accept a relative URL ' + 217 'Cache.put should accept a relative URL ' +
217 'as the request.'); 218 'as the request.');
218 }); 219 });
219 }, 'Cache.put with a relative URL'); 220 }, 'Cache.put with a relative URL');
220 221
221 cache_test(function(cache) { 222 cache_test(function(cache, test) {
222 var request = new Request('http://example.com/foo', { method: 'HEAD' }); 223 var request = new Request('http://example.com/foo', { method: 'HEAD' });
223 return assert_promise_rejects( 224 return promise_rejects(
225 test,
226 new TypeError(),
224 cache.put(request, new Response(test_body)), 227 cache.put(request, new Response(test_body)),
225 new TypeError(),
226 'Cache.put should throw a TypeError for non-GET requests.'); 228 'Cache.put should throw a TypeError for non-GET requests.');
227 }, 'Cache.put with a non-GET request'); 229 }, 'Cache.put with a non-GET request');
228 230
229 cache_test(function(cache) { 231 cache_test(function(cache, test) {
230 return assert_promise_rejects( 232 return promise_rejects(
233 test,
234 new TypeError(),
231 cache.put(new Request(test_url), null), 235 cache.put(new Request(test_url), null),
232 new TypeError(),
233 'Cache.put should throw a TypeError for a null response.'); 236 'Cache.put should throw a TypeError for a null response.');
234 }, 'Cache.put with a null response'); 237 }, 'Cache.put with a null response');
235 238
236 cache_test(function(cache) { 239 cache_test(function(cache, test) {
237 var request = new Request(test_url, {method: 'POST', body: test_body}); 240 var request = new Request(test_url, {method: 'POST', body: test_body});
238 return assert_promise_rejects( 241 return promise_rejects(
242 test,
243 new TypeError(),
239 cache.put(request, new Response(test_body)), 244 cache.put(request, new Response(test_body)),
240 new TypeError(),
241 'Cache.put should throw a TypeError for a POST request.'); 245 'Cache.put should throw a TypeError for a POST request.');
242 }, 'Cache.put with a POST request'); 246 }, 'Cache.put with a POST request');
243 247
244 cache_test(function(cache) { 248 cache_test(function(cache) {
245 var response = new Response(test_body); 249 var response = new Response(test_body);
246 assert_false(response.bodyUsed, 250 assert_false(response.bodyUsed,
247 '[https://fetch.spec.whatwg.org/#dom-body-bodyused] ' + 251 '[https://fetch.spec.whatwg.org/#dom-body-bodyused] ' +
248 'Response.bodyUsed should be initially false.'); 252 'Response.bodyUsed should be initially false.');
249 return response.text().then(function() { 253 return response.text().then(function() {
250 assert_true( 254 assert_true(
251 response.bodyUsed, 255 response.bodyUsed,
252 '[https://fetch.spec.whatwg.org/#concept-body-consume-body] ' + 256 '[https://fetch.spec.whatwg.org/#concept-body-consume-body] ' +
253 'The text() method should make the body disturbed.'); 257 'The text() method should make the body disturbed.');
254 var request = new Request(test_url); 258 var request = new Request(test_url);
255 return cache.put(request, response).then(() => { 259 return cache.put(request, response).then(() => {
256 assert_unreached('cache.put should be rejected'); 260 assert_unreached('cache.put should be rejected');
257 }, () => {}); 261 }, () => {});
258 }); 262 });
259 }, 'Cache.put with a used response body'); 263 }, 'Cache.put with a used response body');
260 264
261 cache_test(function(cache) { 265 cache_test(function(cache) {
262 var response = new Response(test_body); 266 var response = new Response(test_body);
263 return cache.put(new Request(test_url), response) 267 return cache.put(new Request(test_url), response)
264 .then(function() { 268 .then(function() {
265 assert_throws(new TypeError(), () => response.body.getReader()); 269 assert_throws(new TypeError(), () => response.body.getReader());
266 }); 270 });
267 }, 'getReader() after Cache.put'); 271 }, 'getReader() after Cache.put');
268 272
269 cache_test(function(cache) { 273 cache_test(function(cache, test) {
270 return assert_promise_rejects( 274 return promise_rejects(
275 test,
276 new TypeError(),
271 cache.put(new Request(test_url), 277 cache.put(new Request(test_url),
272 new Response(test_body, { headers: { VARY: '*' }})), 278 new Response(test_body, { headers: { VARY: '*' }})),
273 new TypeError(),
274 'Cache.put should reject VARY:* Responses with a TypeError.'); 279 'Cache.put should reject VARY:* Responses with a TypeError.');
275 }, 'Cache.put with a VARY:* Response'); 280 }, 'Cache.put with a VARY:* Response');
276 281
277 cache_test(function(cache) { 282 cache_test(function(cache, test) {
278 return assert_promise_rejects( 283 return promise_rejects(
284 test,
285 new TypeError(),
279 cache.put(new Request(test_url), 286 cache.put(new Request(test_url),
280 new Response(test_body, 287 new Response(test_body,
281 { headers: { VARY: 'Accept-Language,*' }})), 288 { headers: { VARY: 'Accept-Language,*' }})),
282 new TypeError(),
283 'Cache.put should reject Responses with an embedded VARY:* with a ' + 289 'Cache.put should reject Responses with an embedded VARY:* with a ' +
284 'TypeError.'); 290 'TypeError.');
285 }, 'Cache.put with an embedded VARY:* Response'); 291 }, 'Cache.put with an embedded VARY:* Response');
286 292
287 done(); 293 done();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698