Commit 1b144877 authored by dpapad's avatar dpapad Committed by Commit Bot

WebUI: Add JS type checking for more cr_elements/ tests, part 3.

Specifically:
 - cr_fingerprint_progress_arc_tests.js
 - cr_icon_button_focus_tests.js
 - cr_icon_button_tests.js

Bug: 1000989
Change-Id: I46baa47a8019b4434ea52e62a8bf89475fbdef08
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2217033
Auto-Submit: dpapad <dpapad@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#772371}
parent 778ec014
...@@ -60,10 +60,10 @@ js_type_check("closure_compile") { ...@@ -60,10 +60,10 @@ js_type_check("closure_compile") {
":cr_drawer_tests.m", ":cr_drawer_tests.m",
":cr_expand_button_focus_tests.m", ":cr_expand_button_focus_tests.m",
":cr_expand_button_tests.m", ":cr_expand_button_tests.m",
":cr_fingerprint_progress_arc_tests.m",
":cr_icon_button_focus_tests.m",
":cr_icon_button_tests.m",
#":cr_fingerprint_progress_arc_tests",
#":cr_icon_button_focus_tests",
#":cr_icon_button_tests",
#":cr_input_test", #":cr_input_test",
#":cr_lazy_render_tests", #":cr_lazy_render_tests",
#":cr_link_row_tests", #":cr_link_row_tests",
...@@ -207,3 +207,37 @@ js_library("cr_expand_button_tests.m") { ...@@ -207,3 +207,37 @@ js_library("cr_expand_button_tests.m") {
externs_list = [ "$externs_path/mocha-2.5.js" ] externs_list = [ "$externs_path/mocha-2.5.js" ]
extra_deps = [ ":modulize" ] extra_deps = [ ":modulize" ]
} }
js_library("cr_fingerprint_progress_arc_tests.m") {
sources = [ "$root_gen_dir/chrome/test/data/webui/cr_elements/cr_fingerprint_progress_arc_tests.m.js" ]
deps = [
"..:chai_assert",
"//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled",
"//ui/webui/resources/cr_elements/cr_fingerprint:cr_fingerprint_progress_arc.m",
]
externs_list = [ "$externs_path/mocha-2.5.js" ]
extra_deps = [ ":modulize" ]
}
js_library("cr_icon_button_focus_tests.m") {
sources = [ "$root_gen_dir/chrome/test/data/webui/cr_elements/cr_icon_button_focus_tests.m.js" ]
deps = [
"..:chai_assert",
"..:test_util.m",
"//ui/webui/resources/cr_elements/cr_icon_button:cr_icon_button.m",
]
externs_list = [ "$externs_path/mocha-2.5.js" ]
extra_deps = [ ":modulize" ]
}
js_library("cr_icon_button_tests.m") {
sources = [ "$root_gen_dir/chrome/test/data/webui/cr_elements/cr_icon_button_tests.m.js" ]
deps = [
"..:chai_assert",
"..:test_util.m",
"//third_party/polymer/v3_0/components-chromium/iron-test-helpers:mock-interactions",
"//ui/webui/resources/cr_elements/cr_icon_button:cr_icon_button.m",
]
externs_list = [ "$externs_path/mocha-2.5.js" ]
extra_deps = [ ":modulize" ]
}
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
// clang-format off // clang-format off
// #import 'chrome://resources/cr_elements/cr_fingerprint/cr_fingerprint_progress_arc.m.js'; // #import 'chrome://resources/cr_elements/cr_fingerprint/cr_fingerprint_progress_arc.m.js';
// #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 {assertEquals} from '../chai_assert.js';
// clang-format on // clang-format on
/** @fileoverview Suite of tests for cr-fingerprint-progress-arc. */ /** @fileoverview Suite of tests for cr-fingerprint-progress-arc. */
...@@ -28,22 +29,25 @@ suite('cr_fingerprint_progress_arc_test', function() { ...@@ -28,22 +29,25 @@ suite('cr_fingerprint_progress_arc_test', function() {
*/ */
let Color; let Color;
/** @type {?SettingsFingerprintProgressArcElement} */ /** @type {!CrFingerprintProgressArcElement} */
let progressArc = null; let progressArc;
/** @type {?HTMLCanvasElement} */ /** @type {!HTMLCanvasElement} */
let canvas = null; let canvas;
/** @type {Color} */ /** @type {!Color} */
const black = {r: 0, g: 0, b: 0}; const black = {r: 0, g: 0, b: 0};
/** @type {Color} */
/** @type {!Color} */
const blue = {r: 0, g: 0, b: 255}; const blue = {r: 0, g: 0, b: 255};
/** @type {Color} */
/** @type {!Color} */
const white = {r: 255, g: 255, b: 255}; const white = {r: 255, g: 255, b: 255};
setup(function() { setup(function() {
PolymerTest.clearBody(); document.body.innerHTML = '';
progressArc = document.createElement('cr-fingerprint-progress-arc'); progressArc = /** @type {!CrFingerprintProgressArcElement} */ (
document.createElement('cr-fingerprint-progress-arc'));
document.body.appendChild(progressArc); document.body.appendChild(progressArc);
// Override some parameters and function for testing purposes. // Override some parameters and function for testing purposes.
...@@ -51,10 +55,9 @@ suite('cr_fingerprint_progress_arc_test', function() { ...@@ -51,10 +55,9 @@ suite('cr_fingerprint_progress_arc_test', function() {
canvas.width = 300; canvas.width = 300;
canvas.height = 150; canvas.height = 150;
progressArc.circleRadius = 50; progressArc.circleRadius = 50;
progressArc.canvasCircleStrokeWidth_ = 3; progressArc.canvasCircleStrokeWidth = 3;
progressArc.canvasCircleBackgroundColor_ = 'rgba(0,0,0,1.0)'; progressArc.canvasCircleBackgroundColor = 'rgba(0,0,0,1.0)';
progressArc.canvasCircleProgressColor_ = 'rgba(0,0,255,1.0)'; progressArc.canvasCircleProgressColor = 'rgba(0,0,255,1.0)';
progressArc.canvasCircleShadowColor_ = 'rgba(0,0,0,1.0)';
progressArc.clearCanvas = function() { progressArc.clearCanvas = function() {
const ctx = canvas.getContext('2d'); const ctx = canvas.getContext('2d');
ctx.fillStyle = 'rgba(255,255,255,1.0)'; ctx.fillStyle = 'rgba(255,255,255,1.0)';
...@@ -67,7 +70,7 @@ suite('cr_fingerprint_progress_arc_test', function() { ...@@ -67,7 +70,7 @@ suite('cr_fingerprint_progress_arc_test', function() {
/** /**
* Helper function which gets the rgb values at |point| on the canvas. * Helper function which gets the rgb values at |point| on the canvas.
* @param {Point} point * @param {Point} point
* @return {Color} * @return {!Color}
*/ */
function getRGBData(point) { function getRGBData(point) {
const ctx = canvas.getContext('2d'); const ctx = canvas.getContext('2d');
...@@ -78,8 +81,8 @@ suite('cr_fingerprint_progress_arc_test', function() { ...@@ -78,8 +81,8 @@ suite('cr_fingerprint_progress_arc_test', function() {
/** /**
* Helper function which checks if the given color is matches the expected * Helper function which checks if the given color is matches the expected
* color. * color.
* @param {Color} expectedColor * @param {!Color} expectedColor
* @param {Color} actualColor * @param {!Color} actualColor
*/ */
function assertColorEquals(expectedColor, actualColor) { function assertColorEquals(expectedColor, actualColor) {
assertEquals(expectedColor.r, actualColor.r); assertEquals(expectedColor.r, actualColor.r);
...@@ -90,8 +93,8 @@ suite('cr_fingerprint_progress_arc_test', function() { ...@@ -90,8 +93,8 @@ suite('cr_fingerprint_progress_arc_test', function() {
/** /**
* Helper function which checks that a list of points match the color the are * Helper function which checks that a list of points match the color the are
* expected to have on the canvas. * expected to have on the canvas.
* @param {Color} expectedColor * @param {!Color} expectedColor
* @param {!Array<Point>} listOfPoints * @param {!Array<!Point>} listOfPoints
*/ */
function assertListOfColorsEqual(expectedColor, listOfPoints) { function assertListOfColorsEqual(expectedColor, listOfPoints) {
for (const point of listOfPoints) { for (const point of listOfPoints) {
...@@ -103,13 +106,11 @@ suite('cr_fingerprint_progress_arc_test', function() { ...@@ -103,13 +106,11 @@ suite('cr_fingerprint_progress_arc_test', function() {
// Verify that by drawing an arc from 0 to PI/2 with radius 50 and center at // Verify that by drawing an arc from 0 to PI/2 with radius 50 and center at
// (150, 75), points along that arc should be blue, and points not on that // (150, 75), points along that arc should be blue, and points not on that
// arc should remain white. // arc should remain white.
progressArc.drawArc(0, Math.PI / 2, progressArc.canvasCircleProgressColor_); progressArc.drawArc(0, Math.PI / 2, progressArc.canvasCircleProgressColor);
/** @type {Array<Point>} */
let expectedPointsOnArc = [ let expectedPointsOnArc = [
{x: 200, y: 75} /* 0rad */, {x: 185, y: 110} /* PI/4rad */, {x: 200, y: 75} /* 0rad */, {x: 185, y: 110} /* PI/4rad */,
{x: 150, y: 125} /* PI/2rad */ {x: 150, y: 125} /* PI/2rad */
]; ];
/** @type {Array<Point>} */
let expectedPointsNotOnArc = let expectedPointsNotOnArc =
[{x: 115, y: 110} /* 3PI/4rad */, {x: 100, y: 75} /* PI */]; [{x: 115, y: 110} /* 3PI/4rad */, {x: 100, y: 75} /* PI */];
assertListOfColorsEqual(blue, expectedPointsOnArc); assertListOfColorsEqual(blue, expectedPointsOnArc);
...@@ -124,7 +125,7 @@ suite('cr_fingerprint_progress_arc_test', function() { ...@@ -124,7 +125,7 @@ suite('cr_fingerprint_progress_arc_test', function() {
// on that arc should remain white. // on that arc should remain white.
progressArc.drawArc( progressArc.drawArc(
3 * Math.PI / 2, 5 * Math.PI / 2, 3 * Math.PI / 2, 5 * Math.PI / 2,
progressArc.canvasCircleProgressColor_); progressArc.canvasCircleProgressColor);
expectedPointsOnArc = [ expectedPointsOnArc = [
{x: 150, y: 25} /* 3PI/2 */, {x: 185, y: 40} /* 7PI/4 */, {x: 150, y: 25} /* 3PI/2 */, {x: 185, y: 40} /* 7PI/4 */,
{x: 200, y: 75} /* 2PI */, {x: 185, y: 110} /* 9PI/4 */, {x: 200, y: 75} /* 2PI */, {x: 185, y: 110} /* 9PI/4 */,
...@@ -143,12 +144,10 @@ suite('cr_fingerprint_progress_arc_test', function() { ...@@ -143,12 +144,10 @@ suite('cr_fingerprint_progress_arc_test', function() {
// points along that arc should be black, and points not on that arc should // points along that arc should be black, and points not on that arc should
// remain white. // remain white.
progressArc.drawBackgroundCircle(); progressArc.drawBackgroundCircle();
/** @type {Array<Point>} */
const expectedPointsInCircle = [ const expectedPointsInCircle = [
{x: 200, y: 75} /* 0rad */, {x: 150, y: 125} /* PI/2rad */, {x: 200, y: 75} /* 0rad */, {x: 150, y: 125} /* PI/2rad */,
{x: 100, y: 75} /* PIrad */, {x: 150, y: 25} /* 3PI/2rad */ {x: 100, y: 75} /* PIrad */, {x: 150, y: 25} /* 3PI/2rad */
]; ];
/** @type {Array<Point>} */
const expectedPointsNotInCircle = [ const expectedPointsNotInCircle = [
{x: 110, y: 75} /* Too left, outside of stroke */, {x: 110, y: 75} /* Too left, outside of stroke */,
{x: 90, y: 75} /* Too right, inside of stroke */, {x: 90, y: 75} /* Too right, inside of stroke */,
......
...@@ -6,14 +6,17 @@ ...@@ -6,14 +6,17 @@
// #import 'chrome://resources/cr_elements/cr_icon_button/cr_icon_button.m.js'; // #import 'chrome://resources/cr_elements/cr_icon_button/cr_icon_button.m.js';
// //
// #import {flushTasks} from '../test_util.m.js'; // #import {flushTasks} from '../test_util.m.js';
// #import {assertFalse, assertTrue} from '../chai_assert.js';
// clang-format on // clang-format on
suite('cr-icon-button-focus-tests', function() { suite('cr-icon-button-focus-tests', function() {
/** @type {!CrIconButtonElement} */
let button; let button;
setup(async () => { setup(async () => {
PolymerTest.clearBody(); document.body.innerHTML = '';
button = document.createElement('cr-icon-button'); button = /** @type {!CrIconButtonElement} */ (
document.createElement('cr-icon-button'));
document.body.appendChild(button); document.body.appendChild(button);
await test_util.flushTasks(); await test_util.flushTasks();
}); });
......
...@@ -8,9 +8,11 @@ ...@@ -8,9 +8,11 @@
// #import {downAndUp, pressAndReleaseKeyOn} from 'chrome://resources/polymer/v3_0/iron-test-helpers/mock-interactions.js'; // #import {downAndUp, pressAndReleaseKeyOn} from 'chrome://resources/polymer/v3_0/iron-test-helpers/mock-interactions.js';
// #import {eventToPromise, flushTasks} from '../test_util.m.js'; // #import {eventToPromise, flushTasks} from '../test_util.m.js';
// #import {assertEquals, assertFalse, assertTrue} from '../chai_assert.js';
// clang-format on // clang-format on
suite('cr-icon-button', function() { suite('cr-icon-button', function() {
/** @type {!CrIconButtonElement} */
let button; let button;
/** @override */ /** @override */
...@@ -26,8 +28,9 @@ suite('cr-icon-button', function() { ...@@ -26,8 +28,9 @@ suite('cr-icon-button', function() {
} }
setup(async () => { setup(async () => {
PolymerTest.clearBody(); document.body.innerHTML = '';
button = document.createElement('cr-icon-button'); button = /** @type {!CrIconButtonElement} */ (
document.createElement('cr-icon-button'));
document.body.appendChild(button); document.body.appendChild(button);
await test_util.flushTasks(); await test_util.flushTasks();
}); });
...@@ -129,7 +132,8 @@ suite('cr-icon-button', function() { ...@@ -129,7 +132,8 @@ suite('cr-icon-button', function() {
document.body.innerHTML = document.body.innerHTML =
'<cr-icon-button custom-tab-index="-1"></cr-icon-button>'; '<cr-icon-button custom-tab-index="-1"></cr-icon-button>';
await test_util.flushTasks(); await test_util.flushTasks();
button = document.body.querySelector('cr-icon-button'); button = /** @type {!CrIconButtonElement} */ (
document.body.querySelector('cr-icon-button'));
assertEquals('-1', button.getAttribute('tabindex')); assertEquals('-1', button.getAttribute('tabindex'));
button.disabled = true; button.disabled = true;
assertEquals('-1', button.getAttribute('tabindex')); assertEquals('-1', button.getAttribute('tabindex'));
...@@ -139,7 +143,8 @@ suite('cr-icon-button', function() { ...@@ -139,7 +143,8 @@ suite('cr-icon-button', function() {
test('tabindex update', async () => { test('tabindex update', async () => {
document.body.innerHTML = '<cr-icon-button></cr-icon-button>'; document.body.innerHTML = '<cr-icon-button></cr-icon-button>';
button = document.body.querySelector('cr-icon-button'); button = /** @type {!CrIconButtonElement} */ (
document.body.querySelector('cr-icon-button'));
assertEquals('0', button.getAttribute('tabindex')); assertEquals('0', button.getAttribute('tabindex'));
button.customTabIndex = 1; button.customTabIndex = 1;
assertEquals('1', button.getAttribute('tabindex')); assertEquals('1', button.getAttribute('tabindex'));
......
...@@ -103,12 +103,15 @@ Polymer({ ...@@ -103,12 +103,15 @@ Polymer({
// Also put these values as member values so they can be overridden by tests // Also put these values as member values so they can be overridden by tests
// and the tests do not need to be changed every time the UI is. // and the tests do not need to be changed every time the UI is.
/** @private {number} */
canvasCircleStrokeWidth_: CANVAS_CIRCLE_STROKE_WIDTH, /** @type {number} */
/** @private {string} */ canvasCircleStrokeWidth: CANVAS_CIRCLE_STROKE_WIDTH,
canvasCircleBackgroundColor_: CANVAS_CIRCLE_BACKGROUND_COLOR,
/** @private {string} */ /** @type {string} */
canvasCircleProgressColor_: CANVAS_CIRCLE_PROGRESS_COLOR, canvasCircleBackgroundColor: CANVAS_CIRCLE_BACKGROUND_COLOR,
/** @type {string} */
canvasCircleProgressColor: CANVAS_CIRCLE_PROGRESS_COLOR,
/** /**
* Animation ID for fingerprint scan progress bar. * Animation ID for fingerprint scan progress bar.
...@@ -145,7 +148,7 @@ Polymer({ ...@@ -145,7 +148,7 @@ Polymer({
ctx.beginPath(); ctx.beginPath();
ctx.arc(c.width / 2, c.height / 2, this.circleRadius, startAngle, endAngle); ctx.arc(c.width / 2, c.height / 2, this.circleRadius, startAngle, endAngle);
ctx.lineWidth = this.canvasCircleStrokeWidth_; ctx.lineWidth = this.canvasCircleStrokeWidth;
ctx.strokeStyle = color; ctx.strokeStyle = color;
ctx.stroke(); ctx.stroke();
}, },
...@@ -155,7 +158,7 @@ Polymer({ ...@@ -155,7 +158,7 @@ Polymer({
* |circleRadius| and color |CANVAS_CIRCLE_BACKGROUND_COLOR|. * |circleRadius| and color |CANVAS_CIRCLE_BACKGROUND_COLOR|.
*/ */
drawBackgroundCircle() { drawBackgroundCircle() {
this.drawArc(0, 2 * Math.PI, this.canvasCircleBackgroundColor_); this.drawArc(0, 2 * Math.PI, this.canvasCircleBackgroundColor);
}, },
/** /**
...@@ -203,11 +206,10 @@ Polymer({ ...@@ -203,11 +206,10 @@ Polymer({
// |start| + |currentAngle| to 7 * Math.PI / 2 (start is 3 * Math.PI / // |start| + |currentAngle| to 7 * Math.PI / 2 (start is 3 * Math.PI /
// 2) otherwise the regular draw from |start| to |currentAngle| will // 2) otherwise the regular draw from |start| to |currentAngle| will
// draw nothing which will cause a flicker for one frame. // draw nothing which will cause a flicker for one frame.
this.drawArc( this.drawArc(start, start + currentAngle, this.canvasCircleProgressColor);
start, start + currentAngle, this.canvasCircleProgressColor_);
this.drawArc( this.drawArc(
start + currentAngle, currentAngle <= 0 ? 7 * Math.PI / 2 : start, start + currentAngle, currentAngle <= 0 ? 7 * Math.PI / 2 : start,
this.canvasCircleBackgroundColor_); this.canvasCircleBackgroundColor);
currentAngle += step; currentAngle += step;
}; };
......
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