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

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

Issue 2795353002: WebUI: For cr-dialog, handle Enter keys in paper-inputs. (Closed)
Patch Set: update tests Created 3 years, 8 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 5e1f0ef3f52539ab242275b5a26a65c8dfb53c76..8bac6f9066e1796fc741550859420bbdbb5663ef 100644
--- a/chrome/test/data/webui/cr_elements/cr_dialog_test.js
+++ b/chrome/test/data/webui/cr_elements/cr_dialog_test.js
@@ -3,6 +3,10 @@
// found in the LICENSE file.
suite('cr-dialog', function() {
+ function pressEnter(element) {
+ MockInteractions.keyEventOn(element, 'keypress', 13, undefined, 'Enter');
+ }
+
setup(function() {
PolymerTest.clearBody();
});
@@ -44,15 +48,14 @@ suite('cr-dialog', function() {
// MockInteractions triggers event listeners synchronously.
var clickedCounter = 0;
actionButton.addEventListener('click', function() {
- clickedCounter += 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');
+ pressEnter(otherButton);
assertEquals(0, clickedCounter);
// Enter key on the action button should only fire the click handler once.
@@ -86,10 +89,43 @@ suite('cr-dialog', function() {
clicked = true;
});
- MockInteractions.keyEventOn(dialog, 'keypress', 13, undefined, 'Enter');
+ pressEnter(dialog);
assertTrue(clicked);
});
+ test('enter keys from paper-inputs (only) are processed', function() {
+ document.body.innerHTML = `
+ <dialog is="cr-dialog">
+ <div class="title">title</div>
+ <div class="body">
+ <paper-input></paper-input>
+ <foobar></foobar>
+ <button class="action-button">active</button>
+ </div>
+ </dialog>`;
+
+ var dialog = document.body.querySelector('dialog');
+
+ var inputElement = document.body.querySelector('paper-input');
+ var otherElement = document.body.querySelector('foobar');
+ var actionButton = document.body.querySelector('.action-button');
+ assertTrue(!!inputElement);
+ assertTrue(!!otherElement);
+ assertTrue(!!actionButton);
+
+ // MockInteractions triggers event listeners synchronously.
+ var clickedCounter = 0;
+ actionButton.addEventListener('click', function() {
+ clickedCounter++;
+ });
+
+ pressEnter(otherElement);
+ assertEquals(0, clickedCounter);
+
+ pressEnter(inputElement);
+ 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