Commit c57821dd authored by dpapad's avatar dpapad Committed by Commit Bot

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

Specifically:
 - cr_checkbox_test.js
 - cr_container_shadow_test.js
 - cr_dialog_test.js

Bug: 1000989
Change-Id: I8f6f24b966f3158f53035a3326e89e7404659d88
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2209244
Auto-Submit: dpapad <dpapad@chromium.org>
Commit-Queue: John Lee <johntlee@chromium.org>
Reviewed-by: default avatarJohn Lee <johntlee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#770650}
parent 0aab4e59
...@@ -54,10 +54,10 @@ js_type_check("closure_compile") { ...@@ -54,10 +54,10 @@ js_type_check("closure_compile") {
deps = [ deps = [
":cr_action_menu_test.m", ":cr_action_menu_test.m",
":cr_button_tests.m", ":cr_button_tests.m",
":cr_checkbox_test.m",
":cr_container_shadow_behavior_test.m",
":cr_dialog_test.m",
#":cr_checkbox_test",
#":cr_container_shadow_behavior_test",
#":cr_dialog_test",
#":cr_drawer_tests", #":cr_drawer_tests",
#":cr_expand_button_focus_tests", #":cr_expand_button_focus_tests",
#":cr_expand_button_tests", #":cr_expand_button_tests",
...@@ -129,3 +129,42 @@ js_library("cr_button_tests.m") { ...@@ -129,3 +129,42 @@ js_library("cr_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_checkbox_test.m") {
sources = [
"$root_gen_dir/chrome/test/data/webui/cr_elements/cr_checkbox_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_checkbox:cr_checkbox.m",
]
externs_list = [ "$externs_path/mocha-2.5.js" ]
extra_deps = [ ":modulize" ]
}
js_library("cr_container_shadow_behavior_test.m") {
sources = [ "$root_gen_dir/chrome/test/data/webui/cr_elements/cr_container_shadow_behavior_test.m.js" ]
deps = [
"..:chai_assert",
"//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled",
"//ui/webui/resources/cr_elements:cr_container_shadow_behavior.m",
]
externs_list = [ "$externs_path/mocha-2.5.js" ]
extra_deps = [ ":modulize" ]
}
js_library("cr_dialog_test.m") {
sources =
[ "$root_gen_dir/chrome/test/data/webui/cr_elements/cr_dialog_test.m.js" ]
deps = [
"..:chai_assert",
"..:test_util.m",
"//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_dialog:cr_dialog.m",
]
externs_list = [ "$externs_path/mocha-2.5.js" ]
extra_deps = [ ":modulize" ]
}
...@@ -6,13 +6,17 @@ ...@@ -6,13 +6,17 @@
// #import 'chrome://resources/cr_elements/cr_checkbox/cr_checkbox.m.js'; // #import 'chrome://resources/cr_elements/cr_checkbox/cr_checkbox.m.js';
// #import {keyDownOn, keyUpOn, pressAndReleaseKeyOn} from 'chrome://resources/polymer/v3_0/iron-test-helpers/mock-interactions.js'; // #import {keyDownOn, keyUpOn, pressAndReleaseKeyOn} 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-checkbox', function() { suite('cr-checkbox', function() {
/** @type {!CrCheckboxElement} */
let checkbox; let checkbox;
/** @type {!HTMLElement} */
let innerCheckbox;
setup(function() { setup(function() {
PolymerTest.clearBody();
document.body.innerHTML = ` document.body.innerHTML = `
<cr-checkbox> <cr-checkbox>
<div>label <div>label
...@@ -21,46 +25,48 @@ suite('cr-checkbox', function() { ...@@ -21,46 +25,48 @@ suite('cr-checkbox', function() {
</cr-checkbox> </cr-checkbox>
`; `;
checkbox = document.querySelector('cr-checkbox'); checkbox = /** @type {!CrCheckboxElement} */ (
document.querySelector('cr-checkbox'));
innerCheckbox = /** @type {!HTMLElement} */ (checkbox.$$('#checkbox'));
assertNotChecked(); assertNotChecked();
}); });
function assertChecked() { function assertChecked() {
assertTrue(checkbox.checked); assertTrue(checkbox.checked);
assertTrue(checkbox.hasAttribute('checked')); assertTrue(checkbox.hasAttribute('checked'));
assertEquals('true', checkbox.$.checkbox.getAttribute('aria-checked')); assertEquals('true', innerCheckbox.getAttribute('aria-checked'));
} }
function assertNotChecked() { function assertNotChecked() {
assertFalse(checkbox.checked); assertFalse(checkbox.checked);
assertEquals(null, checkbox.getAttribute('checked')); assertEquals(null, checkbox.getAttribute('checked'));
assertEquals('false', checkbox.$.checkbox.getAttribute('aria-checked')); assertEquals('false', innerCheckbox.getAttribute('aria-checked'));
} }
function assertDisabled() { function assertDisabled() {
assertTrue(checkbox.disabled); assertTrue(checkbox.disabled);
assertFalse(checkbox.hasAttribute('tabindex')); assertFalse(checkbox.hasAttribute('tabindex'));
assertEquals('-1', checkbox.$.checkbox.getAttribute('tabindex')); assertEquals('-1', innerCheckbox.getAttribute('tabindex'));
assertTrue(checkbox.hasAttribute('disabled')); assertTrue(checkbox.hasAttribute('disabled'));
assertEquals('true', checkbox.$.checkbox.getAttribute('aria-disabled')); assertEquals('true', innerCheckbox.getAttribute('aria-disabled'));
assertEquals('none', getComputedStyle(checkbox).pointerEvents); assertEquals('none', getComputedStyle(checkbox).pointerEvents);
} }
function assertNotDisabled() { function assertNotDisabled() {
assertFalse(checkbox.disabled); assertFalse(checkbox.disabled);
assertFalse(checkbox.hasAttribute('tabindex')); assertFalse(checkbox.hasAttribute('tabindex'));
assertEquals('0', checkbox.$.checkbox.getAttribute('tabindex')); assertEquals('0', innerCheckbox.getAttribute('tabindex'));
assertFalse(checkbox.hasAttribute('disabled')); assertFalse(checkbox.hasAttribute('disabled'));
assertEquals('false', checkbox.$.checkbox.getAttribute('aria-disabled')); assertEquals('false', innerCheckbox.getAttribute('aria-disabled'));
} }
/** /**
* @param {string} keyName The name of the key to trigger. * @param {string} keyName The name of the key to trigger.
* @param {HTMLElement=} element * @param {!HTMLElement=} element
*/ */
function triggerKeyPressEvent(keyName, element) { function triggerKeyPressEvent(keyName, element) {
element = element || checkbox.$.checkbox; MockInteractions.pressAndReleaseKeyOn(
MockInteractions.pressAndReleaseKeyOn(element, '', undefined, keyName); element || innerCheckbox, 0, undefined, keyName);
} }
// Test that the control is checked when the user taps on it (no movement // Test that the control is checked when the user taps on it (no movement
...@@ -97,7 +103,7 @@ suite('cr-checkbox', function() { ...@@ -97,7 +103,7 @@ suite('cr-checkbox', function() {
test('Toggle checkbox button click', async () => { test('Toggle checkbox button click', async () => {
let whenChanged = test_util.eventToPromise('change', checkbox); let whenChanged = test_util.eventToPromise('change', checkbox);
checkbox.$.checkbox.click(); innerCheckbox.click();
await whenChanged; await whenChanged;
assertChecked(); assertChecked();
whenChanged = test_util.eventToPromise('change', checkbox); whenChanged = test_util.eventToPromise('change', checkbox);
...@@ -122,7 +128,7 @@ suite('cr-checkbox', function() { ...@@ -122,7 +128,7 @@ suite('cr-checkbox', function() {
checkbox.click(); checkbox.click();
assertNotChecked(); assertNotChecked();
checkbox.$.checkbox.click(); innerCheckbox.click();
assertNotChecked(); assertNotChecked();
triggerKeyPressEvent('Enter'); triggerKeyPressEvent('Enter');
assertNotChecked(); assertNotChecked();
...@@ -148,7 +154,8 @@ suite('cr-checkbox', function() { ...@@ -148,7 +154,8 @@ suite('cr-checkbox', function() {
}); });
assertNotChecked(); assertNotChecked();
const link = document.querySelector('a'); const link =
/** @type {!HTMLAnchorElement} */ (document.querySelector('a'));
link.click(); link.click();
assertNotChecked(); assertNotChecked();
...@@ -161,52 +168,54 @@ suite('cr-checkbox', function() { ...@@ -161,52 +168,54 @@ suite('cr-checkbox', function() {
test('space key down does not toggle', () => { test('space key down does not toggle', () => {
assertNotChecked(); assertNotChecked();
MockInteractions.keyDownOn(checkbox.$.checkbox, null, undefined, ' '); MockInteractions.keyDownOn(innerCheckbox, 0, undefined, ' ');
assertNotChecked(); assertNotChecked();
}); });
test('space key up toggles', () => { test('space key up toggles', () => {
assertNotChecked(); assertNotChecked();
MockInteractions.keyUpOn(checkbox.$.checkbox, null, undefined, ' '); MockInteractions.keyUpOn(innerCheckbox, 0, undefined, ' ');
assertChecked(); assertChecked();
}); });
test('InitializingWithTabindex', function() { test('InitializingWithTabindex', function() {
PolymerTest.clearBody();
document.body.innerHTML = ` document.body.innerHTML = `
<cr-checkbox id="checkbox" tab-index="-1"></cr-checkbox> <cr-checkbox id="checkbox" tab-index="-1"></cr-checkbox>
`; `;
checkbox = document.querySelector('cr-checkbox'); checkbox = /** @type {!CrCheckboxElement} */ (
document.querySelector('cr-checkbox'));
innerCheckbox = /** @type {!HTMLElement} */ (checkbox.$$('#checkbox'));
// Should not override tabindex if it is initialized. // Should not override tabindex if it is initialized.
assertEquals(-1, checkbox.tabIndex); assertEquals(-1, checkbox.tabIndex);
assertFalse(checkbox.hasAttribute('tabindex')); assertFalse(checkbox.hasAttribute('tabindex'));
assertEquals('-1', checkbox.$.checkbox.getAttribute('tabindex')); assertEquals('-1', innerCheckbox.getAttribute('tabindex'));
}); });
test('InitializingWithDisabled', function() { test('InitializingWithDisabled', function() {
PolymerTest.clearBody();
document.body.innerHTML = ` document.body.innerHTML = `
<cr-checkbox id="checkbox" disabled></cr-checkbox> <cr-checkbox id="checkbox" disabled></cr-checkbox>
`; `;
checkbox = document.querySelector('cr-checkbox'); checkbox = /** @type {!CrCheckboxElement} */ (
document.querySelector('cr-checkbox'));
innerCheckbox = /** @type {!HTMLElement} */ (checkbox.$$('#checkbox'));
// Initializing with disabled should make tabindex="-1". // Initializing with disabled should make tabindex="-1".
assertEquals(-1, checkbox.tabIndex); assertEquals(-1, checkbox.tabIndex);
assertFalse(checkbox.hasAttribute('tabindex')); assertFalse(checkbox.hasAttribute('tabindex'));
assertEquals('-1', checkbox.$.checkbox.getAttribute('tabindex')); assertEquals('-1', innerCheckbox.getAttribute('tabindex'));
}); });
test('tabindex attribute is controlled by tabIndex', () => { test('tabindex attribute is controlled by tabIndex', () => {
PolymerTest.clearBody();
document.body.innerHTML = ` document.body.innerHTML = `
<cr-checkbox id="checkbox" tabindex="-1"></cr-checkbox> <cr-checkbox id="checkbox" tabindex="-1"></cr-checkbox>
`; `;
checkbox = document.querySelector('cr-checkbox'); checkbox = /** @type {!CrCheckboxElement} */ (
document.querySelector('cr-checkbox'));
assertEquals(0, checkbox.tabIndex); assertEquals(0, checkbox.tabIndex);
assertFalse(checkbox.hasAttribute('tabindex')); assertFalse(checkbox.hasAttribute('tabindex'));
assertEquals('0', checkbox.$.checkbox.getAttribute('tabindex')); assertEquals('0', innerCheckbox.getAttribute('tabindex'));
}); });
}); });
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
// clang-format off // clang-format off
// #import {CrContainerShadowBehavior} from 'chrome://resources/cr_elements/cr_container_shadow_behavior.m.js'; // #import {CrContainerShadowBehavior} from 'chrome://resources/cr_elements/cr_container_shadow_behavior.m.js';
// #import {Polymer, html} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; // #import {Polymer, html} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
// #import {assertFalse, assertTrue} from '../chai_assert.js';
// clang-format on // clang-format on
suite('CrContainerShadowBehavior', function() { suite('CrContainerShadowBehavior', function() {
...@@ -61,11 +62,12 @@ suite('CrContainerShadowBehavior', function() { ...@@ -61,11 +62,12 @@ suite('CrContainerShadowBehavior', function() {
}); });
setup(function() { setup(function() {
PolymerTest.clearBody(); document.body.innerHTML = '';
}); });
test('no bottom shadow', function() { test('no bottom shadow', function() {
const element = document.createElement('test-element'); const element = /** @type {TestElementElement} */ (
document.createElement('test-element'));
document.body.appendChild(element); document.body.appendChild(element);
// Should not have a bottom shadow div. // Should not have a bottom shadow div.
...@@ -80,7 +82,8 @@ suite('CrContainerShadowBehavior', function() { ...@@ -80,7 +82,8 @@ suite('CrContainerShadowBehavior', function() {
}); });
test('show bottom shadow', function() { test('show bottom shadow', function() {
const element = document.createElement('test-element'); const element = /** @type {TestElementElement} */ (
document.createElement('test-element'));
element.showBottomShadow = true; element.showBottomShadow = true;
document.body.appendChild(element); document.body.appendChild(element);
......
...@@ -8,9 +8,11 @@ ...@@ -8,9 +8,11 @@
// #import {eventToPromise, flushTasks} from '../test_util.m.js'; // #import {eventToPromise, flushTasks} from '../test_util.m.js';
// #import {keyDownOn, keyEventOn, tap} from 'chrome://resources/polymer/v3_0/iron-test-helpers/mock-interactions.js'; // #import {keyDownOn, keyEventOn, tap} from 'chrome://resources/polymer/v3_0/iron-test-helpers/mock-interactions.js';
// #import {Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; // #import {Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
// #import {assertEquals, assertFalse, assertNotEquals, assertNotReached, assertTrue} from '../chai_assert.js';
// clang-format on // clang-format on
suite('cr-dialog', function() { suite('cr-dialog', function() {
/** @type {!HTMLElement} element */
function pressEnter(element) { function pressEnter(element) {
MockInteractions.keyEventOn(element, 'keypress', 13, undefined, 'Enter'); MockInteractions.keyEventOn(element, 'keypress', 13, undefined, 'Enter');
} }
...@@ -43,7 +45,7 @@ suite('cr-dialog', function() { ...@@ -43,7 +45,7 @@ suite('cr-dialog', function() {
} }
setup(function() { setup(function() {
PolymerTest.clearBody(); document.body.innerHTML = '';
// Ensure svg, which is referred to by a relative URL, is loaded from // Ensure svg, which is referred to by a relative URL, is loaded from
// chrome://resources and not chrome://test // chrome://resources and not chrome://test
const base = document.createElement('base'); const base = document.createElement('base');
...@@ -58,7 +60,8 @@ suite('cr-dialog', function() { ...@@ -58,7 +60,8 @@ suite('cr-dialog', function() {
<div slot="body">body</div> <div slot="body">body</div>
</cr-dialog>`; </cr-dialog>`;
const dialog = document.body.querySelector('cr-dialog'); const dialog = /** @type {!CrDialogElement} */ (
document.body.querySelector('cr-dialog'));
const whenFired = test_util.eventToPromise('cr-dialog-open', dialog); const whenFired = test_util.eventToPromise('cr-dialog-open', dialog);
dialog.showModal(); dialog.showModal();
return whenFired; return whenFired;
...@@ -71,7 +74,8 @@ suite('cr-dialog', function() { ...@@ -71,7 +74,8 @@ suite('cr-dialog', function() {
<div slot="body">body</div> <div slot="body">body</div>
</cr-dialog>`; </cr-dialog>`;
const dialog = document.body.querySelector('cr-dialog'); const dialog = /** @type {!CrDialogElement} */ (
document.body.querySelector('cr-dialog'));
dialog.showModal(); dialog.showModal();
const whenFired = test_util.eventToPromise('close', dialog); const whenFired = test_util.eventToPromise('close', dialog);
dialog.close(); dialog.close();
...@@ -112,7 +116,8 @@ suite('cr-dialog', function() { ...@@ -112,7 +116,8 @@ suite('cr-dialog', function() {
<div slot="body">body</div> <div slot="body">body</div>
</cr-dialog>`; </cr-dialog>`;
const dialog = document.body.querySelector('cr-dialog'); const dialog = /** @type {!CrDialogElement} */ (
document.body.querySelector('cr-dialog'));
dialog.showModal(); dialog.showModal();
const whenCancelFired = test_util.eventToPromise('cancel', dialog); const whenCancelFired = test_util.eventToPromise('cancel', dialog);
const whenCloseFired = test_util.eventToPromise('close', dialog); const whenCloseFired = test_util.eventToPromise('close', dialog);
...@@ -154,7 +159,8 @@ suite('cr-dialog', function() { ...@@ -154,7 +159,8 @@ suite('cr-dialog', function() {
<div slot="body"><button>button</button></div> <div slot="body"><button>button</button></div>
</cr-dialog>`; </cr-dialog>`;
const dialog = document.body.querySelector('cr-dialog'); const dialog = /** @type {!CrDialogElement} */ (
document.body.querySelector('cr-dialog'));
const button = document.body.querySelector('button'); const button = document.body.querySelector('button');
assertNotEquals(dialog, document.activeElement); assertNotEquals(dialog, document.activeElement);
...@@ -162,8 +168,8 @@ suite('cr-dialog', function() { ...@@ -162,8 +168,8 @@ suite('cr-dialog', function() {
dialog.showModal(); dialog.showModal();
expectEquals(dialog, document.activeElement); assertEquals(dialog, document.activeElement);
expectNotEquals(button, document.activeElement); assertNotEquals(button, document.activeElement);
}); });
test('enter keys should trigger action buttons once', function() { test('enter keys should trigger action buttons once', function() {
...@@ -176,8 +182,10 @@ suite('cr-dialog', function() { ...@@ -176,8 +182,10 @@ suite('cr-dialog', function() {
</div> </div>
</cr-dialog>`; </cr-dialog>`;
const dialog = document.body.querySelector('cr-dialog'); const dialog = /** @type {!CrDialogElement} */ (
const actionButton = document.body.querySelector('.action-button'); document.body.querySelector('cr-dialog'));
const actionButton = /** @type {!HTMLButtonElement} */ (
document.body.querySelector('.action-button'));
dialog.showModal(); dialog.showModal();
...@@ -187,15 +195,23 @@ suite('cr-dialog', function() { ...@@ -187,15 +195,23 @@ suite('cr-dialog', function() {
clickedCounter++; clickedCounter++;
}); });
/** @param {!HTMLButtonElement} button */
function simulateEnterOnButton(button) {
pressEnter(button);
// Also call manually click() since normally this is done by the browser.
button.click();
}
// Enter key on the action button should only fire the click handler once. // Enter key on the action button should only fire the click handler once.
MockInteractions.tap(actionButton, 'keypress', 13, undefined, 'Enter'); simulateEnterOnButton(actionButton);
assertEquals(1, clickedCounter); assertEquals(1, clickedCounter);
// Enter keys on other buttons should be ignored. // Enter keys on other buttons should be ignored.
clickedCounter = 0; clickedCounter = 0;
const otherButton = document.body.querySelector('#other-button'); const otherButton = /** @type {!HTMLButtonElement} */ (
document.body.querySelector('#other-button'));
assertTrue(!!otherButton); assertTrue(!!otherButton);
pressEnter(otherButton); simulateEnterOnButton(otherButton);
assertEquals(0, clickedCounter); assertEquals(0, clickedCounter);
// Enter keys on the close icon in the top-right corner should be ignored. // Enter keys on the close icon in the top-right corner should be ignored.
...@@ -215,7 +231,8 @@ suite('cr-dialog', function() { ...@@ -215,7 +231,8 @@ suite('cr-dialog', function() {
</div> </div>
</cr-dialog>`; </cr-dialog>`;
const dialog = document.body.querySelector('cr-dialog'); const dialog = /** @type {!CrDialogElement} */ (
document.body.querySelector('cr-dialog'));
const hiddenButton = document.body.querySelector('#hidden'); const hiddenButton = document.body.querySelector('#hidden');
const actionButton = document.body.querySelector('#active'); const actionButton = document.body.querySelector('#active');
dialog.showModal(); dialog.showModal();
...@@ -250,7 +267,8 @@ suite('cr-dialog', function() { ...@@ -250,7 +267,8 @@ suite('cr-dialog', function() {
</div> </div>
</cr-dialog>`; </cr-dialog>`;
const dialog = document.body.querySelector('cr-dialog'); const dialog = /** @type {!CrDialogElement} */ (
document.body.querySelector('cr-dialog'));
const otherElement = document.body.querySelector('foobar'); const otherElement = document.body.querySelector('foobar');
const inputCheckboxElement = const inputCheckboxElement =
...@@ -310,7 +328,8 @@ suite('cr-dialog', function() { ...@@ -310,7 +328,8 @@ suite('cr-dialog', function() {
<div slot="body"><button autofocus>button</button></div> <div slot="body"><button autofocus>button</button></div>
</cr-dialog>`; </cr-dialog>`;
const dialog = document.body.querySelector('cr-dialog'); const dialog = /** @type {!CrDialogElement} */ (
document.body.querySelector('cr-dialog'));
const button = document.body.querySelector('button'); const button = document.body.querySelector('button');
assertNotEquals(dialog, document.activeElement); assertNotEquals(dialog, document.activeElement);
...@@ -318,8 +337,8 @@ suite('cr-dialog', function() { ...@@ -318,8 +337,8 @@ suite('cr-dialog', function() {
dialog.showModal(); dialog.showModal();
expectNotEquals(dialog, document.activeElement); assertNotEquals(dialog, document.activeElement);
expectEquals(button, document.activeElement); assertEquals(button, document.activeElement);
}); });
// Ensuring that intersectionObserver does not fire any callbacks before the // Ensuring that intersectionObserver does not fire any callbacks before the
...@@ -331,7 +350,8 @@ suite('cr-dialog', function() { ...@@ -331,7 +350,8 @@ suite('cr-dialog', function() {
<div slot="body">body</div> <div slot="body">body</div>
</cr-dialog>`; </cr-dialog>`;
const dialog = document.body.querySelector('cr-dialog'); const dialog = /** @type {!CrDialogElement} */ (
document.body.querySelector('cr-dialog'));
assertFalse(dialog.open); assertFalse(dialog.open);
const bodyContainer = dialog.$$('.body-container'); const bodyContainer = dialog.$$('.body-container');
assertTrue(!!bodyContainer); assertTrue(!!bodyContainer);
...@@ -355,7 +375,8 @@ suite('cr-dialog', function() { ...@@ -355,7 +375,8 @@ suite('cr-dialog', function() {
</div> </div>
</cr-dialog>`; </cr-dialog>`;
const dialog = document.body.querySelector('cr-dialog'); const dialog = /** @type {!CrDialogElement} */ (
document.body.querySelector('cr-dialog'));
const bodyContainer = dialog.$$('.body-container'); const bodyContainer = dialog.$$('.body-container');
assertTrue(!!bodyContainer); assertTrue(!!bodyContainer);
const topShadow = dialog.$$('#cr-container-shadow-top'); const topShadow = dialog.$$('#cr-container-shadow-top');
...@@ -409,7 +430,8 @@ suite('cr-dialog', function() { ...@@ -409,7 +430,8 @@ suite('cr-dialog', function() {
<div slot="title">title</div> <div slot="title">title</div>
</cr-dialog>`; </cr-dialog>`;
const dialog = document.body.querySelector('cr-dialog'); const dialog = /** @type {!CrDialogElement} */ (
document.body.querySelector('cr-dialog'));
dialog.showModal(); dialog.showModal();
assertTrue(dialog.open); assertTrue(dialog.open);
...@@ -428,7 +450,8 @@ suite('cr-dialog', function() { ...@@ -428,7 +450,8 @@ suite('cr-dialog', function() {
<div slot="title">title</div> <div slot="title">title</div>
</cr-dialog>`; </cr-dialog>`;
const dialog = document.body.querySelector('cr-dialog'); const dialog = /** @type {!CrDialogElement} */ (
document.body.querySelector('cr-dialog'));
dialog.showModal(); dialog.showModal();
assertTrue(dialog.$.close.hidden); assertTrue(dialog.$.close.hidden);
...@@ -452,7 +475,8 @@ suite('cr-dialog', function() { ...@@ -452,7 +475,8 @@ suite('cr-dialog', function() {
<div slot="title">title</div> <div slot="title">title</div>
</cr-dialog>`; </cr-dialog>`;
const dialog = document.body.querySelector('cr-dialog'); const dialog = /** @type {!CrDialogElement} */ (
document.body.querySelector('cr-dialog'));
dialog.showModal(); dialog.showModal();
assertTrue(dialog.open); assertTrue(dialog.open);
...@@ -468,7 +492,8 @@ suite('cr-dialog', function() { ...@@ -468,7 +492,8 @@ suite('cr-dialog', function() {
<div slot="title">title</div> <div slot="title">title</div>
</cr-dialog>`; </cr-dialog>`;
const dialog = document.body.querySelector('cr-dialog'); const dialog = /** @type {!CrDialogElement} */ (
document.body.querySelector('cr-dialog'));
dialog.showModal(); dialog.showModal();
assertTrue(dialog.$.close.hidden); assertTrue(dialog.$.close.hidden);
...@@ -481,7 +506,8 @@ suite('cr-dialog', function() { ...@@ -481,7 +506,8 @@ suite('cr-dialog', function() {
<div slot="title">title</div> <div slot="title">title</div>
</cr-dialog>`; </cr-dialog>`;
const dialog = document.body.querySelector('cr-dialog'); const dialog = /** @type {!CrDialogElement} */ (
document.body.querySelector('cr-dialog'));
dialog.showModal(); dialog.showModal();
assertTrue(dialog.open); assertTrue(dialog.open);
assertTrue(dialog.consumeKeydownEvent); assertTrue(dialog.consumeKeydownEvent);
...@@ -504,7 +530,8 @@ suite('cr-dialog', function() { ...@@ -504,7 +530,8 @@ suite('cr-dialog', function() {
<div slot="title">title</div> <div slot="title">title</div>
</cr-dialog>`; </cr-dialog>`;
const dialog = document.body.querySelector('cr-dialog'); const dialog = /** @type {!CrDialogElement} */ (
document.body.querySelector('cr-dialog'));
dialog.showModal(); dialog.showModal();
assertTrue(dialog.open); assertTrue(dialog.open);
assertFalse(dialog.consumeKeydownEvent); assertFalse(dialog.consumeKeydownEvent);
...@@ -527,7 +554,8 @@ suite('cr-dialog', function() { ...@@ -527,7 +554,8 @@ suite('cr-dialog', function() {
<cr-dialog show-on-attach> <cr-dialog show-on-attach>
<div slot="title">title</div> <div slot="title">title</div>
</cr-dialog>`; </cr-dialog>`;
const dialog = document.body.querySelector('cr-dialog'); const dialog = /** @type {!CrDialogElement} */ (
document.body.querySelector('cr-dialog'));
assertTrue(dialog.open); assertTrue(dialog.open);
}); });
}); });
...@@ -44,7 +44,7 @@ cr.define('test_util', function() { ...@@ -44,7 +44,7 @@ cr.define('test_util', function() {
/** /**
* Converts an event occurrence to a promise. * Converts an event occurrence to a promise.
* @param {string} eventType * @param {string} eventType
* @param {Element|EventTarget} target * @param {!Element|!EventTarget|!Window} target
* @return {!Promise} A promise firing once the event occurs. * @return {!Promise} A promise firing once the event occurs.
*/ */
/* #export */ function eventToPromise(eventType, target) { /* #export */ function eventToPromise(eventType, target) {
......
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