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>
7 function assertThrows(func, expected) {
11 assert_equals(String(ex), expected);
14 assert_true(false, 'Expected an exception with string: ' + expected);
18 assert_equals(new URL('http://www.domain.com/a/b').toString(), 'http://www.domain.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');
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');
25 // Unmatched surrogate handling
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');
31 assertThrows(function() {
33 }, 'TypeError: Failed to construct \'URL\': 1 argument required, but only 0 present.');
34 assertThrows(function() {
36 }, 'SyntaxError: Failed to construct \'URL\': Invalid URL');
37 assertThrows(function() {
39 }, 'SyntaxError: Failed to construct \'URL\': Invalid URL');
40 assertThrows(function() {
41 new URL('http:///www.domain.com/', 'abc');
42 }, 'SyntaxError: Failed to construct \'URL\': Invalid base URL');
43 assertThrows(function() {
44 new URL('http:///www.domain.com/', null);
45 }, 'SyntaxError: Failed to construct \'URL\': Invalid base URL');
46 }, 'Invalid URL parameters');