From fefedeab68461ebc04fd45f91a35835fc9026a56 Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 5 Nov 2013 15:21:06 +0200 Subject: Send window position data back to server after drag (#12885) Change-Id: I9ca766b0e06390c7ab90f9cbd4996b83032789db --- .../components/window/WindowMoveListener.java | 67 ++++++++++++++++++++++ .../components/window/WindowMoveListenerTest.java | 50 ++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/components/window/WindowMoveListener.java create mode 100644 uitest/src/com/vaadin/tests/components/window/WindowMoveListenerTest.java (limited to 'uitest/src/com/vaadin/tests/components') diff --git a/uitest/src/com/vaadin/tests/components/window/WindowMoveListener.java b/uitest/src/com/vaadin/tests/components/window/WindowMoveListener.java new file mode 100644 index 0000000000..e0bc0d9471 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/window/WindowMoveListener.java @@ -0,0 +1,67 @@ +package com.vaadin.tests.components.window; + +import com.vaadin.server.VaadinRequest; +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.Window; + +@SuppressWarnings("serial") +public class WindowMoveListener extends AbstractTestUI { + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.components.AbstractTestUI#setup(com.vaadin.server. + * VaadinRequest) + */ + @Override + protected void setup(VaadinRequest request) { + + Window w = new Window("Caption"); + w.setId("testwindow"); + w.setHeight("100px"); + w.setWidth("100px"); + w.setPositionX(100); + w.setPositionY(100); + addWindow(w); + + Button b = new Button(); + b.setId("testbutton"); + addComponent(b); + b.addClickListener(new ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + for (Window window : getWindows()) { + window.setPositionX(100); + window.setPositionY(100); + } + } + }); + + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.components.AbstractTestUI#getTestDescription() + */ + @Override + protected String getTestDescription() { + return "Tests that windows send their updated position " + + "to server-side after being moved by user"; + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.components.AbstractTestUI#getTicketNumber() + */ + @Override + protected Integer getTicketNumber() { + return 12885; + } + +} \ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/components/window/WindowMoveListenerTest.java b/uitest/src/com/vaadin/tests/components/window/WindowMoveListenerTest.java new file mode 100644 index 0000000000..3ea3b719c0 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/window/WindowMoveListenerTest.java @@ -0,0 +1,50 @@ +package com.vaadin.tests.components.window; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.Point; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Action; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class WindowMoveListenerTest extends MultiBrowserTest { + + @Test + public void testWindowRepositioning() throws Exception { + openTestURL(); + + WebElement window = getDriver().findElement(By.id("testwindow")); + WebElement button = getDriver().findElement(By.id("testbutton")); + + // I'd loved to use the header, but that doesn't work. Footer works + // fine, though :) + WebElement windowHeader = getDriver().findElement( + By.className("v-window-footer")); + + Point winPos = window.getLocation(); + + // move window + Action a = new Actions(driver).clickAndHold(windowHeader) + .moveByOffset(100, 100).release().build(); + a.perform(); + + assertNotEquals("Window was not dragged correctly.", winPos.x, + window.getLocation().x); + assertNotEquals("Window was not dragged correctly.", winPos.y, + window.getLocation().y); + + // re-set window + button.click(); + + assertEquals("Window was not re-positioned correctly.", winPos.x, + window.getLocation().x); + assertEquals("Window was not re-positioned correctly.", winPos.y, + window.getLocation().y); + + } +} \ No newline at end of file -- cgit v1.2.3