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 var URL = 'https://www.example.com/test.html'; | 5 var URL = 'https://www.example.com/test.html'; |
6 | 6 |
7 test(function() { | 7 test(function() { |
8 var headers = new Headers; | 8 var headers = new Headers; |
9 headers.set('User-Agent', 'Mozilla/5.0'); | 9 headers.set('User-Agent', 'Mozilla/5.0'); |
10 headers.set('Accept', 'text/html'); | 10 headers.set('Accept', 'text/html'); |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 'method should not be changed when normalized: ' + | 265 'method should not be changed when normalized: ' + |
266 method); | 266 method); |
267 }); | 267 }); |
268 }, 'Request: valid method names and normalize test'); | 268 }, 'Request: valid method names and normalize test'); |
269 | 269 |
270 test(function() { | 270 test(function() { |
271 var req = new Request(URL); | 271 var req = new Request(URL); |
272 assert_false(req.bodyUsed, | 272 assert_false(req.bodyUsed, |
273 'Request should not be flagged as used if it has not been ' + | 273 'Request should not be flagged as used if it has not been ' + |
274 'consumed.'); | 274 'consumed.'); |
| 275 // See https://crbug.com/501195. |
275 var req2 = new Request(req); | 276 var req2 = new Request(req); |
276 assert_false(req.bodyUsed, | 277 assert_true(req.bodyUsed, |
277 'Request should not be flagged as used if it does not have' + | 278 'Request should be flagged as used if it does not have' + |
278 'body.'); | 279 'body.'); |
279 assert_false(req2.bodyUsed, | 280 assert_false(req2.bodyUsed, |
280 'Request should not be flagged as used if it has not been ' + | 281 'Request should not be flagged as used if it has not been ' + |
281 'consumed.'); | 282 'consumed.'); |
282 }, 'Request construction without body behavior regardning "bodyUsed"'); | 283 }, 'Request construction without body behavior regardning "bodyUsed"'); |
283 | 284 |
284 test(function() { | 285 test(function() { |
285 var req = new Request(URL, {method: 'POST', body: 'hello'}); | 286 var req = new Request(URL, {method: 'POST', body: 'hello'}); |
286 assert_false(req.bodyUsed, | 287 assert_false(req.bodyUsed, |
287 'Request should not be flagged as used if it has not been ' + | 288 'Request should not be flagged as used if it has not been ' + |
288 'consumed.'); | 289 'consumed.'); |
289 var req2 = new Request(req); | 290 var req2 = new Request(req); |
290 assert_true(req.bodyUsed, | 291 assert_true(req.bodyUsed, |
291 'Request should be flagged as used if it has been consumed.'); | 292 'Request should be flagged as used if it has been consumed.'); |
292 assert_false(req2.bodyUsed, | 293 assert_false(req2.bodyUsed, |
293 'Request should not be flagged as used if it has not been ' + | 294 'Request should not be flagged as used if it has not been ' + |
294 'consumed.'); | 295 'consumed.'); |
295 // Now we can create a Request from |req|, because creating |req2| from | 296 // See https://crbug.com/501195. |
296 // |req| sets |req|'s body to null as specified. | 297 assert_throws( |
297 var req3 = new Request(req); | 298 {name: 'TypeError'}, |
298 assert_true(req.bodyUsed, | 299 function() { new Request(req); }, |
299 'Request should be flagged as used if it has been consumed.'); | 300 'Request construction should throw if used.'); |
300 }, 'Request construction without body behavior regardning "bodyUsed"'); | 301 }, 'Request construction without body behavior regardning "bodyUsed"'); |
301 | 302 |
302 test(function() { | 303 test(function() { |
303 var req = new Request(URL, {method: 'POST', body: 'hello'}); | 304 var req = new Request(URL, {method: 'POST', body: 'hello'}); |
304 assert_false(req.bodyUsed, | 305 assert_false(req.bodyUsed, |
305 'Request should not be flagged as used if it has not been ' + | 306 'Request should not be flagged as used if it has not been ' + |
306 'consumed.'); | 307 'consumed.'); |
307 assert_throws( | 308 assert_throws( |
308 {name: 'TypeError'}, | 309 {name: 'TypeError'}, |
309 function() { new Request(req, {method: 'GET'}); }, | 310 function() { new Request(req, {method: 'GET'}); }, |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 | 611 |
611 // Tests for requests context. | 612 // Tests for requests context. |
612 test(function() { | 613 test(function() { |
613 var request = new Request('http://localhost/', {method: 'POST', body: ''}); | 614 var request = new Request('http://localhost/', {method: 'POST', body: ''}); |
614 assert_equals(request.context, '', | 615 assert_equals(request.context, '', |
615 'Request.context should be empty string ' + | 616 'Request.context should be empty string ' + |
616 'for synthetic Request object'); | 617 'for synthetic Request object'); |
617 }, 'RequestContext of a synthetic Request object'); | 618 }, 'RequestContext of a synthetic Request object'); |
618 | 619 |
619 done(); | 620 done(); |
OLD | NEW |