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(func, expected) { |
7 function assertThrows(func, expected) { | |
8 try { | 7 try { |
9 func(); | 8 func(); |
10 } catch (ex) { | 9 } catch (ex) { |
| 10 assert_true(ex instanceof TypeError); |
11 assert_equals(String(ex), expected); | 11 assert_equals(String(ex), expected); |
12 return; | 12 return; |
13 } | 13 } |
14 assert_true(false, 'Expected an exception with string: ' + expected); | 14 assert_true(false, 'Expected a TypeError exception with string: ' + expected
); |
15 } | 15 } |
16 | 16 |
17 test(function() { | 17 test(function() { |
18 assert_equals(new URL('http://www.domain.com/a/b').toString(), 'http://www.d
omain.com/a/b'); | 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'); | 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'); | 20 assert_equals(new URL('b/c', 'http://www.domain.com/a/b').toString(), 'http:
//www.domain.com/a/b/c'); |
21 | 21 |
22 var base = new URL('http://www.domain.com/a/b'); | 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'
); | 23 assert_equals(new URL('b/c', base).toString(), 'http://www.domain.com/a/b/c'
); |
24 | 24 |
25 // Unmatched surrogate handling | 25 // Unmatched surrogate handling |
26 var encodedReplacementCharacter = encodeURIComponent('\ufffd'); | 26 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'); | 27 assert_equals(new URL('b/c', 'http://www.domain.com/\ud801/b').toString(), '
http://www.domain.com/' + encodedReplacementCharacter + '/b/c'); |
28 }, 'Valid URLs'); | 28 }, 'Valid URLs'); |
29 | 29 |
30 test(function() { | 30 test(function() { |
31 assertThrows(function() { | 31 assert_type_error( |
32 new URL(); | 32 function() { new URL(); }, |
33 }, 'TypeError: Failed to construct \'URL\': 1 argument required, but only 0
present.'); | 33 'TypeError: Failed to construct \'URL\': 1 argument required, but only 0
present.'); |
34 assertThrows(function() { | 34 assert_type_error( |
35 new URL(''); | 35 function() { new URL(''); }, |
36 }, 'TypeError: Failed to construct \'URL\': Invalid URL'); | 36 'TypeError: Failed to construct \'URL\': Invalid URL'); |
37 assertThrows(function() { | 37 assert_type_error( |
38 new URL('','about:blank'); | 38 function() { new URL('','about:blank'); }, |
39 }, 'TypeError: Failed to construct \'URL\': Invalid URL'); | 39 'TypeError: Failed to construct \'URL\': Invalid URL'); |
40 assertThrows(function() { | 40 assert_type_error( |
41 new URL('abc'); | 41 function() { new URL('abc'); }, |
42 }, 'TypeError: Failed to construct \'URL\': Invalid URL'); | 42 'TypeError: Failed to construct \'URL\': Invalid URL'); |
43 assertThrows(function() { | 43 assert_type_error( |
44 new URL('//abc'); | 44 function() { new URL('//abc'); }, |
45 }, 'TypeError: Failed to construct \'URL\': Invalid URL'); | 45 'TypeError: Failed to construct \'URL\': Invalid URL'); |
46 assertThrows(function() { | 46 assert_type_error( |
47 new URL('http:///www.domain.com/', 'abc'); | 47 function() { new URL('http:///www.domain.com/', 'abc'); }, |
48 }, 'TypeError: Failed to construct \'URL\': Invalid base URL'); | 48 'TypeError: Failed to construct \'URL\': Invalid base URL'); |
49 assertThrows(function() { | 49 assert_type_error( |
50 new URL('http:///www.domain.com/', null); | 50 function() { new URL('http:///www.domain.com/', null); }, |
51 }, 'TypeError: Failed to construct \'URL\': Invalid base URL'); | 51 'TypeError: Failed to construct \'URL\': Invalid base URL'); |
| 52 assert_type_error( |
| 53 function() { new URL('//abc', null); }, |
| 54 'TypeError: Failed to construct \'URL\': Invalid base URL'); |
52 }, 'Invalid URL parameters'); | 55 }, 'Invalid URL parameters'); |
53 | |
54 </script> | 56 </script> |
OLD | NEW |