OLD | NEW |
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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 var response2 = response.clone(); | 123 var response2 = response.clone(); |
124 assert_false(response.bodyUsed, 'bodyUsed is not set by clone().'); | 124 assert_false(response.bodyUsed, 'bodyUsed is not set by clone().'); |
125 assert_false(response2.bodyUsed, 'bodyUsed is not set by clone().'); | 125 assert_false(response2.bodyUsed, 'bodyUsed is not set by clone().'); |
126 response.headers.set('Content-Language', 'en'); | 126 response.headers.set('Content-Language', 'en'); |
127 var response3; | |
128 assert_equals( | 127 assert_equals( |
129 response2.headers.get('Content-Language'), 'ja', 'Headers of cloned ' + | 128 response2.headers.get('Content-Language'), 'ja', 'Headers of cloned ' + |
130 'response should not change when original response headers are changed.'); | 129 'response should not change when original response headers are changed.'); |
131 | 130 |
132 var p = response.text(); | 131 var p = response.text(); |
133 assert_true(response.bodyUsed, 'bodyUsed should be true when locked.'); | 132 assert_true(response.bodyUsed, 'bodyUsed should be true when locked.'); |
134 assert_false(response2.bodyUsed, | 133 assert_false(response2.bodyUsed, |
135 'Cloned bodies should not share bodyUsed.'); | 134 'Cloned bodies should not share bodyUsed.'); |
136 assert_throws({name: 'TypeError'}, | 135 assert_throws({name: 'TypeError'}, |
137 function() { response3 = response.clone(); }, | 136 function() { response3 = response.clone(); }, |
138 'Response.clone() should throw if the body was used.'); | 137 'Response.clone() should throw if the body was used.'); |
139 return p.then(function(text) { | 138 return p.then(function(text) { |
140 assert_false(response.bodyUsed, | 139 assert_true(response.bodyUsed); |
141 'bodyUsed becomes false when text() is done.'); | |
142 assert_false(response2.bodyUsed); | 140 assert_false(response2.bodyUsed); |
143 response3 = response.clone(); | |
144 return response2.text(); | 141 return response2.text(); |
145 }).then(function(text) { | 142 }).then(function(text) { |
146 assert_equals(text, 'test string', | 143 assert_equals(text, 'test string', |
147 'Response clone response body text should match.'); | 144 'Response clone response body text should match.'); |
148 return Promise.all([response.text(), response2.text(), | 145 assert_true(response2.bodyUsed); |
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 }); | 146 }); |
155 }, 'Behavior of bodyUsed in Response and clone behavior.'); | 147 }, 'Behavior of bodyUsed in Response and clone behavior.'); |
156 | 148 |
157 promise_test(function() { | 149 promise_test(function() { |
158 var response = new Response(null); | 150 var response = new Response(null); |
159 assert_equals( | 151 assert_equals( |
160 response.headers.get('Content-Type'), | 152 response.headers.get('Content-Type'), |
161 'text/plain;charset=UTF-8', | 153 'text/plain;charset=UTF-8', |
162 'A Response constructed with a value coerced to string should have a ' + | 154 'A Response constructed with a value coerced to string should have a ' + |
163 'text Content-Type.'); | 155 'text Content-Type.'); |
(...skipping 13 matching lines...) Expand all Loading... |
177 'A Response constructed with no body should have no Content-Type.'); | 169 'A Response constructed with no body should have no Content-Type.'); |
178 return response.text() | 170 return response.text() |
179 .then(function(text) { | 171 .then(function(text) { |
180 assert_equals(text, '', | 172 assert_equals(text, '', |
181 'Response with no body accessed as text should ' + | 173 'Response with no body accessed as text should ' + |
182 'resolve to the empty string.'); | 174 'resolve to the empty string.'); |
183 }); | 175 }); |
184 }, 'Behavior of Response with no body.'); | 176 }, 'Behavior of Response with no body.'); |
185 | 177 |
186 done(); | 178 done(); |
OLD | NEW |