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

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

Issue 2104013004: MD WebUI: Reimplement cr-shared-menu using iron-dropdown. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address dbeam@ review Created 4 years, 5 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 Suite of tests for cr-shared-menu. */
6 suite('cr-shared-menu', function() {
7 var menu;
8
9 var button;
10
11 var item1;
12 var item2;
13 var item3;
14
15 function afterOpen(callback) {
16 menu.addEventListener('iron-overlay-opened', callback);
Dan Beam 2016/07/12 02:11:38 nit: menu.addEventListener('iron-overlay-opened',
tsergeant 2016/07/13 04:44:36 Done.
17 }
18
19 suiteSetup(function() {
20 return PolymerTest.importHtml(
21 'chrome://resources/polymer/v1_0/paper-item/paper-item.html');
22 });
23
24 setup(function() {
25 PolymerTest.clearBody();
26 // Basic wiring to set up a menu which opens when a button is pressed.
27 menu = document.createElement('cr-shared-menu');
28 menu.$$('#dropdown').noAnimations = true;
29
30 item1 = document.createElement('paper-item');
31 menu.appendChild(item1);
32 item2 = document.createElement('paper-item');
33 menu.appendChild(item2);
34 item3 = document.createElement('paper-item');
35 menu.appendChild(item3);
36
37 button = document.createElement('button');
38 button.addEventListener('tap', function() {
39 menu.toggleMenu(button, {});
40 });
41
42 document.body.appendChild(menu);
43 document.body.appendChild(button);
44 });
45
46 test('opening and closing menu', function(done) {
47 MockInteractions.tap(button);
48 assertTrue(menu.menuOpen);
49
50 afterOpen(function() {
51 // Using tap to close the menu requires that the iron-overlay-behavior
52 // has finished initializing, which happens asynchronously between
53 // tapping the button and firing iron-overlay-opened.
54 MockInteractions.tap(document.body);
55 assertFalse(menu.menuOpen);
56
57 MockInteractions.tap(button);
58 assertTrue(menu.menuOpen);
59
60 // Pressing escape should close the menu.
61 MockInteractions.pressAndReleaseKeyOn(menu, 27);
62 assertTrue(menu.menuOpen);
63 done();
64 });
65 });
66
67 test('refocus button on close', function(done) {
68 button.focus();
69 MockInteractions.tap(button);
70
71 afterOpen(function() {
72 assertTrue(menu.menuOpen);
73 // Focus is applied asynchronously after the menu is opened.
74 assertEquals(item1, menu.shadowRoot.activeElement);
75
76 menu.closeMenu();
77 assertFalse(menu.menuOpen);
78
79 // Button should regain focus after closing the menu.
80 assertEquals(button, document.activeElement);
81
82 done();
83 });
84 });
85
86 test('closeMenu does not refocus button when focus moves', function(done) {
87 var input = document.createElement('input');
88 document.body.appendChild(input);
89
90 button.focus();
91 MockInteractions.tap(button);
92
93 afterOpen(function() {
94 input.focus();
95 menu.closeMenu();
96 assertEquals(input, document.activeElement);
97
98 done();
99 });
100 });
101
102 test('focus is trapped inside the menu', function(done) {
103 button.focus();
104 MockInteractions.tap(button);
105
106 afterOpen(function() {
107 // Simulate shift-tab on first element.
108 assertEquals(item1, menu.shadowRoot.activeElement);
109 MockInteractions.pressAndReleaseKeyOn(item1, 9, ['shift']);
110 assertEquals(item3, menu.shadowRoot.activeElement);
111
112 // Simulate tab on last element.
113 MockInteractions.pressAndReleaseKeyOn(item3, 9);
114 assertEquals(item1, menu.shadowRoot.activeElement);
115
116 done();
117 });
118 });
119
Dan Beam 2016/07/12 02:11:38 nit: remove
tsergeant 2016/07/13 04:44:36 Done.
120 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698