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

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

Powered by Google App Engine
This is Rietveld 408576698