mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-01-03 18:42:00 +01:00
Hardened detection test.
This commit is contained in:
parent
d787b84b13
commit
e128cba84a
@ -135,13 +135,21 @@ function testKnownPixelValue(size, log){
|
|||||||
canvas.height = size;
|
canvas.height = size;
|
||||||
canvas.width = size;
|
canvas.width = size;
|
||||||
var context = canvas.getContext("2d");
|
var context = canvas.getContext("2d");
|
||||||
context.fillStyle = "rgba(0, 127, 255, 1)";
|
var imageData = new ImageData(canvas.width, canvas.height);
|
||||||
var pixelValues = [0, 127, 255, 255];
|
var pixelValues = imageData.data;
|
||||||
context.fillRect(0, 0, canvas.width, canvas.height);
|
for (let i = 0; i < imageData.data.length; i += 1){
|
||||||
|
if (i % 4 !== 3){
|
||||||
|
pixelValues[i] = Math.floor(256 * Math.random());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
pixelValues[i] = 255;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
context.putImageData(imageData, 0, 0);
|
||||||
var p = context.getImageData(0, 0, canvas.width, canvas.height).data;
|
var p = context.getImageData(0, 0, canvas.width, canvas.height).data;
|
||||||
for (var i = 0; i < p.length; i += 1){
|
for (var i = 0; i < p.length; i += 1){
|
||||||
if (p[i] !== pixelValues[i%4]){
|
if (p[i] !== pixelValues[i]){
|
||||||
log("wrong value", p[i], "at", i, "expected", pixelValues[i%4]);
|
log("wrong value", p[i], "at", i, "expected", pixelValues[i]);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user