diff options
author | Artur Signell <artur@vaadin.com> | 2016-05-11 22:47:07 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2016-05-16 09:51:09 +0000 |
commit | 7d2d091ecbb0b995dc46074725eabb456609cdf3 (patch) | |
tree | 90e89cb767f919f82e6e062404a437c0e3055790 /uitest | |
parent | e386748dbc487d264caae0c98bcf5cffbe43d4a2 (diff) | |
download | vaadin-framework-7d2d091ecbb0b995dc46074725eabb456609cdf3.tar.gz vaadin-framework-7d2d091ecbb0b995dc46074725eabb456609cdf3.zip |
Eliminate rounding errors for GridLayout expand ratios (#19797)
Change-Id: Idf05dde5d6526fafee618fd3e2eb1afa63fab7bc
Diffstat (limited to 'uitest')
2 files changed, 97 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/gridlayout/GridLayoutExpandWithManyRows.java b/uitest/src/main/java/com/vaadin/tests/components/gridlayout/GridLayoutExpandWithManyRows.java new file mode 100644 index 0000000000..a901093e31 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/gridlayout/GridLayoutExpandWithManyRows.java @@ -0,0 +1,57 @@ +package com.vaadin.tests.components.gridlayout; + +import com.vaadin.annotations.Theme; +import com.vaadin.server.VaadinRequest; +import com.vaadin.ui.Component; +import com.vaadin.ui.GridLayout; +import com.vaadin.ui.Label; +import com.vaadin.ui.Panel; +import com.vaadin.ui.UI; + +@Theme("tests-valo") +public class GridLayoutExpandWithManyRows extends UI { + + static final int POPULATED_ROWS = 20; + static int ROW_COUNT = 58; + + public static class ColoredLabel extends Label { + private static int colorNumber = 0; + + public ColoredLabel() { + super(); + addStyleName("color-label"); + addStyleName("color-" + (colorNumber++) % 10); + } + } + + @Override + protected void init(VaadinRequest request) { + for (int i = 0; i < 10; i++) { + getPage().getStyles().add(".color-" + i + " {" // + + "background-color: hsl(" + (i * 90) + ", 60%, 70%);" // + + "}"); + } + + GridLayout gridLayout = new GridLayout(6, ROW_COUNT); + for (int i = 0; i < ROW_COUNT; i++) { + gridLayout.setRowExpandRatio(i, 1); + } + gridLayout.setSizeFull(); + for (int i = 0; i < POPULATED_ROWS; i++) { + int upperLeftRow = i * 2; + int upperLeftCol = 0; + int lowerRightCol = 5; + int lowerRightRow = upperLeftRow + 1; + ColoredLabel coloredLabel = new ColoredLabel(); + coloredLabel.setSizeFull(); + gridLayout.addComponent(coloredLabel, upperLeftCol, upperLeftRow, + lowerRightCol, lowerRightRow); + } + + gridLayout.setHeight("500%"); + Component root = new Panel(gridLayout); + root.setSizeFull(); + setContent(root); + + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/gridlayout/GridLayoutExpandWithManyRowsTest.java b/uitest/src/test/java/com/vaadin/tests/components/gridlayout/GridLayoutExpandWithManyRowsTest.java new file mode 100644 index 0000000000..693fdc73db --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/gridlayout/GridLayoutExpandWithManyRowsTest.java @@ -0,0 +1,40 @@ +package com.vaadin.tests.components.gridlayout; + +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.elements.GridLayoutElement; +import com.vaadin.tests.tb3.SingleBrowserTest; + +public class GridLayoutExpandWithManyRowsTest extends SingleBrowserTest { + + @Test + public void equalRowHeights() { + openTestURL(); + GridLayoutElement gridlayout = $(GridLayoutElement.class).first(); + + // Rows are expanded using integer pixels and leftover pixels are added + // to the first N rows. + // The tests uses rowspan=2 so one row in the DOM should be max 2 pixels + // lower than the first row + List<WebElement> slots = gridlayout.findElements(By + .className("v-gridlayout-slot")); + Assert.assertEquals(GridLayoutExpandWithManyRows.POPULATED_ROWS, + slots.size()); + + int firstRowHeight = slots.get(0).getSize().height; + int lastRowHeight = firstRowHeight; + for (int i = 1; i < GridLayoutExpandWithManyRows.POPULATED_ROWS; i++) { + int rowHeight = slots.get(i).getSize().height; + Assert.assertTrue(rowHeight <= firstRowHeight); + Assert.assertTrue(rowHeight >= firstRowHeight - 2); + Assert.assertTrue(rowHeight <= lastRowHeight); + + lastRowHeight = rowHeight; + } + } +} |