From 292b0fc7f0ddd404dc2bcd060a949589870e641e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Teemu=20P=C3=B6ntelin?= Date: Sun, 3 Apr 2016 23:22:48 +0300 Subject: [PATCH] Prevent closing of uncloseable Window on esc (#19700) Change-Id: I4d67cd84c6f4179da6d6fea6b881e8ccd65e70d9 --- server/src/com/vaadin/ui/Window.java | 4 +- .../UncloseableWindowCloseShortcut.java | 46 +++++++++++++++++++ .../UncloseableWindowCloseShortcutTest.java | 45 ++++++++++++++++++ 3 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 uitest/src/com/vaadin/tests/components/window/UncloseableWindowCloseShortcut.java create mode 100644 uitest/src/com/vaadin/tests/components/window/UncloseableWindowCloseShortcutTest.java diff --git a/server/src/com/vaadin/ui/Window.java b/server/src/com/vaadin/ui/Window.java index b5cd384f53..70399ae566 100644 --- a/server/src/com/vaadin/ui/Window.java +++ b/server/src/com/vaadin/ui/Window.java @@ -1051,7 +1051,9 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, @Override public void handleAction(Object sender, Object target) { - window.close(); + if (window.isClosable()) { + window.close(); + } } public boolean equals(int keyCode, int... modifiers) { diff --git a/uitest/src/com/vaadin/tests/components/window/UncloseableWindowCloseShortcut.java b/uitest/src/com/vaadin/tests/components/window/UncloseableWindowCloseShortcut.java new file mode 100644 index 0000000000..1db8e0c87b --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/window/UncloseableWindowCloseShortcut.java @@ -0,0 +1,46 @@ +/* + * 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.AbstractTestUI; +import com.vaadin.ui.Label; +import com.vaadin.ui.Window; + +public class UncloseableWindowCloseShortcut extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Window uncloseable = new Window("Uncloseable", + new Label("Try and close me with esc")); + uncloseable.setClosable(false); + addWindow(uncloseable); + + uncloseable.center(); + uncloseable.focus(); + } + + @Override + protected String getTestDescription() { + return "An uncloseable Window should not be closed with esc key."; + } + + @Override + protected Integer getTicketNumber() { + return 19700; + } + +} diff --git a/uitest/src/com/vaadin/tests/components/window/UncloseableWindowCloseShortcutTest.java b/uitest/src/com/vaadin/tests/components/window/UncloseableWindowCloseShortcutTest.java new file mode 100644 index 0000000000..4574e7b3eb --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/window/UncloseableWindowCloseShortcutTest.java @@ -0,0 +1,45 @@ +/* + * 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 static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.openqa.selenium.Keys; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.WindowElement; +import com.vaadin.tests.tb3.SingleBrowserTest; + +public class UncloseableWindowCloseShortcutTest extends SingleBrowserTest { + + @Test + public void testEscShortcut() { + openTestURL(); + + // Hit esc and verify that the Window was not closed. + driver.findElement(By.cssSelector(".v-window-contents .v-scrollable")) + .sendKeys(Keys.ESCAPE); + assertTrue( + "Uncloseable Window should remain open after esc is pressed.", + isWindowOpen()); + } + + private boolean isWindowOpen() { + return $(WindowElement.class).exists(); + } + +} -- 2.39.5