Add a test for iOS arrow-key repeat
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 22 Jan 2016 22:43:38 +0000 (22:43 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 22 Jan 2016 22:43:38 +0000 (22:43 +0000)
https://bugs.webkit.org/show_bug.cgi?id=152857
<rdar://problem/24017380>

Reviewed by Darin Adler.

* WebKitTestRunner/UIScriptContext/Bindings/UIScriptController.idl:
* WebKitTestRunner/UIScriptContext/UIScriptController.cpp:
(WTR::UIScriptController::keyUpUsingHardwareKeyboard):
(WTR::UIScriptController::keyDownUsingHardwareKeyboard):
* WebKitTestRunner/UIScriptContext/UIScriptController.h:
* WebKitTestRunner/ios/HIDEventGenerator.h:
* WebKitTestRunner/ios/HIDEventGenerator.mm:
(-[HIDEventGenerator keyPress:completionBlock:]):
(-[HIDEventGenerator keyDown:completionBlock:]):
(-[HIDEventGenerator keyUp:completionBlock:]):
* WebKitTestRunner/ios/UIScriptControllerIOS.mm:
(WTR::UIScriptController::typeCharacterUsingHardwareKeyboard):
(WTR::UIScriptController::keyDownUsingHardwareKeyboard):
(WTR::UIScriptController::keyUpUsingHardwareKeyboard):
Make it possible to independently send keyUp/keyDown, instead of just paired.

* fast/events/ios/keyboard-scrolling-repeat-expected.txt: Added.
* fast/events/ios/keyboard-scrolling-repeat.html: Added.
Add the aforementioned test. It waits for the held-down arrow key to scroll twice, then sends the up.

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

LayoutTests/ChangeLog
LayoutTests/fast/events/ios/keyboard-scrolling-repeat-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/ios/keyboard-scrolling-repeat.html [new file with mode: 0644]
Tools/ChangeLog
Tools/WebKitTestRunner/UIScriptContext/Bindings/UIScriptController.idl
Tools/WebKitTestRunner/UIScriptContext/UIScriptController.cpp
Tools/WebKitTestRunner/UIScriptContext/UIScriptController.h
Tools/WebKitTestRunner/ios/HIDEventGenerator.h
Tools/WebKitTestRunner/ios/HIDEventGenerator.mm
Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm

index f1779a4..b9847ee 100644 (file)
@@ -1,3 +1,15 @@
+2016-01-22  Tim Horton  <timothy_horton@apple.com>
+
+        Add a test for iOS arrow-key repeat
+        https://bugs.webkit.org/show_bug.cgi?id=152857
+        <rdar://problem/24017380>
+
+        Reviewed by Darin Adler.
+
+        * fast/events/ios/keyboard-scrolling-repeat-expected.txt: Added.
+        * fast/events/ios/keyboard-scrolling-repeat.html: Added.
+        Add the aforementioned test. It waits for the held-down arrow key to scroll twice, then sends the up.
+
 2016-01-21  Sam Weinig  <sam@webkit.org>
 
         Treat non-https actions on secure pages as mixed content
diff --git a/LayoutTests/fast/events/ios/keyboard-scrolling-repeat-expected.txt b/LayoutTests/fast/events/ios/keyboard-scrolling-repeat-expected.txt
new file mode 100644 (file)
index 0000000..79fed10
--- /dev/null
@@ -0,0 +1,7 @@
+PASS successfullyParsed is true
+
+TEST COMPLETE
+Before starting to hold the down arrow, window.scrollY = 0
+After starting to hold the down arrow, window.scrollY = 40
+After continuing to hold the down arrow, window.scrollY = 80
+
diff --git a/LayoutTests/fast/events/ios/keyboard-scrolling-repeat.html b/LayoutTests/fast/events/ios/keyboard-scrolling-repeat.html
new file mode 100644 (file)
index 0000000..6c04639
--- /dev/null
@@ -0,0 +1,89 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true ] -->
+
+<html>
+
+<head>
+    <script src="../../../resources/js-test-pre.js"></script>
+    <meta name="viewport" content="initial-scale=1.5, user-scalable=no">
+    <script id="ui-script" type="text/plain">
+        (function() {
+            // FIXME (151264): Need to tap to focus so that key events go through.
+            uiController.singleTapAtPoint(50, 25, function() {
+                uiController.keyDownUsingHardwareKeyboard("downArrow", function() {
+                    uiController.didEndScrollingCallback = function() {
+                        uiController.uiScriptComplete();
+                    };
+                });
+            });
+        })();
+    </script>
+
+    <script id="ui-script-waitforscroll" type="text/plain">
+        (function() {
+            uiController.didEndScrollingCallback = function() {
+                uiController.uiScriptComplete();
+            };
+        })();
+    </script>
+
+    <script id="ui-script-keyup" type="text/plain">
+        (function() {
+            uiController.keyUpUsingHardwareKeyboard("downArrow", function() {
+                uiController.uiScriptComplete();
+            });
+        })();
+    </script>
+
+    <script>
+        if (window.testRunner) {
+            testRunner.dumpAsText();
+            testRunner.waitUntilDone();
+        }
+
+        function getInitialUIScript()
+        {
+            return document.getElementById("ui-script").text;
+        }
+
+        function getWaitForScrollUIScript()
+        {
+            return document.getElementById("ui-script-waitforscroll").text;
+        }
+
+        function getKeyUpUIScript()
+        {
+            return document.getElementById("ui-script-keyup").text;
+        }
+
+        function runTest()
+        {
+            if (!window.testRunner || !testRunner.runUIScript)
+                return;
+
+            debug("Before starting to hold the down arrow, window.scrollY = " + window.scrollY);
+            testRunner.runUIScript(getInitialUIScript(), function(result) {
+                debug("After starting to hold the down arrow, window.scrollY = " + window.scrollY);
+                testRunner.runUIScript(getWaitForScrollUIScript(), function(result) {
+                    debug("After continuing to hold the down arrow, window.scrollY = " + window.scrollY);
+                    testRunner.runUIScript(getKeyUpUIScript(), function(result) {
+                        testRunner.notifyDone();
+                    });
+                });
+            });
+        }
+    </script>
+    <style>
+    #placeholder {
+        width: 100px;
+        height: 5000px;
+    }
+    </style>
+</head>
+
+<body style="margin: 0;" onload="runTest()">
+    <div id="placeholder">
+    <div id="console"></div>
+    <script src="../../../resources/js-test-post.js"></script>
+</body>
+
+</html>
index a0c8af7..0337fb5 100644 (file)
@@ -7,6 +7,30 @@
 
 2016-01-22  Tim Horton  <timothy_horton@apple.com>
 
