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

Changeset 267553 in webkit


Ignore:
Timestamp:
Sep 24, 2020, 4:59:10 PM (6 years ago)
Author:
Kate Cheney
Message:

InAppBrowserPrivacy HTTPCookie tests incorrectly use the IsInAppBrowserPrivacyEnabled NSUserDefaults value
https://bugs.webkit.org/show_bug.cgi?id=216896
<rdar://problem/69456713>

Reviewed by Brady Eidson.

The IsInAppBrowserPrivacyEnabled UserDefaults value no longer enables
App-Bound Domains, so the tests should not use it in this way.
Changing the bundle identifier using
cleanUpInAppBrowserPrivacyTestSettings() and
initializeInAppBrowserPrivacyTestSettings() is enough to
enable/disable App-Bound Domains.

This patch also adds a WKHTTPCookieStoreObserver to test setting
app-bound cookies. This ensures we don't get a false positive from
the test by being allowed to set but not retrieve app-bound cookies.

  • TestWebKitAPI/Tests/WebKitCocoa/InAppBrowserPrivacy.mm:

(-[InAppBrowserPrivacyCookieObserver cookiesDidChangeInCookieStore:]):
(setUpCookieTestWithWebsiteDataStore):
(TEST):
(setUpCookieTest): Deleted.
Changed name and simplified.

