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

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

Powered by Google App Engine
This is Rietveld 408576698