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 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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 headers.set('a', 'x'); | 169 headers.set('a', 'x'); |
170 assert_equals(headers.get('a'), 'x'); | 170 assert_equals(headers.get('a'), 'x'); |
171 assert_equals(headers2.get('a'), 'b'); | 171 assert_equals(headers2.get('a'), 'b'); |
172 | 172 |
173 // new Headers with Dictionary | 173 // new Headers with Dictionary |
174 headers = new Headers({'a': 'b', 'c': 'd'}); | 174 headers = new Headers({'a': 'b', 'c': 'd'}); |
175 assert_equals(size(headers), 2, 'headers size should match'); | 175 assert_equals(size(headers), 2, 'headers size should match'); |
176 assert_equals(headers.get('a'), 'b'); | 176 assert_equals(headers.get('a'), 'b'); |
177 assert_equals(headers.get('c'), 'd'); | 177 assert_equals(headers.get('c'), 'd'); |
178 | 178 |
| 179 // Tests for new Headers with valid values. |
| 180 headers = new Headers(); |
| 181 headers.append('a', '\xd0\xa1'); |
| 182 assert_equals(headers.get('a'), '\xd0\xa1'); |
| 183 headers.append('b', 't t'); |
| 184 assert_equals(headers.get('b'), 't t'); |
| 185 headers.append('c', 't\tt'); |
| 186 assert_equals(headers.get('c'), 't\tt'); |
| 187 headers.append('k', ''); |
| 188 assert_equals(headers.get('k'), ''); |
| 189 headers.append('l', ' '); |
| 190 assert_equals(headers.get('l'), ''); |
| 191 headers.append('m', '\r\n\r\n\r\n'); |
| 192 assert_equals(headers.get('m'), ''); |
| 193 |
| 194 headers.set('n', '\xd0\xa1'); |
| 195 assert_equals(headers.get('n'), '\xd0\xa1'); |
| 196 headers.set('o', ''); |
| 197 assert_equals(headers.get('o'), ''); |
| 198 headers.set('p', '\r\n\r\n\r\n\r\t'); |
| 199 assert_equals(headers.get('p'), ''); |
| 200 |
| 201 // Tests for normalizing header values. |
| 202 headers.append('d', ' t'); |
| 203 assert_equals(headers.get('d'), 't'); |
| 204 headers.append('e', 't '); |
| 205 assert_equals(headers.get('e'), 't'); |
| 206 headers.append('f', ' t '); |
| 207 assert_equals(headers.get('f'), 't'); |
| 208 headers.append('g', 'test\r'); |
| 209 assert_equals(headers.get('g'), 'test'); |
| 210 |
| 211 headers.set('h', 'test\n'); |
| 212 assert_equals(headers.get('h'), 'test'); |
| 213 headers.set('i', 'test\r\n'); |
| 214 assert_equals(headers.get('i'), 'test'); |
| 215 headers.set('j', 'test\t'); |
| 216 assert_equals(headers.get('j'), 'test'); |
| 217 |
179 // Throw errors | 218 // Throw errors |
180 INVALID_HEADER_NAMES.forEach(function(name) { | 219 INVALID_HEADER_NAMES.forEach(function(name) { |
181 assert_throws({name: 'TypeError'}, | 220 assert_throws({name: 'TypeError'}, |
182 function() { | 221 function() { |
183 var obj = {}; | 222 var obj = {}; |
184 obj[name] = 'a'; | 223 obj[name] = 'a'; |
185 var headers = new Headers(obj); | 224 var headers = new Headers(obj); |
186 }, | 225 }, |
187 'new Headers with an invalid name (' + name + | 226 'new Headers with an invalid name (' + name + |
188 ') should throw'); | 227 ') should throw'); |
(...skipping 26 matching lines...) Expand all Loading... |
215 'new Headers with a sequence with less than two strings ' + | 254 'new Headers with a sequence with less than two strings ' + |
216 'should throw'); | 255 'should throw'); |
217 assert_throws({name: 'TypeError'}, | 256 assert_throws({name: 'TypeError'}, |
218 function() { var headers = new Headers([['a', 'b'], | 257 function() { var headers = new Headers([['a', 'b'], |
219 ['x', 'y', 'z']]); }, | 258 ['x', 'y', 'z']]); }, |
220 'new Headers with a sequence with more than two strings ' + | 259 'new Headers with a sequence with more than two strings ' + |
221 'should throw'); | 260 'should throw'); |
222 }, 'Headers'); | 261 }, 'Headers'); |
223 | 262 |
224 done(); | 263 done(); |
OLD | NEW |