Browse Source

Prevent closing of uncloseable Window on esc (#19700)

Change-Id: I4d67cd84c6f4179da6d6fea6b881e8ccd65e70d9
tags/7.7.0.alpha1
Teemu Pöntelin 8 years ago
parent
commit
9b46608f6c

+ 3
- 1
server/src/com/vaadin/ui/Window.java View File

@@ -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) {

+ 46
- 0
uitest/src/com/vaadin/tests/components/window/UncloseableWindowCloseShortcut.java View File

@@ -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;
}

}

+ 45
- 0
uitest/src/com/vaadin/tests/components/window/UncloseableWindowCloseShortcutTest.java View File

@@ -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();
}

}

Loading…
Cancel
Save