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

Side by Side Diff: LayoutTests/fast/domurl/url-searchparams-constructor.html

Issue 143313002: Implement URLSearchParams. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebased Created 6 years, 4 months 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 <meta charset="utf-8">
3 <link rel="help" href="http://url.spec.whatwg.org/#urlsearchparams">
4 <script src="../../resources/testharness.js"></script>
5 <script src="../../resources/testharnessreport.js"></script>
6 <script src="resources/testharness-extras.js"></script>
7 <script>
8 test(function() {
9 var params = new URLSearchParams();
10 assert_equals(params + '', '');
11 params = new URLSearchParams('');
12 assert_equals(params + '', '');
13 params = new URLSearchParams('a=b');
14 assert_equals(params + '', 'a=b');
15 params = new URLSearchParams(params);
16 assert_equals(params + '', 'a=b');
17 }, 'Basic URLSearchParams construction');
18
19 test(function() {
20 assert_type_error(function () { URLSearchParams(); }, 'Failed to construct \ 'URLSearchParams\': Please use the \'new\' operator, this DOM object constructor cannot be called as a function.');
21 assert_type_error(function () { new URLSearchParams(DOMException.prototype); });
22
23 var params = new URLSearchParams('');
24 assert_true(params != null, 'constructor returned non-null value.');
25 assert_equals(params.__proto__, URLSearchParams.prototype, 'expected URLSear chParams.prototype as prototype.');
26
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
37 var params = new URLSearchParams('a=b&c');
38 assert_true(params != null, 'constructor returned non-null value.');
39 assert_true(params.has('a'), 'Search params object has name "a"');
40 assert_true(params.has('c'), 'Search params object has name "c"');
41
42 var params = new URLSearchParams('&a&&& &&&&&a+b=& c&m%c3%b8%c3%b8');
43 assert_true(params != null, 'constructor returned non-null value.');
44 assert_true(params.has('a'), 'Search params object has name "a"');
45 assert_true(params.has('a b'), 'Search params object has name "a b"');
46 assert_true(params.has(' '), 'Search params object has name " "');
47 assert_false(params.has('c'), 'Search params object did not have the name "c "');
48 assert_true(params.has(' c'), 'Search params object has name " c"');
49 assert_true(params.has('møø'), 'Search params object has name "møø"');
50
51 }, 'URLSearchParams constructor, string.');
52
53 test(function() {
54 var seed = new URLSearchParams('a=b&c=d');
55 var params = new URLSearchParams(seed);
56 assert_true(params != null, 'constructor returned non-null value.');
57 assert_equals(params.get('a'), 'b');
58 assert_equals(params.get('c'), 'd');
59 assert_false(params.has('d'));
60 // The name-value pairs are copied when created; later updates
61 // should not be observable.
62 seed.append('e', 'f');
63 assert_false(params.has('e'));
64
65 params.append('g', 'h');
66 assert_false(seed.has('g'));
67
68 }, 'URLSearchParams constructor, object.');
69
70 test(function() {
71 var params = new URLSearchParams('a=b+c');
72 assert_equals(params.get('a'), 'b c');
73 params = new URLSearchParams('a+b=c');
74 assert_equals(params.get('a b'), 'c');
75 }, 'Parse +');
76
77 test(function() {
78 var params = new URLSearchParams('a=b c');
79 assert_equals(params.get('a'), 'b c');
80 params = new URLSearchParams('a b=c');
81 assert_equals(params.get('a b'), 'c');
82 }, 'Parse space');
83
84 test(function() {
85 var params = new URLSearchParams('a=b%20c');
86 assert_equals(params.get('a'), 'b c');
87 params = new URLSearchParams('a%20b=c');
88 assert_equals(params.get('a b'), 'c');
89 }, 'Parse %20');
90
91 test(function() {
92 var params = new URLSearchParams('a=b\0c');
93 assert_equals(params.get('a'), 'b\0c');
94 params = new URLSearchParams('a\0b=c');
95 assert_equals(params.get('a\0b'), 'c');
96 }, 'Parse \\0');
97
98 test(function() {
99 var params = new URLSearchParams('a=b%00c');
100 assert_equals(params.get('a'), 'b\0c');
101 params = new URLSearchParams('a%00b=c');
102 assert_equals(params.get('a\0b'), 'c');
103 }, 'Parse %00');
104
105 test(function() {
106 var params = new URLSearchParams('a=b\u2384');
107 assert_equals(params.get('a'), 'b\u2384');
108 params = new URLSearchParams('a\u2384b=c');
109 assert_equals(params.get('a\u2384b'), 'c');
110 }, 'Parse \u2384'); // Unicode Character 'COMPOSITION SYMBOL' (U+2384)
111
112 test(function() {
113 var params = new URLSearchParams('a=b%e2%8e%84');
114 assert_equals(params.get('a'), 'b\u2384');
115 params = new URLSearchParams('a%e2%8e%84b=c');
116 assert_equals(params.get('a\u2384b'), 'c');
117 }, 'Parse %e2%8e%84'); // Unicode Character 'COMPOSITION SYMBOL' (U+2384)
118
119 test(function() {
120 var params = new URLSearchParams('a=b\uD83D\uDCA9c');
121 assert_equals(params.get('a'), 'b\uD83D\uDCA9c');
122 params = new URLSearchParams('a\uD83D\uDCA9b=c');
123 assert_equals(params.get('a\uD83D\uDCA9b'), 'c');
124 }, 'Parse \uD83D\uDCA9'); // Unicode Character 'PILE OF POO' (U+1F4A9)
125
126 test(function() {
127 var params = new URLSearchParams('a=b%f0%9f%92%a9c');
128 assert_equals(params.get('a'), 'b\uD83D\uDCA9c');
129 params = new URLSearchParams('a%f0%9f%92%a9b=c');
130 assert_equals(params.get('a\uD83D\uDCA9b'), 'c');
131 }, 'Parse %f0%9f%92%a9'); // Unicode Character 'PILE OF POO' (U+1F4A9)
132 </script>
OLDNEW
« no previous file with comments | « LayoutTests/fast/domurl/url-searchparams-append.html ('k') | LayoutTests/fast/domurl/url-searchparams-delete.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698