| OLD | NEW |
| (Empty) | |
| 1 <!DOCTYPE HTML> |
| 2 <link rel="help" href="http://url.spec.whatwg.org/#dom-url"> |
| 3 <script src="../../resources/testharness.js"></script> |
| 4 <script src="../../resources/testharnessreport.js"></script> |
| 5 <script> |
| 6 |
| 7 function assertThrows(func, expected) { |
| 8 try { |
| 9 func(); |
| 10 } catch (ex) { |
| 11 assert_equals(String(ex), expected); |
| 12 return; |
| 13 } |
| 14 assert_true(false, 'Expected an exception with string: ' + expected); |
| 15 } |
| 16 |
| 17 test(function() { |
| 18 assert_equals(new URL('http://www.domain.com/a/b').toString(), 'http://www.d
omain.com/a/b'); |
| 19 assert_equals(new URL('/c/d', 'http://www.domain.com/a/b').toString(), 'http
://www.domain.com/c/d'); |
| 20 assert_equals(new URL('b/c', 'http://www.domain.com/a/b').toString(), 'http:
//www.domain.com/a/b/c'); |
| 21 |
| 22 var base = new URL('http://www.domain.com/a/b'); |
| 23 assert_equals(new URL('b/c', base).toString(), 'http://www.domain.com/a/b/c'
); |
| 24 }, 'Valid URLs'); |
| 25 |
| 26 test(function() { |
| 27 assertThrows(function() { |
| 28 new URL(); |
| 29 }, 'TypeError: Failed to construct \'URL\': 1 argument required, but only 0
present.'); |
| 30 assertThrows(function() { |
| 31 new URL('abc'); |
| 32 }, 'SyntaxError: Failed to construct \'URL\': Invalid URL'); |
| 33 assertThrows(function() { |
| 34 new URL('//abc'); |
| 35 }, 'SyntaxError: Failed to construct \'URL\': Invalid URL'); |
| 36 assertThrows(function() { |
| 37 new URL('http:///www.domain.com/', 'abc'); |
| 38 }, 'SyntaxError: Failed to construct \'URL\': Invalid base URL'); |
| 39 assertThrows(function() { |
| 40 new URL('http:///www.domain.com/', null); |
| 41 }, 'SyntaxError: Failed to construct \'URL\': Invalid base URL'); |
| 42 }, 'Invalid URL parameters'); |
| 43 |
| 44 </script> |
| OLD | NEW |