[Cocoa] Fold common UIScriptController functionality on macOS and iOS into UIScriptCo...
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 4 Nov 2018 21:19:44 +0000 (21:19 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 4 Nov 2018 21:19:44 +0000 (21:19 +0000)
https://bugs.webkit.org/show_bug.cgi?id=191231

Reviewed by Simon Fraser.

Moves some UIScriptController method implementations specific to iOS and macOS into UIScriptControllerCocoa, so
it can be shared between iOS-family and macOS platforms. See below for more details.

No change in behavior.

* DumpRenderTree/ios/UIScriptControllerIOS.mm:
(WTR::UIScriptController::overridePreference):

Add a method stub for DumpRenderTree.

* TestRunnerShared/UIScriptContext/UIScriptController.cpp:
* WebKitTestRunner/UIScriptControllerCocoa.mm:
(WTR::UIScriptController::doAsyncTask):
(WTR::UIScriptController::setShareSheetCompletesImmediatelyWithResolution):

Unify these method implementations.

(WTR::UIScriptController::removeViewFromWindow):
(WTR::UIScriptController::addViewToWindow):

Move the macOS implementation to UIScriptControllerCocoa. On iOS, this method currently only adds the web view
to the window, and does not attempt to invoke the given completion block; additionally, invoking the completion
block after a presentation update (as done on macOS) causes pageoverlay/overlay-remove-reinsert-view.html to
begin failing consistently. This patch does not attempt to change behavior, but adds a FIXME describing this.

(WTR::UIScriptController::overridePreference):
(WTR::UIScriptController::findString):
(WTR::UIScriptController::contentsOfUserInterfaceItem const):

Move these from UIScriptControllerMac to UIScriptControllerCocoa, so that it is now implemented on iOS as well.

* WebKitTestRunner/ios/UIScriptControllerIOS.mm:
(WTR::UIScriptController::doAsyncTask): Deleted.
(WTR::UIScriptController::setShareSheetCompletesImmediatelyWithResolution): Deleted.
(WTR::UIScriptController::contentsOfUserInterfaceItem const): Deleted.
(WTR::UIScriptController::findString): Deleted.
(WTR::UIScriptController::removeViewFromWindow): Deleted.
(WTR::UIScriptController::addViewToWindow): Deleted.
* WebKitTestRunner/mac/UIScriptControllerMac.mm:
(WTR::UIScriptController::doAsyncTask): Deleted.
(WTR::UIScriptController::contentsOfUserInterfaceItem const): Deleted.
(WTR::UIScriptController::overridePreference): Deleted.
(WTR::UIScriptController::findString): Deleted.
(WTR::UIScriptController::removeViewFromWindow): Deleted.
(WTR::UIScriptController::addViewToWindow): Deleted.
(WTR::UIScriptController::setShareSheetCompletesImmediatelyWithResolution): Deleted.

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

Tools/ChangeLog
Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm
Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp
Tools/WebKitTestRunner/UIScriptControllerCocoa.mm
Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm
Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm

index f2b0954..a86f9cb 100644 (file)
@@ -1,3 +1,57 @@
+2018-11-04  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [Cocoa] Fold common UIScriptController functionality on macOS and iOS into UIScriptControllerCocoa.mm
+        https://bugs.webkit.org/show_bug.cgi?id=191231
+
+        Reviewed by Simon Fraser.
+
+        Moves some UIScriptController method implementations specific to iOS and macOS into UIScriptControllerCocoa, so
+        it can be shared between iOS-family and macOS platforms. See below for more details.
+
+        No change in behavior.
+
+        * DumpRenderTree/ios/UIScriptControllerIOS.mm:
+        (WTR::UIScriptController::overridePreference):
+
+        Add a method stub for DumpRenderTree.
+
+        * TestRunnerShared/UIScriptContext/UIScriptController.cpp:
+        * WebKitTestRunner/UIScriptControllerCocoa.mm:
+        (WTR::UIScriptController::doAsyncTask):
+        (WTR::UIScriptController::setShareSheetCompletesImmediatelyWithResolution):
+
+        Unify these method implementations.
+
+        (WTR::UIScriptController::removeViewFromWindow):
+        (WTR::UIScriptController::addViewToWindow):
+
+        Move the macOS implementation to UIScriptControllerCocoa. On iOS, this method currently only adds the web view
+        to the window, and does not attempt to invoke the given completion block; additionally, invoking the completion
+        block after a presentation update (as done on macOS) causes pageoverlay/overlay-remove-reinsert-view.html to
+        begin failing consistently. This patch does not attempt to change behavior, but adds a FIXME describing this.
+
+        (WTR::UIScriptController::overridePreference):
+        (WTR::UIScriptController::findString):
+        (WTR::UIScriptController::contentsOfUserInterfaceItem const):
+
+        Move these from UIScriptControllerMac to UIScriptControllerCocoa, so that it is now implemented on iOS as well.
+
+        * WebKitTestRunner/ios/UIScriptControllerIOS.mm:
+        (WTR::UIScriptController::doAsyncTask): Deleted.
+        (WTR::UIScriptController::setShareSheetCompletesImmediatelyWithResolution): Deleted.
+        (WTR::UIScriptController::contentsOfUserInterfaceItem const): Deleted.
+        (WTR::UIScriptController::findString): Deleted.
+        (WTR::UIScriptController::removeViewFromWindow): Deleted.
+        (WTR::UIScriptController::addViewToWindow): Deleted.
+        * WebKitTestRunner/mac/UIScriptControllerMac.mm:
+        (WTR::UIScriptController::doAsyncTask): Deleted.
+        (WTR::UIScriptController::contentsOfUserInterfaceItem const): Deleted.
+        (WTR::UIScriptController::overridePreference): Deleted.
+        (WTR::UIScriptController::findString): Deleted.
+        (WTR::UIScriptController::removeViewFromWindow): Deleted.
+        (WTR::UIScriptController::addViewToWindow): Deleted.
+        (WTR::UIScriptController::setShareSheetCompletesImmediatelyWithResolution): Deleted.
+
 2018-11-04  Eric Carlson  <eric.carlson@apple.com>
 
         [MediaStream] User should not be prompted again after denying getDisplayMedia request
index 109010d..ece78ca 100644 (file)
@@ -394,6 +394,10 @@ bool UIScriptController::isShowingDataListSuggestions() const
     return false;
 }
 
