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

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

Issue 807263007: IDL: Add forEach() method to iterable<>/maplike<>/setlike<> interfaces (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: extend testing Created 5 years, 11 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 test(function() { 5 test(function() {
6 function size(headers) { 6 function size(headers) {
7 var count = 0; 7 var count = 0;
8 for (var header of headers) { 8 for (var header of headers) {
9 ++count; 9 ++count;
10 } 10 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 var expectedKeyMap = {}; 109 var expectedKeyMap = {};
110 for (var key in expectedValueMap) 110 for (var key in expectedValueMap)
111 expectedKeyMap[expectedValueMap[key]] = key; 111 expectedKeyMap[expectedValueMap[key]] = key;
112 for (var value of headers.values()) { 112 for (var value of headers.values()) {
113 assert_true(value in expectedKeyMap); 113 assert_true(value in expectedKeyMap);
114 var key = expectedKeyMap[value]; 114 var key = expectedKeyMap[value];
115 assert_not_equals(key, deleteKey.toLowerCase()); 115 assert_not_equals(key, deleteKey.toLowerCase());
116 } 116 }
117 117
118 // 'entries()' 118 // 'entries()'
119 var entries = [];
119 for (var header of headers.entries()) { 120 for (var header of headers.entries()) {
120 var key = header[0], value = header[1]; 121 var key = header[0], value = header[1];
121 assert_not_equals(key, deleteKey.toLowerCase()); 122 assert_not_equals(key, deleteKey.toLowerCase());
122 assert_true(key in expectedValueMap); 123 assert_true(key in expectedValueMap);
123 assert_equals(headers.get(key), expectedValueMap[key]); 124 assert_equals(headers.get(key), expectedValueMap[key]);
124 assert_equals(value, expectedValueMap[key]); 125 assert_equals(value, expectedValueMap[key]);
126 entries.push(header);
125 } 127 }
126 128
129 // 'forEach()'
130 var thisObject = {};
131 headers.forEach(function (value, key, headersObject) {
132 var header = entries.shift();
133 assert_equals(key, header[0]);
134 assert_equals(value, header[1]);
135 assert_true(thisObject === this);
yhirano 2015/01/23 11:49:03 I think assert_equals uses the strict comparison,
Jens Widell 2015/01/23 11:53:55 Indeed it does, thanks. Changed to use assert_equa
136 assert_true(headersObject === headers);
137 }, thisObject);
138
127 // 'append()', 'getAll()' 139 // 'append()', 'getAll()'
128 var allValues = headers.getAll('X-Fetch-Test'); 140 var allValues = headers.getAll('X-Fetch-Test');
129 assert_equals(allValues.length, 1); 141 assert_equals(allValues.length, 1);
130 assert_equals(size(headers), 4); 142 assert_equals(size(headers), 4);
131 headers.append('X-FETCH-TEST', 'response test field - append'); 143 headers.append('X-FETCH-TEST', 'response test field - append');
132 assert_equals(size(headers), 5, 'headers size should increase by 1.'); 144 assert_equals(size(headers), 5, 'headers size should increase by 1.');
133 assert_equals(headers.get('X-FETCH-Test'), 145 assert_equals(headers.get('X-FETCH-Test'),
134 'response test field - updated', 146 'response test field - updated',
135 'the value of the first header added should be returned.'); 147 'the value of the first header added should be returned.');
136 allValues = headers.getAll('X-FETch-TEST'); 148 allValues = headers.getAll('X-FETch-TEST');
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 'new Headers with a sequence with less than two strings ' + 255 'new Headers with a sequence with less than two strings ' +
244 'should throw'); 256 'should throw');
245 assert_throws({name: 'TypeError'}, 257 assert_throws({name: 'TypeError'},
246 function() { var headers = new Headers([['a', 'b'], 258 function() { var headers = new Headers([['a', 'b'],
247 ['x', 'y', 'z']]); }, 259 ['x', 'y', 'z']]); },
248 'new Headers with a sequence with more than two strings ' + 260 'new Headers with a sequence with more than two strings ' +
249 'should throw'); 261 'should throw');
250 }, 'Headers'); 262 }, 'Headers');
251 263
252 done(); 264 done();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698