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

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

Issue 2814743007: [cr-action-menu] Allow configurable anchors. (Closed)
Patch Set: rebase Created 3 years, 7 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.js » ('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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 assertNotEquals(items[0], menu.root.activeElement); 154 assertNotEquals(items[0], menu.root.activeElement);
155 assertEquals(menu, document.activeElement); 155 assertEquals(menu, document.activeElement);
156 156
157 // Mouse movements should override keyboard focus. 157 // Mouse movements should override keyboard focus.
158 down(); 158 down();
159 down(); 159 down();
160 assertEquals(items[1], menu.root.activeElement); 160 assertEquals(items[1], menu.root.activeElement);
161 makeMouseoverEvent(items[0]); 161 makeMouseoverEvent(items[0]);
162 assertEquals(items[0], menu.root.activeElement); 162 assertEquals(items[0], menu.root.activeElement);
163 }); 163 });
164
165 test('positioning', function() {
166 // A 40x10 box at (100, 250).
167 var config = {
168 left: 100,
169 top: 250,
170 width: 40,
171 height: 10,
172 maxX: 1000,
173 maxY: 2000,
174 };
175
176 // Show right and bottom aligned by default.
177 menu.showAtPosition(config);
178 assertTrue(menu.open);
179 assertEquals('100px', menu.style.left);
180 assertEquals('250px', menu.style.top);
181 menu.close();
182
183 // Center the menu horizontally.
184 menu.showAtPosition(Object.assign({}, config, {
185 anchorAlignmentX: AnchorAlignment.CENTER,
186 }));
187 var menuWidth = menu.offsetWidth;
188 var menuHeight = menu.offsetHeight;
189 assertEquals(`${120 - menuWidth / 2}px`, menu.style.left);
190 assertEquals('250px', menu.style.top);
191 menu.close();
192
193 // Center the menu in both axes.
194 menu.showAtPosition(Object.assign({}, config, {
195 anchorAlignmentX: AnchorAlignment.CENTER,
196 anchorAlignmentY: AnchorAlignment.CENTER,
197 }));
198 menuWidth = menu.offsetWidth;
199 menuHeight = menu.offsetHeight;
200 assertEquals(`${120 - menuWidth / 2}px`, menu.style.left);
201 assertEquals(`${255 - menuHeight / 2}px`, menu.style.top);
202 menu.close();
203
204 // Left and top align the menu.
205 menu.showAtPosition(Object.assign({}, config, {
206 anchorAlignmentX: AnchorAlignment.BEFORE_END,
207 anchorAlignmentY: AnchorAlignment.BEFORE_END,
208 }));
209 menuWidth = menu.offsetWidth;
210 menuHeight = menu.offsetHeight;
211 assertEquals(`${140 - menuWidth}px`, menu.style.left);
212 assertEquals(`${260 - menuHeight}px`, menu.style.top);
213 menu.close();
214
215 // Being left and top aligned at (0, 0) should anchor to the bottom right.
216 menu.showAtPosition(Object.assign({}, config, {
217 anchorAlignmentX: AnchorAlignment.BEFORE_END,
218 anchorAlignmentY: AnchorAlignment.BEFORE_END,
219 left: 0,
220 top: 0,
221 }));
222 menuWidth = menu.offsetWidth;
223 menuHeight = menu.offsetHeight;
224 assertEquals(`0px`, menu.style.left);
225 assertEquals(`0px`, menu.style.top);
226 menu.close();
227
228 // Being aligned to a point in the bottom right should anchor to the top
229 // left.
230 menu.showAtPosition({
231 left: 1000,
232 top: 2000,
233 maxX: 1000,
234 maxY: 2000,
235 });
236 menuWidth = menu.offsetWidth;
237 menuHeight = menu.offsetHeight;
238 assertEquals(`${1000 - menuWidth}px`, menu.style.left);
239 assertEquals(`${2000 - menuHeight}px`, menu.style.top);
240 menu.close();
241
242 // Alignment is reversed in RTL.
243 document.body.style.direction = 'rtl';
244 menu.showAtPosition(config);
245 menuWidth = menu.offsetWidth;
246 menuHeight = menu.offsetHeight;
247 assertTrue(menu.open);
248 assertEquals(140 - menuWidth, menu.offsetLeft);
249 assertEquals('250px', menu.style.top);
250 menu.close();
251 });
164 }); 252 });
OLDNEW
« no previous file with comments | « no previous file | ui/webui/resources/cr_elements/cr_action_menu/cr_action_menu.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698