1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-12-22 21:00:23 +01:00

Refined property descriptor detection test.

This commit is contained in:
kkapsner 2018-07-11 17:38:01 +02:00
parent 6d1c051323
commit 96118e5690

View File

@ -71,17 +71,35 @@ addTest("function name", function(){
addTest("property descriptor", function(log){
"use strict";
var descriptor = Object.getOwnPropertyDescriptor(CanvasRenderingContext2D.prototype, "getImageData");
var desiredDescriptor = {
const properties = [
{
object: CanvasRenderingContext2D.prototype,
name: "getImageData",
descriptor: {
value: function getImageData(x, y, w, h){},
writable: true,
enumerable: 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){
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 value = descriptor[key];
@ -110,6 +128,7 @@ addTest("property descriptor", function(log){
keyLog("type", typeof desiredValue, typeof value);
}
return pass || keyPass;
}, false) || pass;
}, false);
});
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]);
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){
log("Error message wrong. Expected: ", message, "- got:", err.message);
canvasBlocker = true;