Commit 140fc3a1 authored by dpapad's avatar dpapad Committed by Commit Bot

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

Specifically:
 - cr_toast_manager_test.js
 - cr_toast_test.js
 - cr_toggle_test.js
 - cr_toolbar_search_field_tests.js

Bug: 1000989
Change-Id: I9d745caca24c46945e64faca96d9b87fcecd1af9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2227238
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Auto-Submit: dpapad <dpapad@chromium.org>
Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#775025}
parent de9b1270
...@@ -363,12 +363,18 @@ js_type_check("closure_compile_local") { ...@@ -363,12 +363,18 @@ js_type_check("closure_compile_local") {
] ]
deps = [ deps = [
":chai_assert", ":chai_assert",
":mock_timer.m",
":test_browser_proxy.m", ":test_browser_proxy.m",
":test_plural_string_proxy", ":test_plural_string_proxy",
":test_util.m", ":test_util.m",
] ]
} }
js_library("mock_timer.m") {
sources = [ "$root_gen_dir/chrome/test/data/webui/mock_timer.m.js" ]
extra_deps = [ ":modulize_local" ]
}
js_library("test_util.m") { js_library("test_util.m") {
sources = [ "$root_gen_dir/chrome/test/data/webui/test_util.m.js" ] sources = [ "$root_gen_dir/chrome/test/data/webui/test_util.m.js" ]
deps = [ deps = [
......
...@@ -81,11 +81,11 @@ js_type_check("closure_compile") { ...@@ -81,11 +81,11 @@ js_type_check("closure_compile") {
":cr_slider_test.m", ":cr_slider_test.m",
":cr_splitter_test", ":cr_splitter_test",
":cr_tabs_test.m", ":cr_tabs_test.m",
":cr_toast_manager_test.m",
":cr_toast_test.m",
":cr_toggle_test.m",
":cr_toolbar_search_field_tests.m",
#":cr_toast_manager_test",
#":cr_toast_test",
#":cr_toggle_test",
#":cr_toolbar_search_field_tests",
#":cr_view_manager_test", #":cr_view_manager_test",
#":iron_list_focus_test", #":iron_list_focus_test",
#":settings_private_test_constants", #":settings_private_test_constants",
...@@ -422,3 +422,52 @@ js_library("cr_tabs_test.m") { ...@@ -422,3 +422,52 @@ js_library("cr_tabs_test.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_toast_manager_test.m") {
sources = [ "$root_gen_dir/chrome/test/data/webui/cr_elements/cr_toast_manager_test.m.js" ]
deps = [
"..:chai_assert",
"..:test_util.m",
"//ui/webui/resources/cr_elements/cr_toast:cr_toast.m",
"//ui/webui/resources/cr_elements/cr_toast:cr_toast_manager.m",
]
externs_list = [ "$externs_path/mocha-2.5.js" ]
extra_deps = [ ":modulize" ]
}
js_library("cr_toast_test.m") {
sources =
[ "$root_gen_dir/chrome/test/data/webui/cr_elements/cr_toast_test.m.js" ]
deps = [
"..:chai_assert",
"..:mock_timer.m",
"//ui/webui/resources/cr_elements/cr_toast:cr_toast.m",
]
externs_list = [ "$externs_path/mocha-2.5.js" ]
extra_deps = [ ":modulize" ]
}
js_library("cr_toggle_test.m") {
sources =
[ "$root_gen_dir/chrome/test/data/webui/cr_elements/cr_toggle_test.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_toggle:cr_toggle.m",
]
externs_list = [ "$externs_path/mocha-2.5.js" ]
extra_deps = [ ":modulize" ]
}
js_library("cr_toolbar_search_field_tests.m") {
sources = [ "$root_gen_dir/chrome/test/data/webui/cr_elements/cr_toolbar_search_field_tests.m.js" ]
deps = [
"..:chai_assert",
"//third_party/polymer/v3_0/components-chromium/iron-test-helpers:mock-interactions",
"//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled",
"//ui/webui/resources/cr_elements/cr_toolbar:cr_toolbar_search_field.m",
]
externs_list = [ "$externs_path/mocha-2.5.js" ]
extra_deps = [ ":modulize" ]
}
...@@ -5,14 +5,17 @@ ...@@ -5,14 +5,17 @@
// clang-format off // clang-format off
// #import {getToastManager} from 'chrome://resources/cr_elements/cr_toast/cr_toast_manager.m.js'; // #import {getToastManager} from 'chrome://resources/cr_elements/cr_toast/cr_toast_manager.m.js';
// #import {eventToPromise} from '../test_util.m.js'; // #import {eventToPromise} from '../test_util.m.js';
// #import {assertEquals, assertFalse, assertTrue} from '../chai_assert.js';
// clang-format on // clang-format on
suite('cr-toast-manager', () => { suite('cr-toast-manager', () => {
/** @type {!CrToastManagerElement} */
let toastManager; let toastManager;
suiteSetup(() => { suiteSetup(() => {
PolymerTest.clearBody(); document.body.innerHTML = '';
toastManager = document.createElement('cr-toast-manager'); toastManager = /** @type {!CrToastManagerElement} */ (
document.createElement('cr-toast-manager'));
document.body.appendChild(toastManager); document.body.appendChild(toastManager);
}); });
...@@ -45,6 +48,7 @@ suite('cr-toast-manager', () => { ...@@ -45,6 +48,7 @@ suite('cr-toast-manager', () => {
test('duration passed through to toast', () => { test('duration passed through to toast', () => {
toastManager.duration = 3; toastManager.duration = 3;
assertEquals(3, toastManager.$.toast.duration); assertEquals(
3, /** @type {!CrToastElement} */ (toastManager.$$('#toast').duration));
}); });
}); });
...@@ -5,15 +5,19 @@ ...@@ -5,15 +5,19 @@
// clang-format off // clang-format off
// #import 'chrome://resources/cr_elements/cr_toast/cr_toast.m.js'; // #import 'chrome://resources/cr_elements/cr_toast/cr_toast.m.js';
// #import {MockTimer} from '../mock_timer.m.js'; // #import {MockTimer} from '../mock_timer.m.js';
// #import {assertEquals, assertFalse, assertTrue} from '../chai_assert.js';
// clang-format on // clang-format on
suite('cr-toast', function() { suite('cr-toast', function() {
/** @type {!CrToastElement} */
let toast; let toast;
/** @type {!MockTimer} */
let mockTimer; let mockTimer;
setup(function() { setup(function() {
PolymerTest.clearBody(); document.body.innerHTML = '';
toast = document.createElement('cr-toast'); toast = /** @type {!CrToastElement} */ (document.createElement('cr-toast'));
document.body.appendChild(toast); document.body.appendChild(toast);
mockTimer = new MockTimer(); mockTimer = new MockTimer();
mockTimer.install(); mockTimer.install();
......
...@@ -6,18 +6,18 @@ ...@@ -6,18 +6,18 @@
// #import 'chrome://resources/cr_elements/cr_toggle/cr_toggle.m.js'; // #import 'chrome://resources/cr_elements/cr_toggle/cr_toggle.m.js';
// #import {keyEventOn} from 'chrome://resources/polymer/v3_0/iron-test-helpers/mock-interactions.js'; // #import {keyEventOn} from 'chrome://resources/polymer/v3_0/iron-test-helpers/mock-interactions.js';
// #import {eventToPromise} from '../test_util.m.js'; // #import {eventToPromise} from '../test_util.m.js';
// #import {assertEquals, assertFalse, assertTrue} from '../chai_assert.js';
// clang-format on // clang-format on
suite('cr-toggle', function() { suite('cr-toggle', function() {
/** @type {!CrToggleElement} */
let toggle; let toggle;
setup(function() { setup(function() {
PolymerTest.clearBody(); document.body.innerHTML = '';
document.body.innerHTML = ` toggle =
<cr-toggle id="toggle"></cr-toggle> /** @type {!CrToggleElement} */ (document.createElement('cr-toggle'));
`; document.body.appendChild(toggle);
toggle = document.getElementById('toggle');
assertNotChecked(); assertNotChecked();
}); });
...@@ -26,7 +26,8 @@ suite('cr-toggle', function() { ...@@ -26,7 +26,8 @@ suite('cr-toggle', function() {
assertTrue(toggle.hasAttribute('checked')); assertTrue(toggle.hasAttribute('checked'));
assertEquals('true', toggle.getAttribute('aria-pressed')); assertEquals('true', toggle.getAttribute('aria-pressed'));
// Asserting that the toggle button has actually moved. // Asserting that the toggle button has actually moved.
assertTrue(getComputedStyle(toggle.$.knob).transform.includes('matrix')); assertTrue(
getComputedStyle(toggle.$$('#knob')).transform.includes('matrix'));
} }
function assertNotChecked() { function assertNotChecked() {
...@@ -34,7 +35,7 @@ suite('cr-toggle', function() { ...@@ -34,7 +35,7 @@ suite('cr-toggle', function() {
assertEquals(null, toggle.getAttribute('checked')); assertEquals(null, toggle.getAttribute('checked'));
assertEquals('false', toggle.getAttribute('aria-pressed')); assertEquals('false', toggle.getAttribute('aria-pressed'));
// Asserting that the toggle button has not moved. // Asserting that the toggle button has not moved.
assertEquals('none', getComputedStyle(toggle.$.knob).transform); assertEquals('none', getComputedStyle(toggle.$$('#knob')).transform);
} }
function assertDisabled() { function assertDisabled() {
......
...@@ -6,27 +6,29 @@ ...@@ -6,27 +6,29 @@
// #import 'chrome://resources/cr_elements/cr_toolbar/cr_toolbar_search_field.m.js'; // #import 'chrome://resources/cr_elements/cr_toolbar/cr_toolbar_search_field.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 {blur, pressAndReleaseKeyOn} from 'chrome://resources/polymer/v3_0/iron-test-helpers/mock-interactions.js'; // #import {pressAndReleaseKeyOn} from 'chrome://resources/polymer/v3_0/iron-test-helpers/mock-interactions.js';
// #import {assertEquals, assertDeepEquals, assertFalse, assertNotEquals, assertTrue} from '../chai_assert.js';
// clang-format on // clang-format on
/** @fileoverview Suite of tests for cr-toolbar-search-field. */ /** @fileoverview Suite of tests for cr-toolbar-search-field. */
suite('cr-toolbar-search-field', function() { suite('cr-toolbar-search-field', function() {
/** @type {?CrToolbarSearchFieldElement} */ /** @type {!CrToolbarSearchFieldElement} */
let field = null; let field;
/** @type {?Array<string>} */ /** @type {?Array<string>} */
let searches = null; let searches = null;
/** @param {string} term */ /** @param {string} term */
function simulateSearch(term) { function simulateSearch(term) {
field.$.searchInput.value = term; field.$$('#searchInput').value = term;
field.onSearchTermInput(); field.onSearchTermInput();
field.onSearchTermSearch(); field.onSearchTermSearch();
} }
setup(function() { setup(function() {
PolymerTest.clearBody(); document.body.innerHTML = '';
field = document.createElement('cr-toolbar-search-field'); field = /** @type {!CrToolbarSearchFieldElement} */ (
document.createElement('cr-toolbar-search-field'));
searches = []; searches = [];
field.addEventListener('search-changed', function(event) { field.addEventListener('search-changed', function(event) {
searches.push(event.detail); searches.push(event.detail);
...@@ -36,8 +38,6 @@ suite('cr-toolbar-search-field', function() { ...@@ -36,8 +38,6 @@ suite('cr-toolbar-search-field', function() {
teardown(function() { teardown(function() {
field.remove(); field.remove();
field = null;
searches = null;
}); });
// Test that no initial 'search-changed' event is fired during // Test that no initial 'search-changed' event is fired during
...@@ -63,18 +63,19 @@ suite('cr-toolbar-search-field', function() { ...@@ -63,18 +63,19 @@ suite('cr-toolbar-search-field', function() {
assertFalse(field.showingSearch); assertFalse(field.showingSearch);
field.click(); field.click();
assertTrue(field.showingSearch); assertTrue(field.showingSearch);
assertEquals(field.$.searchInput, field.root.activeElement); assertEquals(field.$$('#searchInput'), field.root.activeElement);
MockInteractions.blur(field.$.searchInput); field.$$('#searchInput').blur();
assertFalse(field.showingSearch); assertFalse(field.showingSearch);
field.click(); field.click();
assertEquals(field.$.searchInput, field.root.activeElement); assertEquals(field.$$('#searchInput'), field.root.activeElement);
MockInteractions.pressAndReleaseKeyOn( MockInteractions.pressAndReleaseKeyOn(
field.$.searchInput, 27, '', 'Escape'); /** @type {!HTMLElement} */ (field.$$('#searchInput')), 27, '',
'Escape');
assertFalse(field.showingSearch, 'Pressing escape closes field.'); assertFalse(field.showingSearch, 'Pressing escape closes field.');
assertNotEquals(field.$.searchInput, field.root.activeElement); assertNotEquals(field.$$('#searchInput'), field.root.activeElement);
}); });
test('clear search button clears and refocuses input', function() { test('clear search button clears and refocuses input', function() {
...@@ -88,7 +89,7 @@ suite('cr-toolbar-search-field', function() { ...@@ -88,7 +89,7 @@ suite('cr-toolbar-search-field', function() {
clearSearch.click(); clearSearch.click();
assertTrue(field.showingSearch); assertTrue(field.showingSearch);
assertEquals('', field.getValue()); assertEquals('', field.getValue());
assertEquals(field.$.searchInput, field.root.activeElement); assertEquals(field.$$('#searchInput'), field.root.activeElement);
assertFalse(field.hasSearchText); assertFalse(field.hasSearchText);
assertFalse(field.spinnerActive); assertFalse(field.spinnerActive);
}); });
...@@ -197,7 +198,7 @@ suite('cr-toolbar-search-field', function() { ...@@ -197,7 +198,7 @@ suite('cr-toolbar-search-field', function() {
test('blur does not close field when a search is active', function() { test('blur does not close field when a search is active', function() {
field.click(); field.click();
simulateSearch('test'); simulateSearch('test');
MockInteractions.blur(field.$.searchInput); field.$$('#searchInput').blur();
assertTrue(field.showingSearch); assertTrue(field.showingSearch);
}); });
...@@ -217,7 +218,7 @@ suite('cr-toolbar-search-field', function() { ...@@ -217,7 +218,7 @@ suite('cr-toolbar-search-field', function() {
}); });
test('closes when value is cleared while unfocused', function() { test('closes when value is cleared while unfocused', function() {
MockInteractions.focus(field.$.searchInput); field.$$('#searchInput').focus();
simulateSearch('test'); simulateSearch('test');
Polymer.dom.flush(); Polymer.dom.flush();
...@@ -228,7 +229,7 @@ suite('cr-toolbar-search-field', function() { ...@@ -228,7 +229,7 @@ suite('cr-toolbar-search-field', function() {
// Does close the field if it is blurred before being cleared. // Does close the field if it is blurred before being cleared.
simulateSearch('test'); simulateSearch('test');
MockInteractions.blur(field.$.searchInput); field.$$('#searchInput').blur();
field.setValue(''); field.setValue('');
assertFalse(field.showingSearch); assertFalse(field.showingSearch);
}); });
......
...@@ -23,10 +23,10 @@ ...@@ -23,10 +23,10 @@
/** /**
* Details for active timers. * Details for active timers.
* @type {Array<{callback: Function, * @type {!Array<{callback: Function,
* delay: number, * delay: number,
* key: number, * key: number,
* repeats: boolean}>} * repeats: boolean}|undefined>}
* @private * @private
*/ */
this.timers_ = []; this.timers_ = [];
......
...@@ -42,10 +42,7 @@ polymer_modulizer("cr_toast_manager") { ...@@ -42,10 +42,7 @@ polymer_modulizer("cr_toast_manager") {
html_file = "cr_toast_manager.html" html_file = "cr_toast_manager.html"
html_type = "dom-module" html_type = "dom-module"
auto_imports = [ "ui/webui/resources/html/assert.html|assert" ] auto_imports = [ "ui/webui/resources/html/assert.html|assert" ]
namespace_rewrites = [ namespace_rewrites = [ "cr.toastManager.getToastManager|getToastManager" ]
"cr.toastManager.CrToastManagerElement|CrToastManagerElement",
"cr.toastManager.getToastManager|getToastManager",
]
} }
js_type_check("closure_compile_module") { js_type_check("closure_compile_module") {
......
...@@ -4,16 +4,16 @@ ...@@ -4,16 +4,16 @@
cr.define('cr.toastManager', () => { cr.define('cr.toastManager', () => {
/* eslint-disable */ /* eslint-disable */
/** @private {?cr.toastManager.CrToastManagerElement} */ /** @private {?CrToastManagerElement} */
let toastManagerInstance = null; let toastManagerInstance = null;
/* eslint-enable */ /* eslint-enable */
/** @return {!cr.toastManager.CrToastManagerElement} */ /** @return {!CrToastManagerElement} */
/* #export */ function getToastManager() { /* #export */ function getToastManager() {
return assert(toastManagerInstance); return assert(toastManagerInstance);
} }
/** @param {?cr.toastManager.CrToastManagerElement} instance */ /** @param {?CrToastManagerElement} instance */
function setInstance(instance) { function setInstance(instance) {
assert(!instance || !toastManagerInstance); assert(!instance || !toastManagerInstance);
toastManagerInstance = instance; toastManagerInstance = instance;
...@@ -23,7 +23,7 @@ cr.define('cr.toastManager', () => { ...@@ -23,7 +23,7 @@ cr.define('cr.toastManager', () => {
* @fileoverview Element which shows toasts with optional undo button. * @fileoverview Element which shows toasts with optional undo button.
*/ */
// eslint-disable-next-line // eslint-disable-next-line
/* #export */ let CrToastManagerElement = Polymer({ Polymer({
is: 'cr-toast-manager', is: 'cr-toast-manager',
properties: { properties: {
...@@ -94,7 +94,6 @@ cr.define('cr.toastManager', () => { ...@@ -94,7 +94,6 @@ cr.define('cr.toastManager', () => {
// #cr_define_end // #cr_define_end
return { return {
CrToastManagerElement: CrToastManagerElement,
getToastManager: getToastManager, getToastManager: getToastManager,
}; };
}); });
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