Title: [285799] trunk
Revision
285799
Author
beid...@apple.com
Date
2021-11-14 23:17:34 -0800 (Sun, 14 Nov 2021)

Log Message

Get daemon API ready to work in the iOS simulator (starting with WebPushD)
https://bugs.webkit.org/show_bug.cgi?id=232982

Reviewed by Geoff Garen.

Source/WebKit:

Move all the "enable Notifications" SPI from Mac-only to cross platform:
* UIProcess/API/Cocoa/WKPreferences.mm:
(-[WKPreferences _setNotificationsEnabled:]):
(-[WKPreferences _notificationsEnabled]):
* UIProcess/API/Cocoa/WKPreferencesPrivate.h:
* UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
* UIProcess/Cocoa/UIDelegate.h:
* UIProcess/Cocoa/UIDelegate.mm:
(WebKit::UIDelegate::setDelegate):
(WebKit::UIDelegate::UIClient::decidePolicyForNotificationPermissionRequest):

* WebKit.xcodeproj/project.pbxproj: Add a build phase script to install the daemon executables
  inside a Daemons directory within the built WebKit.framework for engineering builds.
* webpushd/WebPushDaemon.mm:

Tools:

To get this working we needed to:
- Have the Daemons installed in a simulator-runtime-root-visible path
- Point the OSLaunchDJob plist to the simulator-relative path, not Mac-relative
- Solve the "How do I kill existing instances to run a clean test?" problem within the simulator.

This patch does those things.

* TestWebKitAPI/Configurations/TestWebKitAPI-iOS.entitlements:
* TestWebKitAPI/Configurations/TestWebKitAPI.xcconfig:

* TestWebKitAPI/Tests/WebKitCocoa/WebPushDaemon.mm:
(TestWebKitAPI::testWebPushDaemonPList):
(TestWebKitAPI::setUpTestWebPushD):
(TestWebKitAPI::cleanUpTestWebPushD):

* TestWebKitAPI/cocoa/DaemonTestUtilities.h:
* TestWebKitAPI/cocoa/DaemonTestUtilities.mm:
(TestWebKitAPI::registerPlistWithLaunchD):
(TestWebKitAPI::pidOfFirstDaemonInstance):
(TestWebKitAPI::killFirstInstanceOfDaemon):

WebKitLibraries:

* WebKitPrivateFrameworkStubs/iOS/15/AppServerSupport.framework/AppServerSupport.tbd: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (285798 => 285799)


--- trunk/Source/WebKit/ChangeLog	2021-11-15 04:22:34 UTC (rev 285798)
+++ trunk/Source/WebKit/ChangeLog	2021-11-15 07:17:34 UTC (rev 285799)
@@ -1,3 +1,25 @@
+2021-11-14  Brady Eidson  <beid...@apple.com>
+
+        Get daemon API ready to work in the iOS simulator (starting with WebPushD)
+        https://bugs.webkit.org/show_bug.cgi?id=232982
+
+        Reviewed by Geoff Garen.
+
+        Move all the "enable Notifications" SPI from Mac-only to cross platform:
+        * UIProcess/API/Cocoa/WKPreferences.mm:
+        (-[WKPreferences _setNotificationsEnabled:]):
+        (-[WKPreferences _notificationsEnabled]):
+        * UIProcess/API/Cocoa/WKPreferencesPrivate.h:
+        * UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
+        * UIProcess/Cocoa/UIDelegate.h:
+        * UIProcess/Cocoa/UIDelegate.mm:
+        (WebKit::UIDelegate::setDelegate):
+        (WebKit::UIDelegate::UIClient::decidePolicyForNotificationPermissionRequest):
+
+        * WebKit.xcodeproj/project.pbxproj: Add a build phase script to install the daemon executables
+          inside a Daemons directory within the built WebKit.framework for engineering builds.
+        * webpushd/WebPushDaemon.mm:
+
 2021-11-14  Fujii Hironori  <hironori.fu...@sony.com>
 
         [GraphicsLayerWC] Incorrect compositing debug border color

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKPreferences.mm (285798 => 285799)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKPreferences.mm	2021-11-15 04:22:34 UTC (rev 285798)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKPreferences.mm	2021-11-15 07:17:34 UTC (rev 285799)
@@ -1163,16 +1163,6 @@
     return _preferences->standardFontFamily();
 }
 
-- (void)_setNotificationsEnabled:(BOOL)enabled
-{
-    _preferences->setNotificationsEnabled(enabled);
-}
-
-- (BOOL)_notificationsEnabled
-{
-    return _preferences->notificationsEnabled();
-}
-
 - (void)_setBackspaceKeyNavigationEnabled:(BOOL)enabled
 {
     _preferences->setBackspaceKeyNavigationEnabled(enabled);
@@ -1564,6 +1554,16 @@
     _preferences->setAccessHandleEnabled(accessHandleEnabled);
 }
 
