Chromium Code Reviews| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 clickedCounter++; | 51 clickedCounter++; |
| 52 }); | 52 }); |
| 53 | 53 |
| 54 // Enter keys on other buttons should be ignored. | 54 // Enter keys on other buttons should be ignored. |
| 55 clickedCounter = 0; | 55 clickedCounter = 0; |
| 56 var otherButton = document.body.querySelector('#other-button'); | 56 var otherButton = document.body.querySelector('#other-button'); |
| 57 assertTrue(!!otherButton); | 57 assertTrue(!!otherButton); |
| 58 pressEnter(otherButton); | 58 pressEnter(otherButton); |
| 59 assertEquals(0, clickedCounter); | 59 assertEquals(0, clickedCounter); |
| 60 | 60 |
| 61 // Enter keys on the close icon in the top-right corner should be ignored. | |
| 62 var closeButton = document.body.querySelector('* /deep/ #close'); | |
|
dpapad
2017/05/15 23:38:56
Can we use dialog.getCloseButton() instead? See ht
tommycli
2017/05/15 23:43:04
Done.
| |
| 63 assertTrue(!!closeButton); | |
| 64 pressEnter(closeButton); | |
| 65 assertEquals(0, clickedCounter); | |
| 66 | |
| 61 // Enter key on the action button should only fire the click handler once. | 67 // Enter key on the action button should only fire the click handler once. |
| 62 MockInteractions.tap(actionButton, 'keypress', 13, undefined, 'Enter'); | 68 MockInteractions.tap(actionButton, 'keypress', 13, undefined, 'Enter'); |
|
dpapad
2017/05/15 23:38:56
Is the dialog closed (because of the code added ab
tommycli
2017/05/15 23:43:04
I reordered the tests just to be safe.
| |
| 63 assertEquals(1, clickedCounter); | 69 assertEquals(1, clickedCounter); |
| 64 }); | 70 }); |
| 65 | 71 |
| 66 test('enter keys find the first non-hidden non-disabled button', function() { | 72 test('enter keys find the first non-hidden non-disabled button', function() { |
| 67 document.body.innerHTML = ` | 73 document.body.innerHTML = ` |
| 68 <dialog is="cr-dialog"> | 74 <dialog is="cr-dialog"> |
| 69 <div class="title">title</div> | 75 <div class="title">title</div> |
| 70 <div class="body"> | 76 <div class="body"> |
| 71 <button id="hidden" class="action-button" hidden>hidden</button> | 77 <button id="hidden" class="action-button" hidden>hidden</button> |
| 72 <button class="action-button" disabled>disabled</button> | 78 <button class="action-button" disabled>disabled</button> |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 break; | 218 break; |
| 213 } | 219 } |
| 214 }); | 220 }); |
| 215 observer.observe(bodyContainer, {attributes: true}); | 221 observer.observe(bodyContainer, {attributes: true}); |
| 216 | 222 |
| 217 // Height is normally set via CSS, but mixin doesn't work with innerHTML. | 223 // Height is normally set via CSS, but mixin doesn't work with innerHTML. |
| 218 bodyContainer.style.height = '60px'; // Element has "min-height: 60px". | 224 bodyContainer.style.height = '60px'; // Element has "min-height: 60px". |
| 219 bodyContainer.scrollTop = 100; | 225 bodyContainer.scrollTop = 100; |
| 220 }); | 226 }); |
| 221 }); | 227 }); |
| OLD | NEW |