1promise_test(() => fetch("resources/urltestdata.json").then(res => res.json()).then(runURLTests), "Loading data…"); 2 3function setBase(base) { 4 document.getElementById("base").href = base 5} 6 7function bURL(url, base) { 8 base = base || "about:blank" 9 setBase(base) 10 var a = document.createElement("a") 11 a.setAttribute("href", url) 12 return a 13} 14 15function runURLTests(urltests) { 16 for(var i = 0, l = urltests.length; i < l; i++) { 17 var expected = urltests[i] 18 if (typeof expected === "string") continue // skip comments 19 20 test(function() { 21 var url = bURL(expected.input, expected.base) 22 if(expected.failure) { 23 if(url.protocol !== ':') { 24 assert_unreached("Expected URL to fail parsing") 25 } 26 assert_equals(url.href, expected.input, "failure should set href to input") 27 return 28 } 29 30 assert_equals(url.href, expected.href, "href") 31 assert_equals(url.protocol, expected.protocol, "protocol") 32 assert_equals(url.username, expected.username, "username") 33 assert_equals(url.password, expected.password, "password") 34 assert_equals(url.host, expected.host, "host") 35 assert_equals(url.hostname, expected.hostname, "hostname") 36 assert_equals(url.port, expected.port, "port") 37 assert_equals(url.pathname, expected.pathname, "pathname") 38 assert_equals(url.search, expected.search, "search") 39 assert_equals(url.hash, expected.hash, "hash") 40 }, "Parsing: <" + expected.input + "> against <" + expected.base + ">") 41 } 42} 43