1a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochdescription('Tests that when an href attribute is set, the href is no longer subject to updates to the document base URI.');
2a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
3a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochvar a = document.createElement('a');
4a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochvar base = document.createElement('base');
5a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochdocument.head.appendChild(base);
6a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
7a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
8a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochdebug("Search attribute, update document base URI without attribute having been set");
9a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochbase.href = "http://old_base/";
10a94275402997c11dd2e778633dacf4b7e630a35dBen Murdocha.href = "?search";
11a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochbase.href = "http://new_base/";
12a94275402997c11dd2e778633dacf4b7e630a35dBen MurdochshouldBe("a.href", "'http://new_base/?search'");
13a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
14a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochdebug("Search attribute, update document base URI after attribute has been set");
15a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochbase.href = "http://old_base/";
16a94275402997c11dd2e778633dacf4b7e630a35dBen Murdocha.href = "?foo";
17a94275402997c11dd2e778633dacf4b7e630a35dBen Murdocha.search = "search";
18a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochbase.href = "http://new_base/";
19a94275402997c11dd2e778633dacf4b7e630a35dBen MurdochshouldBe("a.href", "'http://old_base/?search'");
20a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochdebug('');
21a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
22a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
23a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochdebug("Pathname attribute, update document base URI without attribute having been set");
24a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochbase.href = "http://old_base/";
25a94275402997c11dd2e778633dacf4b7e630a35dBen Murdocha.href = "path";
26a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochbase.href = "http://new_base/";
27a94275402997c11dd2e778633dacf4b7e630a35dBen MurdochshouldBe("a.href", "'http://new_base/path'");
28a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
29a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochdebug("Pathname attribute, update document base URI after attribute has been set");
30a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochbase.href = "http://old_base/";
31a94275402997c11dd2e778633dacf4b7e630a35dBen Murdocha.href = "foo";
32a94275402997c11dd2e778633dacf4b7e630a35dBen Murdocha.pathname = "path";
33a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochbase.href = "http://new_base/";
34a94275402997c11dd2e778633dacf4b7e630a35dBen MurdochshouldBe("a.href", "'http://old_base/path'");
35a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochdebug('');
36a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
37a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
38a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochdebug("Hash attribute, update document base URI without attribute having been set");
39a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochbase.href = "http://old_base/";
40a94275402997c11dd2e778633dacf4b7e630a35dBen Murdocha.href = "#hash";
41a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochbase.href = "http://new_base/";
42a94275402997c11dd2e778633dacf4b7e630a35dBen MurdochshouldBe("a.href", "'http://new_base/#hash'");
43a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
44a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochdebug("Pathname attribute, update document base URI after attribute has been set");
45a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochbase.href = "http://old_base/";
46a94275402997c11dd2e778633dacf4b7e630a35dBen Murdocha.href = "#foo";
47a94275402997c11dd2e778633dacf4b7e630a35dBen Murdocha.hash = "hash";
48a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochbase.href = "http://new_base/";
49a94275402997c11dd2e778633dacf4b7e630a35dBen MurdochshouldBe("a.href", "'http://old_base/#hash'");
50a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochdebug('');
51a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
52a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
53a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochdebug('Note that for the following attributes, updating the document base URI has no effect because we have to use an abosulte URL for the href in order to set an initial value for the attribute we wish to update. They are included for completeness.');
54a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochdebug('');
55a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
56a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
57a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochdebug("Host attribute, update document base URI without attribute having been set");
58a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochbase.href = "http://old_base/";
59a94275402997c11dd2e778633dacf4b7e630a35dBen Murdocha.href = "http://host:0";
60a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochbase.href = "http://new_base/";
61a94275402997c11dd2e778633dacf4b7e630a35dBen MurdochshouldBe("a.href", "'http://host:0/'");
62a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
63a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochdebug("Host attribute, update document base URI after attribute has been set");
64a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochbase.href = "http://old_base/";
65a94275402997c11dd2e778633dacf4b7e630a35dBen Murdocha.href = "http://foo:80";
66a94275402997c11dd2e778633dacf4b7e630a35dBen Murdocha.host = "host:0";
67a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochbase.href = "http://new_base/";
68a94275402997c11dd2e778633dacf4b7e630a35dBen MurdochshouldBe("a.href", "'http://host:0/'");
69a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochdebug('');
70a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
71a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
72a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochdebug("Hostname attribute, update document base URI without attribute having been set");
73a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochbase.href = "http://old_base/";
74a94275402997c11dd2e778633dacf4b7e630a35dBen Murdocha.href = "http://host";
75a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochbase.href = "http://new_base/";
76a94275402997c11dd2e778633dacf4b7e630a35dBen MurdochshouldBe("a.href", "'http://host/'");
77a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
78a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochdebug("Hostname attribute, update document base URI after attribute has been set");
79a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochbase.href = "http://old_base/";
80a94275402997c11dd2e778633dacf4b7e630a35dBen Murdocha.href = "http://foo";
81a94275402997c11dd2e778633dacf4b7e630a35dBen Murdocha.hostname = "host";
82a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochbase.href = "http://new_base/";
83a94275402997c11dd2e778633dacf4b7e630a35dBen MurdochshouldBe("a.href", "'http://host/'");
84a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochdebug('');
85a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
86a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
87a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochdebug("Protocol attribute, update document base URI without attribute having been set");
88a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochbase.href = "http://old_base/";
89a94275402997c11dd2e778633dacf4b7e630a35dBen Murdocha.href = "protocol:";
90a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochbase.href = "http://new_base/";
91a94275402997c11dd2e778633dacf4b7e630a35dBen MurdochshouldBe("a.href", "'protocol:'");
92a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
93a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochdebug("Protocol attribute, update document base URI after attribute has been set");
94a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochbase.href = "http://old_base/";
95a94275402997c11dd2e778633dacf4b7e630a35dBen Murdocha.href = "foo:";
96a94275402997c11dd2e778633dacf4b7e630a35dBen Murdocha.protocol = "protocol:";
97a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochbase.href = "http://new_base/";
98a94275402997c11dd2e778633dacf4b7e630a35dBen MurdochshouldBe("a.href", "'protocol:'");
99a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochdebug('');
100a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
101a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
102a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochdebug("Port attribute, update document base URI without attribute having been set");
103a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochbase.href = "http://old_base/";
104a94275402997c11dd2e778633dacf4b7e630a35dBen Murdocha.href = "http://host:0";
105a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochbase.href = "http://new_base/";
106a94275402997c11dd2e778633dacf4b7e630a35dBen MurdochshouldBe("a.href", "'http://host:0/'");
107a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
108a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochdebug("Port attribute, update document base URI after attribute has been set");
109a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochbase.href = "http://old_base/";
110a94275402997c11dd2e778633dacf4b7e630a35dBen Murdocha.href = "http://host:80";
111a94275402997c11dd2e778633dacf4b7e630a35dBen Murdocha.port = 0;
112a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochbase.href = "http://new_base/";
113a94275402997c11dd2e778633dacf4b7e630a35dBen MurdochshouldBe("a.href", "'http://host:0/'");
114a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochdebug('');
115a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
116a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
117a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochbase.href = '';
118a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochvar successfullyParsed = true;
119