NSEvent event trackers don't work from WebKitTestRunner
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 14 May 2018 17:26:25 +0000 (17:26 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 14 May 2018 17:26:25 +0000 (17:26 +0000)
https://bugs.webkit.org/show_bug.cgi?id=185383
rdar://problem/40025045

Patch by Jeremy Jones <jeremyj@apple.com> on 2018-05-14
Reviewed by Simon Fraser.

Tools:

Post simulated wheel events to _sendEventToObservers: so they can be handled by NSEvent observers.
NSEvent swipe tracking is used for webkit swipe navigation.

* WebKitTestRunner/mac/EventSenderProxy.mm:
(WTR::EventSenderProxy::mouseScrollByWithWheelAndMomentumPhases):

LayoutTests:

This test initiates back navigation with wheel events.

* swipe/wheel-event-initiated-back-navigation-expected.txt: Added.
* swipe/wheel-event-initiated-back-navigation.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/swipe/wheel-event-initiated-back-navigation-expected.txt [new file with mode: 0644]
LayoutTests/swipe/wheel-event-initiated-back-navigation.html [new file with mode: 0644]
Tools/ChangeLog
Tools/WebKitTestRunner/mac/EventSenderProxy.mm

index 2dd9e58..b6562a9 100644 (file)
@@ -1,3 +1,16 @@
+2018-05-14  Jeremy Jones  <jeremyj@apple.com>
+
+        NSEvent event trackers don't work from WebKitTestRunner
+        https://bugs.webkit.org/show_bug.cgi?id=185383
+        rdar://problem/40025045
+
+        Reviewed by Simon Fraser.
+
+        This test initiates back navigation with wheel events.
+
+        * swipe/wheel-event-initiated-back-navigation-expected.txt: Added.
+        * swipe/wheel-event-initiated-back-navigation.html: Added.
+
 2018-05-14  Yusuke Suzuki  <utatane.tea@gmail.com>
 
         [JSC] timeClip(-0) should produce +0
diff --git a/LayoutTests/swipe/wheel-event-initiated-back-navigation-expected.txt b/LayoutTests/swipe/wheel-event-initiated-back-navigation-expected.txt
new file mode 100644 (file)
index 0000000..4339457
--- /dev/null
@@ -0,0 +1,5 @@
+This is a swipe navigation test.
+
+PASS: mouseWheel caused navigation
+PASS: navigated back to page1
+
diff --git a/LayoutTests/swipe/wheel-event-initiated-back-navigation.html b/LayoutTests/swipe/wheel-event-initiated-back-navigation.html
new file mode 100644 (file)
index 0000000..c612486
--- /dev/null
@@ -0,0 +1,68 @@
+<html>
+<head>
+<script>
+
+function logResult(s) {
+    document.getElementById('result').textContent += s + "\n";
+}
+
+function backSwipe()
+{
+    var divTarget = document.getElementById('content');
+    var documentBounds = divTarget.getBoundingClientRect();
+    
+    eventSender.mouseMoveTo(documentBounds.left + 10, documentBounds.top + 10);
+    eventSender.mouseScrollByWithWheelAndMomentumPhases(100, 0, 'began', 'none');
+    eventSender.mouseScrollByWithWheelAndMomentumPhases(100, 0, 'changed', 'none');
+    eventSender.mouseScrollByWithWheelAndMomentumPhases(100, 0, 'changed', 'none');
+    eventSender.mouseScrollByWithWheelAndMomentumPhases(100, 0, 'ended', 'none');
+}
+
+function startTest()
+{
+    if (!window.eventSender) {
+        logResult('This test must be run in DumpRenderTree/WebKitTestRunner (no eventSender)');
+        return;
+    }
+
+    if (!window.testRunner) {
+        logResult('This test must be run in DumpRenderTree/WebKitTestRunner (no testRunner)');
+        return;
+    }
+
+    testRunner.dumpAsText();
+    testRunner.waitUntilDone();
+    testRunner.overridePreference("WebKitUsesPageCachePreferenceKey", 1);
+    testRunner.setNavigationGesturesEnabled(true);
+
+    window.onpopstate = function(event) {
+        logResult('PASS: mouseWheel caused navigation');
+        if (event.state.name == "page1") {
+            logResult('PASS: navigated back to ' + event.state.name);
+        } else {
+            logResult('FAILED: navigated back to ' + event.state.name);
+        }
+        testRunner.notifyDone();
+    };
+
+    var stateObj = { name: "page1" };
+    history.replaceState(stateObj, "page1", "");
+
+    var stateObj = { name: "page2" };
+    history.pushState(stateObj, "page2", "");
+
+    backSwipe();
+}
+
+window.addEventListener('load', startTest, false);
+
+</script>
+</head>
+<body id="content">
+
+<h1>This is a swipe navigation test.</h1>
+
+<pre id="result"></pre>
+
+</body>
+</html>
\ No newline at end of file
index 8cb18d9..2d5b861 100644 (file)
@@ -1,3 +1,17 @@
+2018-05-14  Jeremy Jones  <jeremyj@apple.com>
+
+        NSEvent event trackers don't work from WebKitTestRunner
+        https://bugs.webkit.org/show_bug.cgi?id=185383
+        rdar://problem/40025045
+
+        Reviewed by Simon Fraser.
+
+        Post simulated wheel events to _sendEventToObservers: so they can be handled by NSEvent observers.
+        NSEvent swipe tracking is used for webkit swipe navigation.
+
+        * WebKitTestRunner/mac/EventSenderProxy.mm:
+        (WTR::EventSenderProxy::mouseScrollByWithWheelAndMomentumPhases):
+
 2018-05-11  Leo Balter  <leonardo.balter@gmail.com>
 
         Test262 Runner should search for the Debug JSC by default
index 790f635..da25e4f 100644 (file)
@@ -43,6 +43,7 @@
 @end
 
 @interface NSEvent (ForTestRunner)
++ (NSEvent *)_sendEventToObservers:(NSEvent *)event;
 - (void)_postDelayed;
 @end
 
@@ -876,6 +877,7 @@ void EventSenderProxy::mouseScrollByWithWheelAndMomentumPhases(int x, int y, int
     // Our event should have the correct settings:
     if (NSView *targetView = [m_testController->mainWebView()->platformView() hitTest:[event locationInWindow]]) {
         [NSApp _setCurrentEvent:event];
+        event = [NSEvent _sendEventToObservers:event];
         [targetView scrollWheel:event];
         [NSApp _setCurrentEvent:nil];
     } else {