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

Side by Side Diff: LayoutTests/fast/domurl/url-searchparams.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 <link rel="help" href="http://url.spec.whatwg.org/#interface-urlsearchparams">
3 <script src="../../resources/testharness.js"></script>
4 <script src="../../resources/testharnessreport.js"></script>
5 <script src="resources/testharness-extras.js"></script>
6 <script>
7 if (!window.gc) {
8 window.gc = function() {
9 if (window.GCController)
10 return GCController.collect();
11 for (var i = 0; i < 10000; i++)
12 var s = new String('abc');
13 }
14 }
15
16 test(function() {
17 assert_true('URLSearchParams' in window);
18 assert_true('toString' in URLSearchParams.prototype);
19 assert_true('append' in URLSearchParams.prototype);
20 assert_true('delete' in URLSearchParams.prototype);
21 assert_true('get' in URLSearchParams.prototype);
22 assert_true('getAll' in URLSearchParams.prototype);
23 assert_true('has' in URLSearchParams.prototype);
24 assert_true('set' in URLSearchParams.prototype);
25 }, 'URLSearchParams interface');
26
27 test(function() {
28 var url = new URL('http://example.org/?a=b');
29 var searchParams = url.searchParams;
30 assert_true(url.searchParams === searchParams, 'Check that the same query ob ject is returned.');
31
32 // Replace with fresh instance and test that identity is also preserved.
33 searchParams = new URLSearchParams();
34 url.searchParams = searchParams;
35 assert_true(url.searchParams === searchParams, 'Check that the same query ob ject is returned.');
36 }, 'URL.searchParams getter');
37
38 test(function() {
39 var url = new URL('http://example.org/?a=b');
40 var searchParams = url.searchParams;
41 assert_equals(searchParams.toString(), 'a=b');
42
43 // Clear contents by assigning an empty instance (but not null.)
44 assert_type_error(function () { url.searchParams = null; });
45 url.searchParams = new URLSearchParams();
46
47 assert_equals(searchParams.toString(), 'a=b');
48 assert_equals(url.searchParams.toString(), '');
49
50 searchParams = url.searchParams;
51 searchParams.set('a', 'b');
52 assert_equals(url.searchParams.toString(), 'a=b');
53 assert_equals(url.search, '?a=b');
54 url.search = '';
55 assert_equals(url.searchParams.toString(), '');
56 assert_equals(url.search, '');
57 assert_equals(searchParams.toString(), '');
58 }, 'URL.searchParams setter, clearing');
59
60 test(function() {
61 var url = new URL('http://example.org');
62 assert_type_error(function() { url.searchParams = null; });
63 assert_type_error(function() { url.searchParams = 2; });
64 assert_type_error(function() { url.searchParams = {}; });
65 }, 'URL.searchParams setter, invalid values');
66
67
68
69 test(function() {
70 var query = 'a=b&c=d';
71 var searchParams = new URLSearchParams(query);
72 var base_url = 'http://example.org/';
73 var url1 = new URL(base_url + 'path1?name1=value1');
74 var url2 = new URL(base_url + 'path2?name2=value2');
75
76 // Make url1 and url2 share query object.
77 url1.searchParams = url2.searchParams = searchParams;
78
79 // Verify that they are now connected.
80 assert_equals(url1.searchParams, url2.searchParams);
81 assert_equals(searchParams.get('a'), 'b');
82 assert_equals(url1.searchParams.get('a'), searchParams.get('a'));
83 assert_equals(url2.searchParams.get('a'), searchParams.get('a'));
84 assert_equals(url1.search, '?' + query);
85 assert_equals(url2.search, '?' + query);
86 assert_equals(url1.toString(), base_url + 'path1?' + query);
87 assert_equals(url2.toString(), base_url + 'path2?' + query);
88
89 // Verify that updates propagate to object's set of URL objects.
90 searchParams.set('a', 'B');
91 assert_equals(url1.searchParams.get('a'), 'B');
92 assert_equals(url2.searchParams.get('a'), 'B');
93
94 searchParams.set('new', 'value');
95 assert_equals(url1.searchParams.get('new'), 'value');
96 assert_equals(url2.searchParams.get('new'), 'value');
97
98 // If a query object loses one of its URL objects,
99 // the connection really is observed.
100 url1.searchParams = new URLSearchParams();
101 searchParams.set('a', 'b');
102 assert_false(url1.searchParams.has('a'));
103 assert_equals(url2.searchParams.get('a'), 'b');
104
105 url1.searchParams.set('foo', 'bar');
106 assert_true(url1.searchParams.has('foo'));
107 assert_false(url2.searchParams.has('foo'));
108 }, 'URL.searchParams setter, object updating');
109
110 test(function() {
111 var url = new URL('http://example.org/file?a=b&c=d');
112 var searchParams = url.searchParams;
113 assert_equals(url.search, '?a=b&c=d');
114 assert_equals(searchParams.toString(), 'a=b&c=d');
115
116 // Test that setting 'search' propagates to the URL object's query
117 // object.
118 url.search = 'e=f&g=h';
119 assert_equals(url.search, '?e=f&g=h');
120 assert_equals(searchParams.toString(), 'e=f&g=h');
121
122 // And in the other direction; altering searchParams propagates
123 // back to 'search'.
124 searchParams.append('i', ' j ');
125 assert_equals(url.search, '?e=f&g=h&i=+j+');
126 assert_equals(url.searchParams.toString(), 'e=f&g=h&i=+j+');
127 assert_equals(searchParams.get('i'), ' j ');
128
129 searchParams.set('e', 'updated');
130 assert_equals(url.search, '?e=updated&g=h&i=+j+');
131 assert_equals(searchParams.get('e'), 'updated');
132
133 var url2 = new URL('http://example.org/file?a=b&c=d');
134 assert_equals(url2.search, '?a=b&c=d');
135 // Replace url2's query object.
136 url2.searchParams = searchParams;
137 assert_equals(url2.search, '?e=updated&g=h&i=+j+');
138
139 // Test that setting 'search' propagates to its
140 // query object..and its associated url objects.
141 url2.search = 'a=b';
142 assert_equals(url2.search, '?a=b');
143 assert_equals(url.search, '?a=b');
144 assert_equals(searchParams.toString(), 'a=b');
145
146 }, 'URL.searchParamd and URL.search setters, update propagation');
147 </script>
OLDNEW
« no previous file with comments | « LayoutTests/fast/domurl/url-search.html ('k') | LayoutTests/fast/domurl/url-searchparams-append.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698