]> source.dussan.org Git - vaadin-framework.git/commitdiff
Read browser width and height from request in Page.init (#9073) 83/283/2
authorJohannes Dahlström <johannesd@vaadin.com>
Fri, 16 Nov 2012 13:34:23 +0000 (15:34 +0200)
committerVaadin Code Review <review@vaadin.com>
Mon, 19 Nov 2012 09:57:16 +0000 (09:57 +0000)
* Also change default screen width and height in WebBrowser to -1 for consistency
* Test for reading browser details in UI.init

Change-Id: I24339fd3742857392e1fc768696eeb2fb5551a90

server/src/com/vaadin/server/Page.java
server/src/com/vaadin/server/WebBrowser.java
uitest/src/com/vaadin/tests/components/ui/UIInitBrowserDetails.html [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/ui/UIInitBrowserDetails.java [new file with mode: 0644]

index cf77c09324016ae1cc3ac0916096e0621fc64be0..501172f80ae75ee8ce9d3e0e75943ddc65334775 100644 (file)
@@ -436,15 +436,27 @@ public class Page implements Serializable {
 
     public void init(VaadinRequest request) {
         // Extract special parameter sent by vaadinBootstrap.js
-        String loc = request.getParameter("loc");
-        if (loc != null) {
+        String location = request.getParameter("loc");
+        String clientWidth = request.getParameter("cw");
+        String clientHeight = request.getParameter("ch");
+
+        if (location != null) {
             try {
-                location = new URI(loc);
+                this.location = new URI(location);
             } catch (URISyntaxException e) {
                 throw new RuntimeException(
                         "Invalid location URI received from client", e);
             }
         }
+        if (clientWidth != null && clientHeight != null) {
+            try {
+                browserWindowWidth = Integer.parseInt(clientWidth);
+                browserWindowHeight = Integer.parseInt(clientHeight);
+            } catch (NumberFormatException e) {
+                throw new RuntimeException(
+                        "Invalid window size received from client", e);
+            }
+        }
     }
 
     public WebBrowser getWebBrowser() {
index 676375a69397c41d20cf6e99a506f9685f16259d..4df535a39ac9de4b70283809b50c7b47b77d3a64 100644 (file)
@@ -32,8 +32,8 @@ import com.vaadin.shared.VBrowserDetails;
  */
 public class WebBrowser implements Serializable {
 
-    private int screenHeight = 0;
-    private int screenWidth = 0;
+    private int screenHeight = -1;
+    private int screenWidth = -1;
     private String browserApplication = null;
     private Locale locale;
     private String address;
@@ -364,7 +364,7 @@ public class WebBrowser implements Serializable {
                 screenHeight = Integer.parseInt(sh);
                 screenWidth = Integer.parseInt(sw);
             } catch (final NumberFormatException e) {
-                screenHeight = screenWidth = 0;
+                screenHeight = screenWidth = -1;
             }
         }
         if (tzo != null) {
diff --git a/uitest/src/com/vaadin/tests/components/ui/UIInitBrowserDetails.html b/uitest/src/com/vaadin/tests/components/ui/UIInitBrowserDetails.html
new file mode 100644 (file)
index 0000000..3fd7a0d
--- /dev/null
@@ -0,0 +1,112 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="http://localhost:8070/" />
+<title>UIInitBrowserDetails</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">UIInitBrowserDetails</td></tr>
+</thead><tbody>
+<tr>
+       <td>open</td>
+       <td>/run/UIInitBrowserDetails?restartApplication</td>
+       <td></td>
+</tr>
+<!--location-->
+<tr>
+       <td>assertNotText</td>
+       <td>vaadin=runUIInitBrowserDetails::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VGridLayout[0]/VLabel[4]</td>
+       <td>null</td>
+</tr>
+<tr>
+       <td>assertNotText</td>
+       <td>vaadin=runUIInitBrowserDetails::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VGridLayout[0]/VLabel[2]</td>
+       <td>null</td>
+</tr>
+<!--browser window width-->
+<tr>
+       <td>assertNotText</td>
+       <td>vaadin=runUIInitBrowserDetails::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VGridLayout[0]/VLabel[4]</td>
+       <td>null</td>
+</tr>
+<tr>
+       <td>assertNotText</td>
+       <td>vaadin=runUIInitBrowserDetails::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VGridLayout[0]/VLabel[5]</td>
+       <td>-1</td>
+</tr>
+<!--browser window height-->
+<tr>
+       <td>assertNotText</td>
+       <td>vaadin=runUIInitBrowserDetails::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VGridLayout[0]/VLabel[10]</td>
+       <td>null</td>
+</tr>
+<tr>
+       <td>assertNotText</td>
+       <td>vaadin=runUIInitBrowserDetails::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VGridLayout[0]/VLabel[8]</td>
+       <td>-1</td>
+</tr>
+<!--screen width-->
+<tr>
+       <td>assertNotText</td>
+       <td>vaadin=runUIInitBrowserDetails::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VGridLayout[0]/VLabel[10]</td>
+       <td>null</td>
+</tr>
+<tr>
+       <td>assertNotText</td>
+       <td>vaadin=runUIInitBrowserDetails::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VGridLayout[0]/VLabel[11]</td>
+       <td>-1</td>
+</tr>
+<!--screen height-->
+<tr>
+       <td>assertNotText</td>
+       <td>vaadin=runUIInitBrowserDetails::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VGridLayout[0]/VLabel[13]</td>
+       <td>null</td>
+</tr>
+<tr>
+       <td>assertNotText</td>
+       <td>vaadin=runUIInitBrowserDetails::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VGridLayout[0]/VLabel[14]</td>
+       <td>-1</td>
+</tr>
+<!--timezone offset-->
+<tr>
+       <td>assertNotText</td>
+       <td>vaadin=runUIInitBrowserDetails::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VGridLayout[0]/VLabel[16]</td>
+       <td>null</td>
+</tr>
+<!--raw timezone offset-->
+<tr>
+       <td>assertNotText</td>
+       <td>vaadin=runUIInitBrowserDetails::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VGridLayout[0]/VLabel[19]</td>
+       <td>null</td>
+</tr>
+<!--dst saving-->
+<tr>
+       <td>assertNotText</td>
+       <td>vaadin=runUIInitBrowserDetails::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VGridLayout[0]/VLabel[22]</td>
+       <td>null</td>
+</tr>
+<!--dst in effect-->
+<tr>
+       <td>assertNotText</td>
+       <td>vaadin=runUIInitBrowserDetails::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VGridLayout[0]/VLabel[25]</td>
+       <td>null</td>
+</tr>
+<!--current date-->
+<tr>
+       <td>assertNotText</td>
+       <td>vaadin=runUIInitBrowserDetails::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VGridLayout[0]/VLabel[28]</td>
+       <td>null</td>
+</tr>
+<tr>
+       <td>assertNotText</td>
+       <td>vaadin=runUIInitBrowserDetails::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VGridLayout[0]/VLabel[29]</td>
+       <td>null</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
diff --git a/uitest/src/com/vaadin/tests/components/ui/UIInitBrowserDetails.java b/uitest/src/com/vaadin/tests/components/ui/UIInitBrowserDetails.java
new file mode 100644 (file)
index 0000000..587c9f0
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+@VaadinApache2LicenseForJavaFiles@
+ */
+
+package com.vaadin.tests.components.ui;
+
+import com.vaadin.server.Page;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.server.WebBrowser;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.GridLayout;
+import com.vaadin.ui.Label;
+
+public class UIInitBrowserDetails extends AbstractTestUI {
+
+    private GridLayout l = new GridLayout(3, 1);
+    private VaadinRequest r;
+
+    @Override
+    protected void setup(VaadinRequest request) {
+        r = request;
+        l.setWidth("100%");
+        addComponent(l);
+
+        Page p = getPage();
+        WebBrowser wb = p.getWebBrowser();
+
+        addDetail("location", "loc", p.getLocation());
+
+        addDetail("browser window width", "cw", p.getBrowserWindowWidth());
+        addDetail("browser window height", "ch", p.getBrowserWindowHeight());
+        addDetail("screen width", "sw", wb.getScreenWidth());
+        addDetail("screen height", "sh", wb.getScreenHeight());
+
+        addDetail("timezone offset", "tzo", wb.getTimezoneOffset());
+        addDetail("raw timezone offset", "rtzo", wb.getRawTimezoneOffset());
+        addDetail("dst saving", "dstd", wb.getDSTSavings());
+        addDetail("dst in effect", "dston", wb.isDSTInEffect());
+        addDetail("current date", "curdate", wb.getCurrentDate());
+    }
+
+    @Override
+    public String getTestDescription() {
+        return "Browser details should be available in UI init";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return Integer.valueOf(9037);
+    }
+
+    private void addDetail(String name, String param, Object value) {
+        l.addComponents(new Label(name), new Label(r.getParameter(param)),
+                new Label("" + value));
+    }
+}