summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2011-12-16 14:44:54 +0200
committerLeif Åstrand <leif@vaadin.com>2011-12-16 14:44:54 +0200
commit2a4728ae31a6d4d144820b75c5cb68b21f7ddcf4 (patch)
tree027fe584a8e912ea52abeb5194a5ede256fe1a22 /tests
parentdd2d3e55e51933ee5759eebe97da026a7eadd08f (diff)
downloadvaadin-framework-2a4728ae31a6d4d144820b75c5cb68b21f7ddcf4.tar.gz
vaadin-framework-2a4728ae31a6d4d144820b75c5cb68b21f7ddcf4.zip
Test for #7895 and #7896
Diffstat (limited to 'tests')
-rw-r--r--tests/testbench/com/vaadin/tests/application/ThreadLocalInstances.html112
-rw-r--r--tests/testbench/com/vaadin/tests/application/ThreadLocalInstances.java114
2 files changed, 226 insertions, 0 deletions
diff --git a/tests/testbench/com/vaadin/tests/application/ThreadLocalInstances.html b/tests/testbench/com/vaadin/tests/application/ThreadLocalInstances.html
new file mode 100644
index 0000000000..9f16ef5ce2
--- /dev/null
+++ b/tests/testbench/com/vaadin/tests/application/ThreadLocalInstances.html
@@ -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="" />
+<title>New Test</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">New Test</td></tr>
+</thead><tbody>
+<tr>
+ <td>open</td>
+ <td>/run/com.vaadin.tests.application.ThreadLocalInstances?restartApplication</td>
+ <td></td>
+</tr>
+<tr>
+ <td>waitForElementHeight</td>
+ <td>vaadin=runcomvaadintestsapplicationThreadLocalInstances::/VVerticalLayout[0]/ChildComponentContainer[1]/VEmbedded[0]/domChild[0]</td>
+ <td>11</td>
+</tr>
+<tr>
+ <td>click</td>
+ <td>vaadin=runcomvaadintestsapplicationThreadLocalInstances::/VVerticalLayout[0]/ChildComponentContainer[2]/VButton[0]/domChild[0]/domChild[0]</td>
+ <td></td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestsapplicationThreadLocalInstances::PID_SLog_row_15</td>
+ <td>1. null app in class init</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestsapplicationThreadLocalInstances::PID_SLog_row_14</td>
+ <td>2. null root in class init</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestsapplicationThreadLocalInstances::PID_SLog_row_13</td>
+ <td>3. null app in app constructor</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestsapplicationThreadLocalInstances::PID_SLog_row_12</td>
+ <td>4. null root in app constructor</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestsapplicationThreadLocalInstances::PID_SLog_row_11</td>
+ <td>5. this app in app init</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestsapplicationThreadLocalInstances::PID_SLog_row_10</td>
+ <td>6. null root in app init</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestsapplicationThreadLocalInstances::PID_SLog_row_9</td>
+ <td>7. this app in root init</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestsapplicationThreadLocalInstances::PID_SLog_row_8</td>
+ <td>8. null root in root init</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestsapplicationThreadLocalInstances::PID_SLog_row_7</td>
+ <td>9. this app in root paint</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestsapplicationThreadLocalInstances::PID_SLog_row_6</td>
+ <td>10. this root in root paint</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestsapplicationThreadLocalInstances::PID_SLog_row_5</td>
+ <td>11. null app in background thread</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestsapplicationThreadLocalInstances::PID_SLog_row_4</td>
+ <td>12. null root in background thread</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestsapplicationThreadLocalInstances::PID_SLog_row_3</td>
+ <td>13. this app in resource handler</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestsapplicationThreadLocalInstances::PID_SLog_row_2</td>
+ <td>14. null root in resource handler</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestsapplicationThreadLocalInstances::PID_SLog_row_1</td>
+ <td>15. this app in button listener</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestsapplicationThreadLocalInstances::PID_SLog_row_0</td>
+ <td>16. this root in button listener</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
diff --git a/tests/testbench/com/vaadin/tests/application/ThreadLocalInstances.java b/tests/testbench/com/vaadin/tests/application/ThreadLocalInstances.java
new file mode 100644
index 0000000000..bb05853b5b
--- /dev/null
+++ b/tests/testbench/com/vaadin/tests/application/ThreadLocalInstances.java
@@ -0,0 +1,114 @@
+package com.vaadin.tests.application;
+
+import com.vaadin.Application;
+import com.vaadin.RootRequiresMoreInformation;
+import com.vaadin.terminal.ApplicationResource;
+import com.vaadin.terminal.DownloadStream;
+import com.vaadin.terminal.PaintException;
+import com.vaadin.terminal.WrappedRequest;
+import com.vaadin.tests.components.AbstractTestApplication;
+import com.vaadin.tests.integration.FlagSeResource;
+import com.vaadin.tests.util.Log;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Embedded;
+import com.vaadin.ui.Root;
+
+public class ThreadLocalInstances extends AbstractTestApplication {
+ private static final Application staticInitApplication = Application
+ .getCurrentApplication();
+ private static final Root staticInitRoot = Root.getCurrentRoot();
+
+ private final Root mainWindow = new Root() {
+ boolean paintReported = false;
+
+ @Override
+ protected void init(WrappedRequest request) {
+ reportCurrentStatus("root init");
+ }
+
+ @Override
+ public void paintContent(com.vaadin.terminal.PaintTarget target)
+ throws PaintException {
+ if (!paintReported) {
+ reportCurrentStatus("root paint");
+ Thread thread = new Thread() {
+ @Override
+ public void run() {
+ synchronized (ThreadLocalInstances.this) {
+ reportCurrentStatus("background thread");
+ }
+ }
+ };
+ thread.start();
+ paintReported = true;
+ }
+ super.paintContent(target);
+ }
+ };
+
+ private final ApplicationResource resource = new FlagSeResource(this) {
+ @Override
+ public DownloadStream getStream() {
+ reportCurrentStatus("resource handler");
+ return super.getStream();
+ }
+ };
+
+ private final Log log = new Log(16);
+
+ public ThreadLocalInstances() {
+ mainWindow.addComponent(log);
+ mainWindow.addComponent(new Embedded("Icon", resource));
+ mainWindow.addComponent(new Button("Sync", new Button.ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ reportCurrentStatus("button listener");
+ }
+ }));
+
+ reportStatus("class init", staticInitApplication, staticInitRoot);
+ reportCurrentStatus("app constructor");
+ }
+
+ @Override
+ public void init() {
+ reportCurrentStatus("app init");
+ }
+
+ @Override
+ protected Root getRoot(WrappedRequest request)
+ throws RootRequiresMoreInformation {
+ return mainWindow;
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Tests the precence of Application.getCurrentApplication() and Root.getCurrentRoot() from different contexts";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return Integer.valueOf(7895);
+ }
+
+ private void reportCurrentStatus(String phase) {
+ reportStatus(phase, Application.getCurrentApplication(),
+ Root.getCurrentRoot());
+ }
+
+ private void reportStatus(String phase, Application application, Root root) {
+ log.log(getState(application, this) + " app in " + phase);
+ log.log(getState(root, mainWindow) + " root in " + phase);
+ }
+
+ private static String getState(Object value, Object reference) {
+ if (value == null) {
+ return "null";
+ } else if (value == reference) {
+ return "this";
+ } else {
+ return value.toString();
+ }
+ }
+
+}