+void UIScriptController::overridePreference(JSStringRef, JSStringRef)
+{
+}
+
 }
 
 #endif // PLATFORM(IOS_FAMILY)
index 6e25be3..e459c6d 100644 (file)
@@ -512,14 +512,14 @@ bool UIScriptController::isShowingDataListSuggestions() const
     return false;
 }
 
-#endif // !PLATFORM(COCOA)
-
-#if !PLATFORM(MAC)
-
 void UIScriptController::overridePreference(JSStringRef, JSStringRef)
 {
 }
 
+#endif // !PLATFORM(COCOA)
+
+#if !PLATFORM(MAC)
+
 void UIScriptController::replaceTextAtRange(JSStringRef, int, int)
 {
 }
index 7f5b6c5..3aabc34 100644 (file)
 #import "UIScriptController.h"
 
 #import "PlatformWebView.h"
+#import "StringFunctions.h"
 #import "TestController.h"
 #import "TestRunnerWKWebView.h"
+#import "UIScriptContext.h"
+#import <JavaScriptCore/JavaScriptCore.h>
 #import <WebKit/WKWebViewPrivate.h>
 
 namespace WTR {
@@ -49,4 +52,116 @@ void UIScriptController::resignFirstResponder()
 #endif
 }
 
+void UIScriptController::doAsyncTask(JSValueRef callback)
+{
+    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
+
+    dispatch_async(dispatch_get_main_queue(), ^{
+        if (!m_context)
+            return;
+        m_context->asyncTaskComplete(callbackID);
+    });
+}
+
+void UIScriptController::setShareSheetCompletesImmediatelyWithResolution(bool resolved)
+{
+#if WK_API_ENABLED
+    TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
+    [webView _setShareSheetCompletesImmediatelyWithResolutionForTesting:resolved];
+#else
+    UNUSED_PARAM(resolved);
+#endif
+}
+
+void UIScriptController::removeViewFromWindow(JSValueRef callback)
+{
+#if WK_API_ENABLED
+    // FIXME: On iOS, we never invoke the completion callback that's passed in. Fixing this causes the layout
+    // test pageoverlay/overlay-remove-reinsert-view.html to start failing consistently on iOS. It seems like
+    // this warrants some more investigation.
+#if PLATFORM(MAC)
+    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
+#else
+    UNUSED_PARAM(callback);
+#endif
+
+    auto* mainWebView = TestController::singleton().mainWebView();
+    mainWebView->removeFromWindow();
+
+#if PLATFORM(MAC)
+    [mainWebView->platformView() _doAfterNextPresentationUpdate:^{
+        if (!m_context)
+            return;
+        m_context->asyncTaskComplete(callbackID);
+    }];
+#endif // PLATFORM(MAC)
+#else
+    UNUSED_PARAM(callback);
+#endif
+}
+
+void UIScriptController::addViewToWindow(JSValueRef callback)
+{
+#if WK_API_ENABLED
+#if PLATFORM(MAC)
+    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
+#else
+    UNUSED_PARAM(callback);
+#endif
+
+    auto* mainWebView = TestController::singleton().mainWebView();
+    mainWebView->addToWindow();
+
+#if PLATFORM(MAC)
+    [mainWebView->platformView() _doAfterNextPresentationUpdate:^{
+        if (!m_context)
+            return;
+        m_context->asyncTaskComplete(callbackID);
+    }];
+#endif // PLATFORM(MAC)
+#else
+    UNUSED_PARAM(callback);
+#endif
+}
+
+void UIScriptController::overridePreference(JSStringRef preferenceRef, JSStringRef valueRef)
+{
+#if WK_API_ENABLED
+    TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
+    WKPreferences *preferences = webView.configuration.preferences;
+
+    String preference = toWTFString(toWK(preferenceRef));
+    String value = toWTFString(toWK(valueRef));
+    if (preference == "WebKitMinimumFontSize")
+        preferences.minimumFontSize = value.toDouble();
+#else
+    UNUSED_PARAM(preferenceRef);
+    UNUSED_PARAM(valueRef);
+#endif
+}
+
+void UIScriptController::findString(JSStringRef string, unsigned long options, unsigned long maxCount)
+{
+#if WK_API_ENABLED
+    TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
+    [webView _findString:toWTFString(toWK(string)) options:options maxCount:maxCount];
+#else
+    UNUSED_PARAM(string);
+    UNUSED_PARAM(options);
+    UNUSED_PARAM(maxCount);
+#endif
+}
+
+JSObjectRef UIScriptController::contentsOfUserInterfaceItem(JSStringRef interfaceItem) const
+{
+#if WK_API_ENABLED
+    TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
+    NSDictionary *contentDictionary = [webView _contentsOfUserInterfaceItem:toWTFString(toWK(interfaceItem))];
+    return JSValueToObject(m_context->jsContext(), [JSValue valueWithObject:contentDictionary inContext:[JSContext contextWithJSGlobalContextRef:m_context->jsContext()]].JSValueRef, nullptr);
+#else
+    UNUSED_PARAM(interfaceItem);
+    return nullptr;
+#endif
+}
+
 } // namespace WTR
