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

Unified Diff: chrome/test/data/webui/cr_elements/cr_action_menu_test.js

Issue 2966163004: [cr-action-menu] Use clientWidth for rtl flipping. (Closed)
Patch Set: fix test on mac Created 3 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 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 62e51011ed259d10ee569e8da711fe095a892fe4..6fa40b55156889925028982ef481e612ee37819b 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
@@ -13,6 +13,9 @@ suite('CrActionMenu', function() {
/** @type {?NodeList<HTMLElement>} */
var items = null;
+ /** @type {HTMLElement} */
+ var dots = null;
+
setup(function() {
PolymerTest.clearBody();
@@ -28,10 +31,13 @@ suite('CrActionMenu', function() {
menu = document.querySelector('dialog[is=cr-action-menu]');
items = menu.querySelectorAll('.dropdown-item');
+ dots = document.querySelector('#dots');
assertEquals(3, items.length);
});
teardown(function() {
+ document.body.style.direction = 'ltr';
+
if (menu.open)
menu.close();
});
@@ -45,25 +51,25 @@ suite('CrActionMenu', function() {
}
test('hidden or disabled items', function() {
- menu.showAt(document.querySelector('#dots'));
+ menu.showAt(dots);
down();
assertEquals(menu.root.activeElement, items[0]);
menu.close();
items[0].hidden = true;
- menu.showAt(document.querySelector('#dots'));
+ menu.showAt(dots);
down();
assertEquals(menu.root.activeElement, items[1]);
menu.close();
items[1].disabled = true;
- menu.showAt(document.querySelector('#dots'));
+ menu.showAt(dots);
down();
assertEquals(menu.root.activeElement, items[2]);
});
test('focus after down/up arrow', function() {
- menu.showAt(document.querySelector('#dots'));
+ menu.showAt(dots);
// The menu should be focused when shown, but not on any of the items.
assertEquals(menu, document.activeElement);
@@ -93,8 +99,8 @@ suite('CrActionMenu', function() {
assertEquals(items[0], menu.root.activeElement);
});
- test('pressing up arrow when no focus will focus last item', function(){
- menu.showAt(document.querySelector('#dots'));
+ test('pressing up arrow when no focus will focus last item', function() {
+ menu.showAt(dots);
assertEquals(menu, document.activeElement);
up();
@@ -106,7 +112,7 @@ suite('CrActionMenu', function() {
var item = document.createElement('button');
item.classList.add('dropdown-item');
menu.insertBefore(item, items[0]);
- menu.showAt(document.querySelector('#dots'));
+ menu.showAt(dots);
down();
assertEquals(item, menu.root.activeElement);
@@ -122,7 +128,7 @@ suite('CrActionMenu', function() {
});
test('close on resize', function() {
- menu.showAt(document.querySelector('#dots'));
+ menu.showAt(dots);
assertTrue(menu.open);
window.dispatchEvent(new CustomEvent('resize'));
@@ -130,7 +136,7 @@ suite('CrActionMenu', function() {
});
test('close on popstate', function() {
- menu.showAt(document.querySelector('#dots'));
+ menu.showAt(dots);
assertTrue(menu.open);
window.dispatchEvent(new CustomEvent('popstate'));
@@ -140,7 +146,6 @@ suite('CrActionMenu', function() {
/** @param {string} key The key to use for closing. */
function testFocusAfterClosing(key) {
return new Promise(function(resolve) {
- var dots = document.querySelector('#dots');
menu.showAt(dots);
assertTrue(menu.open);
@@ -151,7 +156,9 @@ suite('CrActionMenu', function() {
});
}
- test('close on Tab', function() { return testFocusAfterClosing('Tab'); });
+ test('close on Tab', function() {
+ return testFocusAfterClosing('Tab');
+ });
test('close on Escape', function() {
return testFocusAfterClosing('Escape');
});
@@ -162,7 +169,7 @@ suite('CrActionMenu', function() {
node.dispatchEvent(e);
}
- menu.showAt(document.querySelector('#dots'));
+ menu.showAt(dots);
// Moving mouse on option 1 should focus it.
assertNotEquals(items[0], menu.root.activeElement);
@@ -259,7 +266,7 @@ suite('CrActionMenu', function() {
height: 0,
maxX: menuWidth * 2 - 10,
});
- assertEquals(`${menuWidth - 10}px`, menu.style.left);
+ assertEquals(`${menuWidth - 10}px`, menu.style.left);
assertEquals(`0px`, menu.style.top);
menu.close();
@@ -270,88 +277,122 @@ suite('CrActionMenu', function() {
assertEquals(140 - menuWidth, menu.offsetLeft);
assertEquals('250px', menu.style.top);
menu.close();
- document.body.style.direction = 'ltr';
});
- test('offscreen scroll positioning', function() {
+ suite('offscreen scroll positioning', function() {
var bodyHeight = 10000;
var bodyWidth = 20000;
var containerLeft = 5000;
var containerTop = 10000;
var containerWidth = 500;
var containerHeight = 500;
- document.body.innerHTML = `
- <style>
- body {
- height: ${bodyHeight}px;
- width: ${bodyWidth}px;
- }
-
- #container {
- overflow: auto;
- position: absolute;
- top: ${containerTop}px;
- left: ${containerLeft}px;
- height: ${containerHeight}px;
- width: ${containerWidth}px;
- }
-
- #inner-container {
- height: 1000px;
- width: 1000px;
- }
- </style>
- <div id="container">
- <div id="inner-container">
- <button id="dots">...</button>
- <dialog is="cr-action-menu">
- <button class="dropdown-item">Un</button>
- <hr>
- <button class="dropdown-item">Dos</button>
- <button class="dropdown-item">Tres</button>
- </dialog>
+ var menuWidth = 100;
+ var menuHeight = 200;
+
+ setup(function() {
+ document.body.scrollTop = 0;
+ document.body.scrollLeft = 0;
+ document.body.innerHTML = `
+ <style>
+ body {
+ height: ${bodyHeight}px;
+ width: ${bodyWidth}px;
+ }
+
+ #container {
+ overflow: auto;
+ position: absolute;
+ top: ${containerTop}px;
+ left: ${containerLeft}px;
+ right: ${containerLeft}px;
+ height: ${containerHeight}px;
+ width: ${containerWidth}px;
+ }
+
+ #inner-container {
+ height: 1000px;
+ width: 1000px;
+ }
+
+ dialog {
+ height: ${menuHeight};
+ width: ${menuWidth};
+ padding: 0;
+ }
+ </style>
+ <div id="container">
+ <div id="inner-container">
+ <button id="dots">...</button>
+ <dialog is="cr-action-menu">
+ <button class="dropdown-item">Un</button>
+ <hr>
+ <button class="dropdown-item">Dos</button>
+ <button class="dropdown-item">Tres</button>
+ </dialog>
+ </div>
</div>
- </div>
- `;
- menu = document.querySelector('dialog[is=cr-action-menu]');
- var dots = document.querySelector('#dots');
+ `;
+ menu = document.querySelector('dialog[is=cr-action-menu]');
+ dots = document.querySelector('#dots');
+ })
// Show the menu, scrolling the body to the button.
- menu.showAt(
- dots,
- {anchorAlignmentX: AnchorAlignment.AFTER_START});
- assertEquals(`${containerLeft}px`, menu.style.left);
- assertEquals(`${containerTop}px`, menu.style.top);
- menu.close();
+ test('simple offscreen', function() {
+ menu.showAt(dots, {anchorAlignmentX: AnchorAlignment.AFTER_START});
+ assertEquals(`${containerLeft}px`, menu.style.left);
+ assertEquals(`${containerTop}px`, menu.style.top);
+ menu.close();
+ });
// Show the menu, scrolling the container to the button, and the body to the
// button.
- document.body.scrollLeft = bodyWidth;
- document.body.scrollTop = bodyHeight;
+ test('offscreen and out of scroll container viewport', function() {
+ document.body.scrollLeft = bodyWidth;
+ document.body.scrollTop = bodyHeight;
+ var container = document.querySelector('#container');
- document.querySelector('#container').scrollLeft = containerLeft;
- document.querySelector('#container').scrollTop = containerTop;
+ container.scrollLeft = containerLeft;
+ container.scrollTop = containerTop;
- menu.showAt(dots, {anchorAlignmentX: AnchorAlignment.AFTER_START});
- assertEquals(`${containerLeft}px`, menu.style.left);
- assertEquals(`${containerTop}px`, menu.style.top);
- menu.close();
+ menu.showAt(dots, {anchorAlignmentX: AnchorAlignment.AFTER_START});
+ assertEquals(`${containerLeft}px`, menu.style.left);
+ assertEquals(`${containerTop}px`, menu.style.top);
+ menu.close();
+ });
// Show the menu for an already onscreen button. The anchor should be
// overridden so that no scrolling happens.
- document.body.scrollLeft = 0;
- document.body.scrollTop = 0;
+ test('onscreen forces anchor change', function() {
+ var rect = dots.getBoundingClientRect();
+ document.body.scrollLeft = rect.right - document.body.clientWidth + 10;
+ document.body.scrollTop = rect.bottom - document.body.clientHeight + 10;
+
+ menu.showAt(dots, {anchorAlignmentX: AnchorAlignment.AFTER_START});
+ var buttonWidth = dots.offsetWidth;
+ var buttonHeight = dots.offsetHeight;
+ assertEquals(containerLeft - menuWidth + buttonWidth, menu.offsetLeft);
+ assertEquals(containerTop - menuHeight + buttonHeight, menu.offsetTop);
+ menu.close();
+ });
- var rect = dots.getBoundingClientRect();
- document.body.scrollLeft = rect.right - document.body.clientWidth;
- document.body.scrollTop = rect.bottom - document.body.clientHeight;
+ test('scroll position maintained for showAtPosition', function() {
+ document.body.scrollLeft = 500;
+ document.body.scrollTop = 1000;
+ menu.showAtPosition({top: 50, left: 50});
+ assertEquals(550, menu.offsetLeft);
+ assertEquals(1050, menu.offsetTop);
+ menu.close();
+ });
- menu.showAt(dots, {anchorAlignmentX: AnchorAlignment.AFTER_START});
- var menuWidth = menu.offsetWidth;
- var menuHeight = menu.offsetHeight;
- var buttonWidth = dots.offsetWidth;
- var buttonHeight = dots.offsetHeight;
- assertEquals(containerLeft - menuWidth + buttonWidth, menu.offsetLeft);
- assertEquals(containerTop - menuHeight + buttonHeight, menu.offsetTop);
+ test('rtl', function() {
+ // Anchor to an item in RTL.
+ document.body.style.direction = 'rtl';
+ menu.showAt(dots, {anchorAlignmentX: AnchorAlignment.AFTER_START});
+ assertEquals(
+ container.offsetLeft + containerWidth - menuWidth,
+ menu.offsetLeft);
+ assertEquals(containerTop, menu.offsetTop);
+ 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