1description('Test setting the hostname attribute of the URL in HTMLAnchorElement.'); 2 3var a = document.createElement('a'); 4 5debug("Basic test"); 6a.href = "https://www.mydomain.com:8080/path/"; 7a.hostname = "www.otherdomain.com"; 8shouldBe("a.href", "'https://www.otherdomain.com:8080/path/'"); 9 10// IE8 throws an exception "The URL is invalid". 11try { 12debug("Extra slashes before hostname"); 13a.href = "https://www.mydomain.com:8080/path/"; 14a.hostname = "//www.otherdomain.com"; 15shouldBe("a.href", "'https://www.otherdomain.com:8080/path/'"); 16} catch(e) { 17debug("Exception: " + e.description); 18} 19 20// Firefox 3.5.2 does not allow setting the host to foo: protocol 21debug("Set hostname to URL with foo: protocol"); 22a.href = "foo://www.mydomain.com/path/"; 23a.hostname = "www.otherdomain.com"; 24shouldBe("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 . 29debug("Set hostname to null"); 30a.href = "https://www.mydomain.com:8080/path/"; 31a.hostname = null; 32shouldBe("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. 37debug("Set hostname to empty string"); 38a.href = "https://www.mydomain.com:8080/path/"; 39a.hostname = ""; 40shouldBe("a.href", "'https://www.mydomain.com:8080/path/'"); 41 42// IE8 fails to process really: protocol. 43debug("Set hostname to URL with 2 colons"); 44a.href = "really:bad:url"; 45a.hostname = "mydomain.com"; 46shouldBe("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. 52debug("Set a hostname that contains space in it"); 53a.href = "http://www.my domain.com/path/"; 54a.hostname = "www.other domain.com"; 55shouldBe("a.href", "'http://www.my domain.com/path/'"); 56 57// IE8 throws an exception "The URL is invalid". 58try { 59debug("Set hostname on a local file"); 60a.href = "c:/path/testurl.html"; 61a.hostname= "a"; 62shouldBe("a.href", "'c:/path/testurl.html'"); 63} catch(e) { 64debug("Exception: " + e.description); 65} 66 67debug("Set hostname to undefined"); 68a.href = "https://www.mydomain.com:8080/path/"; 69a.hostname = undefined; 70shouldBe("a.href", "'https://undefined:8080/path/'"); 71 72var successfullyParsed = true; 73