+        Add a test for iOS arrow-key repeat
+        https://bugs.webkit.org/show_bug.cgi?id=152857
+        <rdar://problem/24017380>
+
+        Reviewed by Darin Adler.
+
+        * WebKitTestRunner/UIScriptContext/Bindings/UIScriptController.idl:
+        * WebKitTestRunner/UIScriptContext/UIScriptController.cpp:
+        (WTR::UIScriptController::keyUpUsingHardwareKeyboard):
+        (WTR::UIScriptController::keyDownUsingHardwareKeyboard):
+        * WebKitTestRunner/UIScriptContext/UIScriptController.h:
+        * WebKitTestRunner/ios/HIDEventGenerator.h:
+        * WebKitTestRunner/ios/HIDEventGenerator.mm:
+        (-[HIDEventGenerator keyPress:completionBlock:]):
+        (-[HIDEventGenerator keyDown:completionBlock:]):
+        (-[HIDEventGenerator keyUp:completionBlock:]):
+        * WebKitTestRunner/ios/UIScriptControllerIOS.mm:
+        (WTR::UIScriptController::typeCharacterUsingHardwareKeyboard):
+        (WTR::UIScriptController::keyDownUsingHardwareKeyboard):
+        (WTR::UIScriptController::keyUpUsingHardwareKeyboard):
+        Make it possible to independently send keyUp/keyDown, instead of just paired.
+
+2016-01-22  Tim Horton  <timothy_horton@apple.com>
+
         Reproducible "Unhanded web process message 'WebUserContentController:AddUserScripts'" and friends
         https://bugs.webkit.org/show_bug.cgi?id=153193
         <rdar://problem/24222034>
