| Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 1 | <?xml version="1.0" encoding="UTF-8"?> |
| 2 | <!DOCTYPE html> |
| 3 | <html xmlns="http://www.w3.org/1999/xhtml"> |
| 4 | <head> |
| 5 | <title>URL Test</title> |
| 6 | <link rel="author" title="Intel" href="http://www.intel.com/" /> |
| 7 | <link rel="help" href="http://www.w3.org/html/wg/drafts/html/CR/infrastructure.html#urls" /> |
| 8 | <script src="/resources/testharness.js"></script> |
| 9 | <script src="/resources/testharnessreport.js"></script> |
| 10 | <script src="urltestparser.js"></script> |
| 11 | </head> |
| 12 | <body> |
| 13 | <div id="log"></div> |
| 14 | <script> |
| 15 | <![CDATA[ |
| 16 | var setup = async_test("Loading data…") |
| 17 | setup.step(function() { |
| 18 | var request = new XMLHttpRequest() |
| 19 | request.open("GET", "urltestdata.txt") |
| 20 | request.send() |
| 21 | request.responseType = "text" |
| 22 | request.onload = setup.step_func(function() { |
| 23 | runURLTests(request.response); |
| 24 | setup.done() |
| 25 | }) |
| 26 | }) |
| 27 | |
| 28 | function setBase(base) { |
| 29 | document.body.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:base", base); |
| 30 | } |
| 31 | |
| 32 | function bURL(url, base) { |
| 33 | base = base || "about:blank" |
| 34 | setBase(base) |
| 35 | var a = document.createElement("a") |
| 36 | a.setAttribute("href", url) |
| 37 | document.body.appendChild(a) |
| 38 | return a |
| 39 | } |
| 40 | |
| 41 | function runURLTests(raw) { |
| 42 | var urltests = URLTestParser(raw) |
| 43 | for(var i = 0, l = urltests.length; i < l; i++) { |
| 44 | var expected = urltests[i] |
| 45 | test(function() { |
| 46 | var url = bURL(expected.input, expected.base) |
| 47 | if(expected.protocol === ':' && url.protocol !== ':') |
| 48 | assert_unreached('Expected URL to fail parsing') |
| 49 | assert_equals(url.protocol, expected.protocol, "scheme") |
| 50 | assert_equals(url.hostname, expected.hostname, "host") |
| 51 | assert_equals(url.port, expected.port, "port") |
| 52 | assert_equals(url.pathname, expected.path, "path") |
| 53 | assert_equals(url.search, expected.search, "search") |
| 54 | assert_equals(url.hash, expected.hash, "hash") |
| 55 | assert_equals(url.href, expected.href, "href") |
| 56 | }, "Parsing: <" + expected.input + "> against <" + expected.base + ">") |
| 57 | } |
| 58 | } |
| 59 | ]]> |
| 60 | </script> |
| 61 | </body> |
| 62 | </html> |