aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src
diff options
context:
space:
mode:
authorHenri Sara <hesara@vaadin.com>2015-07-11 10:47:47 +0300
committerVaadin Code Review <review@vaadin.com>2015-07-13 07:12:10 +0000
commit8755b91e50da26a214eaf144e230a7cb15637127 (patch)
tree7a3e6b4b2fc961c4a3856b69000753bbba6a5b93 /uitest/src
parent1a9581a33efab4bcf7f1b7a6e555fa373d6f0739 (diff)
downloadvaadin-framework-8755b91e50da26a214eaf144e230a7cb15637127.tar.gz
vaadin-framework-8755b91e50da26a214eaf144e230a7cb15637127.zip
Convert EmbeddedClickListenerRelativeCoordinates test to TB4
Change-Id: Iaac3a80428a9b58ba82e814d8665dd17920ab2bd
Diffstat (limited to 'uitest/src')
-rw-r--r--uitest/src/com/vaadin/tests/components/embedded/EmbeddedClickListenerRelativeCoordinates.java13
-rw-r--r--uitest/src/com/vaadin/tests/components/embedded/EmbeddedClickListenerRelativeCoordinatesTest.java86
2 files changed, 95 insertions, 4 deletions
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());
+ }
+
+}