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

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: add a test 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 });
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