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