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

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/fetch/api/request/request-disturbed.html

Issue 2778753002: Import //fetch from Web Platform Tests. (Closed)
Patch Set: Baselines. 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
(Empty)
1 <!doctype html>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>Request disturbed</title>
6 <meta name="help" href="https://fetch.spec.whatwg.org/#request">
7 <meta name="help" href="https://fetch.spec.whatwg.org/#body-mixin">
8 <meta name="author" title="Canon Research France" href="https://www.crf.cano n.fr">
9 <script src="/resources/testharness.js"></script>
10 <script src="/resources/testharnessreport.js"></script>
11 </head>
12 <body>
13 <script>
14 var initValuesDict = {"method" : "POST",
15 "body" : "Request's body"
16 };
17
18 var noBodyConsumed = new Request("");
19 var bodyConsumed = new Request("", initValuesDict);
20
21 test(() => {
22 assert_equals(noBodyConsumed.body, null, "body's default value is null") ;
23 assert_false(noBodyConsumed.bodyUsed , "bodyUsed is false when request i s not disturbed");
24 assert_not_equals(bodyConsumed.body, null, "non-null body");
25 assert_true(bodyConsumed.body instanceof ReadableStream, "non-null body type");
26 assert_false(noBodyConsumed.bodyUsed, "bodyUsed is false when request is not disturbed");
27 }, "Request's body: initial state");
28
29 noBodyConsumed.blob();
30 bodyConsumed.blob();
31
32 test(function() {
33 assert_false(noBodyConsumed.bodyUsed , "bodyUsed is false when request i s not disturbed");
34 try {
35 noBodyConsumed.clone();
36 } catch (e) {
37 assert_unreached("Can use request not disturbed for creating or clonin g request");
38 }
39 }, "Request without body cannot be disturbed");
40
41 test(function() {
42 assert_true(bodyConsumed.bodyUsed , "bodyUsed is true when request is di sturbed");
43 assert_throws(new TypeError(), function() { bodyConsumed.clone(); });
44 }, "Check cloning a disturbed request");
45
46 test(function() {
47 assert_true(bodyConsumed.bodyUsed , "bodyUsed is true when request is di sturbed");
48 assert_throws(new TypeError(), function() { new Request(bodyConsumed); } );
49 }, "Check creating a new request from a disturbed request");
50
51 promise_test(function() {
52 var bodyRequest = new Request("", initValuesDict);
53 const originalBody = bodyRequest.body;
54 assert_false(bodyRequest.bodyUsed , "bodyUsed is false when request is n ot disturbed");
55 var requestFromRequest = new Request(bodyRequest);
56 assert_true(bodyRequest.bodyUsed , "bodyUsed is true when request is dis turbed");
57 assert_equals(bodyRequest.body, originalBody, "body should not change");
58 assert_not_equals(originalBody, undefined, "body should not be undefined ");
59 assert_not_equals(originalBody, null, "body should not be null");
60 assert_not_equals(requestFromRequest.body, originalBody, "new request's body is new");
61 return requestFromRequest.text(text => {
62 assert_equals(text, "Request's body");
63 });
64 }, "Input request used for creating new request became disturbed");
65
66 promise_test(() => {
67 const bodyRequest = new Request("", initValuesDict);
68 const originalBody = bodyRequest.body;
69 assert_false(bodyRequest.bodyUsed , "bodyUsed is false when request is n ot disturbed");
70 const requestFromRequest = new Request(bodyRequest, { body : "init body" });
71 assert_true(bodyRequest.bodyUsed , "bodyUsed is true when request is dis turbed");
72 assert_equals(bodyRequest.body, originalBody, "body should not change");
73 assert_not_equals(originalBody, undefined, "body should not be undefined ");
74 assert_not_equals(originalBody, null, "body should not be null");
75 assert_not_equals(requestFromRequest.body, originalBody, "new request's body is new");
76
77 return requestFromRequest.text(text => {
78 assert_equals(text, "init body");
79 });
80 }, "Input request used for creating new request became disturbed even if b ody is not used");
81
82 promise_test(function(test) {
83 assert_true(bodyConsumed.bodyUsed , "bodyUsed is true when request is di sturbed");
84 return promise_rejects(test, new TypeError(), bodyConsumed.blob());
85 }, "Check consuming a disturbed request");
86
87 test(function() {
88 var req = new Request(URL, {method: 'POST', body: 'hello'});
89 assert_false(req.bodyUsed,
90 'Request should not be flagged as used if it has not been ' +
91 'consumed.');
92 assert_throws(new TypeError(),
93 function() { new Request(req, {method: 'GET'}); },
94 'A get request may not have body.');
95
96 assert_false(req.bodyUsed, 'After the GET case');
97
98 assert_throws(new TypeError(),
99 function() { new Request(req, {method: 'CONNECT'}); },
100 'Request() with a forbidden method must throw.');
101
102 assert_false(req.bodyUsed, 'After the forbidden method case');
103
104 var req2 = new Request(req);
105 assert_true(req.bodyUsed,
106 'Request should be flagged as used if it has been consumed.' );
107 }, 'Request construction failure should not set "bodyUsed"');
108 </script>
109 </body>
110 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698