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

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: fix test 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..219bdadd67c07dc78a34df5e7814d5b4fe1e0fef 100644
--- a/chrome/test/data/webui/cr_elements/cr_dialog_test.js
+++ b/chrome/test/data/webui/cr_elements/cr_dialog_test.js
@@ -90,6 +90,41 @@ suite('cr-dialog', function() {
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 += 1;
dpapad 2017/04/05 21:34:45 Nit (optional): clickedCounter++;
tommycli 2017/04/05 21:42:48 Done.
+ });
+
+ MockInteractions.keyEventOn(
+ otherElement, 'keypress', 13, undefined, 'Enter');
dpapad 2017/04/05 21:34:45 Nit (optional): Can we make a helper function pre
tommycli 2017/04/05 21:42:48 Done.
+ assertEquals(0, clickedCounter);
+
+ MockInteractions.keyEventOn(
+ inputElement, '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