Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ContextMenuSizeTest.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.components.table;
  17. import static org.hamcrest.CoreMatchers.is;
  18. import static org.hamcrest.MatcherAssert.assertThat;
  19. import static org.hamcrest.Matchers.lessThan;
  20. import java.util.List;
  21. import org.junit.Test;
  22. import org.openqa.selenium.By;
  23. import org.openqa.selenium.WebElement;
  24. import org.openqa.selenium.interactions.Actions;
  25. import org.openqa.selenium.remote.DesiredCapabilities;
  26. import com.vaadin.testbench.parallel.Browser;
  27. import com.vaadin.tests.tb3.MultiBrowserTest;
  28. /**
  29. * Test for context menu position and size.
  30. *
  31. * @author Vaadin Ltd
  32. */
  33. public class ContextMenuSizeTest extends MultiBrowserTest {
  34. @Override
  35. public List<DesiredCapabilities> getBrowsersToTest() {
  36. // context menu doesn't work in phantom JS and works weirdly with IE8
  37. // and selenium.
  38. return getBrowserCapabilities(Browser.IE9, Browser.IE10, Browser.IE11,
  39. Browser.FIREFOX, Browser.CHROME);
  40. }
  41. @Override
  42. public void setup() throws Exception {
  43. super.setup();
  44. openTestURL();
  45. }
  46. private void resizeViewPortHeightTo(int windowHeight) {
  47. // viewport width doesn't matter, let's use a magic number of 500.
  48. testBench().resizeViewPortTo(500, windowHeight);
  49. }
  50. private int getContextMenuY() {
  51. int y = openContextMenu().getLocation().getY();
  52. closeContextMenu();
  53. return y;
  54. }
  55. private int getContextMenuHeight() {
  56. int height = openContextMenu().getSize().getHeight();
  57. closeContextMenu();
  58. return height;
  59. }
  60. private WebElement openContextMenu() {
  61. Actions actions = new Actions(getDriver());
  62. actions.contextClick(findElement(By.className("v-table-cell-wrapper")));
  63. actions.perform();
  64. return findElement(By.className("v-contextmenu"));
  65. }
  66. private void closeContextMenu() {
  67. findElement(By.className("v-app")).click();
  68. }
  69. @Test
  70. public void contextMenuIsResizedToFitWindow() {
  71. int initialHeight = getContextMenuHeight();
  72. resizeViewPortHeightTo(initialHeight - 10);
  73. assertThat(getContextMenuHeight(), lessThan(initialHeight));
  74. resizeViewPortHeightTo(initialHeight + 100);
  75. assertThat(getContextMenuHeight(), is(initialHeight));
  76. }
  77. @Test
  78. public void contextMenuPositionIsChangedAfterResize() {
  79. int height = getContextMenuHeight();
  80. int y = getContextMenuY();
  81. resizeViewPortHeightTo(y + height - 10);
  82. assertThat(getContextMenuY(), lessThan(y));
  83. assertThat(getContextMenuHeight(), is(height));
  84. }
  85. }