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

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: 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="http://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 test(function() {
11 var params = new URLSearchParams();
12 assert_equals(params + '', '');
13 params = new URLSearchParams('');
14 assert_equals(params + '', '');
15 params = new URLSearchParams('a=b');
16 assert_equals(params + '', 'a=b');
17 params = new URLSearchParams(params);
18 assert_equals(params + '', 'a=b');
19 }, 'Basic URLSearchParams construction');
20
21 test(function() {
22 assert_type_error(function () { URLSearchParams(); }, 'Failed to construct \ 'URLSearchParams\': Please use the \'new\' operator, this DOM object constructor cannot be called as a function.');
23 assert_type_error(function () { new URLSearchParams(DOMException.prototype); });
24 var params = new URLSearchParams('');
25 assert_true(params != null, 'constructor returned non-null value.');
26 assert_equals(params.__proto__, URLSearchParams.prototype, 'expected URLSear chParams.prototype as prototype.');
27 params = new URLSearchParams({});
28 assert_equals(params + '', '%5Bobject+Object%5D=');
29 }, 'URLSearchParams constructor, empty.');
30
31 test(function() {
32 var params = new URLSearchParams('a=b');
33 assert_true(params != null, 'constructor returned non-null value.');
34 assert_true(params.has('a'), 'Search params object has name "a"');
35 assert_false(params.has('b'), 'Search params object has not got name "b"');
36 var params = new URLSearchParams('a=b&c');
37 assert_true(params != null, 'constructor returned non-null value.');
38 assert_true(params.has('a'), 'Search params object has name "a"');
39 assert_true(params.has('c'), 'Search params object has name "c"');
40 var params = new URLSearchParams('&a&&& &&&&&a+b=& c&m%c3%b8%c3%b8');
41 assert_true(params != null, 'constructor returned non-null value.');
42 assert_true(params.has('a'), 'Search params object has name "a"');
43 assert_true(params.has('a b'), 'Search params object has name "a b"');
44 assert_true(params.has(' '), 'Search params object has name " "');
45 assert_false(params.has('c'), 'Search params object did not have the name "c "');
46 assert_true(params.has(' c'), 'Search params object has name " c"');
47 assert_true(params.has('møø'), 'Search params object has name "møø"');
48 }, 'URLSearchParams constructor, string.');
49
50 test(function() {
51 var seed = new URLSearchParams('a=b&c=d');
52 var params = new URLSearchParams(seed);
53 assert_true(params != null, 'constructor returned non-null value.');
54 assert_equals(params.get('a'), 'b');
55 assert_equals(params.get('c'), 'd');
56 assert_false(params.has('d'));
57 // The name-value pairs are copied when created; later updates
58 // should not be observable.
59 seed.append('e', 'f');
60 assert_false(params.has('e'));
61 params.append('g', 'h');
62 assert_false(seed.has('g'));
63 }, 'URLSearchParams constructor, object.');
64
65 test(function() {
66 var params = new URLSearchParams('a=b+c');
67 assert_equals(params.get('a'), 'b c');
68 params = new URLSearchParams('a+b=c');
69 assert_equals(params.get('a b'), 'c');
70 }, 'Parse +');
71
72 test(function() {
73 var params = new URLSearchParams('a=b c');
74 assert_equals(params.get('a'), 'b c');
75 params = new URLSearchParams('a b=c');
76 assert_equals(params.get('a b'), 'c');
77 }, 'Parse space');
78
79 test(function() {
80 var params = new URLSearchParams('a=b%20c');
81 assert_equals(params.get('a'), 'b c');
82 params = new URLSearchParams('a%20b=c');
83 assert_equals(params.get('a b'), 'c');
84 }, 'Parse %20');
85
86 test(function() {
87 var params = new URLSearchParams('a=b\0c');
88 assert_equals(params.get('a'), 'b\0c');
89 params = new URLSearchParams('a\0b=c');
90 assert_equals(params.get('a\0b'), 'c');
91 }, 'Parse \\0');
92
93 test(function() {
94 var params = new URLSearchParams('a=b%00c');
95 assert_equals(params.get('a'), 'b\0c');
96 params = new URLSearchParams('a%00b=c');
97 assert_equals(params.get('a\0b'), 'c');
98 }, 'Parse %00');
99
100 test(function() {
101 var params = new URLSearchParams('a=b\u2384');
102 assert_equals(params.get('a'), 'b\u2384');
103 params = new URLSearchParams('a\u2384b=c');
104 assert_equals(params.get('a\u2384b'), 'c');
105 }, 'Parse \u2384'); // Unicode Character 'COMPOSITION SYMBOL' (U+2384)
106
107 test(function() {
108 var params = new URLSearchParams('a=b%e2%8e%84');
109 assert_equals(params.get('a'), 'b\u2384');
110 params = new URLSearchParams('a%e2%8e%84b=c');
111 assert_equals(params.get('a\u2384b'), 'c');
112 }, 'Parse %e2%8e%84'); // Unicode Character 'COMPOSITION SYMBOL' (U+2384)
113
114 test(function() {
115 var params = new URLSearchParams('a=b\uD83D\uDCA9c');
116 assert_equals(params.get('a'), 'b\uD83D\uDCA9c');
117 params = new URLSearchParams('a\uD83D\uDCA9b=c');
118 assert_equals(params.get('a\uD83D\uDCA9b'), 'c');
119 }, 'Parse \uD83D\uDCA9'); // Unicode Character 'PILE OF POO' (U+1F4A9)
120
121 test(function() {
122 var params = new URLSearchParams('a=b%f0%9f%92%a9c');
123 assert_equals(params.get('a'), 'b\uD83D\uDCA9c');
124 params = new URLSearchParams('a%f0%9f%92%a9b=c');
125 assert_equals(params.get('a\uD83D\uDCA9b'), 'c');
126 }, 'Parse %f0%9f%92%a9'); // Unicode Character 'PILE OF POO' (U+1F4A9)
127
128 test(function() {
129 var params = new URLSearchParams('=');
130 assert_equals(params.toString(), '=');
131 }, 'Parse =');
132
133 test(function() {
134 var params = new URLSearchParams('foobar=a\nb');
135 assert_equals(params.toString(), 'foobar=a%0Ab');
136 }, 'Parse \\n');
137 </script>
138 </head>
139 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698