diff options
author | Artur Signell <artur@vaadin.com> | 2016-04-15 18:39:10 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2016-04-18 11:34:44 +0000 |
commit | 871960c70866e3c70eeaedfa20b1a1b6917f68fa (patch) | |
tree | 6638d0f5b57c4f00609f2337a9cfa58d570f898d /uitest/src | |
parent | acba4ff413db5a6e68b85c4e7dd72d76cc7367f6 (diff) | |
download | vaadin-framework-871960c70866e3c70eeaedfa20b1a1b6917f68fa.tar.gz vaadin-framework-871960c70866e3c70eeaedfa20b1a1b6917f68fa.zip |
Only handle shortcuts targeted for UI or body element (#19498)
Change-Id: I796d7e4ac94db1b2b9d8698e9753a5be007a1c8c
Diffstat (limited to 'uitest/src')
-rw-r--r-- | uitest/src/com/vaadin/tests/components/ui/WindowAndUIShortcuts.java | 76 | ||||
-rw-r--r-- | uitest/src/com/vaadin/tests/components/ui/WindowAndUIShortcutsTest.java | 43 |
2 files changed, 119 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/components/ui/WindowAndUIShortcuts.java b/uitest/src/com/vaadin/tests/components/ui/WindowAndUIShortcuts.java new file mode 100644 index 0000000000..c5c9c16e2d --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/ui/WindowAndUIShortcuts.java @@ -0,0 +1,76 @@ +package com.vaadin.tests.components.ui; + +import com.vaadin.annotations.Theme; +import com.vaadin.event.ShortcutAction; +import com.vaadin.server.VaadinRequest; +import com.vaadin.ui.Button; +import com.vaadin.ui.Label; +import com.vaadin.ui.Notification; +import com.vaadin.ui.TextField; +import com.vaadin.ui.UI; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.Window; +import com.vaadin.ui.themes.ValoTheme; + +@Theme(ValoTheme.THEME_NAME) +public class WindowAndUIShortcuts extends UI { + + @Override + protected void init(VaadinRequest request) { + VerticalLayout layout = new VerticalLayout(); + layout.setSizeFull(); + layout.setMargin(true); + + final VerticalLayout mainLayout = new VerticalLayout(); + + mainLayout.addComponent(new Button("Show page", + new Button.ClickListener() { + @Override + public void buttonClick(Button.ClickEvent clickEvent) { + final VerticalLayout pageLayout = new VerticalLayout(); + pageLayout.setSpacing(true); + + pageLayout.addComponent(new Label("Page")); + pageLayout.addComponent(new Button( + "Open dialog window", + new Button.ClickListener() { + @Override + public void buttonClick( + Button.ClickEvent clickEvent) { + Window dialog = new Window(); + dialog.setModal(true); + dialog.setCaption("Press ESC shortcut"); + dialog.setWidth("300px"); + dialog.setHeight("100px"); + + dialog.setContent(new TextField( + "TextField in window")); + addWindow(dialog); + } + })); + Button closeButton = new Button("Close page", + new Button.ClickListener() { + @Override + public void buttonClick( + Button.ClickEvent clickEvent) { + mainLayout.removeComponent(pageLayout); + + Notification + .show("OMG! Page is also closed!"); + } + }); + closeButton + .setClickShortcut(ShortcutAction.KeyCode.ESCAPE); + pageLayout.addComponent(closeButton); + + mainLayout.addComponent(pageLayout); + mainLayout.setExpandRatio(pageLayout, 1); + } + })); + + layout.addComponent(mainLayout); + layout.setExpandRatio(mainLayout, 1); + + setContent(layout); + } +} diff --git a/uitest/src/com/vaadin/tests/components/ui/WindowAndUIShortcutsTest.java b/uitest/src/com/vaadin/tests/components/ui/WindowAndUIShortcutsTest.java new file mode 100644 index 0000000000..93324f0792 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/ui/WindowAndUIShortcutsTest.java @@ -0,0 +1,43 @@ +/* + * 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.ui; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.Keys; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.TextFieldElement; +import com.vaadin.testbench.elements.WindowElement; +import com.vaadin.tests.tb3.SingleBrowserTest; + +public class WindowAndUIShortcutsTest extends SingleBrowserTest { + + @Test + public void windowShortcutShouldNotReachUI() { + openTestURL(); + $(ButtonElement.class).caption("Show page").first().click(); + $(ButtonElement.class).caption("Open dialog window").first().click(); + + WindowElement window = $(WindowElement.class).first(); + window.$(TextFieldElement.class).first().sendKeys(Keys.ESCAPE); + + // Window should have been closed + Assert.assertTrue($(WindowElement.class).all().isEmpty()); + // "Close page" should not have been clicked + Assert.assertTrue($(ButtonElement.class).caption("Close page").exists()); + } +} |