gecko/dom/tests/mochitest/chrome/test_sandbox_bindings.xul
Peter Van der Beken 71b55b1f68 Fix for bug 788532 (Add the new DOM bindings API to DOM lists). r=bz.
--HG--
extra : rebase_source : 18e21a786b6a9cc2aeada52ba5ca3a2614cb596b
2012-09-05 22:49:53 +02:00

79 lines
3.2 KiB
XML

<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=741267
-->
<window title="Mozilla Bug 741267"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<iframe id="t"></iframe>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=741267"
target="_blank">Mozilla Bug 741267</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for Bug 741267 **/
function doTest() {
var win = $("t").contentWindow;
var sandbox = Components.utils.Sandbox(win, { sandboxPrototype: win });
try {
var nl = Components.utils.evalInSandbox("NodeList", sandbox);
is(nl, String(NodeList), "'NodeList' in a sandbox should return the NodeList interface prototype object");
} catch (e) {
ok(false, "'NodeList' shouldn't throw in a sandbox");
}
try {
var et = Components.utils.evalInSandbox("EventTarget", sandbox);
ok(et, "'EventTarget' in a sandbox should return the EventTarget interface prototype object");
} catch (e) {
ok(false, "'EventTarget' shouldn't throw in a sandbox");
}
try {
var xhr = Components.utils.evalInSandbox("XMLHttpRequest()", sandbox);
is(xhr, "[object XMLHttpRequest]", "'XMLHttpRequest()' in a sandbox should create an XMLHttpRequest object");
} catch (e) {
ok(false, "'XMLHttpRequest()' shouldn't throw in a sandbox");
}
try {
var canvas = Components.utils.evalInSandbox("document.createElement('canvas').getContext('2d')", sandbox);
is(canvas.DRAWWINDOW_DRAW_CARET, CanvasRenderingContext2D.DRAWWINDOW_DRAW_CARET, "Constants should be defined on DOM objects in a sandbox");
} catch (e) {
ok(false, "'document.createElement('canvas').getContext('2D')' shouldn't throw in a sandbox");
}
try {
var ctx = Components.utils.evalInSandbox("var ctx = document.createElement('canvas').getContext('2d'); ctx.foopy = 5; ctx", sandbox);
ok(!("foopy" in ctx), "We should have an Xray here");
var data = ctx.createImageData(1, 1);
for (var i = 0; i < data.data.length; ++i) {
// Watch out for premultiplied bits... just set all the alphas to 255
if (i % 4 == 3) {
data.data[i] = 255;
} else {
data.data[i] = i;
}
}
ctx.putImageData(data, 0, 0);
var data2 = ctx.getImageData(0, 0, 1, 1);
is(data2.data.length, data.data.length, "Lengths must match");
for (i = 0; i < data.data.length; ++i)
is(data.data[i], data2.data[i], "Data at " + i + " should match");
} catch (e) {
ok(false, "Imagedata manipulation via an Xray shouldn't throw " + e);
}
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
addLoadEvent(doTest);
]]>
</script>
</window>