Bug 899388 - Part 4: Test to make sure that XUL interfaces are not exposed on content, modulo content XBL. r=bz

This commit is contained in:
Masatoshi Kimura 2013-08-09 23:35:54 +09:00
Родитель 9da15f76e5
Коммит 1bf6b6b99c
3 изменённых файлов: 62 добавлений и 19 удалений

Просмотреть файл

@ -49,6 +49,7 @@ MOCHITEST_FILES = \
file_moving_nodeList.html \
test_performance_now.html \
test_interfaces.html \
file_interfaces.xml \
test_idleapi_permissions.html \
test_stylesheetPI.html \
test_showModalDialog.html \

Просмотреть файл

@ -0,0 +1,19 @@
<?xml version="1.0"?>
<bindings id="xbltestBindings" xmlns="http://www.mozilla.org/xbl">
<binding id="xbltest">
<content>PASS</content>
<implementation>
<constructor>
var win = XPCNativeWrapper.unwrap(window);
var SpecialPowers = win.SpecialPowers;
var is = win.is;
var ok = win.ok;
var interfaceNamesInGlobalScope = win.interfaceNamesInGlobalScope;
var interfaceNamesInXBLScope = win.interfaceNamesInXBLScope;
eval(win.runTest.toString());
runTest(window, true);
win.SimpleTest.finish();
</constructor>
</implementation>
</binding>
</bindings>

Просмотреть файл

@ -43,7 +43,6 @@ var interfaceNamesInGlobalScope =
"CanvasRenderingContext2D",
"CDATASection",
"CharacterData",
"ChromeWindow",
"ClientRect",
"ClientRectList",
"ClipboardEvent",
@ -464,36 +463,60 @@ var interfaceNamesInGlobalScope =
"XPathNSResolver",
"XPathResult",
"XSLTProcessor",
"XULButtonElement",
"XULCheckboxElement",
"XULCommandDispatcher",
"XULCommandEvent",
"XULControlElement",
"XULDocument",
"XULElement",
"XULLabeledControlElement",
"XULPopupElement",
]
// IMPORTANT: Do not change this list without review from a DOM peer!
// If your interface is named nsIDOMSomeInterface and you don't mean to expose
// it to every webpage, simply change its name to nsISomeInterface to fix this problem.
for (var i in SpecialPowers.Components.interfaces) {
var s = i.toString();
var name = null;
if (s.indexOf("nsIDOM") == 0) {
name = s.substring("nsIDOM".length);
} else if (s.indexOf("nsI") == 0) {
name = s.substring("nsI".length);
var interfaceNamesInXBLScope = [
"BoxObject",
"ChromeWindow",
"DOMConstructor",
"TreeColumn",
"TreeColumns",
"TreeContentView",
"TreeSelection",
"XULButtonElement",
"XULCheckboxElement",
"XULCommandDispatcher",
"XULCommandEvent",
"XULControlElement",
"XULControllers",
"XULDocument",
"XULLabeledControlElement",
"XULPopupElement",
"XULTemplateBuilder",
"XULTreeBuilder",
];
function runTest(win, isXBLScope) {
for (var i in SpecialPowers.Components.interfaces) {
var s = i.toString();
var name = null;
if (s.indexOf("nsIDOM") == 0) {
name = s.substring("nsIDOM".length);
} else if (s.indexOf("nsI") == 0) {
name = s.substring("nsI".length);
}
if (name && (name in win)) {
ok(interfaceNamesInGlobalScope.indexOf(name) >= 0 ||
(isXBLScope && interfaceNamesInXBLScope.indexOf(name) >= 0),
"If this is failing: DANGER, are you sure you want to expose the new interface " + name + " to all webpages as a property on the window?");
}
}
if (name && (name in window)) {
ok(interfaceNamesInGlobalScope.indexOf(name) >= 0,
"If this is failing: DANGER, are you sure you want to expose the new interface " + name + " to all webpages as a property on the window?");
for (var name of interfaceNamesInXBLScope) {
is(name in win, isXBLScope,
name + " should" + (isXBLScope ? "" : " NOT") + " be present in the global scope");
}
}
runTest(window, false);
SimpleTest.waitForExplicitFinish();
</script>
<span id="span" style="-moz-binding: url(file_interfaces.xml)"></span>
</pre>
</body>
</html>