summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/url/urlsearchparams-constructor.html
blob: 4e4d5dac35cfd819a20196b35a5506fd92489a72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<!doctype html>
<html>
<head>
<meta charset="utf8">
<link rel="help" href="http://url.spec.whatwg.org/#urlsearchparams">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
test(function() {
    var params = new URLSearchParams();
    assert_equals(params + '', '');
    params = new URLSearchParams('');
    assert_equals(params + '', '');
    params = new URLSearchParams('a=b');
    assert_equals(params + '', 'a=b');
    params = new URLSearchParams(params);
    assert_equals(params + '', 'a=b');
}, 'Basic URLSearchParams construction');

test(function() {
    assert_throws(new TypeError(), function () { URLSearchParams(); },
                  'Calling \'URLSearchParams\' without \'new\' should throw.');
    assert_throws(new TypeError(), function () { new URLSearchParams(DOMException.prototype); });
    var params = new URLSearchParams('');
    assert_true(params != null, 'constructor returned non-null value.');
    assert_equals(params.__proto__, URLSearchParams.prototype, 'expected URLSearchParams.prototype as prototype.');
    params = new URLSearchParams({});
    assert_equals(params + '', '%5Bobject+Object%5D=');
}, 'URLSearchParams constructor, empty.');

test(function() {
    var params = new URLSearchParams('a=b');
    assert_true(params != null, 'constructor returned non-null value.');
    assert_true(params.has('a'), 'Search params object has name "a"');
    assert_false(params.has('b'), 'Search params object has not got name "b"');
    var params = new URLSearchParams('a=b&c');
    assert_true(params != null, 'constructor returned non-null value.');
    assert_true(params.has('a'), 'Search params object has name "a"');
    assert_true(params.has('c'), 'Search params object has name "c"');
    var params = new URLSearchParams('&a&&& &&&&&a+b=& c&m%c3%b8%c3%b8');
    assert_true(params != null, 'constructor returned non-null value.');
    assert_true(params.has('a'), 'Search params object has name "a"');
    assert_true(params.has('a b'), 'Search params object has name "a b"');
    assert_true(params.has(' '), 'Search params object has name " "');
    assert_false(params.has('c'), 'Search params object did not have the name "c"');
    assert_true(params.has(' c'), 'Search params object has name " c"');
    assert_true(params.has('møø'), 'Search params object has name "møø"');
}, 'URLSearchParams constructor, string.');

test(function() {
    var seed = new URLSearchParams('a=b&c=d');
    var params = new URLSearchParams(seed);
    assert_true(params != null, 'constructor returned non-null value.');
    assert_equals(params.get('a'), 'b');
    assert_equals(params.get('c'), 'd');
    assert_false(params.has('d'));
    // The name-value pairs are copied when created; later updates
    // should not be observable.
    seed.append('e', 'f');
    assert_false(params.has('e'));
    params.append('g', 'h');
    assert_false(seed.has('g'));
}, 'URLSearchParams constructor, object.');

test(function() {
    var params = new URLSearchParams('a=b+c');
    assert_equals(params.get('a'), 'b c');
    params = new URLSearchParams('a+b=c');
    assert_equals(params.get('a b'), 'c');
}, 'Parse +');

test(function() {
    var params = new URLSearchParams('a=b c');
    assert_equals(params.get('a'), 'b c');
    params = new URLSearchParams('a b=c');
    assert_equals(params.get('a b'), 'c');
}, 'Parse space');

test(function() {
    var params = new URLSearchParams('a=b%20c');
    assert_equals(params.get('a'), 'b c');
    params = new URLSearchParams('a%20b=c');
    assert_equals(params.get('a b'), 'c');
}, 'Parse %20');

test(function() {
    var params = new URLSearchParams('a=b\0c');
    assert_equals(params.get('a'), 'b\0c');
    params = new URLSearchParams('a\0b=c');
    assert_equals(params.get('a\0b'), 'c');
}, 'Parse \\0');

test(function() {
    var params = new URLSearchParams('a=b%00c');
    assert_equals(params.get('a'), 'b\0c');
    params = new URLSearchParams('a%00b=c');
    assert_equals(params.get('a\0b'), 'c');
}, 'Parse %00');

test(function() {
    var params = new URLSearchParams('a=b\u2384');
    assert_equals(params.get('a'), 'b\u2384');
    params = new URLSearchParams('a\u2384b=c');
    assert_equals(params.get('a\u2384b'), 'c');
}, 'Parse \u2384');  // Unicode Character 'COMPOSITION SYMBOL' (U+2384)

test(function() {
    var params = new URLSearchParams('a=b%e2%8e%84');
    assert_equals(params.get('a'), 'b\u2384');
    params = new URLSearchParams('a%e2%8e%84b=c');
    assert_equals(params.get('a\u2384b'), 'c');
}, 'Parse %e2%8e%84');  // Unicode Character 'COMPOSITION SYMBOL' (U+2384)

test(function() {
    var params = new URLSearchParams('a=b\uD83D\uDCA9c');
    assert_equals(params.get('a'), 'b\uD83D\uDCA9c');
    params = new URLSearchParams('a\uD83D\uDCA9b=c');
    assert_equals(params.get('a\uD83D\uDCA9b'), 'c');
}, 'Parse \uD83D\uDCA9');  // Unicode Character 'PILE OF POO' (U+1F4A9)

test(function() {
    var params = new URLSearchParams('a=b%f0%9f%92%a9c');
    assert_equals(params.get('a'), 'b\uD83D\uDCA9c');
    params = new URLSearchParams('a%f0%9f%92%a9b=c');
    assert_equals(params.get('a\uD83D\uDCA9b'), 'c');
}, 'Parse %f0%9f%92%a9');  // Unicode Character 'PILE OF POO' (U+1F4A9)
</script>
</head>
</html>