|
1 function test() { |
|
2 /** Test for Bug 396843 **/ |
|
3 waitForExplicitFinish(); |
|
4 |
|
5 function testInDocument(doc, documentID) { |
|
6 |
|
7 var allNodes = []; |
|
8 var XMLNodes = []; |
|
9 |
|
10 // HTML |
|
11 function HTML_TAG(name) { |
|
12 allNodes.push(doc.createElement(name)); |
|
13 } |
|
14 |
|
15 /* List copy/pasted from nsHTMLTagList.h */ |
|
16 HTML_TAG("a", "Anchor") |
|
17 HTML_TAG("abbr", "Span") |
|
18 HTML_TAG("acronym", "Span") |
|
19 HTML_TAG("address", "Span") |
|
20 HTML_TAG("applet", "SharedObject") |
|
21 HTML_TAG("area", "Area") |
|
22 HTML_TAG("b", "Span") |
|
23 HTML_TAG("base", "Shared") |
|
24 HTML_TAG("basefont", "Span") |
|
25 HTML_TAG("bdo", "Span") |
|
26 HTML_TAG("bgsound", "Span") |
|
27 HTML_TAG("big", "Span") |
|
28 HTML_TAG("blockquote", "Shared") |
|
29 HTML_TAG("body", "Body") |
|
30 HTML_TAG("br", "BR") |
|
31 HTML_TAG("button", "Button") |
|
32 HTML_TAG("canvas", "Canvas") |
|
33 HTML_TAG("caption", "TableCaption") |
|
34 HTML_TAG("center", "Span") |
|
35 HTML_TAG("cite", "Span") |
|
36 HTML_TAG("code", "Span") |
|
37 HTML_TAG("col", "TableCol") |
|
38 HTML_TAG("colgroup", "TableCol") |
|
39 HTML_TAG("dd", "Span") |
|
40 HTML_TAG("del", "Mod") |
|
41 HTML_TAG("dfn", "Span") |
|
42 HTML_TAG("dir", "Shared") |
|
43 HTML_TAG("div", "Div") |
|
44 HTML_TAG("dl", "SharedList") |
|
45 HTML_TAG("dt", "Span") |
|
46 HTML_TAG("em", "Span") |
|
47 HTML_TAG("embed", "SharedObject") |
|
48 HTML_TAG("fieldset", "FieldSet") |
|
49 HTML_TAG("font", "Font") |
|
50 HTML_TAG("form", "Form") |
|
51 HTML_TAG("frame", "Frame") |
|
52 HTML_TAG("frameset", "FrameSet") |
|
53 HTML_TAG("h1", "Heading") |
|
54 HTML_TAG("h2", "Heading") |
|
55 HTML_TAG("h3", "Heading") |
|
56 HTML_TAG("h4", "Heading") |
|
57 HTML_TAG("h5", "Heading") |
|
58 HTML_TAG("h6", "Heading") |
|
59 HTML_TAG("head", "Head") |
|
60 HTML_TAG("hr", "HR") |
|
61 HTML_TAG("html", "Html") |
|
62 HTML_TAG("i", "Span") |
|
63 HTML_TAG("iframe", "IFrame") |
|
64 HTML_TAG("image", "") |
|
65 HTML_TAG("img", "Image") |
|
66 HTML_TAG("input", "Input") |
|
67 HTML_TAG("ins", "Mod") |
|
68 HTML_TAG("isindex", "Unknown") |
|
69 HTML_TAG("kbd", "Span") |
|
70 HTML_TAG("keygen", "Span") |
|
71 HTML_TAG("label", "Label") |
|
72 HTML_TAG("legend", "Legend") |
|
73 HTML_TAG("li", "LI") |
|
74 HTML_TAG("link", "Link") |
|
75 HTML_TAG("listing", "Span") |
|
76 HTML_TAG("map", "Map") |
|
77 HTML_TAG("marquee", "Div") |
|
78 HTML_TAG("menu", "Shared") |
|
79 HTML_TAG("meta", "Meta") |
|
80 HTML_TAG("multicol", "Unknown") |
|
81 HTML_TAG("nobr", "Span") |
|
82 HTML_TAG("noembed", "Div") |
|
83 HTML_TAG("noframes", "Div") |
|
84 HTML_TAG("noscript", "Div") |
|
85 HTML_TAG("object", "Object") |
|
86 HTML_TAG("ol", "SharedList") |
|
87 HTML_TAG("optgroup", "OptGroup") |
|
88 HTML_TAG("option", "Option") |
|
89 HTML_TAG("p", "Paragraph") |
|
90 HTML_TAG("param", "Shared") |
|
91 HTML_TAG("plaintext", "Span") |
|
92 HTML_TAG("pre", "Pre") |
|
93 HTML_TAG("q", "Shared") |
|
94 HTML_TAG("s", "Span") |
|
95 HTML_TAG("samp", "Span") |
|
96 HTML_TAG("script", "Script") |
|
97 HTML_TAG("select", "Select") |
|
98 HTML_TAG("small", "Span") |
|
99 HTML_TAG("spacer", "Unknown") |
|
100 HTML_TAG("span", "Span") |
|
101 HTML_TAG("strike", "Span") |
|
102 HTML_TAG("strong", "Span") |
|
103 HTML_TAG("style", "Style") |
|
104 HTML_TAG("sub", "Span") |
|
105 HTML_TAG("sup", "Span") |
|
106 HTML_TAG("table", "Table") |
|
107 HTML_TAG("tbody", "TableSection") |
|
108 HTML_TAG("td", "TableCell") |
|
109 HTML_TAG("textarea", "TextArea") |
|
110 HTML_TAG("tfoot", "TableSection") |
|
111 HTML_TAG("th", "TableCell") |
|
112 HTML_TAG("thead", "TableSection") |
|
113 HTML_TAG("template", "Template") |
|
114 HTML_TAG("title", "Title") |
|
115 HTML_TAG("tr", "TableRow") |
|
116 HTML_TAG("tt", "Span") |
|
117 HTML_TAG("u", "Span") |
|
118 HTML_TAG("ul", "SharedList") |
|
119 HTML_TAG("var", "Span") |
|
120 HTML_TAG("wbr", "Shared") |
|
121 HTML_TAG("xmp", "Span") |
|
122 |
|
123 function SVG_TAG(name) { |
|
124 allNodes.push(doc.createElementNS("http://www.w3.org/2000/svg", name)); |
|
125 } |
|
126 |
|
127 // List sorta stolen from SVG element factory. |
|
128 SVG_TAG("a") |
|
129 SVG_TAG("polyline") |
|
130 SVG_TAG("polygon") |
|
131 SVG_TAG("circle") |
|
132 SVG_TAG("ellipse") |
|
133 SVG_TAG("line") |
|
134 SVG_TAG("rect") |
|
135 SVG_TAG("svg") |
|
136 SVG_TAG("g") |
|
137 SVG_TAG("foreignObject") |
|
138 SVG_TAG("path") |
|
139 SVG_TAG("text") |
|
140 SVG_TAG("tspan") |
|
141 SVG_TAG("image") |
|
142 SVG_TAG("style") |
|
143 SVG_TAG("linearGradient") |
|
144 SVG_TAG("metadata") |
|
145 SVG_TAG("radialGradient") |
|
146 SVG_TAG("stop") |
|
147 SVG_TAG("defs") |
|
148 SVG_TAG("desc") |
|
149 SVG_TAG("script") |
|
150 SVG_TAG("use") |
|
151 SVG_TAG("symbol") |
|
152 SVG_TAG("marker") |
|
153 SVG_TAG("title") |
|
154 SVG_TAG("clipPath") |
|
155 SVG_TAG("textPath") |
|
156 SVG_TAG("filter") |
|
157 SVG_TAG("feBlend") |
|
158 SVG_TAG("feColorMatrix") |
|
159 SVG_TAG("feComponentTransfer") |
|
160 SVG_TAG("feComposite") |
|
161 SVG_TAG("feFuncR") |
|
162 SVG_TAG("feFuncG") |
|
163 SVG_TAG("feFuncB") |
|
164 SVG_TAG("feFuncA") |
|
165 SVG_TAG("feGaussianBlur") |
|
166 SVG_TAG("feMerge") |
|
167 SVG_TAG("feMergeNode") |
|
168 SVG_TAG("feMorphology") |
|
169 SVG_TAG("feOffset") |
|
170 SVG_TAG("feFlood") |
|
171 SVG_TAG("feTile") |
|
172 SVG_TAG("feTurbulence") |
|
173 SVG_TAG("feConvolveMatrix") |
|
174 SVG_TAG("feDistantLight") |
|
175 SVG_TAG("fePointLight") |
|
176 SVG_TAG("feSpotLight") |
|
177 SVG_TAG("feDiffuseLighting") |
|
178 SVG_TAG("feSpecularLighting") |
|
179 SVG_TAG("feDisplacementMap") |
|
180 SVG_TAG("feImage") |
|
181 SVG_TAG("pattern") |
|
182 SVG_TAG("mask") |
|
183 SVG_TAG("svgSwitch") |
|
184 |
|
185 // Toss in some other namespaced stuff too, for good measure |
|
186 // XUL stuff might not be creatable in content documents |
|
187 try { |
|
188 allNodes.push(doc.createElementNS( |
|
189 "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", |
|
190 "window")); |
|
191 } catch (e) {} |
|
192 allNodes.push(doc.createElementNS("http://www.w3.org/1998/Math/MathML", |
|
193 "math")); |
|
194 allNodes.push(doc.createElementNS("http://www.w3.org/2001/xml-events", |
|
195 "testname")); |
|
196 allNodes.push(doc.createElementNS("bogus.namespace", "testname")); |
|
197 |
|
198 var XMLDoc = doc.implementation.createDocument("", "", null); |
|
199 |
|
200 // And non-elements |
|
201 allNodes.push(doc.createTextNode("some text")); |
|
202 allNodes.push(doc.createComment("some text")); |
|
203 allNodes.push(doc.createDocumentFragment()); |
|
204 XMLNodes.push(XMLDoc.createCDATASection("some text")); |
|
205 XMLNodes.push(XMLDoc.createProcessingInstruction("PI", "data")); |
|
206 |
|
207 function runTestUnwrapped() { |
|
208 if (!("wrappedJSObject" in doc)) { |
|
209 return; |
|
210 } |
|
211 ok(doc.wrappedJSObject.nodePrincipal === undefined, |
|
212 "Must not have document principal for " + documentID); |
|
213 ok(doc.wrappedJSObject.baseURIObject === undefined, |
|
214 "Must not have document base URI for " + documentID); |
|
215 ok(doc.wrappedJSObject.documentURIObject === undefined, |
|
216 "Must not have document URI for " + documentID); |
|
217 |
|
218 for (var i = 0; i < allNodes.length; ++i) { |
|
219 ok(allNodes[i].wrappedJSObject.nodePrincipal === undefined, |
|
220 "Unexpected principal appears for " + allNodes[i].nodeName + |
|
221 " in " + documentID); |
|
222 ok(allNodes[i].wrappedJSObject.baseURIObject === undefined, |
|
223 "Unexpected base URI appears for " + allNodes[i].nodeName + |
|
224 " in " + documentID); |
|
225 } |
|
226 } |
|
227 |
|
228 function runTestProps() { |
|
229 isnot(doc.nodePrincipal, null, |
|
230 "Must have document principal in " + documentID); |
|
231 is(doc.nodePrincipal instanceof Components.interfaces.nsIPrincipal, |
|
232 true, "document principal must be a principal in " + documentID); |
|
233 isnot(doc.baseURIObject, null, |
|
234 "Must have document base URI in" + documentID); |
|
235 is(doc.baseURIObject instanceof Components.interfaces.nsIURI, |
|
236 true, "document base URI must be a URI in " + documentID); |
|
237 isnot(doc.documentURIObject, null, |
|
238 "Must have document URI " + documentID); |
|
239 is(doc.documentURIObject instanceof Components.interfaces.nsIURI, |
|
240 true, "document URI must be a URI in " + documentID); |
|
241 is(doc.documentURIObject.spec, doc.documentURI, |
|
242 "document URI must be the right URI in " + documentID); |
|
243 |
|
244 for (var i = 0; i < allNodes.length; ++i) { |
|
245 is(allNodes[i].nodePrincipal, doc.nodePrincipal, |
|
246 "Unexpected principal for " + allNodes[i].nodeName + |
|
247 " in " + documentID); |
|
248 is(allNodes[i].baseURIObject, doc.baseURIObject, |
|
249 "Unexpected base URI for " + allNodes[i].nodeName + |
|
250 " in " + documentID); |
|
251 } |
|
252 |
|
253 for (i = 0; i < XMLNodes.length; ++i) { |
|
254 is(XMLNodes[i].nodePrincipal, doc.nodePrincipal, |
|
255 "Unexpected principal for " + XMLNodes[i].nodeName + |
|
256 " in " + documentID); |
|
257 is(XMLNodes[i].baseURIObject.spec, "about:blank", |
|
258 "Unexpected base URI for " + XMLNodes[i].nodeName + |
|
259 " in " + documentID); |
|
260 } |
|
261 } |
|
262 |
|
263 runTestUnwrapped(); |
|
264 runTestProps(); |
|
265 runTestUnwrapped(); |
|
266 } |
|
267 |
|
268 var testsRunning = 2; |
|
269 |
|
270 testInDocument(document, "browser window"); |
|
271 |
|
272 function newTabTest(url) { |
|
273 var newTab = gBrowser.addTab(); |
|
274 var newBrowser = gBrowser.getBrowserForTab(newTab); |
|
275 newBrowser.contentWindow.location.href = url; |
|
276 function testBrowser(event) { |
|
277 newBrowser.removeEventListener("load", testBrowser, true); |
|
278 is(event.target, newBrowser.contentDocument, |
|
279 "Unexpected target in " + url); |
|
280 testInDocument(newBrowser.contentDocument, url); |
|
281 |
|
282 gBrowser.removeTab(newTab); |
|
283 |
|
284 --testsRunning; |
|
285 if (testsRunning == 0) { |
|
286 finish(); |
|
287 } |
|
288 } |
|
289 newBrowser.addEventListener("load", testBrowser, true); |
|
290 } |
|
291 |
|
292 newTabTest("about:blank"); |
|
293 newTabTest("about:config"); |
|
294 } |