Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / dom / HTMLAnchorElement / script-tests / set-href-attribute-pathname.js
blob44412f1ca5dfb3ce16aee2190fc0aafb7824184b
1 description('Test setting the pathname attribute of the URL in HTMLAnchorElement.');
3 var a = document.createElement('a');
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'");
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);
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);
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'");
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'");
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'");
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'");
52 // IE8 throws a security exception.
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@/path#ww'");
58 } catch(e) {
59 debug("Exception: " + e.description);
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'");