⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 285799 in webkit


Ignore:
Timestamp:
Nov 14, 2021, 11:17:34 PM (5 years ago)
Author:
beidson@apple.com
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.
Location:
trunk
Files:
2 added
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r285798 r285799  
     12021-11-14  Brady Eidson  <beidson@apple.com>
     2
     3        Get daemon API ready to work in the iOS simulator (starting with WebPushD)
     4        https://bugs.webkit.org/show_bug.cgi?id=232982
     5
     6        Reviewed by Geoff Garen.
     7
     8        Move all the "enable Notifications" SPI from Mac-only to cross platform:
     9        * UIProcess/API/Cocoa/WKPreferences.mm:
     10        (-[WKPreferences _setNotificationsEnabled:]):
     11        (-[WKPreferences _notificationsEnabled]):
     12        * UIProcess/API/Cocoa/WKPreferencesPrivate.h:
     13        * UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
     14        * UIProcess/Cocoa/UIDelegate.h:
     15        * UIProcess/Cocoa/UIDelegate.mm:
     16        (WebKit::UIDelegate::setDelegate):
     17        (WebKit::UIDelegate::UIClient::decidePolicyForNotificationPermissionRequest):
     18
     19        * WebKit.xcodeproj/project.pbxproj: Add a build phase script to install the daemon executables
     20          inside a Daemons directory within the built WebKit.framework for engineering builds.
     21        * webpushd/WebPushDaemon.mm:
     22
    1232021-11-14  Fujii Hironori  <Hironori.Fujii@sony.com>
    224
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKPreferences.mm

    r285741 r285799  
    11641164}
    11651165
    1166 - (void)_setNotificationsEnabled:(BOOL)enabled
    1167 {
    1168     _preferences->setNotificationsEnabled(enabled);
    1169 }
    1170 
    1171 - (BOOL)_notificationsEnabled
    1172 {
    1173     return _preferences->notificationsEnabled();
    1174 }
    1175 
    11761166- (void)_setBackspaceKeyNavigationEnabled:(BOOL)enabled
    11771167{
     
    15651555}
    15661556
     1557- (void)_setNotificationsEnabled:(BOOL)enabled
     1558{
     1559    _preferences->setNotificationsEnabled(enabled);
     1560}
     1561
     1562- (BOOL)_notificationsEnabled
     1563{
     1564    return _preferences->notificationsEnabled();
     1565}
     1566
    15671567@end
    15681568
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKPreferencesPrivate.h

    r284214 r285799  
    177177@property (nonatomic, setter=_setStorageAPIEnabled:) BOOL _storageAPIEnabled WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
    178178@property (nonatomic, setter=_setAccessHandleEnabled:) BOOL _accessHandleEnabled WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
     179@property (nonatomic, setter=_setNotificationsEnabled:) BOOL _notificationsEnabled WK_API_AVAILABLE(macos(10.13.4), ios(WK_IOS_TBA));
    179180
    180181#if !TARGET_OS_IPHONE
     
    201202@property (nonatomic, setter=_setViewGestureDebuggingEnabled:) BOOL _viewGestureDebuggingEnabled WK_API_AVAILABLE(macos(10.13.4));
    202203@property (nonatomic, setter=_setStandardFontFamily:) NSString *_standardFontFamily WK_API_AVAILABLE(macos(10.13.4));
    203 @property (nonatomic, setter=_setNotificationsEnabled:) BOOL _notificationsEnabled WK_API_AVAILABLE(macos(10.13.4));
    204204@property (nonatomic, setter=_setBackspaceKeyNavigationEnabled:) BOOL _backspaceKeyNavigationEnabled WK_API_AVAILABLE(macos(10.13.4));
    205205@property (nonatomic, setter=_setAllowsInlineMediaPlayback:) BOOL _allowsInlineMediaPlayback WK_API_AVAILABLE(macos(10.14));
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h

    r285444 r285799  
    160160
    161161- (void)_webView:(WKWebView *)webView startXRSessionWithCompletionHandler:(void (^)(id))completionHandler WK_API_AVAILABLE(macos(12.0), ios(15.0));
     162- (void)_webView:(WKWebView *)webView requestNotificationPermissionForSecurityOrigin:(WKSecurityOrigin *)securityOrigin decisionHandler:(void (^)(BOOL))decisionHandler WK_API_AVAILABLE(macos(10.13.4));
    162163
    163164#if TARGET_OS_IPHONE
     
    245246- (void)_webView:(WKWebView *)webView drawHeaderInRect:(CGRect)rect forPageWithTitle:(NSString *)title URL:(NSURL *)url WK_API_AVAILABLE(macos(10.13.4));
    246247- (void)_webView:(WKWebView *)webView drawFooterInRect:(CGRect)rect forPageWithTitle:(NSString *)title URL:(NSURL *)url WK_API_AVAILABLE(macos(10.13.4));
    247 - (void)_webView:(WKWebView *)webView requestNotificationPermissionForSecurityOrigin:(WKSecurityOrigin *)securityOrigin decisionHandler:(void (^)(BOOL))decisionHandler WK_API_AVAILABLE(macos(10.13.4));
    248248- (void)_webView:(WKWebView *)webview mouseDidMoveOverElement:(_WKHitTestResult *)hitTestResult withFlags:(NSEventModifierFlags)flags userInfo:(id <NSSecureCoding>)userInfo;
    249249- (void)_webView:(WKWebView *)webView didExceedBackgroundResourceLimitWhileInForeground:(_WKResourceLimit)limit WK_API_AVAILABLE(macos(10.13.4));
  • trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h

    r285444 r285799  
    106106        bool takeFocus(WebPageProxy*, WKFocusDirection) final;
    107107        void handleAutoplayEvent(WebPageProxy&, WebCore::AutoplayEvent, OptionSet<WebCore::AutoplayEventFlags>) final;
     108        void decidePolicyForNotificationPermissionRequest(WebPageProxy&, API::SecurityOrigin&, CompletionHandler<void(bool allowed)>&&) final;
     109
    108110#if PLATFORM(MAC)
    109111        void showPage(WebPageProxy*) final;
     
    124126        void drawFooter(WebPageProxy&, WebFrameProxy&, WebCore::FloatRect&&) final;
    125127
    126         void decidePolicyForNotificationPermissionRequest(WebPageProxy&, API::SecurityOrigin&, CompletionHandler<void(bool allowed)>&&) final;
    127128        void mouseDidMoveOverElement(WebPageProxy&, const WebHitTestResultData&, OptionSet<WebEvent::Modifier>, API::Object*);
    128129        void didClickAutoFillButton(WebPageProxy&, API::Object*) final;
     
    216217        bool webViewSaveDataToFileSuggestedFilenameMimeTypeOriginatingURL : 1;
    217218        bool webViewRunOpenPanelWithParametersInitiatedByFrameCompletionHandler : 1;
    218         bool webViewRequestNotificationPermissionForSecurityOriginDecisionHandler : 1;
    219219        bool webViewConfigurationForLocalInspector : 1;
    220220        bool webViewDidAttachLocalInspector : 1;
     
    268268        bool webViewStartXRSessionWithCompletionHandler : 1;
    269269#endif
     270        bool webViewRequestNotificationPermissionForSecurityOriginDecisionHandler : 1;
    270271    } m_delegateMethods;
    271272};
  • trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm

    r285444 r285799  
    139139    m_delegateMethods.webViewSaveDataToFileSuggestedFilenameMimeTypeOriginatingURL = [delegate respondsToSelector:@selector(_webView:saveDataToFile:suggestedFilename:mimeType:originatingURL:)];
    140140    m_delegateMethods.webViewRunOpenPanelWithParametersInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(webView:runOpenPanelWithParameters:initiatedByFrame:completionHandler:)];
    141     m_delegateMethods.webViewRequestNotificationPermissionForSecurityOriginDecisionHandler = [delegate respondsToSelector:@selector(_webView:requestNotificationPermissionForSecurityOrigin:decisionHandler:)];
    142141    m_delegateMethods.webViewConfigurationForLocalInspector = [delegate respondsToSelector:@selector(_webView:configurationForLocalInspector:)];
    143142    m_delegateMethods.webViewDidAttachLocalInspector = [delegate respondsToSelector:@selector(_webView:didAttachLocalInspector:)];
     
    197196    m_delegateMethods.webViewStartXRSessionWithCompletionHandler = [delegate respondsToSelector:@selector(_webView:startXRSessionWithCompletionHandler:)];
    198197#endif
     198    m_delegateMethods.webViewRequestNotificationPermissionForSecurityOriginDecisionHandler = [delegate respondsToSelector:@selector(_webView:requestNotificationPermissionForSecurityOrigin:decisionHandler:)];
    199199}
    200200
     
    620620}
    621621
     622void UIDelegate::UIClient::decidePolicyForNotificationPermissionRequest(WebKit::WebPageProxy&, API::SecurityOrigin& securityOrigin, CompletionHandler<void(bool allowed)>&& completionHandler)
     623{
     624    if (!m_uiDelegate)
     625        return completionHandler(false);
     626
     627    if (!m_uiDelegate->m_delegateMethods.webViewRequestNotificationPermissionForSecurityOriginDecisionHandler)
     628        return completionHandler(false);
     629
     630    auto delegate = m_uiDelegate->m_delegate.get();
     631    if (!delegate)
     632        return completionHandler(false);
     633
     634    auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:requestNotificationPermissionForSecurityOrigin:decisionHandler:));
     635    [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate->m_webView.get().get() requestNotificationPermissionForSecurityOrigin:wrapper(securityOrigin) decisionHandler:makeBlockPtr([completionHandler = WTFMove(completionHandler), checker = WTFMove(checker)] (BOOL result) mutable {
     636        if (checker->completionHandlerHasBeenCalled())
     637            return;
     638        checker->didCallCompletionHandler();
     639        completionHandler(result);
     640    }).get()];
     641}
     642
    622643#if PLATFORM(MAC)
    623644bool UIDelegate::UIClient::canRunModal() const
     
    920941
    921942    [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate->m_webView.get().get() saveDataToFile:wrapper(data) suggestedFilename:suggestedFilename mimeType:mimeType originatingURL:originatingURL];
    922 }
    923 
    924 void UIDelegate::UIClient::decidePolicyForNotificationPermissionRequest(WebKit::WebPageProxy&, API::SecurityOrigin& securityOrigin, CompletionHandler<void(bool allowed)>&& completionHandler)
    925 {
    926     if (!m_uiDelegate)
    927         return completionHandler(false);
    928 
    929     if (!m_uiDelegate->m_delegateMethods.webViewRequestNotificationPermissionForSecurityOriginDecisionHandler)
    930         return completionHandler(false);
    931    
    932     auto delegate = m_uiDelegate->m_delegate.get();
    933     if (!delegate)
    934         return completionHandler(false);
    935 
    936     auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:requestNotificationPermissionForSecurityOrigin:decisionHandler:));
    937     [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate->m_webView.get().get() requestNotificationPermissionForSecurityOrigin:wrapper(securityOrigin) decisionHandler:makeBlockPtr([completionHandler = WTFMove(completionHandler), checker = WTFMove(checker)] (BOOL result) mutable {
    938         if (checker->completionHandlerHasBeenCalled())
    939             return;
    940         checker->didCallCompletionHandler();
    941         completionHandler(result);
    942     }).get()];
    943943}
    944944
  • trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj

    r285770 r285799  
    1323913239                                5379C7AC21E5288500E4A8F6 /* Check .xcfilelists */,
    1324013240                                933170072234674500B32554 /* Create symlinks to XPC services for engineering builds */,
     13241                                512B81CA273CAFBE00D87D49 /* Create symlinks to Daemons for engineering builds */,
    1324113242                                0FB94836239F31B700926A8F /* Copy Testing Headers */,
    1324213243                                DFD03A29270D5F57001A996E /* Copy Daemon Plists */,
     
    1373113732                        shellPath = /bin/sh;
    1373213733                        shellScript = "Scripts/process-entitlements.sh\n";
     13734                };
     13735                512B81CA273CAFBE00D87D49 /* Create symlinks to Daemons for engineering builds */ = {
     13736                        isa = PBXShellScriptBuildPhase;
     13737                        buildActionMask = 2147483647;
     13738                        files = (
     13739                        );
     13740                        inputFileListPaths = (
     13741                        );
     13742                        inputPaths = (
     13743                        );
     13744                        name = "Create symlinks to Daemons for engineering builds";
     13745                        outputFileListPaths = (
     13746                        );
     13747                        outputPaths = (
     13748                        );
     13749                        runOnlyForDeploymentPostprocessing = 0;
     13750                        shellPath = /bin/sh;
     13751                        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";
    1373313752                };
    1373413753                5325BDD221DFF47C00A0DEE1 /* ShellScript */ = {
  • trunk/Tools/ChangeLog

    r285781 r285799  
     12021-11-14  Brady Eidson  <beidson@apple.com>
     2
     3        Get daemon API ready to work in the iOS simulator (starting with WebPushD)
     4        https://bugs.webkit.org/show_bug.cgi?id=232982
     5
     6        Reviewed by Geoff Garen.
     7
     8        To get this working we needed to:
     9        - Have the Daemons installed in a simulator-runtime-root-visible path
     10        - Point the OSLaunchDJob plist to the simulator-relative path, not Mac-relative
     11        - Solve the "How do I kill existing instances to run a clean test?" problem within the simulator.
     12       
     13        This patch does those things.
     14       
     15        * TestWebKitAPI/Configurations/TestWebKitAPI-iOS.entitlements:
     16        * TestWebKitAPI/Configurations/TestWebKitAPI.xcconfig:
     17       
     18        * TestWebKitAPI/Tests/WebKitCocoa/WebPushDaemon.mm:
     19        (TestWebKitAPI::testWebPushDaemonPList):
     20        (TestWebKitAPI::setUpTestWebPushD):
     21        (TestWebKitAPI::cleanUpTestWebPushD):
     22       
     23        * TestWebKitAPI/cocoa/DaemonTestUtilities.h:
     24        * TestWebKitAPI/cocoa/DaemonTestUtilities.mm:
     25        (TestWebKitAPI::registerPlistWithLaunchD):
     26        (TestWebKitAPI::pidOfFirstDaemonInstance):
     27        (TestWebKitAPI::killFirstInstanceOfDaemon):
     28
    1292021-11-13  Simon Fraser  <simon.fraser@apple.com>
    230
  • trunk/Tools/TestWebKitAPI/Configurations/TestWebKitAPI-iOS.entitlements

    r285672 r285799  
    1111        <key>com.apple.Pasteboard.paste-unchecked</key>
    1212        <true/>
     13        <key>com.apple.private.xpc.launchd.job-manager</key>
     14        <string>TestWebKitAPI</string>
    1315</dict>
    1416</plist>
  • trunk/Tools/TestWebKitAPI/Configurations/TestWebKitAPI.xcconfig

    r284669 r285799  
    4747WK_APPSERVERSUPPORT_LDFLAGS_macosx = $(WK_APPSERVERSUPPORT_LDFLAGS$(WK_MACOS_1200));
    4848WK_APPSERVERSUPPORT_LDFLAGS_MACOS_SINCE_1200 = -framework AppServerSupport
     49WK_APPSERVERSUPPORT_LDFLAGS_iphoneos = $(WK_APPSERVERSUPPORT_LDFLAGS$(WK_IOS_15));
     50WK_APPSERVERSUPPORT_LDFLAGS_iphonesimulator = $(WK_APPSERVERSUPPORT_LDFLAGS$(WK_IOS_15));
     51WK_APPSERVERSUPPORT_LDFLAGS_IOS_SINCE_15 = -framework AppServerSupport
    4952
    5053WK_AUTHKIT_LDFLAGS = $(WK_AUTHKIT_LDFLAGS_$(WK_PLATFORM_NAME));
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebPushDaemon.mm

    r285547 r285799  
    3333#import <WebKit/_WKExperimentalFeature.h>
    3434
     35// FIXME: These tests are still currently disabled on iOS while tooling issues with `run-api-tests` are resolved.
     36#if PLATFORM(MAC)
     37
    3538static bool alertReceived = false;
    3639@interface NotificationPermissionDelegate : NSObject<WKUIDelegatePrivate>
     
    5356
    5457namespace TestWebKitAPI {
    55 
    56 // FIXME: Get this working in the iOS simulator.
    57 #if PLATFORM(MAC)
    5858
    5959static RetainPtr<NSURL> testWebPushDaemonLocation()
     
    8585        auto programArguments = adoptNS(xpc_array_create(nullptr, 0));
    8686        auto executableLocation = testWebPushDaemonLocation();
     87#if PLATFORM(MAC)
    8788        xpc_array_set_string(programArguments.get(), XPC_ARRAY_APPEND, executableLocation.get().fileSystemRepresentation);
     89#else
     90        // FIXME: These tests are still currently disabled on iOS while tooling issues with `run-api-tests` are resolved.
     91        // Once enabled, this patch must point to the webpushd executable at a path that exists within
     92        // the simulator runtime root.
     93        xpc_array_set_string(programArguments.get(), XPC_ARRAY_APPEND, "/usr/local/bin/webkit-testing/webpushd");
     94#endif
    8895        xpc_array_set_string(programArguments.get(), XPC_ARRAY_APPEND, "--machServiceName");
    8996        xpc_array_set_string(programArguments.get(), XPC_ARRAY_APPEND, "org.webkit.webpushtestdaemon.service");
     
    122129    EXPECT_NULL(error);
    123130
    124     system("killall webpushd -9 2> /dev/null");
     131    killFirstInstanceOfDaemon(@"webpushd");
    125132
    126133    auto plist = testWebPushDaemonPList(tempDir);
     
    136143static void cleanUpTestWebPushD(NSURL *tempDir)
    137144{
    138     system("killall webpushd -9");
     145    killFirstInstanceOfDaemon(@"webpushd");
    139146
    140147    EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:tempDir.path]);
     
    160167    __block bool done = false;
    161168    xpc_connection_send_message_with_reply(connection.get(), dictionary.get(), dispatch_get_main_queue(), ^(xpc_object_t reply) {
     169        if (xpc_get_type(reply) != XPC_TYPE_DICTIONARY) {
     170            NSLog(@"Unexpected non-dictionary: %@", reply);
     171            done = true;
     172            EXPECT_TRUE(FALSE);
     173            return;
     174        }
     175
    162176        size_t dataSize = 0;
    163177        const void* data = xpc_dictionary_get_data(reply, "encoded message", &dataSize);
     
    188202    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
    189203    configuration.get().websiteDataStore = dataStore.get();
     204    [configuration.get().preferences _setNotificationsEnabled:YES];
    190205    for (_WKExperimentalFeature *feature in [WKPreferences _experimentalFeatures]) {
    191206        if ([feature.key isEqualToString:@"BuiltInNotificationsEnabled"])
     
    223238    EXPECT_TRUE([origin.get().host isEqualToString:@"main"]);
    224239
     240    // If we failed to retrieve an expected origin, we will have failed the above checks
     241    if (!origin) {
     242        cleanUpTestWebPushD(tempDirectory);
     243        return;
     244    }
     245
    225246    originOperationDone = false;
    226247    [dataStore _deletePushAndNotificationRegistration:origin.get() completionHandler:^(NSError *error) {
     
    241262}
    242263
     264} // namespace TestWebKitAPI
     265
    243266#endif // PLATFORM(MAC)
    244 
    245 } // namespace TestWebKitAPI
  • trunk/Tools/TestWebKitAPI/cocoa/DaemonTestUtilities.h

    r284218 r285799  
    2626#pragma once
    2727
     28#if PLATFORM(MAC) || PLATFORM(IOS)
     29
    2830#import <wtf/RetainPtr.h>
    2931#import <wtf/spi/darwin/XPCSPI.h>
     
    3638RetainPtr<NSURL> currentExecutableDirectory();
    3739
    38 // FIXME: Get this working in the iOS simulator.
    39 #if PLATFORM(MAC)
     40void killFirstInstanceOfDaemon(NSString *daemonExecutableName);
     41
    4042#if HAVE(OS_LAUNCHD_JOB)
    4143void registerPlistWithLaunchD(RetainPtr<xpc_object_t>&&);
     
    4345void registerPlistWithLaunchD(RetainPtr<NSDictionary>&&, NSURL *tempDir);
    4446#endif
    45 #endif
    4647
    4748} // namespace TestWebKitAPI
     49
     50#endif // PLATFORM(MAC) || PLATFORM(IOS)
     51
  • trunk/Tools/TestWebKitAPI/cocoa/DaemonTestUtilities.mm

    r284218 r285799  
    2727#import "DaemonTestUtilities.h"
    2828
     29#if PLATFORM(MAC) || PLATFORM(IOS)
     30
    2931#import <mach-o/dyld.h>
    3032#import <wtf/Vector.h>
     33
     34NS_ASSUME_NONNULL_BEGIN
     35
     36#if PLATFORM(IOS)
     37@interface NSTask : NSObject
     38- (instancetype)init;
     39- (void)launch;
     40- (void)waitUntilExit;
     41
     42@property (nullable, copy) NSString *launchPath;
     43@property (nullable, copy) NSArray<NSString *> *arguments;
     44@property (nullable, retain) id standardOutput;
     45@property (readonly, getter=isRunning) BOOL running;
     46@end
     47#endif
    3148
    3249namespace TestWebKitAPI {
     
    4966}
    5067
    51 // FIXME: Get this working in the iOS simulator.
    52 #if PLATFORM(MAC)
    5368#if HAVE(OS_LAUNCHD_JOB)
    5469
     
    5873    auto launchDJob = adoptNS([[OSLaunchdJob alloc] initWithPlist:plist.get()]);
    5974    [launchDJob submit:&error];
     75
     76    // In the iOS Simulator we often see the following error here:
     77    // Error Domain=OSLaunchdErrorDomain Code=17 "File exists"
     78    // Tests still behave as expected.
     79#if PLATFORM(MAC)
    6080    EXPECT_FALSE(error);
     81#endif
    6182}
    6283
     
    7899
    79100#endif // HAVE(OS_LAUNCHD_JOB)
    80 #endif // PLATFORM(MAC)
     101
     102static int pidOfFirstDaemonInstance(NSString *daemonExecutableName)
     103{
     104    auto task = adoptNS([[NSTask alloc] init]);
     105    task.get().launchPath = @"/bin/ps";
     106    task.get().arguments = @[
     107        @"-ax",
     108        @"-o",
     109        @"pid,comm"
     110    ];
     111
     112    auto taskPipe = adoptNS([[NSPipe alloc] init]);
     113    [task setStandardOutput:taskPipe.get()];
     114    [task launch];
     115
     116    auto data = adoptNS([[NSMutableData alloc] init]);
     117    while ([task isRunning])
     118        [data appendData:[[taskPipe fileHandleForReading] readDataToEndOfFile]];
     119    [data appendData:[[taskPipe fileHandleForReading] readDataToEndOfFile]];
     120
     121    auto psString = adoptNS([[NSString alloc] initWithData:data.get() encoding:NSUTF8StringEncoding]);
     122    NSArray<NSString *> *psEntries = [psString componentsSeparatedByString:@"\n"];
     123
     124    for (NSString* entry in psEntries) {
     125        if (![entry hasSuffix:daemonExecutableName])
     126            continue;
     127        NSArray<NSString *> *components = [entry componentsSeparatedByString:@" "];
     128        EXPECT_GE([components count], 2u);
     129        return [[components firstObject] integerValue];
     130    }
     131
     132    return 0;
     133}
     134
     135void killFirstInstanceOfDaemon(NSString *daemonExecutableName)
     136{
     137    auto pid = pidOfFirstDaemonInstance(daemonExecutableName);
     138    if (!pid)
     139        return;
     140
     141    auto task = adoptNS([[NSTask alloc] init]);
     142    task.get().launchPath = @"/bin/kill";
     143    task.get().arguments = @[
     144        @"-9",
     145        [@(pid) stringValue]
     146    ];
     147
     148    [task launch];
     149    [task waitUntilExit];
     150}
    81151
    82152} // namespace TestWebKitAPI
     153
     154NS_ASSUME_NONNULL_END
     155
     156#endif // PLATFORM(MAC) || PLATFORM(IOS)
  • trunk/WebKitLibraries/ChangeLog

    r283039 r285799  
     12021-11-14  Brady Eidson  <beidson@apple.com>
     2
     3        Get daemon API ready to work in the iOS simulator (starting with WebPushD)
     4        https://bugs.webkit.org/show_bug.cgi?id=232982
     5
     6        Reviewed by Geoff Garen.
     7
     8        * WebKitPrivateFrameworkStubs/iOS/15/AppServerSupport.framework/AppServerSupport.tbd: Added.
     9
    1102021-09-24  Jonathan Bedard  <jbedard@apple.com>
    211
Note: See TracChangeset for help on using the changeset viewer.