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

Side by Side Diff: LayoutTests/http/tests/fetch/script-tests/response-content.js

Issue 1049983003: [Fetch] Body consume function should not set bodyUsed flag. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@stream-clone
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 unified diff | Download patch
« no previous file with comments | « LayoutTests/http/tests/fetch/script-tests/response.js ('k') | Source/modules/fetch/Body.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 if (self.importScripts) { 1 if (self.importScripts) {
2 importScripts('../resources/fetch-test-helpers.js'); 2 importScripts('../resources/fetch-test-helpers.js');
3 } 3 }
4 4
5 promise_test(function() { 5 promise_test(function() {
6 var response = new Response; 6 var response = new Response;
7 return response.text() 7 return response.text()
8 .then(function(text) { 8 .then(function(text) {
9 assert_equals(text, '', 9 assert_equals(text, '',
10 'response.text() must return an empty string' + 10 'response.text() must return an empty string' +
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 result, expected_body, 112 result, expected_body,
113 'Creating a Response with FormData body must succeed.'); 113 'Creating a Response with FormData body must succeed.');
114 }); 114 });
115 }, 'Behavior of Response with FormData content'); 115 }, 'Behavior of Response with FormData content');
116 116
117 promise_test(function() { 117 promise_test(function() {
118 var headers = new Headers; 118 var headers = new Headers;
119 headers.set('Content-Language', 'ja'); 119 headers.set('Content-Language', 'ja');
120 var response = new Response( 120 var response = new Response(
121 'test string', {method: 'GET', headers: headers}); 121 'test string', {method: 'GET', headers: headers});
122 assert_false(response.bodyUsed, 122 assert_false(response.bodyUsed);
123 'bodyUsed is not set until Response is consumed.');
124 var response2 = response.clone(); 123 var response2 = response.clone();
124 assert_false(response.bodyUsed, 'bodyUsed is not set by clone().');
125 assert_false(response2.bodyUsed, 'bodyUsed is not set by clone().');
125 response.headers.set('Content-Language', 'en'); 126 response.headers.set('Content-Language', 'en');
126 var response3; 127 var response3;
127 assert_false(response2.bodyUsed,
128 'bodyUsed should be false in clone of non-consumed Response.');
129 assert_equals( 128 assert_equals(
130 response2.headers.get('Content-Language'), 'ja', 'Headers of cloned ' + 129 response2.headers.get('Content-Language'), 'ja', 'Headers of cloned ' +
131 'response should not change when original response headers are changed.'); 130 'response should not change when original response headers are changed.');
132 131
133 return response.text() 132 var p = response.text();
134 .then(function(text) { 133 assert_true(response.bodyUsed, 'bodyUsed should be true when locked.');
135 assert_true( 134 assert_false(response2.bodyUsed,
136 response.bodyUsed, 135 'Cloned bodies should not share bodyUsed.');
137 'bodyUsed should be true after a response is consumed.'); 136 assert_throws({name: 'TypeError'},
138 assert_false( 137 function() { response3 = response.clone(); },
139 response2.bodyUsed, 'bodyUsed should be false in Response cloned ' + 138 'Response.clone() should throw if the body was used.');
140 'before the original response was consumed.'); 139 return p.then(function(text) {
141 assert_throws( 140 assert_false(response.bodyUsed,
142 {name: 'TypeError'}, 141 'bodyUsed becomes false when text() is done.');
143 function() { response3 = response.clone(); }, 142 assert_false(response2.bodyUsed);
144 'Response.clone() should throw if the body was used.'); 143 response3 = response.clone();
145 return response2.text(); 144 return response2.text();
146 }) 145 }).then(function(text) {
147 .then(function(text) { 146 assert_equals(text, 'test string',
148 assert_equals(text, 'test string', 147 'Response clone response body text should match.');
149 'Response clone response body text should match.'); 148 return Promise.all([response.text(), response2.text(),
150 }); 149 response3.text()]);
150 }).then(function(texts) {
151 assert_equals(texts[0], '', 'Cloned after consumed.');
152 assert_equals(texts[1], '', 'Already consumed.');
153 assert_equals(texts[2], '', 'Cloned after consumed.');
154 });
151 }, 'Behavior of bodyUsed in Response and clone behavior.'); 155 }, 'Behavior of bodyUsed in Response and clone behavior.');
152 156
153 promise_test(function() { 157 promise_test(function() {
154 var response = new Response(null); 158 var response = new Response(null);
155 assert_equals( 159 assert_equals(
156 response.headers.get('Content-Type'), 160 response.headers.get('Content-Type'),
157 'text/plain;charset=UTF-8', 161 'text/plain;charset=UTF-8',
158 'A Response constructed with a value coerced to string should have a ' + 162 'A Response constructed with a value coerced to string should have a ' +
159 'text Content-Type.'); 163 'text Content-Type.');
160 return response.text() 164 return response.text()
(...skipping 12 matching lines...) Expand all
173 'A Response constructed with no body should have no Content-Type.'); 177 'A Response constructed with no body should have no Content-Type.');
174 return response.text() 178 return response.text()
175 .then(function(text) { 179 .then(function(text) {
176 assert_equals(text, '', 180 assert_equals(text, '',
177 'Response with no body accessed as text should ' + 181 'Response with no body accessed as text should ' +
178 'resolve to the empty string.'); 182 'resolve to the empty string.');
179 }); 183 });
180 }, 'Behavior of Response with no body.'); 184 }, 'Behavior of Response with no body.');
181 185
182 done(); 186 done();
OLDNEW
« no previous file with comments | « LayoutTests/http/tests/fetch/script-tests/response.js ('k') | Source/modules/fetch/Body.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698