From 7d2d091ecbb0b995dc46074725eabb456609cdf3 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Wed, 11 May 2016 22:47:07 +0300 Subject: Eliminate rounding errors for GridLayout expand ratios (#19797) Change-Id: Idf05dde5d6526fafee618fd3e2eb1afa63fab7bc --- .../gridlayout/GridLayoutExpandWithManyRows.java | 57 ++++++++++++++++++++++ .../GridLayoutExpandWithManyRowsTest.java | 40 +++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 uitest/src/main/java/com/vaadin/tests/components/gridlayout/GridLayoutExpandWithManyRows.java create mode 100644 uitest/src/test/java/com/vaadin/tests/components/gridlayout/GridLayoutExpandWithManyRowsTest.java (limited to 'uitest') 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 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; + } + } +} -- cgit v1.2.3