OLD | NEW |
---|---|
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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 | 241 |
242 // Alignment is reversed in RTL. | 242 // Alignment is reversed in RTL. |
243 document.body.style.direction = 'rtl'; | 243 document.body.style.direction = 'rtl'; |
244 menu.showAtPosition(config); | 244 menu.showAtPosition(config); |
245 menuWidth = menu.offsetWidth; | 245 menuWidth = menu.offsetWidth; |
246 menuHeight = menu.offsetHeight; | 246 menuHeight = menu.offsetHeight; |
247 assertTrue(menu.open); | 247 assertTrue(menu.open); |
248 assertEquals(140 - menuWidth, menu.offsetLeft); | 248 assertEquals(140 - menuWidth, menu.offsetLeft); |
249 assertEquals('250px', menu.style.top); | 249 assertEquals('250px', menu.style.top); |
250 menu.close(); | 250 menu.close(); |
251 document.body.style.direction = 'ltr'; | |
252 }); | |
253 | |
254 test('offscreen scroll positioning', function() { | |
255 PolymerTest.clearBody(); | |
256 document.body.innerHTML = ` | |
dpapad
2017/06/22 21:18:36
Could we pull out some of the CSS values into vari
calamity
2017/06/28 04:00:47
Done.
| |
257 <style> | |
258 body { | |
259 height: 10000px; | |
260 width: 20000px; | |
261 } | |
262 | |
263 #container { | |
264 overflow: auto; | |
265 position: absolute; | |
266 top: 5000px; | |
267 left: 10000px; | |
268 height: 500px; | |
269 width: 500px; | |
270 } | |
271 | |
272 #inner-container { | |
273 height: 1000px; | |
274 width: 1000px; | |
275 } | |
276 </style> | |
277 <div id="container"> | |
278 <div id="inner-container"> | |
279 <button id="dots">...</button> | |
280 <dialog is="cr-action-menu"> | |
281 <button class="dropdown-item">Un</button> | |
282 <hr> | |
283 <button class="dropdown-item">Dos</button> | |
284 <button class="dropdown-item">Tres</button> | |
285 </dialog> | |
286 </div> | |
287 </div> | |
288 `; | |
289 menu = document.querySelector('dialog[is=cr-action-menu]'); | |
290 var dots = document.querySelector('#dots'); | |
291 | |
292 // Show the menu, scrolling the body to the button. | |
293 menu.showAt( | |
294 dots, | |
295 {anchorAlignmentX: AnchorAlignment.AFTER_START}); | |
296 assertEquals('10000px', menu.style.left); | |
297 assertEquals('5000px', menu.style.top); | |
298 menu.close(); | |
299 | |
300 // Show the menu, scrolling the container to the button, and the body to the | |
301 // button. | |
302 document.body.scrollLeft = 20000; | |
303 document.body.scrollTop = 10000; | |
304 | |
305 document.querySelector('#container').scrollLeft = 1000; | |
306 document.querySelector('#container').scrollTop = 1000; | |
307 | |
308 menu.showAt(dots, {anchorAlignmentX: AnchorAlignment.AFTER_START}); | |
309 assertEquals('10000px', menu.style.left); | |
310 assertEquals('5000px', menu.style.top); | |
311 menu.close(); | |
312 | |
313 // Show the menu for an already onscreen button. The anchor should be | |
314 // overridden so that no scrolling happens. | |
315 document.body.scrollLeft = 0; | |
316 document.body.scrollTop = 0; | |
317 | |
318 var rect = dots.getBoundingClientRect(); | |
319 document.body.scrollLeft = rect.right - document.body.clientWidth + 10; | |
dpapad
2017/06/22 21:18:36
What is the magic 10 value here?
calamity
2017/06/28 04:00:47
This was added just to make the test easier to vis
| |
320 document.body.scrollTop = rect.bottom - document.body.clientHeight + 10; | |
321 | |
322 menu.showAt(dots, {anchorAlignmentX: AnchorAlignment.AFTER_START}); | |
323 var menuWidth = menu.offsetWidth; | |
324 var menuHeight = menu.offsetHeight; | |
325 var buttonWidth = dots.offsetWidth; | |
326 var buttonHeight = dots.offsetHeight; | |
327 assertEquals(10000 - menuWidth + buttonWidth, menu.offsetLeft); | |
328 assertEquals(5000 - menuHeight + buttonHeight, menu.offsetTop); | |
251 }); | 329 }); |
252 }); | 330 }); |
OLD | NEW |