Changeset 281349 in webkit
- Timestamp:
- Aug 20, 2021, 4:01:58 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 11 edited
-
Source/WebKit/ChangeLog (modified) (1 diff)
-
Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h (modified) (1 diff)
-
Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm (modified) (1 diff)
-
Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm (modified) (1 diff)
-
Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h (modified) (1 diff)
-
Source/WebKit/UIProcess/API/ios/WKWebViewPrivateForTestingIOS.h (modified) (1 diff)
-
Source/WebKit/UIProcess/API/ios/WKWebViewTestingIOS.mm (modified) (1 diff)
-
Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp (modified) (1 diff)
-
Source/WebKit/UIProcess/Network/NetworkProcessProxy.h (modified) (1 diff)
-
Tools/ChangeLog (modified) (1 diff)
-
Tools/TestWebKitAPI/Tests/WebKitCocoa/EventAttribution.mm (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r281332 r281349 1 2021-08-20 Alex Christensen <achristensen@webkit.org> 2 3 Make UIEventAttribution tests less platform dependent 4 https://bugs.webkit.org/show_bug.cgi?id=229323 5 6 Reviewed by John Wilander. 7 8 This allows me to run the UIEventAttribution tests on macOS. 9 It also makes them not time out, which they were doing since r277447. 10 To accomplish this, I added more test SPI to prevent the network process 11 suspension message, which was causing the test to time out on the iOS simulator. 12 13 * UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h: 14 * UIProcess/API/Cocoa/WKWebViewTesting.mm: 15 (-[WKWebView _addEventAttributionWithSourceID:destinationURL:sourceDescription:purchaser:reportEndpoint:optionalNonce:]): 16 * UIProcess/API/Cocoa/WKWebsiteDataStore.mm: 17 (+[WKWebsiteDataStore _preventNetworkProcessSuspensionForTesting]): 18 * UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h: 19 * UIProcess/API/ios/WKWebViewPrivateForTestingIOS.h: 20 * UIProcess/API/ios/WKWebViewTestingIOS.mm: 21 (-[WKWebView _setUIEventAttributionForTesting:withNonce:]): Deleted. 22 * UIProcess/Network/NetworkProcessProxy.cpp: 23 (WebKit::NetworkProcessProxy::preventSuspensionForTesting): 24 (WebKit::NetworkProcessProxy::sendPrepareToSuspend): 25 * UIProcess/Network/NetworkProcessProxy.h: 26 1 27 2021-08-20 Simon Fraser <simon.fraser@apple.com> 2 28 -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h
r279750 r281349 44 44 45 45 @interface WKWebView (WKTesting) 46 47 - (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)); 46 48 47 49 - (void)_setPageScale:(CGFloat)scale withOrigin:(CGPoint)origin; -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm
r279750 r281349 56 56 @implementation WKWebView (WKTesting) 57 57 58 - (void)_addEventAttributionWithSourceID:(uint8_t)sourceID destinationURL:(NSURL *)destination sourceDescription:(NSString *)sourceDescription purchaser:(NSString *)purchaser reportEndpoint:(NSURL *)reportEndpoint optionalNonce:(NSString *)nonce 59 { 60 WebCore::PrivateClickMeasurement measurement( 61 WebCore::PrivateClickMeasurement::SourceID(sourceID), 62 WebCore::PrivateClickMeasurement::SourceSite(reportEndpoint), 63 WebCore::PrivateClickMeasurement::AttributionDestinationSite(destination), 64 sourceDescription, 65 purchaser 66 ); 67 if (nonce) 68 measurement.setEphemeralSourceNonce({ nonce }); 69 70 _page->setPrivateClickMeasurement(WTFMove(measurement)); 71 } 72 58 73 - (void)_setPageScale:(CGFloat)scale withOrigin:(CGPoint)origin 59 74 { -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm
r278475 r281349 732 732 } 733 733 734 + (void)_preventNetworkProcessSuspensionForTesting 735 { 736 WebKit::NetworkProcessProxy::preventSuspensionForTesting(); 737 } 738 734 739 - (BOOL)_networkProcessExists 735 740 { -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h
r279089 r281349 96 96 - (void)_sendNetworkProcessWillSuspendImminently WK_API_AVAILABLE(macos(12.0), ios(15.0)); 97 97 - (void)_sendNetworkProcessDidResume WK_API_AVAILABLE(macos(12.0), ios(15.0)); 98 + (void)_preventNetworkProcessSuspensionForTesting WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA)); 98 99 - (void)_synthesizeAppIsBackground:(BOOL)background WK_API_AVAILABLE(macos(12.0), ios(15.0)); 99 100 - (pid_t)_networkProcessIdentifier WK_API_AVAILABLE(macos(12.0), ios(15.0)); -
trunk/Source/WebKit/UIProcess/API/ios/WKWebViewPrivateForTestingIOS.h
r281279 r281349 88 88 - (void)_setDeviceHasAGXCompilerServiceForTesting; 89 89 90 #if !TARGET_OS_TV && !TARGET_OS_WATCH91 - (void)_setUIEventAttributionForTesting:(UIEventAttribution *)attribution withNonce:(NSString *)nonce;92 #endif93 94 90 - (NSString *)_serializedSelectionCaretBackgroundColorForTesting; 95 91 -
trunk/Source/WebKit/UIProcess/API/ios/WKWebViewTestingIOS.mm
r281279 r281349 466 466 } 467 467 468 #if !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)469 - (void)_setUIEventAttributionForTesting:(UIEventAttribution *)attribution withNonce:(NSString *)nonce470 {471 #if HAVE(UI_EVENT_ATTRIBUTION)472 if (attribution) {473 WebCore::PrivateClickMeasurement measurement(474 WebCore::PrivateClickMeasurement::SourceID(attribution.sourceIdentifier),475 WebCore::PrivateClickMeasurement::SourceSite(attribution.reportEndpoint),476 WebCore::PrivateClickMeasurement::AttributionDestinationSite(attribution.destinationURL),477 attribution.sourceDescription,478 attribution.purchaser479 );480 measurement.setEphemeralSourceNonce({ nonce });481 482 _page->setPrivateClickMeasurement(WTFMove(measurement));483 } else484 _page->setPrivateClickMeasurement(std::nullopt);485 #endif486 }487 #endif488 489 468 - (NSString *)_serializedSelectionCaretBackgroundColorForTesting 490 469 { -
trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp
r281096 r281349 1251 1251 sendSync(Messages::NetworkProcess::ProcessWillSuspendImminentlyForTestingSync(), Messages::NetworkProcess::ProcessWillSuspendImminentlyForTestingSync::Reply(), 0); 1252 1252 } 1253 1253 1254 static bool s_suspensionPreventedForTesting { false }; 1255 void NetworkProcessProxy::preventSuspensionForTesting() 1256 { 1257 s_suspensionPreventedForTesting = true; 1258 } 1259 1254 1260 void NetworkProcessProxy::sendPrepareToSuspend(IsSuspensionImminent isSuspensionImminent, CompletionHandler<void()>&& completionHandler) 1255 1261 { 1262 if (s_suspensionPreventedForTesting) 1263 return completionHandler(); 1256 1264 sendWithAsyncReply(Messages::NetworkProcess::PrepareToSuspend(isSuspensionImminent == IsSuspensionImminent::Yes), WTFMove(completionHandler), 0, { }, ShouldStartProcessThrottlerActivity::No); 1257 1265 } -
trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h
r281070 r281349 232 232 ASCIILiteral clientName() const final { return "NetworkProcess"_s; } 233 233 234 static void preventSuspensionForTesting(); 234 235 void sendProcessWillSuspendImminentlyForTesting(); 235 236 -
trunk/Tools/ChangeLog
r281346 r281349 1 2021-08-20 Alex Christensen <achristensen@webkit.org> 2 3 Make UIEventAttribution tests less platform dependent 4 https://bugs.webkit.org/show_bug.cgi?id=229323 5 6 Reviewed by John Wilander. 7 8 * TestWebKitAPI/Tests/WebKitCocoa/EventAttribution.mm: 9 (TestWebKitAPI::exampleURL): 10 (TestWebKitAPI::runBasicEventAttributionTest): 11 (TestWebKitAPI::TEST): 12 1 13 2021-08-20 Jonathan Bedard <jbedard@apple.com> 2 14 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/EventAttribution.mm
r278872 r281349 26 26 #import "config.h" 27 27 28 #if HAVE(UI_EVENT_ATTRIBUTION)29 30 28 #import "HTTPServer.h" 31 29 #import "PlatformUtilities.h" … … 76 74 namespace TestWebKitAPI { 77 75 78 TEST(EventAttribution, Basic) 79 { 76 static NSURL *exampleURL() 77 { 78 return [NSURL URLWithString:@"https://example.com/"]; 79 } 80 81 void runBasicEventAttributionTest(Function<void(WKWebView *, const HTTPServer&)>&& addAttributionToWebView) 82 { 83 [WKWebsiteDataStore _preventNetworkProcessSuspensionForTesting]; 80 84 bool done = false; 81 85 HTTPServer server([&done, connectionCount = 0] (Connection connection) mutable { … … 110 114 NSURL *serverURL = server.request().URL; 111 115 112 auto exampleURL = [NSURL URLWithString:@"https://example.com/"];113 auto attribution = adoptNS([[MockEventAttribution alloc] initWithReportEndpoint:server.request().URL destinationURL:exampleURL]);114 116 auto webView = adoptNS([WKWebView new]); 115 webView.get()._uiEventAttribution = (UIEventAttribution *)attribution.get();117 addAttributionToWebView(webView.get(), server); 116 118 [[webView configuration].websiteDataStore _setResourceLoadStatisticsEnabled:YES]; 117 119 [[webView configuration].websiteDataStore _allowTLSCertificateChain:@[(id)testCertificate().get()] forHost:serverURL.host]; 118 [webView _setPrivateClickMeasurementAttributionReportURLsForTesting:serverURL destinationURL:exampleURL completionHandler:^{120 [webView _setPrivateClickMeasurementAttributionReportURLsForTesting:serverURL destinationURL:exampleURL() completionHandler:^{ 119 121 [webView _setPrivateClickMeasurementOverrideTimerForTesting:YES completionHandler:^{ 120 122 NSString *html = [NSString stringWithFormat:@"<script>fetch('%@conversionRequestBeforeRedirect',{mode:'no-cors'})</script>", serverURL]; 121 [webView loadHTMLString:html baseURL:exampleURL ];123 [webView loadHTMLString:html baseURL:exampleURL()]; 122 124 }]; 123 125 }]; … … 128 130 TEST(EventAttribution, FraudPrevention) 129 131 { 132 [WKWebsiteDataStore _preventNetworkProcessSuspensionForTesting]; 130 133 bool done = false; 131 134 … … 259 262 NSURL *serverURL = server.request().URL; 260 263 261 auto exampleURL = [NSURL URLWithString:@"https://example.com/"];262 auto attribution = adoptNS([[MockEventAttribution alloc] initWithReportEndpoint:serverURL destinationURL:exampleURL]);263 264 auto webView = adoptNS([WKWebView new]); 264 [webView _ setUIEventAttributionForTesting:(UIEventAttribution *)attribution.get() withNonce:@"ABCDEFabcdef0123456789"];265 [webView _addEventAttributionWithSourceID:42 destinationURL:exampleURL() sourceDescription:@"test source description" purchaser:@"test purchaser" reportEndpoint:serverURL optionalNonce:@"ABCDEFabcdef0123456789"]; 265 266 [[webView configuration].websiteDataStore _setResourceLoadStatisticsEnabled:YES]; 266 267 [[webView configuration].websiteDataStore _allowTLSCertificateChain:@[(id)testCertificate().get()] forHost:serverURL.host]; 267 268 268 [webView _setPrivateClickMeasurementAttributionReportURLsForTesting:serverURL destinationURL:exampleURL completionHandler:^{269 [webView _setPrivateClickMeasurementAttributionReportURLsForTesting:serverURL destinationURL:exampleURL() completionHandler:^{ 269 270 [webView _setPrivateClickMeasurementOverrideTimerForTesting:YES completionHandler:^{ 270 271 [webView _setPrivateClickMeasurementAttributionTokenPublicKeyURLForTesting:serverURL completionHandler:^{ 271 272 [webView _setPrivateClickMeasurementAttributionTokenSignatureURLForTesting:serverURL completionHandler:^{ 272 273 NSString *html = [NSString stringWithFormat:@"<script>setTimeout(function(){ fetch('%@conversionRequestBeforeRedirect',{mode:'no-cors'}); }, 100);</script>", serverURL]; 273 [webView loadHTMLString:html baseURL:exampleURL ];274 [webView loadHTMLString:html baseURL:exampleURL()]; 274 275 }]; 275 276 }]; … … 280 281 #endif 281 282 283 TEST(EventAttribution, Basic) 284 { 285 runBasicEventAttributionTest([](WKWebView *webView, const HTTPServer& server) { 286 [webView _addEventAttributionWithSourceID:42 destinationURL:exampleURL() sourceDescription:@"test source description" purchaser:@"test purchaser" reportEndpoint:server.request().URL optionalNonce:nil]; 287 }); 288 } 289 290 #if HAVE(UI_EVENT_ATTRIBUTION) 291 292 TEST(EventAttribution, BasicWithIOSSPI) 293 { 294 runBasicEventAttributionTest([](WKWebView *webView, const HTTPServer& server) { 295 auto attribution = adoptNS([[MockEventAttribution alloc] initWithReportEndpoint:server.request().URL destinationURL:exampleURL()]); 296 webView._uiEventAttribution = (UIEventAttribution *)attribution.get(); 297 }); 298 } 299 300 #endif // HAVE(UI_EVENT_ATTRIBUTION) 301 282 302 } // namespace TestWebKitAPI 283 284 #endif // PLATFORM(IOS_FAMILY)
Note:
See TracChangeset
for help on using the changeset viewer.