Home | History | Annotate | Download | only in script-tests
      1 description('Test setting the protocol 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/path/";
      7 a.protocol = "http-foo";
      8 shouldBe("a.href", "'http-foo://www.mydomain.com/path/'");
      9 
     10 // IE8 throws "Invalid argument" exception.
     11 debug("Set a protocol that contains ':'");
     12 try {
     13 a.href = "https://www.mydomain.com/path/";
     14 a.protocol = "http:foo";
     15 shouldBe("a.href", "'http://www.mydomain.com/path/'");
     16 } catch(e) {
     17 debug("Exception: " + e.description);
     18 }
     19 
     20 // IE8 throws "Invalid argument" exception.
     21 debug("Set a protocol that contains invalid characters");
     22 try {
     23 a.href = "https://www.mydomain.com/path/";
     24 a.protocol = "http^foo";
     25 shouldBe("a.href", "'https://www.mydomain.com/path/'");
     26 } catch(e) {
     27 debug("Exception: " + e.description);
     28 }
     29 
     30 // The expected behavior should change when the character table is updated.
     31 // IE8 encodes '^' in the host.
     32 debug("Set a protocol to a URL with invalid host name");
     33 a.href = "h:^^";
     34 a.protocol = "foo";
     35 shouldBe("a.href", "'foo:^^'");
     36 
     37 // IE8 throws "Invalid argument" exception.
     38 try {
     39 debug("Set a protocol that starts with ':'");
     40 a.href = "https://www.mydomain.com/path/";
     41 a.protocol = ":http";
     42 shouldBe("a.href", "'https://www.mydomain.com/path/'");
     43 } catch(e) {
     44 debug("Exception: " + e.description);
     45 }
     46 
     47 // IE8 converts null to "null", which is not the right thing to do.
     48 debug("Set protocol to null");
     49 a.href = "https://www.mydomain.com/path/";
     50 a.protocol = null;
     51 shouldBe("a.href", "'https://www.mydomain.com/path/'");
     52 
     53 // IE8 throws "Invalid argument" exception.
     54 try {
     55 debug("Set protocol to empty string");
     56 a.href = "https://www.mydomain.com/path/";
     57 a.protocol = "";
     58 shouldBe("a.href", "'https://www.mydomain.com/path/'");
     59 } catch(e) {
     60 debug("Exception: " + e.description);
     61 }
     62 
     63 // Firefox 3.5.2 tries to build a hierarchical URL.
     64 debug("Set protocol to http on malformed URL");
     65 a.href = "foo:??bar";
     66 a.protocol = "http";
     67 shouldBe("a.href", "'http:??bar'");
     68 
     69 // IE8 keeps the protocol if it is 'c:'.
     70 debug("Set protocol to a URL which points to a local file");
     71 a.href = "c:\path";
     72 a.protocol = "f-oo";
     73 shouldBe("a.href", "'f-oo:path'");
     74 
     75 debug("Set protocol to undefined");
     76 a.href = "https://www.mydomain.com/path/";
     77 a.protocol = undefined;
     78 shouldBe("a.href", "'undefined://www.mydomain.com/path/'");
     79 
     80 var successfullyParsed = true;
     81