| 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 var request3 = new Request(URL, | 122 var request3 = new Request(URL, |
| 123 {headers: [['X-Fetch-Foo', 'foo1'], | 123 {headers: [['X-Fetch-Foo', 'foo1'], |
| 124 ['X-Fetch-Foo', 'foo2'], | 124 ['X-Fetch-Foo', 'foo2'], |
| 125 ['X-Fetch-Bar', 'bar']]}); | 125 ['X-Fetch-Bar', 'bar']]}); |
| 126 assert_equals(request3.headers.getAll('X-Fetch-Foo')[0], 'foo1', | 126 assert_equals(request3.headers.getAll('X-Fetch-Foo')[0], 'foo1', |
| 127 'Request.headers should match'); | 127 'Request.headers should match'); |
| 128 assert_equals(request3.headers.getAll('X-Fetch-Foo')[1], 'foo2', | 128 assert_equals(request3.headers.getAll('X-Fetch-Foo')[1], 'foo2', |
| 129 'Request.headers should match'); | 129 'Request.headers should match'); |
| 130 assert_equals(request3.headers.getAll('X-Fetch-Bar')[0], 'bar', | 130 assert_equals(request3.headers.getAll('X-Fetch-Bar')[0], 'bar', |
| 131 'Request.headers should match'); | 131 'Request.headers should match'); |
| 132 var request4 = new Request(URL, |
| 133 {headers: {'X-Fetch-Foo': 'foo1', |
| 134 'X-Fetch-Foo': 'foo2', |
| 135 'X-Fetch-Bar': 'bar'}}); |
| 136 assert_equals(request4.headers.getAll('X-Fetch-Foo')[0], 'foo2', |
| 137 'Request.headers should match'); |
| 138 assert_equals(request4.headers.getAll('X-Fetch-Bar')[0], 'bar', |
| 139 'Request.headers should match'); |
| 140 // https://github.com/whatwg/fetch/issues/479 |
| 141 var request5 = new Request(request, {headers: undefined}); |
| 142 assert_equals(request5.headers.getAll('X-Fetch-Foo')[0], 'foo1', |
| 143 'Request.headers should match'); |
| 144 assert_equals(request5.headers.getAll('X-Fetch-Foo')[1], 'foo2', |
| 145 'Request.headers should match'); |
| 146 assert_equals(request5.headers.getAll('X-Fetch-Bar')[0], 'bar', |
| 147 'Request.headers should match'); |
| 148 var request6 = new Request(request, {}); |
| 149 assert_equals(request6.headers.getAll('X-Fetch-Foo')[0], 'foo1', |
| 150 'Request.headers should match'); |
| 151 assert_equals(request6.headers.getAll('X-Fetch-Foo')[1], 'foo2', |
| 152 'Request.headers should match'); |
| 153 assert_equals(request6.headers.getAll('X-Fetch-Bar')[0], 'bar', |
| 154 'Request.headers should match'); |
| 155 assert_throws(new TypeError(), |
| 156 () => { new Request(request, {headers: null}) }, |
| 157 'null cannot be converted to a HeaderInit'); |
| 132 }, 'Request header test'); | 158 }, 'Request header test'); |
| 133 | 159 |
| 134 test(function() { | 160 test(function() { |
| 135 var request1 = {}; | 161 var request1 = {}; |
| 136 var request2 = {}; | 162 var request2 = {}; |
| 137 var METHODS = ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'OPTIONS', | 163 var METHODS = ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'OPTIONS', |
| 138 undefined]; | 164 undefined]; |
| 139 var MODES = ['same-origin', 'no-cors', 'cors', '', undefined]; | 165 var MODES = ['same-origin', 'no-cors', 'cors', '', undefined]; |
| 140 function isSimpleMethod(method) { | 166 function isSimpleMethod(method) { |
| 141 return ['GET', 'HEAD', 'POST', undefined].indexOf(method) != -1; | 167 return ['GET', 'HEAD', 'POST', undefined].indexOf(method) != -1; |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 .then(function() { | 714 .then(function() { |
| 689 t.done(); | 715 t.done(); |
| 690 }) | 716 }) |
| 691 .catch(unreached_rejection(t)); | 717 .catch(unreached_rejection(t)); |
| 692 assert_true(request.bodyUsed, | 718 assert_true(request.bodyUsed, |
| 693 'bodyUsed must be true after calling text()'); | 719 'bodyUsed must be true after calling text()'); |
| 694 }, 'Request body test'); | 720 }, 'Request body test'); |
| 695 | 721 |
| 696 test(function() { | 722 test(function() { |
| 697 // https://fetch.spec.whatwg.org/#dom-request | 723 // https://fetch.spec.whatwg.org/#dom-request |
| 698 // Step 20: | 724 // Step 32: |
| 699 // Fill r's Headers object with headers. Rethrow any exceptions. | 725 // Fill r's Headers object with headers. Rethrow any exceptions. |
| 700 INVALID_HEADER_NAMES.forEach(function(name) { | 726 INVALID_HEADER_NAMES.forEach(function(name) { |
| 701 assert_throws( | 727 assert_throws( |
| 702 {name: 'TypeError'}, | 728 {name: 'TypeError'}, |
| 703 function() { | 729 function() { |
| 704 var obj = {}; | 730 var obj = {}; |
| 705 obj[name] = 'a'; | 731 obj[name] = 'a'; |
| 706 new Request('http://localhost/', {headers: obj}); | 732 new Request('http://localhost/', {headers: obj}); |
| 707 }, | 733 }, |
| 708 'new Request with headers with an invalid name (' + name + | 734 'new Request with headers with an invalid name (' + name + |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 credentials: 'include', | 852 credentials: 'include', |
| 827 body: 'this is a body'}); | 853 body: 'this is a body'}); |
| 828 | 854 |
| 829 return req.text() | 855 return req.text() |
| 830 .then(t => { | 856 .then(t => { |
| 831 assert_equals(t, 'this is a body'); | 857 assert_equals(t, 'this is a body'); |
| 832 }); | 858 }); |
| 833 }, 'Credentials and body can both be set.'); | 859 }, 'Credentials and body can both be set.'); |
| 834 | 860 |
| 835 done(); | 861 done(); |
| OLD | NEW |