1description('Test setting the hash attribute of the URL in HTMLAnchorElement.'); 2 3var a = document.createElement('a'); 4 5debug("Hash value does not start with '#'"); 6a.href = "https://www.mydomain.com:8080/path/testurl.html#middle"; 7a.hash = "hash-value"; 8shouldBe("a.href", "'https://www.mydomain.com:8080/path/testurl.html#hash-value'"); 9 10debug("Hash value starts with '#'"); 11a.href = "file:///path/testurl.html#middle"; 12a.hash = "#hash_value"; 13shouldBe("a.href", "'file:///path/testurl.html#hash_value'"); 14 15debug("'?' in hash value"); 16a.href = "http://www.mydomain.com/path/testurl.html#middle"; 17a.hash = "#hash?value"; 18shouldBe("a.href", "'http://www.mydomain.com/path/testurl.html#hash?value'"); 19 20// The expected behavior should change when character table is updated. 21// IE8 and Firefox3.5.2 don't consider these characters as illegal. 22debug("'#' in hash value, and illegal characters in hostname"); 23a.href = "https://www.my\"d(){}|~om?ain#com/path/testurl.html#middle"; 24a.hash = "#hash#value"; 25shouldBe("a.href", "'https://www.my\"d(){}|~om?ain#com/path/testurl.html#middle'"); 26 27// IE8 converts null to "null", which is not the right thing to do. 28// Firefox 3.5.2 removes the '#' at the end, and it should per 29// http://dev.w3.org/html5/spec/infrastructure.html#url-decomposition-idl-attributes . 30debug("Set hash to null"); 31a.href = "https://www.mydomain.com/path/testurl.html#middle"; 32a.hash = null; 33shouldBe("a.href", "'https://www.mydomain.com/path/testurl.html#'"); 34 35// Firefox 3.5.2 removes the '#' at the end, and it should per 36// http://dev.w3.org/html5/spec/infrastructure.html#url-decomposition-idl-attributes . 37debug("Set hash to empty string"); 38a.href = "https://www.mydomain.com/path/testurl.html#middle"; 39a.hash = ""; 40shouldBe("a.href", "'https://www.mydomain.com/path/testurl.html#'"); 41 42// Firefox 3.5.2 does not allow setting hash to mailto: scheme, and it should. 43debug("Add hash to mailto: protocol"); 44a.href = "mailto:e-mail_address@goes_here"; 45a.hash = "hash-value"; 46shouldBe("a.href", "'mailto:e-mail_address@goes_here#hash-value'"); 47 48// IE8 does not percent-encode spaces in the hash component, but it does that 49// in the path component. 50debug("Add hash to file: protocol"); 51a.href = "file:///some path"; 52a.hash = "hash value"; 53shouldBe("a.href", "'file:///some%20path#hash value'"); 54 55debug("Set hash to '#'"); 56a.href = "http://mydomain.com#middle"; 57a.hash = "#"; 58shouldBe("a.href", "'http://mydomain.com/#'"); 59 60// Firefox 3.5.2 does not allow setting hash to foo: scheme, and it should. 61debug("Add hash to non-standard protocol"); 62try { 63a.href = "foo:bar"; 64a.hash = "#hash"; 65shouldBe("a.href", "'foo:bar#hash'"); 66} catch(e) { 67debug("Exception: " + e.description); 68} 69 70var successfullyParsed = true; 71