blob: e18a226dfe919100cf3930077db7c1a208240bce [file] [log] [blame]
<html>
<title>iframe for fetch canvas tainting test</title>
<script>
const NOT_TAINTED = 'NOT_TAINTED';
const TAINTED = 'TAINTED';
const LOAD_ERROR = 'LOAD_ERROR';
// Creates an image element with src=|url| and an optional |cross_origin|
// attibute. Tries to read from the image using a canvas element. Returns
// NOT_TAINTED if the could be read, TAINTED if it could not be read, and
// LOAD_ERROR if loading the image failed.
function create_test_case_promise(url, cross_origin) {
return new Promise(resolve => {
const img = document.createElement('img');
if (cross_origin != '') {
img.crossOrigin = cross_origin;
}
img.onload = function() {
try {
const canvas = document.createElement('canvas');
canvas.width = 100;
canvas.height = 100;
const context = canvas.getContext('2d');
context.drawImage(img, 0, 0);
context.getImageData(0, 0, 100, 100);
resolve(NOT_TAINTED);
} catch (e) {
resolve(TAINTED);
}
};
img.onerror = function() {
resolve(LOAD_ERROR);
}
img.src = url;
});
}
</script>
</html>