This repository has been archived by the owner on Jun 6, 2019. It is now read-only.
forked from annevk/url
-
Notifications
You must be signed in to change notification settings - Fork 52
/
urltestharness.html
59 lines (54 loc) · 1.66 KB
/
urltestharness.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<!doctype html>
<base id=base>
<meta charset=utf-8>
<link rel=stylesheet href=testharness.css>
<script src=testharness.js></script>
<script src=testharnessreport.js></script>
<script src=urltestparser.js></script>
<script>forceJURL = true;</script>
<script src="url.js"></script>
<div id=log></div>
<script>
test(function() {
var u = new URL('http://a/foo');
var u2 = new URL('bar', u);
assert_equals(u.href, 'http://a/foo');
}, 'Consistency Check');
var setup = async_test("Loading data…")
setup.step(function() {
var request = new XMLHttpRequest()
request.open("GET", "urltests.txt")
request.send()
request.responseType = "text"
request.onload = setup.step_func(function() {
runURLTests(request.response);
setup.done()
})
})
function setBase(base) {
document.getElementById("base").href = base
}
function bURL(url, base) {
base = base || "about:blank"
setBase(base)
var a = document.createElement("a")
a.setAttribute("href", url)
return a
}
function runURLTests(raw) {
var urltests = URLTestParser(raw)
for(var i = 0, l = urltests.length; i < l; i++) {
var expected = urltests[i]
test(function() {
var url = bURL(expected.input, expected.base)
assert_equals(url.protocol, expected.protocol, "scheme")
assert_equals(url.hostname, expected.host, "host")
assert_equals(url.port, expected.port, "port")
assert_equals(url.pathname, expected.path, "path")
assert_equals(url.search, expected.search, "search")
assert_equals(url.hash, expected.hash, "hash")
assert_equals(url.href, expected.href, "href")
}, "Parsing: <" + expected.input + "> against <" + expected.base + ">")
}
}
</script>