| 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-hostname.js"></script> | 7 <script> |
| 8 description('Test setting the hostname 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.hostname = "www.otherdomain.com"; |
| 15 shouldBe("a.href", "'https://www.otherdomain.com:8080/path/'"); |
| 16 |
| 17 // IE8 throws an exception "The URL is invalid". |
| 18 try { |
| 19 debug("Extra slashes before hostname"); |
| 20 a.href = "https://www.mydomain.com:8080/path/"; |
| 21 a.hostname = "//www.otherdomain.com"; |
| 22 shouldBe("a.href", "'https://www.otherdomain.com:8080/path/'"); |
| 23 } catch(e) { |
| 24 debug("Exception: " + e.description); |
| 25 } |
| 26 |
| 27 // Firefox 3.5.2 does not allow setting the host to foo: protocol |
| 28 debug("Set hostname to URL with foo: protocol"); |
| 29 a.href = "foo://www.mydomain.com/path/"; |
| 30 a.hostname = "www.otherdomain.com"; |
| 31 shouldBe("a.href", "'foo://www.otherdomain.com/path/'"); |
| 32 |
| 33 debug("Set hostname to null"); |
| 34 a.href = "https://www.mydomain.com:8080/path/"; |
| 35 a.hostname = null; |
| 36 shouldBe("a.href", "'https://null:8080/path/'"); |
| 37 |
| 38 // Both IE8 and Firefox 3.5.2 allow setting the host to empty string, against th
e spec at |
| 39 // http://dev.w3.org/html5/spec/infrastructure.html#url-decomposition-idl-attrib
utes . |
| 40 // Since both do that in a buggy way, WebKit should not follow either one of the
m. |
| 41 debug("Set hostname to empty string"); |
| 42 a.href = "https://www.mydomain.com:8080/path/"; |
| 43 a.hostname = ""; |
| 44 shouldBe("a.href", "'https://www.mydomain.com:8080/path/'"); |
| 45 |
| 46 // IE8 fails to process really: protocol. |
| 47 debug("Set hostname to URL with 2 colons"); |
| 48 a.href = "really:bad:url"; |
| 49 a.hostname = "mydomain.com"; |
| 50 shouldBe("a.href", "'really:bad:url'"); |
| 51 |
| 52 // The expected behavior should change when the character table is updated. |
| 53 // IE8 encodes the space in the hostname. |
| 54 // Firefox3.5.2 and WebKit consider space as illegal character and would not set
|
| 55 // the new hostname. |
| 56 debug("Set a hostname that contains space in it"); |
| 57 a.href = "http://www.my domain.com/path/"; |
| 58 a.hostname = "www.other domain.com"; |
| 59 shouldBe("a.href", "'http://www.my domain.com/path/'"); |
| 60 |
| 61 // IE8 throws an exception "The URL is invalid". |
| 62 try { |
| 63 debug("Set hostname on a local file"); |
| 64 a.href = "c:/path/testurl.html"; |
| 65 a.hostname= "a"; |
| 66 shouldBe("a.href", "'c:/path/testurl.html'"); |
| 67 } catch(e) { |
| 68 debug("Exception: " + e.description); |
| 69 } |
| 70 |
| 71 debug("Set hostname to undefined"); |
| 72 a.href = "https://www.mydomain.com:8080/path/"; |
| 73 a.hostname = undefined; |
| 74 shouldBe("a.href", "'https://undefined:8080/path/'"); |
| 75 </script> |
| 8 </body> | 76 </body> |
| 9 </html> | 77 </html> |
| OLD | NEW |