Commit 20cebc66 authored by Nina Satragno's avatar Nina Satragno Committed by Commit Bot

[webui] Polish up lottie tests

This patch follows-up on crrev.com/c/2320075 to clean up lottie tests:
* Enable closure compilation.
* Re-enable a test that was missed in the previous CL.
* Delete a redundant test that was verifying private behaviour.

Bug: 1000989, 1103865
Change-Id: I3754eb1ebb060179e6a652028751110f9da792f1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2317854
Auto-Submit: Nina Satragno <nsatragno@chromium.org>
Commit-Queue: dpapad <dpapad@chromium.org>
Reviewed-by: default avatardpapad <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#794928}
parent 64ee41dc
...@@ -51,7 +51,6 @@ js_modulizer("modulize") { ...@@ -51,7 +51,6 @@ js_modulizer("modulize") {
js_type_check("closure_compile") { js_type_check("closure_compile") {
is_polymer3 = true is_polymer3 = true
# TODO(crbug.com/1000989): Add JS type checking for all commented out targets.
deps = [ deps = [
":cr_action_menu_test.m", ":cr_action_menu_test.m",
":cr_button_tests.m", ":cr_button_tests.m",
...@@ -67,9 +66,7 @@ js_type_check("closure_compile") { ...@@ -67,9 +66,7 @@ js_type_check("closure_compile") {
":cr_input_test.m", ":cr_input_test.m",
":cr_lazy_render_tests.m", ":cr_lazy_render_tests.m",
":cr_link_row_tests.m", ":cr_link_row_tests.m",
":cr_lottie_tests.m",
#":cr_lottie_tests",
":cr_policy_indicator_behavior_tests.m", ":cr_policy_indicator_behavior_tests.m",
":cr_policy_indicator_tests.m", ":cr_policy_indicator_tests.m",
":cr_policy_pref_indicator_tests.m", ":cr_policy_pref_indicator_tests.m",
...@@ -279,6 +276,19 @@ js_library("cr_link_row_tests.m") { ...@@ -279,6 +276,19 @@ js_library("cr_link_row_tests.m") {
extra_deps = [ ":modulize" ] extra_deps = [ ":modulize" ]
} }
js_library("cr_lottie_tests.m") {
sources = [
"$root_gen_dir/chrome/test/data/webui/cr_elements/cr_lottie_tests.m.js",
]
deps = [
"..:chai_assert",
"..:mock_controller.m",
"//ui/webui/resources/cr_elements/cr_lottie:cr_lottie.m",
]
externs_list = [ "$externs_path/mocha-2.5.js" ]
extra_deps = [ ":modulize" ]
}
js_library("cr_policy_indicator_behavior_tests.m") { js_library("cr_policy_indicator_behavior_tests.m") {
sources = [ "$root_gen_dir/chrome/test/data/webui/cr_elements/cr_policy_indicator_behavior_tests.m.js" ] sources = [ "$root_gen_dir/chrome/test/data/webui/cr_elements/cr_policy_indicator_behavior_tests.m.js" ]
deps = [ deps = [
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
// #import {flush} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; // #import {flush} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
// #import {eventToPromise} from '../test_util.m.js'; // #import {eventToPromise} from '../test_util.m.js';
// #import {MockController, MockMethod} from '../mock_controller.m.js'; // #import {MockController, MockMethod} from '../mock_controller.m.js';
// #import {assertDeepEquals, assertEquals, assertFalse, assertTrue} from '../chai_assert.js';
// clang-format on // clang-format on
/** @fileoverview Suite of tests for cr-lottie. */ /** @fileoverview Suite of tests for cr-lottie. */
...@@ -39,13 +40,13 @@ suite('cr_lottie_test', function() { ...@@ -39,13 +40,13 @@ suite('cr_lottie_test', function() {
/** /**
* A green pixel as returned by samplePixel. * A green pixel as returned by samplePixel.
* @type {!Array<number>>} * @type {!Array<number>}
*/ */
const GREEN_PIXEL = [0, 255, 0, 255]; const GREEN_PIXEL = [0, 255, 0, 255];
/** /**
* A blue pixel as returned by samplePixel. * A blue pixel as returned by samplePixel.
* @type {!Array<number>>} * @type {!Array<number>}
*/ */
const BLUE_PIXEL = [0, 0, 255, 255]; const BLUE_PIXEL = [0, 0, 255, 255];
...@@ -61,7 +62,7 @@ suite('cr_lottie_test', function() { ...@@ -61,7 +62,7 @@ suite('cr_lottie_test', function() {
/** @type {?HTMLCanvasElement} */ /** @type {?HTMLCanvasElement} */
let canvas = null; let canvas = null;
/** @type {?blob} */ /** @type {?Blob} */
let lottieWorkerJs = null; let lottieWorkerJs = null;
/** @type {Promise} */ /** @type {Promise} */
...@@ -70,9 +71,6 @@ suite('cr_lottie_test', function() { ...@@ -70,9 +71,6 @@ suite('cr_lottie_test', function() {
/** @type {Promise} */ /** @type {Promise} */
let waitForPlayingEvent; let waitForPlayingEvent;
/** @type {Promise} */
let waitForResizeEvent;
setup(function(done) { setup(function(done) {
mockController = new MockController(); mockController = new MockController();
...@@ -83,7 +81,7 @@ suite('cr_lottie_test', function() { ...@@ -83,7 +81,7 @@ suite('cr_lottie_test', function() {
xhr.onreadystatechange = function() { xhr.onreadystatechange = function() {
if (xhr.readyState === 4) { if (xhr.readyState === 4) {
assertEquals(200, xhr.status); assertEquals(200, xhr.status);
lottieWorkerJs = xhr.response; lottieWorkerJs = /** @type {Blob} */ (xhr.response);
done(); done();
} }
}; };
...@@ -94,8 +92,9 @@ suite('cr_lottie_test', function() { ...@@ -94,8 +92,9 @@ suite('cr_lottie_test', function() {
}); });
function createLottieElement() { function createLottieElement() {
PolymerTest.clearBody(); document.body.innerHTML = '';
crLottieElement = document.createElement('cr-lottie'); crLottieElement =
/** @type {!CrLottieElement} */ (document.createElement('cr-lottie'));
crLottieElement.animationUrl = SAMPLE_LOTTIE_GREEN; crLottieElement.animationUrl = SAMPLE_LOTTIE_GREEN;
crLottieElement.autoplay = true; crLottieElement.autoplay = true;
...@@ -103,16 +102,14 @@ suite('cr_lottie_test', function() { ...@@ -103,16 +102,14 @@ suite('cr_lottie_test', function() {
test_util.eventToPromise('cr-lottie-initialized', crLottieElement); test_util.eventToPromise('cr-lottie-initialized', crLottieElement);
waitForPlayingEvent = waitForPlayingEvent =
test_util.eventToPromise('cr-lottie-playing', crLottieElement); test_util.eventToPromise('cr-lottie-playing', crLottieElement);
waitForResizeEvent =
test_util.eventToPromise('cr-lottie-resized', crLottieElement);
container = document.createElement('div'); container = /** @type {!HTMLDivElement} */ (document.createElement('div'));
container.style.width = '300px'; container.style.width = '300px';
container.style.height = '200px'; container.style.height = '200px';
document.body.appendChild(container); document.body.appendChild(container);
container.appendChild(crLottieElement); container.appendChild(crLottieElement);
canvas = crLottieElement.offscreenCanvas_; canvas = /** @type {!HTMLCanvasElement} */ (crLottieElement.$$('canvas'));
Polymer.dom.flush(); Polymer.dom.flush();
} }
...@@ -145,34 +142,24 @@ suite('cr_lottie_test', function() { ...@@ -145,34 +142,24 @@ suite('cr_lottie_test', function() {
context.getImageData(canvas.width / 2, canvas.height / 2, 1, 1).data); context.getImageData(canvas.width / 2, canvas.height / 2, 1, 1).data);
} }
test('TestInitializeAnimationAndAutoPlay', async () => { test('TestResize', async () => {
createLottieElement();
assertFalse(crLottieElement.isAnimationLoaded_);
await waitForInitializeEvent;
assertTrue(crLottieElement.isAnimationLoaded_);
await waitForPlayingEvent;
});
// TODO(crbug.com/1021474): flaky.
test.skip('TestResize', async () => {
createLottieElement(); createLottieElement();
await waitForInitializeEvent; await waitForInitializeEvent;
await waitForPlayingEvent; await waitForPlayingEvent;
await waitForResizeEvent;
const newHeight = 300; const newHeight = 300;
const newWidth = 400; const newWidth = 400;
waitForResizeEvent = const waitForResizeEvent =
test_util.eventToPromise('cr-lottie-resized', crLottieElement) /** @type {!Promise<!CustomEvent<{width: number, height: number}>>} */ (
.then(function(e) { test_util.eventToPromise('cr-lottie-resized', crLottieElement));
assertEquals(e.detail.height, newHeight);
assertEquals(e.detail.width, newWidth);
});
// Update size of parent div container to see if the canvas is resized. // Update size of parent div container to see if the canvas is resized.
container.style.width = newWidth + 'px'; container.style.width = newWidth + 'px';
container.style.height = newHeight + 'px'; container.style.height = newHeight + 'px';
await waitForResizeEvent; const resizeEvent = await waitForResizeEvent;
assertEquals(resizeEvent.detail.height, newHeight);
assertEquals(resizeEvent.detail.width, newWidth);
}); });
test('TestPlayPause', async () => { test('TestPlayPause', async () => {
...@@ -266,13 +253,15 @@ suite('cr_lottie_test', function() { ...@@ -266,13 +253,15 @@ suite('cr_lottie_test', function() {
test('TestHidden', async () => { test('TestHidden', async () => {
await waitForPlayingEvent; await waitForPlayingEvent;
assertFalse(crLottieElement.$$('canvas').hidden); assertFalse(canvas.hidden);
crLottieElement.hidden = true; crLottieElement.hidden = true;
assertTrue(crLottieElement.$$('canvas').hidden); assertTrue(canvas.hidden);
}); });
test('TestDetachBeforeImageLoaded', async () => { test('TestDetachBeforeImageLoaded', async () => {
const mockXhr = {}; const mockXhr = {
onreadystatechange: () => {},
};
mockXhr.open = mockController.createFunctionMock(mockXhr, 'open'); mockXhr.open = mockController.createFunctionMock(mockXhr, 'open');
mockXhr.send = mockController.createFunctionMock(mockXhr, 'send'); mockXhr.send = mockController.createFunctionMock(mockXhr, 'send');
mockXhr.abort = mockController.createFunctionMock(mockXhr, 'abort'); mockXhr.abort = mockController.createFunctionMock(mockXhr, 'abort');
...@@ -309,7 +298,9 @@ suite('cr_lottie_test', function() { ...@@ -309,7 +298,9 @@ suite('cr_lottie_test', function() {
}); });
test('TestLoadNewImageWhileOldImageIsStillLoading', async () => { test('TestLoadNewImageWhileOldImageIsStillLoading', async () => {
const mockXhr = {}; const mockXhr = {
onreadystatechange: () => {},
};
mockXhr.open = mockController.createFunctionMock(mockXhr, 'open'); mockXhr.open = mockController.createFunctionMock(mockXhr, 'open');
mockXhr.send = mockController.createFunctionMock(mockXhr, 'send'); mockXhr.send = mockController.createFunctionMock(mockXhr, 'send');
mockXhr.abort = mockController.createFunctionMock(mockXhr, 'abort'); mockXhr.abort = mockController.createFunctionMock(mockXhr, 'abort');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment