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 14 matching lines...) Expand all Loading... | |
25 <button class="dropdown-item">Tres</button> | 25 <button class="dropdown-item">Tres</button> |
26 </dialog> | 26 </dialog> |
27 `; | 27 `; |
28 | 28 |
29 menu = document.querySelector('dialog[is=cr-action-menu]'); | 29 menu = document.querySelector('dialog[is=cr-action-menu]'); |
30 items = menu.querySelectorAll('.dropdown-item'); | 30 items = menu.querySelectorAll('.dropdown-item'); |
31 assertEquals(3, items.length); | 31 assertEquals(3, items.length); |
32 }); | 32 }); |
33 | 33 |
34 teardown(function() { | 34 teardown(function() { |
35 document.body.style.direction = 'ltr'; | |
36 | |
35 if (menu.open) | 37 if (menu.open) |
36 menu.close(); | 38 menu.close(); |
37 }); | 39 }); |
38 | 40 |
39 function down() { | 41 function down() { |
40 MockInteractions.keyDownOn(menu, 'ArrowDown', [], 'ArrowDown'); | 42 MockInteractions.keyDownOn(menu, 'ArrowDown', [], 'ArrowDown'); |
41 } | 43 } |
42 | 44 |
43 function up() { | 45 function up() { |
44 MockInteractions.keyDownOn(menu, 'ArrowUp', [], 'ArrowUp'); | 46 MockInteractions.keyDownOn(menu, 'ArrowUp', [], 'ArrowUp'); |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
263 assertEquals(`0px`, menu.style.top); | 265 assertEquals(`0px`, menu.style.top); |
264 menu.close(); | 266 menu.close(); |
265 | 267 |
266 // Alignment is reversed in RTL. | 268 // Alignment is reversed in RTL. |
267 document.body.style.direction = 'rtl'; | 269 document.body.style.direction = 'rtl'; |
268 menu.showAtPosition(config); | 270 menu.showAtPosition(config); |
269 assertTrue(menu.open); | 271 assertTrue(menu.open); |
270 assertEquals(140 - menuWidth, menu.offsetLeft); | 272 assertEquals(140 - menuWidth, menu.offsetLeft); |
271 assertEquals('250px', menu.style.top); | 273 assertEquals('250px', menu.style.top); |
272 menu.close(); | 274 menu.close(); |
273 document.body.style.direction = 'ltr'; | |
274 }); | 275 }); |
275 | 276 |
276 test('offscreen scroll positioning', function() { | 277 test('offscreen scroll positioning', function() { |
277 var bodyHeight = 10000; | 278 var bodyHeight = 10000; |
278 var bodyWidth = 20000; | 279 var bodyWidth = 20000; |
279 var containerLeft = 5000; | 280 var containerLeft = 5000; |
280 var containerTop = 10000; | 281 var containerTop = 10000; |
281 var containerWidth = 500; | 282 var containerWidth = 500; |
282 var containerHeight = 500; | 283 var containerHeight = 500; |
283 document.body.innerHTML = ` | 284 document.body.innerHTML = ` |
284 <style> | 285 <style> |
285 body { | 286 body { |
286 height: ${bodyHeight}px; | 287 height: ${bodyHeight}px; |
287 width: ${bodyWidth}px; | 288 width: ${bodyWidth}px; |
288 } | 289 } |
289 | 290 |
290 #container { | 291 #container { |
291 overflow: auto; | 292 overflow: auto; |
292 position: absolute; | 293 position: absolute; |
293 top: ${containerTop}px; | 294 top: ${containerTop}px; |
294 left: ${containerLeft}px; | 295 left: ${containerLeft}px; |
296 right: ${containerLeft}px; | |
295 height: ${containerHeight}px; | 297 height: ${containerHeight}px; |
296 width: ${containerWidth}px; | 298 width: ${containerWidth}px; |
297 } | 299 } |
298 | 300 |
299 #inner-container { | 301 #inner-container { |
300 height: 1000px; | 302 height: 1000px; |
301 width: 1000px; | 303 width: 1000px; |
302 } | 304 } |
303 </style> | 305 </style> |
304 <div id="container"> | 306 <div id="container"> |
(...skipping 16 matching lines...) Expand all Loading... | |
321 dots, | 323 dots, |
322 {anchorAlignmentX: AnchorAlignment.AFTER_START}); | 324 {anchorAlignmentX: AnchorAlignment.AFTER_START}); |
323 assertEquals(`${containerLeft}px`, menu.style.left); | 325 assertEquals(`${containerLeft}px`, menu.style.left); |
324 assertEquals(`${containerTop}px`, menu.style.top); | 326 assertEquals(`${containerTop}px`, menu.style.top); |
325 menu.close(); | 327 menu.close(); |
326 | 328 |
327 // Show the menu, scrolling the container to the button, and the body to the | 329 // Show the menu, scrolling the container to the button, and the body to the |
328 // button. | 330 // button. |
329 document.body.scrollLeft = bodyWidth; | 331 document.body.scrollLeft = bodyWidth; |
330 document.body.scrollTop = bodyHeight; | 332 document.body.scrollTop = bodyHeight; |
333 var container = document.querySelector('#container'); | |
331 | 334 |
332 document.querySelector('#container').scrollLeft = containerLeft; | 335 container.scrollLeft = containerLeft; |
333 document.querySelector('#container').scrollTop = containerTop; | 336 container.scrollTop = containerTop; |
334 | 337 |
335 menu.showAt(dots, {anchorAlignmentX: AnchorAlignment.AFTER_START}); | 338 menu.showAt(dots, {anchorAlignmentX: AnchorAlignment.AFTER_START}); |
336 assertEquals(`${containerLeft}px`, menu.style.left); | 339 assertEquals(`${containerLeft}px`, menu.style.left); |
337 assertEquals(`${containerTop}px`, menu.style.top); | 340 assertEquals(`${containerTop}px`, menu.style.top); |
338 menu.close(); | 341 menu.close(); |
339 | 342 |
340 // Show the menu for an already onscreen button. The anchor should be | 343 // Show the menu for an already onscreen button. The anchor should be |
341 // overridden so that no scrolling happens. | 344 // overridden so that no scrolling happens. |
342 document.body.scrollLeft = 0; | 345 document.body.scrollLeft = 0; |
343 document.body.scrollTop = 0; | 346 document.body.scrollTop = 0; |
344 | 347 |
345 var rect = dots.getBoundingClientRect(); | 348 var rect = dots.getBoundingClientRect(); |
346 document.body.scrollLeft = rect.right - document.body.clientWidth; | 349 document.body.scrollLeft = rect.right - document.body.clientWidth; |
347 document.body.scrollTop = rect.bottom - document.body.clientHeight; | 350 document.body.scrollTop = rect.bottom - document.body.clientHeight; |
348 | 351 |
349 menu.showAt(dots, {anchorAlignmentX: AnchorAlignment.AFTER_START}); | 352 menu.showAt(dots, {anchorAlignmentX: AnchorAlignment.AFTER_START}); |
350 var menuWidth = menu.offsetWidth; | 353 var menuWidth = menu.offsetWidth; |
351 var menuHeight = menu.offsetHeight; | 354 var menuHeight = menu.offsetHeight; |
352 var buttonWidth = dots.offsetWidth; | 355 var buttonWidth = dots.offsetWidth; |
353 var buttonHeight = dots.offsetHeight; | 356 var buttonHeight = dots.offsetHeight; |
354 assertEquals(containerLeft - menuWidth + buttonWidth, menu.offsetLeft); | 357 assertEquals(containerLeft - menuWidth + buttonWidth, menu.offsetLeft); |
355 assertEquals(containerTop - menuHeight + buttonHeight, menu.offsetTop); | 358 assertEquals(containerTop - menuHeight + buttonHeight, menu.offsetTop); |
359 menu.close(); | |
360 | |
361 // showAtPosition takes into account scroll position. | |
362 document.body.scrollLeft = 500; | |
dpapad
2017/07/06 22:05:37
The "offscreen scroll positioning" test is becomin
calamity
2017/07/07 03:18:01
Done.
| |
363 document.body.scrollTop = 1000; | |
364 menu.showAtPosition({top: 50, left: 50}); | |
365 assertEquals( | |
366 550, menu.offsetLeft); | |
367 assertEquals(1050, menu.offsetTop); | |
368 menu.close(); | |
369 | |
370 // Anchor to an item in RTL. | |
371 document.body.style.direction = 'rtl'; | |
372 document.body.scrollLeft = 0; | |
373 document.body.scrollTop = 0; | |
374 menu.showAt(dots, {anchorAlignmentX: AnchorAlignment.AFTER_START}); | |
375 assertEquals( | |
376 container.offsetLeft + containerWidth - menuWidth, menu.offsetLeft); | |
377 assertEquals(containerTop, menu.offsetTop); | |
378 menu.close(); | |
356 }); | 379 }); |
357 }); | 380 }); |
OLD | NEW |