From 9be3b40801a73edae8b96c03670d8d2d029f0ee5 Mon Sep 17 00:00:00 2001 From: Matti Tahvonen Date: Tue, 12 Nov 2013 17:12:30 +0200 Subject: [PATCH] Workaround for missing value change event in chrome (#10109) Change-Id: I019527041539fcd0083261b693767144492e626a --- .../com/vaadin/client/ui/VNativeSelect.java | 16 +++ ...electsAndChromeKeyboardNavigationTest.java | 131 ++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/components/nativeselect/NativeSelectsAndChromeKeyboardNavigationTest.java diff --git a/client/src/com/vaadin/client/ui/VNativeSelect.java b/client/src/com/vaadin/client/ui/VNativeSelect.java index 650ff7731a..04cc9e6624 100644 --- a/client/src/com/vaadin/client/ui/VNativeSelect.java +++ b/client/src/com/vaadin/client/ui/VNativeSelect.java @@ -21,6 +21,7 @@ import java.util.Iterator; import com.google.gwt.event.dom.client.ChangeEvent; import com.google.gwt.user.client.ui.ListBox; +import com.vaadin.client.BrowserInfo; import com.vaadin.client.UIDL; public class VNativeSelect extends VOptionGroupBase implements Field { @@ -98,6 +99,21 @@ public class VNativeSelect extends VOptionGroupBase implements Field { // remove temporary empty item select.removeItem(0); firstValueIsTemporaryNullItem = false; + /* + * Workaround to achrome bug that may cause value change event not + * to fire when selection is done with keyboard. + * + * http://dev.vaadin.com/ticket/10109 + * + * Problem is confirmed to exist only on Chrome-Win, but just + * execute in for all webkits. Probably exists also in other + * webkits/blinks on windows. + */ + if (BrowserInfo.get().isWebkit()) { + select.getElement().blur(); + select.getElement().focus(); + } + } } diff --git a/uitest/src/com/vaadin/tests/components/nativeselect/NativeSelectsAndChromeKeyboardNavigationTest.java b/uitest/src/com/vaadin/tests/components/nativeselect/NativeSelectsAndChromeKeyboardNavigationTest.java new file mode 100644 index 0000000000..364d3bd8d4 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/nativeselect/NativeSelectsAndChromeKeyboardNavigationTest.java @@ -0,0 +1,131 @@ +/* + * Copyright 2000-2013 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.nativeselect; + +import java.util.Collections; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.Keys; +import org.openqa.selenium.Platform; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.remote.DesiredCapabilities; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * + * @since + * @author Vaadin Ltd + */ +public class NativeSelectsAndChromeKeyboardNavigationTest extends + MultiBrowserTest { + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.tb3.MultiBrowserTest#getBrowsersToTest() + */ + @Override + public List getBrowsersToTest() { + DesiredCapabilities chrome = DesiredCapabilities.chrome(); + chrome.setPlatform(Platform.WINDOWS); + return Collections.singletonList(chrome); + } + + @Test + public void testValueChangeListenerWithKeyboardNavigation() + throws InterruptedException { + setDebug(true); + openTestURL(); + Thread.sleep(1000); + menu("Component"); + menuSub("Listeners"); + menuSub("Value change listener"); + + getDriver().findElement(By.tagName("body")).click(); + + WebElement select = getDriver().findElement(By.tagName("select")); + select.sendKeys(Keys.ARROW_DOWN); + select.sendKeys(Keys.ARROW_DOWN); + select.sendKeys(Keys.ARROW_DOWN); + + String bodytext = getDriver().findElement(By.tagName("body")).getText(); + + Assert.assertTrue(bodytext.contains("new value: 'Item 1'")); + Assert.assertTrue(bodytext.contains("new value: 'Item 2'")); + Assert.assertTrue(bodytext.contains("new value: 'Item 3'")); + + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.tb3.AbstractTB3Test#getUIClass() + */ + @Override + protected Class getUIClass() { + return NativeSelects.class; + } + + // Uncomment this to debug test in local/portforwarded chromedriver + // @Override + // protected void setupLocalDriver() { + // WebDriver chromeDriver; + // try { + // chromeDriver = new RemoteWebDriver( + // new URL("http://localhost:9515"), getBrowsersToTest() + // .iterator().next()); + // setDriver(chromeDriver); + // } catch (MalformedURLException e) { + // e.printStackTrace(); + // } + // } + // + // /* + // * (non-Javadoc) + // * + // * @see com.vaadin.tests.tb3.AbstractTB3Test#runLocally() + // */ + // @Override + // public boolean runLocally() { + // return false; + // } + + /** + * @since + * @param string + */ + private void menuSub(String string) { + getDriver().findElement(By.xpath("//span[text() = '" + string + "']")) + .click(); + new Actions(getDriver()).moveByOffset(100, 0).build().perform(); + } + + /** + * @since + * @param string + */ + private void menu(String string) { + getDriver().findElement(By.xpath("//span[text() = '" + string + "']")) + .click(); + + } + +} -- 2.39.5