summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2014-04-08 16:56:50 +0300
committerVaadin Code Review <review@vaadin.com>2014-04-14 13:36:31 +0000
commite033fcda3537290a2db1b33ab5e7d5264639f1bb (patch)
treecc7d0e90b25919602d7dc89498fc9630ac3b94aa
parent168de1fefa0f09b07d438968575033e6d234cfb2 (diff)
downloadvaadin-framework-e033fcda3537290a2db1b33ab5e7d5264639f1bb.tar.gz
vaadin-framework-e033fcda3537290a2db1b33ab5e7d5264639f1bb.zip
Always initialize WebBrowser for new sessions (#13571)
Change-Id: I3918498d63032f6b507b52634df5b41470363e15
-rw-r--r--server/src/com/vaadin/server/BootstrapHandler.java4
-rw-r--r--server/src/com/vaadin/server/VaadinService.java3
-rw-r--r--server/src/com/vaadin/server/communication/UIInitHandler.java2
-rw-r--r--uitest/src/com/vaadin/tests/requesthandlers/UnsupportedBrowserHandlerUserAgents.java76
-rw-r--r--uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java31
5 files changed, 105 insertions, 11 deletions
diff --git a/server/src/com/vaadin/server/BootstrapHandler.java b/server/src/com/vaadin/server/BootstrapHandler.java
index 0a4949ffa7..60b4459d2a 100644
--- a/server/src/com/vaadin/server/BootstrapHandler.java
+++ b/server/src/com/vaadin/server/BootstrapHandler.java
@@ -155,10 +155,6 @@ public abstract class BootstrapHandler extends SynchronizedRequestHandler {
}
try {
- // Update WebBrowser here only to make WebBrowser information
- // available in init for LegacyApplications
- session.getBrowser().updateRequestDetails(request);
-
List<UIProvider> uiProviders = session.getUIProviders();
UIClassSelectionEvent classSelectionEvent = new UIClassSelectionEvent(
diff --git a/server/src/com/vaadin/server/VaadinService.java b/server/src/com/vaadin/server/VaadinService.java
index eda794438f..b26097a247 100644
--- a/server/src/com/vaadin/server/VaadinService.java
+++ b/server/src/com/vaadin/server/VaadinService.java
@@ -735,6 +735,9 @@ public abstract class VaadinService implements Serializable {
session.storeInSession(this, request.getWrappedSession());
+ // Initial WebBrowser data comes from the request
+ session.getBrowser().updateRequestDetails(request);
+
// Initial locale comes from the request
Locale locale = request.getLocale();
session.setLocale(locale);
diff --git a/server/src/com/vaadin/server/communication/UIInitHandler.java b/server/src/com/vaadin/server/communication/UIInitHandler.java
index d4b0bc709f..9f299d9427 100644
--- a/server/src/com/vaadin/server/communication/UIInitHandler.java
+++ b/server/src/com/vaadin/server/communication/UIInitHandler.java
@@ -67,7 +67,7 @@ public abstract class UIInitHandler extends SynchronizedRequestHandler {
try {
assert UI.getCurrent() == null;
- // Set browser information from the request
+ // Update browser information from the request
session.getBrowser().updateRequestDetails(request);
UI uI = getBrowserDetailsUI(request, session);
diff --git a/uitest/src/com/vaadin/tests/requesthandlers/UnsupportedBrowserHandlerUserAgents.java b/uitest/src/com/vaadin/tests/requesthandlers/UnsupportedBrowserHandlerUserAgents.java
new file mode 100644
index 0000000000..9147d0fe50
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/requesthandlers/UnsupportedBrowserHandlerUserAgents.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2000-2013 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.requesthandlers;
+
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import org.apache.commons.io.IOUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.tests.tb3.PrivateTB3Configuration;
+
+public class UnsupportedBrowserHandlerUserAgents {
+ /*
+ * This test doesn't use testbench, but it's still in the uitest source
+ * folder since it should be run with the testing server deployed.
+ */
+
+ @Test
+ public void ie7NotSupported() {
+ String response = requestWithUserAgent("Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 5.2; WOW64; .NET CLR 2.0.50727)");
+ Assert.assertTrue("IE7 should not be supported",
+ response.contains("your browser is not supported"));
+ }
+
+ @Test
+ public void ie9Supported() {
+ String response = requestWithUserAgent("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 7.1; Trident/5.0)");
+ Assert.assertFalse("IE9 should be supported",
+ response.contains("your browser is not supported"));
+ }
+
+ @Test
+ public void unknownSupported() {
+ String response = requestWithUserAgent("Very strange user agent, like wat");
+ Assert.assertFalse("Unkonwn user agent should be supported",
+ response.contains("your browser is not supported"));
+ }
+
+ private String requestWithUserAgent(String userAgent) {
+ try {
+ String url = "http://"
+ + PrivateTB3Configuration.getConfiguredDeploymentHostname()
+ + ":"
+ + PrivateTB3Configuration.getConfiguredDeploymentPort()
+ + "/run/"
+ + com.vaadin.tests.components.ui.UIInitTest.class.getName()
+ + "/";
+
+ HttpURLConnection connection = (HttpURLConnection) new URL(url)
+ .openConnection();
+ connection.setRequestProperty("User-Agent", userAgent);
+
+ String response = IOUtils.toString(connection.getInputStream());
+ connection.disconnect();
+
+ return response;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java b/uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java
index 400a2fe429..97150f96ab 100644
--- a/uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java
+++ b/uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java
@@ -25,6 +25,7 @@ import java.net.SocketException;
import java.util.Enumeration;
import java.util.Properties;
+import org.apache.commons.io.IOUtils;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxBinary;
@@ -44,9 +45,8 @@ import com.vaadin.testbench.TestBench;
public abstract class PrivateTB3Configuration extends ScreenshotTB3Test {
private static final String HOSTNAME_PROPERTY = "com.vaadin.testbench.deployment.hostname";
private static final String PORT_PROPERTY = "com.vaadin.testbench.deployment.port";
- private final Properties properties = new Properties();
-
- public PrivateTB3Configuration() {
+ private static final Properties properties = new Properties();
+ static {
File file = new File("work", "eclipse-run-selected-test.properties");
if (file.exists()) {
try {
@@ -57,7 +57,7 @@ public abstract class PrivateTB3Configuration extends ScreenshotTB3Test {
}
}
- private String getProperty(String name) {
+ private static String getProperty(String name) {
String property = properties.getProperty(name);
if (property == null) {
property = System.getProperty(name);
@@ -86,6 +86,15 @@ public abstract class PrivateTB3Configuration extends ScreenshotTB3Test {
if (getClass().getAnnotation(RunLocally.class) != null) {
return "localhost";
}
+ return getConfiguredDeploymentHostname();
+ }
+
+ /**
+ * Gets the hostname that tests are configured to use.
+ *
+ * @return the host name configuration value
+ */
+ public static String getConfiguredDeploymentHostname() {
String hostName = getProperty(HOSTNAME_PROPERTY);
if (hostName == null || "".equals(hostName)) {
@@ -97,6 +106,15 @@ public abstract class PrivateTB3Configuration extends ScreenshotTB3Test {
@Override
protected int getDeploymentPort() {
+ return getConfiguredDeploymentPort();
+ }
+
+ /**
+ * Gets the port that tests are configured to use.
+ *
+ * @return the port configuration value
+ */
+ public static int getConfiguredDeploymentPort() {
String portString = getProperty(PORT_PROPERTY);
int port = 8888;
@@ -115,7 +133,7 @@ public abstract class PrivateTB3Configuration extends ScreenshotTB3Test {
* @throws RuntimeException
* if there was an error or no IP was found
*/
- private String findAutoHostname() {
+ private static String findAutoHostname() {
try {
Enumeration<NetworkInterface> interfaces = NetworkInterface
.getNetworkInterfaces();
@@ -125,7 +143,8 @@ public abstract class PrivateTB3Configuration extends ScreenshotTB3Test {
|| nwInterface.isVirtual()) {
continue;
}
- Enumeration<InetAddress> addresses = nwInterface.getInetAddresses();
+ Enumeration<InetAddress> addresses = nwInterface
+ .getInetAddresses();
while (addresses.hasMoreElements()) {
InetAddress address = addresses.nextElement();
if (address.isLoopbackAddress()) {