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

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: change closure annotations 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..062211dab7a69851e671a22d5af59beb846ca37f 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,49 @@ 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 clickedCounter = 0;
+ actionButton.addEventListener('click', function() {
+ clickedCounter += 1;
+ });
+
+ // Enter key should ignore disabled buttons.
+ MockInteractions.keyEventOn(dialog, 'keypress', 13, undefined, 'Enter');
+ assertEquals(0, clickedCounter);
+
+ // Enter key should trigger enabled buttons.
+ actionButton.disabled = false;
+ MockInteractions.keyEventOn(dialog, 'keypress', 13, undefined, 'Enter');
+ assertEquals(1, clickedCounter);
+
+ // Enter keys on other buttons should be ignored.
+ clickedCounter = 0;
+ var otherButton = document.body.querySelector('#other-button');
+ assertTrue(!!otherButton);
+ MockInteractions.keyEventOn(
+ otherButton, 'keypress', 13, undefined, 'Enter');
+ assertEquals(0, clickedCounter);
+
+ // Enter key on the action button should only fire the click handler once.
+ MockInteractions.tap(actionButton, 'keypress', 13, undefined, 'Enter');
+ assertEquals(1, clickedCounter);
+ });
+
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