From e4bcd53d8c08542981afd645a4be7f0ef3f726ef Mon Sep 17 00:00:00 2001 From: Denis Anisimov Date: Sat, 20 Sep 2014 12:48:50 +0300 Subject: Notification should be closed after delay (#14689). onEventPreview() method is deprecated and it's called now only for the very first handler. We need it to work for any handler. So old onEventPreview() method is explicitly called with updated logic for the onPreviewNativeEvent(). Change-Id: I11d98ef0bbd284b74bbccb4f6ac2ab26de73f209 --- client/src/com/vaadin/client/ui/VNotification.java | 15 ++++++ .../components/notification/NotificationDelay.java | 48 ++++++++++++++++++ .../notification/NotificationDelayTest.java | 57 ++++++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/components/notification/NotificationDelay.java create mode 100644 uitest/src/com/vaadin/tests/components/notification/NotificationDelayTest.java diff --git a/client/src/com/vaadin/client/ui/VNotification.java b/client/src/com/vaadin/client/ui/VNotification.java index 1df58bb38f..5e1df67e18 100644 --- a/client/src/com/vaadin/client/ui/VNotification.java +++ b/client/src/com/vaadin/client/ui/VNotification.java @@ -27,6 +27,7 @@ import com.google.gwt.dom.client.NativeEvent; import com.google.gwt.event.dom.client.KeyCodes; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Event; +import com.google.gwt.user.client.Event.NativePreviewEvent; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.ui.FlowPanel; import com.google.gwt.user.client.ui.HTML; @@ -388,6 +389,20 @@ public class VNotification extends VOverlay { hide(); } + @Override + /* + * Fix for #14689: {@link #onEventPreview(Event)} method is deprecated and + * it's called now only for the very first handler (see super impl). We need + * it to work for any handler. So let's call old {@link + * #onEventPreview(Event)} method explicitly with updated logic for {@link + * #onPreviewNativeEvent(Event)}. + */ + protected void onPreviewNativeEvent(NativePreviewEvent event) { + if (!onEventPreview(Event.as(event.getNativeEvent()))) { + event.cancel(); + } + } + @Override public boolean onEventPreview(Event event) { int type = DOM.eventGetType(event); diff --git a/uitest/src/com/vaadin/tests/components/notification/NotificationDelay.java b/uitest/src/com/vaadin/tests/components/notification/NotificationDelay.java new file mode 100644 index 0000000000..c0db1703bb --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/notification/NotificationDelay.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.notification; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Notification; +import com.vaadin.ui.Notification.Type; + +/** + * UI for notification delay test. + * + * @author Vaadin Ltd + */ +public class NotificationDelay extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Notification notification = new Notification("Foo", + Type.HUMANIZED_MESSAGE); + notification.setDelayMsec(500); + notification.show(getPage()); + } + + @Override + protected String getTestDescription() { + return "Notification should be closed after delay"; + } + + @Override + protected Integer getTicketNumber() { + return 14689; + } + +} diff --git a/uitest/src/com/vaadin/tests/components/notification/NotificationDelayTest.java b/uitest/src/com/vaadin/tests/components/notification/NotificationDelayTest.java new file mode 100644 index 0000000000..219d44710c --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/notification/NotificationDelayTest.java @@ -0,0 +1,57 @@ +/* + * 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.notification; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Test to check notification delay. + * + * @author Vaadin Ltd + */ +public class NotificationDelayTest extends MultiBrowserTest { + + @Test + public void testDelay() throws InterruptedException { + openTestURL(); + + Assert.assertTrue("No notification found", hasNotification()); + Actions actions = new Actions(getDriver()); + actions.moveByOffset(10, 10).build().perform(); + long start = System.currentTimeMillis(); + boolean hidden = false; + while (System.currentTimeMillis() <= start + 5000) { + Thread.sleep(500); + hidden = !hasNotification(); + if (hidden) { + break; + } + } + + Assert.assertTrue("Notification is still visible after 5 seconds", + hidden); + } + + private boolean hasNotification() { + return isElementPresent(By.className("v-Notification")); + } + +} -- cgit v1.2.3