index 5bf0f6f..f52f9a3 100644 (file)
@@ -60,17 +60,6 @@ void UIScriptController::checkForOutstandingCallbacks()
         [NSException raise:@"WebKitTestRunnerTestProblem" format:@"The test completed before all synthesized events had been handled. Perhaps you're calling notifyDone() too early?"];
 }
 
-void UIScriptController::doAsyncTask(JSValueRef callback)
-{
-    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
-
-    dispatch_async(dispatch_get_main_queue(), ^{
-        if (!m_context)
-            return;
-        m_context->asyncTaskComplete(callbackID);
-    });
-}
-
 void UIScriptController::doAfterPresentationUpdate(JSValueRef callback)
 {
     TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
@@ -410,19 +399,6 @@ void UIScriptController::setTimePickerValue(long hour, long minute)
     [webView setTimePickerValueToHour:hour minute:minute];
 }
 
-void UIScriptController::setShareSheetCompletesImmediatelyWithResolution(bool resolved)
-{
-    TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
-    [webView _setShareSheetCompletesImmediatelyWithResolutionForTesting:resolved];
-}
-    
-JSObjectRef UIScriptController::contentsOfUserInterfaceItem(JSStringRef interfaceItem) const
-{
-    TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
-    NSDictionary *contentDictionary = [webView _contentsOfUserInterfaceItem:toWTFString(toWK(interfaceItem))];
-    return JSValueToObject(m_context->jsContext(), [JSValue valueWithObject:contentDictionary inContext:[JSContext contextWithJSGlobalContextRef:m_context->jsContext()]].JSValueRef, nullptr);
-}
-
 static CGPoint contentOffsetBoundedInValidRange(UIScrollView *scrollView, CGPoint contentOffset)
 {
     UIEdgeInsets contentInsets = scrollView.contentInset;
@@ -637,22 +613,6 @@ void UIScriptController::simulateRotationLikeSafari(DeviceOrientation* orientati
     [[UIDevice currentDevice] setOrientation:toUIDeviceOrientation(orientation) animated:YES];
 }
 
-void UIScriptController::findString(JSStringRef string, unsigned long options, unsigned long maxCount)
-{
-    TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
-    [webView _findString:toWTFString(toWK(string)) options:options maxCount:maxCount];
-}
-
-void UIScriptController::removeViewFromWindow(JSValueRef callback)
-{
-    TestController::singleton().mainWebView()->removeFromWindow();
-}
-
-void UIScriptController::addViewToWindow(JSValueRef callback)
-{
-    TestController::singleton().mainWebView()->addToWindow();
-}
-
 void UIScriptController::platformSetDidStartFormControlInteractionCallback()
 {
     TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
index 2c2b5d1..3333b46 100644 (file)
@@ -49,17 +49,6 @@ NSString *nsString(JSStringRef string)
     return CFBridgingRelease(JSStringCopyCFString(kCFAllocatorDefault, string));
 }
 
-void UIScriptController::doAsyncTask(JSValueRef callback)
-{
-    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
-
-    dispatch_async(dispatch_get_main_queue(), ^{
-        if (!m_context)
-            return;
-        m_context->asyncTaskComplete(callbackID);
-    });
-}
-
 void UIScriptController::doAfterPresentationUpdate(JSValueRef callback)
 {
     return doAsyncTask(callback);
@@ -125,34 +114,6 @@ void UIScriptController::simulateAccessibilitySettingsChangeNotification(JSValue
 #endif
 }
 
-JSObjectRef UIScriptController::contentsOfUserInterfaceItem(JSStringRef interfaceItem) const
-{
-#if WK_API_ENABLED
-    TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
-    NSDictionary *contentDictionary = [webView _contentsOfUserInterfaceItem:toWTFString(toWK(interfaceItem))];
-    return JSValueToObject(m_context->jsContext(), [JSValue valueWithObject:contentDictionary inContext:[JSContext contextWithJSGlobalContextRef:m_context->jsContext()]].JSValueRef, nullptr);
-#else
-    UNUSED_PARAM(interfaceItem);
-    return nullptr;
-#endif
-}
-
-void UIScriptController::overridePreference(JSStringRef preferenceRef, JSStringRef valueRef)
-{
-#if WK_API_ENABLED
-    TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
-    WKPreferences *preferences = webView.configuration.preferences;
-
-    String preference = toWTFString(toWK(preferenceRef));
-    String value = toWTFString(toWK(valueRef));
-    if (preference == "WebKitMinimumFontSize")
-        preferences.minimumFontSize = value.toDouble();
-#else
-    UNUSED_PARAM(preferenceRef);
-    UNUSED_PARAM(valueRef);
-#endif
-}
-
 void UIScriptController::simulateRotation(DeviceOrientation*, JSValueRef)
 {
 }
@@ -161,10 +122,6 @@ void UIScriptController::simulateRotationLikeSafari(DeviceOrientation*, JSValueR
 {
 }
 
-void UIScriptController::findString(JSStringRef, unsigned long options, unsigned long maxCount)
-{
-}
-
 bool UIScriptController::isShowingDataListSuggestions() const
 {
 #if WK_API_ENABLED
@@ -177,42 +134,6 @@ bool UIScriptController::isShowingDataListSuggestions() const
     return false;
 }
 
-void UIScriptController::removeViewFromWindow(JSValueRef callback)
-{
-#if WK_API_ENABLED
-    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
-
-    auto* mainWebView = TestController::singleton().mainWebView();
-    mainWebView->removeFromWindow();
-
-    [mainWebView->platformView() _doAfterNextPresentationUpdate: ^ {
-        if (!m_context)
-            return;
-        m_context->asyncTaskComplete(callbackID);
-    }];
-#else
-    UNUSED_PARAM(callback);
-#endif
-}
-
-void UIScriptController::addViewToWindow(JSValueRef callback)
-{
-#if WK_API_ENABLED
-    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
-
-    auto* mainWebView = TestController::singleton().mainWebView();
-    mainWebView->addToWindow();
-
-    [mainWebView->platformView() _doAfterNextPresentationUpdate: ^ {
-        if (!m_context)
-            return;
-        m_context->asyncTaskComplete(callbackID);
-    }];
-#else
-    UNUSED_PARAM(callback);
-#endif
-}
-
 static void playBackEvents(UIScriptContext *context, NSString *eventStream, JSValueRef callback)
 {
     NSError *error = nil;
@@ -270,14 +191,4 @@ bool UIScriptController::isWindowContentViewFirstResponder() const
     return [window firstResponder] == [window contentView];
 }
 
-void UIScriptController::setShareSheetCompletesImmediatelyWithResolution(bool resolved)
-{
-#if WK_API_ENABLED
-    TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
-    [webView _setShareSheetCompletesImmediatelyWithResolutionForTesting:resolved];
-#else
-    UNUSED_PARAM(resolved);
-#endif
-}
-
 } // namespace WTR