]> source.dussan.org Git - vaadin-framework.git/commitdiff
Always initialize WebBrowser for new sessions (#13571)
authorLeif Åstrand <leif@vaadin.com>
Tue, 8 Apr 2014 13:56:50 +0000 (16:56 +0300)
committerVaadin Code Review <review@vaadin.com>
Mon, 14 Apr 2014 13:36:31 +0000 (13:36 +0000)
Change-Id: I3918498d63032f6b507b52634df5b41470363e15

server/src/com/vaadin/server/BootstrapHandler.java
server/src/com/vaadin/server/VaadinService.java
server/src/com/vaadin/server/communication/UIInitHandler.java
uitest/src/com/vaadin/tests/requesthandlers/UnsupportedBrowserHandlerUserAgents.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java

index 0a4949ffa7e0deef146fd7fe2ae73dded5b9ab94..60b4459d2ae2899e8258f69163d3205508823a59 100644 (file)
@@ -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(
index eda794438f6518a3d05e5f0d2b1dad30e492f297..b26097a247cf86942c5030de0218c0cafd1081ea 100644 (file)
@@ -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);
index d4b0bc709ffd14ee3b9fa84294f8f8976c547712..9f299d9427c1a184c2d7880c5cad75cda0873a2b 100644 (file)
@@ -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 (file)
index 0000000..9147d0f
--- /dev/null
@@ -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);
+        }
+    }
+}
index 400a2fe429a423fa5042b152565bb1fe2e734c32..97150f96abc4c5294bdedafe2ad2ee8c57d42901 100644 (file)
@@ -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()) {