| OLD | NEW |
| (Empty) | |
| 1 <!DOCTYPE HTML> |
| 2 <link rel="help" href="http://url.spec.whatwg.org/#dom-url-hostname"> |
| 3 <script src="../../resources/testharness.js"></script> |
| 4 <script src="../../resources/testharnessreport.js"></script> |
| 5 <script> |
| 6 |
| 7 test(function() { |
| 8 var url = new URL('https://www.mydomain.com/path/'); |
| 9 assert_equals(url.hostname, 'www.mydomain.com'); |
| 10 url.hostname = 'www.otherdomain.com'; |
| 11 assert_equals(url.href, 'https://www.otherdomain.com/path/'); |
| 12 }, 'Basic test'); |
| 13 |
| 14 test(function() { |
| 15 var url = new URL('https://www.mydomain.com/path/?key=value'); |
| 16 url.hostname = 'www.other?domain.com'; |
| 17 assert_equals(url.href, 'https://www.other%3Fdomain.com/path/?key=value'); |
| 18 }, 'Set hostname with ? in it'); |
| 19 |
| 20 test(function() { |
| 21 var url = new URL('https://www.mydomain.com/path/'); |
| 22 url.hostname = null; |
| 23 assert_equals(url.href, 'https://null/path/'); |
| 24 }, 'Set hostname to null'); |
| 25 |
| 26 test(function() { |
| 27 var url = new URL('https://www.mydomain.com/path/'); |
| 28 url.hostname = ''; |
| 29 assert_equals(url.href, 'https://www.mydomain.com/path/'); |
| 30 }, 'Set hostname to empty string'); |
| 31 |
| 32 test(function() { |
| 33 var url = new URL('file:///path/'); |
| 34 assert_equals(url.hostname, ''); |
| 35 url.hostname = 'mydomain.com'; |
| 36 assert_equals(url.href, 'file://mydomain.com/path/'); |
| 37 }, 'Set hostname to URL with file: protocol'); |
| 38 |
| 39 test(function() { |
| 40 var url = new URL('https://www.mydomain.com/path/'); |
| 41 url.hostname = 'www.other\\dom/ain.com'; |
| 42 assert_equals(url.href, 'https://www.other%5Cdom%2Fain.com/path/'); |
| 43 }, 'Set hostname containing slashes in it'); |
| 44 |
| 45 test(function() { |
| 46 var url = new URL('https:/\rww.my@domain.com/path/'); |
| 47 assert_equals(url.hostname, 'domain.com'); |
| 48 url.hostname = 'www.other!domain.com'; |
| 49 assert_equals(url.href, 'https://ww.my@www.other%21domain.com/path/'); |
| 50 }, 'Set hostname to a malformed URL'); |
| 51 |
| 52 test(function() { |
| 53 var url = new URL('https://rwwmy@domain.com/purl..th/'); |
| 54 url.hostname = 'www.other!domain.com'; |
| 55 assert_equals(url.href, 'https://rwwmy@www.other%21domain.com/purl..th/'); |
| 56 }, 'Set hostname to URL containing username and ..'); |
| 57 |
| 58 test(function() { |
| 59 var url = new URL('tel:+1-816-555-1212'); |
| 60 assert_equals(url.hostname, ''); |
| 61 url.hostname = '+1-800-555-1212'; |
| 62 assert_equals(url.href, 'tel:+1-816-555-1212'); |
| 63 }, 'Set hostname to a URL with tel: protocol'); |
| 64 |
| 65 test(function() { |
| 66 var url = new URL('http://abc.de/path/file?query#fragment'); |
| 67 url.href = 'invalid'; |
| 68 assert_equals(url.hostname, ''); |
| 69 url.host = 'changed'; |
| 70 assert_equals(url.hostname, ''); |
| 71 assert_equals(url.href, 'invalid'); |
| 72 }, 'hostname property invalid URL'); |
| 73 |
| 74 </script> |
| OLD | NEW |