aboutsummaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorDenis Anisimov <denis@vaadin.com>2014-10-14 22:16:00 +0300
committerVaadin Code Review <review@vaadin.com>2014-10-21 10:21:01 +0000
commita26e300746c0857aadc10f292e2f644f25334123 (patch)
tree97514070a67fed5708dd48a6503764af2590cf87 /uitest
parent6ddca165279e7f7404b794d5032e9d64cbb5a996 (diff)
downloadvaadin-framework-a26e300746c0857aadc10f292e2f644f25334123.tar.gz
vaadin-framework-a26e300746c0857aadc10f292e2f644f25334123.zip
Correct positioning and sizing logic for context menu (#14863).
Change-Id: Ic2edd6e6f53cd8ae3dc2d39477f59261356beafd
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/com/vaadin/tests/components/table/ContextMenuSize.java77
-rw-r--r--uitest/src/com/vaadin/tests/components/table/ContextMenuSizeTest.java131
2 files changed, 208 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/components/table/ContextMenuSize.java b/uitest/src/com/vaadin/tests/components/table/ContextMenuSize.java
new file mode 100644
index 0000000000..ec7301099f
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/table/ContextMenuSize.java
@@ -0,0 +1,77 @@
+/*
+ * 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.table;
+
+import com.vaadin.data.util.BeanItemContainer;
+import com.vaadin.event.Action;
+import com.vaadin.event.Action.Handler;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Table;
+
+/**
+ * Test UI for table context menu position and size.
+ *
+ * @author Vaadin Ltd
+ */
+public class ContextMenuSize extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ Table table = new Table();
+ table.setPageLength(1);
+ table.addActionHandler(new Handler() {
+
+ @Override
+ public void handleAction(Action action, Object sender, Object target) {
+ }
+
+ @Override
+ public Action[] getActions(Object target, Object sender) {
+ return new Action[] { new Action("action1"),
+ new Action("action2"), new Action("action3"),
+ new Action("action4") };
+ }
+ });
+ BeanItemContainer<Bean> container = new BeanItemContainer<Bean>(
+ Bean.class);
+ container.addBean(new Bean());
+ table.setContainerDataSource(container);
+ addComponent(table);
+ }
+
+ @Override
+ public String getDescription() {
+ return "If context menu original position doesn't allow to show it then "
+ + "its bottom should be aligned with the window bottom and height "
+ + "should be reset after repositioning.";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 14863;
+ }
+
+ public static class Bean {
+
+ public String getName() {
+ return "name";
+ }
+
+ public void setName() {
+ }
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/components/table/ContextMenuSizeTest.java b/uitest/src/com/vaadin/tests/components/table/ContextMenuSizeTest.java
new file mode 100644
index 0000000000..bb7001bc97
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/table/ContextMenuSizeTest.java
@@ -0,0 +1,131 @@
+/*
+ * 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.table;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.Dimension;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.interactions.Actions;
+import org.openqa.selenium.remote.DesiredCapabilities;
+
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+/**
+ * Test for context menu position and size.
+ *
+ * @author Vaadin Ltd
+ */
+public class ContextMenuSizeTest extends MultiBrowserTest {
+
+ @Test
+ public void testContextMenuBottom() {
+ openTestURL();
+
+ WebElement menu = openContextMenu();
+ int initialHeight = menu.getSize().getHeight();
+ int y = menu.getLocation().getY();
+
+ closeContextMenu();
+
+ Dimension size = getDriver().manage().window().getSize();
+
+ int windowHeight = y + initialHeight - 10;
+ if (isElementPresent(By.className("v-ff"))) {
+ // FF does something wrong with window height
+ windowHeight = y + initialHeight + 90;
+ } else if (isElementPresent(By.className("v-ch"))) {
+ // Chrome does something wrong with window height
+ windowHeight = y + initialHeight + 20;
+ }
+ getDriver().manage().window()
+ .setSize(new Dimension(size.getWidth(), windowHeight));
+
+ menu = openContextMenu();
+ int height = menu.getSize().getHeight();
+
+ Assert.assertEquals("Context menu height has been changed after "
+ + "window height update which allows to show context as is",
+ initialHeight, height);
+
+ }
+
+ @Test
+ public void testContextMenuSize() {
+ openTestURL();
+
+ WebElement menu = openContextMenu();
+ int initialHeight = menu.getSize().getHeight();
+ int y = menu.getLocation().getY();
+
+ closeContextMenu();
+
+ Dimension size = getDriver().manage().window().getSize();
+
+ int windowHeight = initialHeight - 10;
+ if (isElementPresent(By.className("v-ch"))) {
+ // Chrome does something wrong with window height
+ windowHeight = y + initialHeight;
+ }
+ getDriver().manage().window()
+ .setSize(new Dimension(size.getWidth(), windowHeight));
+
+ menu = openContextMenu();
+ int height = menu.getSize().getHeight();
+
+ Assert.assertTrue(
+ "Context menu height has not been descreased after "
+ + "window height update to value lower than context menu initial height",
+ initialHeight > height);
+ closeContextMenu();
+
+ getDriver().manage().window()
+ .setSize(new Dimension(size.getWidth(), size.getHeight()));
+ menu = openContextMenu();
+ height = menu.getSize().getHeight();
+ Assert.assertEquals("Context menu height has not been reset after "
+ + "window height reset", initialHeight, height);
+ }
+
+ @Override
+ public List<DesiredCapabilities> getBrowsersToTest() {
+ List<DesiredCapabilities> browsers = new ArrayList<DesiredCapabilities>(
+ getAllBrowsers());
+
+ // context menu doesn't work in phantom JS and works wired with IE8 and
+ // selenium.
+ browsers.remove(Browser.PHANTOMJS.getDesiredCapabilities());
+ browsers.remove(Browser.IE8.getDesiredCapabilities());
+ return browsers;
+ }
+
+ private WebElement openContextMenu() {
+ Actions actions = new Actions(getDriver());
+ actions.contextClick(findElement(By.className("v-table-cell-wrapper")));
+ actions.perform();
+ return findElement(By.className("v-contextmenu"));
+ }
+
+ private void closeContextMenu() {
+ Actions actions = new Actions(getDriver());
+ actions.click().build().perform();
+ }
+
+}