https://bugs.webkit.org/show_bug.cgi?id=149653
Reviewed by Tim Horton.
Tools:
Expose functionality in UIScriptController to allow for testing single- and double-tap,
and to listen for completion of scrolling and zooming in the WKWebView.
Tap generation is done using synthetic IOHIDEvents, via a new HIDEventGenerator class
which hides the complexity of creating these events. Event dispatch is asynchronous.
We detect when the last event has been handled by dispatching a vendor-specific event,
which is detected via -_handleHIDEvent: in our UIApplication subclass.
* WebKitTestRunner/Configurations/WebKitTestRunnerApp.xcconfig: Link with IOKit.
* WebKitTestRunner/UIScriptContext/Bindings/UIScriptController.idl: Two new properties
for 'will begin zooming' and 'did end zooming' callbacks, and functions to dispatch
single and double taps.
* WebKitTestRunner/UIScriptContext/UIScriptContext.cpp:
(UIScriptContext::registerCallback): Used to store the callbacks for zooming.
Unlike the "task" callbacks, these are persistent, but we store them in the same hash map.
(UIScriptContext::unregisterCallback):
(UIScriptContext::callbackWithID):
(UIScriptContext::fireCallback):
* WebKitTestRunner/UIScriptContext/UIScriptContext.h:
* WebKitTestRunner/UIScriptContext/UIScriptController.cpp:
(WTR::UIScriptController::setWillBeginZoomingCallback): Cross-platform code.
(WTR::UIScriptController::willBeginZoomingCallback): Ditto.
(WTR::UIScriptController::setDidEndZoomingCallback):
(WTR::UIScriptController::didEndZoomingCallback):
(WTR::UIScriptController::singleTapAtPoint): Non-iOS stub.
(WTR::UIScriptController::doubleTapAtPoint): Ditto.
(WTR::UIScriptController::platformSetWillBeginZoomingCallback):
(WTR::UIScriptController::platformSetDidEndZoomingCallback):
* WebKitTestRunner/UIScriptContext/UIScriptController.h:
* WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj:
* WebKitTestRunner/cocoa/TestRunnerWKWebView.h: Properties for the zooming callbacks.
* WebKitTestRunner/cocoa/TestRunnerWKWebView.mm:
(-[TestRunnerWKWebView zoomToScale:animated:completionHandler:]): Dispatch the zooming callback.
(-[TestRunnerWKWebView scrollViewWillBeginZooming:withView:]): Ditto.
(-[TestRunnerWKWebView scrollViewDidEndZooming:withView:atScale:]): Ditto.
(-[TestRunnerWKWebView onDidEndZooming:]): Deleted.
* WebKitTestRunner/ios/HIDEventGenerator.h: Copied from Tools/WebKitTestRunner/cocoa/TestRunnerWKWebView.h.
* WebKitTestRunner/ios/HIDEventGenerator.m: Added.
(simpleDragCurve):
(calculateNextLocation):
(delayBetweenMove):
(+[HIDEventGenerator sharedHIDEventGenerator]):
(+[HIDEventGenerator nextEventCallbackID]):
(-[HIDEventGenerator init]):
(-[HIDEventGenerator _createIOHIDEventType:]):
(-[HIDEventGenerator _sendHIDEvent:]):
(-[HIDEventGenerator _sendMarkerHIDEventWithCompletionBlock:]):
(-[HIDEventGenerator _updateTouchPoints:count:]):
(-[HIDEventGenerator touchDownAtPoints:touchCount:]):
(-[HIDEventGenerator touchDown:touchCount:]):
(-[HIDEventGenerator touchDown:]):
(-[HIDEventGenerator liftUpAtPoints:touchCount:]):
(-[HIDEventGenerator liftUp:touchCount:]):
(-[HIDEventGenerator liftUp:]):
(-[HIDEventGenerator moveToPoints:touchCount:duration:]):
(-[HIDEventGenerator sendTaps:location:withNumberOfTouches:completionBlock:]):
(-[HIDEventGenerator tap:completionBlock:]):
(-[HIDEventGenerator doubleTap:completionBlock:]):
(-[HIDEventGenerator twoFingerTap:completionBlock:]):
(-[HIDEventGenerator dragWithStartPoint:endPoint:duration:completionBlock:]):
(-[HIDEventGenerator pinchCloseWithStartPoint:endPoint:duration:completionBlock:]):
(-[HIDEventGenerator pinchOpenWithStartPoint:endPoint:duration:completionBlock:]):
(-[HIDEventGenerator markerEventReceived:]):
* WebKitTestRunner/ios/IOKitSPI.h: Added.
* WebKitTestRunner/ios/UIKitSPI.h: Copied from Tools/WebKitTestRunner/cocoa/TestRunnerWKWebView.h.
* WebKitTestRunner/ios/UIScriptControllerIOS.mm:
(WTR::globalToContentCoordinates):
(WTR::UIScriptController::singleTapAtPoint):
(WTR::UIScriptController::doubleTapAtPoint):
(WTR::UIScriptController::platformSetWillBeginZoomingCallback):
(WTR::UIScriptController::platformSetDidEndZoomingCallback):
* WebKitTestRunner/ios/mainIOS.mm:
(-[WebKitTestRunnerApp _handleHIDEvent:]):
LayoutTests:
Simple tests for single tap triggering a click, and double-tap zoom.
* TestExpectations:
* fast/events/ios/double-tap-zoom-expected.txt: Added.
* fast/events/ios/double-tap-zoom.html: Added.
* fast/events/ios/single-tap-generates-click-expected.txt: Added.
* fast/events/ios/single-tap-generates-click.html: Added.
* platform/ios-simulator-wk2/TestExpectations:
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@190368
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2015-09-29 Simon Fraser <simon.fraser@apple.com>
+
+ [iOS] Allow tests to generate user gestures for UI testing
+ https://bugs.webkit.org/show_bug.cgi?id=149653
+
+ Reviewed by Tim Horton.
+
+ Simple tests for single tap triggering a click, and double-tap zoom.
+
+ * TestExpectations:
+ * fast/events/ios/double-tap-zoom-expected.txt: Added.
+ * fast/events/ios/double-tap-zoom.html: Added.
+ * fast/events/ios/single-tap-generates-click-expected.txt: Added.
+ * fast/events/ios/single-tap-generates-click.html: Added.
+ * platform/ios-simulator-wk2/TestExpectations:
+
2015-09-30 Keith Miller <keith_miller@apple.com>
[ES6] Add TypedArray.prototype functionality.
swipe [ Skip ]
fast/zooming/ios [ Skip ]
fast/viewport/ios [ Skip ]
+fast/events/ios [ Skip ]
fast/forms/attributed-strings.html [ Skip ]
fast/scrolling/latching [ Skip ]
--- /dev/null
+Zoomed to scale 1.6
--- /dev/null
+<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true ] -->
+
+<html>
+<head>
+ <meta name="viewport" content="initial-scale=1.0">
+ <script id="ui-script" type="text/plain">
+ (function() {
+ uiController.didEndZoomingCallback = function() {
+ uiController.uiScriptComplete('Zoomed to scale ' + uiController.zoomScale);
+ };
+
+ uiController.doubleTapAtPoint(50, 50, function() {});
+ })();
+ </script>
+ <script>
+ if (window.testRunner) {
+ testRunner.dumpAsText();
+ testRunner.waitUntilDone();
+ }
+
+ function getUIScript()
+ {
+ return document.getElementById('ui-script').text;
+ }
+
+ function runTest()
+ {
+ if (testRunner.runUIScript) {
+ testRunner.runUIScript(getUIScript(), function(result) {
+ document.getElementById('target').innerText = result;
+ testRunner.notifyDone();
+ });
+ }
+ }
+ </script>
+ <style>
+ #target {
+ height: 100px;
+ width: 100px;
+ background-color: silver;
+ }
+ </style>
+</head>
+<body onload="runTest()">
+
+<div id="target">
+</div>
+
+</body>
+</html>
--- /dev/null
+PASS: received click event at 50 50
--- /dev/null
+<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true ] -->
+
+<html>
+<head>
+ <meta name="viewport" content="width=device-width">
+ <script id="ui-script" type="text/plain">
+ (function() {
+ uiController.singleTapAtPoint(50, 50);
+ })();
+ </script>
+ <script>
+ if (window.testRunner) {
+ testRunner.dumpAsText();
+ testRunner.waitUntilDone();
+ }
+
+ function getUIScript()
+ {
+ return document.getElementById('ui-script').text;
+ }
+
+ function runTest()
+ {
+ if (testRunner.runUIScript) {
+ testRunner.runUIScript(getUIScript(), function() {
+ // Just wait for the tap.
+ });
+ }
+ }
+
+ function boxClicked(event)
+ {
+ document.getElementById('target').textContent = 'PASS: received click event at ' + event.clientX + ' ' + event.clientY;
+ if (window.testRunner)
+ testRunner.notifyDone();
+ }
+ </script>
+ <style>
+ #target {
+ height: 100px;
+ width: 100px;
+ background-color: silver;
+ }
+ </style>
+</head>
+<body onload="runTest()">
+
+<div id="target" onclick="boxClicked(event)">
+ FAIL: did not receive click event.
+</div>
+
+</body>
+</html>
fast/harness/concurrent-ui-side-scripts.html [ Pass ]
fast/zooming/ios [ Pass ]
fast/viewport/ios [ Pass ]
+fast/events/ios [ Pass ]
#//////////////////////////////////////////////////////////////////////////////////////////
# End platform-specific directories.
+2015-09-29 Simon Fraser <simon.fraser@apple.com>
+
+ [iOS] Allow tests to generate user gestures for UI testing
+ https://bugs.webkit.org/show_bug.cgi?id=149653
+
+ Reviewed by Tim Horton.
+
+ Expose functionality in UIScriptController to allow for testing single- and double-tap,
+ and to listen for completion of scrolling and zooming in the WKWebView.
+
+ Tap generation is done using synthetic IOHIDEvents, via a new HIDEventGenerator class
+ which hides the complexity of creating these events. Event dispatch is asynchronous.
+ We detect when the last event has been handled by dispatching a vendor-specific event,
+ which is detected via -_handleHIDEvent: in our UIApplication subclass.
+
+ * WebKitTestRunner/Configurations/WebKitTestRunnerApp.xcconfig: Link with IOKit.
+ * WebKitTestRunner/UIScriptContext/Bindings/UIScriptController.idl: Two new properties
+ for 'will begin zooming' and 'did end zooming' callbacks, and functions to dispatch
+ single and double taps.
+ * WebKitTestRunner/UIScriptContext/UIScriptContext.cpp:
+ (UIScriptContext::registerCallback): Used to store the callbacks for zooming.
+ Unlike the "task" callbacks, these are persistent, but we store them in the same hash map.
+ (UIScriptContext::unregisterCallback):
+ (UIScriptContext::callbackWithID):
+ (UIScriptContext::fireCallback):
+ * WebKitTestRunner/UIScriptContext/UIScriptContext.h:
+ * WebKitTestRunner/UIScriptContext/UIScriptController.cpp:
+ (WTR::UIScriptController::setWillBeginZoomingCallback): Cross-platform code.
+ (WTR::UIScriptController::willBeginZoomingCallback): Ditto.
+ (WTR::UIScriptController::setDidEndZoomingCallback):
+ (WTR::UIScriptController::didEndZoomingCallback):
+ (WTR::UIScriptController::singleTapAtPoint): Non-iOS stub.
+ (WTR::UIScriptController::doubleTapAtPoint): Ditto.
+ (WTR::UIScriptController::platformSetWillBeginZoomingCallback):
+ (WTR::UIScriptController::platformSetDidEndZoomingCallback):
+ * WebKitTestRunner/UIScriptContext/UIScriptController.h:
+ * WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj:
+ * WebKitTestRunner/cocoa/TestRunnerWKWebView.h: Properties for the zooming callbacks.
+ * WebKitTestRunner/cocoa/TestRunnerWKWebView.mm:
+ (-[TestRunnerWKWebView zoomToScale:animated:completionHandler:]): Dispatch the zooming callback.
+ (-[TestRunnerWKWebView scrollViewWillBeginZooming:withView:]): Ditto.
+ (-[TestRunnerWKWebView scrollViewDidEndZooming:withView:atScale:]): Ditto.
+ (-[TestRunnerWKWebView onDidEndZooming:]): Deleted.
+ * WebKitTestRunner/ios/HIDEventGenerator.h: Copied from Tools/WebKitTestRunner/cocoa/TestRunnerWKWebView.h.
+ * WebKitTestRunner/ios/HIDEventGenerator.m: Added.
+ (simpleDragCurve):
+ (calculateNextLocation):
+ (delayBetweenMove):
+ (+[HIDEventGenerator sharedHIDEventGenerator]):
+ (+[HIDEventGenerator nextEventCallbackID]):
+ (-[HIDEventGenerator init]):
+ (-[HIDEventGenerator _createIOHIDEventType:]):
+ (-[HIDEventGenerator _sendHIDEvent:]):
+ (-[HIDEventGenerator _sendMarkerHIDEventWithCompletionBlock:]):
+ (-[HIDEventGenerator _updateTouchPoints:count:]):
+ (-[HIDEventGenerator touchDownAtPoints:touchCount:]):
+ (-[HIDEventGenerator touchDown:touchCount:]):
+ (-[HIDEventGenerator touchDown:]):
+ (-[HIDEventGenerator liftUpAtPoints:touchCount:]):
+ (-[HIDEventGenerator liftUp:touchCount:]):
+ (-[HIDEventGenerator liftUp:]):
+ (-[HIDEventGenerator moveToPoints:touchCount:duration:]):
+ (-[HIDEventGenerator sendTaps:location:withNumberOfTouches:completionBlock:]):
+ (-[HIDEventGenerator tap:completionBlock:]):
+ (-[HIDEventGenerator doubleTap:completionBlock:]):
+ (-[HIDEventGenerator twoFingerTap:completionBlock:]):
+ (-[HIDEventGenerator dragWithStartPoint:endPoint:duration:completionBlock:]):
+ (-[HIDEventGenerator pinchCloseWithStartPoint:endPoint:duration:completionBlock:]):
+ (-[HIDEventGenerator pinchOpenWithStartPoint:endPoint:duration:completionBlock:]):
+ (-[HIDEventGenerator markerEventReceived:]):
+ * WebKitTestRunner/ios/IOKitSPI.h: Added.
+ * WebKitTestRunner/ios/UIKitSPI.h: Copied from Tools/WebKitTestRunner/cocoa/TestRunnerWKWebView.h.
+ * WebKitTestRunner/ios/UIScriptControllerIOS.mm:
+ (WTR::globalToContentCoordinates):
+ (WTR::UIScriptController::singleTapAtPoint):
+ (WTR::UIScriptController::doubleTapAtPoint):
+ (WTR::UIScriptController::platformSetWillBeginZoomingCallback):
+ (WTR::UIScriptController::platformSetDidEndZoomingCallback):
+ * WebKitTestRunner/ios/mainIOS.mm:
+ (-[WebKitTestRunnerApp _handleHIDEvent:]):
+
2015-09-30 Dana Burkart <dburkart@apple.com>
git-add-reviewer should trim trailing spaces/newlines
PRODUCT_NAME = WebKitTestRunner;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
-OTHER_LDFLAGS = $(inherited) -l$(WEBKIT_SYSTEM_INTERFACE_LIBRARY) -lWebKitTestRunner -framework JavaScriptCore -framework CoreGraphics -framework ImageIO -framework UIKit -framework WebKit -framework Foundation;
+OTHER_LDFLAGS = $(inherited) -l$(WEBKIT_SYSTEM_INTERFACE_LIBRARY) -lWebKitTestRunner -framework JavaScriptCore -framework CoreGraphics -framework ImageIO -framework IOKit -framework UIKit -framework WebKit -framework Foundation;
SKIP_INSTALL[sdk=macosx*] = YES;
EXCLUDED_SOURCE_FILE_NAMES[sdk=macosx*] = ios/* AppDelegate.m;
EXCLUDED_SOURCE_FILE_NAMES[sdk=appletv*] = ios/Launch.storyboard;
void zoomToScale(double scale, object callback);
+ // Interaction.
+ // These functions post events asynchronously. The callback is fired when the events have been disptached, but any
+ // resulting behavior may also be asynchronous.
+ void singleTapAtPoint(long x, long y, object callback);
+ void doubleTapAtPoint(long x, long y, object callback);
+
+ attribute object willBeginZoomingCallback;
+ attribute object didEndZoomingCallback;
+
+ // View state
readonly attribute double zoomScale;
readonly attribute double minimumZoomScale;
readonly attribute double maximumZoomScale;
m_currentScriptCallbackID = 0;
}
+unsigned UIScriptContext::registerCallback(JSValueRef taskCallback)
+{
+ return prepareForAsyncTask(taskCallback);
+}
+
+void UIScriptContext::unregisterCallback(unsigned callbackID)
+{
+ Task task = m_callbacks.take(callbackID);
+ ASSERT(task.callback);
+ JSValueUnprotect(m_context.get(), task.callback);
+}
+
+JSValueRef UIScriptContext::callbackWithID(unsigned callbackID)
+{
+ Task task = m_callbacks.get(callbackID);
+ return task.callback;
+}
+
+void UIScriptContext::fireCallback(unsigned callbackID)
+{
+ Task task = m_callbacks.get(callbackID);
+ ASSERT(task.callback);
+
+ JSValueRef exception = nullptr;
+ JSObjectRef callbackObject = JSValueToObject(m_context.get(), task.callback, &exception);
+
+ m_currentScriptCallbackID = task.parentScriptCallbackID;
+
+ exception = nullptr;
+ JSObjectCallAsFunction(m_context.get(), callbackObject, JSContextGetGlobalObject(m_context.get()), 0, nullptr, &exception);
+
+ m_currentScriptCallbackID = 0;
+}
+
void UIScriptContext::uiScriptComplete(JSStringRef result)
{
WKRetainPtr<WKStringRef> uiScriptResult = WKStringCreateWithJSString(result);
void runUIScript(WKStringRef script, unsigned scriptCallbackID);
void uiScriptComplete(JSStringRef);
+ // For one-shot tasks callbacks.
unsigned prepareForAsyncTask(JSValueRef taskCallback);
void asyncTaskComplete(unsigned taskCallbackID);
+ // For persistent callbacks.
+ unsigned registerCallback(JSValueRef taskCallback);
+ JSValueRef callbackWithID(unsigned callbackID);
+ void unregisterCallback(unsigned callbackID);
+ void fireCallback(unsigned callbackID);
+
unsigned nextTaskCallbackID();
JSObjectRef objectFromRect(const WKRect&) const;
#include "JSUIScriptController.h"
#include "UIScriptContext.h"
-// #include <JavaScriptCore/JavaScriptCore.h>
+#include <JavaScriptCore/JSValueRef.h>
namespace WTR {
}
#endif
+void UIScriptController::setWillBeginZoomingCallback(JSValueRef callback)
+{
+ m_willBeginZoomingCallback = m_context.registerCallback(callback);
+ platformSetWillBeginZoomingCallback();
+}
+
+JSValueRef UIScriptController::willBeginZoomingCallback() const
+{
+ return m_context.callbackWithID(m_willBeginZoomingCallback);
+}
+
+void UIScriptController::setDidEndZoomingCallback(JSValueRef callback)
+{
+ m_didEndZoomingCallback = m_context.registerCallback(callback);
+ platformSetDidEndZoomingCallback();
+}
+
+JSValueRef UIScriptController::didEndZoomingCallback() const
+{
+ return m_context.callbackWithID(m_didEndZoomingCallback);
+}
+
#if !PLATFORM(IOS)
void UIScriptController::zoomToScale(double, JSValueRef)
{
}
+void UIScriptController::singleTapAtPoint(long x, long y, JSValueRef)
+{
+}
+
+void UIScriptController::doubleTapAtPoint(long x, long y, JSValueRef)
+{
+}
+
double UIScriptController::zoomScale() const
{
return 1;
{
return nullptr;
}
+
+void UIScriptController::platformSetWillBeginZoomingCallback()
+{
+}
+
+void UIScriptController::platformSetDidEndZoomingCallback()
+{
+}
#endif
void UIScriptController::uiScriptComplete(JSStringRef result)
void doAsyncTask(JSValueRef callback);
void zoomToScale(double scale, JSValueRef callback);
+ void singleTapAtPoint(long x, long y, JSValueRef callback);
+ void doubleTapAtPoint(long x, long y, JSValueRef callback);
+
+ void setWillBeginZoomingCallback(JSValueRef);
+ JSValueRef willBeginZoomingCallback() const;
+
+ void setDidEndZoomingCallback(JSValueRef);
+ JSValueRef didEndZoomingCallback() const;
+
double zoomScale() const;
double minimumZoomScale() const;
double maximumZoomScale() const;
private:
UIScriptController(UIScriptContext&);
+
+ void platformSetWillBeginZoomingCallback();
+ void platformSetDidEndZoomingCallback();
virtual JSClassRef wrapperClass() override;
JSObjectRef objectFromRect(const WKRect&) const;
UIScriptContext& m_context;
+
+ unsigned m_willBeginZoomingCallback { 0 };
+ unsigned m_didEndZoomingCallback { 0 };
};
}
0F87B6201BACDA93004EC572 /* UIScriptController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F87B61C1BACDA93004EC572 /* UIScriptController.cpp */; settings = {ASSET_TAGS = (); }; };
0FEB90A01905A834000FDBF3 /* InjectedBundlePageCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0FEB909E1905A776000FDBF3 /* InjectedBundlePageCocoa.mm */; };
0FEB90A51905C016000FDBF3 /* CrashReporterInfo.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0FEB90A31905BC6A000FDBF3 /* CrashReporterInfo.mm */; };
+ 0FEBF85A1BB61DF20028722D /* HIDEventGenerator.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0FEBF8591BB61DF20028722D /* HIDEventGenerator.mm */; settings = {ASSET_TAGS = (); }; };
29210EAE144CACB700835BB5 /* AccessibilityUIElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29210EA9144CACB200835BB5 /* AccessibilityUIElement.cpp */; };
29210EB0144CACBD00835BB5 /* AccessibilityController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29210EA2144CAAA500835BB5 /* AccessibilityController.cpp */; };
29210EB4144CACD500835BB5 /* AccessibilityTextMarker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29210EB1144CACD400835BB5 /* AccessibilityTextMarker.cpp */; };
0FEB909E1905A776000FDBF3 /* InjectedBundlePageCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = InjectedBundlePageCocoa.mm; sourceTree = "<group>"; };
0FEB90A21905BC6A000FDBF3 /* CrashReporterInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CrashReporterInfo.h; path = cocoa/CrashReporterInfo.h; sourceTree = "<group>"; };
0FEB90A31905BC6A000FDBF3 /* CrashReporterInfo.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = CrashReporterInfo.mm; path = cocoa/CrashReporterInfo.mm; sourceTree = "<group>"; };
+ 0FEBF8581BB61DF20028722D /* HIDEventGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HIDEventGenerator.h; sourceTree = "<group>"; };
+ 0FEBF8591BB61DF20028722D /* HIDEventGenerator.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = HIDEventGenerator.mm; sourceTree = "<group>"; };
+ 0FEBF85B1BB62A370028722D /* IOKitSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IOKitSPI.h; sourceTree = "<group>"; };
+ 0FEBF85C1BB62D460028722D /* UIKitSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UIKitSPI.h; sourceTree = "<group>"; };
1A3326051B75396500F89F62 /* TestOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TestOptions.h; sourceTree = "<group>"; };
26D758E5160BECDC00268472 /* GeolocationProviderMock.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GeolocationProviderMock.cpp; sourceTree = "<group>"; };
26D758E6160BECDD00268472 /* GeolocationProviderMock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GeolocationProviderMock.h; sourceTree = "<group>"; };
children = (
0F87B6181BACC558004EC572 /* Launch.storyboard */,
2EE52CEB1890A9A80010ED21 /* InfoPlist.strings */,
+ 0FEBF85B1BB62A370028722D /* IOKitSPI.h */,
+ 0FEBF85C1BB62D460028722D /* UIKitSPI.h */,
+ 0FEBF8581BB61DF20028722D /* HIDEventGenerator.h */,
+ 0FEBF8591BB61DF20028722D /* HIDEventGenerator.mm */,
2EE52D131890A9FB0010ED21 /* PlatformWebViewIOS.mm */,
2EE52D141890A9FB0010ED21 /* TestControllerIOS.mm */,
0F73B55B1BA89042004B3EF4 /* UIScriptControllerIOS.mm */,
2E63ED941891ADAD002A7AFC /* mainIOS.mm in Sources */,
2E63ED921891ADAD002A7AFC /* TestControllerIOS.mm in Sources */,
2E63ED9C1891ADC7002A7AFC /* AppDelegate.m in Sources */,
+ 0FEBF85A1BB61DF20028722D /* HIDEventGenerator.mm in Sources */,
2E63ED911891ADAD002A7AFC /* PlatformWebViewIOS.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
@interface TestRunnerWKWebView : WKWebView
#if PLATFORM(IOS)
+
+@property (nonatomic, copy) void (^willBeginZoomingCallback)(void);
+@property (nonatomic, copy) void (^didEndZoomingCallback)(void);
+
- (void)zoomToScale:(double)scale animated:(BOOL)animated completionHandler:(void (^)(void))completionHandler;
-- (void)onDidEndZooming:(void (^)(void))completionHandler;
+
#endif
@end
#if PLATFORM(IOS)
@interface WKWebView ()
+// FIXME: move these to WKWebView_Private.h
+- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view;
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale;
@end
#if WK_API_ENABLED
@interface TestRunnerWKWebView ()
-@property (nonatomic, copy) void (^zoomCompletionHandler)(void);
+@property (nonatomic, copy) void (^zoomToScaleCompletionHandler)(void);
@end
@implementation TestRunnerWKWebView
#if PLATFORM(IOS)
- (void)zoomToScale:(double)scale animated:(BOOL)animated completionHandler:(void (^)(void))completionHandler
{
- ASSERT(!self.zoomCompletionHandler);
- self.zoomCompletionHandler = completionHandler;
+ ASSERT(!self.zoomToScaleCompletionHandler);
+ self.zoomToScaleCompletionHandler = completionHandler;
[self.scrollView setZoomScale:scale animated:animated];
}
+- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(nullable UIView *)view
+{
+ [super scrollViewWillBeginZooming:scrollView withView:view];
+
+ if (self.willBeginZoomingCallback)
+ self.willBeginZoomingCallback();
+}
+
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale
{
[super scrollViewDidEndZooming:scrollView withView:view atScale:scale];
- if (self.zoomCompletionHandler) {
- self.zoomCompletionHandler();
- self.zoomCompletionHandler = nullptr;
- }
-}
+ if (self.didEndZoomingCallback)
+ self.didEndZoomingCallback();
-- (void)onDidEndZooming:(void (^)(void))completionHandler
-{
- ASSERT(!self.zoomCompletionHandler);
- self.zoomCompletionHandler = completionHandler;
+ if (self.zoomToScaleCompletionHandler) {
+ self.zoomToScaleCompletionHandler();
+ self.zoomToScaleCompletionHandler = nullptr;
+ }
}
#endif
--- /dev/null
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "UIKitSPI.h"
+
+#import <CoreGraphics/CGGeometry.h>
+
+@interface HIDEventGenerator : NSObject
+
++ (HIDEventGenerator *)sharedHIDEventGenerator;
+
+// Touches
+- (void)touchDown:(CGPoint)location;
+- (void)liftUp:(CGPoint)location;
+- (void)moveToPoints:(CGPoint*)locations touchCount:(NSUInteger)count duration:(NSTimeInterval)seconds;
+
+// Taps
+- (void)tap:(CGPoint)location completionBlock:(void (^)(void))completionBlock;
+- (void)doubleTap:(CGPoint)location completionBlock:(void (^)(void))completionBlock;
+- (void)twoFingerTap:(CGPoint)location completionBlock:(void (^)(void))completionBlock;
+
+// Drags
+- (void)dragWithStartPoint:(CGPoint)startLocation endPoint:(CGPoint)endLocation duration:(double)seconds completionBlock:(void (^)(void))completionBlock;
+
+// Pinches
+- (void)pinchCloseWithStartPoint:(CGPoint)startLocation endPoint:(CGPoint)endLocation duration:(double)seconds completionBlock:(void (^)(void))completionBlock;
+- (void)pinchOpenWithStartPoint:(CGPoint)startLocation endPoint:(CGPoint)endLocation duration:(double)seconds completionBlock:(void (^)(void))completionBlock;
+
+- (void)markerEventReceived:(IOHIDEventRef)event;
+
+@end
--- /dev/null
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "HIDEventGenerator.h"
+
+#import "IOKitSPI.h"
+#import "UIKitSPI.h"
+#import <WebCore/SoftLinking.h>
+#import <mach/mach_time.h>
+#import <wtf/Assertions.h>
+#import <wtf/RetainPtr.h>
+
+SOFT_LINK_PRIVATE_FRAMEWORK(BackBoardServices)
+SOFT_LINK(BackBoardServices, BKSHIDEventSetDigitizerInfo, void, (IOHIDEventRef digitizerEvent, uint32_t contextID, uint8_t systemGestureisPossible, uint8_t isSystemGestureStateChangeEvent, CFStringRef displayUUID, CFTimeInterval initialTouchTimestamp, float maxForce), (digitizerEvent, contextID, systemGestureisPossible, isSystemGestureStateChangeEvent, displayUUID, initialTouchTimestamp, maxForce));
+
+static const NSTimeInterval fingerLiftDelay = 5e7;
+static const NSTimeInterval multiTapInterval = 15e7;
+static const NSTimeInterval fingerMoveInterval = 0.016;
+static const IOHIDFloat defaultMajorRadius = 5;
+static const IOHIDFloat defaultPathPressure = 0;
+static const NSUInteger maxTouchCount = 5;
+static const long nanosecondsPerSecond = 1e9;
+
+static int fingerIdentifiers[maxTouchCount] = { 2, 3, 4, 5, 1 };
+
+typedef enum {
+ HandEventNull,
+ HandEventTouched,
+ HandEventMoved,
+ HandEventChordChanged,
+ HandEventLifted,
+ HandEventCanceled,
+ HandEventInRange,
+ HandEventInRangeLift,
+} HandEventType;
+
+typedef struct {
+ int identifier;
+ CGPoint point;
+ IOHIDFloat pathMajorRadius;
+ IOHIDFloat pathPressure;
+ UInt8 pathProximity;
+} SyntheticEventDigitizerInfo;
+
+static CFTimeInterval secondsSinceAbsoluteTime(CFAbsoluteTime startTime)
+{
+ return (CFAbsoluteTimeGetCurrent() - startTime);
+}
+
+static double simpleDragCurve(double a, double b, double t)
+{
+ return (a + (b - a) * sin(sin(t * M_PI / 2) * t * M_PI / 2));
+}
+
+static CGPoint calculateNextLocation(CGPoint a, CGPoint b, CFTimeInterval t)
+{
+ return CGPointMake(simpleDragCurve(a.x, b.x, t), simpleDragCurve(a.y, b.y, t));
+}
+
+static void delayBetweenMove(int eventIndex, double elapsed)
+{
+ // Delay next event until expected elapsed time.
+ double delay = (eventIndex * fingerMoveInterval) - elapsed;
+ if (delay > 0) {
+ struct timespec moveDelay = { 0, static_cast<long>(delay * nanosecondsPerSecond) };
+ nanosleep(&moveDelay, NULL);
+ }
+}
+
+@interface HIDEventGenerator ()
+@property (nonatomic, strong) NSMutableDictionary *eventCallbacks;
+@end
+
+@implementation HIDEventGenerator {
+ IOHIDEventSystemClientRef _ioSystemClient;
+ SyntheticEventDigitizerInfo _activePoints[maxTouchCount];
+ NSUInteger _activePointCount;
+}
+
++ (HIDEventGenerator *)sharedHIDEventGenerator
+{
+ static HIDEventGenerator *eventGenerator = nil;
+ if (!eventGenerator)
+ eventGenerator = [[HIDEventGenerator alloc] init];
+
+ return eventGenerator;
+}
+
++ (unsigned)nextEventCallbackID
+{
+ static unsigned callbackID = 0;
+ return ++callbackID;
+}
+
+- (instancetype)init
+{
+ self = [super init];
+ if (!self)
+ return nil;
+
+ for (NSUInteger i = 0; i < maxTouchCount; ++i)
+ _activePoints[i].identifier = fingerIdentifiers[i];
+
+ _eventCallbacks = [[NSMutableDictionary alloc] init];
+
+ return self;
+}
+
+- (IOHIDEventRef)_createIOHIDEventType:(HandEventType)eventType
+{
+ BOOL isTouching = (eventType == HandEventTouched || eventType == HandEventMoved || eventType == HandEventChordChanged);
+
+ IOHIDDigitizerEventMask eventMask = kIOHIDDigitizerEventTouch;
+ if (eventType == HandEventMoved) {
+ eventMask &= ~kIOHIDDigitizerEventTouch;
+ eventMask |= kIOHIDDigitizerEventPosition;
+ eventMask |= kIOHIDDigitizerEventAttribute;
+ } else if (eventType == HandEventChordChanged) {
+ eventMask |= kIOHIDDigitizerEventPosition;
+ eventMask |= kIOHIDDigitizerEventAttribute;
+ } else if (eventType == HandEventTouched || eventType == HandEventCanceled) {
+ eventMask |= kIOHIDDigitizerEventIdentity;
+ } else if (eventType == HandEventLifted)
+ eventMask |= kIOHIDDigitizerEventIdentity;
+
+ uint64_t machTime = mach_absolute_time();
+ RetainPtr<IOHIDEventRef> eventRef = adoptCF(IOHIDEventCreateDigitizerEvent(kCFAllocatorDefault, machTime,
+ kIOHIDDigitizerTransducerTypeHand,
+ 0,
+ 0,
+ eventMask,
+ 0,
+ 0, 0, 0,
+ 0,
+ 0,
+ 0,
+ isTouching,
+ kIOHIDEventOptionNone));
+
+ IOHIDEventSetIntegerValue(eventRef.get(), kIOHIDEventFieldDigitizerIsDisplayIntegrated, 1);
+
+ for (NSUInteger i = 0; i < _activePointCount; ++i) {
+ SyntheticEventDigitizerInfo* pointInfo = &_activePoints[i];
+ if (eventType == HandEventTouched) {
+ if (!pointInfo->pathMajorRadius)
+ pointInfo->pathMajorRadius = defaultMajorRadius;
+ if (!pointInfo->pathPressure)
+ pointInfo->pathPressure = defaultPathPressure;
+ if (!pointInfo->pathProximity)
+ pointInfo->pathProximity = kGSEventPathInfoInTouch | kGSEventPathInfoInRange;
+ } else if (eventType == HandEventLifted || eventType == HandEventCanceled) {
+ pointInfo->pathMajorRadius = 0;
+ pointInfo->pathPressure = 0;
+ pointInfo->pathProximity = 0;
+ }
+
+ CGPoint point = pointInfo->point;
+ point = CGPointMake(roundf(point.x), roundf(point.y));
+ RetainPtr<IOHIDEventRef> subEvent = adoptCF(IOHIDEventCreateDigitizerFingerEvent(kCFAllocatorDefault, machTime,
+ pointInfo->identifier,
+ pointInfo->identifier,
+ eventMask,
+ point.x, point.y, 0,
+ pointInfo->pathPressure,
+ 0,
+ pointInfo->pathProximity & kGSEventPathInfoInRange,
+ pointInfo->pathProximity & kGSEventPathInfoInTouch,
+ kIOHIDEventOptionNone));
+ IOHIDEventSetFloatValue(subEvent.get(), kIOHIDEventFieldDigitizerMajorRadius, pointInfo->pathMajorRadius);
+ IOHIDEventSetFloatValue(subEvent.get(), kIOHIDEventFieldDigitizerMinorRadius, pointInfo->pathMajorRadius);
+ IOHIDEventAppendEvent(eventRef.get(), subEvent.get(), 0);
+ }
+
+ if (_activePointCount) {
+ IOHIDFloat progress = _activePoints[0].pathPressure;
+ RetainPtr<IOHIDEventRef> forceEvent = adoptCF(IOHIDEventCreateForceEvent(kCFAllocatorDefault,
+ machTime,
+ 0,
+ progress,
+ 0,
+ 0.0,
+ kIOHIDEventOptionNone));
+ IOHIDEventAppendEvent(eventRef.get(), forceEvent.get(), 0);
+ }
+
+ return eventRef.leakRef();
+}
+
+- (BOOL)_sendHIDEvent:(IOHIDEventRef)eventRef
+{
+ if (!_ioSystemClient)
+ _ioSystemClient = IOHIDEventSystemClientCreate(kCFAllocatorDefault);
+
+ if (eventRef) {
+ RetainPtr<IOHIDEventRef> strongEvent = eventRef;
+ dispatch_async(dispatch_get_main_queue(), ^{
+ uint32_t contextID = [UIApplication sharedApplication].keyWindow._contextId;
+ ASSERT(contextID);
+ BKSHIDEventSetDigitizerInfo(strongEvent.get(), contextID, false, false, NULL, 0, 0);
+ [[UIApplication sharedApplication] _enqueueHIDEvent:strongEvent.get()];
+ });
+ }
+ return YES;
+}
+
+- (BOOL)_sendMarkerHIDEventWithCompletionBlock:(void (^)(void))completionBlock
+{
+ unsigned callbackID = [HIDEventGenerator nextEventCallbackID];
+ void (^completionBlockCopy)() = Block_copy(completionBlock);
+ [_eventCallbacks setObject:completionBlockCopy forKey:@(callbackID)];
+
+ uint64_t machTime = mach_absolute_time();
+ RetainPtr<IOHIDEventRef> markerEvent = adoptCF(IOHIDEventCreateVendorDefinedEvent(kCFAllocatorDefault,
+ machTime,
+ kHIDPage_VendorDefinedStart + 100,
+ 0,
+ 1,
+ (uint8_t*)&callbackID,
+ sizeof(unsigned),
+ kIOHIDEventOptionNone));
+
+ if (markerEvent) {
+ markerEvent.get();
+ dispatch_async(dispatch_get_main_queue(), ^{
+ uint32_t contextID = [UIApplication sharedApplication].keyWindow._contextId;
+ ASSERT(contextID);
+ BKSHIDEventSetDigitizerInfo(markerEvent.get(), contextID, false, false, NULL, 0, 0);
+ [[UIApplication sharedApplication] _enqueueHIDEvent:markerEvent.get()];
+ });
+ }
+ return YES;
+}
+
+- (void)_updateTouchPoints:(CGPoint*)points count:(NSUInteger)count
+{
+ HandEventType handEventType;
+
+ // The hand event type is based on previous state.
+ if (!_activePointCount)
+ handEventType = HandEventTouched;
+ else if (!count)
+ handEventType = HandEventLifted;
+ else if (count == _activePointCount)
+ handEventType = HandEventMoved;
+ else
+ handEventType = HandEventChordChanged;
+
+ // Update previous count for next event.
+ _activePointCount = count;
+
+ // Update point locations.
+ for (NSUInteger i = 0; i < count; ++i)
+ _activePoints[i].point = points[i];
+
+ RetainPtr<IOHIDEventRef> eventRef = adoptCF([self _createIOHIDEventType:handEventType]);
+ [self _sendHIDEvent:eventRef.get()];
+}
+
+- (void)touchDownAtPoints:(CGPoint*)locations touchCount:(NSUInteger)touchCount
+{
+ touchCount = MIN(touchCount, maxTouchCount);
+
+ _activePointCount = touchCount;
+
+ for (NSUInteger index = 0; index < touchCount; ++index)
+ _activePoints[index].point = locations[index];
+
+ RetainPtr<IOHIDEventRef> eventRef = adoptCF([self _createIOHIDEventType:HandEventTouched]);
+ [self _sendHIDEvent:eventRef.get()];
+}
+
+- (void)touchDown:(CGPoint)location touchCount:(NSUInteger)touchCount
+{
+ touchCount = MIN(touchCount, maxTouchCount);
+
+ CGPoint locations[touchCount];
+
+ for (NSUInteger index = 0; index < touchCount; ++index)
+ locations[index] = location;
+
+ [self touchDownAtPoints:locations touchCount:touchCount];
+}
+
+- (void)touchDown:(CGPoint)location
+{
+ [self touchDownAtPoints:&location touchCount:1];
+}
+
+- (void)liftUpAtPoints:(CGPoint*)locations touchCount:(NSUInteger)touchCount
+{
+ touchCount = MIN(touchCount, maxTouchCount);
+ touchCount = MIN(touchCount, _activePointCount);
+
+ NSUInteger newPointCount = _activePointCount - touchCount;
+
+ for (NSUInteger index = 0; index < touchCount; ++index)
+ _activePoints[newPointCount + index].point = locations[index];
+
+ RetainPtr<IOHIDEventRef> eventRef = adoptCF([self _createIOHIDEventType:HandEventLifted]);
+ [self _sendHIDEvent:eventRef.get()];
+
+ _activePointCount = newPointCount;
+}
+
+- (void)liftUp:(CGPoint)location touchCount:(NSUInteger)touchCount
+{
+ touchCount = MIN(touchCount, maxTouchCount);
+
+ CGPoint locations[touchCount];
+
+ for (NSUInteger index = 0; index < touchCount; ++index)
+ locations[index] = location;
+
+ [self liftUpAtPoints:locations touchCount:touchCount];
+}
+
+- (void)liftUp:(CGPoint)location
+{
+ [self liftUp:location touchCount:1];
+}
+
+- (void)moveToPoints:(CGPoint*)newLocations touchCount:(NSUInteger)touchCount duration:(NSTimeInterval)seconds
+{
+ touchCount = MIN(touchCount, maxTouchCount);
+
+ CGPoint startLocations[touchCount];
+ CGPoint nextLocations[touchCount];
+
+ CFAbsoluteTime startTime = CFAbsoluteTimeGetCurrent();
+ CFTimeInterval elapsed = 0;
+
+ int eventIndex = 0;
+ while (elapsed < (seconds - fingerMoveInterval)) {
+ elapsed = secondsSinceAbsoluteTime(startTime);
+ CFTimeInterval interval = elapsed / seconds;
+
+ for (NSUInteger i = 0; i < touchCount; ++i) {
+ if (!eventIndex)
+ startLocations[i] = _activePoints[i].point;
+
+ nextLocations[i] = calculateNextLocation(startLocations[i], newLocations[i], interval);
+ }
+ [self _updateTouchPoints:nextLocations count:touchCount];
+
+ delayBetweenMove(eventIndex++, elapsed);
+ }
+
+ [self _updateTouchPoints:newLocations count:touchCount];
+}
+
+- (void)sendTaps:(int)tapCount location:(CGPoint)location withNumberOfTouches:(int)touchCount completionBlock:(void (^)(void))completionBlock
+{
+ struct timespec doubleDelay = { 0, static_cast<long>(multiTapInterval) };
+ struct timespec pressDelay = { 0, static_cast<long>(fingerLiftDelay) };
+
+ for (int i = 0; i < tapCount; i++) {
+ [self touchDown:location touchCount:touchCount];
+ nanosleep(&pressDelay, 0);
+ [self liftUp:location touchCount:touchCount];
+ if (i + 1 != tapCount)
+ nanosleep(&doubleDelay, 0);
+ }
+
+ [self _sendMarkerHIDEventWithCompletionBlock:completionBlock];
+}
+
+- (void)tap:(CGPoint)location completionBlock:(void (^)(void))completionBlock
+{
+ [self sendTaps:1 location:location withNumberOfTouches:1 completionBlock:completionBlock];
+}
+
+- (void)doubleTap:(CGPoint)location completionBlock:(void (^)(void))completionBlock
+{
+ [self sendTaps:2 location:location withNumberOfTouches:1 completionBlock:completionBlock];
+}
+
+- (void)twoFingerTap:(CGPoint)location completionBlock:(void (^)(void))completionBlock
+{
+ [self sendTaps:1 location:location withNumberOfTouches:2 completionBlock:completionBlock];
+}
+
+- (void)dragWithStartPoint:(CGPoint)startLocation endPoint:(CGPoint)endLocation duration:(double)seconds completionBlock:(void (^)(void))completionBlock
+{
+}
+
+- (void)pinchCloseWithStartPoint:(CGPoint)startLocation endPoint:(CGPoint)endLocation duration:(double)seconds completionBlock:(void (^)(void))completionBlock
+{
+}
+
+- (void)pinchOpenWithStartPoint:(CGPoint)startLocation endPoint:(CGPoint)endLocation duration:(double)seconds completionBlock:(void (^)(void))completionBlock
+{
+}
+
+- (void)markerEventReceived:(IOHIDEventRef)event
+{
+ if (IOHIDEventGetType(event) != kIOHIDEventTypeVendorDefined)
+ return;
+
+ CFIndex callbackID = IOHIDEventGetIntegerValue(event, kIOHIDEventFieldVendorDefinedData);
+ void (^completionBlock)() = [_eventCallbacks objectForKey:@(callbackID)];
+ if (completionBlock) {
+ [_eventCallbacks removeObjectForKey:@(callbackID)];
+ completionBlock();
+ Block_release(completionBlock);
+ }
+}
+
+@end
--- /dev/null
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef IOKitSPI_h
+#define IOKitSPI_h
+
+#import <wtf/Platform.h>
+
+#if PLATFORM(IOS)
+
+#if USE(APPLE_INTERNAL_SDK)
+
+#import <IOKit/hid/IOHIDEvent.h>
+#import <IOKit/hid/IOHIDEventSystemClient.h>
+#import <IOKit/hid/IOHIDUsageTables.h>
+
+#else
+
+WTF_EXTERN_C_BEGIN
+
+#ifdef __LP64__
+typedef double IOHIDFloat;
+#else
+typedef float IOHIDFloat;
+#endif
+
+enum {
+ kIOHIDEventOptionNone = 0,
+};
+
+typedef UInt32 IOOptionBits;
+typedef uint32_t IOHIDEventOptionBits;
+typedef uint32_t IOHIDEventField;
+
+typedef struct __IOHIDEventSystemClient * IOHIDEventSystemClientRef;
+typedef struct __IOHIDEvent * IOHIDEventRef;
+
+#define IOHIDEventFieldBase(type) (type << 16)
+
+enum {
+ kHIDPage_VendorDefinedStart = 0xFF00
+};
+
+enum {
+ kIOHIDDigitizerEventRange = 1<<0,
+ kIOHIDDigitizerEventTouch = 1<<1,
+ kIOHIDDigitizerEventPosition = 1<<2,
+ kIOHIDDigitizerEventIdentity = 1<<5,
+ kIOHIDDigitizerEventAttribute = 1<<6,
+ kIOHIDDigitizerEventCancel = 1<<7,
+ kIOHIDDigitizerEventStart = 1<<8,
+};
+typedef uint32_t IOHIDDigitizerEventMask;
+
+enum {
+ kIOHIDEventTypeNULL,
+ kIOHIDEventTypeVendorDefined,
+ kIOHIDEventTypeKeyboard = 3,
+ kIOHIDEventTypeDigitizer = 11,
+};
+typedef uint32_t IOHIDEventType;
+
+enum {
+ kIOHIDEventFieldVendorDefinedUsagePage = IOHIDEventFieldBase(kIOHIDEventTypeVendorDefined),
+ kIOHIDEventFieldVendorDefinedReserved,
+ kIOHIDEventFieldVendorDefinedReserved1,
+ kIOHIDEventFieldVendorDefinedDataLength,
+ kIOHIDEventFieldVendorDefinedData
+};
+
+enum {
+ kIOHIDEventFieldDigitizerX = IOHIDEventFieldBase(kIOHIDEventTypeDigitizer),
+ kIOHIDEventFieldDigitizerY,
+ kIOHIDEventFieldDigitizerMajorRadius = kIOHIDEventFieldDigitizerX + 20,
+ kIOHIDEventFieldDigitizerMinorRadius,
+ kIOHIDEventFieldDigitizerIsDisplayIntegrated = kIOHIDEventFieldDigitizerMajorRadius + 5,
+};
+
+enum {
+ kIOHIDDigitizerTransducerTypeHand = 3
+};
+typedef uint32_t IOHIDDigitizerTransducerType;
+
+IOHIDEventRef IOHIDEventCreateDigitizerEvent(CFAllocatorRef, uint64_t, IOHIDDigitizerTransducerType, uint32_t, uint32_t, IOHIDDigitizerEventMask, uint32_t, IOHIDFloat, IOHIDFloat, IOHIDFloat, IOHIDFloat, IOHIDFloat, boolean_t, boolean_t, IOOptionBits);
+
+IOHIDEventRef IOHIDEventCreateDigitizerFingerEvent(CFAllocatorRef, uint64_t, uint32_t, uint32_t, IOHIDDigitizerEventMask, IOHIDFloat, IOHIDFloat, IOHIDFloat, IOHIDFloat, IOHIDFloat, boolean_t, boolean_t, IOHIDEventOptionBits);
+
+IOHIDEventRef IOHIDEventCreateForceEvent(CFAllocatorRef, uint64_t, uint32_t, IOHIDFloat, uint32_t, IOHIDFloat, IOHIDEventOptionBits);
+
+IOHIDEventRef IOHIDEventCreateKeyboardEvent(CFAllocatorRef, uint64_t, uint32_t, uint32_t, boolean_t, IOOptionBits);
+
+IOHIDEventRef IOHIDEventCreateVendorDefinedEvent(CFAllocatorRef, uint64_t, uint32_t, uint32_t, uint32_t, uint8_t*, CFIndex, IOHIDEventOptionBits);
+
+IOHIDEventType IOHIDEventGetType(IOHIDEventRef);
+
+void IOHIDEventSetFloatValue(IOHIDEventRef, IOHIDEventField, IOHIDFloat);
+
+CFIndex IOHIDEventGetIntegerValue(IOHIDEventRef, IOHIDEventField);
+void IOHIDEventSetIntegerValue(IOHIDEventRef, IOHIDEventField, CFIndex);
+
+void IOHIDEventAppendEvent(IOHIDEventRef, IOHIDEventRef, IOOptionBits);
+
+IOHIDEventSystemClientRef IOHIDEventSystemClientCreate(CFAllocatorRef);
+
+#define kGSEventPathInfoInRange (1 << 0)
+#define kGSEventPathInfoInTouch (1 << 1)
+
+WTF_EXTERN_C_END
+
+#endif // USE(APPLE_INTERNAL_SDK)
+
+#endif // PLATFORM(IOS)
+
+#endif // IOKitSPI_h
--- /dev/null
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <UIKit/UIKit.h>
+
+#if USE(APPLE_INTERNAL_SDK)
+
+#import <UIKit/UIApplication_Private.h>
+#import <UIKit/UIWindow_Private.h>
+
+#else
+
+#import "IOKitSPI.h"
+
+@interface UIApplication ()
+- (void)_enqueueHIDEvent:(IOHIDEventRef)event;
+- (void)_handleHIDEvent:(IOHIDEventRef)event;
+@end
+
+@interface UIWindow ()
+- (uint32_t)_contextId;
+@end
+
+#endif
#if PLATFORM(IOS)
+#import "HIDEventGenerator.h"
#import "PlatformWebView.h"
#import "TestController.h"
#import "TestRunnerWKWebView.h"
return webView.scrollView.zoomScale;
}
+static CGPoint globalToContentCoordinates(TestRunnerWKWebView *webView, long x, long y)
+{
+ CGPoint point = CGPointMake(x, y);
+ point = [webView _convertPointFromContentsToView:point];
+ point = [webView convertPoint:point toView:nil];
+ point = [webView.window convertPoint:point toWindow:nil];
+ return point;
+}
+
+void UIScriptController::singleTapAtPoint(long x, long y, JSValueRef callback)
+{
+ unsigned callbackID = m_context.prepareForAsyncTask(callback);
+
+ [[HIDEventGenerator sharedHIDEventGenerator] tap:globalToContentCoordinates(TestController::singleton().mainWebView()->platformView(), x, y) completionBlock:^{
+ m_context.asyncTaskComplete(callbackID);
+ }];
+}
+
+void UIScriptController::doubleTapAtPoint(long x, long y, JSValueRef callback)
+{
+ unsigned callbackID = m_context.prepareForAsyncTask(callback);
+
+ [[HIDEventGenerator sharedHIDEventGenerator] doubleTap:globalToContentCoordinates(TestController::singleton().mainWebView()->platformView(), x, y) completionBlock:^{
+ m_context.asyncTaskComplete(callbackID);
+ }];
+}
+
double UIScriptController::minimumZoomScale() const
{
TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
return m_context.objectFromRect(wkRect);
}
+void UIScriptController::platformSetWillBeginZoomingCallback()
+{
+ TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
+ webView.willBeginZoomingCallback = ^{
+ m_context.fireCallback(m_willBeginZoomingCallback);
+ };
+}
+
+void UIScriptController::platformSetDidEndZoomingCallback()
+{
+ TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
+ webView.didEndZoomingCallback = ^{
+ m_context.fireCallback(m_didEndZoomingCallback);
+ };
+}
+
}
#endif // PLATFORM(IOS)
#import "config.h"
+#import "HIDEventGenerator.h"
#import "TestController.h"
+#import "UIKitSPI.h"
#import <UIKit/UIKit.h>
static int _argc;
});
}
+- (void)_handleHIDEvent:(IOHIDEventRef)event
+{
+ [[HIDEventGenerator sharedHIDEventGenerator] markerEventReceived:event];
+}
+
@end
int main(int argc, const char* argv[])