Home | History | Annotate | Download | only in script-tests
      1 description('Test setting the host 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.host = "www.otherdomain.com:0";
      8 shouldBe("a.href", "'https://www.otherdomain.com:0/path/'");
      9 
     10 // IE8 throws "The URL is invalid" exception.
     11 debug("Set host with '?' in it");
     12 try {
     13 a.href = "https://www.mydomain.com:8080/path/?key=value";
     14 a.host = "www.other?domain.com:8080";
     15 shouldBe("a.href", "'https://www.other/?domain.com:8080/path/?key=value'");
     16 } catch(e) {
     17 debug("Exception: " + e.description);
     18 }
     19 
     20 debug("Set default port for another protocol");
     21 a.href = "https://www.mydomain.com:8080/path/";
     22 a.host = "www.otherdomain.com:80";
     23 shouldBe("a.href", "'https://www.otherdomain.com:80/path/'");
     24 
     25 debug("Set default port");
     26 a.href = "https://www.mydomain.com:8080/path/";
     27 a.host = "www.otherdomain.com:443";
     28 shouldBe("a.href", "'https://www.otherdomain.com/path/'");
     29 
     30 // Firefox 3.5.2 rejects a port that contains non-digits.
     31 debug("Set host with letters in port number");
     32 a.href = "https://www.mydomain.com:8080/path/";
     33 a.host = "www.otherdomain.com:44a5";
     34 shouldBe("a.href", "'https://www.otherdomain.com:44/path/'");
     35 
     36 // Firefox 3.5.2 ignores the leading space in the port, but errs on reparsing the port.
     37 debug("Leading space in port number");
     38 a.href = "https://www.mydomain.com:8080/path/";
     39 a.host = "www.otherdomain.com: 443";
     40 shouldBe("a.href", "'https://www.otherdomain.com:0/path/'");
     41 
     42 // Firefox 3.5.2 removed the port, clearly against the spec .
     43 debug("Colon without port number");
     44 a.href = "https://www.mydomain.com:8080/path/";
     45 a.host = "www.otherdomain.com:";
     46 shouldBe("a.href", "'https://www.otherdomain.com:0/path/'");
     47 
     48 // IE8 converts null to "null", which is not the right thing to do.
     49 // Firefox 3.5.2 allows setting the host to null, which it shouldn't per
     50 // http://dev.w3.org/html5/spec/infrastructure.html#url-decomposition-idl-attributes .
     51 debug("Set host to null");
     52 a.href = "https://www.mydomain.com:8080/path/";
     53 a.host = null;
     54 shouldBe("a.href", "'https://www.mydomain.com:8080/path/'");
     55 
     56 // Both IE8 and Firefox 3.5.2 allow setting the host to empty string, which they shouldn't, per
     57 // http://dev.w3.org/html5/spec/infrastructure.html#url-decomposition-idl-attributes .
     58 // Since both do that in a buggy way, WebKit does not follow either one of them.
     59 debug("Set host to empty string");
     60 a.href = "https://www.mydomain.com:8080/path/";
     61 a.host = "";
     62 shouldBe("a.href", "'https://www.mydomain.com:8080/path/'");
     63 
     64 // Firefox 3.5.2 does not `set the host for file: .
     65 debug("Set host to URL with file: protocol");
     66 a.href = "file:///path/";
     67 a.host = "mydomain.com";
     68 shouldBe("a.href", "'file://mydomain.com/path/'");
     69 
     70 // IE8 throws if the host contains '/'
     71 debug("Set host containing slashes in it");
     72 try {
     73 a.href = "https://www.mydomain.com:8080/path/";
     74 a.host = "www.other\dom/ain.com";
     75 shouldBe("a.href", "'https://www.otherdom/ain.com/path/'");
     76 } catch(e) {
     77 debug("Exception: " + e.description);
     78 }
     79 
     80 // Firefox 3.5.2 add the missing '/' thus gets a different result than IE8 and Webkit.
     81 debug("Set host to a malformed URL");
     82 a.href = "https:/\rww.my (a] domain.com:8080/path/";
     83 a.host = "www.other!domain.com:15";
     84 shouldBe("a.href", "'https://www.other!domain.com:15/ww.my@domain.com:8080/path/'");
     85 
     86 // IE8 throws an "Object Error" exception.
     87 // Firefox 3.5.2 accepts this but throws an exception later
     88 // WebKit should just reject
     89 debug("Set host that starts with ':'");
     90 try {
     91 a.href = "https://domain.com:8080/path/";
     92 a.host = ":www.otherdomain.com:15";
     93 shouldBe("a.href", "'https://domain.com:8080/path/'");
     94 } catch(e) {
     95 debug("Exception: " + e.description);
     96 }
     97 
     98 // IE8 throws a security exception if the host contains '@'
     99 debug("Set host to URL containing username and ..");
    100 try {
    101 a.href = "https://rwwmy@domain.com:8080/pa..th/";
    102 a.host = "www.other!domain.com:25";
    103 shouldBe("a.href", "'https://rwwmy@www.other!domain.com:25/pa..th/'");
    104 } catch(e) {
    105 debug("Exception: " + e.description);
    106 }
    107 
    108 // Both IE8 and Firefox append the hosts, instead of rejecting, per
    109 // http://dev.w3.org/html5/spec/infrastructure.html#url-decomposition-idl-attributes .
    110 debug("Set host to a URL with tel: protocol");
    111 a.href = "tel:+1-816-555-1212";
    112 a.host = "+1-800-555-1212";
    113 shouldBe("a.href", "'tel:+1-816-555-1212'");
    114 
    115 var successfullyParsed = true;
    116