gecko/content/canvas/test/test_bug397524.html
bzbarsky@mit.edu 6b095f543a Adding test
2008-02-17 12:20:21 -08:00

72 lines
1.9 KiB
HTML

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=397524
-->
<head>
<title>Test for Bug 397524</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=397524">Mozilla Bug 397524</a>
<p id="display">
<canvas id="c1" width="1" height="1"></canvas>
<canvas id="c2" width="1" height="1"></canvas>
<canvas id="c3" width="1" height="1"></canvas>
<img id="i1", src="image_green-1x1.png">
<img id="i2" src="http://example.com/tests/content/canvas/test/image_green-1x1.png">
<img id="i3" src="image_green-redirect">
</p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Bug 397524 **/
SimpleTest.waitForExplicitFinish();
function draw(n) {
$("c" + n).getContext('2d').drawImage($("i" + n), 0, 0);
}
addLoadEvent(function() {
draw(1);
draw(2);
draw(3);
// Should be able to get the data out of the first canvas
$("c1").toDataURL("image/png");
// Should not be able to get the data out of a cross-site load
var gotData = false;
try {
$("c2").toDataURL("image/png");
gotData = true;
} catch (ex if (ex.code == 1000 && ex.name == "NS_ERROR_DOM_SECURITY_ERR")) {
}
is(gotData, false, "Shouldn't be able to read images cross-site!");
// Should not be able to get the data out of a redirected cross-site load
var gotData = false;
try {
$("c3").toDataURL("image/png");
gotData = true;
} catch (ex if (ex.code == 1000 && ex.name == "NS_ERROR_DOM_SECURITY_ERR")) {
}
is(gotData, false, "Shouldn't be able to read images redirected cross-site!");
SimpleTest.finish();
});
</script>
</pre>
</body>
</html>