diff options
author | Denis Anisimov <denis@vaadin.com> | 2016-11-07 09:41:01 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2016-11-14 07:23:22 +0000 |
commit | 5d2f6a372e0c31c471ecfbe7b7483f32e0a00f1d (patch) | |
tree | b8fca3a014f276b75e66a661621c74ea3bb58b17 | |
parent | 3e8f028817582a77ec3654b1f8f99136f327cc70 (diff) | |
download | vaadin-framework-5d2f6a372e0c31c471ecfbe7b7483f32e0a00f1d.tar.gz vaadin-framework-5d2f6a372e0c31c471ecfbe7b7483f32e0a00f1d.zip |
Prevent adding several scrollbar handlers (#19189).
Change-Id: Ib0cc6c6835aab6d263f153362a328bcf2be7bc5c
3 files changed, 134 insertions, 0 deletions
diff --git a/client/src/main/java/com/vaadin/client/widget/escalator/ScrollbarBundle.java b/client/src/main/java/com/vaadin/client/widget/escalator/ScrollbarBundle.java index 6e2fb14f8f..870cbf2660 100644 --- a/client/src/main/java/com/vaadin/client/widget/escalator/ScrollbarBundle.java +++ b/client/src/main/java/com/vaadin/client/widget/escalator/ScrollbarBundle.java @@ -442,6 +442,9 @@ public abstract class ScrollbarBundle implements DeferredWorker { boolean offsetSizeBecomesGreaterThanScrollSize = showsScrollHandle() && newOffsetSizeIsGreaterThanScrollSize; if (offsetSizeBecomesGreaterThanScrollSize && getScrollPos() != 0) { + if (offsetSizeTemporaryScrollHandler != null) { + offsetSizeTemporaryScrollHandler.removeHandler(); + } // must be a field because Java insists. offsetSizeTemporaryScrollHandler = addScrollHandler( new ScrollHandler() { @@ -669,6 +672,9 @@ public abstract class ScrollbarBundle implements DeferredWorker { boolean delayedSizeSet = !BrowserInfo.get().isFirefox(); // must be a field because Java insists. if (delayedSizeSet) { + if (scrollSizeTemporaryScrollHandler != null) { + scrollSizeTemporaryScrollHandler.removeHandler(); + } scrollSizeTemporaryScrollHandler = addScrollHandler( new ScrollHandler() { @Override diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/HorizontalScrollAfterResize.java b/uitest/src/main/java/com/vaadin/tests/components/grid/HorizontalScrollAfterResize.java new file mode 100644 index 0000000000..8e6afa5441 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/HorizontalScrollAfterResize.java @@ -0,0 +1,60 @@ +/* + * Copyright 2000-2016 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; + +import java.util.Arrays; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Grid; + +/** + * @author Vaadin Ltd + * + */ +public class HorizontalScrollAfterResize extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + final Grid grid = new Grid(); + grid.setWidth("100%"); + grid.setHeight("350px"); + grid.setCaption("My Grid"); + + for (int i = 0; i < 10; i++) { + char ch = (char) ('a' + i); + grid.addColumn(ch, String.class); + } + for (int i = 0; i < 100; i++) { + String[] row = new String[10]; + Arrays.fill(row, "test"); + grid.addRow(row); + } + + addComponents(grid); + } + + @Override + protected String getTestDescription() { + return "Don't add more than one scroll handler"; + } + + @Override + protected Integer getTicketNumber() { + return 19189; // also 20254, 19622 + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/HorizontalScrollAfterResizeTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/HorizontalScrollAfterResizeTest.java new file mode 100644 index 0000000000..e1f85fa074 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/HorizontalScrollAfterResizeTest.java @@ -0,0 +1,68 @@ +/* + * Copyright 2000-2016 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; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.Dimension; +import org.openqa.selenium.Point; + +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest; + +/** + * @author Vaadin Ltd + * + */ +public class HorizontalScrollAfterResizeTest extends GridBasicFeaturesTest { + + /** + * The behavior without the fix differs across different browsers but + * scenario should work everywhere. + */ + @Test + public void scrollAfterResize() { + getDriver().manage().window().setSize(new Dimension(600, 400)); + openTestURL(); + getDriver().manage().window().setSize(new Dimension(200, 400)); + + // First scroll to the right + scrollGridHorizontallyTo(600); + Point locationAfterFirstScroll = $(GridElement.class).first() + .getCell(0, 9).getLocation(); + + // resize back + getDriver().manage().window().setSize(new Dimension(600, 400)); + // shrink again + getDriver().manage().window().setSize(new Dimension(200, 400)); + + // second scroll to the right + scrollGridHorizontallyTo(600); + + Point lolocationAfterSecondScrollcation = $(GridElement.class).first() + .getCell(0, 9).getLocation(); + + // With the bug scrolling doesn't happen. Location should be the same as + // first time + Assert.assertEquals(locationAfterFirstScroll, + lolocationAfterSecondScrollcation); + } + + @Override + protected Class<?> getUIClass() { + return HorizontalScrollAfterResize.class; + } +} |