From 8755b91e50da26a214eaf144e230a7cb15637127 Mon Sep 17 00:00:00 2001 From: Henri Sara Date: Sat, 11 Jul 2015 10:47:47 +0300 Subject: [PATCH] Convert EmbeddedClickListenerRelativeCoordinates test to TB4 Change-Id: Iaac3a80428a9b58ba82e814d8665dd17920ab2bd --- ...eddedClickListenerRelativeCoordinates.java | 13 ++- ...dClickListenerRelativeCoordinatesTest.java | 86 +++++++++++++++++++ ...eddedClickListenerRelativeCoordinates.html | 51 ----------- 3 files changed, 95 insertions(+), 55 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/embedded/EmbeddedClickListenerRelativeCoordinatesTest.java delete mode 100644 uitest/tb2/com/vaadin/tests/components/embedded/EmbeddedClickListenerRelativeCoordinates.html diff --git a/uitest/src/com/vaadin/tests/components/embedded/EmbeddedClickListenerRelativeCoordinates.java b/uitest/src/com/vaadin/tests/components/embedded/EmbeddedClickListenerRelativeCoordinates.java index 3c5801e90e..28ffebcf56 100644 --- a/uitest/src/com/vaadin/tests/components/embedded/EmbeddedClickListenerRelativeCoordinates.java +++ b/uitest/src/com/vaadin/tests/components/embedded/EmbeddedClickListenerRelativeCoordinates.java @@ -5,6 +5,7 @@ import com.vaadin.event.MouseEvents.ClickListener; import com.vaadin.server.ThemeResource; import com.vaadin.tests.components.TestBase; import com.vaadin.ui.Embedded; +import com.vaadin.ui.Label; public class EmbeddedClickListenerRelativeCoordinates extends TestBase { @@ -12,17 +13,21 @@ public class EmbeddedClickListenerRelativeCoordinates extends TestBase { protected void setup() { Embedded e = new Embedded("Embedded caption", new ThemeResource( "../runo/icons/64/ok.png")); + final Label xLabel = new Label(); + xLabel.setId("x"); + final Label yLabel = new Label(); + yLabel.setId("y"); e.addListener(new ClickListener() { @Override public void click(ClickEvent event) { - getMainWindow() - .showNotification( - "" + event.getRelativeX() + ", " - + event.getRelativeY()); + xLabel.setValue("" + event.getRelativeX()); + yLabel.setValue("" + event.getRelativeY()); } }); addComponent(e); + addComponent(xLabel); + addComponent(yLabel); } @Override diff --git a/uitest/src/com/vaadin/tests/components/embedded/EmbeddedClickListenerRelativeCoordinatesTest.java b/uitest/src/com/vaadin/tests/components/embedded/EmbeddedClickListenerRelativeCoordinatesTest.java new file mode 100644 index 0000000000..6bed0117f8 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/embedded/EmbeddedClickListenerRelativeCoordinatesTest.java @@ -0,0 +1,86 @@ +/* + * Copyright 2000-2014 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.embedded; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.By; + +import com.vaadin.testbench.elements.EmbeddedElement; +import com.vaadin.testbench.elements.LabelElement; +import com.vaadin.testbench.parallel.BrowserUtil; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class EmbeddedClickListenerRelativeCoordinatesTest extends + MultiBrowserTest { + + @Before + @Override + public void setup() throws Exception { + super.setup(); + openTestURL(); + waitForElementPresent(By.className("v-embedded")); + } + + @Test + public void testRelativeClick() { + clickAt(41, 22); + checkLocation(41, 22); + + clickAt(0, 0); + checkLocation(0, 0); + } + + private void clickAt(int x, int y) { + EmbeddedElement embedded = $(EmbeddedElement.class).first(); + + // IE8 consistently clicks two pixels left and above of the given + // position + if (isIE8()) { + x += 2; + y += 2; + } + embedded.click(x, y); + } + + private void checkLocation(int expectedX, int expectedY) { + LabelElement xLabel = $(LabelElement.class).id("x"); + LabelElement yLabel = $(LabelElement.class).id("y"); + + int x = Integer.parseInt(xLabel.getText()); + int y = Integer.parseInt(yLabel.getText()); + + Assert.assertEquals( + "Reported X-coordinate from Embedded does not match click location", + expectedX, x); + + // IE10 and IE11 sometimes click one pixel below the given position + int tolerance = isIE() ? 1 : 0; + Assert.assertTrue( + "Reported Y-coordinate from Embedded does not match click location", + Math.abs(expectedY - y) <= tolerance); + } + + private boolean isIE() { + return BrowserUtil.isIE(getDesiredCapabilities()); + } + + private boolean isIE8() { + return BrowserUtil.isIE8(getDesiredCapabilities()); + } + +} diff --git a/uitest/tb2/com/vaadin/tests/components/embedded/EmbeddedClickListenerRelativeCoordinates.html b/uitest/tb2/com/vaadin/tests/components/embedded/EmbeddedClickListenerRelativeCoordinates.html deleted file mode 100644 index ae81cfe61c..0000000000 --- a/uitest/tb2/com/vaadin/tests/components/embedded/EmbeddedClickListenerRelativeCoordinates.html +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - -EmbeddedClickListenerRelativeCoordinates - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EmbeddedClickListenerRelativeCoordinates
open/run/com.vaadin.tests.components.embedded.EmbeddedClickListenerRelativeCoordinates?restartApplication
mouseClickvaadin=runcomvaadintestscomponentsembeddedEmbeddedClickListenerRelativeCoordinates::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VEmbedded[0]/domChild[0]41,22
assertTextvaadin=runcomvaadintestscomponentsembeddedEmbeddedClickListenerRelativeCoordinates::Root/VNotification[0]/HTML[0]/domChild[1]41, 22
mouseClickvaadin=runcomvaadintestscomponentsembeddedEmbeddedClickListenerRelativeCoordinates::Root/VNotification[0]0,0
waitForElementNotPresentvaadin=runcomvaadintestscomponentsembeddedEmbeddedClickListenerRelativeCoordinates::Root/VNotification[0]/HTML[0]/domChild[1]
mouseClickvaadin=runcomvaadintestscomponentsembeddedEmbeddedClickListenerRelativeCoordinates::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VEmbedded[0]/domChild[0]0,0
assertTextvaadin=runcomvaadintestscomponentsembeddedEmbeddedClickListenerRelativeCoordinates::Root/VNotification[0]/HTML[0]/domChild[1]0, 0
- - -- 2.39.5