From 0cbba9d6f4a65c04ca0e396c440de0c1c25945ec Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Thu, 18 Apr 2013 12:35:10 +0300 Subject: Initial support for toggling push on the fly (#11506) Still missing is the ability to load vaadinPush.js if it has not yet been loaded. Change-Id: Ibe3596c38a7c4e3432b0396072866ee3072e6d30 --- uitest/src/com/vaadin/tests/push/TogglePush.html | 91 ++++++++++++++++++++++++ uitest/src/com/vaadin/tests/push/TogglePush.java | 82 +++++++++++++++++++++ 2 files changed, 173 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/push/TogglePush.html create mode 100644 uitest/src/com/vaadin/tests/push/TogglePush.java (limited to 'uitest') diff --git a/uitest/src/com/vaadin/tests/push/TogglePush.html b/uitest/src/com/vaadin/tests/push/TogglePush.html new file mode 100644 index 0000000000..b752d2120c --- /dev/null +++ b/uitest/src/com/vaadin/tests/push/TogglePush.html @@ -0,0 +1,91 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run-push/com.vaadin.tests.push.TogglePush?restartApplication
clickvaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[3]/VButton[0]/domChild[0]/domChild[0]
pause2000
assertTextvaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VLabel[0]Counter has been updated 1 times
mouseClickvaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]61,6
clickvaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[3]/VButton[0]/domChild[0]/domChild[0]
pause2000
assertTextvaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VLabel[0]Counter has been updated 1 times
clickvaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VButton[0]/domChild[0]/domChild[0]
assertTextvaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VLabel[0]Counter has been updated 3 times
mouseClickvaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]61,3
clickvaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[3]/VButton[0]/domChild[0]/domChild[0]
pause2000
assertTextvaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VLabel[0]Counter has been updated 4 times
+ + diff --git a/uitest/src/com/vaadin/tests/push/TogglePush.java b/uitest/src/com/vaadin/tests/push/TogglePush.java new file mode 100644 index 0000000000..8e9eafeabb --- /dev/null +++ b/uitest/src/com/vaadin/tests/push/TogglePush.java @@ -0,0 +1,82 @@ +package com.vaadin.tests.push; + +import java.util.Timer; +import java.util.TimerTask; + +import com.vaadin.data.Property.ValueChangeEvent; +import com.vaadin.data.Property.ValueChangeListener; +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.communication.PushMode; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.CheckBox; +import com.vaadin.ui.Label; + +public class TogglePush extends AbstractTestUI { + private final Label counterLabel = new Label(); + private int counter = 0; + + @Override + protected void setup(VaadinRequest request) { + updateCounter(); + addComponent(counterLabel); + + CheckBox pushSetting = new CheckBox("Push enabled"); + pushSetting.setValue(Boolean.valueOf(getPushMode().isEnabled())); + pushSetting.setImmediate(true); + pushSetting.addValueChangeListener(new ValueChangeListener() { + @Override + public void valueChange(ValueChangeEvent event) { + if (event.getProperty().getValue() == Boolean.TRUE) { + setPushMode(PushMode.AUTOMATIC); + } else { + setPushMode(PushMode.DISABLED); + } + } + }); + addComponent(pushSetting); + + addComponent(new Button("Update counter now", + new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + updateCounter(); + } + })); + + addComponent(new Button("Update counter in 1 sec", + new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + new Timer().schedule(new TimerTask() { + @Override + public void run() { + runSafely(new Runnable() { + @Override + public void run() { + updateCounter(); + } + }); + } + }, 1000); + } + })); + } + + public void updateCounter() { + counterLabel.setValue("Counter has been updated " + counter++ + + " times"); + } + + @Override + protected String getTestDescription() { + return "Basic test for enabling and disabling push on the fly."; + } + + @Override + protected Integer getTicketNumber() { + return Integer.valueOf(11506); + } + +} -- cgit v1.2.3