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

Unified Diff: LayoutTests/http/tests/fetch/script-tests/request.js

Issue 1088823002: [Fetch API] Follow a body setting spec change on Request constructor. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Source/modules/fetch/Request.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: LayoutTests/http/tests/fetch/script-tests/request.js
diff --git a/LayoutTests/http/tests/fetch/script-tests/request.js b/LayoutTests/http/tests/fetch/script-tests/request.js
index 823f47446e965b5a1a88c5726804ea9a14fbf929..7de3ba6c804ee5673f747f1fd1eef15b95e6e593 100644
--- a/LayoutTests/http/tests/fetch/script-tests/request.js
+++ b/LayoutTests/http/tests/fetch/script-tests/request.js
@@ -273,20 +273,55 @@ test(function() {
'Request should not be flagged as used if it has not been ' +
'consumed.');
var req2 = new Request(req);
+ assert_false(req.bodyUsed,
+ 'Request should not be flagged as used if it does not have' +
+ 'body.');
+ assert_false(req2.bodyUsed,
+ 'Request should not be flagged as used if it has not been ' +
+ 'consumed.');
+ }, 'Request construction without body behavior regardning "bodyUsed"');
+
+test(function() {
+ var req = new Request(URL, {method: 'POST', body: 'hello'});
+ assert_false(req.bodyUsed,
+ 'Request should not be flagged as used if it has not been ' +
+ 'consumed.');
+ var req2 = new Request(req);
assert_true(req.bodyUsed,
- 'Request should be flagged as used if it is used as a ' +
- 'construction argument of another Request.');
+ 'Request should be flagged as used if it has been consumed.');
assert_false(req2.bodyUsed,
'Request should not be flagged as used if it has not been ' +
'consumed.');
- assert_throws(new TypeError(), function() { new Request(req); },
- 'Request cannot be constructed with a request that has ' +
- 'been flagged as used.');
- assert_throws(new TypeError(), function() { req.clone(); },
- 'Request.clone: If used flag is set, throw a TypeError.');
- },
- 'Request construction behavior regarding "used" body flag and exceptions.');
+ // Now we can create a Request from |req|, because creating |req2| from
+ // |req| sets |req|'s body to null as specified.
+ var req3 = new Request(req);
+ assert_true(req.bodyUsed,
+ 'Request should be flagged as used if it has been consumed.');
+ }, 'Request construction without body behavior regardning "bodyUsed"');
+
+test(function() {
+ var req = new Request(URL, {method: 'POST', body: 'hello'});
+ assert_false(req.bodyUsed,
+ 'Request should not be flagged as used if it has not been ' +
+ 'consumed.');
+ assert_throws(
+ {name: 'TypeError'},
+ function() { new Request(req, {method: 'GET'}); },
+ 'A get request may not have body.');
+ assert_false(req.bodyUsed, 'After the GET case');
+
+ assert_throws(
+ {name: 'TypeError'},
+ function() { new Request(req, {method: 'CONNECT'}); },
+ 'Request() with a forbidden method must throw.');
+
+ assert_false(req.bodyUsed, 'After the forbidden method case');
+
+ var req2 = new Request(req);
+ assert_true(req.bodyUsed,
+ 'Request should be flagged as used if it has been consumed.');
+ }, 'Request construction failure should not set "bodyUsed"');
// Spec: https://fetch.spec.whatwg.org/#dom-request
// Step 21:
@@ -490,6 +525,10 @@ promise_test(function(t) {
.then(function(blob) {
assert_equals(blob.type, 'text/plain');
assert_equals(req.headers.get('Content-Type'), 'text/plain');
+// TODO(yhirano): Currently blob() calling sets |bodyUsed| parmanently. Fix it.
+// return new Request(req).blob();
+// }).then(function(blob) {
+// assert_equals(blob.type, 'text/plain');
});
}, 'MIME type for Blob with non-empty type');
« no previous file with comments | « no previous file | Source/modules/fetch/Request.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698