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

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

Issue 2587463002: [Fetch API] Appending headers of the same name should have their values (Closed)
Patch Set: it will be nicer. Created 4 years 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 test(function() { 5 test(function() {
6 var expectedValueMap = { 6 var expectedValueMap = {
7 'content-language': 'ja', 7 'content-language': 'ja',
8 'content-type': 'text/html; charset=UTF-8', 8 'content-type': 'text/html; charset=UTF-8',
9 'x-fetch-test': 'response test field' 9 'x-fetch-test': 'response test field'
10 }; 10 };
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 }, thisObject); 129 }, thisObject);
130 130
131 // 'append()', 'getAll()' 131 // 'append()', 'getAll()'
132 var allValues = headers.getAll('X-Fetch-Test'); 132 var allValues = headers.getAll('X-Fetch-Test');
133 assert_equals(allValues.length, 1); 133 assert_equals(allValues.length, 1);
134 assert_equals(size(headers), 4); 134 assert_equals(size(headers), 4);
135 headers.append('X-FETCH-TEST', 'response test field - append'); 135 headers.append('X-FETCH-TEST', 'response test field - append');
136 headers.append('X-FETCH-TEST-2', 'response test field - append'); 136 headers.append('X-FETCH-TEST-2', 'response test field - append');
137 assert_equals(size(headers), 5, 'headers size should increase by 1.'); 137 assert_equals(size(headers), 5, 'headers size should increase by 1.');
138 assert_equals(headers.get('X-FETCH-Test'), 138 assert_equals(headers.get('X-FETCH-Test'),
139 'response test field - updated', 139 'response test field - updated,response test field - append',
140 'the value of the first header added should be returned.'); 140 'the value of the first header added should be returned.');
141 allValues = headers.getAll('X-FETch-TEST'); 141 allValues = headers.getAll('X-FETch-TEST');
142 assert_equals(allValues.length, 2); 142 assert_equals(allValues.length, 2);
143 assert_equals(allValues[0], 'response test field - updated'); 143 assert_equals(allValues[0], 'response test field - updated');
144 assert_equals(allValues[1], 'response test field - append'); 144 assert_equals(allValues[1], 'response test field - append');
145 headers.set('X-FETch-Test', 'response test field - set'); 145 headers.set('X-FETch-Test', 'response test field - set');
146 assert_equals(size(headers), 5, 'the second header should be deleted'); 146 assert_equals(size(headers), 5, 'the second header should be deleted');
147 allValues = headers.getAll('X-Fetch-Test'); 147 allValues = headers.getAll('X-Fetch-Test');
148 assert_equals(allValues.length, 1, 'the second header should be deleted'); 148 assert_equals(allValues.length, 1, 'the second header should be deleted');
149 assert_equals(allValues[0], 'response test field - set'); 149 assert_equals(allValues[0], 'response test field - set');
150 headers.append('X-Fetch-TEST', 'response test field - append'); 150 headers.append('X-Fetch-TEST', 'response test field - append');
151 assert_equals(size(headers), 5, 'headers size should not increase by 1.'); 151 assert_equals(size(headers), 5, 'headers size should not increase by 1.');
152 headers.delete('X-FeTCH-Test'); 152 headers.delete('X-FeTCH-Test');
153 assert_equals(size(headers), 4, 'two headers should be deleted.'); 153 assert_equals(size(headers), 4, 'two headers should be deleted.');
154 154
155 // new Headers with sequence<sequence<ByteString>> 155 // new Headers with sequence<sequence<ByteString>>
156 headers = new Headers([['a', 'b'], ['c', 'd'], ['c', 'e']]); 156 headers = new Headers([['a', 'b'], ['c', 'd'], ['c', 'e']]);
157 assert_equals(size(headers), 2, 'headers size should match'); 157 assert_equals(size(headers), 2, 'headers size should match');
158 assert_equals(headers.get('a'), 'b'); 158 assert_equals(headers.get('a'), 'b');
159 assert_equals(headers.get('c'), 'd'); 159 assert_equals(headers.get('c'), 'd,e');
160 assert_equals(headers.getAll('c')[0], 'd'); 160 assert_equals(headers.getAll('c')[0], 'd');
161 assert_equals(headers.getAll('c')[1], 'e'); 161 assert_equals(headers.getAll('c')[1], 'e');
162 162
163 // new Headers with Headers 163 // new Headers with Headers
164 var headers2 = new Headers(headers); 164 var headers2 = new Headers(headers);
165 assert_equals(size(headers2), 2, 'headers size should match'); 165 assert_equals(size(headers2), 2, 'headers size should match');
166 assert_equals(headers2.get('a'), 'b'); 166 assert_equals(headers2.get('a'), 'b');
167 assert_equals(headers2.get('c'), 'd'); 167 assert_equals(headers2.get('c'), 'd,e');
168 assert_equals(headers2.getAll('c')[0], 'd'); 168 assert_equals(headers2.getAll('c')[0], 'd');
169 assert_equals(headers2.getAll('c')[1], 'e'); 169 assert_equals(headers2.getAll('c')[1], 'e');
170 headers.set('a', 'x'); 170 headers.set('a', 'x');
171 assert_equals(headers.get('a'), 'x'); 171 assert_equals(headers.get('a'), 'x');
172 assert_equals(headers2.get('a'), 'b'); 172 assert_equals(headers2.get('a'), 'b');
173 173
174 var headers3 = new Headers();
175 headers3.append('test', 'a');
176 headers3.append('test', '');
jsbell 2016/12/16 22:29:37 Hrm... I think this should throw TypeError: https
177 headers3.append('test', 'b');
178 assert_equals(headers3.get('test'), 'a,b');
174 // new Headers with Dictionary 179 // new Headers with Dictionary
175 headers = new Headers({'a': 'b', 'c': 'd'}); 180 headers = new Headers({'a': 'b', 'c': 'd'});
176 assert_equals(size(headers), 2, 'headers size should match'); 181 assert_equals(size(headers), 2, 'headers size should match');
177 assert_equals(headers.get('a'), 'b'); 182 assert_equals(headers.get('a'), 'b');
178 assert_equals(headers.get('c'), 'd'); 183 assert_equals(headers.get('c'), 'd');
179 184
180 // Throw errors 185 // Throw errors
181 INVALID_HEADER_NAMES.forEach(function(name) { 186 INVALID_HEADER_NAMES.forEach(function(name) {
182 assert_throws({name: 'TypeError'}, 187 assert_throws({name: 'TypeError'},
183 function() { 188 function() {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 values.push(value); 260 values.push(value);
256 } 261 }
257 assert_array_equals(keys, ['a', 'b', 'c'], 262 assert_array_equals(keys, ['a', 'b', 'c'],
258 'The pairs to iterate over should be the return ' + 263 'The pairs to iterate over should be the return ' +
259 'value of an algorithm that implicitly makes a copy.'); 264 'value of an algorithm that implicitly makes a copy.');
260 assert_array_equals(values, ['1,2,3', '2', '3'], 265 assert_array_equals(values, ['1,2,3', '2', '3'],
261 "The values should be combined and separated by ','."); 266 "The values should be combined and separated by ','.");
262 }, 'Iteration mutation'); 267 }, 'Iteration mutation');
263 268
264 done(); 269 done();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698