diff options
Diffstat (limited to 'uitest/src/com/vaadin/tests/extensions')
8 files changed, 470 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/extensions/BasicExtension.java b/uitest/src/com/vaadin/tests/extensions/BasicExtension.java new file mode 100644 index 0000000000..e4fc291728 --- /dev/null +++ b/uitest/src/com/vaadin/tests/extensions/BasicExtension.java @@ -0,0 +1,27 @@ +/* + * Copyright 2011 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.extensions; + +import com.vaadin.server.AbstractClientConnector; +import com.vaadin.server.AbstractExtension; + +public class BasicExtension extends AbstractExtension { + @Override + public void extend(AbstractClientConnector target) { + super.extend(target); + } +}
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/extensions/BasicExtensionTest.html b/uitest/src/com/vaadin/tests/extensions/BasicExtensionTest.html new file mode 100644 index 0000000000..c57882b3f4 --- /dev/null +++ b/uitest/src/com/vaadin/tests/extensions/BasicExtensionTest.html @@ -0,0 +1,41 @@ +<?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.41: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.extensions.BasicExtensionTest?restartApplication</td> + <td></td> +</tr> +<tr> + <td>assertText</td> + <td>//div[1]</td> + <td>BasicExtensionTestConnector extending LabelConnector</td> +</tr> +<tr> + <td>assertText</td> + <td>//div[2]</td> + <td>BasicExtensionTestConnector extending UIConnector</td> +</tr> +<tr> + <td>click</td> + <td>vaadin=runcomvaadintestsextensionsBasicExtensionTest::/VVerticalLayout[0]/VVerticalLayout[0]/VButton[0]/domChild[0]/domChild[0]</td> + <td></td> +</tr> +<tr> + <td>assertText</td> + <td>//div[1]</td> + <td>BasicExtensionTestConnector removed for UIConnector</td> +</tr> +</tbody></table> +</body> +</html> diff --git a/uitest/src/com/vaadin/tests/extensions/BasicExtensionTest.java b/uitest/src/com/vaadin/tests/extensions/BasicExtensionTest.java new file mode 100644 index 0000000000..40856af11e --- /dev/null +++ b/uitest/src/com/vaadin/tests/extensions/BasicExtensionTest.java @@ -0,0 +1,56 @@ +/* + * Copyright 2011 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.extensions; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.WrappedRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.Label; + +@Widgetset("com.vaadin.tests.widgetset.TestingWidgetSet") +public class BasicExtensionTest extends AbstractTestUI { + + @Override + protected void setup(WrappedRequest request) { + Label label = new Label(); + addComponent(label); + + final BasicExtension rootExtension = new BasicExtension(); + rootExtension.extend(this); + new BasicExtension().extend(label); + addComponent(new Button("Remove root extension", new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + rootExtension.removeFromTarget(); + } + })); + } + + @Override + protected String getTestDescription() { + return "Simple test for extending components"; + } + + @Override + protected Integer getTicketNumber() { + return Integer.valueOf(6690); + } + +} diff --git a/uitest/src/com/vaadin/tests/extensions/HelloWorldExtension.java b/uitest/src/com/vaadin/tests/extensions/HelloWorldExtension.java new file mode 100644 index 0000000000..e8a33fd3af --- /dev/null +++ b/uitest/src/com/vaadin/tests/extensions/HelloWorldExtension.java @@ -0,0 +1,51 @@ +/* + * Copyright 2011 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.extensions; + +import com.vaadin.server.AbstractExtension; +import com.vaadin.tests.widgetset.client.helloworldfeature.GreetAgainRpc; +import com.vaadin.tests.widgetset.client.helloworldfeature.HelloWorldRpc; +import com.vaadin.tests.widgetset.client.helloworldfeature.HelloWorldState; +import com.vaadin.ui.Notification; + +public class HelloWorldExtension extends AbstractExtension { + + public HelloWorldExtension() { + registerRpc(new HelloWorldRpc() { + @Override + public void onMessageSent(String message) { + Notification.show(message); + } + }); + } + + @Override + public HelloWorldState getState() { + return (HelloWorldState) super.getState(); + } + + public void setGreeting(String greeting) { + getState().setGreeting(greeting); + } + + public String getGreeting() { + return getState().getGreeting(); + } + + public void greetAgain() { + getRpcProxy(GreetAgainRpc.class).greetAgain(); + } +} diff --git a/uitest/src/com/vaadin/tests/extensions/HelloWorldExtensionTest.java b/uitest/src/com/vaadin/tests/extensions/HelloWorldExtensionTest.java new file mode 100644 index 0000000000..576b16fbb6 --- /dev/null +++ b/uitest/src/com/vaadin/tests/extensions/HelloWorldExtensionTest.java @@ -0,0 +1,52 @@ +/* + * Copyright 2011 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.extensions; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.WrappedRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; + +@Widgetset("com.vaadin.tests.widgetset.TestingWidgetSet") +public class HelloWorldExtensionTest extends AbstractTestUI { + + @Override + protected void setup(WrappedRequest request) { + final HelloWorldExtension extension = new HelloWorldExtension(); + extension.setGreeting("Kind words"); + addExtension(extension); + + addComponent(new Button("Greet again", new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + extension.greetAgain(); + } + })); + } + + @Override + protected String getTestDescription() { + return "Testing basic Extension"; + } + + @Override + protected Integer getTicketNumber() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/uitest/src/com/vaadin/tests/extensions/JavascriptManagerTest.html b/uitest/src/com/vaadin/tests/extensions/JavascriptManagerTest.html new file mode 100644 index 0000000000..7bdb8cd50f --- /dev/null +++ b/uitest/src/com/vaadin/tests/extensions/JavascriptManagerTest.html @@ -0,0 +1,47 @@ +<?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.extensions.JavascriptManagerTest?restartApplication</td> + <td></td> +</tr> +<tr> + <td>assertText</td> + <td>vaadin=runcomvaadintestsextensionsJavascriptManagerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[4]</td> + <td>1. Got 4 arguments</td> +</tr> +<tr> + <td>assertText</td> + <td>vaadin=runcomvaadintestsextensionsJavascriptManagerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[3]</td> + <td>2. Argument 1 as a number: 42</td> +</tr> +<tr> + <td>assertText</td> + <td>vaadin=runcomvaadintestsextensionsJavascriptManagerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[2]</td> + <td>3. Argument 2 as a string: text</td> +</tr> +<tr> + <td>assertText</td> + <td>vaadin=runcomvaadintestsextensionsJavascriptManagerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[1]</td> + <td>4. Argument 3.p as a boolean: true</td> +</tr> +<tr> + <td>assertText</td> + <td>vaadin=runcomvaadintestsextensionsJavascriptManagerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[0]</td> + <td>5. Argument 4 is JSONObject.NULL: true</td> +</tr> + +</tbody></table> +</body> +</html> diff --git a/uitest/src/com/vaadin/tests/extensions/JavascriptManagerTest.java b/uitest/src/com/vaadin/tests/extensions/JavascriptManagerTest.java new file mode 100644 index 0000000000..a4e2acb31e --- /dev/null +++ b/uitest/src/com/vaadin/tests/extensions/JavascriptManagerTest.java @@ -0,0 +1,63 @@ +/* + * Copyright 2011 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.extensions; + +import com.vaadin.external.json.JSONArray; +import com.vaadin.external.json.JSONException; +import com.vaadin.external.json.JSONObject; +import com.vaadin.server.WrappedRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.tests.util.Log; +import com.vaadin.ui.JavaScript; +import com.vaadin.ui.JavaScriptFunction; + +public class JavascriptManagerTest extends AbstractTestUI { + + private Log log = new Log(5); + + @Override + protected void setup(WrappedRequest request) { + addComponent(log); + final JavaScript js = JavaScript.getCurrent(); + js.addFunction("testing.doTest", new JavaScriptFunction() { + @Override + public void call(JSONArray arguments) throws JSONException { + log.log("Got " + arguments.length() + " arguments"); + log.log("Argument 1 as a number: " + arguments.getInt(0)); + log.log("Argument 2 as a string: " + arguments.getString(1)); + log.log("Argument 3.p as a boolean: " + + arguments.getJSONObject(2).getBoolean("p")); + log.log("Argument 4 is JSONObject.NULL: " + + (arguments.get(3) == JSONObject.NULL)); + js.removeFunction("testing.doTest"); + } + }); + js.execute("window.testing.doTest(42, 'text', {p: true}, null)"); + } + + @Override + protected String getTestDescription() { + return "Test javascript callback handling by adding a callback and invoking the javascript."; + } + + @Override + protected Integer getTicketNumber() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/uitest/src/com/vaadin/tests/extensions/SimpleJavaScriptExtensionTest.java b/uitest/src/com/vaadin/tests/extensions/SimpleJavaScriptExtensionTest.java new file mode 100644 index 0000000000..18054c8e0f --- /dev/null +++ b/uitest/src/com/vaadin/tests/extensions/SimpleJavaScriptExtensionTest.java @@ -0,0 +1,133 @@ +/* + * Copyright 2011 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.extensions; + +import com.vaadin.annotations.JavaScript; +import com.vaadin.annotations.StyleSheet; +import com.vaadin.external.json.JSONArray; +import com.vaadin.external.json.JSONException; +import com.vaadin.server.AbstractJavaScriptExtension; +import com.vaadin.server.WrappedRequest; +import com.vaadin.shared.JavaScriptExtensionState; +import com.vaadin.shared.communication.ClientRpc; +import com.vaadin.shared.communication.ServerRpc; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.JavaScriptFunction; +import com.vaadin.ui.Notification; + +public class SimpleJavaScriptExtensionTest extends AbstractTestUI { + + public static class SimpleJavaScriptExtensionState extends + JavaScriptExtensionState { + private String prefix; + + public void setPrefix(String prefix) { + this.prefix = prefix; + } + + public String getPrefix() { + return prefix; + } + } + + public static interface SimpleJavaScriptExtensionClientRpc extends + ClientRpc { + public void greet(String message); + } + + public static interface SimpleJavaScriptExtensionServerRpc extends + ServerRpc { + public void greet(String message); + } + + @JavaScript("/statictestfiles/jsextension.js") + @StyleSheet("/VAADIN/external1.css") + public static class SimpleJavascriptExtension extends + AbstractJavaScriptExtension { + + public SimpleJavascriptExtension() { + registerRpc(new SimpleJavaScriptExtensionServerRpc() { + @Override + public void greet(String message) { + Notification.show(getState().getPrefix() + message); + } + }); + addFunction("greetToServer", new JavaScriptFunction() { + @Override + public void call(JSONArray arguments) throws JSONException { + Notification.show(getState().getPrefix() + + arguments.getString(0)); + } + }); + } + + @Override + public SimpleJavaScriptExtensionState getState() { + return (SimpleJavaScriptExtensionState) super.getState(); + } + + public void setPrefix(String prefix) { + getState().setPrefix(prefix); + } + + public void greetRpc(String message) { + getRpcProxy(SimpleJavaScriptExtensionClientRpc.class) + .greet(message); + } + + public void greetCallback(String message) { + callFunction("greetToClient", message); + } + } + + @Override + protected void setup(WrappedRequest request) { + final SimpleJavascriptExtension simpleJavascriptExtension = new SimpleJavascriptExtension(); + simpleJavascriptExtension.setPrefix("Prefix: "); + addExtension(simpleJavascriptExtension); + addComponent(new Button("Send rpc greeting", + new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + simpleJavascriptExtension.greetRpc("Rpc greeting"); + } + })); + addComponent(new Button("Send callback greeting", + new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + simpleJavascriptExtension + .greetCallback("Callback greeting"); + } + })); + } + + @Override + protected String getTestDescription() { + // TODO Auto-generated method stub + return null; + } + + @Override + protected Integer getTicketNumber() { + // TODO Auto-generated method stub + return null; + } + +} |