| OLD | NEW |
| (Empty) | |
| 1 <!DOCTYPE HTML> |
| 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> |
| 5 <script> |
| 6 |
| 7 test(function() { |
| 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/'); |
| 12 }, 'Basic test'); |
| 13 |
| 14 test(function() { |
| 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'); |
| 19 |
| 20 test(function() { |
| 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'); |
| 25 |
| 26 test(function() { |
| 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'); |
| 31 |
| 32 test(function() { |
| 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'); |
| 37 |
| 38 test(function() { |
| 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'); |
| 43 |
| 44 test(function() { |
| 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'); |
| 49 |
| 50 test(function() { |
| 51 var url = new URL('https://www.mydomain.com:8080/path/'); |
| 52 url.host = null; |
| 53 assert_equals(url.href, 'https://null:8080/path/'); |
| 54 }, 'Set host to null'); |
| 55 |
| 56 test(function() { |
| 57 var url = new URL('https://www.mydomain.com:8080/path/'); |
| 58 url.host = ''; |
| 59 assert_equals(url.href, 'https://www.mydomain.com:8080/path/'); |
| 60 }, 'Set host to empty string'); |
| 61 |
| 62 test(function() { |
| 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'); |
| 68 |
| 69 test(function() { |
| 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'); |
| 74 |
| 75 test(function() { |
| 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'); |
| 81 |
| 82 test(function() { |
| 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 :'); |
| 87 |
| 88 test(function() { |
| 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 ..'); |
| 93 |
| 94 test(function() { |
| 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'); |
| 100 |
| 101 test(function() { |
| 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'); |
| 109 |
| 110 </script> |
| OLD | NEW |