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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 'method should not be changed when normalized: ' + | 328 'method should not be changed when normalized: ' + |
329 method); | 329 method); |
330 }); | 330 }); |
331 }, 'Request: valid method names and normalize test'); | 331 }, 'Request: valid method names and normalize test'); |
332 | 332 |
333 test(function() { | 333 test(function() { |
334 var req = new Request(URL); | 334 var req = new Request(URL); |
335 assert_false(req.bodyUsed, | 335 assert_false(req.bodyUsed, |
336 'Request should not be flagged as used if it has not been ' + | 336 'Request should not be flagged as used if it has not been ' + |
337 'consumed.'); | 337 'consumed.'); |
338 // See https://crbug.com/501195. | |
339 var req2 = new Request(req); | 338 var req2 = new Request(req); |
340 assert_true(req.bodyUsed, | 339 assert_false(req.bodyUsed, |
341 'Request should be flagged as used if it does not have' + | 340 'Request should not be flagged as used if it does not ' + |
342 'body.'); | 341 'have body.'); |
343 assert_false(req2.bodyUsed, | 342 assert_false(req2.bodyUsed, |
344 'Request should not be flagged as used if it has not been ' + | 343 'Request should not be flagged as used if it has not been ' + |
345 'consumed.'); | 344 'consumed.'); |
346 }, 'Request construction without body behavior regardning "bodyUsed"'); | 345 }, 'Request construction without body behavior regardning "bodyUsed"'); |
347 | 346 |
348 test(function() { | 347 test(function() { |
349 var req = new Request(URL, {method: 'POST', body: 'hello'}); | 348 var req = new Request(URL, {method: 'POST', body: 'hello'}); |
350 assert_false(req.bodyUsed, | 349 assert_false(req.bodyUsed, |
351 'Request should not be flagged as used if it has not been ' + | 350 'Request should not be flagged as used if it has not been ' + |
352 'consumed.'); | 351 'consumed.'); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 function() { | 471 function() { |
473 new Request(URL, | 472 new Request(URL, |
474 {method: method, | 473 {method: method, |
475 body: new Blob(['Test Blob'], {type: 'test/type'}) | 474 body: new Blob(['Test Blob'], {type: 'test/type'}) |
476 }); | 475 }); |
477 }, | 476 }, |
478 'Request of GET/HEAD method cannot have RequestInit body.'); | 477 'Request of GET/HEAD method cannot have RequestInit body.'); |
479 }); | 478 }); |
480 }, 'Request of GET/HEAD method cannot have RequestInit body.'); | 479 }, 'Request of GET/HEAD method cannot have RequestInit body.'); |
481 | 480 |
| 481 test(() => { |
| 482 var req = new Request(URL, {method: 'POST', body: 'hello'}); |
| 483 req.text(); |
| 484 assert_true(req.bodyUsed); |
| 485 assert_throws({name: 'TypeError'}, () => { req.clone(); }); |
| 486 }, 'Used => clone'); |
| 487 |
482 promise_test(function() { | 488 promise_test(function() { |
483 var headers = new Headers; | 489 var headers = new Headers; |
484 headers.set('Content-Language', 'ja'); | 490 headers.set('Content-Language', 'ja'); |
485 var req = new Request(URL, { | 491 var req = new Request(URL, { |
486 method: 'POST', | 492 method: 'POST', |
487 headers: headers, | 493 headers: headers, |
488 body: new Blob(['Test Blob'], {type: 'test/type'}) | 494 body: new Blob(['Test Blob'], {type: 'test/type'}) |
489 }); | 495 }); |
490 var req2 = req.clone(); | 496 var req2 = req.clone(); |
| 497 assert_false(req.bodyUsed); |
| 498 assert_false(req2.bodyUsed); |
491 // Change headers and of original request. | 499 // Change headers and of original request. |
492 req.headers.set('Content-Language', 'en'); | 500 req.headers.set('Content-Language', 'en'); |
493 assert_equals(req2.headers.get('Content-Language'), 'ja', | 501 assert_equals(req2.headers.get('Content-Language'), 'ja', |
494 'Headers of cloned request should not change when ' + | 502 'Headers of cloned request should not change when ' + |
495 'original request headers are changed.'); | 503 'original request headers are changed.'); |
496 | 504 |
497 return req.text().then(function(text) { | 505 return req.text().then(function(text) { |
498 assert_equals(text, 'Test Blob', 'Body of request should match.'); | 506 assert_equals(text, 'Test Blob', 'Body of request should match.'); |
499 return req2.text(); | 507 return req2.text(); |
500 }).then(function(text) { | 508 }).then(function(text) { |
501 assert_equals(text, 'Test Blob', 'Cloned request body should match.'); | 509 assert_equals(text, 'Test Blob', 'Cloned request body should match.'); |
502 return Promise.all([req.text(), req2.text()]); | |
503 }).then(function(texts) { | |
504 assert_equals(texts[0], '', 'The body is consumed.'); | |
505 assert_equals(texts[1], '', 'The body is consumed.'); | |
506 return req.clone().text(); | |
507 }).then(function(text) { | |
508 assert_equals(text, '', 'The body was consumed before cloned.'); | |
509 }); | 510 }); |
510 }, 'Test clone behavior with loading content from Request.'); | 511 }, 'Test clone behavior with loading content from Request.'); |
511 | 512 |
512 async_test(function(t) { | 513 async_test(function(t) { |
513 var request = | 514 var request = |
514 new Request(URL, | 515 new Request(URL, |
515 { | 516 { |
516 method: 'POST', | 517 method: 'POST', |
517 body: new Blob(['Test Blob'], {type: 'test/type'}) | 518 body: new Blob(['Test Blob'], {type: 'test/type'}) |
518 }); | 519 }); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 }, 'MIME type for Blob'); | 665 }, 'MIME type for Blob'); |
665 | 666 |
666 promise_test(function(t) { | 667 promise_test(function(t) { |
667 var req = new Request('http://localhost/', | 668 var req = new Request('http://localhost/', |
668 {method: 'POST', | 669 {method: 'POST', |
669 body: new Blob([''], {type: 'Text/Plain'})}); | 670 body: new Blob([''], {type: 'Text/Plain'})}); |
670 return req.blob() | 671 return req.blob() |
671 .then(function(blob) { | 672 .then(function(blob) { |
672 assert_equals(blob.type, 'text/plain'); | 673 assert_equals(blob.type, 'text/plain'); |
673 assert_equals(req.headers.get('Content-Type'), 'text/plain'); | 674 assert_equals(req.headers.get('Content-Type'), 'text/plain'); |
674 return new Request(req).blob(); | |
675 }).then(function(blob) { | |
676 assert_equals(blob.type, 'text/plain'); | |
677 }); | 675 }); |
678 }, 'MIME type for Blob with non-empty type'); | 676 }, 'MIME type for Blob with non-empty type'); |
679 | 677 |
680 promise_test(function(t) { | 678 promise_test(function(t) { |
681 var req = new Request('http://localhost/', | 679 var req = new Request('http://localhost/', |
682 {method: 'POST', body: new FormData()}); | 680 {method: 'POST', body: new FormData()}); |
683 return req.blob() | 681 return req.blob() |
684 .then(function(blob) { | 682 .then(function(blob) { |
685 assert_equals(blob.type.indexOf('multipart/form-data; boundary='), | 683 assert_equals(blob.type.indexOf('multipart/form-data; boundary='), |
686 0); | 684 0); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 {method: 'POST', | 732 {method: 'POST', |
735 body: new Blob([''], {type: 'Text/Plain'}), | 733 body: new Blob([''], {type: 'Text/Plain'}), |
736 headers: [['Content-Type', 'Text/Html']]}); | 734 headers: [['Content-Type', 'Text/Html']]}); |
737 return req.blob() | 735 return req.blob() |
738 .then(function(blob) { | 736 .then(function(blob) { |
739 assert_equals(blob.type, 'text/html'); | 737 assert_equals(blob.type, 'text/html'); |
740 assert_equals(req.headers.get('Content-Type'), 'Text/Html'); | 738 assert_equals(req.headers.get('Content-Type'), 'Text/Html'); |
741 }); | 739 }); |
742 }, 'Extract a MIME type (1)'); | 740 }, 'Extract a MIME type (1)'); |
743 | 741 |
744 promise_test(function(t) { | |
745 var req = new Request('http://localhost/', {method: 'POST', body: 'hello'}); | |
746 return req.text().then(function(text) { | |
747 assert_equals(text, 'hello'); | |
748 var req2 = new Request(req); | |
749 assert_true(req.bodyUsed); | |
750 assert_false(req2.bodyUsed); | |
751 return req2.text(); | |
752 }).then(function(text) { | |
753 assert_equals(text, ''); | |
754 }); | |
755 }, 'Consume and pass'); | |
756 | |
757 done(); | 742 done(); |
OLD | NEW |