OLD | NEW |
(Empty) | |
| 1 <!doctype html> |
| 2 <html> |
| 3 <head> |
| 4 <meta charset="utf8"> |
| 5 <link rel="help" href="https://url.spec.whatwg.org/#dom-urlsearchparams"> |
| 6 <script src="../../resources/testharness.js"></script> |
| 7 <script src="../../resources/testharnessreport.js"></script> |
| 8 <script> |
| 9 var expectedValues = { |
| 10 'a': '1', |
| 11 'b': '2', |
| 12 'c': '3' |
| 13 }; |
| 14 |
| 15 var params = new URLSearchParams(); |
| 16 params.append('a', '1'); |
| 17 params.append('b', '2'); |
| 18 params.append('c', '3'); |
| 19 |
| 20 test(function() { |
| 21 for (var param of params) { |
| 22 var key = param[0]; |
| 23 var value = param[1]; |
| 24 assert_true(key in expectedValues); |
| 25 assert_equals(params.get(key), expectedValues[key]); |
| 26 assert_equals(value, expectedValues[key]); |
| 27 } |
| 28 }, 'for...of Iteration'); |
| 29 |
| 30 test(function() { |
| 31 for (var key of params.keys()) { |
| 32 assert_true(key in expectedValues); |
| 33 assert_equals(params.get(key), expectedValues[key]); |
| 34 } |
| 35 }, 'keys'); |
| 36 |
| 37 test(function() { |
| 38 var expectedKeys = {}; |
| 39 for (var key in expectedValues) |
| 40 expectedKeys[expectedValues[key]] = key; |
| 41 |
| 42 for (var value of params.values()) |
| 43 assert_true(value in expectedKeys); |
| 44 }, 'values'); |
| 45 |
| 46 test(function () { |
| 47 for (var param of params.entries()) { |
| 48 var key = param[0]; |
| 49 var value = param[1]; |
| 50 assert_true(key in expectedValues); |
| 51 assert_equals(params.get(key), expectedValues[key]); |
| 52 assert_equals(value, expectedValues[key]); |
| 53 } |
| 54 }, 'entries'); |
| 55 |
| 56 test(function () { |
| 57 params.forEach(function (value, key, paramsObject) { |
| 58 assert_true(key in expectedValues); |
| 59 assert_equals(params.get(key), expectedValues[key]); |
| 60 assert_equals(value, expectedValues[key]); |
| 61 assert_equals(paramsObject, params); |
| 62 }); |
| 63 }, 'forEach'); |
| 64 </script> |
| 65 </head> |
| 66 </html> |
OLD | NEW |