+- (void)_setNotificationsEnabled:(BOOL)enabled
+{
+    _preferences->setNotificationsEnabled(enabled);
+}
+
+- (BOOL)_notificationsEnabled
+{
+    return _preferences->notificationsEnabled();
+}
+
 @end
 
 

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKPreferencesPrivate.h (285798 => 285799)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKPreferencesPrivate.h	2021-11-15 04:22:34 UTC (rev 285798)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKPreferencesPrivate.h	2021-11-15 07:17:34 UTC (rev 285799)
@@ -176,6 +176,7 @@
 @property (nonatomic, setter=_setFileSystemAccessEnabled:) BOOL _fileSystemAccessEnabled WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 @property (nonatomic, setter=_setStorageAPIEnabled:) BOOL _storageAPIEnabled WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 @property (nonatomic, setter=_setAccessHandleEnabled:) BOOL _accessHandleEnabled WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+@property (nonatomic, setter=_setNotificationsEnabled:) BOOL _notificationsEnabled WK_API_AVAILABLE(macos(10.13.4), ios(WK_IOS_TBA));
 
 #if !TARGET_OS_IPHONE
 @property (nonatomic, setter=_setWebGLEnabled:) BOOL _webGLEnabled WK_API_AVAILABLE(macos(10.13.4));
@@ -200,7 +201,6 @@
 @property (nonatomic, setter=_setPlugInSnapshottingEnabled:) BOOL _plugInSnapshottingEnabled WK_API_AVAILABLE(macos(10.13.4));
 @property (nonatomic, setter=_setViewGestureDebuggingEnabled:) BOOL _viewGestureDebuggingEnabled WK_API_AVAILABLE(macos(10.13.4));
 @property (nonatomic, setter=_setStandardFontFamily:) NSString *_standardFontFamily WK_API_AVAILABLE(macos(10.13.4));
-@property (nonatomic, setter=_setNotificationsEnabled:) BOOL _notificationsEnabled WK_API_AVAILABLE(macos(10.13.4));
 @property (nonatomic, setter=_setBackspaceKeyNavigationEnabled:) BOOL _backspaceKeyNavigationEnabled WK_API_AVAILABLE(macos(10.13.4));
 @property (nonatomic, setter=_setAllowsInlineMediaPlayback:) BOOL _allowsInlineMediaPlayback WK_API_AVAILABLE(macos(10.14));
 @property (nonatomic, setter=_setApplePayEnabled:) BOOL _applePayEnabled WK_API_AVAILABLE(macos(10.14));

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h (285798 => 285799)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h	2021-11-15 04:22:34 UTC (rev 285798)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h	2021-11-15 07:17:34 UTC (rev 285799)
@@ -159,6 +159,7 @@
 - (void)_webViewDidDisableInspectorBrowserDomain:(WKWebView *)webView WK_API_AVAILABLE(macos(12.0), ios(15.0));
 
 - (void)_webView:(WKWebView *)webView startXRSessionWithCompletionHandler:(void (^)(id))completionHandler WK_API_AVAILABLE(macos(12.0), ios(15.0));
+- (void)_webView:(WKWebView *)webView requestNotificationPermissionForSecurityOrigin:(WKSecurityOrigin *)securityOrigin decisionHandler:(void (^)(BOOL))decisionHandler WK_API_AVAILABLE(macos(10.13.4));
 
 #if TARGET_OS_IPHONE
 
@@ -244,7 +245,6 @@
 - (CGFloat)_webViewFooterHeight:(WKWebView *)webView WK_API_AVAILABLE(macos(10.13.4));
 - (void)_webView:(WKWebView *)webView drawHeaderInRect:(CGRect)rect forPageWithTitle:(NSString *)title URL:(NSURL *)url WK_API_AVAILABLE(macos(10.13.4));
 - (void)_webView:(WKWebView *)webView drawFooterInRect:(CGRect)rect forPageWithTitle:(NSString *)title URL:(NSURL *)url WK_API_AVAILABLE(macos(10.13.4));
