Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Unified Diff: components/cronet/ios/test/cronet_http_test.mm

Issue 2617853002: [Cronet] Use CookieStoreIOS to sync cookies to system store. (Closed)
Patch Set: Add SetSystemCookie test, address comments. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/cronet/ios/cronet_environment.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/cronet/ios/test/cronet_http_test.mm
diff --git a/components/cronet/ios/test/cronet_http_test.mm b/components/cronet/ios/test/cronet_http_test.mm
index 21d0419e6c3ef5ffec62cc19b248071bc4d45db5..f87822f2d56749414ff268dfb9790bedde396a23 100644
--- a/components/cronet/ios/test/cronet_http_test.mm
+++ b/components/cronet/ios/test/cronet_http_test.mm
@@ -258,9 +258,16 @@ TEST_F(HttpTest, SetUserAgentIsExact) {
TEST_F(HttpTest, SetCookie) {
const char kCookieHeader[] = "Cookie";
const char kCookieLine[] = "aaaa=bbb";
- NSURL* echoCookieUrl =
+ NSHTTPCookieStorage* systemCookieStorage =
+ [NSHTTPCookieStorage sharedHTTPCookieStorage];
+ NSURL* cookieUrl =
net::NSURLWithGURL(GURL(TestServer::GetEchoHeaderURL(kCookieHeader)));
- StartDataTaskAndWaitForCompletion([session_ dataTaskWithURL:echoCookieUrl]);
+ // Verify that cookie is not set in system storage.
+ for (NSHTTPCookie* cookie in [systemCookieStorage cookiesForURL:cookieUrl]) {
+ EXPECT_FALSE([[cookie name] isEqualToString:@"aaaa"]);
+ }
+
+ StartDataTaskAndWaitForCompletion([session_ dataTaskWithURL:cookieUrl]);
EXPECT_EQ(nil, [delegate_ error]);
EXPECT_EQ(nil, [delegate_ responseBody]);
@@ -271,10 +278,42 @@ TEST_F(HttpTest, SetCookie) {
EXPECT_TRUE([[delegate_ responseBody]
containsString:base::SysUTF8ToNSString(kCookieLine)]);
- StartDataTaskAndWaitForCompletion([session_ dataTaskWithURL:echoCookieUrl]);
+ StartDataTaskAndWaitForCompletion([session_ dataTaskWithURL:cookieUrl]);
EXPECT_EQ(nil, [delegate_ error]);
EXPECT_TRUE([[delegate_ responseBody]
containsString:base::SysUTF8ToNSString(kCookieLine)]);
+
+ // Verify that cookie is set in system storage.
+ NSHTTPCookie* systemCookie = nil;
+ for (NSHTTPCookie* cookie in [systemCookieStorage cookiesForURL:cookieUrl]) {
+ if ([cookie.name isEqualToString:@"aaaa"]) {
+ systemCookie = cookie;
+ break;
+ }
+ }
+ EXPECT_TRUE([[systemCookie value] isEqualToString:@"bbb"]);
+ [systemCookieStorage deleteCookie:systemCookie];
+}
+
+TEST_F(HttpTest, SetSystemCookie) {
+ const char kCookieHeader[] = "Cookie";
+ NSHTTPCookieStorage* systemCookieStorage =
+ [NSHTTPCookieStorage sharedHTTPCookieStorage];
+ NSURL* echoCookieUrl =
+ net::NSURLWithGURL(GURL(TestServer::GetEchoHeaderURL(kCookieHeader)));
+ NSHTTPCookie* systemCookie = [NSHTTPCookie cookieWithProperties:@{
+ NSHTTPCookiePath : [echoCookieUrl path],
+ NSHTTPCookieName : @"cccc",
+ NSHTTPCookieValue : @"dddd",
+ NSHTTPCookieDomain : [echoCookieUrl host],
+ }];
+ [systemCookieStorage setCookie:systemCookie];
+
+ StartDataTaskAndWaitForCompletion([session_ dataTaskWithURL:echoCookieUrl]);
+ EXPECT_EQ(nil, [delegate_ error]);
+ // Verify that cookie set in system store was sent to the serever.
+ EXPECT_TRUE([[delegate_ responseBody] isEqualToString:@"cccc=dddd"]);
kapishnikov 2017/01/06 16:23:17 I would use containsString here since the cookie h
mef 2017/01/06 17:58:59 Done.
+ [systemCookieStorage deleteCookie:systemCookie];
kapishnikov 2017/01/06 16:23:17 If the above 'EXPECTs' fail, the cookie is not goi
mef 2017/01/06 17:58:59 Done.
}
TEST_F(HttpTest, FilterOutRequest) {
« no previous file with comments | « components/cronet/ios/cronet_environment.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698