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

Side by Side Diff: LayoutTests/http/tests/serviceworker/resources/cache-put-worker.js

Issue 882383002: [Fetch] Request with GET/HEAD method cannot have body (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 10 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 importScripts('worker-testharness.js'); 1 importScripts('worker-testharness.js');
2 importScripts('/resources/testharness-helpers.js'); 2 importScripts('/resources/testharness-helpers.js');
3 importScripts('override_assert_object_equals.js'); 3 importScripts('override_assert_object_equals.js');
4 4
5 var test_url = 'https://example.com/foo'; 5 var test_url = 'https://example.com/foo';
6 var test_body = 'Hello world!'; 6 var test_body = 'Hello world!';
7 7
8 cache_test(function(cache) { 8 cache_test(function(cache) {
9 var request = new Request(test_url); 9 var request = new Request(test_url);
10 var response = new Response(test_body); 10 var response = new Response(test_body);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 'Response.bodyUsed should be initially false.'); 60 'Response.bodyUsed should be initially false.');
61 return cache.put(request, response) 61 return cache.put(request, response)
62 .then(function() { 62 .then(function() {
63 assert_false(response.bodyUsed, 63 assert_false(response.bodyUsed,
64 'Cache.put should not mark empty response\'s body used'); 64 'Cache.put should not mark empty response\'s body used');
65 }); 65 });
66 }, 'Cache.put with Response without a body'); 66 }, 'Cache.put with Response without a body');
67 67
68 cache_test(function(cache) { 68 cache_test(function(cache) {
69 var request = new Request(test_url, { 69 var request = new Request(test_url, {
70 method: 'GET', 70 method: 'POST',
71 body: 'Hello' 71 body: 'Hello'
72 }); 72 });
73 var response = new Response(test_body); 73 var response = new Response(test_body);
74 assert_false(request.bodyUsed, 74 assert_false(request.bodyUsed,
75 '[https://fetch.spec.whatwg.org/#dom-body-bodyused] ' + 75 '[https://fetch.spec.whatwg.org/#dom-body-bodyused] ' +
76 'Request.bodyUsed should be initially false.'); 76 'Request.bodyUsed should be initially false.');
77 return cache.put(request, response.clone()) 77 return cache.put(request, response.clone())
78 .then(function() { 78 .then(function() {
79 assert_true(request.bodyUsed, 79 assert_true(request.bodyUsed,
80 'Cache.put should consume Request body.'); 80 'Cache.put should consume Request body.');
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 }, 'Cache.put with a non-GET request'); 284 }, 'Cache.put with a non-GET request');
285 285
286 cache_test(function(cache) { 286 cache_test(function(cache) {
287 return assert_promise_rejects( 287 return assert_promise_rejects(
288 cache.put(new Request(test_url), null), 288 cache.put(new Request(test_url), null),
289 new TypeError(), 289 new TypeError(),
290 'Cache.put should throw a TypeError for a null response.'); 290 'Cache.put should throw a TypeError for a null response.');
291 }, 'Cache.put with a null response'); 291 }, 'Cache.put with a null response');
292 292
293 cache_test(function(cache) { 293 cache_test(function(cache) {
294 var request = new Request(test_url, {body: test_body}); 294 var request = new Request(test_url, {method: 'POST', body: test_body});
295 assert_false(request.bodyUsed, 295 assert_false(request.bodyUsed,
296 '[https://fetch.spec.whatwg.org/#dom-body-bodyused] ' + 296 '[https://fetch.spec.whatwg.org/#dom-body-bodyused] ' +
297 'Request.bodyUsed should be initially false.'); 297 'Request.bodyUsed should be initially false.');
298 var copy = new Request(request); 298 var copy = new Request(request);
299 assert_true(request.bodyUsed, 299 assert_true(request.bodyUsed,
300 '[https://fetch.spec.whatwg.org/#dom-request] ' + 300 '[https://fetch.spec.whatwg.org/#dom-request] ' +
301 'Request constructor should set input\'s used flag.'); 301 'Request constructor should set input\'s used flag.');
302 return assert_promise_rejects( 302 return assert_promise_rejects(
303 cache.put(request, new Response(test_body)), 303 cache.put(request, new Response(test_body)),
304 new TypeError(), 304 new TypeError(),
305 'Cache.put should throw a TypeError for a request with used body.'); 305 'Cache.put should throw a TypeError for a request with used body.');
306 }, 'Cache.put with a used request body'); 306 }, 'Cache.put with a used request body');
307 307
308 cache_test(function(cache) { 308 cache_test(function(cache) {
309 var response = new Response(test_body); 309 var response = new Response(test_body);
310 assert_false(response.bodyUsed, 310 assert_false(response.bodyUsed,
311 '[https://fetch.spec.whatwg.org/#dom-body-bodyused] ' + 311 '[https://fetch.spec.whatwg.org/#dom-body-bodyused] ' +
312 'Response.bodyUsed should be initially false.'); 312 'Response.bodyUsed should be initially false.');
313 response.text().then(function() { 313 response.text().then(function() {
314 assert_true( 314 assert_true(
315 response.bodyUsed, 315 response.bodyUsed,
316 '[https://fetch.spec.whatwg.org/#concept-body-consume-body] ' + 316 '[https://fetch.spec.whatwg.org/#concept-body-consume-body] ' +
317 'The text() method should consume the body of the response.'); 317 'The text() method should consume the body of the response.');
318 return assert_promise_rejects( 318 return assert_promise_rejects(
319 cache.put(new Request(test_url), response), 319 cache.put(new Request(test_url), response),
320 new TypeError(), 320 new TypeError(),
321 'Cache.put should throw a TypeError for a response with used body.'); 321 'Cache.put should throw a TypeError for a response with used body.');
322 }); 322 });
323 }, 'Cache.put with a used response body'); 323 }, 'Cache.put with a used response body');
OLDNEW
« no previous file with comments | « LayoutTests/http/tests/serviceworker/resources/cache-match-worker.js ('k') | Source/modules/fetch/Request.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698