Should have a test to make sure links don't navigate after a cancelled force
authorbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Sep 2015 23:48:58 +0000 (23:48 +0000)
committerbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Sep 2015 23:48:58 +0000 (23:48 +0000)
click
https://bugs.webkit.org/show_bug.cgi?id=148846

Reviewed by Tim Horton.

Tools:

New EventSender function for a started then cancelled force click.
* WebKitTestRunner/EventSenderProxy.h:
* WebKitTestRunner/InjectedBundle/Bindings/EventSendingController.idl:
* WebKitTestRunner/InjectedBundle/EventSendingController.cpp:
(WTR::EventSendingController::mouseForceClick):
(WTR::EventSendingController::startAndCancelMouseForceClick):
(WTR::EventSendingController::mouseForceDown):
* WebKitTestRunner/InjectedBundle/EventSendingController.h:
* WebKitTestRunner/TestController.cpp:
(WTR::TestController::didReceiveSynchronousMessageFromInjectedBundle):
* WebKitTestRunner/mac/EventSenderProxy.mm:
(WTR::EventSenderProxy::mouseForceClick):
(WTR::EventSenderProxy::startAndCancelMouseForceClick):
(WTR::EventSenderProxy::mouseForceDown):
(WTR::EventSenderProxy::mouseMoveTo):

LayoutTests:

* fast/events/cancelled-force-click-link-navigation-expected.txt: Added.
* fast/events/cancelled-force-click-link-navigation.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@189400 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/events/cancelled-force-click-link-navigation-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/cancelled-force-click-link-navigation.html [new file with mode: 0644]
Tools/ChangeLog
Tools/WebKitTestRunner/EventSenderProxy.h
Tools/WebKitTestRunner/InjectedBundle/Bindings/EventSendingController.idl
Tools/WebKitTestRunner/InjectedBundle/EventSendingController.cpp
Tools/WebKitTestRunner/InjectedBundle/EventSendingController.h
Tools/WebKitTestRunner/TestController.cpp
Tools/WebKitTestRunner/mac/EventSenderProxy.mm

index 170406c..29d22bd 100644 (file)
@@ -1,3 +1,14 @@
+2015-09-04  Beth Dakin  <bdakin@apple.com>
+
+        Should have a test to make sure links don't navigate after a cancelled force 
+        click
+        https://bugs.webkit.org/show_bug.cgi?id=148846
+
+        Reviewed by Tim Horton.
+
+        * fast/events/cancelled-force-click-link-navigation-expected.txt: Added.
+        * fast/events/cancelled-force-click-link-navigation.html: Added.
+
 2015-09-04  Chris Dumez  <cdumez@apple.com>
 
         Unreviewed, add bug number for http/tests/w3c/html/semantics/text-level-semantics/the-wbr-element/wbr-element.html
diff --git a/LayoutTests/fast/events/cancelled-force-click-link-navigation-expected.txt b/LayoutTests/fast/events/cancelled-force-click-link-navigation-expected.txt
new file mode 100644 (file)
index 0000000..3a834bd
--- /dev/null
@@ -0,0 +1,2 @@
+Link
+SUCCESS! We did not navigate to the link after starting a force click.
diff --git a/LayoutTests/fast/events/cancelled-force-click-link-navigation.html b/LayoutTests/fast/events/cancelled-force-click-link-navigation.html
new file mode 100644 (file)
index 0000000..909a13e
--- /dev/null
@@ -0,0 +1,49 @@
+<html>
+<head>
+<script>
+
+var didNavigate = false;
+
+window.onbeforeunload = function () {
+    didNavigate = true;
+};
+
+function checkForDone()
+{
+    if (!didNavigate) {
+        var console = document.getElementById("console");
+        console.innerHTML = "SUCCESS! We did not navigate to the link after starting a force click.";
+    }
+
+    if (window.testRunner)
+        testRunner.notifyDone();
+}
+
+function spinRunLoop()
+{
+    window.setTimeout(checkForDone, 0);
+}
+
+function startTest()
+{
+    if (window.testRunner) {
+        testRunner.dumpAsText();
+        testRunner.waitUntilDone();
+    }
+
+    if (window.eventSender) {
+        eventSender.mouseMoveTo(16, 16);
+        eventSender.startAndCancelMouseForceClick();
+        window.setTimeout(spinRunLoop, 0);
+    }
+}
+</script>
+</head>
+
+<body onload="startTest()">
+
+<a href="resources/do-not-navigate-here.html">Link</a>
+<pre id="console">Failed. This test must be run in the test harness. To run the test manually, start force clicking on the link, but don't click hard enough to pop open the preview. Then make sure that the original document does not navigate anywhere.</pre>
+
+</body>
+</html>
index ff9982a..863f741 100644 (file)
@@ -1,3 +1,27 @@
+2015-09-04  Beth Dakin  <bdakin@apple.com>
+
+        Should have a test to make sure links don't navigate after a cancelled force 
+        click
+        https://bugs.webkit.org/show_bug.cgi?id=148846
+
+        Reviewed by Tim Horton.
+
+        New EventSender function for a started then cancelled force click.
+        * WebKitTestRunner/EventSenderProxy.h:
+        * WebKitTestRunner/InjectedBundle/Bindings/EventSendingController.idl:
+        * WebKitTestRunner/InjectedBundle/EventSendingController.cpp:
+        (WTR::EventSendingController::mouseForceClick):
+        (WTR::EventSendingController::startAndCancelMouseForceClick):
+        (WTR::EventSendingController::mouseForceDown):
+        * WebKitTestRunner/InjectedBundle/EventSendingController.h:
+        * WebKitTestRunner/TestController.cpp:
+        (WTR::TestController::didReceiveSynchronousMessageFromInjectedBundle):
+        * WebKitTestRunner/mac/EventSenderProxy.mm:
+        (WTR::EventSenderProxy::mouseForceClick):
+        (WTR::EventSenderProxy::startAndCancelMouseForceClick):
+        (WTR::EventSenderProxy::mouseForceDown):
+        (WTR::EventSenderProxy::mouseMoveTo):
+
 2015-09-04  Tim Horton  <timothy_horton@apple.com>
 
         Add a test for r179736 (programmatic navigation during swipe causing a crash)
