Browse Source

Read browser width and height from request in Page.init (#9073)

* Also change default screen width and height in WebBrowser to -1 for consistency
* Test for reading browser details in UI.init

Change-Id: I24339fd3742857392e1fc768696eeb2fb5551a90
tags/7.0.0.beta10
Johannes Dahlström 11 years ago
parent
commit
977c8b01c0

+ 15
- 3
server/src/com/vaadin/server/Page.java View 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() {

+ 3
- 3
server/src/com/vaadin/server/WebBrowser.java View 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) {

+ 112
- 0
uitest/src/com/vaadin/tests/components/ui/UIInitBrowserDetails.html View File

@@ -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>

+ 56
- 0
uitest/src/com/vaadin/tests/components/ui/UIInitBrowserDetails.java View File

@@ -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));
}
}

Loading…
Cancel
Save