Title: [277451] trunk/Tools
- Revision
- 277451
- Author
- [email protected]
- Date
- 2021-05-13 14:28:34 -0700 (Thu, 13 May 2021)
Log Message
Add unit test using WKHTTPCookieStoreObserver and cookies received from HTTP
https://bugs.webkit.org/show_bug.cgi?id=225773
Patch by Alex Christensen <[email protected]> on 2021-05-13
Reviewed by Chris Dumez.
We only had tests that added cookies through the API, not through the network.
I thought it was broken but it isn't. Still worth adding the test.
* TestWebKitAPI/Tests/WebKitCocoa/WKHTTPCookieStore.mm:
(deleteAllCookies):
(TEST):
Modified Paths
Diff
Modified: trunk/Tools/ChangeLog (277450 => 277451)
--- trunk/Tools/ChangeLog 2021-05-13 20:54:21 UTC (rev 277450)
+++ trunk/Tools/ChangeLog 2021-05-13 21:28:34 UTC (rev 277451)
@@ -1,3 +1,17 @@
+2021-05-13 Alex Christensen <[email protected]>
+
+ Add unit test using WKHTTPCookieStoreObserver and cookies received from HTTP
+ https://bugs.webkit.org/show_bug.cgi?id=225773
+
+ Reviewed by Chris Dumez.
+
+ We only had tests that added cookies through the API, not through the network.
+ I thought it was broken but it isn't. Still worth adding the test.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/WKHTTPCookieStore.mm:
+ (deleteAllCookies):
+ (TEST):
+
2021-05-13 Chris Dumez <[email protected]>
Rename FileSystem::directoryName() to FileSystem::parentPath()
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKHTTPCookieStore.mm (277450 => 277451)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKHTTPCookieStore.mm 2021-05-13 20:54:21 UTC (rev 277450)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKHTTPCookieStore.mm 2021-05-13 21:28:34 UTC (rev 277451)
@@ -25,6 +25,7 @@
#import "config.h"
+#import "HTTPServer.h"
#import "PlatformUtilities.h"
#import "TestNavigationDelegate.h"
#import "TestWKWebView.h"
@@ -34,6 +35,7 @@
#import <WebKit/WKWebsiteDataStorePrivate.h>
#import <WebKit/_WKProcessPoolConfiguration.h>
#import <WebKit/_WKWebsiteDataStoreConfiguration.h>
+#import <wtf/BlockPtr.h>
#import <wtf/ProcessPrivilege.h>
#import <wtf/RetainPtr.h>
#import <wtf/Seconds.h>
@@ -457,6 +459,58 @@
TestWebKitAPI::Util::run(&gotFlag);
}
+static void deleteCookies(WKHTTPCookieStore *store, RetainPtr<NSMutableArray> cookies, BlockPtr<void(void)> completionBlock)
+{
+ if (![cookies count])
+ return completionBlock();
+ [store deleteCookie:[cookies lastObject] completionHandler:^(void) {
+ [cookies removeLastObject];
+ deleteCookies(store, cookies, completionBlock);
+ }];
+}
+
+TEST(WKHTTPCookieStore, ObserveCookiesReceivedFromHTTP)
+{
+ TestWebKitAPI::HTTPServer server({{ "/", {{{ "Set-Cookie", "testkey=testvalue" }}, "hello" }}});
+
+ auto removeAllCookies = [] (WKHTTPCookieStore *store) {
+ __block bool deletedAllCookies = false;
+ [store getAllCookies:^(NSArray<NSHTTPCookie *> *cookies) {
+ deleteCookies(store, adoptNS([cookies mutableCopy]), ^{
+ deletedAllCookies = true;
+ });
+ }];
+ TestWebKitAPI::Util::run(&deletedAllCookies);
+ };
+
+ auto runTest = [&] (WKWebsiteDataStore *dataStore) {
+ auto configuration = adoptNS([WKWebViewConfiguration new]);
+ configuration.get().websiteDataStore = dataStore;
+ auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectZero configuration:configuration.get()]);
+ auto observer = adoptNS([CookieObserver new]);
+ globalCookieStore = webView.get().configuration.websiteDataStore.httpCookieStore;
+ removeAllCookies(globalCookieStore.get());
+ [globalCookieStore addObserver:observer.get()];
+ observerCallbacks = 0;
+ [webView loadRequest:server.request()];
+ [webView _test_waitForDidFinishNavigation];
+ while (!observerCallbacks)
+ TestWebKitAPI::Util::spinRunLoop();
+ __block bool gotCookie = false;
+ [globalCookieStore getAllCookies:^(NSArray<NSHTTPCookie *> *cookies) {
+ RELEASE_ASSERT(cookies.count == 1u);
+ EXPECT_WK_STREQ(cookies[0].name, "testkey");
+ EXPECT_WK_STREQ(cookies[0].value, "testvalue");
+ gotCookie = true;
+ }];
+ TestWebKitAPI::Util::run(&gotCookie);
+ EXPECT_EQ(observerCallbacks, 1u);
+ };
+
+ runTest([WKWebsiteDataStore defaultDataStore]);
+ runTest([WKWebsiteDataStore nonPersistentDataStore]);
+}
+
static bool finished;
@interface CookieUIDelegate : NSObject <WKUIDelegate>
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes