7ff0b3f54b6b92ded7f555d042e35df61db7e41c
[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 // IE8 converts null to "null", which is not the right thing to do.
36 debug("Set pathname to null");
37 a.href = "https://www.mydomain.com/path/testurl.html?key=value";
38 a.pathname = null;
39 shouldBe("a.href", "'https://www.mydomain.com/?key=value'");
40
41 debug("Set pathname to empty string");
42 a.href = "https://www.mydomain.com/?key=value";
43 a.pathname = "";
44 shouldBe("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.
48 debug("Set pathname that includes illegal characters to URL that contains illegal characters.");
49 a.href = "https://www.my|d[]()omain.com/path/testurl.html?key=value";
50 a.pathname = "p$a|th";
51 shouldBe("a.href", "'https://www.my|d[]()omain.com/path/testurl.html?key=value'");
52
53 // IE8 throws a security exception.
54 try {
55 debug("Set pathname to URL that contains '@' in host");
56 a.href = "http://w@#ww";
57 a.pathname = "path";
58 shouldBe("a.href", "'http://w@/path#ww'");
59 } catch(e) {
60 debug("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 .
66 debug("Set pathname to a URL with non-hierarchical protocol");
67 a.href = "tel:+1800-555-1212";
68 a.pathname = "the-path";
69 shouldBe("a.href", "'tel:+1800-555-1212'");