summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorDenis Anisimov <denis@vaadin.com>2014-10-04 11:32:32 +0300
committerMarkus Koivisto <markus@vaadin.com>2014-10-14 17:59:49 +0300
commit041a1e2181c769942795517fd0b6a9a57fa7b764 (patch)
tree0ba68a9808b1104da44e61743240c290b3eff725 /server
parent26b205d25230b7402e73a0202ed145373eae4bf3 (diff)
downloadvaadin-framework-041a1e2181c769942795517fd0b6a9a57fa7b764.tar.gz
vaadin-framework-041a1e2181c769942795517fd0b6a9a57fa7b764.zip
Check eventRouter value against null in Page class (#14803).
Change-Id: Ia7dd54c4cf10a2c56a5ef36864a6bb94f1d9167f
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/server/Page.java13
-rw-r--r--server/tests/src/com/vaadin/server/PageTest.java92
2 files changed, 100 insertions, 5 deletions
diff --git a/server/src/com/vaadin/server/Page.java b/server/src/com/vaadin/server/Page.java
index 3acea97c0f..3ddf4862b2 100644
--- a/server/src/com/vaadin/server/Page.java
+++ b/server/src/com/vaadin/server/Page.java
@@ -485,14 +485,14 @@ public class Page implements Serializable {
}
private void addListener(Class<?> eventType, Object target, Method method) {
- if (eventRouter == null) {
+ if (!hasEventRouter()) {
eventRouter = new EventRouter();
}
eventRouter.addListener(eventType, target, method);
}
private void removeListener(Class<?> eventType, Object target, Method method) {
- if (eventRouter != null) {
+ if (hasEventRouter()) {
eventRouter.removeListener(eventType, target, method);
}
}
@@ -599,7 +599,7 @@ public class Page implements Serializable {
}
private void fireEvent(EventObject event) {
- if (eventRouter != null) {
+ if (hasEventRouter()) {
eventRouter.fireEvent(event);
}
}
@@ -776,8 +776,8 @@ public class Page implements Serializable {
BrowserWindowResizeListener resizeListener) {
removeListener(BrowserWindowResizeEvent.class, resizeListener,
BROWSER_RESIZE_METHOD);
- getState(true).hasResizeListeners = eventRouter
- .hasListeners(BrowserWindowResizeEvent.class);
+ getState(true).hasResizeListeners = hasEventRouter()
+ && eventRouter.hasListeners(BrowserWindowResizeEvent.class);
}
/**
@@ -1242,4 +1242,7 @@ public class Page implements Serializable {
return state;
}
+ private boolean hasEventRouter() {
+ return eventRouter != null;
+ }
}
diff --git a/server/tests/src/com/vaadin/server/PageTest.java b/server/tests/src/com/vaadin/server/PageTest.java
new file mode 100644
index 0000000000..b782b1f67d
--- /dev/null
+++ b/server/tests/src/com/vaadin/server/PageTest.java
@@ -0,0 +1,92 @@
+/*
+ * 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.server;
+
+import org.easymock.EasyMock;
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.server.Page.BrowserWindowResizeEvent;
+import com.vaadin.server.Page.BrowserWindowResizeListener;
+import com.vaadin.shared.ui.ui.PageState;
+import com.vaadin.ui.UI;
+
+/**
+ *
+ * Tests for {@link Page}
+ *
+ * @author Vaadin Ltd
+ */
+public class PageTest {
+
+ @Test
+ public void removeBrowserWindowResizeListener_listenerIsAttached_listenerRemoved() {
+ Page page = new Page(EasyMock.createMock(UI.class),
+ EasyMock.createMock(PageState.class));
+
+ TestBrowserWindowResizeListener listener = new TestBrowserWindowResizeListener();
+ page.addBrowserWindowResizeListener(listener);
+ page.removeBrowserWindowResizeListener(listener);
+
+ page.updateBrowserWindowSize(0, 0, true);
+
+ Assert.assertFalse("Listener is called after removal",
+ listener.isCalled());
+ }
+
+ @Test
+ public void removeBrowserWindowResizeListener_listenerIsNotAttached_stateIsUpdated() {
+ TestPage page = new TestPage(EasyMock.createMock(UI.class),
+ EasyMock.createMock(PageState.class));
+
+ BrowserWindowResizeListener listener = EasyMock
+ .createMock(BrowserWindowResizeListener.class);
+ page.removeBrowserWindowResizeListener(listener);
+
+ Assert.assertFalse(
+ "Page state 'hasResizeListeners' property has wrong value",
+ page.getState(false).hasResizeListeners);
+ }
+
+ private static class TestPage extends Page {
+
+ public TestPage(UI uI, PageState state) {
+ super(uI, state);
+ }
+
+ @Override
+ protected PageState getState(boolean markAsDirty) {
+ return super.getState(markAsDirty);
+ }
+
+ }
+
+ private static class TestBrowserWindowResizeListener implements
+ BrowserWindowResizeListener {
+
+ @Override
+ public void browserWindowResized(BrowserWindowResizeEvent event) {
+ isCalled = true;
+ }
+
+ public boolean isCalled() {
+ return isCalled;
+ }
+
+ private boolean isCalled;
+
+ }
+}