index 073d7fd..763fb4b 100644 (file)
@@ -36,6 +36,8 @@ interface UIScriptController {
     void doubleTapAtPoint(long x, long y, object callback);
 
     void typeCharacterUsingHardwareKeyboard(DOMString character, object callback);
+    void keyDownUsingHardwareKeyboard(DOMString character, object callback);
+    void keyUpUsingHardwareKeyboard(DOMString character, object callback);
 
     attribute object didShowKeyboardCallback;
     attribute object didHideKeyboardCallback;
index a13408c..a564382 100644 (file)
@@ -130,6 +130,14 @@ void UIScriptController::typeCharacterUsingHardwareKeyboard(JSStringRef, JSValue
 {
 }
 
+void UIScriptController::keyUpUsingHardwareKeyboard(JSStringRef, JSValueRef)
+{
+}
+
+void UIScriptController::keyDownUsingHardwareKeyboard(JSStringRef, JSValueRef)
+{
+}
+
 double UIScriptController::zoomScale() const
 {
     return 1;
index 4017284..858439c 100644 (file)
@@ -51,6 +51,8 @@ public:
     void doubleTapAtPoint(long x, long y, JSValueRef callback);
     
     void typeCharacterUsingHardwareKeyboard(JSStringRef character, JSValueRef callback);
+    void keyDownUsingHardwareKeyboard(JSStringRef character, JSValueRef callback);
+    void keyUpUsingHardwareKeyboard(JSStringRef character, JSValueRef callback);
 
     void setWillBeginZoomingCallback(JSValueRef);
     JSValueRef willBeginZoomingCallback() const;
index af9be6a..38ba029 100644 (file)
@@ -51,6 +51,8 @@
 - (void)markerEventReceived:(IOHIDEventRef)event;
 
 // Keyboard
+- (void)keyPress:(NSString *)character completionBlock:(void (^)(void))completionBlock;
 - (void)keyDown:(NSString *)character completionBlock:(void (^)(void))completionBlock;
+- (void)keyUp:(NSString *)character completionBlock:(void (^)(void))completionBlock;
 
 @end
index dbb828d..71cdbd2 100644 (file)
@@ -574,6 +574,24 @@ static inline uint32_t hidUsageCodeForCharacter(NSString *key)
     return 0;
 }
 
+- (void)keyPress:(NSString *)character completionBlock:(void (^)(void))completionBlock
+{
+    bool shouldWrapWithShift = shouldWrapWithShiftKeyEventForCharacter(character);
+    uint32_t usage = hidUsageCodeForCharacter(character);
+    uint64_t absoluteMachTime = mach_absolute_time();
+
+    if (shouldWrapWithShift)
+        [self _sendIOHIDKeyboardEvent:absoluteMachTime usage:kHIDUsage_KeyboardLeftShift isKeyDown:true];
+
+    [self _sendIOHIDKeyboardEvent:absoluteMachTime usage:usage isKeyDown:true];
+    [self _sendIOHIDKeyboardEvent:absoluteMachTime usage:usage isKeyDown:false];
+
+    if (shouldWrapWithShift)
+        [self _sendIOHIDKeyboardEvent:absoluteMachTime usage:kHIDUsage_KeyboardLeftShift isKeyDown:false];
+
+    [self _sendMarkerHIDEventWithCompletionBlock:completionBlock];
+}
+
 - (void)keyDown:(NSString *)character completionBlock:(void (^)(void))completionBlock
 {
     bool shouldWrapWithShift = shouldWrapWithShiftKeyEventForCharacter(character);
@@ -584,6 +602,16 @@ static inline uint32_t hidUsageCodeForCharacter(NSString *key)
         [self _sendIOHIDKeyboardEvent:absoluteMachTime usage:kHIDUsage_KeyboardLeftShift isKeyDown:true];
 
     [self _sendIOHIDKeyboardEvent:absoluteMachTime usage:usage isKeyDown:true];
+
+    [self _sendMarkerHIDEventWithCompletionBlock:completionBlock];
+}
+
+- (void)keyUp:(NSString *)character completionBlock:(void (^)(void))completionBlock
+{
+    bool shouldWrapWithShift = shouldWrapWithShiftKeyEventForCharacter(character);
+    uint32_t usage = hidUsageCodeForCharacter(character);
+    uint64_t absoluteMachTime = mach_absolute_time();
+
     [self _sendIOHIDKeyboardEvent:absoluteMachTime usage:usage isKeyDown:false];
 
     if (shouldWrapWithShift)
index 005d024..131ec35 100644 (file)
@@ -106,6 +106,18 @@ void UIScriptController::typeCharacterUsingHardwareKeyboard(JSStringRef characte
     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
 
     // Assumes that the keyboard is already shown.
+    [[HIDEventGenerator sharedHIDEventGenerator] keyPress:toWTFString(toWK(character)) completionBlock:^{
+        if (!m_context)
+            return;
+        m_context->asyncTaskComplete(callbackID);
+    }];
+}
+
+void UIScriptController::keyDownUsingHardwareKeyboard(JSStringRef character, JSValueRef callback)
+{
+    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
+
+    // Assumes that the keyboard is already shown.
     [[HIDEventGenerator sharedHIDEventGenerator] keyDown:toWTFString(toWK(character)) completionBlock:^{
         if (!m_context)
             return;
@@ -113,6 +125,18 @@ void UIScriptController::typeCharacterUsingHardwareKeyboard(JSStringRef characte
     }];
 }
 
+void UIScriptController::keyUpUsingHardwareKeyboard(JSStringRef character, JSValueRef callback)
+{
+    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
+
+    // Assumes that the keyboard is already shown.
+    [[HIDEventGenerator sharedHIDEventGenerator] keyUp:toWTFString(toWK(character)) completionBlock:^{
+        if (!m_context)
+            return;
+        m_context->asyncTaskComplete(callbackID);
+    }];
+}
+
 double UIScriptController::minimumZoomScale() const
 {
     TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();