<!DOCTYPE HTML>
<link rel="help" href="http://url.spec.whatwg.org/#dom-url-search">
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script>
test(function() {
var url = new URL('http://www.domain.com/');
assert_equals(url.search, '');
url = new URL('http://www.domain.com/?');
assert_equals(url.search, '');
url = new URL('http://www.domain.com/?a');
assert_equals(url.search, '?a');
url.search = '';
assert_equals(url.search, '');
assert_equals(url.toString(), 'http://www.domain.com/');
url.search = '?';
assert_equals(url.search, '');
assert_equals(url.toString(), 'http://www.domain.com/');
url.search = 'a';
assert_equals(url.search, '?a');
url.search = '?b';
assert_equals(url.search, '?b');
url.search = '??b';
assert_equals(url.search, '??b');
url.search = 'a#b';
assert_equals(url.search, '?a%23b');
url.search = 'a?b';
assert_equals(url.search, '?a?b');
}, 'Basic search');
test(function() {
var url = new URL('mailto:[email protected]');
assert_equals(url.search, '');
url.search = 'a';
assert_equals(url.search, '?a');
}, 'non hierarchical');
test(function() {
var url = new URL('http://abc.de:8080/path/file?query#fragment');
var expected = '?query';
assert_equals(url.search, expected);
assert_throws_js(TypeError, () => { url.href = 'invalid'; });
assert_equals(url.search, expected);
url.search = 'changed';
assert_equals(url.search, '?changed');
assert_equals(url.href, 'http://abc.de:8080/path/file?changed#fragment');
}, 'search property invalid URL');
</script>