-- (void)_webView:(WKWebView *)webView requestNotificationPermissionForSecurityOrigin:(WKSecurityOrigin *)securityOrigin decisionHandler:(void (^)(BOOL))decisionHandler WK_API_AVAILABLE(macos(10.13.4));
 - (void)_webView:(WKWebView *)webview mouseDidMoveOverElement:(_WKHitTestResult *)hitTestResult withFlags:(NSEventModifierFlags)flags userInfo:(id <NSSecureCoding>)userInfo;
 - (void)_webView:(WKWebView *)webView didExceedBackgroundResourceLimitWhileInForeground:(_WKResourceLimit)limit WK_API_AVAILABLE(macos(10.13.4));
 - (void)_webView:(WKWebView *)webView setResizable:(BOOL)isResizable WK_API_AVAILABLE(macos(10.13.4));

Modified: trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h (285798 => 285799)


--- trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h	2021-11-15 04:22:34 UTC (rev 285798)
+++ trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h	2021-11-15 07:17:34 UTC (rev 285799)
@@ -105,6 +105,8 @@
         void didResignInputElementStrongPasswordAppearance(WebPageProxy&, API::Object*) final;
         bool takeFocus(WebPageProxy*, WKFocusDirection) final;
         void handleAutoplayEvent(WebPageProxy&, WebCore::AutoplayEvent, OptionSet<WebCore::AutoplayEventFlags>) final;
+        void decidePolicyForNotificationPermissionRequest(WebPageProxy&, API::SecurityOrigin&, CompletionHandler<void(bool allowed)>&&) final;
+
 #if PLATFORM(MAC)
         void showPage(WebPageProxy*) final;
         void focus(WebPageProxy*) final;
@@ -123,7 +125,6 @@
         void drawHeader(WebPageProxy&, WebFrameProxy&, WebCore::FloatRect&&) final;
         void drawFooter(WebPageProxy&, WebFrameProxy&, WebCore::FloatRect&&) final;
 
-        void decidePolicyForNotificationPermissionRequest(WebPageProxy&, API::SecurityOrigin&, CompletionHandler<void(bool allowed)>&&) final;
         void mouseDidMoveOverElement(WebPageProxy&, const WebHitTestResultData&, OptionSet<WebEvent::Modifier>, API::Object*);
         void didClickAutoFillButton(WebPageProxy&, API::Object*) final;
         void toolbarsAreVisible(WebPageProxy&, Function<void(bool)>&&) final;
@@ -215,7 +216,6 @@
         bool webViewDidExceedBackgroundResourceLimitWhileInForeground : 1;
         bool webViewSaveDataToFileSuggestedFilenameMimeTypeOriginatingURL : 1;
         bool webViewRunOpenPanelWithParametersInitiatedByFrameCompletionHandler : 1;
-        bool webViewRequestNotificationPermissionForSecurityOriginDecisionHandler : 1;
         bool webViewConfigurationForLocalInspector : 1;
         bool webViewDidAttachLocalInspector : 1;
         bool webViewWillCloseLocalInspector : 1;
@@ -267,6 +267,7 @@
 #if ENABLE(WEBXR) && PLATFORM(COCOA)
         bool webViewStartXRSessionWithCompletionHandler : 1;
 #endif
+        bool webViewRequestNotificationPermissionForSecurityOriginDecisionHandler : 1;
     } m_delegateMethods;
 };
 

Modified: trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm (285798 => 285799)


--- trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm	2021-11-15 04:22:34 UTC (rev 285798)
+++ trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm	2021-11-15 07:17:34 UTC (rev 285799)
@@ -138,7 +138,6 @@
     m_delegateMethods.webViewDidExceedBackgroundResourceLimitWhileInForeground = [delegate respondsToSelector:@selector(_webView:didExceedBackgroundResourceLimitWhileInForeground:)];
     m_delegateMethods.webViewSaveDataToFileSuggestedFilenameMimeTypeOriginatingURL = [delegate respondsToSelector:@selector(_webView:saveDataToFile:suggestedFilename:mimeType:originatingURL:)];
     m_delegateMethods.webViewRunOpenPanelWithParametersInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(webView:runOpenPanelWithParameters:initiatedByFrame:completionHandler:)];
-    m_delegateMethods.webViewRequestNotificationPermissionForSecurityOriginDecisionHandler = [delegate respondsToSelector:@selector(_webView:requestNotificationPermissionForSecurityOrigin:decisionHandler:)];
     m_delegateMethods.webViewConfigurationForLocalInspector = [delegate respondsToSelector:@selector(_webView:configurationForLocalInspector:)];
     m_delegateMethods.webViewDidAttachLocalInspector = [delegate respondsToSelector:@selector(_webView:didAttachLocalInspector:)];
     m_delegateMethods.webViewWillCloseLocalInspector = [delegate respondsToSelector:@selector(_webView:willCloseLocalInspector:)];
