1description('Test setting the host attribute of the URL in HTMLAnchorElement.');
2
3var a = document.createElement('a');
4
5debug("Basic test");
6a.href = "https://www.mydomain.com:8080/path/";
7a.host = "www.otherdomain.com:0";
8shouldBe("a.href", "'https://www.otherdomain.com:0/path/'");
9
10// IE8 throws "The URL is invalid" exception.
11debug("Set host with '?' in it");
12try {
13a.href = "https://www.mydomain.com:8080/path/?key=value";
14a.host = "www.other?domain.com:8080";
15shouldBe("a.href", "'https://www.other/?domain.com:8080/path/?key=value'");
16} catch(e) {
17debug("Exception: " + e.description);
18}
19
20debug("Set default port for another protocol");
21a.href = "https://www.mydomain.com:8080/path/";
22a.host = "www.otherdomain.com:80";
23shouldBe("a.href", "'https://www.otherdomain.com:80/path/'");
24
25debug("Set default port");
26a.href = "https://www.mydomain.com:8080/path/";
27a.host = "www.otherdomain.com:443";
28shouldBe("a.href", "'https://www.otherdomain.com/path/'");
29
30// Firefox 3.5.2 rejects a port that contains non-digits.
31debug("Set host with letters in port number");
32a.href = "https://www.mydomain.com:8080/path/";
33a.host = "www.otherdomain.com:44a5";
34shouldBe("a.href", "'https://www.otherdomain.com:44/path/'");
35
36// Firefox 3.5.2 ignores the leading space in the port, but errs on reparsing the port.
37debug("Leading space in port number");
38a.href = "https://www.mydomain.com:8080/path/";
39a.host = "www.otherdomain.com: 443";
40shouldBe("a.href", "'https://www.otherdomain.com:0/path/'");
41
42// Firefox 3.5.2 removed the port, clearly against the spec .
43debug("Colon without port number");
44a.href = "https://www.mydomain.com:8080/path/";
45a.host = "www.otherdomain.com:";
46shouldBe("a.href", "'https://www.otherdomain.com:0/path/'");
47
48// IE8 converts null to "null", which is not the right thing to do.
49// Firefox 3.5.2 allows setting the host to null, which it shouldn't per
50// http://dev.w3.org/html5/spec/infrastructure.html#url-decomposition-idl-attributes .
51debug("Set host to null");
52a.href = "https://www.mydomain.com:8080/path/";
53a.host = null;
54shouldBe("a.href", "'https://www.mydomain.com:8080/path/'");
55
56// Both IE8 and Firefox 3.5.2 allow setting the host to empty string, which they shouldn't, per
57// http://dev.w3.org/html5/spec/infrastructure.html#url-decomposition-idl-attributes .
58// Since both do that in a buggy way, WebKit does not follow either one of them.
59debug("Set host to empty string");
60a.href = "https://www.mydomain.com:8080/path/";
61a.host = "";
62shouldBe("a.href", "'https://www.mydomain.com:8080/path/'");
63
64// Firefox 3.5.2 does not `set the host for file: .
65debug("Set host to URL with file: protocol");
66a.href = "file:///path/";
67a.host = "mydomain.com";
68shouldBe("a.href", "'file://mydomain.com/path/'");
69
70// IE8 throws if the host contains '/'
71debug("Set host containing slashes in it");
72try {
73a.href = "https://www.mydomain.com:8080/path/";
74a.host = "www.other\dom/ain.com";
75shouldBe("a.href", "'https://www.otherdom/ain.com/path/'");
76} catch(e) {
77debug("Exception: " + e.description);
78}
79
80// Firefox 3.5.2 add the missing '/' thus gets a different result than IE8 and Webkit.
81debug("Set host to a malformed URL");
82a.href = "https:/\rww.my@domain.com:8080/path/";
83a.host = "www.other!domain.com:15";
84shouldBe("a.href", "'https://www.other!domain.com:15/ww.my@domain.com:8080/path/'");
85
86// IE8 throws an "Object Error" exception.
87// Firefox 3.5.2 accepts this but throws an exception later
88// WebKit should just reject
89debug("Set host that starts with ':'");
90try {
91a.href = "https://domain.com:8080/path/";
92a.host = ":www.otherdomain.com:15";
93shouldBe("a.href", "'https://domain.com:8080/path/'");
94} catch(e) {
95debug("Exception: " + e.description);
96}
97
98// IE8 throws a security exception if the host contains '@'
99debug("Set host to URL containing username and ..");
100try {
101a.href = "https://rwwmy@domain.com:8080/pa..th/";
102a.host = "www.other!domain.com:25";
103shouldBe("a.href", "'https://rwwmy@www.other!domain.com:25/pa..th/'");
104} catch(e) {
105debug("Exception: " + e.description);
106}
107
108// Both IE8 and Firefox append the hosts, instead of rejecting, per
109// http://dev.w3.org/html5/spec/infrastructure.html#url-decomposition-idl-attributes .
110debug("Set host to a URL with tel: protocol");
111a.href = "tel:+1-816-555-1212";
112a.host = "+1-800-555-1212";
113shouldBe("a.href", "'tel:+1-816-555-1212'");
114
115var successfullyParsed = true;
116