OLD | NEW |
1 <!doctype html> | 1 <!doctype html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <meta charset="utf8"> | 4 <meta charset="utf8"> |
5 <link rel="help" href="https://url.spec.whatwg.org/#urlsearchparams"> | 5 <link rel="help" href="https://url.spec.whatwg.org/#urlsearchparams"> |
6 <script src="../../resources/testharness.js"></script> | 6 <script src="../../resources/testharness.js"></script> |
7 <script src="../../resources/testharnessreport.js"></script> | 7 <script src="../../resources/testharnessreport.js"></script> |
8 <script src="resources/testharness-extras.js"></script> | 8 <script src="resources/testharness-extras.js"></script> |
9 <script> | 9 <script> |
10 function assert_type_error(f, msg) { | 10 function assert_type_error(f, msg) { |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 test(function() { | 27 test(function() { |
28 var params = new URLSearchParams(); | 28 var params = new URLSearchParams(); |
29 assert_equals(params + '', ''); | 29 assert_equals(params + '', ''); |
30 params = new URLSearchParams(''); | 30 params = new URLSearchParams(''); |
31 assert_equals(params + '', ''); | 31 assert_equals(params + '', ''); |
32 params = new URLSearchParams('a=b'); | 32 params = new URLSearchParams('a=b'); |
33 assert_equals(params + '', 'a=b'); | 33 assert_equals(params + '', 'a=b'); |
34 params = new URLSearchParams(params); | 34 params = new URLSearchParams(params); |
35 assert_equals(params + '', 'a=b'); | 35 assert_equals(params + '', 'a=b'); |
| 36 |
| 37 // Leading '?' should be ignored. |
| 38 params = new URLSearchParams('?a=b'); |
| 39 assert_equals(params + '', 'a=b'); |
| 40 |
| 41 // https://url.spec.whatwg.org/#concept-urlencoded-byte-serializer |
| 42 // is performed upon stringification of |params|, requiring that |
| 43 // '?' is percent encoded. |
| 44 params = new URLSearchParams('??a=b'); |
| 45 assert_equals(params + '', '%3Fa=b'); |
| 46 params = new URLSearchParams('?'); |
| 47 assert_equals(params + '', ''); |
| 48 params = new URLSearchParams('??'); |
| 49 assert_equals(params + '', '%3F='); |
36 }, 'Basic URLSearchParams construction'); | 50 }, 'Basic URLSearchParams construction'); |
37 | 51 |
38 test(function() { | 52 test(function() { |
39 assert_type_error(function () { URLSearchParams(); }, 'Failed to construct \
'URLSearchParams\': Please use the \'new\' operator, this DOM object constructor
cannot be called as a function.'); | 53 assert_type_error(function () { URLSearchParams(); }, 'Failed to construct \
'URLSearchParams\': Please use the \'new\' operator, this DOM object constructor
cannot be called as a function.'); |
40 | 54 |
41 var params = new URLSearchParams(''); | 55 var params = new URLSearchParams(''); |
42 assert_not_equals(params, null, 'constructor returned non-null value.'); | 56 assert_not_equals(params, null, 'constructor returned non-null value.'); |
43 assert_equals(params.__proto__, URLSearchParams.prototype, 'expected URLSear
chParams.prototype as prototype.'); | 57 assert_equals(params.__proto__, URLSearchParams.prototype, 'expected URLSear
chParams.prototype as prototype.'); |
44 params = new URLSearchParams({}); | 58 params = new URLSearchParams({}); |
45 assert_equals(params + '', '%5Bobject+Object%5D='); | 59 assert_equals(params + '', '%5Bobject+Object%5D='); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 assert_equals(params.toString(), '='); | 168 assert_equals(params.toString(), '='); |
155 }, 'Parse ='); | 169 }, 'Parse ='); |
156 | 170 |
157 test(function() { | 171 test(function() { |
158 var params = new URLSearchParams('foobar=a\nb'); | 172 var params = new URLSearchParams('foobar=a\nb'); |
159 assert_equals(params.toString(), 'foobar=a%0Ab'); | 173 assert_equals(params.toString(), 'foobar=a%0Ab'); |
160 }, 'Parse \\n'); | 174 }, 'Parse \\n'); |
161 </script> | 175 </script> |
162 </head> | 176 </head> |
163 </html> | 177 </html> |
OLD | NEW |