@@ -196,6 +195,7 @@
 #if ENABLE(WEBXR) && PLATFORM(COCOA)
     m_delegateMethods.webViewStartXRSessionWithCompletionHandler = [delegate respondsToSelector:@selector(_webView:startXRSessionWithCompletionHandler:)];
 #endif
+    m_delegateMethods.webViewRequestNotificationPermissionForSecurityOriginDecisionHandler = [delegate respondsToSelector:@selector(_webView:requestNotificationPermissionForSecurityOrigin:decisionHandler:)];
 }
 
 #if ENABLE(CONTEXT_MENUS)
@@ -619,6 +619,27 @@
     [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate->m_webView.get().get() handleAutoplayEvent:toWKAutoplayEvent(event) withFlags:toWKAutoplayEventFlags(flags)];
 }
 
+void UIDelegate::UIClient::decidePolicyForNotificationPermissionRequest(WebKit::WebPageProxy&, API::SecurityOrigin& securityOrigin, CompletionHandler<void(bool allowed)>&& completionHandler)
+{
+    if (!m_uiDelegate)
+        return completionHandler(false);
+
+    if (!m_uiDelegate->m_delegateMethods.webViewRequestNotificationPermissionForSecurityOriginDecisionHandler)
+        return completionHandler(false);
+
+    auto delegate = m_uiDelegate->m_delegate.get();
+    if (!delegate)
+        return completionHandler(false);
+
+    auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:requestNotificationPermissionForSecurityOrigin:decisionHandler:));
+    [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate->m_webView.get().get() requestNotificationPermissionForSecurityOrigin:wrapper(securityOrigin) decisionHandler:makeBlockPtr([completionHandler = WTFMove(completionHandler), checker = WTFMove(checker)] (BOOL result) mutable {
+        if (checker->completionHandlerHasBeenCalled())
+            return;
+        checker->didCallCompletionHandler();
+        completionHandler(result);
+    }).get()];
+}
+
 #if PLATFORM(MAC)
 bool UIDelegate::UIClient::canRunModal() const
 {
@@ -921,27 +942,6 @@
     [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate->m_webView.get().get() saveDataToFile:wrapper(data) suggestedFilename:suggestedFilename mimeType:mimeType originatingURL:originatingURL];
 }
 
-void UIDelegate::UIClient::decidePolicyForNotificationPermissionRequest(WebKit::WebPageProxy&, API::SecurityOrigin& securityOrigin, CompletionHandler<void(bool allowed)>&& completionHandler)
-{
-    if (!m_uiDelegate)
-        return completionHandler(false);
-
-    if (!m_uiDelegate->m_delegateMethods.webViewRequestNotificationPermissionForSecurityOriginDecisionHandler)
-        return completionHandler(false);
-    
-    auto delegate = m_uiDelegate->m_delegate.get();
-    if (!delegate)
-        return completionHandler(false);
-
-    auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:requestNotificationPermissionForSecurityOrigin:decisionHandler:));
-    [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate->m_webView.get().get() requestNotificationPermissionForSecurityOrigin:wrapper(securityOrigin) decisionHandler:makeBlockPtr([completionHandler = WTFMove(completionHandler), checker = WTFMove(checker)] (BOOL result) mutable {
-        if (checker->completionHandlerHasBeenCalled())
-            return;
-        checker->didCallCompletionHandler();
-        completionHandler(result);
-    }).get()];
-}
-
 Ref<API::InspectorConfiguration> UIDelegate::UIClient::configurationForLocalInspector(WebPageProxy&, WebInspectorUIProxy& inspector)
 {
     if (!m_uiDelegate)

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (285798 => 285799)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2021-11-15 04:22:34 UTC (rev 285798)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2021-11-15 07:17:34 UTC (rev 285799)
@@ -13238,6 +13238,7 @@
 				1D12CC4E2414265300FDA0A3 /* Copy Feature Flags Plist */,
 				5379C7AC21E5288500E4A8F6 /* Check .xcfilelists */,
 				933170072234674500B32554 /* Create symlinks to XPC services for engineering builds */,
+				512B81CA273CAFBE00D87D49 /* Create symlinks to Daemons for engineering builds */,
 				0FB94836239F31B700926A8F /* Copy Testing Headers */,
 				DFD03A29270D5F57001A996E /* Copy Daemon Plists */,
 			);
@@ -13731,6 +13732,24 @@
 			shellPath = /bin/sh;
 			shellScript = "Scripts/process-entitlements.sh\n";
 		};
