Title: [237786] trunk/Tools
Revision
237786
Author
wenson_hs...@apple.com
Date
2018-11-04 13:19:44 -0800 (Sun, 04 Nov 2018)

Log Message

[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.

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (237785 => 237786)


--- trunk/Tools/ChangeLog	2018-11-04 16:38:36 UTC (rev 237785)
+++ trunk/Tools/ChangeLog	2018-11-04 21:19:44 UTC (rev 237786)
@@ -1,3 +1,57 @@
+2018-11-04  Wenson Hsieh  <wenson_hs...@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.carl...@apple.com>
 
         [MediaStream] User should not be prompted again after denying getDisplayMedia request

Modified: trunk/Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm (237785 => 237786)


--- trunk/Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm	2018-11-04 16:38:36 UTC (rev 237785)
+++ trunk/Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm	2018-11-04 21:19:44 UTC (rev 237786)
@@ -394,6 +394,10 @@
     return false;
 }
 
+void UIScriptController::overridePreference(JSStringRef, JSStringRef)
+{
 }
 
+}
+
 #endif // PLATFORM(IOS_FAMILY)

Modified: trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp (237785 => 237786)


--- trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp	2018-11-04 16:38:36 UTC (rev 237785)
+++ trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp	2018-11-04 21:19:44 UTC (rev 237786)
@@ -512,14 +512,14 @@
     return false;
 }
 
+void UIScriptController::overridePreference(JSStringRef, JSStringRef)
+{
+}
+
 #endif // !PLATFORM(COCOA)
 
 #if !PLATFORM(MAC)
 
-void UIScriptController::overridePreference(JSStringRef, JSStringRef)
-{
-}
-
 void UIScriptController::replaceTextAtRange(JSStringRef, int, int)
 {
 }

Modified: trunk/Tools/WebKitTestRunner/UIScriptControllerCocoa.mm (237785 => 237786)


--- trunk/Tools/WebKitTestRunner/UIScriptControllerCocoa.mm	2018-11-04 16:38:36 UTC (rev 237785)
+++ trunk/Tools/WebKitTestRunner/UIScriptControllerCocoa.mm	2018-11-04 21:19:44 UTC (rev 237786)
@@ -27,8 +27,11 @@
 #import "UIScriptController.h"
 
 #import "PlatformWebView.h"
+#import "StringFunctions.h"
 #import "TestController.h"
 #import "TestRunnerWKWebView.h"
+#import "UIScriptContext.h"
+#import <_javascript_Core/_javascript_Core.h>
 #import <WebKit/WKWebViewPrivate.h>
 
 namespace WTR {
@@ -49,4 +52,116 @@
 #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

Modified: trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm (237785 => 237786)


--- trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm	2018-11-04 16:38:36 UTC (rev 237785)
+++ trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm	2018-11-04 21:19:44 UTC (rev 237786)
@@ -60,17 +60,6 @@
         [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 @@
     [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 @@
     [[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();

Modified: trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm (237785 => 237786)


--- trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm	2018-11-04 16:38:36 UTC (rev 237785)
+++ trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm	2018-11-04 21:19:44 UTC (rev 237786)
@@ -49,17 +49,6 @@
     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 @@
 #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::findString(JSStringRef, unsigned long options, unsigned long maxCount)
-{
-}
-
 bool UIScriptController::isShowingDataListSuggestions() const
 {
 #if WK_API_ENABLED
@@ -177,42 +134,6 @@
     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 @@
     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
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to