| <!DOCTYPE HTML> |
| <link rel="help" href="http://url.spec.whatwg.org/#dom-url-port"> |
| <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.port, ''); |
| |
| url = new URL('http://www.domain.com:8080/'); |
| assert_equals(url.port, '8080'); |
| |
| url.port = 8081; |
| assert_equals(url.port, '8081'); |
| |
| url.port = ''; |
| assert_equals(url.port, ''); |
| |
| url.port = 80; |
| assert_equals(url.port, ''); |
| |
| url.port = 0; |
| assert_equals(url.port, '0'); |
| |
| url.port = '8080junk'; |
| assert_equals(url.port, '8080'); |
| |
| url.port = 'junk8080'; |
| assert_equals(url.port, '0'); |
| }, 'Basic port'); |
| |
| test(function() { |
| var url = new URL('mailto:foo@bar.com'); |
| assert_equals(url.port, ''); |
| |
| url = new URL('file:///home/abarth'); |
| assert_equals(url.port, ''); |
| }, 'no port'); |
| |
| test(function() { |
| var url = new URL('http://abc.de:8080/path/file?query#fragment'); |
| url.href = 'invalid'; |
| assert_equals(url.port, ''); |
| |
| url.port = '8081'; |
| assert_equals(url.port, ''); |
| assert_equals(url.href, 'invalid'); |
| }, 'port property invalid URL'); |
| |
| </script> |