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