Add test and infrastructure for link popover
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Oct 2016 01:08:25 +0000 (01:08 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Oct 2016 01:08:25 +0000 (01:08 +0000)
https://bugs.webkit.org/show_bug.cgi?id=163406

Patch by Megan Gardner <megan_gardner@apple.com> on 2016-10-17
Reviewed by Simon Fraser.

Source/WebKit2:

Add infrastructure to see when a link popover appears, and what URL it has loaded.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView didShowForcePressPreview]):
(-[WKWebView didDismissForcePressPreview]):
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _contentsOfUserInterfaceItem:]):
(-[WKContentView _presentedViewControllerForPreviewItemController:]):
(-[WKContentView _previewItemController:didDismissPreview:committing:]):
(-[WKContentView _previewItemControllerDidCancelPreview:]):

Tools:

Added functionality test for link popovers.
Can query for what URL is loaded, and that the popover has appeared or has
been dismissed.
Added a link popover test.

* DumpRenderTree/ios/UIScriptControllerIOS.mm:
(WTR::UIScriptController::platformSetDidShowForcePressPreviewCallback):
(WTR::UIScriptController::platformSetDidDismissForcePressPreviewCallback):
(WTR::UIScriptController::platformSetDidEndFormControlInteractionCallback): Deleted.
* TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
* TestRunnerShared/UIScriptContext/UIScriptContext.h:
* TestRunnerShared/UIScriptContext/UIScriptController.cpp:
(WTR::UIScriptController::setDidShowForcePressPreviewCallback):
(WTR::UIScriptController::didShowForcePressPreviewCallback):
(WTR::UIScriptController::setDidDismissForcePressPreviewCallback):
(WTR::UIScriptController::didDismissForcePressPreviewCallback):
(WTR::UIScriptController::platformSetDidShowForcePressPreviewCallback):
(WTR::UIScriptController::platformSetDidDismissForcePressPreviewCallback):
(WTR::UIScriptController::didEndFormControlInteractionCallback): Deleted.
(WTR::UIScriptController::platformSetDidEndFormControlInteractionCallback): Deleted.
* TestRunnerShared/UIScriptContext/UIScriptController.h:
* WebKitTestRunner/cocoa/TestRunnerWKWebView.h:
* WebKitTestRunner/cocoa/TestRunnerWKWebView.mm:
(-[TestRunnerWKWebView dealloc]):
(-[TestRunnerWKWebView didShowForcePressPreview]):
(-[TestRunnerWKWebView didDismissForcePressPreview]):
* WebKitTestRunner/ios/UIScriptControllerIOS.mm:
(WTR::UIScriptController::platformSetDidShowForcePressPreviewCallback):
(WTR::UIScriptController::platformSetDidDismissForcePressPreviewCallback):
(WTR::UIScriptController::platformSetDidEndFormControlInteractionCallback): Deleted.

LayoutTests:

* fast/events/touch/ios/iphone7/force-press-on-link-expected.txt: Added.
* fast/events/touch/ios/iphone7/force-press-on-link.html: Added.

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

16 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/events/touch/ios/iphone7/force-press-on-link-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/touch/ios/iphone7/force-press-on-link.html [new file with mode: 0644]
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h
Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm
Tools/ChangeLog
Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm
Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl
Tools/TestRunnerShared/UIScriptContext/UIScriptContext.h
Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp
Tools/TestRunnerShared/UIScriptContext/UIScriptController.h
Tools/WebKitTestRunner/cocoa/TestRunnerWKWebView.h
Tools/WebKitTestRunner/cocoa/TestRunnerWKWebView.mm
Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm

index 480cfdd..bedab5f 100644 (file)
@@ -1,3 +1,13 @@
+2016-10-17  Megan Gardner  <megan_gardner@apple.com>
+
+        Add test and infrastructure for link popover
+        https://bugs.webkit.org/show_bug.cgi?id=163406
+
+        Reviewed by Simon Fraser.
+
+        * fast/events/touch/ios/iphone7/force-press-on-link-expected.txt: Added.
+        * fast/events/touch/ios/iphone7/force-press-on-link.html: Added.
+
 2016-10-17  Joseph Pecoraro  <pecoraro@apple.com>
 
         Web Inspector: Add toggles for debugger pauses at console.assert failures
