diff options
author | Henrik Paul <henrik@vaadin.com> | 2014-09-25 15:34:33 +0300 |
---|---|---|
committer | Teemu Suo-Anttila <teemusa@vaadin.com> | 2014-10-03 06:04:58 +0000 |
commit | edbca6ac0fbfbd8a3a126e8efc89dff07202813f (patch) | |
tree | 0effcc57e42200adcc46e1a168ca258fa9f878d1 /uitest | |
parent | 0375cb57b53ffa45dbc1e6fbd94e3d15e23b9ec3 (diff) | |
download | vaadin-framework-edbca6ac0fbfbd8a3a126e8efc89dff07202813f.tar.gz vaadin-framework-edbca6ac0fbfbd8a3a126e8efc89dff07202813f.zip |
Fixes a race condition in Escalator's scrolling (#13334)
Change-Id: I8bd6195bfbf37c847919e3092d486e67fe79cd5c
Diffstat (limited to 'uitest')
6 files changed, 75 insertions, 9 deletions
diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorBasicClientFeaturesTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorBasicClientFeaturesTest.java index eff964bd4f..8f29a71536 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorBasicClientFeaturesTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorBasicClientFeaturesTest.java @@ -43,6 +43,8 @@ public abstract class EscalatorBasicClientFeaturesTest extends MultiBrowserTest protected static final String BODY_ROWS = "Body Rows"; protected static final String FOOTER_ROWS = "Footer Rows"; + protected static final String REMOVE_ALL_INSERT_SCROLL = "Remove all, insert 30 and scroll 40px"; + protected static final String GENERAL = "General"; protected static final String POPULATE_COLUMN_ROW = "Populate Escalator (columns, then rows)"; protected static final String POPULATE_ROW_COLUMN = "Populate Escalator (rows, then columns)"; @@ -191,4 +193,8 @@ public abstract class EscalatorBasicClientFeaturesTest extends MultiBrowserTest protected Object executeScript(String script, Object... args) { return ((JavascriptExecutor) getDriver()).executeScript(script, args); } + + protected void populate() { + selectMenuPath(GENERAL, POPULATE_COLUMN_ROW); + } } diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorColspanTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorColspanTest.java index 8cbba35faa..3c3e16e65a 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorColspanTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorColspanTest.java @@ -84,8 +84,4 @@ public class EscalatorColspanTest extends EscalatorBasicClientFeaturesTest { return Integer.parseInt(attribute); } } - - private void populate() { - selectMenuPath(GENERAL, POPULATE_COLUMN_ROW); - } } diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorColumnFreezingTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorColumnFreezingTest.java index fb217789c2..2ea0d8638b 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorColumnFreezingTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorColumnFreezingTest.java @@ -25,7 +25,8 @@ import java.util.regex.Pattern; import org.junit.Test; import org.openqa.selenium.WebElement; -public class EscalatorColumnFreezingTest extends EscalatorBasicClientFeaturesTest { +public class EscalatorColumnFreezingTest extends + EscalatorBasicClientFeaturesTest { private final static Pattern TRANSFORM_PATTERN = Pattern.compile(// @formatter:off // any start of the string @@ -88,10 +89,6 @@ public class EscalatorColumnFreezingTest extends EscalatorBasicClientFeaturesTes assertEquals(NO_FREEZE, getFrozenScrollCompensation(bodyCell)); } - private void populate() { - selectMenuPath(GENERAL, POPULATE_COLUMN_ROW); - } - private static boolean isFrozen(WebElement cell) { return cell.getAttribute("class").contains("frozen"); } diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorScrollTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorScrollTest.java new file mode 100644 index 0000000000..d2be88b557 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorScrollTest.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.grid.basicfeatures; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +public class EscalatorScrollTest extends EscalatorBasicClientFeaturesTest { + + /** + * Before the fix, removing and adding rows and also scrolling would put the + * scroll state in an internally inconsistent state. The scrollbar would've + * been scrolled correctly, but the body wasn't. + * + * This was due to optimizations that didn't keep up with the promises, so + * to say. So the optimizations were removed. + */ + @Test + public void testScrollRaceCondition() { + openTestURL(); + populate(); + + scrollVerticallyTo(40); + String originalStyle = getTBodyStyle(); + selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, REMOVE_ALL_INSERT_SCROLL); + + // body should be scrolled to exactly the same spot. (not 0) + assertEquals(originalStyle, getTBodyStyle()); + } + + private String getTBodyStyle() { + WebElement tbody = getEscalator().findElement(By.tagName("tbody")); + return tbody.getAttribute("style"); + } +} diff --git a/uitest/src/com/vaadin/tests/widgetset/client/grid/EscalatorBasicClientFeaturesWidget.java b/uitest/src/com/vaadin/tests/widgetset/client/grid/EscalatorBasicClientFeaturesWidget.java index 54c870b8f7..987dcc1bb7 100644 --- a/uitest/src/com/vaadin/tests/widgetset/client/grid/EscalatorBasicClientFeaturesWidget.java +++ b/uitest/src/com/vaadin/tests/widgetset/client/grid/EscalatorBasicClientFeaturesWidget.java @@ -481,6 +481,16 @@ public class EscalatorBasicClientFeaturesWidget extends .getRowCount() - 50, 50); } }, menupath); + addMenuCommand("Remove all, insert 30 and scroll 40px", + new ScheduledCommand() { + @Override + public void execute() { + removeRows(escalator.getBody(), 0, escalator.getBody() + .getRowCount()); + insertRows(escalator.getBody(), 0, 30); + escalator.setScrollTop(40); + } + }, menupath); } private void createRowsMenu(final RowContainer container, String[] menupath) { diff --git a/uitest/src/com/vaadin/tests/widgetset/client/grid/EscalatorProxy.java b/uitest/src/com/vaadin/tests/widgetset/client/grid/EscalatorProxy.java index ac1de01f1e..866fdbd5c2 100644 --- a/uitest/src/com/vaadin/tests/widgetset/client/grid/EscalatorProxy.java +++ b/uitest/src/com/vaadin/tests/widgetset/client/grid/EscalatorProxy.java @@ -203,4 +203,10 @@ public class EscalatorProxy extends Escalator { logWidget.updateDebugLabel(); } + @Override + public void setScrollTop(double scrollTop) { + logWidget.log("setScrollTop " + scrollTop); + logWidget.updateDebugLabel(); + super.setScrollTop(scrollTop); + } } |