Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/virtual/threaded/fast/compositorworker/animation-worklet-animator-registration.html |
| diff --git a/third_party/WebKit/LayoutTests/virtual/threaded/fast/compositorworker/animation-worklet-animator-registration.html b/third_party/WebKit/LayoutTests/virtual/threaded/fast/compositorworker/animation-worklet-animator-registration.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ef8b449c981ee90e0a7bc1dc20ae9409acbc2c57 |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/virtual/threaded/fast/compositorworker/animation-worklet-animator-registration.html |
| @@ -0,0 +1,72 @@ |
| +<!DOCTYPE html> |
| + |
| +<script id="duplicate" type="text/worklet"> |
| +try { |
| + registerAnimator("duplicate", class { animate() {} }); |
| + registerAnimator("duplicate", class { animate() {} }); |
| +} catch(e) { console.log(e); } |
| +</script> |
| + |
| +<script id="no_class" type="text/worklet"> |
| +try { |
| + registerAnimator("no_class", ""); |
| +} catch(e) { console.log(e); } |
| +</script> |
| + |
| +<script id="empty_string" type="text/worklet"> |
| +try { |
| + registerAnimator("", class { animate() {} }); |
| +} catch(e) { console.log(e); } |
| +</script> |
| + |
| +<script id="empty_string" type="text/worklet"> |
| +registerAnimator("test", class { |
| + constructor() { |
| + console.log("test animator constructor called."); |
| + } |
| + animate() { |
| + console.log("test animator animate called."); |
| + } |
| +}); |
| +</script> |
| + |
| +<script> |
| +// TODO(majidvp): The try/catch in above test cases should not be needed but at the moment |
| +// threaded worklet does not correctly pass error to its parent context. It crashes in |
| +// https://codesearch.chromium.org/chromium/src/third_party/WebKit/Source/bindings/core/v8/WorkerOrWorkletScriptController.cpp?sq=package:chromium&dr&l=320 |
| + |
| +function runInAnimationWorklet(code) { |
| + return window.animationWorklet.import( |
| + URL.createObjectURL(new Blob([code], {type: 'text/javascript'})) |
| + ); |
| +} |
| + |
| +// Load test cases in worklet context in sequence and wait until they are resolved. |
| +function runTests(testcases) { |
| + if (window.testRunner) { |
| + testRunner.waitUntilDone(); |
| + testRunner.dumpAsText(); |
| + } |
| + |
| + const runInSequence = testcases.reduce((chain, testcase) => { |
| + return chain.then( _ => { |
| + return runInAnimationWorklet(testcase); |
| + }); |
| + }, Promise.resolve()); |
| + |
| + // TODO(majidvp): Figure out how to wait on AnimationWorklet, which runs on a separate thread, |
| + // to complete its tasks instead of a timeout. |
|
flackr
2017/03/13 19:04:51
animationWorklet.import should return a promise wh
majidvp
2017/03/13 22:07:53
The above runeSequence chains those promises. The
|
| + runInSequence.then(_ => { |
| + setTimeout(_ => { |
| + if (window.testRunner) |
| + testRunner.notifyDone(); |
| + }, 100); |
| + }); |
| +} |
| + |
| +const testcases = Array.prototype.map.call(document.querySelectorAll('script[type$=worklet]'), ($el) => { |
| + return $el.textContent; |
| +}); |
| + |
| +runTests(testcases); |
| +</script> |