--- /dev/null
+/*
+ * Copyright 2000-2013 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.vaadin.tests.components.ui;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.locks.ReentrantLock;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.support.ui.ExpectedConditions;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.server.VaadinService;
+import com.vaadin.server.VaadinSession;
+import com.vaadin.shared.communication.PushMode;
+import com.vaadin.tests.components.AbstractTestUIWithLog;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.UI;
+import com.vaadin.util.CurrentInstance;
+
+public class UIAccess extends AbstractTestUIWithLog {
+
+ public static class UIAccessTest extends MultiBrowserTest {
+ @Override
+ protected boolean isPushEnabled() {
+ return true;
+ }
+
+ @Test
+ public void testThreadLocals() {
+ getCurrentInstanceWhenPushingButton().click();
+ waitUntil(ExpectedConditions.textToBePresentInElement(
+ vaadinLocatorById("Log_row_0"), "1."));
+ Assert.assertEquals(
+ "0. Current UI matches in beforeResponse? true",
+ vaadinElementById("Log_row_1").getText());
+ Assert.assertEquals(
+ "1. Current session matches in beforeResponse? true",
+ vaadinElementById("Log_row_0").getText());
+
+ }
+
+ private WebElement getCurrentInstanceWhenPushingButton() {
+ return vaadinElement("/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[7]/VButton[0]");
+ }
+ }
+
+ private volatile boolean checkCurrentInstancesBeforeResponse = false;
+
+ 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",
+ new Button.ClickListener() {
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ log.clear();
+ // Ensure beforeClientResponse is invoked
+ markAsDirty();
+ checkFromBeforeClientResponse = access(new Runnable() {
+ @Override
+ public void run() {
+ log("Access from UI thread is run");
+ }
+ });
+ log("Access from UI thread future is done? "
+ + checkFromBeforeClientResponse.isDone());
+ }
+ }));
+ addComponent(new Button("Access from background thread",
+ new Button.ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ log.clear();
+ final CountDownLatch latch = new CountDownLatch(1);
+
+ new Thread() {
+ @Override
+ public void run() {
+ final boolean threadHasCurrentResponse = VaadinService
+ .getCurrentResponse() != null;
+ // session is locked by request thread at this
+ // point
+ final Future<Void> initialFuture = access(new Runnable() {
+ @Override
+ public void run() {
+ log("Initial background message");
+ log("Thread has current response? "
+ + threadHasCurrentResponse);
+ }
+ });
+
+ // Let request thread continue
+ latch.countDown();
+
+ // Wait until thread can be locked
+ while (!getSession().getLockInstance()
+ .tryLock()) {
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ try {
+ log("Thread got lock, inital future done? "
+ + initialFuture.isDone());
+ setPollInterval(-1);
+ } finally {
+ getSession().unlock();
+ }
+ }
+ }.start();
+
+ // Wait for thread to do initialize before continuing
+ try {
+ latch.await();
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+
+ setPollInterval(3000);
+ }
+ }));
+ addComponent(new Button("Access throwing exception",
+ new Button.ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ log.clear();
+ final Future<Void> firstFuture = access(new Runnable() {
+ @Override
+ public void run() {
+ log("Throwing exception in access");
+ throw new RuntimeException(
+ "Catch me if you can");
+ }
+ });
+ access(new Runnable() {
+ @Override
+ public void run() {
+ log("firstFuture is done? "
+ + firstFuture.isDone());
+ try {
+ firstFuture.get();
+ log("Should not get here");
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ } catch (ExecutionException e) {
+ log("Got exception from firstFuture: "
+ + e.getMessage());
+ }
+ }
+ });
+ }
+ }));
+ addComponent(new Button("Cancel future before started",
+ new Button.ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ log.clear();
+ Future<Void> future = access(new Runnable() {
+ @Override
+ public void run() {
+ log("Should not get here");
+ }
+ });
+ future.cancel(false);
+ log("future was cancled, should not start");
+ }
+ }));
+ addComponent(new Button("Cancel running future",
+ new Button.ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ log.clear();
+ final ReentrantLock interruptLock = new ReentrantLock();
+
+ final Future<Void> future = access(new Runnable() {
+ @Override
+ public void run() {
+ log("Waiting for thread to start");
+ while (!interruptLock.isLocked()) {
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ log("Premature interruption");
+ throw new RuntimeException(e);
+ }
+ }
+
+ log("Thread started, waiting for interruption");
+ try {
+ interruptLock.lockInterruptibly();
+ } catch (InterruptedException e) {
+ log("I was interrupted");
+ }
+ }
+ });
+
+ new Thread() {
+ @Override
+ public void run() {
+ interruptLock.lock();
+ // Wait until UI thread has started waiting for
+ // the lock
+ while (!interruptLock.hasQueuedThreads()) {
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ future.cancel(true);
+ }
+ }.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().getService().runPendingAccessTasks(
+ getSession());
+
+ log.log("has request after access? "
+ + (VaadinService.getCurrentRequest() != null));
+ log("Test value after access: "
+ + CurrentInstance
+ .get(CurrentInstanceTestType.class));
+ }
+ }));
+
+ addComponent(new Button("CurrentInstance when pushing",
+ new Button.ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ log.clear();
+ if (getPushConfiguration().getPushMode() != PushMode.AUTOMATIC) {
+ log("Can only test with automatic push enabled");
+ return;
+ }
+
+ final VaadinSession session = getSession();
+ new Thread() {
+ @Override
+ public void run() {
+ // Pretend this isn't a Vaadin thread
+ CurrentInstance.clearAll();
+
+ /*
+ * Get explicit lock to ensure the (implicit)
+ * push does not happen during normal request
+ * handling.
+ */
+ session.lock();
+ try {
+ access(new Runnable() {
+ @Override
+ public void run() {
+ checkCurrentInstancesBeforeResponse = true;
+ // Trigger beforeClientResponse
+ markAsDirty();
+ }
+ });
+ } finally {
+ session.unlock();
+ }
+ }
+ }.start();
+ }
+ }));
+ }
+
+ @Override
+ public void beforeClientResponse(boolean initial) {
+ if (checkFromBeforeClientResponse != null) {
+ log("beforeClientResponse future is done? "
+ + checkFromBeforeClientResponse.isDone());
+ checkFromBeforeClientResponse = null;
+ }
+ if (checkCurrentInstancesBeforeResponse) {
+ UI currentUI = UI.getCurrent();
+ VaadinSession currentSession = VaadinSession.getCurrent();
+
+ log("Current UI matches in beforeResponse? " + (currentUI == this));
+ log("Current session matches in beforeResponse? "
+ + (currentSession == getSession()));
+ checkCurrentInstancesBeforeResponse = false;
+ }
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Test for various ways of using UI.access";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return Integer.valueOf(11897);
+ }
+
+}
+++ /dev/null
-/*
- * Copyright 2000-2013 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package com.vaadin.tests.components.ui;
-
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-import java.util.concurrent.locks.ReentrantLock;
-
-import com.vaadin.server.VaadinRequest;
-import com.vaadin.server.VaadinService;
-import com.vaadin.server.VaadinSession;
-import com.vaadin.shared.communication.PushMode;
-import com.vaadin.tests.components.AbstractTestUIWithLog;
-import com.vaadin.ui.Button;
-import com.vaadin.ui.Button.ClickEvent;
-import com.vaadin.ui.UI;
-import com.vaadin.util.CurrentInstance;
-
-public class UiAccess extends AbstractTestUIWithLog {
-
- private volatile boolean checkCurrentInstancesBeforeResponse = false;
-
- 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",
- new Button.ClickListener() {
-
- @Override
- public void buttonClick(ClickEvent event) {
- log.clear();
- // Ensure beforeClientResponse is invoked
- markAsDirty();
- checkFromBeforeClientResponse = access(new Runnable() {
- @Override
- public void run() {
- log("Access from UI thread is run");
- }
- });
- log("Access from UI thread future is done? "
- + checkFromBeforeClientResponse.isDone());
- }
- }));
- addComponent(new Button("Access from background thread",
- new Button.ClickListener() {
- @Override
- public void buttonClick(ClickEvent event) {
- log.clear();
- final CountDownLatch latch = new CountDownLatch(1);
-
- new Thread() {
- @Override
- public void run() {
- final boolean threadHasCurrentResponse = VaadinService
- .getCurrentResponse() != null;
- // session is locked by request thread at this
- // point
- final Future<Void> initialFuture = access(new Runnable() {
- @Override
- public void run() {
- log("Initial background message");
- log("Thread has current response? "
- + threadHasCurrentResponse);
- }
- });
-
- // Let request thread continue
- latch.countDown();
-
- // Wait until thread can be locked
- while (!getSession().getLockInstance()
- .tryLock()) {
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- }
- try {
- log("Thread got lock, inital future done? "
- + initialFuture.isDone());
- setPollInterval(-1);
- } finally {
- getSession().unlock();
- }
- }
- }.start();
-
- // Wait for thread to do initialize before continuing
- try {
- latch.await();
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
-
- setPollInterval(3000);
- }
- }));
- addComponent(new Button("Access throwing exception",
- new Button.ClickListener() {
- @Override
- public void buttonClick(ClickEvent event) {
- log.clear();
- final Future<Void> firstFuture = access(new Runnable() {
- @Override
- public void run() {
- log("Throwing exception in access");
- throw new RuntimeException(
- "Catch me if you can");
- }
- });
- access(new Runnable() {
- @Override
- public void run() {
- log("firstFuture is done? "
- + firstFuture.isDone());
- try {
- firstFuture.get();
- log("Should not get here");
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- } catch (ExecutionException e) {
- log("Got exception from firstFuture: "
- + e.getMessage());
- }
- }
- });
- }
- }));
- addComponent(new Button("Cancel future before started",
- new Button.ClickListener() {
- @Override
- public void buttonClick(ClickEvent event) {
- log.clear();
- Future<Void> future = access(new Runnable() {
- @Override
- public void run() {
- log("Should not get here");
- }
- });
- future.cancel(false);
- log("future was cancled, should not start");
- }
- }));
- addComponent(new Button("Cancel running future",
- new Button.ClickListener() {
- @Override
- public void buttonClick(ClickEvent event) {
- log.clear();
- final ReentrantLock interruptLock = new ReentrantLock();
-
- final Future<Void> future = access(new Runnable() {
- @Override
- public void run() {
- log("Waiting for thread to start");
- while (!interruptLock.isLocked()) {
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) {
- log("Premature interruption");
- throw new RuntimeException(e);
- }
- }
-
- log("Thread started, waiting for interruption");
- try {
- interruptLock.lockInterruptibly();
- } catch (InterruptedException e) {
- log("I was interrupted");
- }
- }
- });
-
- new Thread() {
- @Override
- public void run() {
- interruptLock.lock();
- // Wait until UI thread has started waiting for
- // the lock
- while (!interruptLock.hasQueuedThreads()) {
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- }
-
- future.cancel(true);
- }
- }.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().getService().runPendingAccessTasks(
- getSession());
-
- log.log("has request after access? "
- + (VaadinService.getCurrentRequest() != null));
- log("Test value after access: "
- + CurrentInstance
- .get(CurrentInstanceTestType.class));
- }
- }));
-
- addComponent(new Button("CurrentInstance when pushing",
- new Button.ClickListener() {
- @Override
- public void buttonClick(ClickEvent event) {
- log.clear();
- if (getPushConfiguration().getPushMode() != PushMode.AUTOMATIC) {
- log("Can only test with automatic push enabled");
- return;
- }
-
- final VaadinSession session = getSession();
- new Thread() {
- @Override
- public void run() {
- // Pretend this isn't a Vaadin thread
- CurrentInstance.clearAll();
-
- /*
- * Get explicit lock to ensure the (implicit)
- * push does not happen during normal request
- * handling.
- */
- session.lock();
- try {
- access(new Runnable() {
- @Override
- public void run() {
- checkCurrentInstancesBeforeResponse = true;
- // Trigger beforeClientResponse
- markAsDirty();
- }
- });
- } finally {
- session.unlock();
- }
- }
- }.start();
- }
- }));
- }
-
- @Override
- public void beforeClientResponse(boolean initial) {
- if (checkFromBeforeClientResponse != null) {
- log("beforeClientResponse future is done? "
- + checkFromBeforeClientResponse.isDone());
- checkFromBeforeClientResponse = null;
- }
- if (checkCurrentInstancesBeforeResponse) {
- UI currentUI = UI.getCurrent();
- VaadinSession currentSession = VaadinSession.getCurrent();
-
- log("Current UI matches in beforeResponse? " + (currentUI == this));
- log("Current session matches in beforeResponse? "
- + (currentSession == getSession()));
- checkCurrentInstancesBeforeResponse = false;
- }
- }
-
- @Override
- protected String getTestDescription() {
- return "Test for various ways of using UI.access";
- }
-
- @Override
- protected Integer getTicketNumber() {
- return Integer.valueOf(11897);
- }
-
-}
+++ /dev/null
-<?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.components.ui.UiAccess?restartApplication&transport=websocket</td>
- <td></td>
-</tr>
-<tr>
- <td>click</td>
- <td>vaadin=runcomvaadintestscomponentsuiUiAccess::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[7]/VButton[0]/domChild[0]/domChild[0]</td>
- <td></td>
-</tr>
-<tr>
- <td>waitForNotText</td>
- <td>vaadin=runcomvaadintestscomponentsuiUiAccess::PID_SLog_row_0</td>
- <td></td>
-</tr>
-<tr>
- <td>assertText</td>
- <td>vaadin=runcomvaadintestscomponentsuiUiAccess::PID_SLog_row_0</td>
- <td>exact:1. Current session matches in beforeResponse? true</td>
-</tr>
-<tr>
- <td>assertText</td>
- <td>vaadin=runcomvaadintestscomponentsuiUiAccess::PID_SLog_row_1</td>
- <td>exact:0. Current UI matches in beforeResponse? true</td>
-</tr>
-</tbody></table>
-</body>
-</html>
+++ /dev/null
-<?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:8888/" />
-<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-push/com.vaadin.tests.push.BarInUIDL?restartApplication</td>
- <td></td>
-</tr>
-<tr>
- <td>click</td>
- <td>vaadin=runpushcomvaadintestspushBarInUIDL::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VButton[0]/domChild[0]</td>
- <td></td>
-</tr>
-<tr>
- <td>assertText</td>
- <td>vaadin=runpushcomvaadintestspushBarInUIDL::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VLabel[0]</td>
- <td>Thank you for clicking | bar</td>
-</tr>
-<tr>
- <td>click</td>
- <td>vaadin=runpushcomvaadintestspushBarInUIDL::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VButton[0]/domChild[0]</td>
- <td></td>
-</tr>
-<tr>
- <td>assertText</td>
- <td>vaadin=runpushcomvaadintestspushBarInUIDL::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VLabel[0]</td>
- <td>Thank you for clicking | bar</td>
-</tr>
-
-</tbody></table>
-</body>
-</html>
package com.vaadin.tests.push;
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.annotations.Push;
import com.vaadin.server.VaadinRequest;
+import com.vaadin.shared.ui.ui.Transport;
import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.tests.tb3.MultiBrowserTest;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Label;
+@Push(transport = Transport.STREAMING)
public class BarInUIDL extends AbstractTestUI {
+ public static class BarInUIDLTest extends MultiBrowserTest {
+ @Test
+ public void sendBarInUIDL() {
+ getButton().click();
+ Assert.assertEquals(
+ "Thank you for clicking | bar",
+ vaadinElement(
+ "/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VLabel[0]")
+ .getText());
+ getButton().click();
+ Assert.assertEquals(
+ "Thank you for clicking | bar",
+ vaadinElement(
+ "/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VLabel[0]")
+ .getText());
+ }
+
+ private WebElement getButton() {
+ return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VButton[0]");
+ }
+ }
+
/*
* (non-Javadoc)
*
+++ /dev/null
-<?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:8888/" />
-<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-push/com.vaadin.tests.push.BasicPush?restartApplication&debug</td>
- <td></td>
-</tr>
-<!--Test client initiated push -->
-<tr>
- <td>assertText</td>
- <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VLabel[0]</td>
- <td>0</td>
-</tr>
-<tr>
- <td>click</td>
- <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VButton[0]/domChild[0]/domChild[0]</td>
- <td></td>
-</tr>
-<tr>
- <td>assertText</td>
- <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VLabel[0]</td>
- <td>1</td>
-</tr>
-<tr>
- <td>click</td>
- <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VButton[0]/domChild[0]/domChild[0]</td>
- <td></td>
-</tr>
-<tr>
- <td>click</td>
- <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VButton[0]/domChild[0]/domChild[0]</td>
- <td></td>
-</tr>
-<tr>
- <td>click</td>
- <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VButton[0]/domChild[0]/domChild[0]</td>
- <td></td>
-</tr>
-<tr>
- <td>assertText</td>
- <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VLabel[0]</td>
- <td>4</td>
-</tr>
-<!--Test server initiated push-->
-<tr>
- <td>click</td>
- <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VButton[0]/domChild[0]/domChild[0]</td>
- <td></td>
-</tr>
-<tr>
- <td>assertText</td>
- <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[4]/VLabel[0]</td>
- <td>0</td>
-</tr>
-<tr>
- <td>pause</td>
- <td>3000</td>
- <td></td>
-</tr>
-<tr>
- <td>assertText</td>
- <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[4]/VLabel[0]</td>
- <td>1</td>
-</tr>
-<tr>
- <td>pause</td>
- <td>3000</td>
- <td></td>
-</tr>
-<tr>
- <td>assertText</td>
- <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[4]/VLabel[0]</td>
- <td>2</td>
-</tr>
-</tbody></table>
-</body>
-</html>
+/*
+ * Copyright 2000-2013 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
package com.vaadin.tests.push;
-import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
-import com.vaadin.annotations.Widgetset;
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.annotations.Push;
import com.vaadin.data.util.ObjectProperty;
import com.vaadin.server.VaadinRequest;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.tests.components.AbstractTestUI;
-import com.vaadin.tests.widgetset.TestingWidgetSet;
+import com.vaadin.tests.tb3.MultiBrowserTest;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Label;
-@Widgetset(TestingWidgetSet.NAME)
+@Push
public class BasicPush extends AbstractTestUI {
+ public static abstract class BasicPushTest extends MultiBrowserTest {
+
+ @Test
+ public void testPush() {
+ // Test client initiated push
+ Assert.assertEquals(0, getClientCounter());
+ getIncrementButton().click();
+ Assert.assertEquals(
+ "Client counter not incremented by button click", 1,
+ getClientCounter());
+ getIncrementButton().click();
+ getIncrementButton().click();
+ getIncrementButton().click();
+ Assert.assertEquals(
+ "Four clicks should have incremented counter to 4", 4,
+ getClientCounter());
+
+ // Test server initiated push
+ getServerCounterStartButton().click();
+ try {
+ Assert.assertEquals(0, getServerCounter());
+ sleep(3000);
+ int serverCounter = getServerCounter();
+ if (serverCounter < 1) {
+ // No push has happened
+ Assert.fail("No push has occured within 3s");
+ }
+ sleep(3000);
+ if (getServerCounter() <= serverCounter) {
+ // No push has happened
+ Assert.fail("Only one push took place within 6s");
+
+ }
+ } finally {
+ // Avoid triggering push assertions
+ getServerCounterStopButton().click();
+ }
+ }
+
+ private int getServerCounter() {
+ return Integer.parseInt(getServerCounterElement().getText());
+ }
+
+ private int getClientCounter() {
+ return Integer.parseInt(getClientCounterElement().getText());
+ }
+
+ private WebElement getServerCounterElement() {
+ return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[4]/VLabel[0]");
+ }
+
+ private WebElement getServerCounterStartButton() {
+ return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VButton[0]/domChild[0]/domChild[0]");
+ }
+
+ private WebElement getServerCounterStopButton() {
+ return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[6]/VButton[0]/domChild[0]/domChild[0]");
+ }
+
+ private WebElement getIncrementButton() {
+ return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VButton[0]/domChild[0]/domChild[0]");
+ }
+
+ private WebElement getClientCounterElement() {
+ return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VLabel[0]");
+ }
+ }
+
private ObjectProperty<Integer> counter = new ObjectProperty<Integer>(0);
private ObjectProperty<Integer> counter2 = new ObjectProperty<Integer>(0);
private final Timer timer = new Timer(true);
- private final TimerTask task = new TimerTask() {
-
- @Override
- public void run() {
- access(new Runnable() {
- @Override
- public void run() {
- counter2.setValue(counter2.getValue() + 1);
- }
- });
- }
- };
+ private TimerTask task;
@Override
protected void setup(VaadinRequest request) {
lbl.setCaption("Server counter (updates each 3s by server thread) :");
addComponent(lbl);
- addComponent(new Button("Reset", new Button.ClickListener() {
+ addComponent(new Button("Start timer", new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
counter2.setValue(0);
+ if (task != null) {
+ task.cancel();
+ }
+ task = new TimerTask() {
+
+ @Override
+ public void run() {
+ access(new Runnable() {
+ @Override
+ public void run() {
+ counter2.setValue(counter2.getValue() + 1);
+ }
+ });
+ }
+ };
+ timer.scheduleAtFixedRate(task, 3000, 3000);
+ }
+ }));
+
+ addComponent(new Button("Stop timer", new Button.ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ if (task != null) {
+ task.cancel();
+ task = null;
+ }
}
}));
}
@Override
public void attach() {
super.attach();
- timer.scheduleAtFixedRate(task, new Date(), 3000);
}
@Override
+/*
+ * Copyright 2000-2013 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
package com.vaadin.tests.push;
+import org.junit.Test;
+
import com.vaadin.annotations.Push;
+import com.vaadin.server.VaadinRequest;
import com.vaadin.shared.ui.ui.Transport;
@Push(transport = Transport.STREAMING)
public class BasicPushStreaming extends BasicPush {
@Override
- protected void setup(com.vaadin.server.VaadinRequest request) {
- addComponent(new PushConfigurator(this));
+ public void init(VaadinRequest request) {
+ super.init(request);
+ // Don't use fallback so we can easier detect if streaming fails
+ getPushConfiguration().setFallbackTransport(Transport.STREAMING);
+
}
+
+ public static class BasicPushStreamingTest extends BasicPushTest {
+ @Override
+ @Test
+ public void testPush() {
+ super.testPush();
+ }
+ }
+
}
+/*
+ * Copyright 2000-2013 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
package com.vaadin.tests.push;
+import java.util.Collection;
+
+import org.openqa.selenium.remote.DesiredCapabilities;
+
import com.vaadin.annotations.Push;
+import com.vaadin.server.VaadinRequest;
import com.vaadin.shared.ui.ui.Transport;
+import com.vaadin.tests.tb3.WebsocketTest;
@Push(transport = Transport.WEBSOCKET)
public class BasicPushWebsocket extends BasicPush {
+
+ @Override
+ public void init(VaadinRequest request) {
+ super.init(request);
+ // Don't use fallback so we can easier detect if websocket fails
+ getPushConfiguration().setFallbackTransport(Transport.WEBSOCKET);
+ }
+
+ public static class BasicPushWebsocketTest extends BasicPushTest {
+ @Override
+ public Collection<DesiredCapabilities> getBrowsersToTest() {
+ return WebsocketTest.getWebsocketBrowsers();
+ }
+ }
+
}
+++ /dev/null
-<?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:8888/" />
-<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>
-<!--Websocket-->
-<tr>
- <td>open</td>
- <td>/run/com.vaadin.tests.push.PushConfigurationTest?debug&restartApplication</td>
- <td></td>
-</tr>
-<tr>
- <td>assertNotText</td>
- <td>vaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VLabel[0]</td>
- <td>4</td>
-</tr>
-<tr>
- <td>select</td>
- <td>vaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[1]/VNativeSelect[0]/domChild[0]</td>
- <td>label=WEBSOCKET</td>
-</tr>
-<tr>
- <td>assertNotText</td>
- <td>vaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VLabel[0]</td>
- <td>4</td>
-</tr>
-<tr>
- <td>select</td>
- <td>vaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VNativeSelect[0]/domChild[0]</td>
- <td>label=AUTOMATIC</td>
-</tr>
-<tr>
- <td>assertText</td>
- <td>vaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[5]/VLabel[0]/domChild[0]</td>
- <td>*fallbackTransport: streaming*transport: websocket*</td>
-</tr>
-<tr>
- <td>assertNotText</td>
- <td>vaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VLabel[0]</td>
- <td>4</td>
-</tr>
-<tr>
- <td>waitForText</td>
- <td>vaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VLabel[0]</td>
- <td>4</td>
-</tr>
-<!--Use debug console to verify we used the correct transport type-->
-<tr>
- <td>assertTextPresent</td>
- <td>Push connection established using websocket</td>
- <td></td>
-</tr>
-<tr>
- <td>assertTextNotPresent</td>
- <td>Push connection established using streaming</td>
- <td>Push connection established using streaming</td>
-</tr>
-<tr>
- <td>select</td>
- <td>vaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VNativeSelect[0]/domChild[0]</td>
- <td>label=DISABLED</td>
-</tr>
-<!--Streaming-->
-<tr>
- <td>open</td>
- <td>/run/com.vaadin.tests.push.PushConfigurationTest?debug&restartApplication</td>
- <td></td>
-</tr>
-<tr>
- <td>assertNotText</td>
- <td>vaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VLabel[0]</td>
- <td>4</td>
-</tr>
-<tr>
- <td>select</td>
- <td>vaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[1]/VNativeSelect[0]/domChild[0]</td>
- <td>label=STREAMING</td>
-</tr>
-<tr>
- <td>assertNotText</td>
- <td>vaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VLabel[0]</td>
- <td>4</td>
-</tr>
-<tr>
- <td>select</td>
- <td>vaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VNativeSelect[0]/domChild[0]</td>
- <td>label=AUTOMATIC</td>
-</tr>
-<tr>
- <td>assertNotText</td>
- <td>vaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VLabel[0]</td>
- <td>4</td>
-</tr>
-<tr>
- <td>assertText</td>
- <td>vaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[5]/VLabel[0]/domChild[0]</td>
- <td>*fallbackTransport: streaming*transport: streaming*</td>
-</tr>
-<tr>
- <td>waitForText</td>
- <td>vaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VLabel[0]</td>
- <td>4</td>
-</tr>
-<!--Use debug console to verify we used the correct transport type-->
-<tr>
- <td>assertTextNotPresent</td>
- <td>Push connection established using websocket</td>
- <td></td>
-</tr>
-<tr>
- <td>assertTextPresent</td>
- <td>Push connection established using streaming</td>
- <td></td>
-</tr>
-<tr>
- <td>select</td>
- <td>vaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VNativeSelect[0]/domChild[0]</td>
- <td>label=DISABLED</td>
-</tr>
-</tbody></table>
-</body>
-</html>
+/*
+ * Copyright 2000-2013 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
package com.vaadin.tests.push;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.support.ui.Select;
+
import com.vaadin.data.util.ObjectProperty;
import com.vaadin.server.VaadinRequest;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.tests.tb3.WebsocketTest;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Label;
public class PushConfigurationTest extends AbstractTestUI {
+ public static class PushConfigurationWebsocket extends WebsocketTest {
+
+ @Override
+ protected boolean isDebug() {
+ return true;
+ }
+
+ @Test
+ public void testWebsocketAndStreaming() {
+ // Websocket
+ Assert.assertEquals(1, getServerCounter());
+ new Select(getTransportSelect()).selectByVisibleText("WEBSOCKET");
+ new Select(getPushModeSelect()).selectByVisibleText("AUTOMATIC");
+ Assert.assertTrue(vaadinElement(
+ "/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[5]/VLabel[0]/domChild[0]")
+ .getText()
+ .matches(
+ "^[\\s\\S]*fallbackTransport: streaming[\\s\\S]*transport: websocket[\\s\\S]*$"));
+ int counter = getServerCounter();
+
+ for (int second = 0;; second++) {
+ if (second >= 5) {
+ Assert.fail("timeout");
+ }
+ if (getServerCounter() >= (counter + 2)) {
+ break;
+ }
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ }
+ }
+
+ // Use debug console to verify we used the correct transport type
+ Assert.assertTrue(driver.getPageSource().contains(
+ "Push connection established using websocket"));
+ Assert.assertFalse(driver.getPageSource().contains(
+ "Push connection established using streaming"));
+
+ new Select(getPushModeSelect()).selectByVisibleText("DISABLED");
+
+ // Streaming
+ driver.get(getTestUrl());
+ Assert.assertEquals(1, getServerCounter());
+
+ new Select(getTransportSelect()).selectByVisibleText("STREAMING");
+ new Select(getPushModeSelect()).selectByVisibleText("AUTOMATIC");
+ Assert.assertTrue(vaadinElement(
+ "/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[5]/VLabel[0]/domChild[0]")
+ .getText()
+ .matches(
+ "^[\\s\\S]*fallbackTransport: streaming[\\s\\S]*transport: streaming[\\s\\S]*$"));
+
+ counter = getServerCounter();
+ for (int second = 0;; second++) {
+ if (second >= 5) {
+ Assert.fail("timeout");
+ }
+ if (getServerCounter() >= (counter + 2)) {
+ break;
+ }
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ }
+ }
+
+ // Use debug console to verify we used the correct transport type
+ Assert.assertFalse(driver.getPageSource().contains(
+ "Push connection established using websocket"));
+ Assert.assertTrue(driver.getPageSource().contains(
+ "Push connection established using streaming"));
+
+ }
+
+ private WebElement getPushModeSelect() {
+ return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VNativeSelect[0]/domChild[0]");
+ }
+
+ private WebElement getTransportSelect() {
+ return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[1]/VNativeSelect[0]/domChild[0]");
+ }
+
+ private int getServerCounter() {
+ return Integer.parseInt(getServerCounterElement().getText());
+ }
+
+ private WebElement getServerCounterElement() {
+ return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VLabel[0]");
+ }
+ }
+
private ObjectProperty<Integer> counter = new ObjectProperty<Integer>(0);
private ObjectProperty<Integer> counter2 = new ObjectProperty<Integer>(0);
+++ /dev/null
-<?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-push/com.vaadin.tests.push.PushFromInit?debug&restartApplication</td>
- <td></td>
-</tr>
-<tr>
- <td>waitForText</td>
- <td>vaadin=runpushcomvaadintestspushPushFromInit::PID_SLog_row_1</td>
- <td>1. Logged in init</td>
-</tr>
-<tr>
- <td>assertText</td>
- <td>vaadin=runpushcomvaadintestspushPushFromInit::PID_SLog_row_0</td>
- <td>2. Logged from background thread started in init</td>
-</tr>
-
-</tbody></table>
-</body>
-</html>
+/*
+ * Copyright 2000-2013 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
package com.vaadin.tests.push;
+import org.junit.Assert;
+import org.junit.Test;
+
import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUIWithLog;
+import com.vaadin.tests.tb3.MultiBrowserTest;
import com.vaadin.ui.Button;
public class PushFromInit extends AbstractTestUIWithLog {
+ public static class PushFromInitTB3 extends MultiBrowserTest {
+ @Test
+ public void testPushFromInit() {
+ for (int second = 0;; second++) {
+ if (second >= 30) {
+ Assert.fail("timeout");
+ }
+ try {
+ if ("1. Logged in init".equals(vaadinElementById(
+ "Log_row_1").getText())) {
+ break;
+ }
+ } catch (Exception e) {
+ }
+ try {
+ Thread.sleep(200);
+ } catch (InterruptedException e) {
+ }
+ }
+
+ Assert.assertEquals(
+ "2. Logged from background thread started in init",
+ vaadinElementById("Log_row_0").getText());
+
+ }
+ }
+
@Override
protected void setup(VaadinRequest request) {
new Thread() {
+++ /dev/null
-<?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://192.168.2.162:8888/" />
-<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-push/com.vaadin.tests.components.panel.PanelChangeContents?restartApplication</td>
- <td></td>
-</tr>
-<tr>
- <td>assertText</td>
- <td>vaadin=runpushcomvaadintestscomponentspanelPanelChangeContents::/VVerticalLayout[0]/Slot[1]/VPanel[0]/VVerticalLayout[0]/Slot[0]/VLabel[0]</td>
- <td>stats</td>
-</tr>
-<tr>
- <td>click</td>
- <td>vaadin=runpushcomvaadintestscomponentspanelPanelChangeContents::/VVerticalLayout[0]/Slot[0]/VHorizontalLayout[0]/Slot[1]/VButton[0]/domChild[0]/domChild[0]</td>
- <td></td>
-</tr>
-<tr>
- <td>assertText</td>
- <td>vaadin=runpushcomvaadintestscomponentspanelPanelChangeContents::/VVerticalLayout[0]/Slot[1]/VPanel[0]/VVerticalLayout[0]/Slot[0]/VLabel[0]</td>
- <td>companies</td>
-</tr>
-<tr>
- <td>click</td>
- <td>vaadin=runpushcomvaadintestscomponentspanelPanelChangeContents::/VVerticalLayout[0]/Slot[0]/VHorizontalLayout[0]/Slot[0]/VButton[0]/domChild[0]/domChild[0]</td>
- <td></td>
-</tr>
-<tr>
- <td>assertText</td>
- <td>vaadin=runpushcomvaadintestscomponentspanelPanelChangeContents::/VVerticalLayout[0]/Slot[1]/VPanel[0]/VVerticalLayout[0]/Slot[0]/VLabel[0]</td>
- <td>stats</td>
-</tr>
-
-</tbody></table>
-</body>
-</html>
--- /dev/null
+/*
+ * Copyright 2000-2013 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+/**
+ *
+ */
+package com.vaadin.tests.push;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.tests.components.panel.PanelChangeContents;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class PushReattachedComponent extends MultiBrowserTest {
+
+ @Override
+ protected boolean isPushEnabled() {
+ return true;
+ }
+
+ @Override
+ protected Class<?> getUIClass() {
+ return PanelChangeContents.class;
+ }
+
+ @Test
+ public void testReattachComponentUsingPush() {
+ Assert.assertEquals(
+ "stats",
+ vaadinElement(
+ "/VVerticalLayout[0]/Slot[1]/VPanel[0]/VVerticalLayout[0]/Slot[0]/VLabel[0]")
+ .getText());
+ vaadinElement(
+ "/VVerticalLayout[0]/Slot[0]/VHorizontalLayout[0]/Slot[1]/VButton[0]/domChild[0]/domChild[0]")
+ .click();
+ Assert.assertEquals(
+ "companies",
+ vaadinElement(
+ "/VVerticalLayout[0]/Slot[1]/VPanel[0]/VVerticalLayout[0]/Slot[0]/VLabel[0]")
+ .getText());
+ vaadinElement(
+ "/VVerticalLayout[0]/Slot[0]/VHorizontalLayout[0]/Slot[0]/VButton[0]/domChild[0]/domChild[0]")
+ .click();
+ Assert.assertEquals(
+ "stats",
+ vaadinElement(
+ "/VVerticalLayout[0]/Slot[1]/VPanel[0]/VVerticalLayout[0]/Slot[0]/VLabel[0]")
+ .getText());
+
+ }
+}
+++ /dev/null
-<?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:8888/" />
-<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.push.BasicPushStreaming?debug&restartApplication</td>
- <td></td>
-</tr>
-<tr>
- <td>waitForTextPresent</td>
- <td>Push connection established using streaming</td>
- <td></td>
-</tr>
-<tr>
- <td>assertTextNotPresent</td>
- <td>Push connection established using websocket</td>
- <td></td>
-</tr>
-<tr>
- <td>open</td>
- <td>/run/com.vaadin.tests.push.BasicPushWebsocket?debug&restartApplication</td>
- <td></td>
-</tr>
-<tr>
- <td>assertTextNotPresent</td>
- <td>Push connection established using streaming</td>
- <td></td>
-</tr>
-<tr>
- <td>waitForTextPresent</td>
- <td>Push connection established using websocket</td>
- <td></td>
-</tr>
-</tbody></table>
-</body>
-</html>
+++ /dev/null
-<?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:8888/" />
-<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-push/com.vaadin.tests.push.BasicPush?restartApplication&debug&transport=streaming</td>
- <td></td>
-</tr>
-<!--Test client initiated push -->
-<tr>
- <td>assertText</td>
- <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VLabel[0]</td>
- <td>0</td>
-</tr>
-<tr>
- <td>click</td>
- <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VButton[0]/domChild[0]/domChild[0]</td>
- <td></td>
-</tr>
-<tr>
- <td>assertText</td>
- <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VLabel[0]</td>
- <td>1</td>
-</tr>
-<tr>
- <td>click</td>
- <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VButton[0]/domChild[0]/domChild[0]</td>
- <td></td>
-</tr>
-<tr>
- <td>click</td>
- <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VButton[0]/domChild[0]/domChild[0]</td>
- <td></td>
-</tr>
-<tr>
- <td>click</td>
- <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VButton[0]/domChild[0]/domChild[0]</td>
- <td></td>
-</tr>
-<tr>
- <td>assertText</td>
- <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VLabel[0]</td>
- <td>4</td>
-</tr>
-<!--Test server initiated push-->
-<tr>
- <td>click</td>
- <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VButton[0]/domChild[0]/domChild[0]</td>
- <td></td>
-</tr>
-<tr>
- <td>assertText</td>
- <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[4]/VLabel[0]</td>
- <td>0</td>
-</tr>
-<tr>
- <td>pause</td>
- <td>3000</td>
- <td></td>
-</tr>
-<tr>
- <td>assertText</td>
- <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[4]/VLabel[0]</td>
- <td>1</td>
-</tr>
-<tr>
- <td>pause</td>
- <td>3000</td>
- <td></td>
-</tr>
-<tr>
- <td>assertText</td>
- <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[4]/VLabel[0]</td>
- <td>2</td>
-</tr>
-</tbody></table>
-</body>
-</html>
+++ /dev/null
-<?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-push/com.vaadin.tests.push.TogglePush?restartApplication</td>
- <td></td>
-</tr>
-<tr>
- <td>click</td>
- <td>vaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[3]/VButton[0]/domChild[0]/domChild[0]</td>
- <td></td>
-</tr>
-<tr>
- <td>pause</td>
- <td>2000</td>
- <td></td>
-</tr>
-<!--Push is enabled, so text gets updated-->
-<tr>
- <td>assertText</td>
- <td>vaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VLabel[0]</td>
- <td>Counter has been updated 1 times</td>
-</tr>
-<tr>
- <td>mouseClick</td>
- <td>vaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]</td>
- <td>61,6</td>
-</tr>
-<tr>
- <td>click</td>
- <td>vaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[3]/VButton[0]/domChild[0]/domChild[0]</td>
- <td></td>
-</tr>
-<tr>
- <td>pause</td>
- <td>2000</td>
- <td></td>
-</tr>
-<!--Push is disabled, so text is not updated-->
-<tr>
- <td>assertText</td>
- <td>vaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VLabel[0]</td>
- <td>Counter has been updated 1 times</td>
-</tr>
-<tr>
- <td>click</td>
- <td>vaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VButton[0]/domChild[0]/domChild[0]</td>
- <td></td>
-</tr>
-<!--Direct update is visible, and includes previous update-->
-<tr>
- <td>assertText</td>
- <td>vaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VLabel[0]</td>
- <td>Counter has been updated 3 times</td>
-</tr>
-<tr>
- <td>mouseClick</td>
- <td>vaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]</td>
- <td>61,3</td>
-</tr>
-<tr>
- <td>click</td>
- <td>vaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[3]/VButton[0]/domChild[0]/domChild[0]</td>
- <td></td>
-</tr>
-<tr>
- <td>pause</td>
- <td>2000</td>
- <td></td>
-</tr>
-<!--Push is enabled again, so text gets updated-->
-<tr>
- <td>assertText</td>
- <td>vaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VLabel[0]</td>
- <td>Counter has been updated 4 times</td>
-</tr>
-
-</tbody></table>
-</body>
-</html>
+/*
+ * Copyright 2000-2013 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
package com.vaadin.tests.push;
import java.util.Timer;
import java.util.TimerTask;
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.WebElement;
+
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.tests.tb3.MultiBrowserTest;
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 {
+ public static class TogglePushInInitTB3 extends MultiBrowserTest {
+ @Override
+ protected boolean isPushEnabled() {
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.tests.tb3.AbstractTB3Test#getTestUrl()
+ */
+ @Override
+ protected String getTestUrl() {
+ return null;
+ }
+
+ @Test
+ public void togglePushInInit() {
+ String baseUrl = getBaseURL();
+ if (baseUrl.endsWith("/")) {
+ baseUrl = baseUrl.substring(0, baseUrl.length() - 1);
+ }
+
+ String url = baseUrl + getDeploymentPath();
+
+ // Open with push disabled
+ driver.get(addParameter(url, "push=disabled"));
+
+ Assert.assertFalse(getPushToggle().isSelected());
+
+ getDelayedCounterUpdateButton().click();
+ sleep(2000);
+ Assert.assertEquals("Counter has been updated 0 times",
+ getCounterText());
+
+ // Open with push enabled
+ driver.get(addParameter(url, "push=enabled"));
+ Assert.assertTrue(getPushToggle().isSelected());
+
+ getDelayedCounterUpdateButton().click();
+ sleep(2000);
+ Assert.assertEquals("Counter has been updated 1 times",
+ getCounterText());
+
+ }
+
+ /**
+ * @since
+ * @param url
+ * @param string
+ * @return
+ */
+ private String addParameter(String url, String queryParameter) {
+ if (url.contains("?")) {
+ return url + "&" + queryParameter;
+ } else {
+ return url + "?" + queryParameter;
+ }
+ }
+
+ private String getCounterText() {
+ return vaadinElement(
+ "/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VLabel[0]")
+ .getText();
+ }
+
+ private WebElement getPushToggle() {
+ return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]");
+ }
+
+ private WebElement getDelayedCounterUpdateButton() {
+ return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[3]/VButton[0]/domChild[0]/domChild[0]");
+ }
+
+ }
+
+ public static class TogglePushTB3 extends MultiBrowserTest {
+
+ @Override
+ protected boolean isPushEnabled() {
+ return true;
+ }
+
+ @Test
+ public void togglePush() {
+ getDelayedCounterUpdateButton().click();
+ sleep(2000);
+
+ // Push is enabled, so text gets updated
+ Assert.assertEquals("Counter has been updated 1 times",
+ getCounterText());
+
+ // Disable push
+ getPushToggle().click();
+ getDelayedCounterUpdateButton().click();
+ sleep(2000);
+ // Push is disabled, so text is not updated
+ Assert.assertEquals("Counter has been updated 1 times",
+ getCounterText());
+
+ getDirectCounterUpdateButton().click();
+ // Direct update is visible, and includes previous update
+ Assert.assertEquals("Counter has been updated 3 times",
+ getCounterText());
+
+ // Re-enable push
+ getPushToggle().click();
+ getDelayedCounterUpdateButton().click();
+ sleep(2000);
+
+ // Push is enabled again, so text gets updated
+ Assert.assertEquals("Counter has been updated 4 times",
+ getCounterText());
+ }
+
+ private WebElement getDirectCounterUpdateButton() {
+ return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VButton[0]/domChild[0]/domChild[0]");
+ }
+
+ private WebElement getPushToggle() {
+ return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]");
+ }
+
+ private String getCounterText() {
+ return vaadinElement(
+ "/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VLabel[0]")
+ .getText();
+ }
+
+ private WebElement getDelayedCounterUpdateButton() {
+ return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[3]/VButton[0]/domChild[0]/domChild[0]");
+ }
+ }
+
private final Label counterLabel = new Label();
private int counter = 0;
+++ /dev/null
-<?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:8071/" />
-<title>TogglePushInInit</title>
-</head>
-<body>
-<table cellpadding="1" cellspacing="1" border="1">
-<thead>
-<tr><td rowspan="1" colspan="3">TogglePushInInit</td></tr>
-</thead><tbody>
-<!--Open with push disabled-->
-<tr>
- <td>open</td>
- <td>/run-push/com.vaadin.tests.push.TogglePush?restartApplication&push=disabled</td>
- <td></td>
-</tr>
-<tr>
- <td>assertValue</td>
- <td>vaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]</td>
- <td>off</td>
-</tr>
-<tr>
- <td>click</td>
- <td>vaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[3]/VButton[0]/domChild[0]/domChild[0]</td>
- <td></td>
-</tr>
-<tr>
- <td>pause</td>
- <td>2000</td>
- <td></td>
-</tr>
-<tr>
- <td>assertText</td>
- <td>vaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VLabel[0]</td>
- <td>Counter has been updated 0 times</td>
-</tr>
-<!--Open with push enabled-->
-<tr>
- <td>open</td>
- <td>/run-push/com.vaadin.tests.push.TogglePush?restartApplication&push=enabled</td>
- <td></td>
-</tr>
-<tr>
- <td>assertValue</td>
- <td>vaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]</td>
- <td>on</td>
-</tr>
-<tr>
- <td>click</td>
- <td>vaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[3]/VButton[0]/domChild[0]/domChild[0]</td>
- <td></td>
-</tr>
-<tr>
- <td>pause</td>
- <td>2000</td>
- <td></td>
-</tr>
-<tr>
- <td>assertText</td>
- <td>vaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VLabel[0]</td>
- <td>Counter has been updated 1 times</td>
-</tr>
-
-</tbody></table>
-</body>
-</html>
+++ /dev/null
-<?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://192.168.2.162:8888/" />
-<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.push.TrackMessageSizeUnitTests?restartApplication</td>
- <td></td>
-</tr>
-<tr>
- <td>assertText</td>
- <td>vaadin=runcomvaadintestspushTrackMessageSizeUnitTests::PID_SLog_row_0</td>
- <td>1. All tests run</td>
-</tr>
-</tbody></table>
-</body>
-</html>
import org.apache.commons.io.IOUtils;
import org.json.JSONArray;
import org.json.JSONException;
+import org.junit.Assert;
+import org.junit.Test;
import com.vaadin.annotations.JavaScript;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinService;
import com.vaadin.server.VaadinServletService;
import com.vaadin.tests.components.AbstractTestUIWithLog;
+import com.vaadin.tests.tb3.MultiBrowserTest;
import com.vaadin.ui.JavaScriptFunction;
// Load vaadinPush.js so that jQueryVaadin is defined
@JavaScript("vaadin://vaadinPush.js")
public class TrackMessageSizeUnitTests extends AbstractTestUIWithLog {
+ public static class TrackMessageSizeUnitTestsTB3 extends MultiBrowserTest {
+ @Test
+ public void runTests() {
+ Assert.assertEquals("1. All tests run",
+ vaadinElementById("Log_row_0").getText());
+ }
+ }
+
private String testMethod = "function testSequence(expected, data) {\n"
+ " var request = {trackMessageLength: true, messageDelimiter: '|'};\n"
+ " var response = {partialMessage: ''};\n"
package com.vaadin.tests.tb3;
import java.net.URL;
+import java.util.Collection;
+import java.util.Collections;
import org.junit.After;
import org.junit.Before;
+import org.junit.runner.RunWith;
+import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.BrowserType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
+import org.openqa.selenium.support.ui.ExpectedCondition;
+import org.openqa.selenium.support.ui.ExpectedConditions;
+import org.openqa.selenium.support.ui.WebDriverWait;
import com.vaadin.server.LegacyApplication;
-import com.vaadin.testbench.By;
import com.vaadin.testbench.TestBench;
import com.vaadin.testbench.TestBenchTestCase;
import com.vaadin.ui.UI;
*
* @author Vaadin Ltd
*/
+@RunWith(value = TB3Runner.class)
public abstract class AbstractTB3Test extends TestBenchTestCase {
/**
* Height of the screenshots we want to capture
*/
protected abstract String getDeploymentHostname();
+ /**
+ * Produces a collection of browsers to run the test on. This method is
+ * executed by the test runner when determining how many test methods to
+ * invoke and with what parameters. For each returned value a test method is
+ * ran and before running that,
+ * {@link #setDesiredCapabilities(DesiredCapabilities)} is invoked with the
+ * value returned by this method.
+ *
+ * This method is not static to allow overriding it in sub classes. By
+ * default runs the test only on Firefox
+ *
+ * @return The browsers to run the test on
+ */
+ public Collection<DesiredCapabilities> getBrowsersToTest() {
+ return Collections.singleton(BrowserUtil.firefox(17));
+
+ }
+
/**
* Used to determine which capabilities should be used when setting up a
* {@link WebDriver} for this test. Typically set by a test runner or left
}
/**
- * Finds a Vaadin element based on the part of a TB3 style locator following
- * the :: (e.g.
- * vaadin=runLabelModes::PID_Scheckboxaction-Enabled/domChild[0] ->
+ * Finds an element based on the part of a TB2 style locator following the
+ * :: (e.g. vaadin=runLabelModes::PID_Scheckboxaction-Enabled/domChild[0] ->
* PID_Scheckboxaction-Enabled/domChild[0]).
*
* @param vaadinLocator
* @return
*/
protected WebElement vaadinElement(String vaadinLocator) {
- String base = getApplicationId(getDeploymentPath());
-
- base += "::";
-
- return driver.findElement(By.vaadin(base + vaadinLocator));
+ return driver.findElement(vaadinLocator(vaadinLocator));
}
/**
* @return
*/
public WebElement vaadinElementById(String id) {
- return vaadinElement("PID_S" + id);
+ return driver.findElement(vaadinLocatorById(id));
+ }
+
+ /**
+ * Finds a {@link By} locator based on the part of a TB2 style locator
+ * following the :: (e.g.
+ * vaadin=runLabelModes::PID_Scheckboxaction-Enabled/domChild[0] ->
+ * PID_Scheckboxaction-Enabled/domChild[0]).
+ *
+ * @param vaadinLocator
+ * The part following :: of the vaadin locator string
+ * @return
+ */
+ public org.openqa.selenium.By vaadinLocator(String vaadinLocator) {
+ String base = getApplicationId(getDeploymentPath());
+
+ base += "::";
+ return com.vaadin.testbench.By.vaadin(base + vaadinLocator);
+ }
+
+ /**
+ * Constructs a {@link By} locator for the id given using Component.setId
+ *
+ * @param id
+ * The id to locate
+ * @return a locator for the given id
+ */
+ public By vaadinLocatorById(String id) {
+ return vaadinLocator("PID_S" + id);
+ }
+
+ /**
+ * Waits a short while for the given condition to become true. Use e.g. as
+ * {@link #waitUntil(ExpectedConditions.textToBePresentInElement(by, text))}
+ *
+ * @param condition
+ * the condition to wait for to become true
+ */
+ protected void waitUntil(ExpectedCondition<Boolean> condition) {
+ new WebDriverWait(driver, 10).until(condition);
+ }
+
+ /**
+ * Waits a short while for the given condition to become false. Use e.g. as
+ * {@link #waitUntilNot(ExpectedConditions.textToBePresentInElement(by,
+ * text))}
+ *
+ * @param condition
+ * the condition to wait for to become false
+ */
+ protected void waitUntilNot(ExpectedCondition<Boolean> condition) {
+ new WebDriverWait(driver, 10).until(ExpectedConditions.not(condition));
}
/**
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.List;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized.Parameters;
import org.openqa.selenium.remote.DesiredCapabilities;
/**
*
* @author Vaadin Ltd
*/
-@RunWith(value = TB3Runner.class)
public abstract class MultiBrowserTest extends PrivateTB3Configuration {
- private static List<DesiredCapabilities> allBrowsers = new ArrayList<DesiredCapabilities>();
- private static List<DesiredCapabilities> websocketBrowsers = new ArrayList<DesiredCapabilities>();
+ static List<DesiredCapabilities> allBrowsers = new ArrayList<DesiredCapabilities>();
static {
allBrowsers.add(BrowserUtil.ie(8));
allBrowsers.add(BrowserUtil.ie(9));
allBrowsers.add(BrowserUtil.chrome(29));
allBrowsers.add(BrowserUtil.opera(12));
- websocketBrowsers.addAll(allBrowsers);
- websocketBrowsers.remove(BrowserUtil.ie(8));
- websocketBrowsers.remove(BrowserUtil.ie(9));
- }
-
- @Parameters
- public static Collection<DesiredCapabilities> getBrowsersForTest() {
- return getAllBrowsers();
- }
-
- public static Collection<DesiredCapabilities> getAllBrowsers() {
- return Collections.unmodifiableCollection(allBrowsers);
}
/**
- * @return A subset of {@link #getAllBrowsers()} including only those which
- * support websockets
+ * @return all supported browsers which are actively tested
*/
- public static Collection<DesiredCapabilities> getWebsocketBrowsers() {
- return Collections.unmodifiableCollection(websocketBrowsers);
+ public static List<DesiredCapabilities> getAllBrowsers() {
+ return allBrowsers;
+ }
+
+ @Override
+ public Collection<DesiredCapabilities> getBrowsersToTest() {
+ return allBrowsers;
}
}
package com.vaadin.tests.tb3;
import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.Arrays;
-import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.junit.Test;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.InitializationError;
import org.junit.runners.model.Statement;
protected List<FrameworkMethod> computeTestMethods() {
List<FrameworkMethod> tests = new LinkedList<FrameworkMethod>();
- // Find all methods in our test class marked with @Parameters.
- for (FrameworkMethod method : getTestClass().getAnnotatedMethods(
- Parameters.class)) {
- // Make sure the Parameters method is static
- if (!Modifier.isStatic(method.getMethod().getModifiers())) {
- throw new IllegalArgumentException("@Parameters " + method
- + " must be static.");
- }
-
- // Execute the method (statically)
- Object params;
- try {
- params = method.getMethod().invoke(
- getTestClass().getJavaClass());
- } catch (Throwable t) {
- throw new RuntimeException("Could not run test factory method "
- + method.getName(), t);
- }
-
- // Did the factory return an array? If so, make it a list.
- if (params.getClass().isArray()) {
- params = Arrays.asList((Object[]) params);
- }
+ if (!AbstractTB3Test.class.isAssignableFrom(getTestClass()
+ .getJavaClass())) {
+ throw new RuntimeException(getClass().getName() + " only supports "
+ + AbstractTB3Test.class.getName());
+ }
- // Did the factory return a scalar object? If so, put it in a list.
- if (!(params instanceof Iterable<?>)) {
- params = Collections.singletonList(params);
- }
+ try {
+ AbstractTB3Test testClassInstance = (AbstractTB3Test) getTestClass()
+ .getOnlyConstructor().newInstance();
+ for (DesiredCapabilities capabilities : testClassInstance
+ .getBrowsersToTest()) {
- // For each object returned by the factory.
- for (Object param : (Iterable<?>) params) {
- if (!(param instanceof DesiredCapabilities)) {
- throw new RuntimeException("Unexpected parameter type "
- + param.getClass().getName()
- + " when expecting DesiredCapabilities");
- }
- DesiredCapabilities capabilities = (DesiredCapabilities) param;
// Find any methods marked with @Test.
for (FrameworkMethod m : getTestClass().getAnnotatedMethods(
Test.class)) {
tests.add(new TB3Method(m.getMethod(), capabilities));
}
}
+ } catch (Exception e) {
+ throw new RuntimeException("Error retrieving browsers to run on", e);
}
return tests;
--- /dev/null
+/*
+ * Copyright 2000-2013 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+/**
+ *
+ */
+package com.vaadin.tests.tb3;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import org.openqa.selenium.remote.DesiredCapabilities;
+
+/**
+ * A {@link MultiBrowserTest} which restricts the tests to the browsers which
+ * support websocket
+ *
+ * @author Vaadin Ltd
+ */
+public abstract class WebsocketTest extends PrivateTB3Configuration {
+ private static List<DesiredCapabilities> websocketBrowsers = new ArrayList<DesiredCapabilities>();
+ static {
+ websocketBrowsers.addAll(MultiBrowserTest.getAllBrowsers());
+ websocketBrowsers.remove(BrowserUtil.ie(8));
+ websocketBrowsers.remove(BrowserUtil.ie(9));
+ }
+
+ /**
+ * @return All supported browsers which are actively tested and support
+ * websockets
+ */
+ public static Collection<DesiredCapabilities> getWebsocketBrowsers() {
+ return Collections.unmodifiableCollection(websocketBrowsers);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.tests.tb3.AbstractTB3Test#getBrowserToRunOn()
+ */
+ @Override
+ public Collection<DesiredCapabilities> getBrowsersToTest() {
+ return getWebsocketBrowsers();
+ }
+}