1 description('Test setting the host attribute of the URL in HTMLAnchorElement.');
3 var a
= document
.createElement('a');
6 a
.href
= "https://www.mydomain.com:8080/path/";
7 a
.host
= "www.otherdomain.com:0";
8 shouldBe("a.href", "'https://www.otherdomain.com:0/path/'");
10 debug("Set host without port");
11 a
.href
= "https://www.mydomain.com:8080/path/";
12 a
.host
= "www.otherdomain.com";
13 shouldBe("a.href", "'https://www.otherdomain.com:8080/path/'");
15 // IE8 throws "The URL is invalid" exception.
16 debug("Set host with '?' in it");
18 a
.href
= "https://www.mydomain.com:8080/path/?key=value";
19 a
.host
= "www.other?domain.com:8080";
20 shouldBe("a.href", "'https://www.other/?domain.com:8080/path/?key=value'");
22 debug("Exception: " + e
.description
);
25 debug("Set default port for another protocol");
26 a
.href
= "https://www.mydomain.com:8080/path/";
27 a
.host
= "www.otherdomain.com:80";
28 shouldBe("a.href", "'https://www.otherdomain.com:80/path/'");
30 debug("Set default port");
31 a
.href
= "https://www.mydomain.com:8080/path/";
32 a
.host
= "www.otherdomain.com:443";
33 shouldBe("a.href", "'https://www.otherdomain.com/path/'");
35 debug("Set host with invalid port");
36 a
.href
= "https://www.mydomain.com:8080/path/";
37 a
.host
= "www.otherdomain.com:invalid";
38 shouldBe("a.href", "'https://www.otherdomain.com:0/path/'");
40 // Firefox 3.5.2 rejects a port that contains non-digits.
41 debug("Set host with letters in port number");
42 a
.href
= "https://www.mydomain.com:8080/path/";
43 a
.host
= "www.otherdomain.com:44a5";
44 shouldBe("a.href", "'https://www.otherdomain.com:44/path/'");
46 // Firefox 3.5.2 ignores the leading space in the port, but errs on reparsing the port.
47 debug("Leading space in port number");
48 a
.href
= "https://www.mydomain.com:8080/path/";
49 a
.host
= "www.otherdomain.com: 443";
50 shouldBe("a.href", "'https://www.otherdomain.com:0/path/'");
52 // Firefox 3.5.2 removed the port, clearly against the spec .
53 debug("Colon without port number");
54 a
.href
= "https://www.mydomain.com:8080/path/";
55 a
.host
= "www.otherdomain.com:";
56 shouldBe("a.href", "'https://www.otherdomain.com:0/path/'");
58 debug("Set host to null");
59 a
.href
= "https://www.mydomain.com:8080/path/";
61 shouldBe("a.href", "'https://null:8080/path/'");
63 // Both IE8 and Firefox 3.5.2 allow setting the host to empty string, which they shouldn't, per
64 // http://dev.w3.org/html5/spec/infrastructure.html#url-decomposition-idl-attributes .
65 // Since both do that in a buggy way, WebKit does not follow either one of them.
66 debug("Set host to empty string");
67 a
.href
= "https://www.mydomain.com:8080/path/";
69 shouldBe("a.href", "'https://www.mydomain.com:8080/path/'");
71 // Firefox 3.5.2 does not `set the host for file: .
72 debug("Set host to URL with file: protocol");
73 a
.href
= "file:///path/";
74 a
.host
= "mydomain.com";
75 shouldBe("a.href", "'file://mydomain.com/path/'");
77 // IE8 throws if the host contains '/'
78 debug("Set host containing slashes in it");
80 a
.href
= "https://www.mydomain.com:8080/path/";
81 a
.host
= "www.other\dom/ain.com";
82 shouldBe("a.href", "'https://www.otherdom%2Fain.com:8080/path/'");
84 debug("Exception: " + e
.description
);
87 // WebKit fails to strip the \r in the authority, and therefore treats the URL as invalid
88 // and gets a different result than Firefox or Chrome; we should probably strip it
89 debug("Set host to a malformed URL");
90 a
.href
= "https:/\rww.my@domain.com:8080/path/";
91 a
.host
= "www.other!domain.com:15";
92 shouldBe("a.href", "'https:/\\rww.my@domain.com:8080/path/'");
94 // IE8 throws an "Object Error" exception.
95 // Firefox 3.5.2 accepts this but throws an exception later
96 // WebKit should just reject
97 debug("Set host that starts with ':'");
99 a
.href
= "https://domain.com:8080/path/";
100 a
.host
= ":www.otherdomain.com:15";
101 shouldBe("a.href", "'https://domain.com:8080/path/'");
103 debug("Exception: " + e
.description
);
106 // IE8 throws a security exception if the host contains '@'
107 debug("Set host to URL containing username and ..");
109 a
.href
= "https://rwwmy@domain.com:8080/pa..th/";
110 a
.host
= "www.other!domain.com:25";
111 shouldBe("a.href", "'https://rwwmy@www.other!domain.com:25/pa..th/'");
113 debug("Exception: " + e
.description
);
116 // Both IE8 and Firefox append the hosts, instead of rejecting, per
117 // http://dev.w3.org/html5/spec/infrastructure.html#url-decomposition-idl-attributes .
118 debug("Set host to a URL with tel: protocol");
119 a
.href
= "tel:+1-816-555-1212";
120 a
.host
= "+1-800-555-1212";
121 shouldBe("a.href", "'tel:+1-816-555-1212'");