summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2013-05-28 14:55:35 +0300
committerLeif Åstrand <leif@vaadin.com>2013-05-28 14:55:35 +0300
commit2b5ba963af81bb8a21f51ab29bd47ecd0054daa6 (patch)
tree34820369bc481fa23972914f45e4be5513ba6303 /uitest
parente52df7cdf8bbee662f539b1cee7344debb07c586 (diff)
downloadvaadin-framework-2b5ba963af81bb8a21f51ab29bd47ecd0054daa6.tar.gz
vaadin-framework-2b5ba963af81bb8a21f51ab29bd47ecd0054daa6.zip
Define how CurrentInstance works with access() (#11897)
Change-Id: I7ca62c5706fd37e7c44ed46703bcdce159b367f4
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/com/vaadin/tests/components/ui/UiAccess.html51
-rw-r--r--uitest/src/com/vaadin/tests/components/ui/UiAccess.java82
2 files changed, 132 insertions, 1 deletions
diff --git a/uitest/src/com/vaadin/tests/components/ui/UiAccess.html b/uitest/src/com/vaadin/tests/components/ui/UiAccess.html
index 664b15c16f..8ae2f2f48e 100644
--- a/uitest/src/com/vaadin/tests/components/ui/UiAccess.html
+++ b/uitest/src/com/vaadin/tests/components/ui/UiAccess.html
@@ -121,7 +121,56 @@
<td>vaadin=runcomvaadintestscomponentsuiUiAccess::PID_SLog_row_0</td>
<td>2. I was interrupted</td>
</tr>
-
+<tr>
+ <td>click</td>
+ <td>vaadin=runcomvaadintestscomponentsuiUiAccess::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[5]/VButton[0]/domChild[0]/domChild[0]</td>
+ <td></td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentsuiUiAccess::PID_SLog_row_3</td>
+ <td>0. accessSynchronously has request? true</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentsuiUiAccess::PID_SLog_row_2</td>
+ <td>1. Test value in accessSynchronously: Set before accessSynchronosly</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentsuiUiAccess::PID_SLog_row_1</td>
+ <td>2. has request after accessSynchronously? true</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentsuiUiAccess::PID_SLog_row_0</td>
+ <td>3. Test value after accessSynchornously: Set in accessSynchronosly</td>
+</tr>
+<tr>
+ <td>click</td>
+ <td>vaadin=runcomvaadintestscomponentsuiUiAccess::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[6]/VButton[0]/domChild[0]/domChild[0]</td>
+ <td></td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentsuiUiAccess::PID_SLog_row_3</td>
+ <td>0. access has request? false</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentsuiUiAccess::PID_SLog_row_2</td>
+ <td>1. Test value in access: Set before access</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentsuiUiAccess::PID_SLog_row_1</td>
+ <td>2. has request after access? true</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentsuiUiAccess::PID_SLog_row_0</td>
+ <td>3. Test value after access: Set before run pending</td>
+</tr>
</tbody></table>
</body>
</html>
diff --git a/uitest/src/com/vaadin/tests/components/ui/UiAccess.java b/uitest/src/com/vaadin/tests/components/ui/UiAccess.java
index c68da6ee54..c39f65243d 100644
--- a/uitest/src/com/vaadin/tests/components/ui/UiAccess.java
+++ b/uitest/src/com/vaadin/tests/components/ui/UiAccess.java
@@ -26,11 +26,25 @@ import com.vaadin.server.VaadinService;
import com.vaadin.tests.components.AbstractTestUIWithLog;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.util.CurrentInstance;
public class UiAccess extends AbstractTestUIWithLog {
private Future<Void> checkFromBeforeClientResponse;
+ private class CurrentInstanceTestType {
+ private String value;
+
+ public CurrentInstanceTestType(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public String toString() {
+ return value;
+ }
+ }
+
@Override
protected void setup(VaadinRequest request) {
addComponent(new Button("Access from UI thread",
@@ -211,6 +225,74 @@ public class UiAccess extends AbstractTestUIWithLog {
}.start();
}
}));
+ addComponent(new Button("CurrentInstance accessSynchronously values",
+ new Button.ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ log.clear();
+ // accessSynchronously should maintain values
+ CurrentInstance.set(CurrentInstanceTestType.class,
+ new CurrentInstanceTestType(
+ "Set before accessSynchronosly"));
+ accessSynchronously(new Runnable() {
+ @Override
+ public void run() {
+ log.log("accessSynchronously has request? "
+ + (VaadinService.getCurrentRequest() != null));
+ log.log("Test value in accessSynchronously: "
+ + CurrentInstance
+ .get(CurrentInstanceTestType.class));
+ CurrentInstance.set(
+ CurrentInstanceTestType.class,
+ new CurrentInstanceTestType(
+ "Set in accessSynchronosly"));
+ }
+ });
+ log.log("has request after accessSynchronously? "
+ + (VaadinService.getCurrentRequest() != null));
+ log("Test value after accessSynchornously: "
+ + CurrentInstance
+ .get(CurrentInstanceTestType.class));
+ }
+ }));
+ addComponent(new Button("CurrentInstance access values",
+ new Button.ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ log.clear();
+ // accessSynchronously should maintain values
+ CurrentInstance
+ .setInheritable(CurrentInstanceTestType.class,
+ new CurrentInstanceTestType(
+ "Set before access"));
+ access(new Runnable() {
+ @Override
+ public void run() {
+ log.log("access has request? "
+ + (VaadinService.getCurrentRequest() != null));
+ log.log("Test value in access: "
+ + CurrentInstance
+ .get(CurrentInstanceTestType.class));
+ CurrentInstance.setInheritable(
+ CurrentInstanceTestType.class,
+ new CurrentInstanceTestType(
+ "Set in access"));
+ }
+ });
+ CurrentInstance.setInheritable(
+ CurrentInstanceTestType.class,
+ new CurrentInstanceTestType(
+ "Set before run pending"));
+
+ getSession().runPendingAccessTasks();
+
+ log.log("has request after access? "
+ + (VaadinService.getCurrentRequest() != null));
+ log("Test value after access: "
+ + CurrentInstance
+ .get(CurrentInstanceTestType.class));
+ }
+ }));
}
@Override