2 <link rel="help" href="http://url.spec.whatwg.org/#dom-url-host">
3 <script src="../../resources/testharness.js"></script>
4 <script src="../../resources/testharnessreport.js"></script>
8 var url = new URL('https://www.mydomain.com:8080/path/');
9 assert_equals(url.host, 'www.mydomain.com:8080');
10 url.host = 'www.otherdomain.com:0';
11 assert_equals(url.href, 'https://www.otherdomain.com:0/path/');
15 var url = new URL('https://www.mydomain.com:8080/path/?key=value');
16 url.host = 'www.other?domain.com:8080';
17 assert_equals(url.href, 'https://www.other%3Fdomain.com:8080/path/?key=value');
18 }, 'Set host with ? in it');
21 var url = new URL('https://www.mydomain.com:8080/path/');
22 url.host = 'www.otherdomain.com:80';
23 assert_equals(url.href, 'https://www.otherdomain.com:80/path/');
24 }, 'Set default port for another protocol');
27 var url = new URL('https://www.mydomain.com:8080/path/');
28 url.host = 'www.otherdomain.com:443';
29 assert_equals(url.href, 'https://www.otherdomain.com/path/');
30 }, 'Set default port');
33 var url = new URL('https://www.mydomain.com:8080/path/');
34 url.host = 'www.otherdomain.com:44a5';
35 assert_equals(url.href, 'https://www.otherdomain.com:44/path/');
36 }, 'Set host with letters in port number');
39 var url = new URL('https://www.mydomain.com:8080/path/');
40 url.host = 'www.otherdomain.com: 443';
41 assert_equals(url.href, 'https://www.otherdomain.com:0/path/');
42 }, 'Leading space in port number');
45 var url = new URL('https://www.mydomain.com:8080/path/');
46 url.host = 'www.otherdomain.com:';
47 assert_equals(url.href, 'https://www.otherdomain.com:0/path/');
48 }, 'Colon without port number');
51 var url = new URL('https://www.mydomain.com:8080/path/');
53 assert_equals(url.href, 'https://null:8080/path/');
54 }, 'Set host to null');
57 var url = new URL('https://www.mydomain.com:8080/path/');
59 assert_equals(url.href, 'https://www.mydomain.com:8080/path/');
60 }, 'Set host to empty string');
63 var url = new URL('file:///path/');
64 assert_equals(url.host, '');
65 url.host = 'mydomain.com';
66 assert_equals(url.href, 'file://mydomain.com/path/');
67 }, 'Set host to URL with file: protocol');
70 var url = new URL('https://www.mydomain.com:8080/path/');
71 url.host = 'www.other\\dom/ain.com';
72 assert_equals(url.href, 'https://www.other%5Cdom%2Fain.com:8080/path/');
73 }, 'Set host containing slashes in it');
76 var url = new URL('https:/\rww.my@domain.com:8080/path/');
77 assert_equals(url.host, 'domain.com:8080');
78 url.host = 'www.other!domain.com:15';
79 assert_equals(url.href, 'https://ww.my@www.other%21domain.com:15/path/');
80 }, 'Set host to a malformed URL');
83 var url = new URL('https://domain.com:8080/path/');
84 url.host = ':www.otherdomain.com:15';
85 assert_equals(url.href, 'https://domain.com:8080/path/');
86 }, 'Set host that starts with :');
89 var url = new URL('https://rwwmy@domain.com:8080/purl..th/');
90 url.host = 'www.other!domain.com:25';
91 assert_equals(url.href, 'https://rwwmy@www.other%21domain.com:25/purl..th/');
92 }, 'Set host to URL containing username and ..');
95 var url = new URL('tel:+1-816-555-1212');
96 assert_equals(url.host, '');
97 url.host = '+1-800-555-1212';
98 assert_equals(url.href, 'tel:+1-816-555-1212');
99 }, 'Set host to a URL with tel: protocol');
102 var url = new URL('http://abc.de/path/file?query#fragment');
103 url.href = 'invalid';
104 assert_equals(url.host, '');
105 url.host = 'changed';
106 assert_equals(url.host, '');
107 assert_equals(url.href, 'invalid');
108 }, 'host property invalid URL');