Diff
Modified: trunk/Source/WebKit/ChangeLog (281348 => 281349)
--- trunk/Source/WebKit/ChangeLog 2021-08-20 22:58:48 UTC (rev 281348)
+++ trunk/Source/WebKit/ChangeLog 2021-08-20 23:01:58 UTC (rev 281349)
@@ -1,3 +1,29 @@
+2021-08-20 Alex Christensen <[email protected]>
+
+ Make UIEventAttribution tests less platform dependent
+ https://bugs.webkit.org/show_bug.cgi?id=229323
+
+ Reviewed by John Wilander.
+
+ This allows me to run the UIEventAttribution tests on macOS.
+ It also makes them not time out, which they were doing since r277447.
+ To accomplish this, I added more test SPI to prevent the network process
+ suspension message, which was causing the test to time out on the iOS simulator.
+
+ * UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h:
+ * UIProcess/API/Cocoa/WKWebViewTesting.mm:
+ (-[WKWebView _addEventAttributionWithSourceID:destinationURL:sourceDescription:purchaser:reportEndpoint:optionalNonce:]):
+ * UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
+ (+[WKWebsiteDataStore _preventNetworkProcessSuspensionForTesting]):
+ * UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
+ * UIProcess/API/ios/WKWebViewPrivateForTestingIOS.h:
+ * UIProcess/API/ios/WKWebViewTestingIOS.mm:
+ (-[WKWebView _setUIEventAttributionForTesting:withNonce:]): Deleted.
+ * UIProcess/Network/NetworkProcessProxy.cpp:
+ (WebKit::NetworkProcessProxy::preventSuspensionForTesting):
+ (WebKit::NetworkProcessProxy::sendPrepareToSuspend):
+ * UIProcess/Network/NetworkProcessProxy.h:
+
2021-08-20 Simon Fraser <[email protected]>
Change the mysterious uint64_t argument to detectDataInAllFrames() to OptionSet<WebCore::DataDetectorType>
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h (281348 => 281349)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h 2021-08-20 22:58:48 UTC (rev 281348)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h 2021-08-20 23:01:58 UTC (rev 281349)
@@ -44,6 +44,8 @@
@interface WKWebView (WKTesting)
+- (void)_addEventAttributionWithSourceID:(uint8_t)sourceID destinationURL:(NSURL *)destination sourceDescription:(NSString *)sourceDescription purchaser:(NSString *)purchaser reportEndpoint:(NSURL *)reportEndpoint optionalNonce:(nullable NSString *)nonce WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+
- (void)_setPageScale:(CGFloat)scale withOrigin:(CGPoint)origin;
- (CGFloat)_pageScale;
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm (281348 => 281349)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm 2021-08-20 22:58:48 UTC (rev 281348)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm 2021-08-20 23:01:58 UTC (rev 281349)
@@ -55,6 +55,21 @@
@implementation WKWebView (WKTesting)
+- (void)_addEventAttributionWithSourceID:(uint8_t)sourceID destinationURL:(NSURL *)destination sourceDescription:(NSString *)sourceDescription purchaser:(NSString *)purchaser reportEndpoint:(NSURL *)reportEndpoint optionalNonce:(NSString *)nonce
+{
+ WebCore::PrivateClickMeasurement measurement(
+ WebCore::PrivateClickMeasurement::SourceID(sourceID),
+ WebCore::PrivateClickMeasurement::SourceSite(reportEndpoint),
+ WebCore::PrivateClickMeasurement::AttributionDestinationSite(destination),
+ sourceDescription,
+ purchaser
+ );
+ if (nonce)
+ measurement.setEphemeralSourceNonce({ nonce });
+
+ _page->setPrivateClickMeasurement(WTFMove(measurement));
+}
+
- (void)_setPageScale:(CGFloat)scale withOrigin:(CGPoint)origin
{
_page->scalePage(scale, WebCore::roundedIntPoint(origin));
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm (281348 => 281349)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm 2021-08-20 22:58:48 UTC (rev 281348)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm 2021-08-20 23:01:58 UTC (rev 281349)
@@ -731,6 +731,11 @@
WebKit::WebsiteDataStore::makeNextNetworkProcessLaunchFailForTesting();
}
++ (void)_preventNetworkProcessSuspensionForTesting
+{
+ WebKit::NetworkProcessProxy::preventSuspensionForTesting();
+}
+
- (BOOL)_networkProcessExists
{
return !!_websiteDataStore->networkProcessIfExists();
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h (281348 => 281349)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h 2021-08-20 22:58:48 UTC (rev 281348)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h 2021-08-20 23:01:58 UTC (rev 281349)
@@ -95,6 +95,7 @@
- (void)_sendNetworkProcessPrepareToSuspend:(void(^)(void))completionHandler WK_API_AVAILABLE(macos(12.0), ios(15.0));
- (void)_sendNetworkProcessWillSuspendImminently WK_API_AVAILABLE(macos(12.0), ios(15.0));
- (void)_sendNetworkProcessDidResume WK_API_AVAILABLE(macos(12.0), ios(15.0));
++ (void)_preventNetworkProcessSuspensionForTesting WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
- (void)_synthesizeAppIsBackground:(BOOL)background WK_API_AVAILABLE(macos(12.0), ios(15.0));
- (pid_t)_networkProcessIdentifier WK_API_AVAILABLE(macos(12.0), ios(15.0));
+ (void)_makeNextNetworkProcessLaunchFailForTesting WK_API_AVAILABLE(macos(12.0), ios(15.0));
Modified: trunk/Source/WebKit/UIProcess/API/ios/WKWebViewPrivateForTestingIOS.h (281348 => 281349)
--- trunk/Source/WebKit/UIProcess/API/ios/WKWebViewPrivateForTestingIOS.h 2021-08-20 22:58:48 UTC (rev 281348)
+++ trunk/Source/WebKit/UIProcess/API/ios/WKWebViewPrivateForTestingIOS.h 2021-08-20 23:01:58 UTC (rev 281349)
@@ -87,10 +87,6 @@
- (void)_setDeviceHasAGXCompilerServiceForTesting;
-#if !TARGET_OS_TV && !TARGET_OS_WATCH
-- (void)_setUIEventAttributionForTesting:(UIEventAttribution *)attribution withNonce:(NSString *)nonce;
-#endif
-
- (NSString *)_serializedSelectionCaretBackgroundColorForTesting;
@end
Modified: trunk/Source/WebKit/UIProcess/API/ios/WKWebViewTestingIOS.mm (281348 => 281349)
--- trunk/Source/WebKit/UIProcess/API/ios/WKWebViewTestingIOS.mm 2021-08-20 22:58:48 UTC (rev 281348)
+++ trunk/Source/WebKit/UIProcess/API/ios/WKWebViewTestingIOS.mm 2021-08-20 23:01:58 UTC (rev 281349)
@@ -465,27 +465,6 @@
_page->setDeviceHasAGXCompilerServiceForTesting();
}
-#if !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
-- (void)_setUIEventAttributionForTesting:(UIEventAttribution *)attribution withNonce:(NSString *)nonce
-{
-#if HAVE(UI_EVENT_ATTRIBUTION)
- if (attribution) {
- WebCore::PrivateClickMeasurement measurement(
- WebCore::PrivateClickMeasurement::SourceID(attribution.sourceIdentifier),
- WebCore::PrivateClickMeasurement::SourceSite(attribution.reportEndpoint),
- WebCore::PrivateClickMeasurement::AttributionDestinationSite(attribution.destinationURL),
- attribution.sourceDescription,
- attribution.purchaser
- );
- measurement.setEphemeralSourceNonce({ nonce });
-
- _page->setPrivateClickMeasurement(WTFMove(measurement));
- } else
- _page->setPrivateClickMeasurement(std::nullopt);
-#endif
-}
-#endif
-
- (NSString *)_serializedSelectionCaretBackgroundColorForTesting
{
UIColor *backgroundColor = [[_contentView textInteractionAssistant].selectionView valueForKeyPath:@"caretView.backgroundColor"];
Modified: trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp (281348 => 281349)
--- trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp 2021-08-20 22:58:48 UTC (rev 281348)
+++ trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp 2021-08-20 23:01:58 UTC (rev 281349)
@@ -1250,9 +1250,17 @@
if (canSendMessage())
sendSync(Messages::NetworkProcess::ProcessWillSuspendImminentlyForTestingSync(), Messages::NetworkProcess::ProcessWillSuspendImminentlyForTestingSync::Reply(), 0);
}
-
+
+static bool s_suspensionPreventedForTesting { false };
+void NetworkProcessProxy::preventSuspensionForTesting()
+{
+ s_suspensionPreventedForTesting = true;
+}
+
void NetworkProcessProxy::sendPrepareToSuspend(IsSuspensionImminent isSuspensionImminent, CompletionHandler<void()>&& completionHandler)
{
+ if (s_suspensionPreventedForTesting)
+ return completionHandler();
sendWithAsyncReply(Messages::NetworkProcess::PrepareToSuspend(isSuspensionImminent == IsSuspensionImminent::Yes), WTFMove(completionHandler), 0, { }, ShouldStartProcessThrottlerActivity::No);
}
Modified: trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h (281348 => 281349)
--- trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h 2021-08-20 22:58:48 UTC (rev 281348)
+++ trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h 2021-08-20 23:01:58 UTC (rev 281349)
@@ -231,6 +231,7 @@
void sendProcessDidResume() final;
ASCIILiteral clientName() const final { return "NetworkProcess"_s; }
+ static void preventSuspensionForTesting();
void sendProcessWillSuspendImminentlyForTesting();
void registerSchemeForLegacyCustomProtocol(const String&);
Modified: trunk/Tools/ChangeLog (281348 => 281349)
--- trunk/Tools/ChangeLog 2021-08-20 22:58:48 UTC (rev 281348)
+++ trunk/Tools/ChangeLog 2021-08-20 23:01:58 UTC (rev 281349)
@@ -1,3 +1,15 @@
+2021-08-20 Alex Christensen <[email protected]>
+
+ Make UIEventAttribution tests less platform dependent
+ https://bugs.webkit.org/show_bug.cgi?id=229323
+
+ Reviewed by John Wilander.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/EventAttribution.mm:
+ (TestWebKitAPI::exampleURL):
+ (TestWebKitAPI::runBasicEventAttributionTest):
+ (TestWebKitAPI::TEST):
+
2021-08-20 Jonathan Bedard <[email protected]>
[git-webkit] Add pull-request command (Part 1)
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/EventAttribution.mm (281348 => 281349)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/EventAttribution.mm 2021-08-20 22:58:48 UTC (rev 281348)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/EventAttribution.mm 2021-08-20 23:01:58 UTC (rev 281349)
@@ -25,8 +25,6 @@
#import "config.h"
-#if HAVE(UI_EVENT_ATTRIBUTION)
-
#import "HTTPServer.h"
#import "PlatformUtilities.h"
#import "TestNavigationDelegate.h"
@@ -75,8 +73,14 @@
namespace TestWebKitAPI {
-TEST(EventAttribution, Basic)
+static NSURL *exampleURL()
{
+ return [NSURL URLWithString:@"https://example.com/"];
+}
+
+void runBasicEventAttributionTest(Function<void(WKWebView *, const HTTPServer&)>&& addAttributionToWebView)
+{
+ [WKWebsiteDataStore _preventNetworkProcessSuspensionForTesting];
bool done = false;
HTTPServer server([&done, connectionCount = 0] (Connection connection) mutable {
switch (++connectionCount) {
@@ -109,16 +113,14 @@
}, HTTPServer::Protocol::Https);
NSURL *serverURL = server.request().URL;
- auto exampleURL = [NSURL URLWithString:@"https://example.com/"];
- auto attribution = adoptNS([[MockEventAttribution alloc] initWithReportEndpoint:server.request().URL destinationURL:exampleURL]);
auto webView = adoptNS([WKWebView new]);
- webView.get()._uiEventAttribution = (UIEventAttribution *)attribution.get();
+ addAttributionToWebView(webView.get(), server);
[[webView configuration].websiteDataStore _setResourceLoadStatisticsEnabled:YES];
[[webView configuration].websiteDataStore _allowTLSCertificateChain:@[(id)testCertificate().get()] forHost:serverURL.host];
- [webView _setPrivateClickMeasurementAttributionReportURLsForTesting:serverURL destinationURL:exampleURL completionHandler:^{
+ [webView _setPrivateClickMeasurementAttributionReportURLsForTesting:serverURL destinationURL:exampleURL() completionHandler:^{
[webView _setPrivateClickMeasurementOverrideTimerForTesting:YES completionHandler:^{
NSString *html = [NSString stringWithFormat:@"<script>fetch('%@conversionRequestBeforeRedirect',{mode:'no-cors'})</script>", serverURL];
- [webView loadHTMLString:html baseURL:exampleURL];
+ [webView loadHTMLString:html baseURL:exampleURL()];
}];
}];
Util::run(&done);
@@ -127,6 +129,7 @@
#if HAVE(RSA_BSSA)
TEST(EventAttribution, FraudPrevention)
{
+ [WKWebsiteDataStore _preventNetworkProcessSuspensionForTesting];
bool done = false;
// Generate the server key pair.
@@ -258,19 +261,17 @@
}, HTTPServer::Protocol::Https);
NSURL *serverURL = server.request().URL;
- auto exampleURL = [NSURL URLWithString:@"https://example.com/"];
- auto attribution = adoptNS([[MockEventAttribution alloc] initWithReportEndpoint:serverURL destinationURL:exampleURL]);
auto webView = adoptNS([WKWebView new]);
- [webView _setUIEventAttributionForTesting:(UIEventAttribution *)attribution.get() withNonce:@"ABCDEFabcdef0123456789"];
+ [webView _addEventAttributionWithSourceID:42 destinationURL:exampleURL() sourceDescription:@"test source description" purchaser:@"test purchaser" reportEndpoint:serverURL optionalNonce:@"ABCDEFabcdef0123456789"];
[[webView configuration].websiteDataStore _setResourceLoadStatisticsEnabled:YES];
[[webView configuration].websiteDataStore _allowTLSCertificateChain:@[(id)testCertificate().get()] forHost:serverURL.host];
- [webView _setPrivateClickMeasurementAttributionReportURLsForTesting:serverURL destinationURL:exampleURL completionHandler:^{
+ [webView _setPrivateClickMeasurementAttributionReportURLsForTesting:serverURL destinationURL:exampleURL() completionHandler:^{
[webView _setPrivateClickMeasurementOverrideTimerForTesting:YES completionHandler:^{
[webView _setPrivateClickMeasurementAttributionTokenPublicKeyURLForTesting:serverURL completionHandler:^{
[webView _setPrivateClickMeasurementAttributionTokenSignatureURLForTesting:serverURL completionHandler:^{
NSString *html = [NSString stringWithFormat:@"<script>setTimeout(function(){ fetch('%@conversionRequestBeforeRedirect',{mode:'no-cors'}); }, 100);</script>", serverURL];
- [webView loadHTMLString:html baseURL:exampleURL];
+ [webView loadHTMLString:html baseURL:exampleURL()];
}];
}];
}];
@@ -279,6 +280,23 @@
}
#endif
+TEST(EventAttribution, Basic)
+{
+ runBasicEventAttributionTest([](WKWebView *webView, const HTTPServer& server) {
+ [webView _addEventAttributionWithSourceID:42 destinationURL:exampleURL() sourceDescription:@"test source description" purchaser:@"test purchaser" reportEndpoint:server.request().URL optionalNonce:nil];
+ });
+}
+
+#if HAVE(UI_EVENT_ATTRIBUTION)
+
+TEST(EventAttribution, BasicWithIOSSPI)
+{
+ runBasicEventAttributionTest([](WKWebView *webView, const HTTPServer& server) {
+ auto attribution = adoptNS([[MockEventAttribution alloc] initWithReportEndpoint:server.request().URL destinationURL:exampleURL()]);
+ webView._uiEventAttribution = (UIEventAttribution *)attribution.get();
+ });
+}
+
+#endif // HAVE(UI_EVENT_ATTRIBUTION)
+
} // namespace TestWebKitAPI
-
-#endif // PLATFORM(IOS_FAMILY)