diff --git a/LayoutTests/fast/events/touch/ios/iphone7/force-press-on-link-expected.txt b/LayoutTests/fast/events/touch/ios/iphone7/force-press-on-link-expected.txt
new file mode 100644 (file)
index 0000000..7cb8416
--- /dev/null
@@ -0,0 +1 @@
+PASS: correct page loaded in popover
diff --git a/LayoutTests/fast/events/touch/ios/iphone7/force-press-on-link.html b/LayoutTests/fast/events/touch/ios/iphone7/force-press-on-link.html
new file mode 100644 (file)
index 0000000..eda45b1
--- /dev/null
@@ -0,0 +1,111 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true ] -->
+
+<html>
+<head>
+    <script>
+        if (window.testRunner) {
+            testRunner.dumpAsText();
+            testRunner.waitUntilDone();
+        }
+
+        function getUIScript()
+        {
+            return `
+            (function() {
+                var eventStream = {
+                    events : [
+                        {
+                            interpolate : "linear",
+                            timestep: 0.025,
+                            startEvent : {
+                                inputType : "hand",
+                                timeOffset : 0,
+                                touches : [
+                                    {
+                                        inputType : "finger",
+                                        phase : "began",
+                                        id : 1,
+                                        x : 20,
+                                        y : 40,
+                                        pressure : 0
+                                    }
+                                ]
+                            },
+                            endEvent : {
+                                inputType : "hand",
+                                timeOffset : 3.0,
+                                touches : [
+                                    {
+                                        inputType : "finger",
+                                        phase : "stationary",
+                                        id : 1,
+                                        x : 20,
+                                        y : 40,
+                                        pressure : 500
+                                    }
+                                ]
+                            }
+                        }
+                    ]
+                };
+
+                uiController.sendEventStream(JSON.stringify(eventStream), function() {});
+             
+                uiController.didShowForcePressPreviewCallback = function() {
+                    uiController.uiScriptComplete(JSON.stringify(uiController.contentsOfUserInterfaceItem('linkPreviewPopoverContents')));
+                };
+             
+            })();`
+        }
+    
+        function getUIFinishScript()
+        {
+            return `
+            (function() {
+                uiController.liftUpAtPoint(20, 40, 1, function() {
+                   uiController.uiScriptComplete();
+                });
+            })();`
+        }
+
+        function runTest()
+        {
+            if (!testRunner.runUIScript)
+                return;
+
+            var output = '';
+            var target = document.getElementById('target');
+            
+            if (testRunner.runUIScript) {
+                testRunner.runUIScript(getUIScript(), function(result) {
+                    var uiContentsDictionary = JSON.parse(result);
+                    var pageURL = uiContentsDictionary.linkPreviewPopoverContents.pageURL;
+                    if (pageURL = 'http://localhost:54321')
+                        output += 'PASS: correct page loaded in popover';
+                    document.getElementById('target').innerHTML = output;
+                                       
+                    testRunner.runUIScript(getUIFinishScript(), function() {
+                        testRunner.notifyDone();
+                    });
+               });
+            }
+        }
+
+        window.addEventListener('load', runTest, false);
+    </script>
+    <style>
+        #target {
+            height: 100px;
+            width: 200px;
+            background-color: silver;
+        }
+    </style>
+    <meta name="viewport" content="initial-scale=1">
+</head>
+<body>
+<div id="target">
+    <a href="http://localhost:54321">Link Test</a>
+    This test requires UIScriptController to run.
+</div>
+</body>
+</html>
index f1713cd..8127df3 100644 (file)
@@ -1,3 +1,22 @@
+2016-10-17  Megan Gardner  <megan_gardner@apple.com>
+
+        Add test and infrastructure for link popover
+        https://bugs.webkit.org/show_bug.cgi?id=163406
+
+        Reviewed by Simon Fraser.
+
+        Add infrastructure to see when a link popover appears, and what URL it has loaded.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView didShowForcePressPreview]):
+        (-[WKWebView didDismissForcePressPreview]):
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView _contentsOfUserInterfaceItem:]):
+        (-[WKContentView _presentedViewControllerForPreviewItemController:]):
+        (-[WKContentView _previewItemController:didDismissPreview:committing:]):
+        (-[WKContentView _previewItemControllerDidCancelPreview:]):
+
 2016-10-17  Tim Horton  <timothy_horton@apple.com>
 
         REGRESSION (r169805): WKWebView canGoBack returning YES when nothing is in the back-forward list after restoring session state
