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

Side by Side Diff: chrome/test/data/webui/cr_elements/cr_dialog_test.js

Issue 2884113002: WebUI: Stop keypresses on the close icon from firing the Enter handler. (Closed)
Patch Set: update tests Created 3 years, 7 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 unified diff | Download patch
« no previous file with comments | « no previous file | ui/webui/resources/cr_elements/cr_dialog/cr_dialog.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 break; 216 break;
213 } 217 }
214 }); 218 });
215 observer.observe(bodyContainer, {attributes: true}); 219 observer.observe(bodyContainer, {attributes: true});
216 220
217 // Height is normally set via CSS, but mixin doesn't work with innerHTML. 221 // Height is normally set via CSS, but mixin doesn't work with innerHTML.
218 bodyContainer.style.height = '60px'; // Element has "min-height: 60px". 222 bodyContainer.style.height = '60px'; // Element has "min-height: 60px".
219 bodyContainer.scrollTop = 100; 223 bodyContainer.scrollTop = 100;
220 }); 224 });
221 }); 225 });
OLDNEW
« no previous file with comments | « no previous file | ui/webui/resources/cr_elements/cr_dialog/cr_dialog.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698