| OLD | NEW |
| 1 <!DOCTYPE HTML> | 1 <!DOCTYPE HTML> |
| 2 <link rel="help" href="http://url.spec.whatwg.org/#dom-url"> | 2 <link rel="help" href="http://url.spec.whatwg.org/#dom-url"> |
| 3 <script src="../../resources/testharness.js"></script> | 3 <script src="../../resources/testharness.js"></script> |
| 4 <script src="../../resources/testharnessreport.js"></script> | 4 <script src="../../resources/testharnessreport.js"></script> |
| 5 <script> | 5 <script> |
| 6 | 6 function assert_type_error(f, msg) { |
| 7 function assertThrows(func, expected) { | 7 assert_throws(TypeError(), f, msg); |
| 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 } | 8 } |
| 16 | 9 |
| 17 test(function() { | 10 test(function() { |
| 18 assert_equals(new URL('http://www.domain.com/a/b').toString(), 'http://www.d
omain.com/a/b'); | 11 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'); | 12 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'); | 13 assert_equals(new URL('b/c', 'http://www.domain.com/a/b').toString(), 'http:
//www.domain.com/a/b/c'); |
| 21 | 14 |
| 22 var base = new URL('http://www.domain.com/a/b'); | 15 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'
); | 16 assert_equals(new URL('b/c', base).toString(), 'http://www.domain.com/a/b/c'
); |
| 24 | 17 |
| 25 // Unmatched surrogate handling | 18 // Unmatched surrogate handling |
| 26 var encodedReplacementCharacter = encodeURIComponent('\ufffd'); | 19 var encodedReplacementCharacter = encodeURIComponent('\ufffd'); |
| 27 assert_equals(new URL('b/c', 'http://www.domain.com/\ud801/b').toString(), '
http://www.domain.com/' + encodedReplacementCharacter + '/b/c'); | 20 assert_equals(new URL('b/c', 'http://www.domain.com/\ud801/b').toString(), '
http://www.domain.com/' + encodedReplacementCharacter + '/b/c'); |
| 28 }, 'Valid URLs'); | 21 }, 'Valid URLs'); |
| 29 | 22 |
| 30 test(function() { | 23 test(function() { |
| 31 assertThrows(function() { | 24 assert_type_error( |
| 32 new URL(); | 25 function() { new URL(); }, |
| 33 }, 'TypeError: Failed to construct \'URL\': 1 argument required, but only 0
present.'); | 26 'TypeError: Failed to construct \'URL\': 1 argument required, but only 0
present.'); |
| 34 assertThrows(function() { | 27 assert_type_error( |
| 35 new URL(''); | 28 function() { new URL(''); }, |
| 36 }, 'TypeError: Failed to construct \'URL\': Invalid URL'); | 29 'TypeError: Failed to construct \'URL\': Invalid URL'); |
| 37 assertThrows(function() { | 30 assert_type_error( |
| 38 new URL('','about:blank'); | 31 function() { new URL('','about:blank'); }, |
| 39 }, 'TypeError: Failed to construct \'URL\': Invalid URL'); | 32 'TypeError: Failed to construct \'URL\': Invalid URL'); |
| 40 assertThrows(function() { | 33 assert_type_error( |
| 41 new URL('abc'); | 34 function() { new URL('abc'); }, |
| 42 }, 'TypeError: Failed to construct \'URL\': Invalid URL'); | 35 'TypeError: Failed to construct \'URL\': Invalid URL'); |
| 43 assertThrows(function() { | 36 assert_type_error( |
| 44 new URL('//abc'); | 37 function() { new URL('//abc'); }, |
| 45 }, 'TypeError: Failed to construct \'URL\': Invalid URL'); | 38 'TypeError: Failed to construct \'URL\': Invalid URL'); |
| 46 assertThrows(function() { | 39 assert_type_error( |
| 47 new URL('http:///www.domain.com/', 'abc'); | 40 function() { new URL('http:///www.domain.com/', 'abc'); }, |
| 48 }, 'TypeError: Failed to construct \'URL\': Invalid base URL'); | 41 'TypeError: Failed to construct \'URL\': Invalid base URL'); |
| 49 assertThrows(function() { | 42 assert_type_error( |
| 50 new URL('http:///www.domain.com/', null); | 43 function() { new URL('http:///www.domain.com/', null); }, |
| 51 }, 'TypeError: Failed to construct \'URL\': Invalid base URL'); | 44 'TypeError: Failed to construct \'URL\': Invalid base URL'); |
| 45 assert_type_error( |
| 46 function() { new URL('//abc', null); }, |
| 47 'TypeError: Failed to construct \'URL\': Invalid base URL'); |
| 52 }, 'Invalid URL parameters'); | 48 }, 'Invalid URL parameters'); |
| 53 | |
| 54 </script> | 49 </script> |
| OLD | NEW |