Changeset 267553 in webkit
- Timestamp:
- Sep 24, 2020, 4:59:10 PM (6 years ago)
- Location:
- trunk/Tools
- Files:
-
- 2 edited
-
ChangeLog (modified) (1 diff)
-
TestWebKitAPI/Tests/WebKitCocoa/InAppBrowserPrivacy.mm (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r267542 r267553 1 2020-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 1 27 2020-09-24 Jonathan Bedard <jbedard@apple.com> 2 28 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/InAppBrowserPrivacy.mm
r267344 r267553 511 511 static RetainPtr<WKHTTPCookieStore> globalCookieStore; 512 512 static bool gotFlag = false; 513 514 static void setUpCookieTest() 515 { 516 globalCookieStore = [[WKWebsiteDataStore defaultDataStore] httpCookieStore]; 513 static 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 529 static 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 517 541 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;534 542 gotFlag = false; 535 543 [globalCookieStore getAllCookies:[cookiesPtr = &cookies](NSArray<NSHTTPCookie *> *nsCookies) { … … 550 558 { 551 559 initializeInAppBrowserPrivacyTestSettings(); 552 [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"WebKitDebugIsInAppBrowserPrivacyEnabled"];553 560 554 561 auto dataStore = [WKWebsiteDataStore defaultDataStore]; … … 557 564 [webView _test_waitForDidFinishNavigation]; 558 565 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()]; 563 569 564 570 // Non app-bound cookie. … … 595 601 596 602 cleanUpInAppBrowserPrivacyTestSettings(); 597 [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"WebKitDebugIsInAppBrowserPrivacyEnabled"];598 603 gotFlag = false; 599 604 600 605 // Check the cookie store to make sure only one cookie was set. 606 NSArray<NSHTTPCookie *> *cookies = nil; 601 607 [globalCookieStore getAllCookies:[cookiesPtr = &cookies](NSArray<NSHTTPCookie *> *nsCookies) { 602 608 *cookiesPtr = [nsCookies retain]; … … 607 613 608 614 ASSERT_EQ(cookies.count, 1u); 615 EXPECT_WK_STREQ(cookies[0].domain, @"www.webkit.org"); 616 while (observerCallbacks != 1u) 617 TestWebKitAPI::Util::spinRunLoop(); 609 618 610 619 [cookies release]; … … 615 624 616 625 TestWebKitAPI::Util::run(&gotFlag); 626 [globalCookieStore removeObserver:observer.get()]; 617 627 } 618 628 … … 621 631 // Since we can't set non-app-bound cookies with In-App Browser privacy protections on, 622 632 // 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]); 628 636 629 637 // Non app-bound cookie. … … 643 651 }]; 644 652 653 gotFlag = false; 645 654 auto webView = adoptNS([TestWKWebView new]); 646 655 [webView synchronouslyLoadHTMLString:@"start network process"]; … … 660 669 TestWebKitAPI::Util::run(&gotFlag); 661 670 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; 662 687 gotFlag = false; 663 688 [globalCookieStore getAllCookies:[cookiesPtr = &cookies](NSArray<NSHTTPCookie *> *nsCookies) { … … 668 693 TestWebKitAPI::Util::run(&gotFlag); 669 694 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 685 695 ASSERT_EQ(cookies.count, 1u); 686 696 … … 696 706 gotFlag = false; 697 707 [globalCookieStore deleteCookie:appBoundCookie.get() completionHandler:[]() { 698 // Reset flag.699 [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"WebKitDebugIsInAppBrowserPrivacyEnabled"];700 708 cleanUpInAppBrowserPrivacyTestSettings(); 701 709 gotFlag = true; … … 709 717 // Since we can't set non-app-bound cookies with In-App Browser privacy protections on, 710 718 // 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]); 713 721 714 722 globalCookieStore = [[WKWebsiteDataStore defaultDataStore] httpCookieStore]; … … 734 742 735 743 // Now enable protections and ensure we can only retrieve the app-bound cookies. 736 [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"WebKitDebugIsInAppBrowserPrivacyEnabled"];737 744 initializeInAppBrowserPrivacyTestSettings(); 738 745 … … 744 751 [globalCookieStore deleteCookie:nonAppBoundCookie completionHandler:^{ 745 752 [globalCookieStore deleteCookie:appBoundCookie completionHandler:^{ 746 [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"WebKitDebugIsInAppBrowserPrivacyEnabled"];747 753 cleanUpInAppBrowserPrivacyTestSettings(); 748 754 done = true;
Note:
See TracChangeset
for help on using the changeset viewer.