/** Test for Bug 682299 **/
SimpleTest.requestFlakyTimeout("untriaged");
function createCanvas(width, height) { var c = document.createElement("canvas");
c.width = width;
c.height = height;
return c;
}
function checkGetImageData(ctx, v) {
try { var data = ctx.getImageData(0, 0, 1, 1);
ok(true, "drawImage '" + v.src + "' then getImageData with crossOrigin='" + v.crossOrigin + "' worked");
} catch(error) {
ok(!v.crossOrigin && error.name === "SecurityError", "drawImage '" + v.src + "' then getImageData with crossOrigin='" + v.crossOrigin + "' failed");
v.tainted = true;
}
}
function checkGetImageDataTainted(ctx, v) {
try { var data = ctx.getImageData(0, 0, 1, 1);
ok(false, "changing the CORS mode should not allow reading data from remote videos");
} catch (error) {
ok(error.name === "SecurityError", "changing the CORS mode, drawImage '" + v.src + "' then getImageData with crossOrigin='" + v.crossOrigin + "' failed");
}
}
function checkCaptureStream(c, v) {
try { var stream = c.captureStream(0);
ok(true, "drawImage '" + v.src + "' then captureStream with crossOrigin='" + v.crossOrigin + "' worked");
} catch(error) {
ok(!v.crossOrigin && error.name === "SecurityError", "drawImage '" + v.src + "' then captureStream with crossOrigin='" + v.crossOrigin + "' failed");
v.tainted = true;
}
}
function checkCaptureStreamTainted(c, v) {
try { var stream = c.captureStream(0);
ok(false, "changing the CORS mode should not allow capturing a stream from remote videos");
} catch (error) {
ok(error.name === "SecurityError", "changing the CORS mode, drawImage '" + v.src + "' then captureStream with crossOrigin='" + v.crossOrigin + "' failed");
}
}
function testCanvasDrawImage(v) { var c = createCanvas(v.width, v.height); var ctx = c.getContext("2d");
ctx.drawImage(v, 0, 0);
function testCanvasCreatePattern(v) { var c = createCanvas(v.width, v.height); var ctx = c.getContext("2d");
ctx.fillStyle = ctx.createPattern(v, "");
ctx.fillRect(0, 0, c.width, c.height);
function vidDataSuccess(e) {
ok(!e.target.error, "Load '" + e.target.src + "' with crossOrigin='" + e.target.crossOrigin + "'");
testCanvasDrawImage(e.target);
testCanvasCreatePattern(e.target);
if (document.gl) {
testWebGL(document.gl, e.target);
}
// If we change the CORS mode after loading the file without CORS it should still throw a security error
if (e.target.tainted) {
e.target.crossOrigin = "anonymous";
testTaintedCanvas(e.target);
}
doneTest(e);
}
function vidLoadFailure(e) {
ok(false, "Load '" + e.target.src + "' with crossOrigin='" + e.target.crossOrigin + "'");
doneTest(e);
}
function vidErrorSuccess(e) {
ok(e.target.error.code === MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED, "Load '" + e.target.src + "' with crossOrigin='" + e.target.crossOrigin + "'");
doneTest(e);
}
// Build the video file test array
for (var i = 0; i < serverAttrValues.length; i++) {
for (var n = 0; n < clientAttrValues.length; n++) {
corsTests.push({
name: host + videoFile + serverAttrValues[i][0],
nameIntent: serverAttrValues[i][1],
cors: clientAttrValues[n][0],
corsIntent: clientAttrValues[n][1]
});
}
}
try {
document.gl = createCanvas(16, 16).getContext("experimental-webgl");
} catch (ex) {
// Mac OS X 10.5 doesn't support WebGL, so we won't run the WebGL tests
}
document.manager.runTests(corsTests, startTest);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.