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

Side by Side Diff: third_party/WebKit/LayoutTests/fast/domurl/urlsearchparams-constructor.html

Issue 1442643008: Implement 'URLSearchParams' (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test. Created 5 years, 1 month 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
(Empty)
1 <!doctype html>
2 <html>
3 <head>
4 <meta charset="utf8">
5 <link rel="help" href="https://url.spec.whatwg.org/#urlsearchparams">
6 <script src="../../resources/testharness.js"></script>
7 <script src="../../resources/testharnessreport.js"></script>
8 <script src="resources/testharness-extras.js"></script>
9 <script>
10 function assert_type_error(f, msg) {
11 assert_throws(TypeError(), f, msg);
12 }
13
14 // Consider upstreaming something kinda like this.
15 function assert_iteration_equals(iteration, expectation) {
16 var actual = [...iteration];
17 assert_equals(actual.length, expectation.length);
18 for (var i = 0; i < actual.length; i++) {
19 assert_equals(typeof actual[i], typeof expectation[i]);
20 if (actual[i] instanceof Array)
21 assert_array_equals(actual[i], expectation[i]);
22 else
23 assert_equals(actual[i], expectation[i]);
24 }
25 }
26
27 test(function() {
28 var params = new URLSearchParams();
29 assert_equals(params + '', '');
30 params = new URLSearchParams('');
31 assert_equals(params + '', '');
32 params = new URLSearchParams('a=b');
33 assert_equals(params + '', 'a=b');
34 params = new URLSearchParams(params);
35 assert_equals(params + '', 'a=b');
36 }, 'Basic URLSearchParams construction');
37
38 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.');
40
41 var params = new URLSearchParams('');
42 assert_not_equals(params, null, 'constructor returned non-null value.');
43 assert_equals(params.__proto__, URLSearchParams.prototype, 'expected URLSear chParams.prototype as prototype.');
44 params = new URLSearchParams({});
45 assert_equals(params + '', '%5Bobject+Object%5D=');
46 }, 'URLSearchParams constructor, empty.');
47
48 test(function() {
49 var params = new URLSearchParams('a=b');
50 assert_not_equals(params, null, 'constructor returned non-null value.');
51 assert_true(params.has('a'), 'Search params object has name "a"');
52 assert_false(params.has('b'), 'Search params object has not got name "b"');
53
54 var params = new URLSearchParams('a=b&c');
55 assert_not_equals(params, null, 'constructor returned non-null value.');
56 assert_true(params.has('a'), 'Search params object has name "a"');
57 assert_true(params.has('c'), 'Search params object has name "c"');
58
59 var params = new URLSearchParams('&a&&& &&&&&a+b=& c&m%c3%b8%c3%b8');
60 assert_not_equals(params, null, 'constructor returned non-null value.');
61 assert_true(params.has('a'), 'Search params object has name "a"');
62 assert_true(params.has('a b'), 'Search params object has name "a b"');
63 assert_true(params.has(' '), 'Search params object has name " "');
64 assert_false(params.has('c'), 'Search params object did not have the name "c "');
65 assert_true(params.has(' c'), 'Search params object has name " c"');
66 assert_true(params.has('møø'), 'Search params object has name "møø"');
67 }, 'URLSearchParams constructor, string.');
68
69 test(function() {
70 var seed = new URLSearchParams('a=b&c=d');
71 var params = new URLSearchParams(seed);
72 assert_not_equals(params, null, 'constructor returned non-null value.');
73 assert_iteration_equals(params, [ ['a', 'b' ], [ 'c', 'd' ] ]);
74 // The name-value pairs are copied when created; later updates
75 // should not be observable.
76 seed.append('e', 'f');
77 assert_false(params.has('e'));
78 params.append('g', 'h');
79 assert_false(seed.has('g'));
80 }, 'URLSearchParams constructor, object.');
81
82 test(function() {
83 var params = new URLSearchParams('a=b+c');
84 assert_equals(params.get('a'), 'b c');
85 params = new URLSearchParams('a+b=c');
86 assert_equals(params.get('a b'), 'c');
87 }, 'Parse +');
88
89 test(function() {
90 var params = new URLSearchParams('a=b%2Bc');
91 assert_equals(params.get('a'), 'b+c');
92 params = new URLSearchParams('a%2Bb=c');
93 assert_equals(params.get('a+b'), 'c');
94 }, 'Parse %2B');
95
96 test(function() {
97 var params = new URLSearchParams('a=b c');
98 assert_equals(params.get('a'), 'b c');
99 params = new URLSearchParams('a b=c');
100 assert_equals(params.get('a b'), 'c');
101 }, 'Parse space');
102
103 test(function() {
104 var params = new URLSearchParams('a=b%20c');
105 assert_equals(params.get('a'), 'b c');
106 params = new URLSearchParams('a%20b=c');
107 assert_equals(params.get('a b'), 'c');
108 }, 'Parse %20');
109
110 test(function() {
111 var params = new URLSearchParams('a=b\0c');
112 assert_equals(params.get('a'), 'b\0c');
113 params = new URLSearchParams('a\0b=c');
114 assert_equals(params.get('a\0b'), 'c');
115 }, 'Parse \\0');
116
117 test(function() {
118 var params = new URLSearchParams('a=b%00c');
119 assert_equals(params.get('a'), 'b\0c');
120 params = new URLSearchParams('a%00b=c');
121 assert_equals(params.get('a\0b'), 'c');
122 }, 'Parse %00');
123
124 test(function() {
125 var params = new URLSearchParams('a=b\u2384');
126 assert_equals(params.get('a'), 'b\u2384');
127 params = new URLSearchParams('a\u2384b=c');
128 assert_equals(params.get('a\u2384b'), 'c');
129 }, 'Parse \u2384'); // Unicode Character 'COMPOSITION SYMBOL' (U+2384)
130
131 test(function() {
132 var params = new URLSearchParams('a=b%e2%8e%84');
133 assert_equals(params.get('a'), 'b\u2384');
134 params = new URLSearchParams('a%e2%8e%84b=c');
135 assert_equals(params.get('a\u2384b'), 'c');
136 }, 'Parse %e2%8e%84'); // Unicode Character 'COMPOSITION SYMBOL' (U+2384)
137
138 test(function() {
139 var params = new URLSearchParams('a=b\uD83D\uDCA9c');
140 assert_equals(params.get('a'), 'b\uD83D\uDCA9c');
141 params = new URLSearchParams('a\uD83D\uDCA9b=c');
142 assert_equals(params.get('a\uD83D\uDCA9b'), 'c');
143 }, 'Parse \uD83D\uDCA9'); // Unicode Character 'PILE OF POO' (U+1F4A9)
144
145 test(function() {
146 var params = new URLSearchParams('a=b%f0%9f%92%a9c');
147 assert_equals(params.get('a'), 'b\uD83D\uDCA9c');
148 params = new URLSearchParams('a%f0%9f%92%a9b=c');
149 assert_equals(params.get('a\uD83D\uDCA9b'), 'c');
150 }, 'Parse %f0%9f%92%a9'); // Unicode Character 'PILE OF POO' (U+1F4A9)
151
152 test(function() {
153 var params = new URLSearchParams('=');
154 assert_equals(params.toString(), '=');
155 }, 'Parse =');
156
157 test(function() {
158 var params = new URLSearchParams('foobar=a\nb');
159 assert_equals(params.toString(), 'foobar=a%0Ab');
160 }, 'Parse \\n');
161 </script>
162 </head>
163 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698