diff options
author | Artur Signell <artur@vaadin.com> | 2015-07-15 20:37:20 +0300 |
---|---|---|
committer | Mika Murtojarvi <mika@vaadin.com> | 2015-08-04 14:14:24 +0300 |
commit | ae9adec0467ea88fd12e0295791b77f5ef3010ae (patch) | |
tree | 7f3347339a5f6450a56f43046899a97bab1ccba1 /uitest/src | |
parent | 951101ce39620501ed8aa1751909b7bc697713a3 (diff) | |
download | vaadin-framework-ae9adec0467ea88fd12e0295791b77f5ef3010ae.tar.gz vaadin-framework-ae9adec0467ea88fd12e0295791b77f5ef3010ae.zip |
Ensure server side focus is applied when opening a window (#17731)
This change removes all deferred commands for handling window focus to
ensure
the focus events are triggered in the expected order
Change-Id: I46598243d1022b82cf64f0e60169f52248c3cc72
Diffstat (limited to 'uitest/src')
3 files changed, 129 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/components/window/OpenModalWindowAndFocusField.java b/uitest/src/com/vaadin/tests/components/window/OpenModalWindowAndFocusField.java new file mode 100644 index 0000000000..1c82a3de02 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/window/OpenModalWindowAndFocusField.java @@ -0,0 +1,62 @@ +/* + * 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.window; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.TextArea; +import com.vaadin.ui.Window; + +public class OpenModalWindowAndFocusField extends AbstractTestUIWithLog { + + @Override + protected void setup(VaadinRequest request) { + Button button = new Button("Open modal and focus textarea"); + button.setId("openFocus"); + button.addClickListener(new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + open(true); + } + }); + addComponent(button); + + button = new Button("Only open modal"); + button.setId("open"); + button.addClickListener(new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + open(false); + } + + }); + addComponent(button); + + } + + private void open(boolean focus) { + Window wind = new Window(); + wind.setModal(true); + TextArea ta = new TextArea(); + wind.setContent(ta); + addWindow(wind); + if (focus) { + ta.focus(); + } + } +} diff --git a/uitest/src/com/vaadin/tests/components/window/OpenModalWindowAndFocusFieldTest.java b/uitest/src/com/vaadin/tests/components/window/OpenModalWindowAndFocusFieldTest.java new file mode 100644 index 0000000000..5dba1c3285 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/window/OpenModalWindowAndFocusFieldTest.java @@ -0,0 +1,48 @@ +/* + * 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.window; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.TextAreaElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class OpenModalWindowAndFocusFieldTest extends MultiBrowserTest { + + @Test + public void openModalAndFocusField() { + openTestURL(); + $(ButtonElement.class).id("openFocus").click(); + TextAreaElement textArea = $(TextAreaElement.class).first(); + + assertElementsEquals(textArea, getActiveElement()); + } + + @Test + public void openModal() { + openTestURL(); + $(ButtonElement.class).id("open").click(); + // WindowElement window = $(WindowElement.class).first(); + WebElement windowFocusElement = findElement(By + .xpath("//div[@class='v-window-contents']/div[@class='v-scrollable']")); + + assertElementsEquals(windowFocusElement, getActiveElement()); + } + +} diff --git a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java index 0e983ab959..2e3854cb2b 100644 --- a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java +++ b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java @@ -50,6 +50,7 @@ import org.openqa.selenium.interactions.Keyboard; import org.openqa.selenium.interactions.Mouse; import org.openqa.selenium.interactions.internal.Coordinates; import org.openqa.selenium.internal.Locatable; +import org.openqa.selenium.internal.WrapsElement; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.HttpCommandExecutor; import org.openqa.selenium.remote.RemoteWebDriver; @@ -1176,4 +1177,22 @@ public abstract class AbstractTB3Test extends ParallelTest { return ((Number) executeScript(script, e)).intValue(); } + + protected void assertElementsEquals(WebElement expectedElement, + WebElement actualElement) { + while (expectedElement instanceof WrapsElement) { + expectedElement = ((WrapsElement) expectedElement) + .getWrappedElement(); + } + while (actualElement instanceof WrapsElement) { + actualElement = ((WrapsElement) actualElement).getWrappedElement(); + } + + Assert.assertEquals(expectedElement, actualElement); + } + + protected WebElement getActiveElement() { + return (WebElement) executeScript("return document.activeElement;"); + + } } |