• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1test(function() {
2    var params = new URLSearchParams('a=b&c=d');
3    params.delete('a');
4    assert_equals(params + '', 'c=d');
5    params = new URLSearchParams('a=a&b=b&a=a&c=c');
6    params.delete('a');
7    assert_equals(params + '', 'b=b&c=c');
8    params = new URLSearchParams('a=a&=&b=b&c=c');
9    params.delete('');
10    assert_equals(params + '', 'a=a&b=b&c=c');
11    params = new URLSearchParams('a=a&null=null&b=b');
12    params.delete(null);
13    assert_equals(params + '', 'a=a&b=b');
14    params = new URLSearchParams('a=a&undefined=undefined&b=b');
15    params.delete(undefined);
16    assert_equals(params + '', 'a=a&b=b');
17}, 'Delete basics');
18
19test(function() {
20    var params = new URLSearchParams();
21    params.append('first', 1);
22    assert_true(params.has('first'), 'Search params object has name "first"');
23    assert_equals(params.get('first'), '1', 'Search params object has name "first" with value "1"');
24    params.delete('first');
25    assert_false(params.has('first'), 'Search params object has no "first" name');
26    params.append('first', 1);
27    params.append('first', 10);
28    params.delete('first');
29    assert_false(params.has('first'), 'Search params object has no "first" name');
30}, 'Deleting appended multiple');
31
32test(function() {
33    var url = new URL('http://example.com/?param1&param2');
34    url.searchParams.delete('param1');
35    url.searchParams.delete('param2');
36    assert_equals(url.href, 'http://example.com/', 'url.href does not have ?');
37    assert_equals(url.search, '', 'url.search does not have ?');
38}, 'Deleting all params removes ? from URL');
39
40test(function() {
41    var url = new URL('http://example.com/?');
42    url.searchParams.delete('param1');
43    assert_equals(url.href, 'http://example.com/', 'url.href does not have ?');
44    assert_equals(url.search, '', 'url.search does not have ?');
45}, 'Removing non-existent param removes ? from URL');
46
47test(() => {
48  const url = new URL('data:space    ?test');
49  assert_true(url.searchParams.has('test'));
50  url.searchParams.delete('test');
51  assert_false(url.searchParams.has('test'));
52  assert_equals(url.search, '');
53  assert_equals(url.pathname, 'space');
54  assert_equals(url.href, 'data:space');
55}, 'Changing the query of a URL with an opaque path can impact the path');
56
57test(() => {
58  const url = new URL('data:space    ?test#test');
59  url.searchParams.delete('test');
60  assert_equals(url.search, '');
61  assert_equals(url.pathname, 'space    ');
62  assert_equals(url.href, 'data:space    #test');
63}, 'Changing the query of a URL with an opaque path can impact the path if the URL has no fragment');
64
65test(() => {
66  const params = new URLSearchParams();
67  params.append('a', 'b');
68  params.append('a', 'c');
69  params.append('a', 'd');
70  params.delete('a', 'c');
71  assert_equals(params.toString(), 'a=b&a=d');
72}, "Two-argument delete()");
73