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

Unified 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, 8 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/webui/cr_elements/cr_action_menu_test.js
diff --git a/chrome/test/data/webui/cr_elements/cr_action_menu_test.js b/chrome/test/data/webui/cr_elements/cr_action_menu_test.js
index 9715fba33f54b0568f705bc7bed33a9e220c61ef..f18dd1456e20688564368f7a0d3b957761505d4c 100644
--- a/chrome/test/data/webui/cr_elements/cr_action_menu_test.js
+++ b/chrome/test/data/webui/cr_elements/cr_action_menu_test.js
@@ -161,4 +161,92 @@ suite('CrActionMenu', function() {
makeMouseoverEvent(items[0]);
assertEquals(items[0], menu.root.activeElement);
});
+
+ test('positioning', function() {
+ // A 40x10 box at (100, 250).
+ var config = {
+ left: 100,
+ top: 250,
+ width: 40,
+ height: 10,
+ maxX: 1000,
+ maxY: 2000,
+ };
+
+ // Show right and bottom aligned by default.
+ menu.showAtPosition(config);
+ assertTrue(menu.open);
+ assertEquals('100px', menu.style.left);
+ assertEquals('250px', menu.style.top);
+ menu.close();
+
+ // Center the menu horizontally.
+ menu.showAtPosition(Object.assign({}, config, {
+ anchorAlignmentX: AnchorAlignment.CENTER,
+ }));
+ var menuWidth = menu.offsetWidth;
+ var menuHeight = menu.offsetHeight;
+ assertEquals(`${120 - menuWidth / 2}px`, menu.style.left);
+ assertEquals('250px', menu.style.top);
+ menu.close();
+
+ // Center the menu in both axes.
+ menu.showAtPosition(Object.assign({}, config, {
+ anchorAlignmentX: AnchorAlignment.CENTER,
+ anchorAlignmentY: AnchorAlignment.CENTER,
+ }));
+ menuWidth = menu.offsetWidth;
+ menuHeight = menu.offsetHeight;
+ assertEquals(`${120 - menuWidth / 2}px`, menu.style.left);
+ assertEquals(`${255 - menuHeight / 2}px`, menu.style.top);
+ menu.close();
+
+ // Left and top align the menu.
+ menu.showAtPosition(Object.assign({}, config, {
+ anchorAlignmentX: AnchorAlignment.BEFORE_END,
+ anchorAlignmentY: AnchorAlignment.BEFORE_END,
+ }));
+ menuWidth = menu.offsetWidth;
+ menuHeight = menu.offsetHeight;
+ assertEquals(`${140 - menuWidth}px`, menu.style.left);
+ assertEquals(`${260 - menuHeight}px`, menu.style.top);
+ menu.close();
+
+ // Being left and top aligned at (0, 0) should anchor to the bottom right.
+ menu.showAtPosition(Object.assign({}, config, {
+ anchorAlignmentX: AnchorAlignment.BEFORE_END,
+ anchorAlignmentY: AnchorAlignment.BEFORE_END,
+ left: 0,
+ top: 0,
+ }));
+ menuWidth = menu.offsetWidth;
+ menuHeight = menu.offsetHeight;
+ assertEquals(`0px`, menu.style.left);
+ assertEquals(`0px`, menu.style.top);
+ menu.close();
+
+ // Being aligned to a point in the bottom right should anchor to the top
+ // left.
+ menu.showAtPosition({
+ left: 1000,
+ top: 2000,
+ maxX: 1000,
+ maxY: 2000,
+ });
+ menuWidth = menu.offsetWidth;
+ menuHeight = menu.offsetHeight;
+ assertEquals(`${1000 - menuWidth}px`, menu.style.left);
+ assertEquals(`${2000 - menuHeight}px`, menu.style.top);
+ menu.close();
+
+ // Alignment is reversed in RTL.
+ document.body.style.direction = 'rtl';
+ menu.showAtPosition(config);
+ menuWidth = menu.offsetWidth;
+ menuHeight = menu.offsetHeight;
+ assertTrue(menu.open);
+ assertEquals(140 - menuWidth, menu.offsetLeft);
+ assertEquals('250px', menu.style.top);
+ menu.close();
+ });
});
« 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