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

Side by Side Diff: chrome/test/data/webui/settings/settings_action_menu_test.js

Issue 2402553002: MD Settings: Implementing modal popup/action menus. (Closed)
Patch Set: Fix test breakage caused by compiler suppress hack. Created 4 years, 2 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
(Empty)
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
3 // found in the LICENSE file.
4
5 /** @fileoverview Tests for settings-action-menu element. */
6 suite('SettingsActionMenu', function() {
7 var menu = null;
8 var buttons = null;
Dan Beam 2016/10/14 03:51:13 nit: @types if you can
dpapad 2016/10/14 17:39:23 Done.
9
10 setup(function() {
11 PolymerTest.clearBody();
12
13 document.body.innerHTML = `
14 <button id='dots'>...</button>
Dan Beam 2016/10/14 03:51:13 nit: use " instead of '
15 <dialog is='settings-action-menu'>
16 <button class='dropdown-item'>Un</button>
17 <button class='dropdown-item'>Dos</button>
18 <button class='dropdown-item'>Tres</button>
19 </dialog>
20 `;
21
22 menu = document.querySelector('dialog[is=settings-action-menu]');
23 buttons = menu.querySelectorAll('button');
Dan Beam 2016/10/14 03:51:13 arguable nit: use .dropdown-item / items instead
dpapad 2016/10/14 17:39:23 Done.
24 assertEquals(3, buttons.length);
25 });
26
27 teardown(function() {
28 if (menu.open)
29 menu.close();
30 });
31
32 test('focus after showing', function() {
33 menu.showAt(document.querySelector('#dots'));
34 assertEquals(buttons[0], menu.root.activeElement);
35 assertEquals(buttons[0], menu.querySelector('[autofocus]'));
Dan Beam 2016/10/14 03:51:13 do you want to check that this is the only [autofo
dpapad 2016/10/14 17:39:23 Done, good idea.
36
37 menu.close();
38 buttons[0].hidden = true;
39 menu.showAt(document.querySelector('#dots'));
40 assertEquals(buttons[1], menu.root.activeElement);
41 assertEquals(buttons[1], menu.querySelector('[autofocus]'));
42
43 menu.close();
44 buttons[1].hidden = true;
45 menu.showAt(document.querySelector('#dots'));
46 assertEquals(buttons[2], menu.root.activeElement);
47 assertEquals(buttons[2], menu.querySelector('[autofocus]'));
48
49 menu.close();
50 buttons[2].disabled = true;
51 menu.showAt(document.querySelector('#dots'));
52 assertEquals(null, menu.root.activeElement);
53 assertEquals(null, menu.querySelector('[autofocus]'));
54 });
55
56 test('focus after down/up arrow', function() {
57 function down() {
58 MockInteractions.keyDownOn(menu, 'ArrowDown', [], 'ArrowDown');
59 }
60
61 function up() {
62 MockInteractions.keyDownOn(menu, 'ArrowUp', [], 'ArrowUp');
63 }
64
65 menu.showAt(document.querySelector('#dots'));
66 assertEquals(buttons[0], menu.root.activeElement);
67
68 down();
69 assertEquals(buttons[1], menu.root.activeElement);
70 down();
71 assertEquals(buttons[2], menu.root.activeElement);
72 down();
73 assertEquals(buttons[0], menu.root.activeElement);
74 up();
75 assertEquals(buttons[2], menu.root.activeElement);
76 up();
77 assertEquals(buttons[1], menu.root.activeElement);
78 up();
79 assertEquals(buttons[0], menu.root.activeElement);
80 up();
81 assertEquals(buttons[2], menu.root.activeElement);
82
83 buttons[1].disabled = true;
84 up();
85 assertEquals(buttons[0], menu.root.activeElement);
86 });
87
88 test('close on resize', function() {
89 menu.showAt(document.querySelector('#dots'));
90 assertTrue(menu.open);
91
92 window.dispatchEvent(new CustomEvent('resize'));
93 assertFalse(menu.open);
94 });
95
96 test('close on Tab', function() {
97 menu.showAt(document.querySelector('#dots'));
98 assertTrue(menu.open);
99
100 MockInteractions.keyDownOn(menu, 'Tab', [], 'Tab');
101 assertFalse(menu.open);
102 });
103 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698