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 19 matching lines...) Expand all Loading... | |
30 var deleteKey = 'Content-Type'; | 30 var deleteKey = 'Content-Type'; |
31 headers.delete(deleteKey); | 31 headers.delete(deleteKey); |
32 assert_equals(size(headers), 2, 'headers size should have -1 size'); | 32 assert_equals(size(headers), 2, 'headers size should have -1 size'); |
33 Object.keys(expectedValueMap).forEach(function(key) { | 33 Object.keys(expectedValueMap).forEach(function(key) { |
34 if (key == deleteKey.toLowerCase()) | 34 if (key == deleteKey.toLowerCase()) |
35 assert_false(headers.has(key)); | 35 assert_false(headers.has(key)); |
36 else | 36 else |
37 assert_true(headers.has(key)); | 37 assert_true(headers.has(key)); |
38 }); | 38 }); |
39 | 39 |
40 // 'set()' | 40 // 'set()' |
jsbell
2016/12/16 17:58:26
Do we have cases for invalid names/values anywhere
| |
41 var testCasesForSet = [ | 41 var testCasesForSet = [ |
42 // For a new key/value pair. | 42 // For a new key/value pair. |
43 { key: 'Cache-Control', | 43 { key: 'Cache-Control', |
44 value: 'max-age=3600', | 44 value: 'max-age=3600', |
45 isNewEntry: true }, | 45 isNewEntry: true }, |
46 | 46 |
47 // For an existing key. | 47 // For an existing key. |
48 { key: 'X-Fetch-Test', | 48 { key: 'X-Fetch-Test', |
49 value: 'response test field - updated', | 49 value: 'response test field - updated', |
50 isUpdate: true }, | 50 isUpdate: true }, |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 // new Headers with Dictionary | 174 // new Headers with Dictionary |
175 headers = new Headers({'a': 'b', 'c': 'd'}); | 175 headers = new Headers({'a': 'b', 'c': 'd'}); |
176 assert_equals(size(headers), 2, 'headers size should match'); | 176 assert_equals(size(headers), 2, 'headers size should match'); |
177 assert_equals(headers.get('a'), 'b'); | 177 assert_equals(headers.get('a'), 'b'); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
255 values.push(value); | 255 values.push(value); |
256 } | 256 } |
257 assert_array_equals(keys, ['a', 'b', 'c'], | 257 assert_array_equals(keys, ['a', 'b', 'c'], |
258 'The pairs to iterate over should be the return ' + | 258 'The pairs to iterate over should be the return ' + |
259 'value of an algorithm that implicitly makes a copy.'); | 259 'value of an algorithm that implicitly makes a copy.'); |
260 assert_array_equals(values, ['1,2,3', '2', '3'], | 260 assert_array_equals(values, ['1,2,3', '2', '3'], |
261 "The values should be combined and separated by ','."); | 261 "The values should be combined and separated by ','."); |
262 }, 'Iteration mutation'); | 262 }, 'Iteration mutation'); |
263 | 263 |
264 done(); | 264 done(); |
OLD | NEW |