+		512B81CA273CAFBE00D87D49 /* Create symlinks to Daemons for engineering builds */ = {
+			isa = PBXShellScriptBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+			);
+			inputFileListPaths = (
+			);
+			inputPaths = (
+			);
+			name = "Create symlinks to Daemons for engineering builds";
+			outputFileListPaths = (
+			);
+			outputPaths = (
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+			shellPath = /bin/sh;
+			shellScript = "if [[ \"${DEPLOYMENT_LOCATION}\" == \"YES\" ]]; then\n    exit\nfi\n\n# If we move the Mac Daemons path to WebKit.framework/Versions/A/Daemons,\n# in addition to a Mac-specific plists, the Mac paths below have to be updated as well.\nif [[ ${WK_PLATFORM_NAME} != \"macosx\" ]]; then\n    DAEMONS_PATH=\"${BUILT_PRODUCTS_DIR}/WebKit.framework/Daemons\"\n    BUILT_PRODUCTS_DIR_RELATIVE_PATH_FROM_DAEMONS=\"../..\"\nelse\n    DAEMONS_PATH=\"${BUILT_PRODUCTS_DIR}/WebKit.framework/Daemons\"\n    BUILT_PRODUCTS_DIR_RELATIVE_PATH_FROM_DAEMONS=\"../..\"\nfi\n\nmkdir -p \"${DAEMONS_PATH}\"\nln -sFh \"${BUILT_PRODUCTS_DIR_RELATIVE_PATH_FROM_DAEMONS}/webpushd\" \"${DAEMONS_PATH}/webpushd\"\nln -sFh \"${BUILT_PRODUCTS_DIR_RELATIVE_PATH_FROM_DAEMONS}/adattributiond\" \"${DAEMONS_PATH}/adattributiond\"\n";
+		};
 		5325BDD221DFF47C00A0DEE1 /* ShellScript */ = {
 			isa = PBXShellScriptBuildPhase;
 			buildActionMask = 2147483647;

Modified: trunk/Tools/ChangeLog (285798 => 285799)


--- trunk/Tools/ChangeLog	2021-11-15 04:22:34 UTC (rev 285798)
+++ trunk/Tools/ChangeLog	2021-11-15 07:17:34 UTC (rev 285799)
@@ -1,3 +1,31 @@
+2021-11-14  Brady Eidson  <beid...@apple.com>
+
+        Get daemon API ready to work in the iOS simulator (starting with WebPushD)
+        https://bugs.webkit.org/show_bug.cgi?id=232982
+
+        Reviewed by Geoff Garen.
+
+        To get this working we needed to:
+        - Have the Daemons installed in a simulator-runtime-root-visible path
+        - Point the OSLaunchDJob plist to the simulator-relative path, not Mac-relative
+        - Solve the "How do I kill existing instances to run a clean test?" problem within the simulator.
+        
+        This patch does those things.
+        
+        * TestWebKitAPI/Configurations/TestWebKitAPI-iOS.entitlements:
+        * TestWebKitAPI/Configurations/TestWebKitAPI.xcconfig:
+        
+        * TestWebKitAPI/Tests/WebKitCocoa/WebPushDaemon.mm:
+        (TestWebKitAPI::testWebPushDaemonPList):
+        (TestWebKitAPI::setUpTestWebPushD):
+        (TestWebKitAPI::cleanUpTestWebPushD):
+        
+        * TestWebKitAPI/cocoa/DaemonTestUtilities.h:
+        * TestWebKitAPI/cocoa/DaemonTestUtilities.mm:
+        (TestWebKitAPI::registerPlistWithLaunchD):
+        (TestWebKitAPI::pidOfFirstDaemonInstance):
+        (TestWebKitAPI::killFirstInstanceOfDaemon):
+
 2021-11-13  Simon Fraser  <simon.fra...@apple.com>
 
         Implement UIScriptController.sendEventStream() for DumpRenderTree

Modified: trunk/Tools/TestWebKitAPI/Configurations/TestWebKitAPI-iOS.entitlements (285798 => 285799)


--- trunk/Tools/TestWebKitAPI/Configurations/TestWebKitAPI-iOS.entitlements	2021-11-15 04:22:34 UTC (rev 285798)
+++ trunk/Tools/TestWebKitAPI/Configurations/TestWebKitAPI-iOS.entitlements	2021-11-15 07:17:34 UTC (rev 285799)
@@ -10,5 +10,7 @@
 	<true/>
 	<key>com.apple.Pasteboard.paste-unchecked</key>
 	<true/>
+	<key>com.apple.private.xpc.launchd.job-manager</key>
+	<string>TestWebKitAPI</string>
 </dict>
 </plist>

Modified: trunk/Tools/TestWebKitAPI/Configurations/TestWebKitAPI.xcconfig (285798 => 285799)


--- trunk/Tools/TestWebKitAPI/Configurations/TestWebKitAPI.xcconfig	2021-11-15 04:22:34 UTC (rev 285798)
+++ trunk/Tools/TestWebKitAPI/Configurations/TestWebKitAPI.xcconfig	2021-11-15 07:17:34 UTC (rev 285799)
@@ -46,6 +46,9 @@
 WK_APPSERVERSUPPORT_LDFLAGS = $(WK_APPSERVERSUPPORT_LDFLAGS_$(WK_PLATFORM_NAME));
 WK_APPSERVERSUPPORT_LDFLAGS_macosx = $(WK_APPSERVERSUPPORT_LDFLAGS$(WK_MACOS_1200));
 WK_APPSERVERSUPPORT_LDFLAGS_MACOS_SINCE_1200 = -framework AppServerSupport
+WK_APPSERVERSUPPORT_LDFLAGS_iphoneos = $(WK_APPSERVERSUPPORT_LDFLAGS$(WK_IOS_15));
+WK_APPSERVERSUPPORT_LDFLAGS_iphonesimulator = $(WK_APPSERVERSUPPORT_LDFLAGS$(WK_IOS_15));
+WK_APPSERVERSUPPORT_LDFLAGS_IOS_SINCE_15 = -framework AppServerSupport
 
 WK_AUTHKIT_LDFLAGS = $(WK_AUTHKIT_LDFLAGS_$(WK_PLATFORM_NAME));
 WK_AUTHKIT_LDFLAGS_iphoneos = $(WK_AUTHKIT_LDFLAGS$(WK_IOS_13));

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebPushDaemon.mm (285798 => 285799)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebPushDaemon.mm	2021-11-15 04:22:34 UTC (rev 285798)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebPushDaemon.mm	2021-11-15 07:17:34 UTC (rev 285799)
@@ -32,6 +32,9 @@
 #import <WebKit/WKUIDelegatePrivate.h>
 #import <WebKit/_WKExperimentalFeature.h>
 
+// FIXME: These tests are still currently disabled on iOS while tooling issues with `run-api-tests` are resolved.
+#if PLATFORM(MAC)
+
 static bool alertReceived = false;
 @interface NotificationPermissionDelegate : NSObject<WKUIDelegatePrivate>
 @end
@@ -53,9 +56,6 @@
 
 namespace TestWebKitAPI {
 
-// FIXME: Get this working in the iOS simulator.
-#if PLATFORM(MAC)
-
 static RetainPtr<NSURL> testWebPushDaemonLocation()
 {
     return [currentExecutableDirectory() URLByAppendingPathComponent:@"webpushd" isDirectory:NO];
@@ -84,7 +84,14 @@
     {
         auto programArguments = adoptNS(xpc_array_create(nullptr, 0));
         auto executableLocation = testWebPushDaemonLocation();
+#if PLATFORM(MAC)
         xpc_array_set_string(programArguments.get(), XPC_ARRAY_APPEND, executableLocation.get().fileSystemRepresentation);
+#else
+        // FIXME: These tests are still currently disabled on iOS while tooling issues with `run-api-tests` are resolved.
+        // Once enabled, this patch must point to the webpushd executable at a path that exists within
+        // the simulator runtime root.
+        xpc_array_set_string(programArguments.get(), XPC_ARRAY_APPEND, "/usr/local/bin/webkit-testing/webpushd");
+#endif
         xpc_array_set_string(programArguments.get(), XPC_ARRAY_APPEND, "--machServiceName");
         xpc_array_set_string(programArguments.get(), XPC_ARRAY_APPEND, "org.webkit.webpushtestdaemon.service");
         xpc_dictionary_set_value(plist.get(), "ProgramArguments", programArguments.get());
@@ -121,7 +128,7 @@
         [fileManager removeItemAtURL:tempDir error:&error];
     EXPECT_NULL(error);
 
-    system("killall webpushd -9 2> /dev/null");
+    killFirstInstanceOfDaemon(@"webpushd");
 
     auto plist = testWebPushDaemonPList(tempDir);
 #if HAVE(OS_LAUNCHD_JOB)
@@ -135,7 +142,7 @@
 
 static void cleanUpTestWebPushD(NSURL *tempDir)
 {
-    system("killall webpushd -9");
+    killFirstInstanceOfDaemon(@"webpushd");
 
     EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:tempDir.path]);
     NSError *error = nil;
@@ -159,6 +166,13 @@
     
     __block bool done = false;
     xpc_connection_send_message_with_reply(connection.get(), dictionary.get(), dispatch_get_main_queue(), ^(xpc_object_t reply) {
+        if (xpc_get_type(reply) != XPC_TYPE_DICTIONARY) {
+            NSLog(@"Unexpected non-dictionary: %@", reply);
+            done = true;
+            EXPECT_TRUE(FALSE);
+            return;
+        }
+
         size_t dataSize = 0;
         const void* data = "" "encoded message", &dataSize);
         EXPECT_EQ(dataSize, 15u);
@@ -187,6 +201,7 @@
 
     auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     configuration.get().websiteDataStore = dataStore.get();
+    [configuration.get().preferences _setNotificationsEnabled:YES];
     for (_WKExperimentalFeature *feature in [WKPreferences _experimentalFeatures]) {
         if ([feature.key isEqualToString:@"BuiltInNotificationsEnabled"])
             [[configuration preferences] _setEnabled:YES forFeature:feature];
@@ -222,6 +237,12 @@
     EXPECT_TRUE([origin.get().protocol isEqualToString:@"testing"]);
     EXPECT_TRUE([origin.get().host isEqualToString:@"main"]);
 
+    // If we failed to retrieve an expected origin, we will have failed the above checks
+    if (!origin) {
+        cleanUpTestWebPushD(tempDirectory);
+        return;
+    }
+
     originOperationDone = false;
     [dataStore _deletePushAndNotificationRegistration:origin.get() completionHandler:^(NSError *error) {
         EXPECT_FALSE(!!error);
@@ -240,6 +261,6 @@
     cleanUpTestWebPushD(tempDirectory);
 }
 
+} // namespace TestWebKitAPI
+
 #endif // PLATFORM(MAC)
-
-} // namespace TestWebKitAPI

Modified: trunk/Tools/TestWebKitAPI/cocoa/DaemonTestUtilities.h (285798 => 285799)


--- trunk/Tools/TestWebKitAPI/cocoa/DaemonTestUtilities.h	2021-11-15 04:22:34 UTC (rev 285798)
+++ trunk/Tools/TestWebKitAPI/cocoa/DaemonTestUtilities.h	2021-11-15 07:17:34 UTC (rev 285799)
@@ -25,6 +25,8 @@
 
 #pragma once
 
+#if PLATFORM(MAC) || PLATFORM(IOS)
+
 #import <wtf/RetainPtr.h>
 #import <wtf/spi/darwin/XPCSPI.h>
 
@@ -35,13 +37,15 @@
 
 RetainPtr<NSURL> currentExecutableDirectory();
 
-// FIXME: Get this working in the iOS simulator.
-#if PLATFORM(MAC)
+void killFirstInstanceOfDaemon(NSString *daemonExecutableName);
+
 #if HAVE(OS_LAUNCHD_JOB)
 void registerPlistWithLaunchD(RetainPtr<xpc_object_t>&&);
 #else
 void registerPlistWithLaunchD(RetainPtr<NSDictionary>&&, NSURL *tempDir);
 #endif
-#endif
 
 } // namespace TestWebKitAPI
+
+#endif // PLATFORM(MAC) || PLATFORM(IOS)
+

Modified: trunk/Tools/TestWebKitAPI/cocoa/DaemonTestUtilities.mm (285798 => 285799)


--- trunk/Tools/TestWebKitAPI/cocoa/DaemonTestUtilities.mm	2021-11-15 04:22:34 UTC (rev 285798)
+++ trunk/Tools/TestWebKitAPI/cocoa/DaemonTestUtilities.mm	2021-11-15 07:17:34 UTC (rev 285799)
@@ -26,9 +26,26 @@
 #import "config.h"
 #import "DaemonTestUtilities.h"
 
+#if PLATFORM(MAC) || PLATFORM(IOS)
+
 #import <mach-o/dyld.h>
 #import <wtf/Vector.h>
 
+NS_ASSUME_NONNULL_BEGIN
+
+#if PLATFORM(IOS)
+@interface NSTask : NSObject
+- (instancetype)init;
+- (void)launch;
+- (void)waitUntilExit;
+
+@property (nullable, copy) NSString *launchPath;
+@property (nullable, copy) NSArray<NSString *> *arguments;
+@property (nullable, retain) id standardOutput;
+@property (readonly, getter=isRunning) BOOL running;
+@end
+#endif
+
 namespace TestWebKitAPI {
 
 static RetainPtr<NSURL> currentExecutableLocation()
@@ -48,8 +65,6 @@
     return [currentExecutableLocation() URLByDeletingLastPathComponent];
 }
 
-// FIXME: Get this working in the iOS simulator.
-#if PLATFORM(MAC)
 #if HAVE(OS_LAUNCHD_JOB)
 
 void registerPlistWithLaunchD(RetainPtr<xpc_object_t>&& plist)
@@ -57,7 +72,13 @@
     NSError *error = nil;
     auto launchDJob = adoptNS([[OSLaunchdJob alloc] initWithPlist:plist.get()]);
     [launchDJob submit:&error];
+
+    // In the iOS Simulator we often see the following error here:
+    // Error Domain=OSLaunchdErrorDomain Code=17 "File exists"
+    // Tests still behave as expected.
+#if PLATFORM(MAC)
     EXPECT_FALSE(error);
+#endif
 }
 
 #else // HAVE(OS_LAUNCHD_JOB)
@@ -77,6 +98,59 @@
 }
 
 #endif // HAVE(OS_LAUNCHD_JOB)
-#endif // PLATFORM(MAC)
 
+static int pidOfFirstDaemonInstance(NSString *daemonExecutableName)
+{
+    auto task = adoptNS([[NSTask alloc] init]);
+    task.get().launchPath = @"/bin/ps";
+    task.get().arguments = @[
+        @"-ax",
+        @"-o",
+        @"pid,comm"
+    ];
+
+    auto taskPipe = adoptNS([[NSPipe alloc] init]);
+    [task setStandardOutput:taskPipe.get()];
+    [task launch];
+
+    auto data = "" alloc] init]);
+    while ([task isRunning])
+        [data appendData:[[taskPipe fileHandleForReading] readDataToEndOfFile]];
+    [data appendData:[[taskPipe fileHandleForReading] readDataToEndOfFile]];
+
+    auto psString = adoptNS([[NSString alloc] initWithData:data.get() encoding:NSUTF8StringEncoding]);
+    NSArray<NSString *> *psEntries = [psString componentsSeparatedByString:@"\n"];
+
+    for (NSString* entry in psEntries) {
+        if (![entry hasSuffix:daemonExecutableName])
+            continue;
+        NSArray<NSString *> *components = [entry componentsSeparatedByString:@" "];
+        EXPECT_GE([components count], 2u);
+        return [[components firstObject] integerValue];
+    }
+
+    return 0;
+}
+
+void killFirstInstanceOfDaemon(NSString *daemonExecutableName)
+{
+    auto pid = pidOfFirstDaemonInstance(daemonExecutableName);
+    if (!pid)
+        return;
+
+    auto task = adoptNS([[NSTask alloc] init]);
+    task.get().launchPath = @"/bin/kill";
+    task.get().arguments = @[
+        @"-9",
+        [@(pid) stringValue]
+    ];
+
+    [task launch];
+    [task waitUntilExit];
+}
+
 } // namespace TestWebKitAPI
