]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fast-forward DateField only with left mouse button (#8012)
authorTeemu Pöntelin <teemu@vaadin.com>
Sun, 4 May 2014 14:12:54 +0000 (17:12 +0300)
committerTeemu Pöntelin <teemu@vaadin.com>
Sun, 4 May 2014 14:12:54 +0000 (17:12 +0300)
Change-Id: Ib21c650feeed1ca584b2aeefb6c694e73e12b90d

client/src/com/vaadin/client/ui/VCalendarPanel.java
uitest/src/com/vaadin/tests/components/datefield/DateFieldFastForward.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/datefield/DateFieldFastForwardTest.java [new file with mode: 0644]

index 74462e501d9bbd47eb786164b2a5bcff343d53c5..0725e15f667d7713d537f7958b0798ab3ecebb53 100644 (file)
@@ -22,6 +22,7 @@ import java.util.Iterator;
 import com.google.gwt.aria.client.Roles;
 import com.google.gwt.aria.client.SelectedValue;
 import com.google.gwt.dom.client.Element;
+import com.google.gwt.dom.client.NativeEvent;
 import com.google.gwt.dom.client.Node;
 import com.google.gwt.event.dom.client.BlurEvent;
 import com.google.gwt.event.dom.client.BlurHandler;
@@ -1498,11 +1499,12 @@ public class VCalendarPanel extends FocusableFlexTable implements
      */
     @Override
     public void onMouseDown(MouseDownEvent event) {
-        // Allow user to click-n-hold for fast-forward or fast-rewind.
+        // Click-n-hold the left mouse button for fast-forward or fast-rewind.
         // Timer is first used for a 500ms delay after mousedown. After that has
         // elapsed, another timer is triggered to go off every 150ms. Both
         // timers are cancelled on mouseup or mouseout.
-        if (event.getSource() instanceof VEventButton) {
+        if (event.getNativeButton() == NativeEvent.BUTTON_LEFT
+                && event.getSource() instanceof VEventButton) {
             final VEventButton sender = (VEventButton) event.getSource();
             processClickEvent(sender);
             mouseTimer = new Timer() {
diff --git a/uitest/src/com/vaadin/tests/components/datefield/DateFieldFastForward.java b/uitest/src/com/vaadin/tests/components/datefield/DateFieldFastForward.java
new file mode 100644 (file)
index 0000000..b38f58e
--- /dev/null
@@ -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.components.datefield;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.InlineDateField;
+
+public class DateFieldFastForward extends AbstractTestUI {
+
+    @Override
+    protected void setup(VaadinRequest request) {
+        addComponent(new InlineDateField());
+    }
+
+    @Override
+    protected String getTestDescription() {
+        return "Tests that right-click doesn't interfere with fast-forwarding (holding down left mouse button).";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 8012;
+    }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/datefield/DateFieldFastForwardTest.java b/uitest/src/com/vaadin/tests/components/datefield/DateFieldFastForwardTest.java
new file mode 100644 (file)
index 0000000..028160c
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * 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.datefield;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.interactions.Actions;
+
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class DateFieldFastForwardTest extends MultiBrowserTest {
+
+    @Test
+    public void testFastForwardOnRightMouseClick() throws Exception {
+        openTestURL();
+
+        WebElement nextMonthButton = driver.findElement(By
+                .className("v-button-nextmonth"));
+
+        // Click and hold left mouse button to start fast forwarding.
+        new Actions(driver).clickAndHold(nextMonthButton).perform();
+        Thread.sleep(1000);
+
+        // Right click and release the left button.
+        new Actions(driver).contextClick(nextMonthButton)
+                .release(nextMonthButton).perform();
+
+        // Now the fast forwarding should be ended, get the expected month.
+        String expectedMonth = getSelectedMonth();
+
+        // Wait for a while.
+        Thread.sleep(1000);
+
+        // Verify that we didn't fast forward any further after the left button
+        // was released.
+        String actualMonth = getSelectedMonth();
+        assertEquals(expectedMonth, actualMonth);
+    }
+
+    private String getSelectedMonth() {
+        return driver.findElement(
+                By.className("v-inline-datefield-calendarpanel-month"))
+                .getText();
+    }
+
+}