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.

WidgetUtilTest.java 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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.util;
  17. import java.util.List;
  18. import org.junit.Assert;
  19. import org.junit.Test;
  20. import org.openqa.selenium.By;
  21. import org.openqa.selenium.WebElement;
  22. import org.openqa.selenium.remote.DesiredCapabilities;
  23. import com.vaadin.testbench.parallel.Browser;
  24. import com.vaadin.testbench.parallel.BrowserUtil;
  25. import com.vaadin.tests.tb3.MultiBrowserTest;
  26. import com.vaadin.tests.widgetset.server.WidgetUtilUI;
  27. public class WidgetUtilTest extends MultiBrowserTest {
  28. @Override
  29. public List<DesiredCapabilities> getBrowsersToTest() {
  30. List<DesiredCapabilities> l = super.getBrowsersToTest();
  31. // IE8 does not support getComputedStyle
  32. l.remove(Browser.IE8.getDesiredCapabilities());
  33. return l;
  34. }
  35. @Test
  36. public void testBlockElementRequiredSizeComputedStyle() {
  37. openTestURL();
  38. WebElement testComponent = findElement(By
  39. .className("v-widget-util-test"));
  40. testComponent.click();
  41. int padding = (int) Math.ceil(2.4 + 3.5);
  42. int border = (int) Math.ceil(1.8 * 2);
  43. int baseWidth = 300;
  44. int baseHeight = 50;
  45. if (BrowserUtil.isPhantomJS(getDesiredCapabilities())
  46. && getDesiredCapabilities().getVersion().equals("1")) {
  47. // PhantomJS1 rounds padding to integers
  48. padding = 2 + 3;
  49. }
  50. if (browserRoundsBorderToInteger(getDesiredCapabilities())) {
  51. border = 1 * 2;
  52. }
  53. assertExpectedSize(testComponent, "noBorderPadding", baseWidth + "x"
  54. + baseHeight);
  55. assertExpectedSize(testComponent, "border", (baseWidth + border) + "x"
  56. + (baseHeight + border));
  57. assertExpectedSize(testComponent, "padding", (baseWidth + padding)
  58. + "x" + (baseHeight + padding));
  59. assertExpectedSize(testComponent, "borderPadding",
  60. (baseWidth + border + padding) + "x"
  61. + (baseHeight + border + padding));
  62. }
  63. private void assertExpectedSize(WebElement testComponent, String id,
  64. String size) {
  65. WebElement e = testComponent.findElement(By.id(id));
  66. Assert.assertEquals(id + ": " + size, e.getText());
  67. }
  68. private boolean browserRoundsBorderToInteger(
  69. DesiredCapabilities capabilities) {
  70. // Note that this is how the Windows browsers in the test cluster work.
  71. // On Mac, Firefox works slightly differently (rounds border to 1.5px).
  72. return (BrowserUtil.isChrome(capabilities)
  73. || BrowserUtil.isPhantomJS(capabilities) || BrowserUtil
  74. .isFirefox(capabilities));
  75. }
  76. @Override
  77. protected Class<?> getUIClass() {
  78. return WidgetUtilUI.class;
  79. }
  80. }