summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorOlli Tietäväinen <ollit@vaadin.com>2018-04-16 17:56:16 +0300
committerIlia Motornyi <elmot@vaadin.com>2018-04-16 17:56:16 +0300
commitd0bc2ad8f940506d2d2aa1a79725b5ed636a914b (patch)
tree2589ced7c5664a843a80bff2c15c7a52d290b080 /uitest
parent4dec38e73d23e09d193bec02fbd1ce8629098578 (diff)
downloadvaadin-framework-d0bc2ad8f940506d2d2aa1a79725b5ed636a914b.tar.gz
vaadin-framework-d0bc2ad8f940506d2d2aa1a79725b5ed636a914b.zip
Add a check for tab events trying to set focus outside a modal Window (#10655)
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/window/ModalWindowFocus.java2
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/window/ModalWindowFocusTest.java3
-rwxr-xr-xuitest/src/test/java/com/vaadin/tests/components/window/ModalWindowRefocusTest.java61
3 files changed, 64 insertions, 2 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/window/ModalWindowFocus.java b/uitest/src/main/java/com/vaadin/tests/components/window/ModalWindowFocus.java
index 38ce020b80..20a6e4cfc7 100644
--- a/uitest/src/main/java/com/vaadin/tests/components/window/ModalWindowFocus.java
+++ b/uitest/src/main/java/com/vaadin/tests/components/window/ModalWindowFocus.java
@@ -16,6 +16,7 @@ public class ModalWindowFocus extends AbstractReindeerTestUI {
protected void setup(VaadinRequest req) {
Button button = new Button("Open windows");
+ button.setTabIndex(2);
button.setId("firstButton");
addComponent(button);
button.addClickListener(event -> {
@@ -42,6 +43,7 @@ public class ModalWindowFocus extends AbstractReindeerTestUI {
});
Button button2 = new Button(
"Open unclosable and unresizable modal window");
+ button2.setTabIndex(1);
addComponent(button2);
button2.setId("modalWindowButton");
button2.addClickListener(event -> {
diff --git a/uitest/src/test/java/com/vaadin/tests/components/window/ModalWindowFocusTest.java b/uitest/src/test/java/com/vaadin/tests/components/window/ModalWindowFocusTest.java
index b5bd7bcdcc..4bece63be6 100644
--- a/uitest/src/test/java/com/vaadin/tests/components/window/ModalWindowFocusTest.java
+++ b/uitest/src/test/java/com/vaadin/tests/components/window/ModalWindowFocusTest.java
@@ -96,7 +96,7 @@ public class ModalWindowFocusTest extends MultiBrowserTest {
"this has been focused".equals(tfe.getValue()));
}
- private void pressKeyAndWait(Keys key) {
+ protected void pressKeyAndWait(Keys key) {
new Actions(driver).sendKeys(key).build().perform();
sleep(100);
}
@@ -113,7 +113,6 @@ public class ModalWindowFocusTest extends MultiBrowserTest {
assertEquals("true", ariaModal);
String role = windowElement.getAttribute("role");
assertEquals("dialog", role);
-
}
}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/window/ModalWindowRefocusTest.java b/uitest/src/test/java/com/vaadin/tests/components/window/ModalWindowRefocusTest.java
new file mode 100755
index 0000000000..d09d3ce027
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/window/ModalWindowRefocusTest.java
@@ -0,0 +1,61 @@
+package com.vaadin.tests.components.window;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.openqa.selenium.Keys;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.remote.DesiredCapabilities;
+
+import com.vaadin.testbench.By;
+import com.vaadin.testbench.elements.TextFieldElement;
+import com.vaadin.testbench.parallel.Browser;
+
+/**
+ * Tests that a modal window is focused on creation and that on closing a window
+ * focus is given to underlying modal window
+ *
+ * @author Vaadin Ltd
+ */
+public class ModalWindowRefocusTest extends ModalWindowFocusTest {
+
+ @Override
+ public List<DesiredCapabilities> getBrowsersToTest() {
+ // Chrome doesn't support clicking on the modality curtain
+ return getBrowserCapabilities(Browser.IE11, Browser.EDGE,
+ Browser.FIREFOX);
+ }
+
+ @Override
+ protected Class<?> getUIClass() {
+ return ModalWindowFocus.class;
+ }
+
+ /**
+ * Open modal window -> click modality curtain to remove focus from Window
+ * -> press tab thrice so that focus goes into Window again and focuses the
+ * text field so that the focus event is fired.
+ */
+ @Test
+ public void testFocusOutsideModal() {
+ waitForElementPresent(By.id("modalWindowButton"));
+ WebElement button = findElement(By.id("modalWindowButton"));
+ button.click();
+ waitForElementPresent(By.id("focusfield"));
+ WebElement curtain = findElement(
+ org.openqa.selenium.By.className("v-window-modalitycurtain"));
+ curtain.click();
+
+ pressKeyAndWait(Keys.TAB);
+ pressKeyAndWait(Keys.TAB);
+ pressKeyAndWait(Keys.TAB);
+
+ TextFieldElement tfe = $(TextFieldElement.class).id("focusfield");
+ assertTrue("First TextField should have received focus",
+ "this has been focused".equals(tfe.getValue()));
+
+ }
+
+}