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

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: More tests + ref count unattached URLSearchParams objects Created 6 years, 11 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>
7 function assert_typeerror(f, msg) {
arv (Not doing code reviews) 2014/01/22 16:12:05 assert_type_error
8 try {
9 f();
10 assert_unreached("Expected to throw a TypeError");
arv (Not doing code reviews) 2014/01/22 16:12:05 This is a common error (maybe you even got it from
sof 2014/01/22 19:27:09 Thanks, bug was all mine :), fixed. (Would be nice
11 } catch (e) {
12 assert_true(e instanceof TypeError);
13 if (msg)
14 assert_equals(e.message, msg);
15 }
16 }
17
18 test(function() {
19 var params = new URLSearchParams();
20 assert_equals(params + "", "");
21 params = new URLSearchParams("");
22 assert_equals(params + "", "");
23 params = new URLSearchParams("a=b");
24 assert_equals(params + "", "a=b");
25 params = new URLSearchParams(params);
26 assert_equals(params + "", "a=b");
27 }, "Basic URLSearchParams construction");
28
29 test(function() {
30 assert_typeerror(function () { URLSearchParams(); }, "Failed to construct 'U RLSearchParams': Please use the 'new' operator, this DOM object constructor cann ot be called as a function.");
31 assert_typeerror(function () { new URLSearchParams({}); }, "Failed to constr uct 'URLSearchParams': Argument not a string nor a URLSearchParams object.");
32 assert_typeerror(function () { new URLSearchParams(Date); }, "Failed to cons truct 'URLSearchParams': Argument not a string nor a URLSearchParams object.");
33 var params = new URLSearchParams("");
34 assert_true(params != null, "constructor returned non-null value.");
35 assert_equals(params.__proto__, URLSearchParams.prototype, "expected URLSear chParams.prototype as prototype.");
36 }, "URLSearchParams constructor, empty.");
37
38 test(function() {
39 var params = new URLSearchParams("a=b");
40 assert_true(params != null, "constructor returned non-null value.");
41 assert_true(params.has("a"), "Search params object has name 'a'");
42 assert_false(params.has("b"), "Search params object has not got name 'b'");
43
44 var params = new URLSearchParams("a=b&c");
45 assert_true(params != null, "constructor returned non-null value.");
46 assert_true(params.has("a"), "Search params object has name 'a'");
47 assert_true(params.has("c"), "Search params object has name 'c'");
48
49 var params = new URLSearchParams("&a&&& &&&&&a+b=& c&m%c3%b8%c3%b8");
50 assert_true(params != null, "constructor returned non-null value.");
51 assert_true(params.has("a"), "Search params object has name 'a'");
52 assert_true(params.has("a b"), "Search params object has name 'a b'");
53 assert_true(params.has(" "), "Search params object has name ' '");
54 assert_false(params.has("c"), "Search params object did not have the name 'c '");
55 assert_true(params.has(" c"), "Search params object has name ' c'");
56 assert_true(params.has("møø"), "Search params object has name 'møø'");
57
58 }, "URLSearchParams constructor, string.");
59
60 test(function() {
61 var seed = new URLSearchParams("a=b&c=d");
62 var params = new URLSearchParams(seed);
63 assert_true(params != null, "constructor returned non-null value.");
64 assert_equals(params.get("a"), "b");
65 assert_equals(params.get("c"), "d");
66 assert_false(params.has("d"));
67 // The name-value pairs are copied when created; later updates
68 // should not be observable.
69 seed.append("e", "f");
70 assert_false(params.has("e"));
71
72 params.append("g", "h");
73 assert_false(seed.has("g"));
74
75 }, "URLSearchParams constructor, object.");
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 +");
83
84 test(function() {
85 var params = new URLSearchParams("a=b c");
86 assert_equals(params.get("a"), "b c");
87 params = new URLSearchParams("a b=c");
88 assert_equals(params.get("a b"), "c");
89 }, "Parse space");
90
91 test(function() {
92 var params = new URLSearchParams("a=b%20c");
93 assert_equals(params.get("a"), "b c");
94 params = new URLSearchParams("a%20b=c");
95 assert_equals(params.get("a b"), "c");
96 }, "Parse %20");
97
98 test(function() {
99 var params = new URLSearchParams("a=b\0c");
100 assert_equals(params.get("a"), "b\0c");
101 params = new URLSearchParams("a\0b=c");
102 assert_equals(params.get("a\0b"), "c");
103 }, "Parse \\0");
104
105 test(function() {
106 var params = new URLSearchParams("a=b%00c");
107 assert_equals(params.get("a"), "b\0c");
108 params = new URLSearchParams("a%00b=c");
109 assert_equals(params.get("a\0b"), "c");
110 }, "Parse %00");
111
112 test(function() {
113 var params = new URLSearchParams("a=b\u2384");
114 assert_equals(params.get("a"), "b\u2384");
115 params = new URLSearchParams("a\u2384b=c");
116 assert_equals(params.get("a\u2384b"), "c");
117 }, "Parse \u2384"); // Unicode Character "COMPOSITION SYMBOL" (U+2384)
118
119 test(function() {
120 var params = new URLSearchParams("a=b%e2%8e%84");
121 assert_equals(params.get("a"), "b\u2384");
122 params = new URLSearchParams("a%e2%8e%84b=c");
123 assert_equals(params.get("a\u2384b"), "c");
124 }, "Parse %e2%8e%84"); // Unicode Character "COMPOSITION SYMBOL" (U+2384)
125
126 test(function() {
127 var params = new URLSearchParams('a=b\uD83D\uDCA9c');
128 assert_equals(params.get('a'), 'b\uD83D\uDCA9c');
129 params = new URLSearchParams('a\uD83D\uDCA9b=c');
130 assert_equals(params.get('a\uD83D\uDCA9b'), 'c');
131 }, 'Parse \uD83D\uDCA9'); // Unicode Character 'PILE OF POO' (U+1F4A9)
132
133 test(function() {
134 var params = new URLSearchParams('a=b%f0%9f%92%a9c');
135 assert_equals(params.get('a'), 'b\uD83D\uDCA9c');
136 params = new URLSearchParams('a%f0%9f%92%a9b=c');
137 assert_equals(params.get('a\uD83D\uDCA9b'), 'c');
138 }, 'Parse %f0%9f%92%a9'); // Unicode Character 'PILE OF POO' (U+1F4A9)
139 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698