|
|
|
Lines 18-33
https://bugzilla.mozilla.org/show_bug.cg
|
Link Here
|
|---|
|
| 18 |
<pre id="test"> |
18 |
<pre id="test"> |
| 19 |
<script class="testbody" type="text/javascript"> |
19 |
<script class="testbody" type="text/javascript"> |
| 20 |
|
20 |
|
| 21 |
/** Test for Bug 389797 **/ |
21 |
/** Test for Bug 389797 **/ |
| 22 |
var allTags = []; |
22 |
var allTags = []; |
| 23 |
var classInfos = {}; |
23 |
var classInfos = {}; |
| 24 |
var interfaces = {}; |
24 |
var interfaces = {}; |
| 25 |
var interfacesNonClassinfo = {}; |
25 |
var interfacesNonClassinfo = {}; |
|
|
26 |
var interfacesNonDOM = {}; |
| 26 |
|
27 |
|
| 27 |
function getClassName(tag) { |
28 |
function getClassName(tag) { |
| 28 |
return "HTML" + classInfos[tag] + "Element"; |
29 |
return "HTML" + classInfos[tag] + "Element"; |
| 29 |
} |
30 |
} |
| 30 |
|
31 |
|
| 31 |
function HTML_TAG(aTagName, aImplClass) { |
32 |
function HTML_TAG(aTagName, aImplClass) { |
| 32 |
allTags.push(aTagName); |
33 |
allTags.push(aTagName); |
| 33 |
classInfos[aTagName] = aImplClass; |
34 |
classInfos[aTagName] = aImplClass; |
|
Lines 36-56
function HTML_TAG(aTagName, aImplClass)
|
Link Here
|
|---|
|
| 36 |
"nsIDOMNSElement", |
37 |
"nsIDOMNSElement", |
| 37 |
"nsIDOMEventTarget", |
38 |
"nsIDOMEventTarget", |
| 38 |
"nsIDOMNSEventTarget", |
39 |
"nsIDOMNSEventTarget", |
| 39 |
"nsIDOMNSHTMLElement", |
40 |
"nsIDOMNSHTMLElement", |
| 40 |
"nsIDOMElementCSSInlineStyle", |
41 |
"nsIDOMElementCSSInlineStyle", |
| 41 |
"nsIDOMNodeSelector" ]; |
42 |
"nsIDOMNodeSelector" ]; |
| 42 |
|
43 |
|
| 43 |
// Some interfaces don't appear in classinfo because other interfaces that |
44 |
// Some interfaces don't appear in classinfo because other interfaces that |
| 44 |
// inherit from them do. |
45 |
// inherit from them do. These are visible to unprivileged script. |
| 45 |
interfacesNonClassinfo[aTagName] = |
46 |
interfacesNonClassinfo[aTagName] = |
| 46 |
[ "nsIDOMNode", |
47 |
[ "nsIDOMNode", |
| 47 |
"nsIDOMElement", |
48 |
"nsIDOMElement" ]; |
| 48 |
"nsIDOM3EventTarget", |
49 |
|
|
|
50 |
// Some interfaces don't appear in classinfo at all because they are |
| 51 |
// implementation details of the underlying XPCOM objects. These are not |
| 52 |
// visible to unpriviliged script. |
| 53 |
interfacesNonDOM[aTagName] = |
| 54 |
[ "nsIDOM3EventTarget", |
| 49 |
"nsISupportsWeakReference" ]; |
55 |
"nsISupportsWeakReference" ]; |
| 50 |
|
56 |
|
| 51 |
var interfaceName = "nsIDOM" + getClassName(aTagName); |
57 |
var interfaceName = "nsIDOM" + getClassName(aTagName); |
| 52 |
if (interfaceName in Components.interfaces) { // no nsIDOMHTMLSpanElement |
58 |
if (interfaceName in Components.interfaces) { // no nsIDOMHTMLSpanElement |
| 53 |
interfaces[aTagName].push(interfaceName); |
59 |
interfaces[aTagName].push(interfaceName); |
| 54 |
interfacesNonClassinfo[aTagName].push("nsIDOMHTMLElement"); |
60 |
interfacesNonClassinfo[aTagName].push("nsIDOMHTMLElement"); |
| 55 |
} else if (aTagName != "ins" && aTagName != "del") { |
61 |
} else if (aTagName != "ins" && aTagName != "del") { |
| 56 |
// Inherits directly from nsIDOMHTMLElement, unless it's "ins" or "del", |
62 |
// Inherits directly from nsIDOMHTMLElement, unless it's "ins" or "del", |
|
Lines 67-83
function HTML_TAG(aTagName, aImplClass)
|
Link Here
|
|---|
|
| 67 |
if (arguments.length > 2) { |
73 |
if (arguments.length > 2) { |
| 68 |
for (var i = 0; i < arguments[2].length; ++i) { |
74 |
for (var i = 0; i < arguments[2].length; ++i) { |
| 69 |
interfaces[aTagName].push(arguments[2][i]); |
75 |
interfaces[aTagName].push(arguments[2][i]); |
| 70 |
} |
76 |
} |
| 71 |
} |
77 |
} |
| 72 |
|
78 |
|
| 73 |
if (arguments.length > 3) { |
79 |
if (arguments.length > 3) { |
| 74 |
for (i = 0; i < arguments[3].length; ++i) { |
80 |
for (i = 0; i < arguments[3].length; ++i) { |
| 75 |
interfacesNonClassinfo[aTagName].push(arguments[3][i]); |
81 |
interfacesNonDOM[aTagName].push(arguments[3][i]); |
| 76 |
} |
82 |
} |
| 77 |
} |
83 |
} |
| 78 |
} |
84 |
} |
| 79 |
|
85 |
|
| 80 |
const objectIfaces = [ |
86 |
const objectIfaces = [ |
| 81 |
"imgIDecoderObserver", "nsIRequestObserver", "nsIStreamListener", |
87 |
"imgIDecoderObserver", "nsIRequestObserver", "nsIStreamListener", |
| 82 |
"nsIFrameLoaderOwner", "nsIObjectLoadingContent", "nsIInterfaceRequestor", |
88 |
"nsIFrameLoaderOwner", "nsIObjectLoadingContent", "nsIInterfaceRequestor", |
| 83 |
"nsIChannelEventSink" |
89 |
"nsIChannelEventSink" |
|
Lines 256-273
for each (var tag in allTags) {
|
Link Here
|
|---|
|
| 256 |
// Check that each node QIs to all the things we expect it to QI to |
262 |
// Check that each node QIs to all the things we expect it to QI to |
| 257 |
for each (var iface in interfaces[tag].concat(interfacesNonClassinfo[tag])) { |
263 |
for each (var iface in interfaces[tag].concat(interfacesNonClassinfo[tag])) { |
| 258 |
is(iface in Components.interfaces, true, |
264 |
is(iface in Components.interfaces, true, |
| 259 |
iface + " not in Components.interfaces"); |
265 |
iface + " not in Components.interfaces"); |
| 260 |
is(node instanceof Components.interfaces[iface], true, |
266 |
is(node instanceof Components.interfaces[iface], true, |
| 261 |
tagName(tag) + " does not QI to " + iface); |
267 |
tagName(tag) + " does not QI to " + iface); |
| 262 |
} |
268 |
} |
| 263 |
|
269 |
|
|
|
270 |
// Check that each node doesn't QI to non-DOM things |
| 271 |
for each (var iface in interfacesNonDOM[tag]) { |
| 272 |
is(iface in Components.interfaces, true, |
| 273 |
iface + " not in Components.interfaces"); |
| 274 |
is(node instanceof Components.interfaces[iface], false, |
| 275 |
tagName(tag) + " should not QI to " + iface); |
| 276 |
} |
| 277 |
} |
| 278 |
|
| 279 |
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); |
| 280 |
|
| 281 |
for each (var tag in allTags) { |
| 282 |
var node = document.createElement(tag); |
| 283 |
|
| 284 |
// Have to use the proto's toString(), since HTMLAnchorElement and company |
| 285 |
// override toString(). |
| 286 |
var nodeString = HTMLElement.prototype.toString.apply(node); |
| 287 |
|
| 288 |
// Debug builds have extra info, so chop off after "Element" if it's followed |
| 289 |
// by ' ' or ']' |
| 290 |
nodeString = nodeString.replace(/Element[\] ].*/, "Element"); |
| 291 |
|
| 292 |
// Check that each node doesn't QI to non-DOM things, except when we have privs |
| 293 |
for each (var iface in interfacesNonDOM[tag]) { |
| 294 |
is(iface in Components.interfaces, true, |
| 295 |
iface + " not in Components.interfaces"); |
| 296 |
is(node instanceof Components.interfaces[iface], true, |
| 297 |
tagName(tag) + " should QI to " + iface + " from privileged script"); |
| 298 |
} |
| 299 |
|
| 264 |
// Now see what classinfo reports |
300 |
// Now see what classinfo reports |
| 265 |
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); |
|
|
| 266 |
var nodeClassInfo = node.QueryInterface(Components.interfaces.nsIClassInfo); |
301 |
var nodeClassInfo = node.QueryInterface(Components.interfaces.nsIClassInfo); |
| 267 |
var count = {}; |
302 |
var count = {}; |
| 268 |
var classInfoInterfaces = |
303 |
var classInfoInterfaces = |
| 269 |
nodeClassInfo.getInterfaces(count). |
304 |
nodeClassInfo.getInterfaces(count). |
| 270 |
map(function(id) { return Components.interfacesByID[id].toString(); }); |
305 |
map(function(id) { return Components.interfacesByID[id].toString(); }); |
| 271 |
|
306 |
|
| 272 |
// Make sure that we know about all the things classinfo claims |
307 |
// Make sure that we know about all the things classinfo claims |
| 273 |
for each (var classInfoInterface in classInfoInterfaces) { |
308 |
for each (var classInfoInterface in classInfoInterfaces) { |