| 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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 var menuHeight = menu.offsetHeight; | 208 var menuHeight = menu.offsetHeight; |
| 209 assertEquals(`${120 - menuWidth / 2}px`, menu.style.left); | 209 assertEquals(`${120 - menuWidth / 2}px`, menu.style.left); |
| 210 assertEquals('250px', menu.style.top); | 210 assertEquals('250px', menu.style.top); |
| 211 menu.close(); | 211 menu.close(); |
| 212 | 212 |
| 213 // Center the menu in both axes. | 213 // Center the menu in both axes. |
| 214 menu.showAtPosition(Object.assign({}, config, { | 214 menu.showAtPosition(Object.assign({}, config, { |
| 215 anchorAlignmentX: AnchorAlignment.CENTER, | 215 anchorAlignmentX: AnchorAlignment.CENTER, |
| 216 anchorAlignmentY: AnchorAlignment.CENTER, | 216 anchorAlignmentY: AnchorAlignment.CENTER, |
| 217 })); | 217 })); |
| 218 menuWidth = menu.offsetWidth; | |
| 219 menuHeight = menu.offsetHeight; | |
| 220 assertEquals(`${120 - menuWidth / 2}px`, menu.style.left); | 218 assertEquals(`${120 - menuWidth / 2}px`, menu.style.left); |
| 221 assertEquals(`${255 - menuHeight / 2}px`, menu.style.top); | 219 assertEquals(`${255 - menuHeight / 2}px`, menu.style.top); |
| 222 menu.close(); | 220 menu.close(); |
| 223 | 221 |
| 224 // Left and top align the menu. | 222 // Left and top align the menu. |
| 225 menu.showAtPosition(Object.assign({}, config, { | 223 menu.showAtPosition(Object.assign({}, config, { |
| 226 anchorAlignmentX: AnchorAlignment.BEFORE_END, | 224 anchorAlignmentX: AnchorAlignment.BEFORE_END, |
| 227 anchorAlignmentY: AnchorAlignment.BEFORE_END, | 225 anchorAlignmentY: AnchorAlignment.BEFORE_END, |
| 228 })); | 226 })); |
| 229 menuWidth = menu.offsetWidth; | |
| 230 menuHeight = menu.offsetHeight; | |
| 231 assertEquals(`${140 - menuWidth}px`, menu.style.left); | 227 assertEquals(`${140 - menuWidth}px`, menu.style.left); |
| 232 assertEquals(`${260 - menuHeight}px`, menu.style.top); | 228 assertEquals(`${260 - menuHeight}px`, menu.style.top); |
| 233 menu.close(); | 229 menu.close(); |
| 234 | 230 |
| 235 // Being left and top aligned at (0, 0) should anchor to the bottom right. | 231 // Being left and top aligned at (0, 0) should anchor to the bottom right. |
| 236 menu.showAtPosition(Object.assign({}, config, { | 232 menu.showAtPosition(Object.assign({}, config, { |
| 237 anchorAlignmentX: AnchorAlignment.BEFORE_END, | 233 anchorAlignmentX: AnchorAlignment.BEFORE_END, |
| 238 anchorAlignmentY: AnchorAlignment.BEFORE_END, | 234 anchorAlignmentY: AnchorAlignment.BEFORE_END, |
| 239 left: 0, | 235 left: 0, |
| 240 top: 0, | 236 top: 0, |
| 241 })); | 237 })); |
| 242 menuWidth = menu.offsetWidth; | |
| 243 menuHeight = menu.offsetHeight; | |
| 244 assertEquals(`0px`, menu.style.left); | 238 assertEquals(`0px`, menu.style.left); |
| 245 assertEquals(`0px`, menu.style.top); | 239 assertEquals(`0px`, menu.style.top); |
| 246 menu.close(); | 240 menu.close(); |
| 247 | 241 |
| 248 // Being aligned to a point in the bottom right should anchor to the top | 242 // Being aligned to a point in the bottom right should anchor to the top |
| 249 // left. | 243 // left. |
| 250 menu.showAtPosition({ | 244 menu.showAtPosition({ |
| 251 left: 1000, | 245 left: 1000, |
| 252 top: 2000, | 246 top: 2000, |
| 253 maxX: 1000, | 247 maxX: 1000, |
| 254 maxY: 2000, | 248 maxY: 2000, |
| 255 }); | 249 }); |
| 256 menuWidth = menu.offsetWidth; | |
| 257 menuHeight = menu.offsetHeight; | |
| 258 assertEquals(`${1000 - menuWidth}px`, menu.style.left); | 250 assertEquals(`${1000 - menuWidth}px`, menu.style.left); |
| 259 assertEquals(`${2000 - menuHeight}px`, menu.style.top); | 251 assertEquals(`${2000 - menuHeight}px`, menu.style.top); |
| 260 menu.close(); | 252 menu.close(); |
| 261 | 253 |
| 254 // If the viewport can't fit the menu, align the menu to the viewport. |
| 255 menu.showAtPosition({ |
| 256 left: menuWidth - 5, |
| 257 top: 0, |
| 258 width: 0, |
| 259 height: 0, |
| 260 maxX: menuWidth * 2 - 10, |
| 261 }); |
| 262 assertEquals(`${menuWidth - 10}px`, menu.style.left); |
| 263 assertEquals(`0px`, menu.style.top); |
| 264 menu.close(); |
| 265 |
| 262 // Alignment is reversed in RTL. | 266 // Alignment is reversed in RTL. |
| 263 document.body.style.direction = 'rtl'; | 267 document.body.style.direction = 'rtl'; |
| 264 menu.showAtPosition(config); | 268 menu.showAtPosition(config); |
| 265 menuWidth = menu.offsetWidth; | |
| 266 menuHeight = menu.offsetHeight; | |
| 267 assertTrue(menu.open); | 269 assertTrue(menu.open); |
| 268 assertEquals(140 - menuWidth, menu.offsetLeft); | 270 assertEquals(140 - menuWidth, menu.offsetLeft); |
| 269 assertEquals('250px', menu.style.top); | 271 assertEquals('250px', menu.style.top); |
| 270 menu.close(); | 272 menu.close(); |
| 271 document.body.style.direction = 'ltr'; | 273 document.body.style.direction = 'ltr'; |
| 272 }); | 274 }); |
| 273 | 275 |
| 274 test('offscreen scroll positioning', function() { | 276 test('offscreen scroll positioning', function() { |
| 275 PolymerTest.clearBody(); | 277 PolymerTest.clearBody(); |
| 276 var bodyHeight = 10000; | 278 var bodyHeight = 10000; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 | 349 |
| 348 menu.showAt(dots, {anchorAlignmentX: AnchorAlignment.AFTER_START}); | 350 menu.showAt(dots, {anchorAlignmentX: AnchorAlignment.AFTER_START}); |
| 349 var menuWidth = menu.offsetWidth; | 351 var menuWidth = menu.offsetWidth; |
| 350 var menuHeight = menu.offsetHeight; | 352 var menuHeight = menu.offsetHeight; |
| 351 var buttonWidth = dots.offsetWidth; | 353 var buttonWidth = dots.offsetWidth; |
| 352 var buttonHeight = dots.offsetHeight; | 354 var buttonHeight = dots.offsetHeight; |
| 353 assertEquals(containerLeft - menuWidth + buttonWidth, menu.offsetLeft); | 355 assertEquals(containerLeft - menuWidth + buttonWidth, menu.offsetLeft); |
| 354 assertEquals(containerTop - menuHeight + buttonHeight, menu.offsetTop); | 356 assertEquals(containerTop - menuHeight + buttonHeight, menu.offsetTop); |
| 355 }); | 357 }); |
| 356 }); | 358 }); |
| OLD | NEW |