Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7314)

Unified Diff: chrome/test/data/webui/cr_elements/cr_dialog_test.js

Issue 2788673003: WebUI: For cr-dialog, make Enter click the action-button, if it exists. (Closed)
Patch Set: add test Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/webui/cr_elements/cr_dialog_test.js
diff --git a/chrome/test/data/webui/cr_elements/cr_dialog_test.js b/chrome/test/data/webui/cr_elements/cr_dialog_test.js
index 7cd767e59c7bf61bbd7bdd2180f35ad6371a3b3b..93da5da31f8e38963e118ee141e5b03f4ebd9f06 100644
--- a/chrome/test/data/webui/cr_elements/cr_dialog_test.js
+++ b/chrome/test/data/webui/cr_elements/cr_dialog_test.js
@@ -26,6 +26,47 @@ suite('cr-dialog', function() {
expectNotEquals(button, document.activeElement);
});
+ test('enter key clicks action button', function() {
+ document.body.innerHTML = `
+ <dialog is="cr-dialog">
+ <div class="title">title</div>
+ <div class="body">
+ <button class="action-button" disabled>button</button>
+ <button id="other-button">other button</button>
+ </div>
+ </dialog>`;
+
+ var dialog = document.body.querySelector('dialog');
+ var actionButton = document.body.querySelector('.action-button');
+
+ dialog.showModal();
+
+ // MockInteractions triggers event listeners synchronously.
+ var clicked = false;
+ actionButton.addEventListener('click', function() {
+ clicked = true;
+ });
+
+ // Enter key should ignore disabled buttons.
+ MockInteractions.keyEventOn(
+ dialog, 'keypress', 13, undefined, 'Enter');
dpapad 2017/04/03 19:30:24 Nit: Indent off by 2
tommycli 2017/04/03 22:57:55 Done. I ran git cl format --js.
+ assertFalse(clicked);
+
+ // Enter key should trigger enabled buttons.
+ actionButton.disabled = false;
+ MockInteractions.keyEventOn(
+ dialog, 'keypress', 13, undefined, 'Enter');
dpapad 2017/04/03 19:30:24 Nit: Indent off by 2
tommycli 2017/04/03 22:57:55 Done. Ran git cl format --js.
+ assertTrue(clicked);
+
+ // Enter keys on other buttons should be ignored.
+ clicked = false;
+ var otherButton = document.body.querySelector('#other-button');
+ assertTrue(!!otherButton);
+ MockInteractions.keyEventOn(
+ otherButton, 'keypress', 13, undefined, 'Enter');
dpapad 2017/04/03 19:30:24 Nit: Indent off by 2
tommycli 2017/04/03 22:57:55 Done.
+ assertFalse(clicked);
+ });
dpapad 2017/04/03 19:30:24 Optional suggestion for one more test case. - Ch
tommycli 2017/04/03 22:57:55 Done.
+
test('focuses [autofocus] instead of title when present', function() {
document.body.innerHTML = `
<dialog is="cr-dialog">

Powered by Google App Engine
This is Rietveld 408576698