Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Errors

<!DOCTYPE HTML>
<title>WebGL cross-origin textures test</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
<body>
<canvas id="canvas" style="border: none;" width="100" height="100">
<p class="fallback"> FAIL (fallback content) </p>
</canvas>
<script>
SimpleTest.waitForExplicitFinish();
const OK = "";
var gl;
var number_of_tests_live = 0;
var all_tests_started = false;
function verifyError(actual_error, expected_error, message) {
ok(actual_error == expected_error,
message + ": expected " + expected_error + ", got " + actual_error);
}
function testTexture(url, crossOriginAttribute, expected_error) {
number_of_tests_live++;
var image = new Image();
if (crossOriginAttribute == "just-crossOrigin-without-value") {
var div = document.createElement('div');
div.innerHTML="<img crossOrigin>";
image = div.children[0];
}
else if (crossOriginAttribute != "missing-value-default")
image.crossOrigin = crossOriginAttribute;
function testDone() {
number_of_tests_live--;
if (number_of_tests_live == 0 && all_tests_started)
SimpleTest.finish();
}
image.onload = function() {
var tex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex);
var actual_error = OK;
try {
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
} catch(e) {
actual_error = e.name;
}
verifyError(actual_error, expected_error, "texImage2D on " + url + " with crossOrigin=" + image.crossOrigin);
testDone();
};
image.onerror = function(event) {
ok(expected_error != OK, "Got an error but expected OK!");
testDone();
}
image.src = url;
}
addLoadEvent(function () {
var canvas = document.getElementById("canvas");
gl = canvas.getContext("experimental-webgl");
if (!gl) {
todo(false, "Canvas WebGL not supported");
SimpleTest.finish();
return;
}
"missing-value-default",
OK);
"",
OK);
"just-crossOrigin-without-value",
OK);
"missing-value-default",
"SecurityError");
"",
"SecurityError");
"just-crossOrigin-without-value",
"SecurityError");
"missing-value-default",
"SecurityError");
"",
OK);
"just-crossOrigin-without-value",
OK);
"anonymous",
OK);
"use-credentials",
"SecurityError");
"missing-value-default",
"SecurityError");
"",
OK);
"just-crossOrigin-without-value",
OK);
"anonymous",
OK);
"use-credentials",
OK);
// Test that bad values for crossorigin="..." are interpreted as invalid-value-default which is "anonymous".
"foobar",
OK);
"foobar",
"SecurityError");
"foobar",
OK);
"foobar",
OK);
all_tests_started = true;
});
</script>