index 2d4696a..ffe41f0 100644 (file)
@@ -4547,6 +4547,16 @@ static WebCore::UserInterfaceLayoutDirection toUserInterfaceLayoutDirection(UISe
     // For subclasses to override.
 }
 
+- (void)_didShowForcePressPreview
+{
+    // For subclasses to override.
+}
+
+- (void)_didDismissForcePressPreview
+{
+    // For subclasses to override.
+}
+
 - (NSArray<UIView *> *)_uiTextSelectionRectViews
 {
     return [_contentView valueForKeyPath:@"interactionAssistant.selectionView.rangeView.m_rectViews"];
index d4315b6..754f62f 100644 (file)
@@ -268,6 +268,9 @@ typedef NS_ENUM(NSInteger, _WKImmediateActionType) {
 - (void)didStartFormControlInteraction WK_API_AVAILABLE(ios(WK_IOS_TBA));
 - (void)didEndFormControlInteraction WK_API_AVAILABLE(ios(WK_IOS_TBA));
 
+- (void)_didShowForcePressPreview WK_API_AVAILABLE(ios(WK_IOS_TBA));
+- (void)_didDismissForcePressPreview WK_API_AVAILABLE(ios(WK_IOS_TBA));
+
 @property (nonatomic, readonly) NSArray<UIView *> *_uiTextSelectionRectViews WK_API_AVAILABLE(ios(WK_IOS_TBA));
 
 #endif
index 0376f08..d5d3513 100644 (file)
@@ -3849,6 +3849,11 @@ static bool isAssistableInputType(InputType type)
     if ([userInterfaceItem isEqualToString:@"actionSheet"])
         return @{ userInterfaceItem: [_actionSheetAssistant currentAvailableActionTitles] };
     
+    if ([userInterfaceItem isEqualToString:@"linkPreviewPopoverContents"]) {
+        NSString *url = [_previewItemController previewData][UIPreviewDataLink];
+        return @{ userInterfaceItem: @{ @"pageURL": url } };
+    }
+    
     return nil;
 }
 
@@ -4022,6 +4027,8 @@ static NSString *previewIdentifierForElementAction(_WKElementAction *action)
 - (UIViewController *)_presentedViewControllerForPreviewItemController:(UIPreviewItemController *)controller
 {
     id <WKUIDelegatePrivate> uiDelegate = static_cast<id <WKUIDelegatePrivate>>([_webView UIDelegate]);
+    
+    [_webView _didShowForcePressPreview];
 
     NSURL *targetURL = controller.previewData[UIPreviewDataLink];
     URL coreTargetURL = targetURL;
@@ -4128,6 +4135,8 @@ static NSString *previewIdentifierForElementAction(_WKElementAction *action)
         [uiDelegate _webView:_webView didDismissPreviewViewController:viewController committing:committing];
     else if ([uiDelegate respondsToSelector:@selector(_webView:didDismissPreviewViewController:)])
         [uiDelegate _webView:_webView didDismissPreviewViewController:viewController];
+    
+    [_webView _didDismissForcePressPreview];
 }
 
 - (UIImage *)_presentationSnapshotForPreviewItemController:(UIPreviewItemController *)controller
@@ -4161,6 +4170,8 @@ static NSString *previewIdentifierForElementAction(_WKElementAction *action)
 - (void)_previewItemControllerDidCancelPreview:(UIPreviewItemController *)controller
 {
     _highlightLongPressCanClick = NO;
+    
+    [_webView _didDismissForcePressPreview];
 }
 
 @end
index b0cae69..9ddbbac 100644 (file)
@@ -1,3 +1,41 @@
+2016-10-17  Megan Gardner  <megan_gardner@apple.com>
+
+        Add test and infrastructure for link popover
+        https://bugs.webkit.org/show_bug.cgi?id=163406
+
+        Reviewed by Simon Fraser.
+
+        Added functionality test for link popovers.
+        Can query for what URL is loaded, and that the popover has appeared or has
+        been dismissed.
+        Added a link popover test.
+
+        * DumpRenderTree/ios/UIScriptControllerIOS.mm:
+        (WTR::UIScriptController::platformSetDidShowForcePressPreviewCallback):
+        (WTR::UIScriptController::platformSetDidDismissForcePressPreviewCallback):
+        (WTR::UIScriptController::platformSetDidEndFormControlInteractionCallback): Deleted.
+        * TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
+        * TestRunnerShared/UIScriptContext/UIScriptContext.h:
+        * TestRunnerShared/UIScriptContext/UIScriptController.cpp:
+        (WTR::UIScriptController::setDidShowForcePressPreviewCallback):
+        (WTR::UIScriptController::didShowForcePressPreviewCallback):
+        (WTR::UIScriptController::setDidDismissForcePressPreviewCallback):
+        (WTR::UIScriptController::didDismissForcePressPreviewCallback):
+        (WTR::UIScriptController::platformSetDidShowForcePressPreviewCallback):
+        (WTR::UIScriptController::platformSetDidDismissForcePressPreviewCallback):
+        (WTR::UIScriptController::didEndFormControlInteractionCallback): Deleted.
+        (WTR::UIScriptController::platformSetDidEndFormControlInteractionCallback): Deleted.
+        * TestRunnerShared/UIScriptContext/UIScriptController.h:
+        * WebKitTestRunner/cocoa/TestRunnerWKWebView.h:
+        * WebKitTestRunner/cocoa/TestRunnerWKWebView.mm:
+        (-[TestRunnerWKWebView dealloc]):
+        (-[TestRunnerWKWebView didShowForcePressPreview]):
+        (-[TestRunnerWKWebView didDismissForcePressPreview]):
+        * WebKitTestRunner/ios/UIScriptControllerIOS.mm:
+        (WTR::UIScriptController::platformSetDidShowForcePressPreviewCallback):
+        (WTR::UIScriptController::platformSetDidDismissForcePressPreviewCallback):
+        (WTR::UIScriptController::platformSetDidEndFormControlInteractionCallback): Deleted.
+
 2016-10-17  Tim Horton  <timothy_horton@apple.com>
 
         REGRESSION (r169805): WKWebView canGoBack returning YES when nothing is in the back-forward list after restoring session state
index 0c5728e..a9d3c63 100644 (file)
@@ -173,6 +173,14 @@ void UIScriptController::platformSetDidStartFormControlInteractionCallback()
 void UIScriptController::platformSetDidEndFormControlInteractionCallback()
 {
 }
+    
+void UIScriptController::platformSetDidShowForcePressPreviewCallback()
+{
+}
+
+void UIScriptController::platformSetDidDismissForcePressPreviewCallback()
+{
+}
 
 void UIScriptController::platformSetWillBeginZoomingCallback()
 {
index 891293a..984dcf6 100644 (file)
@@ -122,6 +122,10 @@ interface UIScriptController {
     attribute object didStartFormControlInteractionCallback;
     attribute object didEndFormControlInteractionCallback;
 
+    // Force press preview handling
+    attribute object didShowForcePressPreviewCallback;
+    attribute object didDismissForcePressPreviewCallback;
+
     // <select> picker
     void selectFormAccessoryPickerRow(long rowIndex);
 
index 0e63c4c..01ef238 100644 (file)
@@ -56,6 +56,8 @@ typedef enum  {
     CallbackTypeDidEndScrolling,
     CallbackTypeDidStartFormControlInteraction,
     CallbackTypeDidEndFormControlInteraction,
+    CallbackTypeDidShowForcePressPreview,
+    CallbackTypeDidDismissForcePressPreview,
     CallbackTypeNonPersistent = firstNonPersistentCallbackID
 } CallbackType;
 
index 5c4cba5..4043cd7 100644 (file)
@@ -79,6 +79,28 @@ JSValueRef UIScriptController::didEndFormControlInteractionCallback() const
 {
     return m_context->callbackWithID(CallbackTypeDidEndFormControlInteraction);
 }
+    
+void UIScriptController::setDidShowForcePressPreviewCallback(JSValueRef callback)
+{
+    m_context->registerCallback(callback, CallbackTypeDidShowForcePressPreview);
+    platformSetDidShowForcePressPreviewCallback();
+}
+
+JSValueRef UIScriptController::didShowForcePressPreviewCallback() const
+{
+    return m_context->callbackWithID(CallbackTypeDidShowForcePressPreview);
+}
+
+void UIScriptController::setDidDismissForcePressPreviewCallback(JSValueRef callback)
+{
+    m_context->registerCallback(callback, CallbackTypeDidDismissForcePressPreview);
+    platformSetDidDismissForcePressPreviewCallback();
+}
+
+JSValueRef UIScriptController::didDismissForcePressPreviewCallback() const
+{
+    return m_context->callbackWithID(CallbackTypeDidDismissForcePressPreview);
+}
 
 void UIScriptController::setWillBeginZoomingCallback(JSValueRef callback)
 {
@@ -253,6 +275,14 @@ void UIScriptController::platformSetDidStartFormControlInteractionCallback()
 void UIScriptController::platformSetDidEndFormControlInteractionCallback()
 {
 }
+    
+void UIScriptController::platformSetDidShowForcePressPreviewCallback()
+{
+}
+
+void UIScriptController::platformSetDidDismissForcePressPreviewCallback()
+{
+}
 
 void UIScriptController::platformSetWillBeginZoomingCallback()
 {
index 085a7ca..af60950 100644 (file)
@@ -85,6 +85,12 @@ public:
 
     void setDidEndFormControlInteractionCallback(JSValueRef);
     JSValueRef didEndFormControlInteractionCallback() const;
+    
+    void setDidShowForcePressPreviewCallback(JSValueRef);
+    JSValueRef didShowForcePressPreviewCallback() const;
+    
+    void setDidDismissForcePressPreviewCallback(JSValueRef);
+    JSValueRef didDismissForcePressPreviewCallback() const;
 
     void setWillBeginZoomingCallback(JSValueRef);
     JSValueRef willBeginZoomingCallback() const;
@@ -118,6 +124,8 @@ private:
 
     void platformSetDidStartFormControlInteractionCallback();
     void platformSetDidEndFormControlInteractionCallback();
+    void platformSetDidShowForcePressPreviewCallback();
+    void platformSetDidDismissForcePressPreviewCallback();
     void platformSetWillBeginZoomingCallback();
     void platformSetDidEndZoomingCallback();
     void platformSetDidShowKeyboardCallback();
index 0f28c28..e5d9b4a 100644 (file)
@@ -33,6 +33,8 @@
 
 @property (nonatomic, copy) void (^didStartFormControlInteractionCallback)(void);
 @property (nonatomic, copy) void (^didEndFormControlInteractionCallback)(void);
+@property (nonatomic, copy) void (^didShowForcePressPreviewCallback)(void);
+@property (nonatomic, copy) void (^didDismissForcePressPreviewCallback)(void);
 @property (nonatomic, copy) void (^willBeginZoomingCallback)(void);
 @property (nonatomic, copy) void (^didEndZoomingCallback)(void);
 @property (nonatomic, copy) void (^didShowKeyboardCallback)(void);
index fa7a2ef..d86358d 100644 (file)
@@ -75,6 +75,8 @@
 
     self.didStartFormControlInteractionCallback = nil;
     self.didEndFormControlInteractionCallback = nil;
+    self.didShowForcePressPreviewCallback = nil;
+    self.didDismissForcePressPreviewCallback = nil;
     self.willBeginZoomingCallback = nil;
     self.didEndZoomingCallback = nil;
     self.didShowKeyboardCallback = nil;
         self.didEndFormControlInteractionCallback();
 }
 
+- (void)_didShowForcePressPreview
+{
+    if (self.didShowForcePressPreviewCallback)
+        self.didShowForcePressPreviewCallback();
+}
+
+- (void)_didDismissForcePressPreview
+{
+    if (self.didDismissForcePressPreviewCallback)
+        self.didDismissForcePressPreviewCallback();
+}
+
 - (void)zoomToScale:(double)scale animated:(BOOL)animated completionHandler:(void (^)(void))completionHandler
 {
     ASSERT(!self.zoomToScaleCompletionHandler);
index f6214da..a888699 100644 (file)
@@ -367,6 +367,26 @@ void UIScriptController::platformSetDidEndFormControlInteractionCallback()
         m_context->fireCallback(CallbackTypeDidEndFormControlInteraction);
     };
 }
+    
+void UIScriptController::platformSetDidShowForcePressPreviewCallback()
+{
+    TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
+    webView.didShowForcePressPreviewCallback = ^ {
+        if (!m_context)
+            return;
+        m_context->fireCallback(CallbackTypeDidShowForcePressPreview);
+    };
+}
+
+void UIScriptController::platformSetDidDismissForcePressPreviewCallback()
+{
+    TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
+    webView.didDismissForcePressPreviewCallback = ^ {
+        if (!m_context)
+            return;
+        m_context->fireCallback(CallbackTypeDidEndFormControlInteraction);
+    };
+}
 
 void UIScriptController::platformSetWillBeginZoomingCallback()
 {