blob: 1350c66e7820186da488772a19c3a4fe93207838 [file] [log] [blame]
<!DOCTYPE HTML>
<link rel="help" href="http://url.spec.whatwg.org/#dom-url-hostname">
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script>
test(function() {
var url = new URL('https://www.mydomain.com/path/');
assert_equals(url.hostname, 'www.mydomain.com');
url.hostname = 'www.otherdomain.com';
assert_equals(url.href, 'https://www.otherdomain.com/path/');
}, 'Basic test');
test(function() {
var url = new URL('https://www.mydomain.com/path/?key=value');
url.hostname = 'www.other?domain.com';
assert_equals(url.href, 'https://www.other%3Fdomain.com/path/?key=value');
}, 'Set hostname with ? in it');
test(function() {
var url = new URL('https://www.mydomain.com/path/');
url.hostname = null;
assert_equals(url.href, 'https://null/path/');
}, 'Set hostname to null');
test(function() {
var url = new URL('https://www.mydomain.com/path/');
url.hostname = '';
assert_equals(url.href, 'https://www.mydomain.com/path/');
}, 'Set hostname to empty string');
test(function() {
var url = new URL('file:///path/');
assert_equals(url.hostname, '');
url.hostname = 'mydomain.com';
assert_equals(url.href, 'file://mydomain.com/path/');
}, 'Set hostname to URL with file: protocol');
test(function() {
var url = new URL('https://www.mydomain.com/path/');
url.hostname = 'www.other\\dom/ain.com';
assert_equals(url.href, 'https://www.other%5Cdom%2Fain.com/path/');
}, 'Set hostname containing slashes in it');
test(function() {
var url = new URL('https:/\rww.my@domain.com/path/');
assert_equals(url.hostname, 'domain.com');
url.hostname = 'www.other!domain.com';
assert_equals(url.href, 'https://ww.my@www.other%21domain.com/path/');
}, 'Set hostname to a malformed URL');
test(function() {
var url = new URL('https://rwwmy@domain.com/purl..th/');
url.hostname = 'www.other!domain.com';
assert_equals(url.href, 'https://rwwmy@www.other%21domain.com/purl..th/');
}, 'Set hostname to URL containing username and ..');
test(function() {
var url = new URL('tel:+1-816-555-1212');
assert_equals(url.hostname, '');
url.hostname = '+1-800-555-1212';
assert_equals(url.href, 'tel:+1-816-555-1212');
}, 'Set hostname to a URL with tel: protocol');
test(function() {
var url = new URL('http://abc.de/path/file?query#fragment');
url.href = 'invalid';
assert_equals(url.hostname, '');
url.host = 'changed';
assert_equals(url.hostname, '');
assert_equals(url.href, 'invalid');
}, 'hostname property invalid URL');
</script>