+
+NS_ASSUME_NONNULL_END
+
+#endif // PLATFORM(MAC) || PLATFORM(IOS)

Modified: trunk/WebKitLibraries/ChangeLog (285798 => 285799)


--- trunk/WebKitLibraries/ChangeLog	2021-11-15 04:22:34 UTC (rev 285798)
+++ trunk/WebKitLibraries/ChangeLog	2021-11-15 07:17:34 UTC (rev 285799)
@@ -1,3 +1,12 @@
+2021-11-14  Brady Eidson  <beid...@apple.com>
+
+        Get daemon API ready to work in the iOS simulator (starting with WebPushD)
+        https://bugs.webkit.org/show_bug.cgi?id=232982
+
+        Reviewed by Geoff Garen.
+
+        * WebKitPrivateFrameworkStubs/iOS/15/AppServerSupport.framework/AppServerSupport.tbd: Added.
+
 2021-09-24  Jonathan Bedard  <jbed...@apple.com>
 
         [iOS 15] Support building WebKit (Part 3)

Added: trunk/WebKitLibraries/WebKitPrivateFrameworkStubs/iOS/15/AppServerSupport.framework/AppServerSupport.tbd (0 => 285799)


--- trunk/WebKitLibraries/WebKitPrivateFrameworkStubs/iOS/15/AppServerSupport.framework/AppServerSupport.tbd	                        (rev 0)
+++ trunk/WebKitLibraries/WebKitPrivateFrameworkStubs/iOS/15/AppServerSupport.framework/AppServerSupport.tbd	2021-11-15 07:17:34 UTC (rev 285799)
@@ -0,0 +1,8 @@
+--- !tapi-tbd-v3
+archs:           [ x86_64, arm64, arm64e ]
+install-name:    '/System/Library/PrivateFrameworks/AppServerSupport.framework/AppServerSupport'
+platform: ios
+exports:
+  - archs:           [ x86_64, arm64, arm64e ]
+    objc-classes:    [ OSLaunchdJob ]
+...
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to