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

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: merge 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
« no previous file with comments | « no previous file | ui/webui/resources/cr_elements/cr_action_menu/cr_action_menu.js » ('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 /** 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'));
98 assertEquals(menu, document.activeElement);
99
100 up();
101 assertEquals(items[items.length - 1], menu.root.activeElement);
102 });
103
96 test('close on resize', function() { 104 test('close on resize', function() {
97 menu.showAt(document.querySelector('#dots')); 105 menu.showAt(document.querySelector('#dots'));
98 assertTrue(menu.open); 106 assertTrue(menu.open);
99 107
100 window.dispatchEvent(new CustomEvent('resize')); 108 window.dispatchEvent(new CustomEvent('resize'));
101 assertFalse(menu.open); 109 assertFalse(menu.open);
102 }); 110 });
103 111
104 test('close on popstate', function() { 112 test('close on popstate', function() {
105 menu.showAt(document.querySelector('#dots')); 113 menu.showAt(document.querySelector('#dots'));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 assertEquals(menu, document.activeElement); 155 assertEquals(menu, document.activeElement);
148 156
149 // Mouse movements should override keyboard focus. 157 // Mouse movements should override keyboard focus.
150 down(); 158 down();
151 down(); 159 down();
152 assertEquals(items[1], menu.root.activeElement); 160 assertEquals(items[1], menu.root.activeElement);
153 makeMouseoverEvent(items[0]); 161 makeMouseoverEvent(items[0]);
154 assertEquals(items[0], menu.root.activeElement); 162 assertEquals(items[0], menu.root.activeElement);
155 }); 163 });
156 }); 164 });
OLDNEW
« no previous file with comments | « no previous file | ui/webui/resources/cr_elements/cr_action_menu/cr_action_menu.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698