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

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

Issue 2803543003: WebUI: fix cr-action-menu keyboard off-by-one issue (Closed)
Patch Set: add test Created 3 years, 8 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
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 /** 5 /**
6 * @fileoverview Tests for cr-action-menu element. Runs as an interactive UI 6 * @fileoverview Tests for cr-action-menu element. Runs as an interactive UI
7 * test, since many of these tests check focus behavior. 7 * test, since many of these tests check focus behavior.
8 */ 8 */
9 suite('CrActionMenu', function() { 9 suite('CrActionMenu', function() {
10 /** @type {?CrActionMenuElement} */ 10 /** @type {?CrActionMenuElement} */
(...skipping 22 matching lines...) Expand all
33 33
34 teardown(function() { 34 teardown(function() {
35 if (menu.open) 35 if (menu.open)
36 menu.close(); 36 menu.close();
37 }); 37 });
38 38
39 function down() { 39 function down() {
40 MockInteractions.keyDownOn(menu, 'ArrowDown', [], 'ArrowDown'); 40 MockInteractions.keyDownOn(menu, 'ArrowDown', [], 'ArrowDown');
41 } 41 }
42 42
43 function up() {
44 MockInteractions.keyDownOn(menu, 'ArrowUp', [], 'ArrowUp');
45 }
46
43 test('hidden or disabled items', function() { 47 test('hidden or disabled items', function() {
44 menu.showAt(document.querySelector('#dots')); 48 menu.showAt(document.querySelector('#dots'));
45 down(); 49 down();
46 assertEquals(menu.root.activeElement, items[0]); 50 assertEquals(menu.root.activeElement, items[0]);
47 51
48 menu.close(); 52 menu.close();
49 items[0].hidden = true; 53 items[0].hidden = true;
50 menu.showAt(document.querySelector('#dots')); 54 menu.showAt(document.querySelector('#dots'));
51 down(); 55 down();
52 assertEquals(menu.root.activeElement, items[1]); 56 assertEquals(menu.root.activeElement, items[1]);
53 57
54 menu.close(); 58 menu.close();
55 items[1].disabled = true; 59 items[1].disabled = true;
56 menu.showAt(document.querySelector('#dots')); 60 menu.showAt(document.querySelector('#dots'));
57 down(); 61 down();
58 assertEquals(menu.root.activeElement, items[2]); 62 assertEquals(menu.root.activeElement, items[2]);
59 }); 63 });
60 64
61 test('focus after down/up arrow', function() { 65 test('focus after down/up arrow', function() {
62 function up() {
63 MockInteractions.keyDownOn(menu, 'ArrowUp', [], 'ArrowUp');
64 }
65
66 menu.showAt(document.querySelector('#dots')); 66 menu.showAt(document.querySelector('#dots'));
67 67
68 // The menu should be focused when shown, but not on any of the items. 68 // The menu should be focused when shown, but not on any of the items.
69 assertEquals(menu, document.activeElement); 69 assertEquals(menu, document.activeElement);
70 assertNotEquals(items[0], menu.root.activeElement); 70 assertNotEquals(items[0], menu.root.activeElement);
71 assertNotEquals(items[1], menu.root.activeElement); 71 assertNotEquals(items[1], menu.root.activeElement);
72 assertNotEquals(items[2], menu.root.activeElement); 72 assertNotEquals(items[2], menu.root.activeElement);
73 73
74 down(); 74 down();
75 assertEquals(items[0], menu.root.activeElement); 75 assertEquals(items[0], menu.root.activeElement);
(...skipping 10 matching lines...) Expand all
86 up(); 86 up();
87 assertEquals(items[0], menu.root.activeElement); 87 assertEquals(items[0], menu.root.activeElement);
88 up(); 88 up();
89 assertEquals(items[2], menu.root.activeElement); 89 assertEquals(items[2], menu.root.activeElement);
90 90
91 items[1].disabled = true; 91 items[1].disabled = true;
92 up(); 92 up();
93 assertEquals(items[0], menu.root.activeElement); 93 assertEquals(items[0], menu.root.activeElement);
94 }); 94 });
95 95
96 test('pressing up arrow when no focus will focus last item', function(){
97 menu.showAt(document.querySelector('#dots'));
dpapad 2017/04/05 21:49:13 assertEquals(menu, document.activeElement);
scottchen 2017/04/06 17:54:02 Done.
98
99 up();
100 assertEquals(items[2], menu.root.activeElement);
dpapad 2017/04/05 21:49:13 Nit (optional): Make it more explicit that we expe
scottchen 2017/04/06 17:54:02 Done.
101 });
102
96 test('close on resize', function() { 103 test('close on resize', function() {
97 menu.showAt(document.querySelector('#dots')); 104 menu.showAt(document.querySelector('#dots'));
98 assertTrue(menu.open); 105 assertTrue(menu.open);
99 106
100 window.dispatchEvent(new CustomEvent('resize')); 107 window.dispatchEvent(new CustomEvent('resize'));
101 assertFalse(menu.open); 108 assertFalse(menu.open);
102 }); 109 });
103 110
104 test('close on popstate', function() { 111 test('close on popstate', function() {
105 menu.showAt(document.querySelector('#dots')); 112 menu.showAt(document.querySelector('#dots'));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 assertEquals(menu, document.activeElement); 154 assertEquals(menu, document.activeElement);
148 155
149 // Mouse movements should override keyboard focus 156 // Mouse movements should override keyboard focus
150 down(); 157 down();
151 down(); 158 down();
152 assertEquals(items[1], menu.root.activeElement); 159 assertEquals(items[1], menu.root.activeElement);
153 makeMouseoverEvent(items[0]); 160 makeMouseoverEvent(items[0]);
154 assertEquals(items[0], menu.root.activeElement); 161 assertEquals(items[0], menu.root.activeElement);
155 }); 162 });
156 }); 163 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698