You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GridLayoutExtraSpacingTest.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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.gridlayout;
  17. import java.io.IOException;
  18. import org.junit.Assert;
  19. import org.junit.Test;
  20. import org.openqa.selenium.By;
  21. import org.openqa.selenium.WebElement;
  22. import com.vaadin.testbench.elements.CheckBoxElement;
  23. import com.vaadin.testbench.elements.CssLayoutElement;
  24. import com.vaadin.testbench.elements.GridLayoutElement;
  25. import com.vaadin.tests.tb3.MultiBrowserTest;
  26. public class GridLayoutExtraSpacingTest extends MultiBrowserTest {
  27. @Test
  28. public void componentRowFour() throws IOException, Exception {
  29. openTestURL();
  30. CssLayoutElement component = $(CssLayoutElement.class).first();
  31. GridLayoutElement gridLayout = $(GridLayoutElement.class).first();
  32. // Spacing on, not hiding empty rows/columns
  33. // There should be 3 * 6px spacing (red) above the csslayout
  34. verifySpacingAbove(3 * 6, gridLayout, component);
  35. CheckBoxElement spacingCheckbox = $(CheckBoxElement.class).caption(
  36. "spacing").first();
  37. check(spacingCheckbox);
  38. // Spacing off, not hiding empty rows/columns
  39. // There should not be any spacing (red) above the csslayout
  40. verifySpacingAbove(0, gridLayout, component);
  41. CheckBoxElement hideRowsColumnsCheckbox = $(CheckBoxElement.class)
  42. .caption("hide empty rows/columns").first();
  43. check(hideRowsColumnsCheckbox);
  44. // Spacing off, hiding empty rows/columns
  45. // There should not be any spacing (red) above the csslayout
  46. verifySpacingAbove(0, gridLayout, component);
  47. check(spacingCheckbox);
  48. // Spacing on, hiding empty rows/columns
  49. // There should not be any spacing (red) above or below the csslayout
  50. // Oh PhantomJs...
  51. sleep(100);
  52. // FIXME: This should be 0 but there is a bug somewhere
  53. // verifySpacingAbove(0, gridLayout, component);
  54. verifySpacingBelow(6, gridLayout, component);
  55. }
  56. /**
  57. * workaround for http://dev.vaadin.com/ticket/13763
  58. */
  59. private void check(CheckBoxElement checkbox) {
  60. WebElement cb = checkbox.findElement(By.xpath("input"));
  61. if (BrowserUtil.isChrome(getDesiredCapabilities())) {
  62. testBenchElement(cb).click(0, 0);
  63. } else {
  64. cb.click();
  65. }
  66. }
  67. private void verifySpacingAbove(int spacing, GridLayoutElement gridLayout,
  68. CssLayoutElement component) {
  69. assertHeight(component, 500 - spacing, 1);
  70. int offset = component.getLocation().getY()
  71. - gridLayout.getLocation().getY();
  72. Assert.assertEquals(spacing, offset);
  73. }
  74. private void verifySpacingBelow(int spacing, GridLayoutElement gridLayout,
  75. CssLayoutElement component) {
  76. assertHeight(component, 500 - spacing, 1);
  77. int offset = component.getLocation().getY()
  78. - gridLayout.getLocation().getY();
  79. Assert.assertEquals(0, offset);
  80. }
  81. private void assertHeight(WebElement component, int height, int tolerance) {
  82. Assert.assertTrue(Math.abs(height - component.getSize().getHeight()) <= tolerance);
  83. }
  84. }