OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <script> |
| 5 function runner(tests) { |
| 6 if (window.testRunner) { |
| 7 testRunner.waitUntilDone(); |
| 8 testRunner.dumpAsText(); |
| 9 } |
| 10 |
| 11 tests.reduce(function(chain, obj) { |
| 12 return chain.then(function() { |
| 13 if (obj.expectedError) { |
| 14 console.log('The worklet should throw an error with: "' + obj.ex
pectedError + '"'); |
| 15 } else { |
| 16 console.log('The worklet should not throw an error.'); |
| 17 } |
| 18 var blob = new Blob([obj.script], {type: 'text/javascript'}); |
| 19 return paintWorklet.import(URL.createObjectURL(blob)); |
| 20 }); |
| 21 }, Promise.resolve()).then(function() { |
| 22 if (window.testRunner) { |
| 23 testRunner.notifyDone(); |
| 24 } |
| 25 }); |
| 26 } |
| 27 |
| 28 function runTest() { |
| 29 runner([{ |
| 30 expectedError: "A class with name:'foo' is already registered.", |
| 31 script: "registerPaint('foo', class { paint() { } }); registerPaint('foo
', class { paint() { } });", |
| 32 }, { |
| 33 expectedError: "The empty string is not a valid name.", |
| 34 script: "registerPaint('', class { });", |
| 35 }, { |
| 36 expectedError: "failed!", |
| 37 script: "registerPaint('foo3', class { static get inputProperties() { th
row Error('failed!'); } });", |
| 38 }, { |
| 39 expectedError: "The value provided is neither an array, nor does it have
indexed properties.", |
| 40 script: "registerPaint('foo4', class { static get inputProperties() { re
turn 42; } });", |
| 41 }, { |
| 42 expectedError: "The 'prototype' object on the class does not exist.", |
| 43 script: "var a = function() { }; a.prototype = undefined; registerPaint(
'foo5', a);", |
| 44 }, { |
| 45 expectedError: "The 'prototype' property on the class is not an object."
, |
| 46 script: "var b = function() { }; b.prototype = 42; registerPaint('foo6',
b);", |
| 47 }, { |
| 48 expectedError: "The 'paint' function on the prototype does not exist.", |
| 49 script: "registerPaint('foo7', class { });", |
| 50 }, { |
| 51 expectedError: "The 'paint' property on the prototype is not a function.
", |
| 52 script: "registerPaint('foo8', class { get paint() { return 42; } });", |
| 53 }, { |
| 54 script: "registerPaint('foo9', class { paint() { } }); console.log('Succ
ess for \\'foo9\\'.');", |
| 55 }, { |
| 56 script: "var c = function() { }; c.prototype.paint = function() { }; reg
isterPaint('foo10', c); console.log('Success for \\'foo10\\'.');", |
| 57 }]); |
| 58 } |
| 59 </script> |
| 60 </head> |
| 61 <body onload="runTest()"> |
| 62 <p>This tests a series of PaintWorkletGlobalScope#registerPaint calls.</p> |
| 63 <p>See the devtools console for test output.</p> |
| 64 </body> |
| 65 </html> |
OLD | NEW |