about summary refs log tree commit diff stats
path: root/test/js/hyperlink.html
blob: ff7115c1421c058716c08501d75df1a9bbef2696 (plain) (blame)
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
<!doctype html>
<title>Test template</title>
<a id=invalid>invalid</a>
<a id=valid href='https://username:password@example.org/path?search#hash'>valid</a>
<div id=x>Fail</div>
<script src=asserts.js></script>
<script>
const invalid = document.getElementById("invalid");
assertEquals(invalid.href, "");
assertEquals(invalid.protocol, ":");
assertEquals(invalid.search, "");
assertEquals(invalid.hostname, "");
assertEquals(invalid.hash, "");
const valid = document.getElementById("valid");
const url = new URL("https://username:password@example.org/path?search#hash");
assertEquals(valid.protocol, "https:");
for (const x in ["href", "origin", "protocol", "username", "password", "host",
	"hostname", "port", "pathname", "search", "hash"]) {
	assertEquals(valid[x], url[x]);
}
invalid.remove();
valid.remove();
const a = document.createElement("a");
a.href = "https://example.org";
assertEquals(a + "", "https://example.org/");
assertEquals(a.protocol, "https:");
a.protocol = "http"
assertEquals(a + "", "http://example.org/")
assertEquals(a.href, "http://example.org/");
a.protocol = "ftp"
a.protocol = "http"
assertEquals(a.href, "http://example.org/");
assertEquals(a.toString(), "http://example.org/");
assertEquals(JSON.stringify(Object.getOwnPropertyDescriptors(a)), "{}");
document.getElementById("x").textContent = "Success";
</script>