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