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

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

Issue 2755213002: MD WebUI: fix action menu initial focus to be more like context menus (Closed)
Patch Set: fix tests Created 3 years, 9 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.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 /** 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 18 matching lines...) Expand all
29 menu = document.querySelector('dialog[is=cr-action-menu]'); 29 menu = document.querySelector('dialog[is=cr-action-menu]');
30 items = menu.querySelectorAll('.dropdown-item'); 30 items = menu.querySelectorAll('.dropdown-item');
31 assertEquals(3, items.length); 31 assertEquals(3, items.length);
32 }); 32 });
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 test('focus after showing', function() { 39 function down() {
40 MockInteractions.keyDownOn(menu, 'ArrowDown', [], 'ArrowDown');
41 }
42
43 test('hidden or disabled items', function() {
40 menu.showAt(document.querySelector('#dots')); 44 menu.showAt(document.querySelector('#dots'));
45 down();
41 assertEquals(menu.root.activeElement, items[0]); 46 assertEquals(menu.root.activeElement, items[0]);
42 47
43 menu.close(); 48 menu.close();
44 items[0].hidden = true; 49 items[0].hidden = true;
45 menu.showAt(document.querySelector('#dots')); 50 menu.showAt(document.querySelector('#dots'));
51 down();
46 assertEquals(menu.root.activeElement, items[1]); 52 assertEquals(menu.root.activeElement, items[1]);
47 53
48 menu.close(); 54 menu.close();
49 items[1].hidden = true; 55 items[1].disabled = true;
50 menu.showAt(document.querySelector('#dots')); 56 menu.showAt(document.querySelector('#dots'));
57 down();
51 assertEquals(menu.root.activeElement, items[2]); 58 assertEquals(menu.root.activeElement, items[2]);
52
53 menu.close();
54 items[2].disabled = true;
55 menu.showAt(document.querySelector('#dots'));
56 assertEquals(null, menu.root.activeElement);
57 }); 59 });
58 60
59 test('focus after down/up arrow', function() { 61 test('focus after down/up arrow', function() {
60 function down() {
61 MockInteractions.keyDownOn(menu, 'ArrowDown', [], 'ArrowDown');
62 }
63
64 function up() { 62 function up() {
65 MockInteractions.keyDownOn(menu, 'ArrowUp', [], 'ArrowUp'); 63 MockInteractions.keyDownOn(menu, 'ArrowUp', [], 'ArrowUp');
66 } 64 }
67 65
68 menu.showAt(document.querySelector('#dots')); 66 menu.showAt(document.querySelector('#dots'));
67
68 // The menu should be focused when shown, but not on any of the items.
69 assertEquals(menu, document.activeElement);
70 assertNotEquals(items[0], menu.root.activeElement);
dpapad 2017/03/18 01:03:05 Optional nit: What is the value of menu.root.activ
Dan Beam 2017/03/18 17:55:06 it's not null, it's a wrapper in the shadow DOM an
71 assertNotEquals(items[1], menu.root.activeElement);
72 assertNotEquals(items[2], menu.root.activeElement);
73
74 down();
69 assertEquals(items[0], menu.root.activeElement); 75 assertEquals(items[0], menu.root.activeElement);
70
71 down(); 76 down();
72 assertEquals(items[1], menu.root.activeElement); 77 assertEquals(items[1], menu.root.activeElement);
73 down(); 78 down();
74 assertEquals(items[2], menu.root.activeElement); 79 assertEquals(items[2], menu.root.activeElement);
75 down(); 80 down();
76 assertEquals(items[0], menu.root.activeElement); 81 assertEquals(items[0], menu.root.activeElement);
77 up(); 82 up();
78 assertEquals(items[2], menu.root.activeElement); 83 assertEquals(items[2], menu.root.activeElement);
79 up(); 84 up();
80 assertEquals(items[1], menu.root.activeElement); 85 assertEquals(items[1], menu.root.activeElement);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 MockInteractions.keyDownOn(menu, key, [], key); 121 MockInteractions.keyDownOn(menu, key, [], key);
117 assertFalse(menu.open); 122 assertFalse(menu.open);
118 }); 123 });
119 } 124 }
120 125
121 test('close on Tab', function() { return testFocusAfterClosing('Tab'); }); 126 test('close on Tab', function() { return testFocusAfterClosing('Tab'); });
122 test('close on Escape', function() { 127 test('close on Escape', function() {
123 return testFocusAfterClosing('Escape'); 128 return testFocusAfterClosing('Escape');
124 }); 129 });
125 }); 130 });
OLDNEW
« no previous file with comments | « no previous file | ui/webui/resources/cr_elements/cr_action_menu/cr_action_menu.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698