Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/fetch/script-tests/request.js

Issue 2691513002: Fetch: Make Headers' constructor match the current spec IDL. (Closed)
Patch Set: Patch v2 Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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(request, {headers: undefined});
133 assert_equals(request4.headers.getAll('X-Fetch-Foo')[0], 'foo1',
134 'Request.headers should match');
135 assert_equals(request4.headers.getAll('X-Fetch-Foo')[1], 'foo2',
136 'Request.headers should match');
137 assert_equals(request4.headers.getAll('X-Fetch-Bar')[0], 'bar',
138 'Request.headers should match');
132 }, 'Request header test'); 139 }, 'Request header test');
133 140
134 test(function() { 141 test(function() {
135 var request1 = {}; 142 var request1 = {};
136 var request2 = {}; 143 var request2 = {};
137 var METHODS = ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'OPTIONS', 144 var METHODS = ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'OPTIONS',
138 undefined]; 145 undefined];
139 var MODES = ['same-origin', 'no-cors', 'cors', '', undefined]; 146 var MODES = ['same-origin', 'no-cors', 'cors', '', undefined];
140 function isSimpleMethod(method) { 147 function isSimpleMethod(method) {
141 return ['GET', 'HEAD', 'POST', undefined].indexOf(method) != -1; 148 return ['GET', 'HEAD', 'POST', undefined].indexOf(method) != -1;
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 .then(function() { 682 .then(function() {
676 t.done(); 683 t.done();
677 }) 684 })
678 .catch(unreached_rejection(t)); 685 .catch(unreached_rejection(t));
679 assert_true(request.bodyUsed, 686 assert_true(request.bodyUsed,
680 'bodyUsed must be true after calling text()'); 687 'bodyUsed must be true after calling text()');
681 }, 'Request body test'); 688 }, 'Request body test');
682 689
683 test(function() { 690 test(function() {
684 // https://fetch.spec.whatwg.org/#dom-request 691 // https://fetch.spec.whatwg.org/#dom-request
685 // Step 20: 692 // Step 32:
686 // Fill r's Headers object with headers. Rethrow any exceptions. 693 // Fill r's Headers object with headers. Rethrow any exceptions.
687 INVALID_HEADER_NAMES.forEach(function(name) { 694 INVALID_HEADER_NAMES.forEach(function(name) {
688 assert_throws( 695 assert_throws(
689 {name: 'TypeError'}, 696 {name: 'TypeError'},
690 function() { 697 function() {
691 var obj = {}; 698 var obj = {};
692 obj[name] = 'a'; 699 obj[name] = 'a';
693 new Request('http://localhost/', {headers: obj}); 700 new Request('http://localhost/', {headers: obj});
694 }, 701 },
695 'new Request with headers with an invalid name (' + name + 702 'new Request with headers with an invalid name (' + name +
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 credentials: 'include', 820 credentials: 'include',
814 body: 'this is a body'}); 821 body: 'this is a body'});
815 822
816 return req.text() 823 return req.text()
817 .then(t => { 824 .then(t => {
818 assert_equals(t, 'this is a body'); 825 assert_equals(t, 'this is a body');
819 }); 826 });
820 }, 'Credentials and body can both be set.'); 827 }, 'Credentials and body can both be set.');
821 828
822 done(); 829 done();
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/fetch/Headers.h » ('j') | third_party/WebKit/Source/modules/fetch/Headers.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698