Home | History | Annotate | Download | only in script-tests
      1 description('Test setting the hash attribute of the URL in HTMLAnchorElement.');
      2 
      3 var a = document.createElement('a');
      4 
      5 debug("Hash value does not start with '#'");
      6 a.href = "https://www.mydomain.com:8080/path/testurl.html#middle";
      7 a.hash = "hash-value";
      8 shouldBe("a.href", "'https://www.mydomain.com:8080/path/testurl.html#hash-value'");
      9 
     10 debug("Hash value starts with '#'");
     11 a.href = "file:///path/testurl.html#middle";
     12 a.hash = "#hash_value";
     13 shouldBe("a.href", "'file:///path/testurl.html#hash_value'");
     14 
     15 debug("'?' in hash value");
     16 a.href = "http://www.mydomain.com/path/testurl.html#middle";
     17 a.hash = "#hash?value";
     18 shouldBe("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.
     22 debug("'#' in hash value, and illegal characters in hostname");
     23 a.href = "https://www.my\"d(){}|~om?ain#com/path/testurl.html#middle";
     24 a.hash = "#hash#value";
     25 shouldBe("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 .
     30 debug("Set hash to null");
     31 a.href = "https://www.mydomain.com/path/testurl.html#middle";
     32 a.hash = null;
     33 shouldBe("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 .
     37 debug("Set hash to empty string");
     38 a.href = "https://www.mydomain.com/path/testurl.html#middle";
     39 a.hash = "";
     40 shouldBe("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.
     43 debug("Add hash to mailto: protocol");
     44 a.href = "mailto:e-mail_address@goes_here";
     45 a.hash = "hash-value";
     46 shouldBe("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.
     50 debug("Add hash to file: protocol");
     51 a.href = "file:///some path";
     52 a.hash = "hash value";
     53 shouldBe("a.href", "'file:///some%20path#hash value'");
     54 
     55 debug("Set hash to '#'");
     56 a.href = "http://mydomain.com#middle";
     57 a.hash = "#";
     58 shouldBe("a.href", "'http://mydomain.com/#'");
     59 
     60 // Firefox 3.5.2 does not allow setting hash to foo: scheme, and it should.
     61 debug("Add hash to non-standard protocol");
     62 try {
     63 a.href = "foo:bar";
     64 a.hash = "#hash";
     65 shouldBe("a.href", "'foo:bar#hash'");
     66 } catch(e) {
     67 debug("Exception: " + e.description);
     68 }
     69 
     70 var successfullyParsed = true;
     71