1description('Test setting the pathname attribute of the URL in HTMLAnchorElement.');
2
3var a = document.createElement('a');
4
5debug("Set pathname that starts with slash");
6a.href = "https://www.mydomain.com/path/testurl.html?key=value";
7a.pathname = "/path name";
8shouldBe("a.href", "'https://www.mydomain.com/path%20name?key=value'");
9
10// IE8 throws an "Invalid URL" exception.
11try {
12debug("Set pathname that does not start with slash and contains '?'");
13a.href = "https://www.mydomain.com/path/testurl.html?key=value";
14a.pathname = "pa?th";
15shouldBe("a.href", "'https://www.mydomain.com/pa%3Fth?key=value'");
16} catch(e) {
17debug("Exception: " + e.description);
18}
19
20// IE8 throws an "Invalid URL" exception.
21try {
22debug("Set pathname that starts with double slash and contains '#'");
23a.href = "https://www.mydomain.com/path?key=value";
24a.pathname = "//path#name";
25shouldBe("a.href", "'https://www.mydomain.com//path%23name?key=value'");
26} catch(e) {
27debug("Exception: " + e.description);
28}
29
30debug("Set a pathname containing .. in it");
31a.href = "https://www.mydomain.com/path/testurl.html?key=value";
32a.pathname = "/it/../path";
33shouldBe("a.href", "'https://www.mydomain.com/path?key=value'");
34
35// IE8 converts null to "null", which is not the right thing to do.
36debug("Set pathname to null");
37a.href = "https://www.mydomain.com/path/testurl.html?key=value";
38a.pathname = null;
39shouldBe("a.href", "'https://www.mydomain.com/?key=value'");
40
41debug("Set pathname to empty string");
42a.href = "https://www.mydomain.com/?key=value";
43a.pathname = "";
44shouldBe("a.href", "'https://www.mydomain.com/?key=value'");
45
46// The expected behavior should change when the character table is updated.
47// IE8 considers this URL as valid.
48debug("Set pathname that includes illegal characters to URL that contains illegal characters.");
49a.href = "https://www.my|d[]()omain.com/path/testurl.html?key=value";
50a.pathname = "p$a|th";
51shouldBe("a.href", "'https://www.my|d[]()omain.com/path/testurl.html?key=value'");
52
53// IE8 throws a security exception.
54try {
55debug("Set pathname to URL that contains '@' in host");
56a.href = "http://w@#ww";
57a.pathname = "path";
58shouldBe("a.href", "'http://w@/path#ww'");
59} catch(e) {
60debug("Exception: " + e.description);
61}
62
63// IE8 allows setting the pathname, for non-hierarchial URL.
64// It is not supposed to allow that per
65// http://dev.w3.org/html5/spec/infrastructure.html#url-decomposition-idl-attributes .
66debug("Set pathname to a URL with non-hierarchical protocol");
67a.href = "tel:+1800-555-1212";
68a.pathname = "the-path";
69shouldBe("a.href", "'tel:+1800-555-1212'");
70
71var successfullyParsed = true;
72