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