Chromium Code Reviews| 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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 var req2 = new Request(req); | 275 var req2 = new Request(req); |
| 276 assert_false(req.bodyUsed, | |
| 277 'Request should not be flagged as used if it does not have' + | |
| 278 'body.'); | |
| 279 assert_false(req2.bodyUsed, | |
| 280 'Request should not be flagged as used if it has not been ' + | |
| 281 'consumed.'); | |
| 282 }, 'Request construction without body behavior regardning "bodyUsed"'); | |
| 283 | |
| 284 test(function() { | |
| 285 var req = new Request(URL, {method: 'POST', body: 'hello'}); | |
| 286 assert_false(req.bodyUsed, | |
| 287 'Request should not be flagged as used if it has not been ' + | |
| 288 'consumed.'); | |
| 289 var req2 = new Request(req); | |
| 276 assert_true(req.bodyUsed, | 290 assert_true(req.bodyUsed, |
| 277 'Request should be flagged as used if it is used as a ' + | 291 'Request should be flagged as used if it has been consumed.'); |
| 278 'construction argument of another Request.'); | |
| 279 assert_false(req2.bodyUsed, | 292 assert_false(req2.bodyUsed, |
| 280 'Request should not be flagged as used if it has not been ' + | 293 'Request should not be flagged as used if it has not been ' + |
| 281 'consumed.'); | 294 'consumed.'); |
| 282 assert_throws(new TypeError(), function() { new Request(req); }, | 295 // Now we can create a Request from |req|, because creating |req2| from |
| 283 'Request cannot be constructed with a request that has ' + | 296 // |req| sets |req|'s body to null as specified. |
| 284 'been flagged as used.'); | 297 var req3 = new Request(req); |
| 285 assert_throws(new TypeError(), function() { req.clone(); }, | 298 assert_true(req.bodyUsed, |
| 286 'Request.clone: If used flag is set, throw a TypeError.'); | 299 'Request should be flagged as used if it has been consumed.'); |
| 287 }, | 300 }, 'Request construction without body behavior regardning "bodyUsed"'); |
| 288 'Request construction behavior regarding "used" body flag and exceptions.'); | |
| 289 | 301 |
| 302 test(function() { | |
| 303 var req = new Request(URL, {method: 'POST', body: 'hello'}); | |
| 304 assert_false(req.bodyUsed, | |
| 305 'Request should not be flagged as used if it has not been ' + | |
| 306 'consumed.'); | |
| 307 assert_throws( | |
| 308 {name: 'TypeError'}, | |
| 309 function() { new Request(req, {method: 'GET'}); }, | |
| 310 'A get request may not have body.'); | |
| 311 | |
| 312 assert_false(req.bodyUsed, 'After the GET case'); | |
| 313 | |
| 314 assert_throws( | |
| 315 {name: 'TypeError'}, | |
| 316 function() { new Request(req, {method: 'CONNECT'}); }, | |
| 317 'Request() with a forbidden method must throw.'); | |
| 318 | |
| 319 assert_false(req.bodyUsed, 'After the forbidden method case'); | |
| 320 | |
| 321 var req2 = new Request(req); | |
| 322 assert_true(req.bodyUsed, | |
| 323 'Request should be flagged as used if it has been consumed.'); | |
| 324 }, 'Request construction failure should not set "bodyUsed"'); | |
| 290 | 325 |
| 291 // Spec: https://fetch.spec.whatwg.org/#dom-request | 326 // Spec: https://fetch.spec.whatwg.org/#dom-request |
| 292 // Step 21: | 327 // Step 21: |
| 293 // If request's method is `GET` or `HEAD`, throw a TypeError. | 328 // If request's method is `GET` or `HEAD`, throw a TypeError. |
| 294 promise_test(function() { | 329 promise_test(function() { |
| 295 var headers = new Headers; | 330 var headers = new Headers; |
| 296 headers.set('Content-Language', 'ja'); | 331 headers.set('Content-Language', 'ja'); |
| 297 ['GET', 'HEAD'].forEach(function(method) { | 332 ['GET', 'HEAD'].forEach(function(method) { |
| 298 assert_throws( | 333 assert_throws( |
| 299 {name: 'TypeError'}, | 334 {name: 'TypeError'}, |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 483 }, 'MIME type for Blob'); | 518 }, 'MIME type for Blob'); |
| 484 | 519 |
| 485 promise_test(function(t) { | 520 promise_test(function(t) { |
| 486 var req = new Request('http://localhost/', | 521 var req = new Request('http://localhost/', |
| 487 {method: 'POST', | 522 {method: 'POST', |
| 488 body: new Blob([''], {type: 'Text/Plain'})}); | 523 body: new Blob([''], {type: 'Text/Plain'})}); |
| 489 return req.blob() | 524 return req.blob() |
| 490 .then(function(blob) { | 525 .then(function(blob) { |
| 491 assert_equals(blob.type, 'text/plain'); | 526 assert_equals(blob.type, 'text/plain'); |
| 492 assert_equals(req.headers.get('Content-Type'), 'text/plain'); | 527 assert_equals(req.headers.get('Content-Type'), 'text/plain'); |
| 528 // TODO(yhirano): Currently blob() calling sets |bodyUsed| parmanently. Fix it. | |
| 529 // return req.blob(); | |
|
hiroshige
2015/04/17 09:29:06
Shouldn't this be "return (new Request(req)).blob(
yhirano
2015/04/17 09:37:04
Done.
| |
| 530 // }).then(function() { | |
| 531 // assert_equals(blob.type, 'text/plain'); | |
| 493 }); | 532 }); |
| 494 }, 'MIME type for Blob with non-empty type'); | 533 }, 'MIME type for Blob with non-empty type'); |
| 495 | 534 |
| 496 promise_test(function(t) { | 535 promise_test(function(t) { |
| 497 var req = new Request('http://localhost/', | 536 var req = new Request('http://localhost/', |
| 498 {method: 'POST', body: new FormData()}); | 537 {method: 'POST', body: new FormData()}); |
| 499 return req.blob() | 538 return req.blob() |
| 500 .then(function(blob) { | 539 .then(function(blob) { |
| 501 assert_equals(blob.type.indexOf('multipart/form-data; boundary='), | 540 assert_equals(blob.type.indexOf('multipart/form-data; boundary='), |
| 502 0); | 541 0); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 572 | 611 |
| 573 // Tests for requests context. | 612 // Tests for requests context. |
| 574 test(function() { | 613 test(function() { |
| 575 var request = new Request('http://localhost/', {method: 'POST', body: ''}); | 614 var request = new Request('http://localhost/', {method: 'POST', body: ''}); |
| 576 assert_equals(request.context, '', | 615 assert_equals(request.context, '', |
| 577 'Request.context should be empty string ' + | 616 'Request.context should be empty string ' + |
| 578 'for synthetic Request object'); | 617 'for synthetic Request object'); |
| 579 }, 'RequestContext of a synthetic Request object'); | 618 }, 'RequestContext of a synthetic Request object'); |
| 580 | 619 |
| 581 done(); | 620 done(); |
| OLD | NEW |