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 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 .then(function() { | 641 .then(function() { |
642 var params = new URLSearchParams(); | 642 var params = new URLSearchParams(); |
643 params.append('sample string', '1234567890'); | 643 params.append('sample string', '1234567890'); |
644 request = new Request(URL, {method: 'POST', body: params}); | 644 request = new Request(URL, {method: 'POST', body: params}); |
645 return request.text(); | 645 return request.text(); |
646 }) | 646 }) |
647 .then(function(result) { | 647 .then(function(result) { |
648 assert_equals(result, "sample+string=1234567890"); | 648 assert_equals(result, "sample+string=1234567890"); |
649 }) | 649 }) |
650 .then(function() { | 650 .then(function() { |
| 651 // Alphanumeric characters and *-._ shouldn't be percent-encoded. |
| 652 // The others must. |
| 653 var params = new URLSearchParams(); |
| 654 params.append('\0\x1f!)*+,-./:?[^_{~\x7f\u0080', |
| 655 '\0\x1f!)*+,-./:?[^_{~\x7f\u0080'); |
| 656 request = new Request(URL, {method: 'POST', body: params}); |
| 657 return request.text(); |
| 658 }) |
| 659 .then(function(result) { |
| 660 assert_equals( |
| 661 result, |
| 662 "%00%1F%21%29*%2B%2C-.%2F%3A%3F%5B%5E_%7B%7E%7F%C2%80=" + |
| 663 "%00%1F%21%29*%2B%2C-.%2F%3A%3F%5B%5E_%7B%7E%7F%C2%80"); |
| 664 }) |
| 665 .then(function() { |
| 666 // CR and LF shouldn't be normalized into CRLF. |
| 667 var params = new URLSearchParams(); |
| 668 params.append('\r \n \r\n', '\r \n \r\n'); |
| 669 request = new Request(URL, {method: 'POST', body: params}); |
| 670 return request.text(); |
| 671 }) |
| 672 .then(function(result) { |
| 673 assert_equals(result, "%0D+%0A+%0D%0A=%0D+%0A+%0D%0A"); |
| 674 }) |
| 675 .then(function() { |
651 t.done(); | 676 t.done(); |
652 }) | 677 }) |
653 .catch(unreached_rejection(t)); | 678 .catch(unreached_rejection(t)); |
654 assert_true(request.bodyUsed, | 679 assert_true(request.bodyUsed, |
655 'bodyUsed must be true after calling text()'); | 680 'bodyUsed must be true after calling text()'); |
656 }, 'Request body test'); | 681 }, 'Request body test'); |
657 | 682 |
658 test(function() { | 683 test(function() { |
659 // https://fetch.spec.whatwg.org/#dom-request | 684 // https://fetch.spec.whatwg.org/#dom-request |
660 // Step 20: | 685 // Step 20: |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
788 credentials: 'include', | 813 credentials: 'include', |
789 body: 'this is a body'}); | 814 body: 'this is a body'}); |
790 | 815 |
791 return req.text() | 816 return req.text() |
792 .then(t => { | 817 .then(t => { |
793 assert_equals(t, 'this is a body'); | 818 assert_equals(t, 'this is a body'); |
794 }); | 819 }); |
795 }, 'Credentials and body can both be set.'); | 820 }, 'Credentials and body can both be set.'); |
796 | 821 |
797 done(); | 822 done(); |
OLD | NEW |