From bdceccd1aa779ec8facc71320678bf7a0bfa4628 Mon Sep 17 00:00:00 2001 From: Ahmed Ashour Date: Wed, 22 Nov 2017 08:31:56 +0100 Subject: Disabled ComboBox should not open popup on pasting (Fixes #7898) (#10240) --- .../combobox/ComboBoxPasteWithDisabled.java | 26 +++++++++++++ .../ComboBoxCombinedWithEnterShortcutTest.java | 1 + .../combobox/ComboBoxPasteWithDisabledTest.java | 44 ++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxPasteWithDisabled.java create mode 100644 uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxPasteWithDisabledTest.java (limited to 'uitest/src') diff --git a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxPasteWithDisabled.java b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxPasteWithDisabled.java new file mode 100644 index 0000000000..c7347fe9c5 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxPasteWithDisabled.java @@ -0,0 +1,26 @@ +package com.vaadin.tests.components.combobox; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.ComboBox; + +public class ComboBoxPasteWithDisabled extends AbstractTestUI { + + @Override + public String getDescription() { + return "Paste from Clipboard should not open the popup of a disabled ComboBox"; + } + + @Override + protected Integer getTicketNumber() { + return 7898; + } + + @Override + protected void setup(VaadinRequest request) { + ComboBox comboBox = new ComboBox<>(); + comboBox.setEnabled(false); + addComponent(comboBox); + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxCombinedWithEnterShortcutTest.java b/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxCombinedWithEnterShortcutTest.java index fb967819f9..a221a1ac00 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxCombinedWithEnterShortcutTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxCombinedWithEnterShortcutTest.java @@ -24,6 +24,7 @@ import com.vaadin.testbench.elements.ComboBoxElement; import com.vaadin.tests.tb3.MultiBrowserTest; public class ComboBoxCombinedWithEnterShortcutTest extends MultiBrowserTest { + @Test public void testKeyboardSelection() throws InterruptedException { openTestURL(); diff --git a/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxPasteWithDisabledTest.java b/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxPasteWithDisabledTest.java new file mode 100644 index 0000000000..10d0db5d3d --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxPasteWithDisabledTest.java @@ -0,0 +1,44 @@ +package com.vaadin.tests.components.combobox; + +import static org.junit.Assert.assertFalse; + +import org.junit.Test; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.elements.ComboBoxElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class ComboBoxPasteWithDisabledTest extends MultiBrowserTest { + + @Test + public void pasteWithDisabled() throws InterruptedException { + openTestURL(); + ComboBoxElement cb = $(ComboBoxElement.class).first(); + + cb.click(); + + WebElement input = cb.getInputField(); + JavascriptExecutor js = (JavascriptExecutor) getDriver(); + + // .sendKeys() doesn't allow sending to a disabled element + js.executeScript("arguments[0].removeAttribute('disabled')", input); + + String os = System.getProperty("os.name").toLowerCase(); + String paste; + if (os.contains("windows")) { + paste = Keys.chord(Keys.CONTROL, "v"); + } else if (os.contains("linux")) { + paste = Keys.chord(Keys.CONTROL, Keys.SHIFT, "v"); + } else { + // mac + paste = Keys.chord(Keys.COMMAND, "v"); + } + + input.sendKeys(paste); + + assertFalse(cb.isPopupOpen()); + } + +} -- cgit v1.2.3