Chromium Code Reviews| 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 9f3d898a0b54ebe897fbcfaa8dbc237c41d8b3b3..5dc956f4ac487e70aba5707024483ddd6ce3472c 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 |
| @@ -268,5 +268,89 @@ 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() { |
| + PolymerTest.clearBody(); |
|
dpapad
2017/06/28 17:49:40
Nit: Since you are replacing innerHTML below, this
calamity
2017/06/29 06:16:16
Done.
|
| + 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> |
| + </div> |
| + </div> |
| + `; |
| + menu = document.querySelector('dialog[is=cr-action-menu]'); |
| + var 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(); |
| + |
| + // Show the menu, scrolling the container to the button, and the body to the |
| + // button. |
| + document.body.scrollLeft = bodyWidth; |
| + document.body.scrollTop = bodyHeight; |
| + |
| + document.querySelector('#container').scrollLeft = containerLeft; |
| + document.querySelector('#container').scrollTop = containerTop; |
| + |
| + 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; |
| + |
| + var rect = dots.getBoundingClientRect(); |
| + document.body.scrollLeft = rect.right - document.body.clientWidth; |
| + document.body.scrollTop = rect.bottom - document.body.clientHeight; |
| + |
| + 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); |
| }); |
| }); |