blob: 6b545787ddf1c7b951a6e17562d618408ed006e0 [file] [log] [blame]
// The following functions depend on functions in js-test-pre.js.
var canvas, context;
function testDataRetrievalAllowed() {
// Control tests.
debug("Testing data retrieval on an untainted canvas:");
canvas = document.createElement("canvas");
canvas.width = 100;
canvas.height = 100;
shouldNotThrow("canvas.getContext('2d').getImageData(0, 0, 100, 100)");
shouldNotThrow("canvas.toDataURL()");
// CORS tests.
debug("<br />Testing data retrieval on a canvas tainted by a remote video pattern:");
canvas = document.createElement("canvas");
canvas.width = 100;
canvas.height = 100;
context = canvas.getContext("2d");
context.fillStyle = context.createPattern(video, "repeat");
context.fillRect(0, 0, 100, 100);
shouldThrowErrorName("context.getImageData(0, 0, 100, 100)", "SecurityError");
shouldThrowErrorName("canvas.toDataURL()", "SecurityError");
}
function testDataRetrievalForbidden(description) {
// Control tests.
debug("Testing data retrieval on an untainted canvas:");
canvas = document.createElement("canvas");
canvas.width = 100;
canvas.height = 100;
shouldNotThrow("canvas.getContext('2d').getImageData(0, 0, 100, 100)");
shouldNotThrow("canvas.toDataURL()");
// CORS tests.
debug("<br />Testing data retrieval on a canvas tainted by a pattern generated by a " + description + ":");
canvas = document.createElement("canvas");
canvas.width = 100;
canvas.height = 100;
context = canvas.getContext("2d");
context.fillStyle = context.createPattern(video, "repeat");
context.fillRect(0, 0, 100, 100);
shouldThrowErrorName("context.getImageData(0, 0, 100, 100)", "SecurityError");
shouldThrowErrorName("canvas.toDataURL()", "SecurityError");
}