summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/com/vaadin/tests/contextclick/AbstractContextClickTest.java66
-rw-r--r--uitest/src/com/vaadin/tests/contextclick/TreeContextClick.java39
-rw-r--r--uitest/src/com/vaadin/tests/contextclick/TreeContextClickTest.java78
3 files changed, 168 insertions, 15 deletions
diff --git a/uitest/src/com/vaadin/tests/contextclick/AbstractContextClickTest.java b/uitest/src/com/vaadin/tests/contextclick/AbstractContextClickTest.java
index 2323d0c9cb..ce97c87b75 100644
--- a/uitest/src/com/vaadin/tests/contextclick/AbstractContextClickTest.java
+++ b/uitest/src/com/vaadin/tests/contextclick/AbstractContextClickTest.java
@@ -18,7 +18,10 @@ package com.vaadin.tests.contextclick;
import static org.junit.Assert.assertEquals;
import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebElement;
@@ -27,11 +30,15 @@ import org.openqa.selenium.remote.DesiredCapabilities;
import com.vaadin.testbench.elements.AbstractComponentElement;
import com.vaadin.testbench.elements.ButtonElement;
-import com.vaadin.testbench.parallel.BrowserUtil;
+import com.vaadin.testbench.parallel.TestCategory;
import com.vaadin.tests.tb3.MultiBrowserTest;
+@TestCategory("contextclick")
public abstract class AbstractContextClickTest extends MultiBrowserTest {
+ private Pattern defaultLog = Pattern
+ .compile("[0-9]+. ContextClickEvent: [(]([0-9]+), ([0-9]+)[)]");
+
@Override
public List<DesiredCapabilities> getBrowsersToTest() {
return getBrowsersSupportingContextMenu();
@@ -67,15 +74,25 @@ public abstract class AbstractContextClickTest extends MultiBrowserTest {
Point l = component.getLocation();
- int drift = 0;
- // IE 10 and 11 report different Y location.
- if (BrowserUtil.isIE(getDesiredCapabilities(), 10)
- || BrowserUtil.isIE(getDesiredCapabilities(), 11)) {
- drift = 1;
- }
-
- assertEquals(index + ". ContextClickEvent: (" + (l.getX() + 10) + ", "
- + (l.getY() + 10 + drift) + ")", getLogRow(0));
+ Matcher matcher = defaultLog.matcher(getLogRow(0));
+ Assert.assertTrue(
+ "Log row content did not match default listener output: "
+ + getLogRow(0), matcher.find());
+
+ int xCoord = Integer.parseInt(matcher.group(1));
+ int yCoord = Integer.parseInt(matcher.group(2));
+
+ int xExpected = l.getX() + 10;
+ int yExpected = l.getY() + 10;
+
+ Assert.assertTrue(
+ "X Coordinate differs too much from expected. Expected: "
+ + xExpected + ", actual: " + xCoord,
+ Math.abs(xExpected - xCoord) <= 1);
+ Assert.assertTrue(
+ "Y Coordinate differs too much from expected. Expected: "
+ + yExpected + ", actual: " + yCoord,
+ Math.abs(yExpected - yCoord) <= 1);
}
protected void addOrRemoveDefaultListener() {
@@ -89,15 +106,34 @@ public abstract class AbstractContextClickTest extends MultiBrowserTest {
}
/**
- * Performs a context click followed by a regular click. This prevents
- * browser context menu from blocking future operations.
+ * Performs a context click on given element at coordinates 10, 10 followed
+ * by a regular click. This prevents browser context menu from blocking
+ * future operations.
*
* @param e
* web element
*/
protected void contextClick(WebElement e) {
- new Actions(getDriver()).moveToElement(e, 10, 10).contextClick()
- .perform();
- new Actions(getDriver()).moveToElement(e, 5, 5).click().perform();
+ contextClick(e, 10, 10);
+ }
+
+ /**
+ * Performs a context click on given element at given coordinates followed
+ * by a regular click. This prevents browser context menu from blocking
+ * future operations.
+ *
+ * @param e
+ * web element
+ * @param xCoord
+ * x coordinate
+ * @param yCoord
+ * y coordinate
+ */
+ protected void contextClick(WebElement e, int xCoord, int yCoord) {
+ new Actions(getDriver()).moveToElement(e, xCoord, yCoord)
+ .contextClick().perform();
+ new Actions(getDriver()).moveToElement(e, xCoord - 5, yCoord - 5)
+ .click().perform();
}
+
}
diff --git a/uitest/src/com/vaadin/tests/contextclick/TreeContextClick.java b/uitest/src/com/vaadin/tests/contextclick/TreeContextClick.java
new file mode 100644
index 0000000000..6b58138ab2
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/contextclick/TreeContextClick.java
@@ -0,0 +1,39 @@
+/*
+ * 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.contextclick;
+
+import com.vaadin.ui.Tree;
+import com.vaadin.ui.Tree.TreeContextClickEvent;
+
+public class TreeContextClick extends
+ AbstractContextClickUI<Tree, TreeContextClickEvent> {
+
+ @Override
+ protected Tree createTestComponent() {
+ Tree tree = new Tree();
+ tree.addItem("Foo");
+ tree.addItem("Bar");
+ tree.addItem("Baz");
+ tree.setParent("Baz", "Bar");
+ tree.setHeight("200px");
+ return tree;
+ }
+
+ @Override
+ protected void handleContextClickEvent(TreeContextClickEvent event) {
+ log("ContextClickEvent: " + event.getItemId());
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/contextclick/TreeContextClickTest.java b/uitest/src/com/vaadin/tests/contextclick/TreeContextClickTest.java
new file mode 100644
index 0000000000..180349af63
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/contextclick/TreeContextClickTest.java
@@ -0,0 +1,78 @@
+/*
+ * 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.contextclick;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.interactions.Actions;
+
+import com.vaadin.testbench.By;
+import com.vaadin.testbench.elements.TreeElement;
+
+public class TreeContextClickTest extends AbstractContextClickTest {
+
+ @Test
+ public void testContextClickOnItem() {
+ openTestURL();
+
+ addOrRemoveTypedListener();
+
+ List<WebElement> nodes = $(TreeElement.class).first().findElements(
+ By.className("v-tree-node"));
+
+ contextClick(nodes.get(1));
+
+ assertEquals("1. ContextClickEvent: Bar", getLogRow(0));
+
+ contextClick(nodes.get(0));
+
+ assertEquals("2. ContextClickEvent: Foo", getLogRow(0));
+ }
+
+ @Test
+ public void testContextClickOnSubItem() {
+ openTestURL();
+
+ addOrRemoveTypedListener();
+
+ List<WebElement> nodes = $(TreeElement.class).first().findElements(
+ By.className("v-tree-node"));
+
+ new Actions(getDriver()).moveToElement(nodes.get(1), 10, 10).click()
+ .perform();
+
+ nodes = $(TreeElement.class).first().findElements(
+ By.className("v-tree-node"));
+ contextClick(nodes.get(2));
+
+ assertEquals("1. ContextClickEvent: Baz", getLogRow(0));
+ }
+
+ @Test
+ public void testContextClickOnEmptyArea() {
+ openTestURL();
+
+ addOrRemoveTypedListener();
+
+ contextClick($(TreeElement.class).first(), 20, 100);
+
+ assertEquals("1. ContextClickEvent: null", getLogRow(0));
+ }
+}