Location:
trunk/Tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r267542 r267553  
     12020-09-24  Kate Cheney  <katherine_cheney@apple.com>
     2
     3        InAppBrowserPrivacy HTTPCookie tests incorrectly use the IsInAppBrowserPrivacyEnabled NSUserDefaults value
     4        https://bugs.webkit.org/show_bug.cgi?id=216896
     5        <rdar://problem/69456713>
     6
     7        Reviewed by Brady Eidson.
     8
     9        The IsInAppBrowserPrivacyEnabled UserDefaults value no longer enables
     10        App-Bound Domains, so the tests should not use it in this way.
     11        Changing the bundle identifier using
     12        cleanUpInAppBrowserPrivacyTestSettings() and
     13        initializeInAppBrowserPrivacyTestSettings() is enough to
     14        enable/disable App-Bound Domains.
     15
     16        This patch also adds a WKHTTPCookieStoreObserver to test setting
     17        app-bound cookies. This ensures we don't get a false positive from
     18        the test by being allowed to set but not retrieve app-bound cookies.
     19
     20        * TestWebKitAPI/Tests/WebKitCocoa/InAppBrowserPrivacy.mm:
     21        (-[InAppBrowserPrivacyCookieObserver cookiesDidChangeInCookieStore:]):
     22        (setUpCookieTestWithWebsiteDataStore):
     23        (TEST):
     24        (setUpCookieTest): Deleted.
     25        Changed name and simplified.
     26
    1272020-09-24  Jonathan Bedard  <jbedard@apple.com>
    228
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/InAppBrowserPrivacy.mm

    r267344 r267553  
    511511static RetainPtr<WKHTTPCookieStore> globalCookieStore;
    512512static bool gotFlag = false;
    513 
    514 static void setUpCookieTest()
    515 {
    516     globalCookieStore = [[WKWebsiteDataStore defaultDataStore] httpCookieStore];
     513static uint64_t observerCallbacks;
     514
     515@interface InAppBrowserPrivacyCookieObserver : NSObject<WKHTTPCookieStoreObserver>
     516- (void)cookiesDidChangeInCookieStore:(WKHTTPCookieStore *)cookieStore;
     517@end
     518
     519@implementation InAppBrowserPrivacyCookieObserver
     520
     521- (void)cookiesDidChangeInCookieStore:(WKHTTPCookieStore *)cookieStore
     522{
     523    ASSERT_EQ(cookieStore, globalCookieStore.get());
     524    ++observerCallbacks;
     525}
     526
     527@end
     528
     529static void setUpCookieTestWithWebsiteDataStore(WKWebsiteDataStore* dataStore)
     530{
     531    gotFlag = false;
     532    // Clear out any website data.
     533    [dataStore removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:[] {
     534        gotFlag = true;
     535    }];
     536    TestWebKitAPI::Util::run(&gotFlag);
     537
     538    observerCallbacks = 0;
     539    globalCookieStore = dataStore.httpCookieStore;
     540
    517541    NSArray<NSHTTPCookie *> *cookies = nil;
    518     [globalCookieStore getAllCookies:[cookiesPtr = &cookies](NSArray<NSHTTPCookie *> *nsCookies) {
    519         *cookiesPtr = [nsCookies retain];
    520         gotFlag = true;
    521     }];
    522 
    523     TestWebKitAPI::Util::run(&gotFlag);
    524 
    525     for (id cookie in cookies) {
    526         gotFlag = false;
    527         [globalCookieStore deleteCookie:cookie completionHandler:[]() {
    528             gotFlag = true;
    529         }];
    530         TestWebKitAPI::Util::run(&gotFlag);
    531     }
    532 
    533     cookies = nil;
    534542    gotFlag = false;
    535543    [globalCookieStore getAllCookies:[cookiesPtr = &cookies](NSArray<NSHTTPCookie *> *nsCookies) {
     
    550558{
    551559    initializeInAppBrowserPrivacyTestSettings();
    552     [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"WebKitDebugIsInAppBrowserPrivacyEnabled"];
    553560
    554561    auto dataStore = [WKWebsiteDataStore defaultDataStore];
     
    557564    [webView _test_waitForDidFinishNavigation];
    558565
    559     setUpCookieTest();
    560     globalCookieStore = [dataStore httpCookieStore];
    561 
    562     NSArray<NSHTTPCookie *> *cookies = nil;
     566    setUpCookieTestWithWebsiteDataStore(dataStore);
     567    RetainPtr<InAppBrowserPrivacyCookieObserver> observer = adoptNS([[InAppBrowserPrivacyCookieObserver alloc] init]);
     568    [globalCookieStore addObserver:observer.get()];
    563569
    564570    // Non app-bound cookie.
     
    595601
    596602    cleanUpInAppBrowserPrivacyTestSettings();
    597     [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"WebKitDebugIsInAppBrowserPrivacyEnabled"];
    598603    gotFlag = false;
    599604
    600605    // Check the cookie store to make sure only one cookie was set.
     606    NSArray<NSHTTPCookie *> *cookies = nil;
    601607    [globalCookieStore getAllCookies:[cookiesPtr = &cookies](NSArray<NSHTTPCookie *> *nsCookies) {
    602608        *cookiesPtr = [nsCookies retain];
     
    607613
    608614    ASSERT_EQ(cookies.count, 1u);
     615    EXPECT_WK_STREQ(cookies[0].domain, @"www.webkit.org");
     616    while (observerCallbacks != 1u)
     617        TestWebKitAPI::Util::spinRunLoop();
    609618
    610619    [cookies release];
     
    615624
    616625    TestWebKitAPI::Util::run(&gotFlag);
     626    [globalCookieStore removeObserver:observer.get()];
    617627}
    618628
     
    621631    // Since we can't set non-app-bound cookies with In-App Browser privacy protections on,
    622632    // we can turn the protections off to set a cookie we will then try to get with protections enabled.
    623     [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"WebKitDebugIsInAppBrowserPrivacyEnabled"];
    624 
    625     setUpCookieTest();
    626     globalCookieStore = [[WKWebsiteDataStore defaultDataStore] httpCookieStore];
    627     NSArray<NSHTTPCookie *> *cookies = nil;
     633    cleanUpInAppBrowserPrivacyTestSettings();
     634
     635    setUpCookieTestWithWebsiteDataStore([WKWebsiteDataStore defaultDataStore]);
    628636
    629637    // Non app-bound cookie.
     
    643651    }];
    644652
     653    gotFlag = false;
    645654    auto webView = adoptNS([TestWKWebView new]);
    646655    [webView synchronouslyLoadHTMLString:@"start network process"];
     
    660669    TestWebKitAPI::Util::run(&gotFlag);
    661670
     671    gotFlag = false;
     672    NSArray<NSHTTPCookie *> *cookies = nil;
     673    [globalCookieStore getAllCookies:[cookiesPtr = &cookies](NSArray<NSHTTPCookie *> *nsCookies) {
     674        *cookiesPtr = [nsCookies retain];
     675        gotFlag = true;
     676    }];
     677
     678    TestWebKitAPI::Util::run(&gotFlag);
     679
     680    // Confirm both cookies are in the store.
     681    ASSERT_EQ(cookies.count, 2u);
     682
     683    // Now enable protections and ensure we can only retrieve the app-bound cookies.
     684    initializeInAppBrowserPrivacyTestSettings();
     685
     686    cookies = nil;
    662687    gotFlag = false;
    663688    [globalCookieStore getAllCookies:[cookiesPtr = &cookies](NSArray<NSHTTPCookie *> *nsCookies) {
     
    668693    TestWebKitAPI::Util::run(&gotFlag);
    669694
    670     // Confirm both cookies are in the store.
    671     ASSERT_EQ(cookies.count, 2u);
    672 
    673     // Now enable protections and ensure we can only retrieve the app-bound cookies.
    674     [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"WebKitDebugIsInAppBrowserPrivacyEnabled"];
    675     initializeInAppBrowserPrivacyTestSettings();
    676 
    677     gotFlag = false;
    678     [globalCookieStore getAllCookies:[cookiesPtr = &cookies](NSArray<NSHTTPCookie *> *nsCookies) {
    679         *cookiesPtr = [nsCookies retain];
    680         gotFlag = true;
    681     }];
    682 
    683     TestWebKitAPI::Util::run(&gotFlag);
    684 
    685695    ASSERT_EQ(cookies.count, 1u);
    686696
     
    696706    gotFlag = false;
    697707    [globalCookieStore deleteCookie:appBoundCookie.get() completionHandler:[]() {
    698         // Reset flag.
    699         [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"WebKitDebugIsInAppBrowserPrivacyEnabled"];
    700708        cleanUpInAppBrowserPrivacyTestSettings();
    701709        gotFlag = true;
     
    709717    // Since we can't set non-app-bound cookies with In-App Browser privacy protections on,
    710718    // we can turn the protections off to set a cookie we will then try to get with protections enabled.
    711     [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"WebKitDebugIsInAppBrowserPrivacyEnabled"];
    712     setUpCookieTest();
     719    cleanUpInAppBrowserPrivacyTestSettings();
     720    setUpCookieTestWithWebsiteDataStore([WKWebsiteDataStore defaultDataStore]);
    713721
    714722    globalCookieStore = [[WKWebsiteDataStore defaultDataStore] httpCookieStore];
     
    734742
    735743            // Now enable protections and ensure we can only retrieve the app-bound cookies.
    736             [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"WebKitDebugIsInAppBrowserPrivacyEnabled"];
    737744            initializeInAppBrowserPrivacyTestSettings();
    738745
     
    744751                    [globalCookieStore deleteCookie:nonAppBoundCookie completionHandler:^{
    745752                        [globalCookieStore deleteCookie:appBoundCookie completionHandler:^{
    746                             [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"WebKitDebugIsInAppBrowserPrivacyEnabled"];
    747753                            cleanUpInAppBrowserPrivacyTestSettings();
    748754                            done = true;
Note: See TracChangeset for help on using the changeset viewer.