|
18 | 18 | }, 'Basic URLSearchParams construction');
|
19 | 19 |
|
20 | 20 | test(function() {
|
21 |
| - assert_throws(new TypeError(), function () { URLSearchParams(); }, |
22 |
| - 'Calling \'URLSearchParams\' without \'new\' should throw.'); |
23 |
| - assert_throws(new TypeError(), function () { new URLSearchParams(DOMException.prototype); }); |
24 |
| - var params = new URLSearchParams(''); |
| 21 | + var params = new URLSearchParams() |
| 22 | + assert_equals(params.toString(), "") |
| 23 | +}, "URLSearchParams constructor, no arguments") |
| 24 | + |
| 25 | +test(() => { |
| 26 | + params = new URLSearchParams(DOMException.prototype); |
| 27 | + assert_equals(params.toString(), "Error=") |
| 28 | +}, "URLSearchParams constructor, DOMException.prototype as argument") |
| 29 | + |
| 30 | +test(() => { |
| 31 | + params = new URLSearchParams(''); |
25 | 32 | assert_true(params != null, 'constructor returned non-null value.');
|
26 | 33 | assert_equals(params.__proto__, URLSearchParams.prototype, 'expected URLSearchParams.prototype as prototype.');
|
| 34 | +}, "URLSearchParams constructor, empty string as argument") |
| 35 | + |
| 36 | +test(() => { |
27 | 37 | params = new URLSearchParams({});
|
28 |
| - assert_equals(params + '', '%5Bobject+Object%5D='); |
29 |
| -}, 'URLSearchParams constructor, empty.'); |
| 38 | + assert_equals(params + '', ""); |
| 39 | +}, 'URLSearchParams constructor, {} as argument'); |
30 | 40 |
|
31 | 41 | test(function() {
|
32 | 42 | var params = new URLSearchParams('a=b');
|
|
124 | 134 | params = new URLSearchParams('a%f0%9f%92%a9b=c');
|
125 | 135 | assert_equals(params.get('a\uD83D\uDCA9b'), 'c');
|
126 | 136 | }, 'Parse %f0%9f%92%a9'); // Unicode Character 'PILE OF POO' (U+1F4A9)
|
| 137 | + |
| 138 | +;[ |
| 139 | + { "input": {"+": "%C2"}, "output": [[" ", "\uFFFD"]], "name": "object with +" }, |
| 140 | + { "input": {c: "x", a: "?"}, "output": [["c", "x"], ["a", "?"]], "name": "object with two keys" }, |
| 141 | + { "input": [["c", "x"], ["a", "?"]], "output": [["c", "x"], ["a", "?"]], "name": "array with two keys" } |
| 142 | +].forEach((val) => { |
| 143 | + test(() => { |
| 144 | + let params = new URLSearchParams(val.input), |
| 145 | + i = 0 |
| 146 | + for (let param of params) { |
| 147 | + assert_array_equals(param, val.output[i]) |
| 148 | + i++ |
| 149 | + } |
| 150 | + }, "Construct with " + val.name) |
| 151 | +}) |
| 152 | + |
| 153 | +test(() => { |
| 154 | + params = new URLSearchParams() |
| 155 | + params[Symbol.iterator] = function *() { |
| 156 | + yield ["a", "b"] |
| 157 | + } |
| 158 | + let params2 = new URLSearchParams(params) |
| 159 | + assert_equals(params2.get("a"), "b") |
| 160 | +}, "Custom [Symbol.iterator]") |
127 | 161 | </script>
|
128 | 162 | </head>
|
129 | 163 | </html>
|
0 commit comments