skia2/modules/canvaskit/tests/skottie.spec.js
Kevin Lubick cc8a76f3c7 [canvaskit] Add gm helper functions to tests.
Note to the reviewer: Look at tests/util.js first and then
look at the others. Gerrit lets you ignore whitespace changes,
which I would recommend for this.

This emulates tests on the C++ side and dramatically reduces
boilerplate on the test code.

This also uses the beforeEach(async () => {}) trick to save
a lot of promise resolutions before each tests.

I try to clean up the style a bit as I go, seriously thinking
about adding eslint for at least the tests.

Change-Id: Iced4abb57f66572035ab5d1a54b374055e8aaa58
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/281439
Reviewed-by: Joe Gregorio <jcgregorio@google.com>
2020-04-03 19:12:02 +00:00

44 lines
1.5 KiB
JavaScript

describe('Skottie behavior', () => {
let container;
beforeEach(async () => {
await LoadCanvasKit;
container = document.createElement('div');
container.innerHTML = `
<canvas width=600 height=600 id=test></canvas>
<canvas width=600 height=600 id=report></canvas>`;
document.body.appendChild(container);
});
afterEach(() => {
document.body.removeChild(container);
});
const imgPromise = fetch('/assets/flightAnim.gif')
.then((response) => response.arrayBuffer());
const jsonPromise = fetch('/assets/animated_gif.json')
.then((response) => response.text());
gm('skottie_animgif', (canvas, promises) => {
if (!CanvasKit.skottie || !CanvasKit.managed_skottie) {
console.warn('Skipping test because not compiled with skottie');
return;
}
const animation = CanvasKit.MakeManagedAnimation(promises[1], {
'flightAnim.gif': promises[0],
});
expect(animation).toBeTruthy();
const bounds = {fLeft: 0, fTop: 0, fRight: 500, fBottom: 500};
canvas.clear(CanvasKit.WHITE);
animation.render(canvas, bounds);
// There was a bug, fixed in https://skia-review.googlesource.com/c/skia/+/241757
// that seeking again and drawing again revealed.
animation.seek(0.5);
canvas.clear(CanvasKit.WHITE);
animation.render(canvas, bounds);
animation.delete();
}, imgPromise, jsonPromise);
});