Index: LayoutTests/fast/domurl/url-searchparams.html |
diff --git a/LayoutTests/fast/domurl/url-searchparams.html b/LayoutTests/fast/domurl/url-searchparams.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..fe819e81d4e3e9195a93515a387c67191e527a4c |
--- /dev/null |
+++ b/LayoutTests/fast/domurl/url-searchparams.html |
@@ -0,0 +1,147 @@ |
+<!DOCTYPE html> |
+<link rel="help" href="http://url.spec.whatwg.org/#interface-urlsearchparams"> |
+<script src="../../resources/testharness.js"></script> |
+<script src="../../resources/testharnessreport.js"></script> |
+<script src="resources/testharness-extras.js"></script> |
+<script> |
+if (!window.gc) { |
+ window.gc = function() { |
+ if (window.GCController) |
+ return GCController.collect(); |
+ for (var i = 0; i < 10000; i++) |
+ var s = new String('abc'); |
+ } |
+} |
+ |
+test(function() { |
+ assert_true('URLSearchParams' in window); |
+ assert_true('toString' in URLSearchParams.prototype); |
+ assert_true('append' in URLSearchParams.prototype); |
+ assert_true('delete' in URLSearchParams.prototype); |
+ assert_true('get' in URLSearchParams.prototype); |
+ assert_true('getAll' in URLSearchParams.prototype); |
+ assert_true('has' in URLSearchParams.prototype); |
+ assert_true('set' in URLSearchParams.prototype); |
+}, 'URLSearchParams interface'); |
+ |
+test(function() { |
+ var url = new URL('http://example.org/?a=b'); |
+ var searchParams = url.searchParams; |
+ assert_true(url.searchParams === searchParams, 'Check that the same query object is returned.'); |
+ |
+ // Replace with fresh instance and test that identity is also preserved. |
+ searchParams = new URLSearchParams(); |
+ url.searchParams = searchParams; |
+ assert_true(url.searchParams === searchParams, 'Check that the same query object is returned.'); |
+}, 'URL.searchParams getter'); |
+ |
+test(function() { |
+ var url = new URL('http://example.org/?a=b'); |
+ var searchParams = url.searchParams; |
+ assert_equals(searchParams.toString(), 'a=b'); |
+ |
+ // Clear contents by assigning an empty instance (but not null.) |
+ assert_type_error(function () { url.searchParams = null; }); |
+ url.searchParams = new URLSearchParams(); |
+ |
+ assert_equals(searchParams.toString(), 'a=b'); |
+ assert_equals(url.searchParams.toString(), ''); |
+ |
+ searchParams = url.searchParams; |
+ searchParams.set('a', 'b'); |
+ assert_equals(url.searchParams.toString(), 'a=b'); |
+ assert_equals(url.search, '?a=b'); |
+ url.search = ''; |
+ assert_equals(url.searchParams.toString(), ''); |
+ assert_equals(url.search, ''); |
+ assert_equals(searchParams.toString(), ''); |
+}, 'URL.searchParams setter, clearing'); |
+ |
+test(function() { |
+ var url = new URL('http://example.org'); |
+ assert_type_error(function() { url.searchParams = null; }); |
+ assert_type_error(function() { url.searchParams = 2; }); |
+ assert_type_error(function() { url.searchParams = {}; }); |
+}, 'URL.searchParams setter, invalid values'); |
+ |
+ |
+ |
+test(function() { |
+ var query = 'a=b&c=d'; |
+ var searchParams = new URLSearchParams(query); |
+ var base_url = 'http://example.org/'; |
+ var url1 = new URL(base_url + 'path1?name1=value1'); |
+ var url2 = new URL(base_url + 'path2?name2=value2'); |
+ |
+ // Make url1 and url2 share query object. |
+ url1.searchParams = url2.searchParams = searchParams; |
+ |
+ // Verify that they are now connected. |
+ assert_equals(url1.searchParams, url2.searchParams); |
+ assert_equals(searchParams.get('a'), 'b'); |
+ assert_equals(url1.searchParams.get('a'), searchParams.get('a')); |
+ assert_equals(url2.searchParams.get('a'), searchParams.get('a')); |
+ assert_equals(url1.search, '?' + query); |
+ assert_equals(url2.search, '?' + query); |
+ assert_equals(url1.toString(), base_url + 'path1?' + query); |
+ assert_equals(url2.toString(), base_url + 'path2?' + query); |
+ |
+ // Verify that updates propagate to object's set of URL objects. |
+ searchParams.set('a', 'B'); |
+ assert_equals(url1.searchParams.get('a'), 'B'); |
+ assert_equals(url2.searchParams.get('a'), 'B'); |
+ |
+ searchParams.set('new', 'value'); |
+ assert_equals(url1.searchParams.get('new'), 'value'); |
+ assert_equals(url2.searchParams.get('new'), 'value'); |
+ |
+ // If a query object loses one of its URL objects, |
+ // the connection really is observed. |
+ url1.searchParams = new URLSearchParams(); |
+ searchParams.set('a', 'b'); |
+ assert_false(url1.searchParams.has('a')); |
+ assert_equals(url2.searchParams.get('a'), 'b'); |
+ |
+ url1.searchParams.set('foo', 'bar'); |
+ assert_true(url1.searchParams.has('foo')); |
+ assert_false(url2.searchParams.has('foo')); |
+}, 'URL.searchParams setter, object updating'); |
+ |
+test(function() { |
+ var url = new URL('http://example.org/file?a=b&c=d'); |
+ var searchParams = url.searchParams; |
+ assert_equals(url.search, '?a=b&c=d'); |
+ assert_equals(searchParams.toString(), 'a=b&c=d'); |
+ |
+ // Test that setting 'search' propagates to the URL object's query |
+ // object. |
+ url.search = 'e=f&g=h'; |
+ assert_equals(url.search, '?e=f&g=h'); |
+ assert_equals(searchParams.toString(), 'e=f&g=h'); |
+ |
+ // And in the other direction; altering searchParams propagates |
+ // back to 'search'. |
+ searchParams.append('i', ' j '); |
+ assert_equals(url.search, '?e=f&g=h&i=+j+'); |
+ assert_equals(url.searchParams.toString(), 'e=f&g=h&i=+j+'); |
+ assert_equals(searchParams.get('i'), ' j '); |
+ |
+ searchParams.set('e', 'updated'); |
+ assert_equals(url.search, '?e=updated&g=h&i=+j+'); |
+ assert_equals(searchParams.get('e'), 'updated'); |
+ |
+ var url2 = new URL('http://example.org/file?a=b&c=d'); |
+ assert_equals(url2.search, '?a=b&c=d'); |
+ // Replace url2's query object. |
+ url2.searchParams = searchParams; |
+ assert_equals(url2.search, '?e=updated&g=h&i=+j+'); |
+ |
+ // Test that setting 'search' propagates to its |
+ // query object..and its associated url objects. |
+ url2.search = 'a=b'; |
+ assert_equals(url2.search, '?a=b'); |
+ assert_equals(url.search, '?a=b'); |
+ assert_equals(searchParams.toString(), 'a=b'); |
+ |
+}, 'URL.searchParamd and URL.search setters, update propagation'); |
+</script> |