aboutsummaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <teemusa@vaadin.com>2015-05-25 15:14:39 +0300
committerTeppo Kurki <teppo.kurki@vaadin.com>2015-05-27 05:44:51 +0000
commita95f757546892a855def121ec5ce5e5bda927a29 (patch)
treef789ec0c399c5edbf3965bf932d1ec502a10dc9a /uitest
parent0a7b430d50dc8d82e2ca23296381939a7f444846 (diff)
downloadvaadin-framework-a95f757546892a855def121ec5ce5e5bda927a29.tar.gz
vaadin-framework-a95f757546892a855def121ec5ce5e5bda927a29.zip
Fix Grid client-side event support (#17986)
Added a public API to get an EventCellReference for the most recent fired event. Also EventCellReference now contains information on Grid section and some related helpers. Change-Id: Ia8a166da6f322084d65f9b1cb242e22b0e66e53b
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientContextMenuEventTest.java67
-rw-r--r--uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java44
2 files changed, 111 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientContextMenuEventTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientContextMenuEventTest.java
new file mode 100644
index 0000000000..b7242c87be
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientContextMenuEventTest.java
@@ -0,0 +1,67 @@
+/*
+ * 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.grid.basicfeatures.client;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.interactions.Actions;
+import org.openqa.selenium.remote.DesiredCapabilities;
+
+import com.vaadin.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest;
+
+public class GridClientContextMenuEventTest extends GridBasicClientFeaturesTest {
+
+ @Override
+ public List<DesiredCapabilities> getBrowsersToTest() {
+ // PhantomJS doesn't support context click..
+ return getBrowsersExcludingPhantomJS();
+ }
+
+ @Test
+ public void testContextMenuEventIsHandledCorrectly() {
+ setDebug(true);
+ openTestURL();
+
+ selectMenuPath("Component", "Internals", "Listeners",
+ "Add context menu listener");
+
+ openDebugLogTab();
+ clearDebugMessages();
+
+ new Actions(getDriver())
+ .moveToElement(getGridElement().getCell(0, 0), 5, 5)
+ .contextClick().perform();
+
+ assertTrue(
+ "Debug log was not visible",
+ isElementPresent(By
+ .xpath("//span[text() = 'Prevented opening a context menu in grid body']")));
+
+ new Actions(getDriver())
+ .moveToElement(getGridElement().getHeaderCell(0, 0), 5, 5)
+ .contextClick().perform();
+
+ assertTrue(
+ "Debug log was not visible",
+ isElementPresent(By
+ .xpath("//span[text() = 'Prevented opening a context menu in grid header']")));
+
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java b/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java
index 81f000c44e..12c2443c01 100644
--- a/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java
+++ b/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java
@@ -28,7 +28,10 @@ import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.event.dom.client.ContextMenuEvent;
+import com.google.gwt.event.dom.client.ContextMenuHandler;
import com.google.gwt.event.shared.HandlerRegistration;
+import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
@@ -52,6 +55,7 @@ import com.vaadin.client.widget.grid.CellReference;
import com.vaadin.client.widget.grid.CellStyleGenerator;
import com.vaadin.client.widget.grid.DetailsGenerator;
import com.vaadin.client.widget.grid.EditorHandler;
+import com.vaadin.client.widget.grid.EventCellReference;
import com.vaadin.client.widget.grid.RendererCellReference;
import com.vaadin.client.widget.grid.RowReference;
import com.vaadin.client.widget.grid.RowStyleGenerator;
@@ -521,6 +525,46 @@ public class GridBasicClientFeaturesWidget extends
.addColumnVisibilityChangeHandler(handler);
}
}, listenersPath);
+ addMenuCommand("Add context menu listener", new ScheduledCommand() {
+
+ HandlerRegistration handler = null;
+ ContextMenuHandler contextMenuHandler = new ContextMenuHandler() {
+
+ @Override
+ public void onContextMenu(ContextMenuEvent event) {
+ event.preventDefault();
+ final String location;
+ EventCellReference<?> cellRef = grid
+ .getEventCell();
+ if (cellRef.isHeader()) {
+ location = "header";
+ } else if (cellRef.isBody()) {
+ location = "body";
+ } else if (cellRef.isFooter()) {
+ location = "footer";
+ } else {
+ location = "somewhere";
+ }
+
+ getLogger().info(
+ "Prevented opening a context menu in grid "
+ + location);
+ }
+ };
+
+ @Override
+ public void execute() {
+ if (handler != null) {
+ grid.unsinkEvents(Event.ONCONTEXTMENU);
+ handler.removeHandler();
+ } else {
+ grid.sinkEvents(Event.ONCONTEXTMENU);
+ handler = grid.addDomHandler(contextMenuHandler,
+ ContextMenuEvent.getType());
+ }
+ }
+
+ }, listenersPath);
}
private void createStateMenu() {