summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorMatti Hosio <mhosio@vaadin.com>2015-01-14 12:13:31 +0200
committerSauli Tähkäpää <sauli@vaadin.com>2015-01-21 11:04:19 +0200
commitc72d60ba1ff38db9ede283f91ed657419dc79619 (patch)
treebac9ca78ee440ac7b127c6de15f3439889e5374d /uitest
parent513901091f8878d8b6b135d32b04091ed68f87b2 (diff)
downloadvaadin-framework-c72d60ba1ff38db9ede283f91ed657419dc79619.tar.gz
vaadin-framework-c72d60ba1ff38db9ede283f91ed657419dc79619.zip
Remove unnecessary scrollbar when zooming in or out (#15164)
Adds overflow-hidden in cases where scrollbars should not be needed Change-Id: Icee2444b0e7ee999fe49fadcb1598027453d49c5
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/com/vaadin/tests/components/table/UnnecessaryScrollbarWhenZooming.java51
-rw-r--r--uitest/src/com/vaadin/tests/components/table/UnnecessaryScrollbarWhenZoomingTest.java195
2 files changed, 246 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/components/table/UnnecessaryScrollbarWhenZooming.java b/uitest/src/com/vaadin/tests/components/table/UnnecessaryScrollbarWhenZooming.java
new file mode 100644
index 0000000000..8d95261825
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/table/UnnecessaryScrollbarWhenZooming.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.table;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Table;
+
+public class UnnecessaryScrollbarWhenZooming extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ Table table = new Table("A Table");
+ table.setId("test-table");
+ table.addContainerProperty("Text property 1", String.class, null);
+ table.addContainerProperty("Text property 2", String.class, null);
+ table.addContainerProperty("Text property 3", String.class, null);
+ table.addContainerProperty("Numeric property", Integer.class, null);
+ table.addItem(new Object[] { "Value 1 ", "Value 2", "Value 3",
+ new Integer(39) }, new Integer(1));
+ table.addItem(new Object[] { "Value 1 ", "Value 2", "Value 3",
+ new Integer(39) }, new Integer(2));
+ table.setWidth("100%");
+ table.setPageLength(0);
+ addComponent(table);
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Test case for extra scrollbar being displayed in Table when browser window is zoomed (or page length is 0)";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 15164;
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/table/UnnecessaryScrollbarWhenZoomingTest.java b/uitest/src/com/vaadin/tests/components/table/UnnecessaryScrollbarWhenZoomingTest.java
new file mode 100644
index 0000000000..df01800180
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/table/UnnecessaryScrollbarWhenZoomingTest.java
@@ -0,0 +1,195 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.table;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.Arrays;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.openqa.selenium.JavascriptExecutor;
+import org.openqa.selenium.Keys;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.remote.DesiredCapabilities;
+import org.openqa.selenium.support.ui.ExpectedConditions;
+import org.openqa.selenium.support.ui.WebDriverWait;
+
+import com.vaadin.testbench.By;
+import com.vaadin.testbench.commands.TestBenchCommandExecutor;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class UnnecessaryScrollbarWhenZoomingTest extends MultiBrowserTest {
+
+ private ZoomLevelSetter zoomSetter;
+ private int zoomOutIterations = 3;
+ private int zoomInIterations = 3;
+
+ @Before
+ public void init() {
+ testBench().resizeViewPortTo(995, 400);
+ DesiredCapabilities capabilities = getDesiredCapabilities();
+ if (BrowserUtil.isChrome(capabilities)
+ || BrowserUtil.isPhantomJS(capabilities)) {
+ zoomSetter = new ChromeZoomLevelSetter(driver);
+ } else {
+ zoomSetter = new NonChromeZoomLevelSetter(driver);
+ }
+ zoomSetter.resetZoom();
+ openTestURL();
+ // IE sometimes has trouble waiting long enough.
+ new WebDriverWait(getDriver(), 30).until(ExpectedConditions
+ .presenceOfElementLocated(By
+ .cssSelector(".v-table-body-wrapper")));
+ }
+
+ @Test
+ public void testInitial() {
+ testExtraScrollbarsNotShown();
+ }
+
+ @Test
+ public void testZoomingIn() {
+ for (int i = 0; i < zoomInIterations; i++) {
+ zoomSetter.increaseZoom();
+ testExtraScrollbarsNotShown();
+ }
+ }
+
+ @Test
+ public void testZoomingOut() throws InterruptedException {
+ for (int i = 0; i < zoomOutIterations; i++) {
+ zoomSetter.decreaseZoom();
+ testExtraScrollbarsNotShown();
+ }
+ }
+
+ @After
+ public void resetZoomLevel() {
+ zoomSetter.resetZoom();
+ }
+
+ private void testExtraScrollbarsNotShown() {
+ // wait a bit for the layout
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ Assert.fail();
+ }
+ WebElement element = findElement(By
+ .cssSelector(".v-table-body-wrapper"));
+ assertNotNull("There must be a table", element);
+ String overflow = element.getCssValue("overflow");
+ // As long as the overflow is hidden, there will not be scroll bars.
+ if (!"hidden".equals(overflow)) {
+ // compare scroll width to offset width. True if scrolling.
+ String detectHorizontalScroll = "return arguments[0].scrollWidth > arguments[0].clientWidth";
+ Boolean horizontal = (Boolean) ((TestBenchCommandExecutor) getDriver())
+ .executeScript(detectHorizontalScroll, element);
+ assertEquals("there must be no horizontal scrollbar", false,
+ horizontal);
+
+ String detectVerticalScroll = "return arguments[0].scrollHeight > arguments[0].clientHeight";
+ Boolean vertical = (Boolean) ((TestBenchCommandExecutor) getDriver())
+ .executeScript(detectVerticalScroll, element);
+ assertEquals("there must be no vertical scrollbar", false, vertical);
+ }
+ }
+
+ interface ZoomLevelSetter {
+ public void increaseZoom();
+
+ public void decreaseZoom();
+
+ public void resetZoom();
+ }
+
+ /*
+ * A class for setting the zoom levels by sending keys such as ctrl and +.
+ */
+ class NonChromeZoomLevelSetter implements ZoomLevelSetter {
+ private WebDriver driver;
+
+ public NonChromeZoomLevelSetter(WebDriver driver) {
+ this.driver = driver;
+ }
+
+ @Override
+ public void increaseZoom() {
+ getElement().sendKeys(Keys.chord(Keys.CONTROL, Keys.ADD));
+ }
+
+ @Override
+ public void decreaseZoom() {
+ getElement().sendKeys(Keys.chord(Keys.CONTROL, Keys.SUBTRACT));
+ }
+
+ @Override
+ public void resetZoom() {
+ getElement().sendKeys(Keys.chord(Keys.CONTROL, "0"));
+ }
+
+ private WebElement getElement() {
+ return driver.findElement(By.tagName("html"));
+ }
+ }
+
+ /*
+ * A class for setting the zoom levels using JavaScript. This setter is used
+ * for browsers for which the method of sending the keys ctrl and + does not
+ * work.
+ */
+ class ChromeZoomLevelSetter implements ZoomLevelSetter {
+ private JavascriptExecutor js;
+ private int currentZoomIndex = 2;
+ private int[] zoomLevels = { 70, 80, 90, 100, 110, 120, 130 };
+
+ public ChromeZoomLevelSetter(WebDriver driver) {
+ js = (JavascriptExecutor) driver;
+ }
+
+ @Override
+ public void increaseZoom() {
+ currentZoomIndex++;
+ if (currentZoomIndex >= zoomLevels.length) {
+ currentZoomIndex = zoomLevels.length - 1;
+ }
+ js.executeScript("document.body.style.zoom='"
+ + zoomLevels[currentZoomIndex] + "%'");
+ }
+
+ @Override
+ public void decreaseZoom() {
+ currentZoomIndex--;
+ if (currentZoomIndex < 0) {
+ currentZoomIndex = 0;
+ }
+ js.executeScript("document.body.style.zoom='"
+ + zoomLevels[currentZoomIndex] + "%'");
+ }
+
+ @Override
+ public void resetZoom() {
+ js.executeScript("document.body.style.zoom='100%'");
+ currentZoomIndex = Arrays.binarySearch(zoomLevels, 100);
+ }
+ }
+
+}