blob: 2bd21d4fdc0d4b69614bed338627efb8ea0b43af [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script>
function runner(tests) {
if (window.testRunner) {
testRunner.waitUntilDone();
testRunner.dumpAsText();
}
tests.reduce(function(chain, obj) {
return chain.then(function() {
if (obj.expectedError) {
console.log('The worklet should throw an error with: "' + obj.expectedError + '"');
} else {
console.log('The worklet should not throw an error.');
}
var blob = new Blob([obj.script], {type: 'text/javascript'});
return paintWorklet.import(URL.createObjectURL(blob));
});
}, Promise.resolve()).then(function() {
if (window.testRunner) {
testRunner.notifyDone();
}
});
}
function runTest() {
runner([{
expectedError: "A class with name:'foo' is already registered.",
script: "registerPaint('foo', class { paint() { } }); registerPaint('foo', class { paint() { } });",
}, {
expectedError: "The empty string is not a valid name.",
script: "registerPaint('', class { });",
}, {
expectedError: "failed!",
script: "registerPaint('foo3', class { static get inputProperties() { throw Error('failed!'); } });",
}, {
expectedError: "The value provided is neither an array, nor does it have indexed properties.",
script: "registerPaint('foo4', class { static get inputProperties() { return 42; } });",
}, {
expectedError: "The 'prototype' object on the class does not exist.",
script: "var a = function() { }; a.prototype = undefined; registerPaint('foo5', a);",
}, {
expectedError: "The 'prototype' property on the class is not an object.",
script: "var b = function() { }; b.prototype = 42; registerPaint('foo6', b);",
}, {
expectedError: "The 'paint' function on the prototype does not exist.",
script: "registerPaint('foo7', class { });",
}, {
expectedError: "The 'paint' property on the prototype is not a function.",
script: "registerPaint('foo8', class { get paint() { return 42; } });",
}, {
script: "registerPaint('foo9', class { paint() { } }); console.log('Success for \\'foo9\\'.');",
}, {
script: "var c = function() { }; c.prototype.paint = function() { }; registerPaint('foo10', c); console.log('Success for \\'foo10\\'.');",
}]);
}
</script>
</head>
<body onload="runTest()">
<p>This tests a series of PaintWorkletGlobalScope#registerPaint calls.</p>
<p>See the devtools console for test output.</p>
</body>
</html>