index 7b2ecd9..70d9401 100644 (file)
@@ -67,6 +67,7 @@ public:
     void mouseForceUp();
     void mouseForceChanged(float);
     void mouseForceClick();
+    void startAndCancelMouseForceClick();
     void mouseMoveTo(double x, double y);
     void mouseScrollBy(int x, int y);
     void mouseScrollByWithWheelAndMomentumPhases(int x, int y, int phase, int momentum);
index c74366e..f3280bb 100644 (file)
@@ -28,6 +28,7 @@ interface EventSendingController {
     void mouseUp(long buttonNumber, object modifierArray);
     void mouseMoveTo(long x, long y);
     void mouseForceClick();
+    void startAndCancelMouseForceClick();
     void mouseForceDown();
     void mouseForceUp();
     void mouseForceChanged(double force);
index 2c45589..c9b1ad9 100644 (file)
@@ -267,6 +267,18 @@ void EventSendingController::mouseForceClick()
     WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
 }
 
+void EventSendingController::startAndCancelMouseForceClick()
+{
+    WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
+    WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
+
+    WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
+    WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("StartAndCancelMouseForceClick"));
+    WKDictionarySetItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
+
+    WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
+}
+
 void EventSendingController::mouseForceDown()
 {
     WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
index 7b9784a..c23c36d 100644 (file)
@@ -47,6 +47,7 @@ public:
     void mouseUp(int button, JSValueRef modifierArray);
     void mouseMoveTo(int x, int y);
     void mouseForceClick();
+    void startAndCancelMouseForceClick();
     void mouseForceDown();
     void mouseForceUp();
     void mouseForceChanged(double force);
index 795f1ee..aaefa1c 100644 (file)
@@ -1216,6 +1216,11 @@ WKRetainPtr<WKTypeRef> TestController::didReceiveSynchronousMessageFromInjectedB
             return 0;
         }
 
+        if (WKStringIsEqualToUTF8CString(subMessageName, "StartAndCancelMouseForceClick")) {
+            m_eventSenderProxy->startAndCancelMouseForceClick();
+            return 0;
+        }
+
         if (WKStringIsEqualToUTF8CString(subMessageName, "MouseForceDown")) {
             m_eventSenderProxy->mouseForceDown();
             return 0;
index 228c6f5..68c1107 100644 (file)
@@ -467,6 +467,42 @@ void EventSenderProxy::mouseForceClick()
 #pragma clang diagnostic pop
 }
 
+void EventSenderProxy::startAndCancelMouseForceClick()
+{
+    sendMouseDownToStartPressureEvents();
+
+    RetainPtr<NSEvent> beginPressure = beginPressureEvent(1);
+    RetainPtr<NSEvent> increasingPressure = pressureChangeEvent(1, PressureChangeDirection::Increasing);
+    RetainPtr<NSEvent> releasingPressure = pressureChangeEvent(1, PressureChangeDirection::Decreasing);
+    NSEvent *mouseUp = [NSEvent mouseEventWithType:NSLeftMouseUp
+        location:NSMakePoint(m_position.x, m_position.y)
+        modifierFlags:0
+        timestamp:absoluteTimeForEventTime(currentEventTime())
+        windowNumber:[m_testController->mainWebView()->platformWindow() windowNumber]
+        context:[NSGraphicsContext currentContext]
+        eventNumber:++eventNumber
+        clickCount:m_clickCount
+        pressure:0.0];
+
+    NSView *targetView = [m_testController->mainWebView()->platformView() hitTest:[beginPressure.get() locationInWindow]];
+    targetView = targetView ? targetView : m_testController->mainWebView()->platformView();
+    ASSERT(targetView);
+
+    // Since AppKit does not implement forceup/down as mouse events, we need to send two pressure events to detect
+    // the change in stage that marks those moments.
+    handleForceEventSynchronously(beginPressure.get());
+    handleForceEventSynchronously(increasingPressure.get());
+    handleForceEventSynchronously(releasingPressure.get());
+    [NSApp sendEvent:mouseUp];
+
+    [NSApp _setCurrentEvent:nil];
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wnonnull"
+    // WKView caches the most recent pressure event, so send it a nil event to clear the cache.
+    [targetView pressureChangeWithEvent:nil];
+#pragma clang diagnostic pop
+}
+
 void EventSenderProxy::mouseForceDown()
 {
     sendMouseDownToStartPressureEvents();
@@ -576,6 +612,10 @@ void EventSenderProxy::mouseForceChanged(float)
 void EventSenderProxy::mouseForceClick()
 {
 }
+
+void EventSenderProxy::startAndCancelMouseForceClick()
+{
+}
 #endif // defined(__LP64__) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101003
 
 void EventSenderProxy::mouseMoveTo(double x, double y)