Chromium Code Reviews| 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"> |