summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Anisimov <denis@vaadin.com>2014-09-20 12:48:50 +0300
committerVaadin Code Review <review@vaadin.com>2015-01-15 13:58:58 +0000
commit18c9f688ca78ec85133bda863de5c4069247b835 (patch)
treee2dddf5cfd2cd4cda16adcb1fda9d763514d65a5
parent9789826c1342a3c1e01cbe64f274d5eb504c2a6e (diff)
downloadvaadin-framework-18c9f688ca78ec85133bda863de5c4069247b835.tar.gz
vaadin-framework-18c9f688ca78ec85133bda863de5c4069247b835.zip
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
-rw-r--r--client/src/com/vaadin/client/ui/VNotification.java15
-rw-r--r--uitest/src/com/vaadin/tests/components/notification/NotificationDelay.java48
-rw-r--r--uitest/src/com/vaadin/tests/components/notification/NotificationDelayTest.java57
3 files changed, 120 insertions, 0 deletions
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;
@@ -389,6 +390,20 @@ public class VNotification extends VOverlay {
}
@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);
// "modal"
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"));
+ }
+
+}