| OLD | NEW |
| (Empty) |
| 1 description('Test setting the host attribute of the URL in HTMLAnchorElement.'); | |
| 2 | |
| 3 var a = document.createElement('a'); | |
| 4 | |
| 5 debug("Basic test"); | |
| 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/'"); | |
| 9 | |
| 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/'"); | |
| 14 | |
| 15 // IE8 throws "The URL is invalid" exception. | |
| 16 debug("Set host with '?' in it"); | |
| 17 try { | |
| 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'"); | |
| 21 } catch(e) { | |
| 22 debug("Exception: " + e.description); | |
| 23 } | |
| 24 | |
| 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/'"); | |
| 29 | |
| 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/'"); | |
| 34 | |
| 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/'"); | |
| 39 | |
| 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/'"); | |
| 45 | |
| 46 // Firefox 3.5.2 ignores the leading space in the port, but errs on reparsing th
e 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/'"); | |
| 51 | |
| 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/'"); | |
| 57 | |
| 58 debug("Set host to null"); | |
| 59 a.href = "https://www.mydomain.com:8080/path/"; | |
| 60 a.host = null; | |
| 61 shouldBe("a.href", "'https://null:8080/path/'"); | |
| 62 | |
| 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-attrib
utes . | |
| 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/"; | |
| 68 a.host = ""; | |
| 69 shouldBe("a.href", "'https://www.mydomain.com:8080/path/'"); | |
| 70 | |
| 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/'"); | |
| 76 | |
| 77 // IE8 throws if the host contains '/' | |
| 78 debug("Set host containing slashes in it"); | |
| 79 try { | |
| 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/'"); | |
| 83 } catch(e) { | |
| 84 debug("Exception: " + e.description); | |
| 85 } | |
| 86 | |
| 87 // WebKit fails to strip the \r in the authority, and therefore treats the URL a
s 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/'"); | |
| 93 | |
| 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 ':'"); | |
| 98 try { | |
| 99 a.href = "https://domain.com:8080/path/"; | |
| 100 a.host = ":www.otherdomain.com:15"; | |
| 101 shouldBe("a.href", "'https://domain.com:8080/path/'"); | |
| 102 } catch(e) { | |
| 103 debug("Exception: " + e.description); | |
| 104 } | |
| 105 | |
| 106 // IE8 throws a security exception if the host contains '@' | |
| 107 debug("Set host to URL containing username and .."); | |
| 108 try { | |
| 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/'"); | |
| 112 } catch(e) { | |
| 113 debug("Exception: " + e.description); | |
| 114 } | |
| 115 | |
| 116 // Both IE8 and Firefox append the hosts, instead of rejecting, per | |
| 117 // http://dev.w3.org/html5/spec/infrastructure.html#url-decomposition-idl-attrib
utes . | |
| 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'"); | |
| OLD | NEW |