Changeset 282368 in webkit
- Timestamp:
- Sep 13, 2021, 3:36:21 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 27 edited
-
Source/WTF/ChangeLog (modified) (1 diff)
-
Source/WTF/wtf/PlatformHave.h (modified) (1 diff)
-
Source/WTF/wtf/spi/darwin/XPCSPI.h (modified) (1 diff)
-
Source/WebKit/ChangeLog (modified) (1 diff)
-
Source/WebKit/NetworkProcess/NetworkSession.cpp (modified) (1 diff)
-
Source/WebKit/NetworkProcess/NetworkSessionCreationParameters.cpp (modified) (3 diffs)
-
Source/WebKit/NetworkProcess/NetworkSessionCreationParameters.h (modified) (1 diff)
-
Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementConnection.cpp (modified) (1 diff)
-
Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementConnection.h (modified) (2 diffs)
-
Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManagerInterface.cpp (modified) (1 diff)
-
Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManagerInterface.h (modified) (1 diff)
-
Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManagerProxy.cpp (modified) (2 diffs)
-
Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManagerProxy.h (modified) (3 diffs)
-
Source/WebKit/NetworkProcess/PrivateClickMeasurement/cocoa/PrivateClickMeasurementDaemonConnectionCocoa.mm (modified) (2 diffs)
-
Source/WebKit/NetworkProcess/mac/com.apple.WebKit.NetworkProcess.sb.in (modified) (1 diff)
-
Source/WebKit/Shared/EntryPointUtilities/Cocoa/Daemon/PCMDaemonEntryPoint.mm (modified) (5 diffs)
-
Source/WebKit/UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.h (modified) (1 diff)
-
Source/WebKit/UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.mm (modified) (1 diff)
-
Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp (modified) (1 diff)
-
Source/WebKit/UIProcess/WebsiteData/WebsiteDataStoreConfiguration.cpp (modified) (2 diffs)
-
Source/WebKit/UIProcess/WebsiteData/WebsiteDataStoreConfiguration.h (modified) (2 diffs)
-
Tools/ChangeLog (modified) (1 diff)
-
Tools/TestWebKitAPI/Configurations/TestPCMDaemon.xcconfig (added)
-
Tools/TestWebKitAPI/Configurations/TestWebKitAPI-macOS-internal.entitlements (modified) (1 diff)
-
Tools/TestWebKitAPI/Configurations/TestWebKitAPI-macOS.entitlements (modified) (1 diff)
-
Tools/TestWebKitAPI/Configurations/TestWebKitAPI.xcconfig (modified) (2 diffs)
-
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (modified) (14 diffs)
-
Tools/TestWebKitAPI/Tests/WebKitCocoa/EventAttribution.mm (modified) (2 diffs)
-
Tools/TestWebKitAPI/cocoa/TestPCMDaemonMain.c (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r282361 r282368 1 2021-09-13 Alex Christensen <achristensen@webkit.org> 2 3 Add unit test that uses PCM daemon 4 https://bugs.webkit.org/show_bug.cgi?id=230191 5 6 Reviewed by Chris Dumez. 7 8 * wtf/PlatformHave.h: 9 * wtf/spi/darwin/XPCSPI.h: 10 1 11 2021-09-13 Sihui Liu <sihui_liu@apple.com> 2 12 -
trunk/Source/WTF/wtf/PlatformHave.h
r282221 r282368 814 814 #define HAVE_NETWORK_LOADER 1 815 815 #define HAVE_SEC_TRUST_COPY_CERTIFICATE_CHAIN 1 816 #define HAVE_OS_LAUNCHD_JOB 1 816 817 #endif 817 818 -
trunk/Source/WTF/wtf/spi/darwin/XPCSPI.h
r282230 r282368 115 115 #include <os/transaction_private.h> 116 116 #include <xpc/private.h> 117 #else 117 #if HAVE(OS_LAUNCHD_JOB) 118 #include <AppServerSupport/OSLaunchdJob.h> 119 #endif // HAVE(OS_LAUNCHD_JOB) 120 #else // USE(APPLE_INTERNAL_SDK) 121 122 #ifdef __OBJC__ 123 #if HAVE(OS_LAUNCHD_JOB) 124 @interface OSLaunchdJob : NSObject 125 - (instancetype)initWithPlist:(xpc_object_t)plist; 126 - (BOOL)submit:(NSError **)errorOut; 127 @end 128 #endif // HAVE(OS_LAUNCHD_JOB) 129 #endif // __OBJC__ 118 130 119 131 extern "C" const char * const XPC_ACTIVITY_RANDOM_INITIAL_DELAY; -
trunk/Source/WebKit/ChangeLog
r282367 r282368 1 2021-09-13 Alex Christensen <achristensen@webkit.org> 2 3 Add unit test that uses PCM daemon 4 https://bugs.webkit.org/show_bug.cgi?id=230191 5 6 Reviewed by Chris Dumez. 7 8 I make a way to specify what mach service to connect to, 9 then I temporarily register an executable with launchd to provide that mach service, 10 then I run the test communicating with that executable. 11 12 * NetworkProcess/NetworkSession.cpp: 13 (WebKit::managerOrProxy): 14 * NetworkProcess/NetworkSessionCreationParameters.cpp: 15 (WebKit::NetworkSessionCreationParameters::encode const): 16 (WebKit::NetworkSessionCreationParameters::decode): 17 * NetworkProcess/NetworkSessionCreationParameters.h: 18 * NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementConnection.cpp: 19 (WebKit::PCM::Connection::Connection): 20 (WebKit::PCM::Connection::send const): 21 (WebKit::PCM::Connection::sendWithReply const): 22 (WebKit::PCM::Connection::connectionToDaemon): Deleted. 23 (WebKit::PCM::Connection::send): Deleted. 24 (WebKit::PCM::Connection::sendWithReply): Deleted. 25 * NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementConnection.h: 26 * NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManagerInterface.cpp: 27 (WebKit::PCM::managerPointer): 28 (WebKit::PCM::initializePCMStorageInDirectory): 29 (WebKit::PCM::daemonManager): 30 * NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManagerInterface.h: 31 * NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManagerProxy.cpp: 32 (WebKit::PCM::ManagerProxy::sendMessage const): 33 (WebKit::PCM::ManagerProxy::sendMessageWithReply const): 34 (WebKit::PCM::ManagerProxy::ManagerProxy): 35 (WebKit::PCM::sendMessage): Deleted. 36 (WebKit::PCM::sendMessageWithReply): Deleted. 37 * NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManagerProxy.h: 38 * NetworkProcess/PrivateClickMeasurement/cocoa/PrivateClickMeasurementDaemonConnectionCocoa.mm: 39 (WebKit::PCM::Connection::Connection): 40 (WebKit::PCM::Connection::initializeConnectionIfNeeded const): 41 (WebKit::PCM::Connection::send const): 42 (WebKit::PCM::Connection::sendWithReply const): 43 (WebKit::PCM::Connection::connectionToDaemon): Deleted. 44 (WebKit::PCM::Connection::send): Deleted. 45 (WebKit::PCM::Connection::sendWithReply): Deleted. 46 * NetworkProcess/mac/com.apple.WebKit.NetworkProcess.sb.in: 47 * Shared/EntryPointUtilities/Cocoa/Daemon/PCMDaemonEntryPoint.mm: 48 (WebKit::startListeningForMachServiceConnections): 49 (WebKit::registerScheduledActivityHandler): 50 (WebKit::PCMDaemonMain): 51 * UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.h: 52 * UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.mm: 53 (-[_WKWebsiteDataStoreConfiguration pcmMachServiceName]): 54 (-[_WKWebsiteDataStoreConfiguration setPCMMachServiceName:]): 55 * UIProcess/WebsiteData/WebsiteDataStore.cpp: 56 (WebKit::WebsiteDataStore::parameters): 57 * UIProcess/WebsiteData/WebsiteDataStoreConfiguration.cpp: 58 (WebKit::WebsiteDataStoreConfiguration::WebsiteDataStoreConfiguration): 59 (WebKit::WebsiteDataStoreConfiguration::copy const): 60 * UIProcess/WebsiteData/WebsiteDataStoreConfiguration.h: 61 (WebKit::WebsiteDataStoreConfiguration::setPCMMachServiceName): 62 (WebKit::WebsiteDataStoreConfiguration::pcmMachServiceName const): 63 1 64 2021-09-13 Tim Horton <timothy_horton@apple.com> 2 65 -
trunk/Source/WebKit/NetworkProcess/NetworkSession.cpp
r282305 r282368 96 96 static UniqueRef<PCM::ManagerInterface> managerOrProxy(NetworkSession& networkSession, NetworkProcess& networkProcess, const NetworkSessionCreationParameters& parameters) 97 97 { 98 // FIXME: Turn this on and remove ManagerInterface once rdar://80701098 is closed. 99 constexpr bool usePCMDaemon = false; 100 101 if (usePCMDaemon) 102 return makeUniqueRef<PCM::ManagerProxy>(); 98 if (!parameters.pcmMachServiceName.isEmpty()) 99 return makeUniqueRef<PCM::ManagerProxy>(parameters.pcmMachServiceName); 103 100 return makeUniqueRef<PrivateClickMeasurementManager>(makeUniqueRef<PCM::ClientImpl>(networkSession, networkProcess), pcmStoreDirectory(networkSession, parameters.resourceLoadStatisticsParameters.directory, parameters.resourceLoadStatisticsParameters.privateClickMeasurementStorageDirectory)); 104 101 } -
trunk/Source/WebKit/NetworkProcess/NetworkSessionCreationParameters.cpp
r280128 r282368 88 88 encoder << useNetworkLoader; 89 89 encoder << allowsHSTSWithUntrustedRootCertificate; 90 encoder << pcmMachServiceName; 90 91 encoder << resourceLoadStatisticsParameters; 91 92 } … … 294 295 if (!allowsHSTSWithUntrustedRootCertificate) 295 296 return std::nullopt; 296 297 298 std::optional<String> pcmMachServiceName; 299 decoder >> pcmMachServiceName; 300 if (!pcmMachServiceName) 301 return std::nullopt; 302 297 303 std::optional<ResourceLoadStatisticsParameters> resourceLoadStatisticsParameters; 298 304 decoder >> resourceLoadStatisticsParameters; 299 305 if (!resourceLoadStatisticsParameters) 300 306 return std::nullopt; 301 307 302 308 return {{ 303 309 *sessionID … … 348 354 , WTFMove(*useNetworkLoader) 349 355 , WTFMove(*allowsHSTSWithUntrustedRootCertificate) 356 , WTFMove(*pcmMachServiceName) 350 357 , WTFMove(*resourceLoadStatisticsParameters) 351 358 }}; -
trunk/Source/WebKit/NetworkProcess/NetworkSessionCreationParameters.h
r280128 r282368 103 103 bool useNetworkLoader { false }; 104 104 bool allowsHSTSWithUntrustedRootCertificate { false }; 105 String pcmMachServiceName; 105 106 106 107 ResourceLoadStatisticsParameters resourceLoadStatisticsParameters; -
trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementConnection.cpp
r282230 r282368 35 35 #if !PLATFORM(COCOA) 36 36 37 Connection Connection::connectionToDaemon() 38 { 39 notImplemented(); 40 return { }; 41 } 42 43 void Connection::send(MessageType, EncodedMessage&&) 37 Connection::Connection(CString&&) 44 38 { 45 39 notImplemented(); 46 40 } 47 41 48 void Connection::sendWithReply(MessageType, EncodedMessage&&, CompletionHandler<void(EncodedMessage&&)>&& completionHandler) 42 void Connection::send(MessageType, EncodedMessage&&) const 43 { 44 notImplemented(); 45 } 46 47 void Connection::sendWithReply(MessageType, EncodedMessage&&, CompletionHandler<void(EncodedMessage&&)>&& completionHandler) const 49 48 { 50 49 notImplemented(); -
trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementConnection.h
r282230 r282368 27 27 28 28 #include <wtf/Vector.h> 29 #include <wtf/WeakPtr.h> 29 30 30 31 #if PLATFORM(COCOA) … … 40 41 using EncodedMessage = Vector<uint8_t>; 41 42 42 class Connection {43 class Connection : public CanMakeWeakPtr<Connection> { 43 44 public: 44 static Connection connectionToDaemon();45 explicit Connection(CString&& machServiceName); 45 46 46 void send(MessageType, EncodedMessage&&) ;47 void sendWithReply(MessageType, EncodedMessage&&, CompletionHandler<void(EncodedMessage&&)>&&) ;47 void send(MessageType, EncodedMessage&&) const; 48 void sendWithReply(MessageType, EncodedMessage&&, CompletionHandler<void(EncodedMessage&&)>&&) const; 48 49 49 50 private: 50 51 #if PLATFORM(COCOA) 51 Connection(OSObjectPtr<xpc_connection_t>&&);52 void initializeConnectionIfNeeded() const; 52 53 53 OSObjectPtr<xpc_connection_t> m_connection; 54 const CString m_machServiceName; 55 mutable OSObjectPtr<xpc_connection_t> m_connection; 54 56 #endif 55 57 }; -
trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManagerInterface.cpp
r282269 r282368 168 168 } 169 169 170 static std::unique_ptr<PrivateClickMeasurementManager>& managerPointer() 171 { 172 static NeverDestroyed<std::unique_ptr<PrivateClickMeasurementManager>> manager; 173 return manager.get(); 174 } 175 176 void initializePCMStorageInDirectory(const String& storageDirectory) 177 { 178 ASSERT(!managerPointer()); 179 managerPointer() = makeUnique<PrivateClickMeasurementManager>(makeUniqueRef<PCM::DaemonClient>(), storageDirectory); 180 } 181 170 182 static PrivateClickMeasurementManager& daemonManager() 171 183 { 172 // FIXME: Give the manager a valid storage directory. 173 static NeverDestroyed<PrivateClickMeasurementManager> instance(makeUniqueRef<PCM::DaemonClient>(), String()); 174 return instance.get(); 184 ASSERT(managerPointer()); 185 return *managerPointer(); 175 186 } 176 187 -
trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManagerInterface.h
r282269 r282368 102 102 bool messageTypeSendsReply(MessageType); 103 103 104 void initializePCMStorageInDirectory(const String&); 105 104 106 } // namespace PCM 105 107 -
trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManagerProxy.cpp
r282269 r282368 36 36 37 37 template<MessageType messageType, typename... Args> 38 void sendMessage(Args&&... args)38 void ManagerProxy::sendMessage(Args&&... args) const 39 39 { 40 40 Encoder encoder; 41 41 encoder.encode(std::forward<Args>(args)...); 42 Connection::connectionToDaemon().send(messageType, encoder.takeBuffer());42 m_connection.send(messageType, encoder.takeBuffer()); 43 43 } 44 44 … … 62 62 63 63 template<MessageType messageType, typename... Args, typename... ReplyArgs> 64 void sendMessageWithReply(CompletionHandler<void(ReplyArgs...)>&& completionHandler, Args&&... args)64 void ManagerProxy::sendMessageWithReply(CompletionHandler<void(ReplyArgs...)>&& completionHandler, Args&&... args) const 65 65 { 66 66 Encoder encoder; 67 67 encoder.encode(std::forward<Args>(args)...); 68 Connection::connectionToDaemon().sendWithReply(messageType, encoder.takeBuffer(), [completionHandler = WTFMove(completionHandler)] (auto replyBuffer) mutable {68 m_connection.sendWithReply(messageType, encoder.takeBuffer(), [completionHandler = WTFMove(completionHandler)] (auto replyBuffer) mutable { 69 69 Decoder decoder(WTFMove(replyBuffer)); 70 70 ReplyCaller<ReplyArgs...>::callReply(WTFMove(decoder), WTFMove(completionHandler)); 71 71 }); 72 72 } 73 74 ManagerProxy::ManagerProxy(const String& machServiceName) 75 : m_connection(machServiceName.utf8()) { } 73 76 74 77 void ManagerProxy::storeUnattributed(WebCore::PrivateClickMeasurement&& pcm) -
trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManagerProxy.h
r282269 r282368 26 26 #pragma once 27 27 28 #include "PrivateClickMeasurementConnection.h" 28 29 #include "PrivateClickMeasurementManagerInterface.h" 29 30 #include <wtf/FastMalloc.h> 31 #include <wtf/text/CString.h> 30 32 31 33 namespace WebKit { … … 36 38 WTF_MAKE_FAST_ALLOCATED; 37 39 public: 40 ManagerProxy(const String& machServiceName); 41 38 42 void storeUnattributed(WebCore::PrivateClickMeasurement&&) final; 39 43 void handleAttribution(WebCore::PrivateClickMeasurement::AttributionTriggerData&&, const URL& requestURL, WebCore::RegistrableDomain&& redirectDomain, const URL& firstPartyURL) final; … … 54 58 void destroyStoreForTesting(CompletionHandler<void()>&&) final; 55 59 void allowTLSCertificateChainForLocalPCMTesting(const WebCore::CertificateInfo&) final; 60 61 private: 62 template<MessageType messageType, typename... Args> 63 void sendMessage(Args&&...) const; 64 template<MessageType messageType, typename... Args, typename... ReplyArgs> 65 void sendMessageWithReply(CompletionHandler<void(ReplyArgs...)>&&, Args&&...) const; 66 67 Connection m_connection; 56 68 }; 57 69 -
trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/cocoa/PrivateClickMeasurementDaemonConnectionCocoa.mm
r282230 r282368 34 34 namespace PCM { 35 35 36 Connection::Connection( OSObjectPtr<xpc_connection_t>&& connection)37 : m_ connection(WTFMove(connection)) { }36 Connection::Connection(CString&& machServiceName) 37 : m_machServiceName(WTFMove(machServiceName)) { } 38 38 39 Connection Connection::connectionToDaemon() 39 void Connection::initializeConnectionIfNeeded() const 40 40 { 41 ASSERT(RunLoop::isMain()); 42 static NeverDestroyed<OSObjectPtr<xpc_connection_t>> connection; 43 if (!connection.get()) { 44 connection.get() = adoptOSObject(xpc_connection_create_mach_service("com.apple.webkit.adattributiond.service", dispatch_get_main_queue(), 0)); 45 xpc_connection_set_event_handler(connection.get().get(), ^(xpc_object_t event) { 46 ASSERT(RunLoop::isMain()); 47 if (event == XPC_ERROR_CONNECTION_INTERRUPTED) { 48 // Daemon crashed, we will need to make a new connection to a new instance of the daemon. 49 connection.get() = nullptr; 50 } else 51 ASSERT_NOT_REACHED(); 52 }); 53 xpc_connection_activate(connection.get().get()); 54 } 55 return Connection(OSObjectPtr<xpc_connection_t>(connection.get())); 41 if (m_connection) 42 return; 43 m_connection = adoptOSObject(xpc_connection_create_mach_service(m_machServiceName.data(), dispatch_get_main_queue(), 0)); 44 xpc_connection_set_event_handler(m_connection.get(), [weakThis = makeWeakPtr(*this)](xpc_object_t event) { 45 if (!weakThis) 46 return; 47 if (event == XPC_ERROR_CONNECTION_INVALID) 48 WTFLogAlways("Failed to connect to mach service %s, likely because it is not registered with launchd", weakThis->m_machServiceName.data()); 49 if (event == XPC_ERROR_CONNECTION_INTERRUPTED) { 50 // Daemon crashed, we will need to make a new connection to a new instance of the daemon. 51 weakThis->m_connection = nullptr; 52 } 53 }); 54 xpc_connection_activate(m_connection.get()); 56 55 } 57 56 … … 64 63 } 65 64 66 void Connection::send(MessageType messageType, EncodedMessage&& message) 65 void Connection::send(MessageType messageType, EncodedMessage&& message) const 67 66 { 68 if (!m_connection) { 69 ASSERT_NOT_REACHED(); 70 return; 71 } 67 ASSERT(RunLoop::isMain()); 68 initializeConnectionIfNeeded(); 72 69 73 70 xpc_connection_send_message(m_connection.get(), dictionaryFromMessage(messageType, WTFMove(message)).get()); 74 71 } 75 72 76 void Connection::sendWithReply(MessageType messageType, EncodedMessage&& message, CompletionHandler<void(EncodedMessage&&)>&& completionHandler) 73 void Connection::sendWithReply(MessageType messageType, EncodedMessage&& message, CompletionHandler<void(EncodedMessage&&)>&& completionHandler) const 77 74 { 78 if (!m_connection) { 79 ASSERT_NOT_REACHED(); 80 return completionHandler({ }); 81 } 75 ASSERT(RunLoop::isMain()); 76 initializeConnectionIfNeeded(); 82 77 83 78 auto dictionary = dictionaryFromMessage(messageType, WTFMove(message)); 84 79 xpc_connection_send_message_with_reply(m_connection.get(), dictionary.get(), dispatch_get_main_queue(), makeBlockPtr([completionHandler = WTFMove(completionHandler)] (xpc_object_t reply) mutable { 80 ASSERT(RunLoop::isMain()); 85 81 if (xpc_get_type(reply) != XPC_TYPE_DICTIONARY) { 86 82 ASSERT_NOT_REACHED(); -
trunk/Source/WebKit/NetworkProcess/mac/com.apple.WebKit.NetworkProcess.sb.in
r282230 r282368 359 359 360 360 (allow mach-lookup (global-name "com.apple.webkit.adattributiond.service")) 361 (allow mach-lookup (global-name "org.webkit.pcmtestdaemon.service")) 361 362 362 363 (with-filter (uid 0) -
trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/Daemon/PCMDaemonEntryPoint.mm
r282269 r282368 32 32 #import <Foundation/Foundation.h> 33 33 #import <wtf/CompletionHandler.h> 34 #import <wtf/FileSystem.h> 34 35 #import <wtf/HashSet.h> 35 36 #import <wtf/NeverDestroyed.h> … … 77 78 } 78 79 79 static void startListeningForMachServiceConnections( )80 static void startListeningForMachServiceConnections(const char* serviceName) 80 81 { 81 static NeverDestroyed<OSObjectPtr<xpc_connection_t>> listener = xpc_connection_create_mach_service( "com.apple.webkit.adattributiond.service", dispatch_get_main_queue(), XPC_CONNECTION_MACH_SERVICE_LISTENER);82 static NeverDestroyed<OSObjectPtr<xpc_connection_t>> listener = xpc_connection_create_mach_service(serviceName, dispatch_get_main_queue(), XPC_CONNECTION_MACH_SERVICE_LISTENER); 82 83 xpc_connection_set_event_handler(listener.get().get(), ^(xpc_object_t peer) { 83 84 if (xpc_get_type(peer) != XPC_TYPE_CONNECTION) … … 87 88 88 89 xpc_connection_set_event_handler(peer, ^(xpc_object_t event) { 90 if (event == XPC_ERROR_CONNECTION_INVALID) 91 NSLog(@"Failed to start listening for connections to mach service %s, likely because it is not registered with launchd", serviceName); 89 92 if (event == XPC_ERROR_CONNECTION_INTERRUPTED) { 90 93 NSLog(@"removing peer connection %p", peer); … … 105 108 static void registerScheduledActivityHandler() 106 109 { 110 NSLog(@"Registering XPC activity"); 107 111 xpc_activity_register("com.apple.webkit.adattributiond.activity", XPC_ACTIVITY_CHECK_IN, ^(xpc_activity_t activity) { 108 112 if (xpc_activity_get_state(activity) == XPC_ACTIVITY_STATE_CHECK_IN) { … … 126 130 int PCMDaemonMain(int argc, const char** argv) 127 131 { 128 if (argc != 2 || strcmp(argv[1], "runAsDaemon")) {129 NSLog(@" This executable is intended to be run as a daemon.");132 if (argc < 5 || strcmp(argv[1], "--machServiceName") || strcmp(argv[3], "--storageLocation")) { 133 NSLog(@"Usage: %s --machServiceName <name> --storageLocation <location> [--startActivity]", argv[0]); 130 134 return -1; 131 135 } 136 const char* machServiceName = argv[2]; 137 const char* storageLocation = argv[4]; 138 bool startActivity = argc > 5 && !strcmp(argv[5], "--startActivity"); 139 132 140 @autoreleasepool { 133 141 enterSandbox(); 134 startListeningForMachServiceConnections(); 135 registerScheduledActivityHandler(); 142 startListeningForMachServiceConnections(machServiceName); 143 if (startActivity) 144 registerScheduledActivityHandler(); 136 145 WTF::initializeMainThread(); 146 PCM::initializePCMStorageInDirectory(FileSystem::stringFromFileSystemRepresentation(storageLocation)); 137 147 } 138 148 CFRunLoopRun(); -
trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.h
r282130 r282368 77 77 @property (nonatomic) BOOL enableInAppBrowserPrivacyForTesting WK_API_AVAILABLE(macos(12.0), ios(15.0)); 78 78 @property (nonatomic) BOOL allowsHSTSWithUntrustedRootCertificate WK_API_AVAILABLE(macos(12.0), ios(15.0)); 79 @property (nonatomic, nullable, copy, setter=setPCMMachServiceName:) NSString *pcmMachServiceName WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA)); 79 80 80 81 @property (nonatomic, nullable, copy) NSURL *alternativeServicesStorageDirectory WK_API_AVAILABLE(macos(11.0), ios(14.0)); -
trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.mm
r282130 r282368 522 522 } 523 523 524 - (NSString *)pcmMachServiceName 525 { 526 return _configuration->pcmMachServiceName(); 527 } 528 529 - (void)setPCMMachServiceName:(NSString *)name 530 { 531 _configuration->setPCMMachServiceName(name); 532 } 533 524 534 - (BOOL)allLoadsBlockedByDeviceManagementRestrictionsForTesting 525 535 { -
trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp
r282269 r282368 2061 2061 networkSessionParameters.preventsSystemHTTPProxyAuthentication = m_configuration->preventsSystemHTTPProxyAuthentication(); 2062 2062 networkSessionParameters.allowsHSTSWithUntrustedRootCertificate = m_configuration->allowsHSTSWithUntrustedRootCertificate(); 2063 networkSessionParameters.pcmMachServiceName = m_configuration->pcmMachServiceName(); 2063 2064 2064 2065 parameters.networkSessionParameters = WTFMove(networkSessionParameters); -
trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStoreConfiguration.cpp
r282130 r282368 52 52 setModelElementCacheDirectory(WebsiteDataStore::defaultModelElementCacheDirectory()); 53 53 #endif 54 // FIXME: Give m_pcmMachServiceName a default value and remove PCM::ManagerInterface once rdar://80701098 is closed. 54 55 } 55 56 } … … 101 102 copy->m_enableInAppBrowserPrivacyForTesting = this->m_enableInAppBrowserPrivacyForTesting; 102 103 copy->m_allowsHSTSWithUntrustedRootCertificate = this->m_allowsHSTSWithUntrustedRootCertificate; 104 copy->m_pcmMachServiceName = this->m_pcmMachServiceName; 103 105 #if PLATFORM(COCOA) 104 106 if (m_proxyConfiguration) -
trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStoreConfiguration.h
r282130 r282368 181 181 void setAllowsHSTSWithUntrustedRootCertificate(bool allows) { m_allowsHSTSWithUntrustedRootCertificate = allows; } 182 182 183 void setPCMMachServiceName(String&& name) { m_pcmMachServiceName = WTFMove(name); } 184 const String& pcmMachServiceName() const { return m_pcmMachServiceName; } 185 183 186 private: 184 187 IsPersistent m_isPersistent { IsPersistent::No }; … … 233 236 bool m_enableInAppBrowserPrivacyForTesting { false }; 234 237 bool m_allowsHSTSWithUntrustedRootCertificate { false }; 238 String m_pcmMachServiceName; 235 239 #if PLATFORM(COCOA) 236 240 RetainPtr<CFDictionaryRef> m_proxyConfiguration; -
trunk/Tools/ChangeLog
r282365 r282368 1 2021-09-13 Alex Christensen <achristensen@webkit.org> 2 3 Add unit test that uses PCM daemon 4 https://bugs.webkit.org/show_bug.cgi?id=230191 5 6 Reviewed by Chris Dumez. 7 8 * TestWebKitAPI/Configurations/TestPCMDaemon.xcconfig: Added. 9 * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: 10 * TestWebKitAPI/Tests/WebKitCocoa/EventAttribution.mm: 11 (TestWebKitAPI::currentExecutableLocation): 12 (TestWebKitAPI::testDaemonPList): 13 (TestWebKitAPI::TEST): 14 * TestWebKitAPI/cocoa/TestPCMDaemonMain.c: Copied from Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementConnection.cpp. 15 (main): 16 1 17 2021-09-13 Chris Dumez <cdumez@apple.com> 2 18 -
trunk/Tools/TestWebKitAPI/Configurations/TestWebKitAPI-macOS-internal.entitlements
r270381 r282368 3 3 <plist version="1.0"> 4 4 <dict> 5 <key>com.apple.private.xpc.launchd.job-manager</key> 6 <string>TestWebKitAPI</string> 5 7 <key>com.apple.hid.manager.user-access-device</key> 6 8 <true/> -
trunk/Tools/TestWebKitAPI/Configurations/TestWebKitAPI-macOS.entitlements
r270381 r282368 3 3 <plist version="1.0"> 4 4 <dict> 5 <key>com.apple.private.xpc.launchd.job-manager</key> 6 <string>TestWebKitAPI</string> 5 7 <key>keychain-access-groups</key> 6 8 <array> -
trunk/Tools/TestWebKitAPI/Configurations/TestWebKitAPI.xcconfig
r279479 r282368 44 44 FRAMEWORK_SEARCH_PATHS_cocoatouch = $(inherited) $(WK_PRIVATE_FRAMEWORKS_DIR); 45 45 46 WK_APPSERVERSUPPORT_LDFLAGS = $(WK_APPSERVERSUPPORT_LDFLAGS_$(WK_PLATFORM_NAME)); 47 WK_APPSERVERSUPPORT_LDFLAGS_macosx = $(WK_APPSERVERSUPPORT_LDFLAGS$(WK_MACOS_1200)); 48 WK_APPSERVERSUPPORT_LDFLAGS_MACOS_SINCE_1200 = -framework AppServerSupport 49 46 50 WK_AUTHKIT_LDFLAGS = $(WK_AUTHKIT_LDFLAGS_$(WK_PLATFORM_NAME)); 47 51 WK_AUTHKIT_LDFLAGS_iphoneos = $(WK_AUTHKIT_LDFLAGS$(WK_IOS_13)); … … 87 91 OTHER_CPLUSPLUSFLAGS = $(inherited) -isystem $(SDKROOT)/System/Library/Frameworks/System.framework/PrivateHeaders; 88 92 89 OTHER_LDFLAGS = $(inherited) -lgtest -force_load $(BUILT_PRODUCTS_DIR)/libTestWebKitAPI.a -framework JavaScriptCore -framework WebKit -lWebCoreTestSupport $(WK_A UTHKIT_LDFLAGS) -framework Network $(WK_HID_LDFLAGS) $(WK_OPENGL_LDFLAGS) $(WK_PDFKIT_LDFLAGS) $(WK_SYSTEM_LDFLAGS) $(WK_UIKITMACHELPER_LDFLAGS) $(WK_VISIONKITCORE_LDFLAGS) $(OTHER_LDFLAGS_PLATFORM_$(WK_COCOA_TOUCH));93 OTHER_LDFLAGS = $(inherited) -lgtest -force_load $(BUILT_PRODUCTS_DIR)/libTestWebKitAPI.a -framework JavaScriptCore -framework WebKit -lWebCoreTestSupport $(WK_APPSERVERSUPPORT_LDFLAGS) $(WK_AUTHKIT_LDFLAGS) -framework Network $(WK_HID_LDFLAGS) $(WK_OPENGL_LDFLAGS) $(WK_PDFKIT_LDFLAGS) $(WK_SYSTEM_LDFLAGS) $(WK_UIKITMACHELPER_LDFLAGS) $(WK_VISIONKITCORE_LDFLAGS) $(OTHER_LDFLAGS_PLATFORM_$(WK_COCOA_TOUCH)); 90 94 OTHER_LDFLAGS_PLATFORM_ = -framework Cocoa -framework Carbon; 91 95 -
trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
r281779 r282368 37 37 ); 38 38 dependencies = ( 39 5C1B1D1C26EC2EEC00882DA2 /* PBXTargetDependency */, 39 40 7C83E0301D0A5E1B00FEBCF3 /* PBXTargetDependency */, 40 41 7C83E0321D0A5E1D00FEBCF3 /* PBXTargetDependency */, … … 479 480 5C16F8FC230C94370074C4A8 /* TextSize.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C16F8FB230C942B0074C4A8 /* TextSize.mm */; }; 480 481 5C19A5241FD0F60100EEA323 /* CookiePrivateBrowsing.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C19A5231FD0F32600EEA323 /* CookiePrivateBrowsing.mm */; }; 482 5C1B1D1726EC27DE00882DA2 /* TestPCMDaemonMain.c in Sources */ = {isa = PBXBuildFile; fileRef = 5C1B1D1626EC27C500882DA2 /* TestPCMDaemonMain.c */; }; 481 483 5C23DF0B2246015800F454B6 /* Challenge.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C23DF0A2245C9D700F454B6 /* Challenge.mm */; }; 482 484 5C2936931D5BF70D00DEAB1E /* CookieAcceptPolicy.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C2936911D5BF63E00DEAB1E /* CookieAcceptPolicy.mm */; }; … … 1298 1300 1299 1301 /* Begin PBXContainerItemProxy section */ 1302 5C1B1D1B26EC2EEC00882DA2 /* PBXContainerItemProxy */ = { 1303 isa = PBXContainerItemProxy; 1304 containerPortal = 08FB7793FE84155DC02AAC07 /* Project object */; 1305 proxyType = 1; 1306 remoteGlobalIDString = 5C1B1D0826EC278500882DA2; 1307 remoteInfo = TestPCMDaemon; 1308 }; 1300 1309 5C9D922122D7DC84008E9266 /* PBXContainerItemProxy */ = { 1301 1310 isa = PBXContainerItemProxy; … … 2332 2341 5C16F8FB230C942B0074C4A8 /* TextSize.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TextSize.mm; sourceTree = "<group>"; }; 2333 2342 5C19A5231FD0F32600EEA323 /* CookiePrivateBrowsing.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CookiePrivateBrowsing.mm; sourceTree = "<group>"; }; 2343 5C1B1D1426EC278500882DA2 /* TestPCMDaemon */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = TestPCMDaemon; sourceTree = BUILT_PRODUCTS_DIR; }; 2344 5C1B1D1626EC27C500882DA2 /* TestPCMDaemonMain.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = TestPCMDaemonMain.c; path = cocoa/TestPCMDaemonMain.c; sourceTree = "<group>"; }; 2345 5C1B1D1A26EC284E00882DA2 /* TestPCMDaemon.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = TestPCMDaemon.xcconfig; sourceTree = "<group>"; }; 2334 2346 5C23DF0A2245C9D700F454B6 /* Challenge.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Challenge.mm; sourceTree = "<group>"; }; 2335 2347 5C2936911D5BF63E00DEAB1E /* CookieAcceptPolicy.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CookieAcceptPolicy.mm; sourceTree = "<group>"; }; … … 3163 3175 3164 3176 /* Begin PBXFrameworksBuildPhase section */ 3177 5C1B1D0E26EC278500882DA2 /* Frameworks */ = { 3178 isa = PBXFrameworksBuildPhase; 3179 buildActionMask = 2147483647; 3180 files = ( 3181 ); 3182 runOnlyForDeploymentPostprocessing = 0; 3183 }; 3165 3184 7C83DF641D0A590C00FEBCF3 /* Frameworks */ = { 3166 3185 isa = PBXFrameworksBuildPhase; … … 3307 3326 2D1C04A51D76298B000A6816 /* TestNavigationDelegate.h */, 3308 3327 2D1C04A61D76298B000A6816 /* TestNavigationDelegate.mm */, 3328 5C1B1D1626EC27C500882DA2 /* TestPCMDaemonMain.c */, 3309 3329 516281232325C17A00BB7E42 /* TestPDFDocument.h */, 3310 3330 516281242325C17B00BB7E42 /* TestPDFDocument.mm */, … … 3365 3385 isa = PBXGroup; 3366 3386 children = ( 3387 5C1B1D1426EC278500882DA2 /* TestPCMDaemon */, 3367 3388 8DD76FA10486AA7600D96B5E /* TestWebKitAPI */, 3368 3389 7C83E0231D0A5AE400FEBCF3 /* TestWTF */, … … 4294 4315 BC575AE2126E88B1006F0F12 /* InjectedBundle.xcconfig */, 4295 4316 A1B89B99221E029F00EB4CEA /* SDKVariant.xcconfig */, 4317 5C1B1D1A26EC284E00882DA2 /* TestPCMDaemon.xcconfig */, 4296 4318 5735F0251F3A4EA6000EE801 /* TestWebKitAPI-iOS.entitlements */, 4297 4319 51EB125324C66BCB000CB030 /* TestWebKitAPI-macOS-internal.entitlements */, … … 4980 5002 4981 5003 /* Begin PBXNativeTarget section */ 5004 5C1B1D0826EC278500882DA2 /* TestPCMDaemon */ = { 5005 isa = PBXNativeTarget; 5006 buildConfigurationList = 5C1B1D1126EC278500882DA2 /* Build configuration list for PBXNativeTarget "TestPCMDaemon" */; 5007 buildPhases = ( 5008 5C1B1D0B26EC278500882DA2 /* Sources */, 5009 5C1B1D0E26EC278500882DA2 /* Frameworks */, 5010 ); 5011 buildRules = ( 5012 ); 5013 dependencies = ( 5014 ); 5015 name = TestPCMDaemon; 5016 productInstallPath = "$(HOME)/bin"; 5017 productName = TestPCMDaemon; 5018 productReference = 5C1B1D1426EC278500882DA2 /* TestPCMDaemon */; 5019 productType = "com.apple.product-type.tool"; 5020 }; 4982 5021 7C83DE951D0A590C00FEBCF3 /* TestWTFLibrary */ = { 4983 5022 isa = PBXNativeTarget; … … 5139 5178 A13EBB481B87339E00097110 /* WebProcessPlugIn */, 5140 5179 537CF84322EFD64100C6EBB3 /* Apply Configuration to XCFileLists */, 5180 5C1B1D0826EC278500882DA2 /* TestPCMDaemon */, 5141 5181 ); 5142 5182 }; … … 5215 5255 5216 5256 /* Begin PBXSourcesBuildPhase section */ 5257 5C1B1D0B26EC278500882DA2 /* Sources */ = { 5258 isa = PBXSourcesBuildPhase; 5259 buildActionMask = 2147483647; 5260 files = ( 5261 5C1B1D1726EC27DE00882DA2 /* TestPCMDaemonMain.c in Sources */, 5262 ); 5263 runOnlyForDeploymentPostprocessing = 0; 5264 }; 5217 5265 7C83DE961D0A590C00FEBCF3 /* Sources */ = { 5218 5266 isa = PBXSourcesBuildPhase; … … 6079 6127 6080 6128 /* Begin PBXTargetDependency section */ 6129 5C1B1D1C26EC2EEC00882DA2 /* PBXTargetDependency */ = { 6130 isa = PBXTargetDependency; 6131 target = 5C1B1D0826EC278500882DA2 /* TestPCMDaemon */; 6132 targetProxy = 5C1B1D1B26EC2EEC00882DA2 /* PBXContainerItemProxy */; 6133 }; 6081 6134 5C9D922222D7DC84008E9266 /* PBXTargetDependency */ = { 6082 6135 isa = PBXTargetDependency; … … 6161 6214 name = Release; 6162 6215 }; 6216 5C1B1D1226EC278500882DA2 /* Debug */ = { 6217 isa = XCBuildConfiguration; 6218 baseConfigurationReference = 5C1B1D1A26EC284E00882DA2 /* TestPCMDaemon.xcconfig */; 6219 buildSettings = { 6220 PRODUCT_NAME = "$(TARGET_NAME)"; 6221 }; 6222 name = Debug; 6223 }; 6224 5C1B1D1326EC278500882DA2 /* Release */ = { 6225 isa = XCBuildConfiguration; 6226 baseConfigurationReference = 5C1B1D1A26EC284E00882DA2 /* TestPCMDaemon.xcconfig */; 6227 buildSettings = { 6228 PRODUCT_NAME = "$(TARGET_NAME)"; 6229 }; 6230 name = Release; 6231 }; 6163 6232 5C9D921A22D7DA02008E9266 /* Debug */ = { 6164 6233 isa = XCBuildConfiguration; … … 6289 6358 defaultConfigurationName = Release; 6290 6359 }; 6360 5C1B1D1126EC278500882DA2 /* Build configuration list for PBXNativeTarget "TestPCMDaemon" */ = { 6361 isa = XCConfigurationList; 6362 buildConfigurations = ( 6363 5C1B1D1226EC278500882DA2 /* Debug */, 6364 5C1B1D1326EC278500882DA2 /* Release */, 6365 ); 6366 defaultConfigurationIsVisible = 0; 6367 defaultConfigurationName = Release; 6368 }; 6291 6369 5C9D921922D7DA02008E9266 /* Build configuration list for PBXAggregateTarget "Generate Unified Sources" */ = { 6292 6370 isa = XCConfigurationList; -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/EventAttribution.mm
r282269 r282368 28 28 #import "HTTPServer.h" 29 29 #import "PlatformUtilities.h" 30 #import "Test.h" 30 31 #import "TestNavigationDelegate.h" 31 32 #import "TestWKWebView.h" 32 33 #import "Utilities.h" 34 #import <WebKit/WKMain.h> 33 35 #import <WebKit/WKWebViewPrivate.h> 34 36 #import <WebKit/WKWebViewPrivateForTesting.h> 35 37 #import <WebKit/WKWebsiteDataStorePrivate.h> 36 38 #import <WebKit/_WKWebsiteDataStoreConfiguration.h> 39 #import <mach-o/dyld.h> 40 #import <wtf/OSObjectPtr.h> 41 #import <wtf/spi/darwin/XPCSPI.h> 37 42 38 43 #if HAVE(RSA_BSSA) … … 361 366 } 362 367 368 // FIXME: Get this working in the iOS simulator. 369 #if PLATFORM(MAC) 370 371 static RetainPtr<NSURL> currentExecutableLocation() 372 { 373 uint32_t size { 0 }; 374 _NSGetExecutablePath(nullptr, &size); 375 Vector<char> buffer; 376 buffer.resize(size + 1); 377 _NSGetExecutablePath(buffer.data(), &size); 378 buffer[size] = '\0'; 379 auto pathString = adoptNS([[NSString alloc] initWithUTF8String:buffer.data()]); 380 return adoptNS([[NSURL alloc] initFileURLWithPath:pathString.get() isDirectory:NO]); 381 } 382 383 static RetainPtr<NSURL> currentExecutableDirectory() 384 { 385 return [currentExecutableLocation() URLByDeletingLastPathComponent]; 386 } 387 388 static RetainPtr<NSURL> testPCMDaemonLocation() 389 { 390 return [currentExecutableDirectory() URLByAppendingPathComponent:@"TestPCMDaemon" isDirectory:NO]; 391 } 392 393 #if HAVE(OS_LAUNCHD_JOB) 394 395 static OSObjectPtr<xpc_object_t> testDaemonPList(NSURL *storageLocation) 396 { 397 auto plist = adoptOSObject(xpc_dictionary_create(nullptr, nullptr, 0)); 398 xpc_dictionary_set_string(plist.get(), "_ManagedBy", "TestWebKitAPI"); 399 xpc_dictionary_set_string(plist.get(), "Label", "org.webkit.pcmtestdaemon"); 400 xpc_dictionary_set_bool(plist.get(), "LaunchOnlyOnce", true); 401 402 { 403 auto environmentVariables = adoptOSObject(xpc_dictionary_create(nullptr, nullptr, 0)); 404 xpc_dictionary_set_string(environmentVariables.get(), "DYLD_FRAMEWORK_PATH", currentExecutableDirectory().get().fileSystemRepresentation); 405 xpc_dictionary_set_value(plist.get(), "EnvironmentVariables", environmentVariables.get()); 406 } 407 { 408 auto machServices = adoptOSObject(xpc_dictionary_create(nullptr, nullptr, 0)); 409 xpc_dictionary_set_bool(machServices.get(), "org.webkit.pcmtestdaemon.service", true); 410 xpc_dictionary_set_value(plist.get(), "MachServices", machServices.get()); 411 } 412 { 413 auto programArguments = adoptOSObject(xpc_array_create(nullptr, 0)); 414 auto executableLocation = testPCMDaemonLocation(); 415 xpc_array_set_string(programArguments.get(), XPC_ARRAY_APPEND, executableLocation.get().fileSystemRepresentation); 416 xpc_array_set_string(programArguments.get(), XPC_ARRAY_APPEND, "--machServiceName"); 417 xpc_array_set_string(programArguments.get(), XPC_ARRAY_APPEND, "org.webkit.pcmtestdaemon.service"); 418 xpc_array_set_string(programArguments.get(), XPC_ARRAY_APPEND, "--storageLocation"); 419 xpc_array_set_string(programArguments.get(), XPC_ARRAY_APPEND, storageLocation.fileSystemRepresentation); 420 xpc_dictionary_set_value(plist.get(), "ProgramArguments", programArguments.get()); 421 } 422 return plist; 423 } 424 425 #else 426 427 static RetainPtr<NSDictionary> testDaemonPList(NSURL *storageLocation) 428 { 429 return @{ 430 @"Label" : @"org.webkit.pcmtestdaemon", 431 @"LaunchOnlyOnce" : @YES, 432 @"EnvironmentVariables" : @{ @"DYLD_FRAMEWORK_PATH" : currentExecutableDirectory().get().path }, 433 @"MachServices" : @{ @"org.webkit.pcmtestdaemon.service" : @YES }, 434 @"ProgramArguments" : @[ 435 testPCMDaemonLocation().get().path, 436 @"--machServiceName", 437 @"org.webkit.pcmtestdaemon.service", 438 @"--storageLocation", 439 storageLocation.path 440 ] 441 }; 442 } 443 444 #endif 445 446 TEST(EventAttribution, Daemon) 447 { 448 NSFileManager *fileManager = [NSFileManager defaultManager]; 449 NSURL *tempDir = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"EventAttributionDaemonTest"] isDirectory:YES]; 450 NSError *error = nil; 451 if ([fileManager fileExistsAtPath:tempDir.path]) 452 [fileManager removeItemAtURL:tempDir error:&error]; 453 EXPECT_NULL(error); 454 455 auto plist = testDaemonPList(tempDir); 456 #if HAVE(OS_LAUNCHD_JOB) 457 auto launchDJob = adoptNS([[OSLaunchdJob alloc] initWithPlist:plist.get()]); 458 [launchDJob submit:&error]; 459 #else 460 NSURL *plistLocation = [tempDir URLByAppendingPathComponent:@"DaemonInfo.plist"]; 461 BOOL success = [fileManager createDirectoryAtURL:tempDir withIntermediateDirectories:YES attributes:nil error:&error]; 462 EXPECT_TRUE(success); 463 EXPECT_NULL(error); 464 success = [plist writeToURL:plistLocation error:&error]; 465 EXPECT_TRUE(success); 466 system([NSString stringWithFormat:@"launchctl load %@", plistLocation.path].UTF8String); 467 #endif 468 EXPECT_NULL(error); 469 470 auto dataStoreConfiguration = adoptNS([_WKWebsiteDataStoreConfiguration new]); 471 dataStoreConfiguration.get().pcmMachServiceName = @"org.webkit.pcmtestdaemon.service"; 472 auto viewConfiguration = adoptNS([WKWebViewConfiguration new]); 473 viewConfiguration.get().websiteDataStore = adoptNS([[WKWebsiteDataStore alloc] _initWithConfiguration:dataStoreConfiguration.get()]).get(); 474 runBasicEventAttributionTest(viewConfiguration.get(), [](WKWebView *webView, const HTTPServer& server) { 475 [webView _addEventAttributionWithSourceID:42 destinationURL:exampleURL() sourceDescription:@"test source description" purchaser:@"test purchaser" reportEndpoint:server.request().URL optionalNonce:nil]; 476 }); 477 478 system("killall TestPCMDaemon -9"); 479 #if HAVE(OS_LAUNCHD_JOB) 480 // LaunchOnlyOnce takes care of cleanup with launchd. 481 #else 482 system([NSString stringWithFormat:@"launchctl unload %@", plistLocation.path].UTF8String); 483 #endif 484 485 EXPECT_TRUE([fileManager fileExistsAtPath:tempDir.path]); 486 [fileManager removeItemAtURL:tempDir error:&error]; 487 EXPECT_NULL(error); 488 } 489 490 #endif // PLATFORM(MAC) 491 363 492 #if HAVE(UI_EVENT_ATTRIBUTION) 364 493
Note:
See TracChangeset
for help on using the changeset viewer.