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