| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 suite('cr-dialog', function() { | 5 suite('cr-dialog', function() { |
| 6 function pressEnter(element) { | 6 function pressEnter(element) { |
| 7 MockInteractions.keyEventOn(element, 'keypress', 13, undefined, 'Enter'); | 7 MockInteractions.keyEventOn(element, 'keypress', 13, undefined, 'Enter'); |
| 8 } | 8 } |
| 9 | 9 |
| 10 setup(function() { | 10 setup(function() { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 var actionButton = document.body.querySelector('.action-button'); | 44 var actionButton = document.body.querySelector('.action-button'); |
| 45 | 45 |
| 46 dialog.showModal(); | 46 dialog.showModal(); |
| 47 | 47 |
| 48 // MockInteractions triggers event listeners synchronously. | 48 // MockInteractions triggers event listeners synchronously. |
| 49 var clickedCounter = 0; | 49 var clickedCounter = 0; |
| 50 actionButton.addEventListener('click', function() { | 50 actionButton.addEventListener('click', function() { |
| 51 clickedCounter++; | 51 clickedCounter++; |
| 52 }); | 52 }); |
| 53 | 53 |
| 54 // Enter key on the action button should only fire the click handler once. |
| 55 MockInteractions.tap(actionButton, 'keypress', 13, undefined, 'Enter'); |
| 56 assertEquals(1, clickedCounter); |
| 57 |
| 54 // Enter keys on other buttons should be ignored. | 58 // Enter keys on other buttons should be ignored. |
| 55 clickedCounter = 0; | 59 clickedCounter = 0; |
| 56 var otherButton = document.body.querySelector('#other-button'); | 60 var otherButton = document.body.querySelector('#other-button'); |
| 57 assertTrue(!!otherButton); | 61 assertTrue(!!otherButton); |
| 58 pressEnter(otherButton); | 62 pressEnter(otherButton); |
| 59 assertEquals(0, clickedCounter); | 63 assertEquals(0, clickedCounter); |
| 60 | 64 |
| 61 // Enter key on the action button should only fire the click handler once. | 65 // Enter keys on the close icon in the top-right corner should be ignored. |
| 62 MockInteractions.tap(actionButton, 'keypress', 13, undefined, 'Enter'); | 66 pressEnter(dialog.getCloseButton()); |
| 63 assertEquals(1, clickedCounter); | 67 assertEquals(0, clickedCounter); |
| 64 }); | 68 }); |
| 65 | 69 |
| 66 test('enter keys find the first non-hidden non-disabled button', function() { | 70 test('enter keys find the first non-hidden non-disabled button', function() { |
| 67 document.body.innerHTML = ` | 71 document.body.innerHTML = ` |
| 68 <dialog is="cr-dialog"> | 72 <dialog is="cr-dialog"> |
| 69 <div class="title">title</div> | 73 <div class="title">title</div> |
| 70 <div class="body"> | 74 <div class="body"> |
| 71 <button id="hidden" class="action-button" hidden>hidden</button> | 75 <button id="hidden" class="action-button" hidden>hidden</button> |
| 72 <button class="action-button" disabled>disabled</button> | 76 <button class="action-button" disabled>disabled</button> |
| 73 <button class="action-button" disabled hidden>disabled hidden</button> | 77 <button class="action-button" disabled hidden>disabled hidden</button> |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 break; | 214 break; |
| 211 } | 215 } |
| 212 }); | 216 }); |
| 213 observer.observe(bodyContainer, {attributes: true}); | 217 observer.observe(bodyContainer, {attributes: true}); |
| 214 | 218 |
| 215 // Height is normally set via CSS, but mixin doesn't work with innerHTML. | 219 // Height is normally set via CSS, but mixin doesn't work with innerHTML. |
| 216 bodyContainer.style.height = '1px'; | 220 bodyContainer.style.height = '1px'; |
| 217 bodyContainer.scrollTop = 100; | 221 bodyContainer.scrollTop = 100; |
| 218 }); | 222 }); |
| 219 }); | 223 }); |
| OLD | NEW |