Ignore URL.origin in URL web-platform-tests
[WebKit-https.git] / LayoutTests / imported / w3c / web-platform-tests / url / a-element.js
1 var setup = async_test("Loading data‚Ķ")
2 setup.step(function() {
3   var request = new XMLHttpRequest()
4   request.open("GET", "urltestdata.json")
5   request.send()
6   request.responseType = "json"
7   request.onload = setup.step_func(function() {
8     runURLTests(request.response)
9     setup.done()
10   })
11 })
12
13 function setBase(base) {
14   document.getElementById("base").href = base
15 }
16
17 function bURL(url, base) {
18   base = base || "about:blank"
19   setBase(base)
20   var a = document.createElement("a")
21   a.setAttribute("href", url)
22   return a
23 }
24
25 function runURLTests(urltests) {
26   for(var i = 0, l = urltests.length; i < l; i++) {
27     var expected = urltests[i]
28     if (typeof expected === "string") continue // skip comments
29
30     test(function() {
31       var url = bURL(expected.input, expected.base)
32       if(expected.failure) {
33         if(url.protocol !== ':') {
34           assert_unreached("Expected URL to fail parsing")
35         }
36         assert_equals(url.href, expected.input, "failure should set href to input")
37         return
38       }
39
40       assert_equals(url.href, expected.href, "href")
41       assert_equals(url.protocol, expected.protocol, "protocol")
42       assert_equals(url.username, expected.username, "username")
43       assert_equals(url.password, expected.password, "password")
44       assert_equals(url.host, expected.host, "host")
45       assert_equals(url.hostname, expected.hostname, "hostname")
46       assert_equals(url.port, expected.port, "port")
47       assert_equals(url.pathname, expected.pathname, "pathname")
48       assert_equals(url.search, expected.search, "search")
49       assert_equals(url.hash, expected.hash, "hash")
50     }, "Parsing: <" + expected.input + "> against <" + expected.base + ">")
51   }
52 }