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

Changeset 281349 in webkit


Ignore:
Timestamp:
Aug 20, 2021, 4:01:58 PM (5 years ago)
Author:
achristensen@apple.com
Message:

Make UIEventAttribution tests less platform dependent
https://bugs.webkit.org/show_bug.cgi?id=229323

Reviewed by John Wilander.

Source/WebKit:

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:

Tools:

  • TestWebKitAPI/Tests/WebKitCocoa/EventAttribution.mm:

(TestWebKitAPI::exampleURL):
(TestWebKitAPI::runBasicEventAttributionTest):
(TestWebKitAPI::TEST):

Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r281332 r281349  
     12021-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
    1272021-08-20  Simon Fraser  <simon.fraser@apple.com>
    228
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h

    r279750 r281349  
    4444
    4545@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));
    4648
    4749- (void)_setPageScale:(CGFloat)scale withOrigin:(CGPoint)origin;
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm

    r279750 r281349  
    5656@implementation WKWebView (WKTesting)
    5757
     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
    5873- (void)_setPageScale:(CGFloat)scale withOrigin:(CGPoint)origin
    5974{
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm

    r278475 r281349  
    732732}
    733733
     734+ (void)_preventNetworkProcessSuspensionForTesting
     735{
     736    WebKit::NetworkProcessProxy::preventSuspensionForTesting();
     737}
     738
    734739- (BOOL)_networkProcessExists
    735740{
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h

    r279089 r281349  
    9696- (void)_sendNetworkProcessWillSuspendImminently WK_API_AVAILABLE(macos(12.0), ios(15.0));
    9797- (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));
    9899- (void)_synthesizeAppIsBackground:(BOOL)background WK_API_AVAILABLE(macos(12.0), ios(15.0));
    99100- (pid_t)_networkProcessIdentifier WK_API_AVAILABLE(macos(12.0), ios(15.0));
  • trunk/Source/WebKit/UIProcess/API/ios/WKWebViewPrivateForTestingIOS.h

    r281279 r281349  
    8888- (void)_setDeviceHasAGXCompilerServiceForTesting;
    8989
    90 #if !TARGET_OS_TV && !TARGET_OS_WATCH
    91 - (void)_setUIEventAttributionForTesting:(UIEventAttribution *)attribution withNonce:(NSString *)nonce;
    92 #endif
    93 
    9490- (NSString *)_serializedSelectionCaretBackgroundColorForTesting;
    9591
  • trunk/Source/WebKit/UIProcess/API/ios/WKWebViewTestingIOS.mm

    r281279 r281349  
    466466}
    467467
    468 #if !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
    469 - (void)_setUIEventAttributionForTesting:(UIEventAttribution *)attribution withNonce:(NSString *)nonce
    470 {
    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.purchaser
    479         );
    480         measurement.setEphemeralSourceNonce({ nonce });
    481 
    482         _page->setPrivateClickMeasurement(WTFMove(measurement));
    483     } else
    484         _page->setPrivateClickMeasurement(std::nullopt);
    485 #endif
    486 }
    487 #endif
    488 
    489468- (NSString *)_serializedSelectionCaretBackgroundColorForTesting
    490469{
  • trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp

    r281096 r281349  
    12511251        sendSync(Messages::NetworkProcess::ProcessWillSuspendImminentlyForTestingSync(), Messages::NetworkProcess::ProcessWillSuspendImminentlyForTestingSync::Reply(), 0);
    12521252}
    1253    
     1253
     1254static bool s_suspensionPreventedForTesting { false };
     1255void NetworkProcessProxy::preventSuspensionForTesting()
     1256{
     1257    s_suspensionPreventedForTesting = true;
     1258}
     1259
    12541260void NetworkProcessProxy::sendPrepareToSuspend(IsSuspensionImminent isSuspensionImminent, CompletionHandler<void()>&& completionHandler)
    12551261{
     1262    if (s_suspensionPreventedForTesting)
     1263        return completionHandler();
    12561264    sendWithAsyncReply(Messages::NetworkProcess::PrepareToSuspend(isSuspensionImminent == IsSuspensionImminent::Yes), WTFMove(completionHandler), 0, { }, ShouldStartProcessThrottlerActivity::No);
    12571265}
  • trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h

    r281070 r281349  
    232232    ASCIILiteral clientName() const final { return "NetworkProcess"_s; }
    233233   
     234    static void preventSuspensionForTesting();
    234235    void sendProcessWillSuspendImminentlyForTesting();
    235236
  • trunk/Tools/ChangeLog

    r281346 r281349  
     12021-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
    1132021-08-20  Jonathan Bedard  <jbedard@apple.com>
    214
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/EventAttribution.mm

    r278872 r281349  
    2626#import "config.h"
    2727
    28 #if HAVE(UI_EVENT_ATTRIBUTION)
    29 
    3028#import "HTTPServer.h"
    3129#import "PlatformUtilities.h"
     
    7674namespace TestWebKitAPI {
    7775
    78 TEST(EventAttribution, Basic)
    79 {
     76static NSURL *exampleURL()
     77{
     78    return [NSURL URLWithString:@"https://example.com/"];
     79}
     80
     81void runBasicEventAttributionTest(Function<void(WKWebView *, const HTTPServer&)>&& addAttributionToWebView)
     82{
     83    [WKWebsiteDataStore _preventNetworkProcessSuspensionForTesting];
    8084    bool done = false;
    8185    HTTPServer server([&done, connectionCount = 0] (Connection connection) mutable {
     
    110114    NSURL *serverURL = server.request().URL;
    111115
    112     auto exampleURL = [NSURL URLWithString:@"https://example.com/"];
    113     auto attribution = adoptNS([[MockEventAttribution alloc] initWithReportEndpoint:server.request().URL destinationURL:exampleURL]);
    114116    auto webView = adoptNS([WKWebView new]);
    115     webView.get()._uiEventAttribution = (UIEventAttribution *)attribution.get();
     117    addAttributionToWebView(webView.get(), server);
    116118    [[webView configuration].websiteDataStore _setResourceLoadStatisticsEnabled:YES];
    117119    [[webView configuration].websiteDataStore _allowTLSCertificateChain:@[(id)testCertificate().get()] forHost:serverURL.host];
    118     [webView _setPrivateClickMeasurementAttributionReportURLsForTesting:serverURL destinationURL:exampleURL completionHandler:^{
     120    [webView _setPrivateClickMeasurementAttributionReportURLsForTesting:serverURL destinationURL:exampleURL() completionHandler:^{
    119121        [webView _setPrivateClickMeasurementOverrideTimerForTesting:YES completionHandler:^{
    120122            NSString *html = [NSString stringWithFormat:@"<script>fetch('%@conversionRequestBeforeRedirect',{mode:'no-cors'})</script>", serverURL];
    121             [webView loadHTMLString:html baseURL:exampleURL];
     123            [webView loadHTMLString:html baseURL:exampleURL()];
    122124        }];
    123125    }];
     
    128130TEST(EventAttribution, FraudPrevention)
    129131{
     132    [WKWebsiteDataStore _preventNetworkProcessSuspensionForTesting];
    130133    bool done = false;
    131134
     
    259262    NSURL *serverURL = server.request().URL;
    260263
    261     auto exampleURL = [NSURL URLWithString:@"https://example.com/"];
    262     auto attribution = adoptNS([[MockEventAttribution alloc] initWithReportEndpoint:serverURL destinationURL:exampleURL]);
    263264    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"];
    265266    [[webView configuration].websiteDataStore _setResourceLoadStatisticsEnabled:YES];
    266267    [[webView configuration].websiteDataStore _allowTLSCertificateChain:@[(id)testCertificate().get()] forHost:serverURL.host];
    267268
    268     [webView _setPrivateClickMeasurementAttributionReportURLsForTesting:serverURL destinationURL:exampleURL completionHandler:^{
     269    [webView _setPrivateClickMeasurementAttributionReportURLsForTesting:serverURL destinationURL:exampleURL() completionHandler:^{
    269270        [webView _setPrivateClickMeasurementOverrideTimerForTesting:YES completionHandler:^{
    270271            [webView _setPrivateClickMeasurementAttributionTokenPublicKeyURLForTesting:serverURL completionHandler:^{
    271272                [webView _setPrivateClickMeasurementAttributionTokenSignatureURLForTesting:serverURL completionHandler:^{
    272273                    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()];
    274275                }];
    275276            }];
     
    280281#endif
    281282
     283TEST(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
     292TEST(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
    282302} // namespace TestWebKitAPI
    283 
    284 #endif // PLATFORM(IOS_FAMILY)
Note: See TracChangeset for help on using the changeset viewer.