diff options
author | Leif Åstrand <leif@vaadin.com> | 2013-06-06 12:01:37 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-06-10 10:48:23 +0000 |
commit | e7201fd30803dbbd231c9a26745b21d5b807abc0 (patch) | |
tree | a246e6860e75e25ad9e8a5b159bd6944c1567ba9 /uitest | |
parent | d6fca7820739508387ae6db33af3a4a4fb5a846e (diff) | |
download | vaadin-framework-e7201fd30803dbbd231c9a26745b21d5b807abc0.tar.gz vaadin-framework-e7201fd30803dbbd231c9a26745b21d5b807abc0.zip |
Allow using element resize listeners from javascript connectors (#11996)
Change-Id: I97b280c2e260752be87ce85d2eda81ec4f14d4fe
Diffstat (limited to 'uitest')
3 files changed, 200 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/components/javascriptcomponent/JavaScriptResizeListener.html b/uitest/src/com/vaadin/tests/components/javascriptcomponent/JavaScriptResizeListener.html new file mode 100644 index 0000000000..53af1d4ceb --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/javascriptcomponent/JavaScriptResizeListener.html @@ -0,0 +1,81 @@ +<?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.javascriptcomponent.JavaScriptResizeListener?restartApplication&debug</td> + <td></td> +</tr> +<tr> + <td>assertText</td> + <td>vaadin=runcomvaadintestscomponentsjavascriptcomponentJavaScriptResizeListener::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VCssLayout[0]/JavaScriptWidget[0]</td> + <td>Initial state</td> +</tr> +<!--Changing size has no effect without listener--> +<tr> + <td>click</td> + <td>vaadin=runcomvaadintestscomponentsjavascriptcomponentJavaScriptResizeListener::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VButton[0]/domChild[0]/domChild[0]</td> + <td></td> +</tr> +<tr> + <td>assertText</td> + <td>vaadin=runcomvaadintestscomponentsjavascriptcomponentJavaScriptResizeListener::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VCssLayout[0]/JavaScriptWidget[0]</td> + <td>Initial state</td> +</tr> +<!--Reports the size when the listener is added--> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentsjavascriptcomponentJavaScriptResizeListener::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]</td> + <td>52,4</td> +</tr> +<tr> + <td>assertText</td> + <td>vaadin=runcomvaadintestscomponentsjavascriptcomponentJavaScriptResizeListener::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VCssLayout[0]/JavaScriptWidget[0]</td> + <td>Current size is 200 x 50</td> +</tr> +<!--Size change is detected when listener is active--> +<tr> + <td>click</td> + <td>vaadin=runcomvaadintestscomponentsjavascriptcomponentJavaScriptResizeListener::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VButton[0]/domChild[0]</td> + <td></td> +</tr> +<tr> + <td>assertText</td> + <td>vaadin=runcomvaadintestscomponentsjavascriptcomponentJavaScriptResizeListener::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VCssLayout[0]/JavaScriptWidget[0]</td> + <td>Current size is 100 x 100</td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentsjavascriptcomponentJavaScriptResizeListener::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]</td> + <td>69,2</td> +</tr> +<tr> + <td>assertText</td> + <td>vaadin=runcomvaadintestscomponentsjavascriptcomponentJavaScriptResizeListener::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VCssLayout[0]/JavaScriptWidget[0]</td> + <td>Listener disabled</td> +</tr> +<!--Nothing happens when changing size after removing listener--> +<tr> + <td>click</td> + <td>vaadin=runcomvaadintestscomponentsjavascriptcomponentJavaScriptResizeListener::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VButton[0]/domChild[0]/domChild[0]</td> + <td></td> +</tr> +<tr> + <td>assertText</td> + <td>vaadin=runcomvaadintestscomponentsjavascriptcomponentJavaScriptResizeListener::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VCssLayout[0]/JavaScriptWidget[0]</td> + <td>Listener disabled</td> +</tr> + +</tbody></table> +</body> +</html> diff --git a/uitest/src/com/vaadin/tests/components/javascriptcomponent/JavaScriptResizeListener.java b/uitest/src/com/vaadin/tests/components/javascriptcomponent/JavaScriptResizeListener.java new file mode 100644 index 0000000000..9d0094b833 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/javascriptcomponent/JavaScriptResizeListener.java @@ -0,0 +1,96 @@ +/* + * 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.javascriptcomponent; + +import com.vaadin.annotations.JavaScript; +import com.vaadin.data.Property; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.AbstractJavaScriptComponent; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.CheckBox; +import com.vaadin.ui.CssLayout; + +public class JavaScriptResizeListener extends AbstractTestUI { + + @JavaScript("ResizeJsConnector.js") + public class ResizeJsComponent extends AbstractJavaScriptComponent { + public void setListenerEnabled(boolean enabled) { + callFunction("setListenerEnabled", Boolean.valueOf(enabled)); + } + } + + private final ResizeJsComponent resizeJsComponent = new ResizeJsComponent(); + + private final CssLayout holder = new CssLayout(); + + @Override + protected void setup(VaadinRequest request) { + + addComponent(new Button("Change holder size", + new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + updateHolderSize(); + } + })); + addComponent(new CheckBox("Listener active") { + { + setImmediate(true); + addValueChangeListener(new ValueChangeListener() { + @Override + public void valueChange(Property.ValueChangeEvent event) { + resizeJsComponent.setListenerEnabled(event + .getProperty().getValue() == Boolean.TRUE); + } + }); + } + }); + + updateHolderSize(); + addComponent(holder); + + resizeJsComponent.setSizeFull(); + holder.addComponent(resizeJsComponent); + } + + private void updateHolderSize() { + if (holder.getHeight() == 100) { + holder.setHeight("50px"); + } else { + holder.setHeight("100px"); + } + + if (holder.getWidth() == 100) { + holder.setWidth("200px"); + } else { + holder.setWidth("100px"); + } + } + + @Override + protected String getTestDescription() { + return "Test for getting resize events for javascript components"; + } + + @Override + protected Integer getTicketNumber() { + return Integer.valueOf(11996); + } + +} diff --git a/uitest/src/com/vaadin/tests/components/javascriptcomponent/ResizeJsConnector.js b/uitest/src/com/vaadin/tests/components/javascriptcomponent/ResizeJsConnector.js new file mode 100644 index 0000000000..4e871aa1b7 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/javascriptcomponent/ResizeJsConnector.js @@ -0,0 +1,23 @@ +function com_vaadin_tests_components_javascriptcomponent_JavaScriptResizeListener_ResizeJsComponent() { + var self = this; + var e = this.getElement(); + + var setText = function(text) { + e.innerHTML = text; + } + setText('Initial state'); + + var resizeListener = function(event) { + setText('Current size is ' + event.element.offsetWidth + " x " + event.element.offsetHeight); + }; + + this.setListenerEnabled = function(enabled) { + if (enabled) { + setText("Listener enabled"); + self.addResizeListener(e, resizeListener); + } else { + setText("Listener disabled"); + self.removeResizeListener(e, resizeListener); + } + } +}
\ No newline at end of file |