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 // IE8 throws "The URL is invalid" exception.
11 debug("Set host with '?' in it");
13 a.href = "https://www.mydomain.com:8080/path/?key=value";
14 a.host = "www.other?domain.com:8080";
15 shouldBe("a.href", "'https://www.other/?domain.com:8080/path/?key=value'");
17 debug("Exception: " + e.description);
20 debug("Set default port for another protocol");
21 a.href = "https://www.mydomain.com:8080/path/";
22 a.host = "www.otherdomain.com:80";
23 shouldBe("a.href", "'https://www.otherdomain.com:80/path/'");
25 debug("Set default port");
26 a.href = "https://www.mydomain.com:8080/path/";
27 a.host = "www.otherdomain.com:443";
28 shouldBe("a.href", "'https://www.otherdomain.com/path/'");
30 // Firefox 3.5.2 rejects a port that contains non-digits.
31 debug("Set host with letters in port number");
32 a.href = "https://www.mydomain.com:8080/path/";
33 a.host = "www.otherdomain.com:44a5";
34 shouldBe("a.href", "'https://www.otherdomain.com:44/path/'");
36 // Firefox 3.5.2 ignores the leading space in the port, but errs on reparsing the port.
37 debug("Leading space in port number");
38 a.href = "https://www.mydomain.com:8080/path/";
39 a.host = "www.otherdomain.com: 443";
40 shouldBe("a.href", "'https://www.otherdomain.com:0/path/'");
42 // Firefox 3.5.2 removed the port, clearly against the spec .
43 debug("Colon without port number");
44 a.href = "https://www.mydomain.com:8080/path/";
45 a.host = "www.otherdomain.com:";
46 shouldBe("a.href", "'https://www.otherdomain.com:0/path/'");
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 .
51 debug("Set host to null");
52 a.href = "https://www.mydomain.com:8080/path/";
54 shouldBe("a.href", "'https://www.mydomain.com:8080/path/'");
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.
59 debug("Set host to empty string");
60 a.href = "https://www.mydomain.com:8080/path/";
62 shouldBe("a.href", "'https://www.mydomain.com:8080/path/'");
64 // Firefox 3.5.2 does not `set the host for file: .
65 debug("Set host to URL with file: protocol");
66 a.href = "file:///path/";
67 a.host = "mydomain.com";
68 shouldBe("a.href", "'file://mydomain.com/path/'");
70 // IE8 throws if the host contains '/'
71 debug("Set host containing slashes in it");
73 a.href = "https://www.mydomain.com:8080/path/";
74 a.host = "www.other\dom/ain.com";
75 shouldBe("a.href", "'https://www.otherdom/ain.com/path/'");
77 debug("Exception: " + e.description);
80 // WebKit fails to strip the \r in the authority, and therefore treats the URL as invalid
81 // and gets a different result than Firefox or Chrome; we should probably strip it
82 debug("Set host to a malformed URL");
83 a.href = "https:/\rww.my@domain.com:8080/path/";
84 a.host = "www.other!domain.com:15";
85 shouldBe("a.href", "'https:/\\rww.my@domain.com:8080/path/'");
87 // IE8 throws an "Object Error" exception.
88 // Firefox 3.5.2 accepts this but throws an exception later
89 // WebKit should just reject
90 debug("Set host that starts with ':'");
92 a.href = "https://domain.com:8080/path/";
93 a.host = ":www.otherdomain.com:15";
94 shouldBe("a.href", "'https://domain.com:8080/path/'");
96 debug("Exception: " + e.description);
99 // IE8 throws a security exception if the host contains '@'
100 debug("Set host to URL containing username and ..");
102 a.href = "https://rwwmy@domain.com:8080/pa..th/";
103 a.host = "www.other!domain.com:25";
104 shouldBe("a.href", "'https://rwwmy@www.other!domain.com:25/pa..th/'");
106 debug("Exception: " + e.description);
109 // Both IE8 and Firefox append the hosts, instead of rejecting, per
110 // http://dev.w3.org/html5/spec/infrastructure.html#url-decomposition-idl-attributes .
111 debug("Set host to a URL with tel: protocol");
112 a.href = "tel:+1-816-555-1212";
113 a.host = "+1-800-555-1212";
114 shouldBe("a.href", "'tel:+1-816-555-1212'");