mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-01-08 20:54:49 +01:00
Refined property descriptor detection test.
This commit is contained in:
parent
6d1c051323
commit
96118e5690
@ -71,17 +71,35 @@ addTest("function name", function(){
|
|||||||
addTest("property descriptor", function(log){
|
addTest("property descriptor", function(log){
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var descriptor = Object.getOwnPropertyDescriptor(CanvasRenderingContext2D.prototype, "getImageData");
|
const properties = [
|
||||||
var desiredDescriptor = {
|
{
|
||||||
|
object: CanvasRenderingContext2D.prototype,
|
||||||
|
name: "getImageData",
|
||||||
|
descriptor: {
|
||||||
value: function getImageData(x, y, w, h){},
|
value: function getImageData(x, y, w, h){},
|
||||||
writable: true,
|
writable: true,
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
configurable: true
|
configurable: true
|
||||||
};
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
object: HTMLCanvasElement.prototype,
|
||||||
|
name: "toDataURL",
|
||||||
|
descriptor: {
|
||||||
|
value: function toDataURL(){},
|
||||||
|
writable: true,
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return properties.reduce(function(pass, property){
|
||||||
|
const desiredDescriptor = property.descriptor;
|
||||||
|
const descriptor = Object.getOwnPropertyDescriptor(property.object, property.name);
|
||||||
return Object.keys(desiredDescriptor).reduce(function(pass, key){
|
return Object.keys(desiredDescriptor).reduce(function(pass, key){
|
||||||
function keyLog(type, expected, got){
|
function keyLog(type, expected, got){
|
||||||
log("wrong " + type + " for ", key, "- expected:", expected, "- got:", got);
|
log(property.name + ": wrong " + type + " for ", key, "- expected:", expected, "- got:", got);
|
||||||
}
|
}
|
||||||
var desiredValue = desiredDescriptor[key];
|
var desiredValue = desiredDescriptor[key];
|
||||||
var value = descriptor[key];
|
var value = descriptor[key];
|
||||||
@ -110,6 +128,7 @@ addTest("property descriptor", function(log){
|
|||||||
keyLog("type", typeof desiredValue, typeof value);
|
keyLog("type", typeof desiredValue, typeof value);
|
||||||
}
|
}
|
||||||
return pass || keyPass;
|
return pass || keyPass;
|
||||||
|
}, false) || pass;
|
||||||
}, false);
|
}, false);
|
||||||
});
|
});
|
||||||
addTest("error provocation 1", function(log){
|
addTest("error provocation 1", function(log){
|
||||||
@ -191,7 +210,8 @@ addTest("error properties", function(log){
|
|||||||
log("Error stack starts wrong. Expected:", start, "- got :", err.stack.split(/\n/g, 2)[0]);
|
log("Error stack starts wrong. Expected:", start, "- got :", err.stack.split(/\n/g, 2)[0]);
|
||||||
canvasBlocker = true;
|
canvasBlocker = true;
|
||||||
}
|
}
|
||||||
var message = "'getImageData' called on an object that does not implement interface CanvasRenderingContext2D.";
|
var message = "'getImageData' called on an object that " +
|
||||||
|
"does not implement interface CanvasRenderingContext2D.";
|
||||||
if (err.message !== message){
|
if (err.message !== message){
|
||||||
log("Error message wrong. Expected: ", message, "- got:", err.message);
|
log("Error message wrong. Expected: ", message, "- got:", err.message);
|
||||||
canvasBlocker = true;
|
canvasBlocker = true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user