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

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

Issue 1860623002: Add support for URL.searchParams getter. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 8 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="https://url.spec.whatwg.org/#interface-urlsearchparams">
3 <script src="../../resources/testharness.js"></script>
4 <script src="../../resources/testharnessreport.js"></script>
5 <script>
6 function assert_type_error(f, msg) {
7 assert_throws(TypeError(), f, msg);
8 }
9
10 test(function() {
11 var url = new URL('http://example.org/?a=b');
12 var searchParams = url.searchParams;
13 assert_true(url.searchParams === searchParams, 'Object identity should hold. ');
14 }, 'URL.searchParams getter');
15
16 test(function() {
17 var url = new URL('http://example.org/?a=b');
18 var searchParams = url.searchParams;
19 assert_equals(searchParams.toString(), 'a=b');
20
21 searchParams.set('a', 'b');
22 assert_equals(url.searchParams.toString(), 'a=b');
23 assert_equals(url.search, '?a=b');
24 url.search = '';
25 assert_equals(url.searchParams.toString(), '');
26 assert_equals(url.search, '');
27 assert_equals(searchParams.toString(), '');
28 }, 'URL.searchParams updating, clearing');
29
30 test(function() {
31 'use strict';
32 var urlString = 'http://example.org';
33 var url = new URL(urlString);
34 assert_type_error(function() { url.searchParams = new URLSearchParams(urlStr ing); });
35 assert_type_error(function() { url.searchParams = null; });
36 assert_type_error(function() { url.searchParams = 2; });
37 assert_type_error(function() { url.searchParams = {}; });
38 }, 'URL.searchParams setter, invalid values');
39
40 test(function() {
41 var url = new URL('http://example.org/file?a=b&c=d');
42 var searchParams = url.searchParams;
43 assert_equals(url.search, '?a=b&c=d');
44 assert_equals(searchParams.toString(), 'a=b&c=d');
45
46 // Test that setting 'search' propagates to the URL object's query
47 // object.
48 url.search = 'e=f&g=h';
49 assert_equals(url.search, '?e=f&g=h');
50 assert_equals(searchParams.toString(), 'e=f&g=h');
51
52 // ..and same but with a leading '?'.
53 url.search = '?e=f&g=h';
54 assert_equals(url.search, '?e=f&g=h');
55 assert_equals(searchParams.toString(), 'e=f&g=h');
56
57 // And in the other direction; altering searchParams propagates
58 // back to 'search'.
59 searchParams.append('i', ' j ');
60 assert_equals(url.search, '?e=f&g=h&i=+j+');
61 assert_equals(url.searchParams.toString(), 'e=f&g=h&i=+j+');
62 assert_equals(searchParams.get('i'), ' j ');
63
64 searchParams.set('e', 'updated');
65 assert_equals(url.search, '?e=updated&g=h&i=+j+');
66 assert_equals(searchParams.get('e'), 'updated');
67
68 var url2 = new URL('http://example.org/file??a=b&c=d');
69 assert_equals(url2.search, '??a=b&c=d');
70 assert_equals(url2.searchParams.toString(), '%3Fa=b&c=d');
71
72 url2.href = 'http://example.org/file??a=b';
73 assert_equals(url2.search, '??a=b');
74 assert_equals(url2.searchParams.toString(), '%3Fa=b');
75 }, 'URL.searchParams and URL.search setters, update propagation');
76 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698