OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import <Cronet/Cronet.h> | 5 #import <Cronet/Cronet.h> |
6 #import <Foundation/Foundation.h> | 6 #import <Foundation/Foundation.h> |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 [systemCookieStorage setCookie:systemCookie]; | 315 [systemCookieStorage setCookie:systemCookie]; |
316 | 316 |
317 StartDataTaskAndWaitForCompletion([session_ dataTaskWithURL:echoCookieUrl]); | 317 StartDataTaskAndWaitForCompletion([session_ dataTaskWithURL:echoCookieUrl]); |
318 [systemCookieStorage deleteCookie:systemCookie]; | 318 [systemCookieStorage deleteCookie:systemCookie]; |
319 EXPECT_EQ(nil, [delegate_ error]); | 319 EXPECT_EQ(nil, [delegate_ error]); |
320 // Verify that cookie set in system store was sent to the serever. | 320 // Verify that cookie set in system store was sent to the serever. |
321 EXPECT_TRUE([[delegate_ responseBody] containsString:cookieName]); | 321 EXPECT_TRUE([[delegate_ responseBody] containsString:cookieName]); |
322 EXPECT_TRUE([[delegate_ responseBody] containsString:cookieValue]); | 322 EXPECT_TRUE([[delegate_ responseBody] containsString:cookieValue]); |
323 } | 323 } |
324 | 324 |
| 325 TEST_F(HttpTest, SystemCookieWithNullCreationTime) { |
| 326 const char kCookieHeader[] = "Cookie"; |
| 327 NSString* cookieName = [NSString |
| 328 stringWithFormat:@"SetSystemCookie-%@", [[NSUUID UUID] UUIDString]]; |
| 329 NSString* cookieValue = [[NSUUID UUID] UUIDString]; |
| 330 NSHTTPCookieStorage* systemCookieStorage = |
| 331 [NSHTTPCookieStorage sharedHTTPCookieStorage]; |
| 332 NSURL* echoCookieUrl = |
| 333 net::NSURLWithGURL(GURL(TestServer::GetEchoHeaderURL(kCookieHeader))); |
| 334 NSHTTPCookie* nullCreationTimeCookie = [NSHTTPCookie cookieWithProperties:@{ |
| 335 NSHTTPCookiePath : [echoCookieUrl path], |
| 336 NSHTTPCookieName : cookieName, |
| 337 NSHTTPCookieValue : cookieValue, |
| 338 NSHTTPCookieDomain : [echoCookieUrl host], |
| 339 @"Created" : [NSNumber numberWithDouble:0.0], |
| 340 }]; |
| 341 [systemCookieStorage setCookie:nullCreationTimeCookie]; |
| 342 NSHTTPCookie* normalCookie = [NSHTTPCookie cookieWithProperties:@{ |
| 343 NSHTTPCookiePath : [echoCookieUrl path], |
| 344 NSHTTPCookieName : [cookieName stringByAppendingString:@"-normal"], |
| 345 NSHTTPCookieValue : cookieValue, |
| 346 NSHTTPCookieDomain : [echoCookieUrl host], |
| 347 }]; |
| 348 [systemCookieStorage setCookie:normalCookie]; |
| 349 StartDataTaskAndWaitForCompletion([session_ dataTaskWithURL:echoCookieUrl]); |
| 350 [systemCookieStorage deleteCookie:nullCreationTimeCookie]; |
| 351 [systemCookieStorage deleteCookie:normalCookie]; |
| 352 EXPECT_EQ(nil, [delegate_ error]); |
| 353 // Verify that cookie set in system store was sent to the serever. |
| 354 EXPECT_TRUE([[delegate_ responseBody] containsString:cookieName]); |
| 355 EXPECT_TRUE([[delegate_ responseBody] containsString:cookieValue]); |
| 356 } |
| 357 |
325 TEST_F(HttpTest, FilterOutRequest) { | 358 TEST_F(HttpTest, FilterOutRequest) { |
326 NSURL* url = | 359 NSURL* url = |
327 net::NSURLWithGURL(GURL(TestServer::GetEchoHeaderURL("User-Agent"))); | 360 net::NSURLWithGURL(GURL(TestServer::GetEchoHeaderURL("User-Agent"))); |
328 __block BOOL block_used = NO; | 361 __block BOOL block_used = NO; |
329 NSURLSessionDataTask* task = [session_ dataTaskWithURL:url]; | 362 NSURLSessionDataTask* task = [session_ dataTaskWithURL:url]; |
330 [Cronet setRequestFilterBlock:^(NSURLRequest* request) { | 363 [Cronet setRequestFilterBlock:^(NSURLRequest* request) { |
331 block_used = YES; | 364 block_used = YES; |
332 EXPECT_EQ([request URL], url); | 365 EXPECT_EQ([request URL], url); |
333 return NO; | 366 return NO; |
334 }]; | 367 }]; |
335 StartDataTaskAndWaitForCompletion(task); | 368 StartDataTaskAndWaitForCompletion(task); |
336 EXPECT_TRUE(block_used); | 369 EXPECT_TRUE(block_used); |
337 EXPECT_EQ(nil, [delegate_ error]); | 370 EXPECT_EQ(nil, [delegate_ error]); |
338 EXPECT_FALSE([[delegate_ responseBody] | 371 EXPECT_FALSE([[delegate_ responseBody] |
339 containsString:base::SysUTF8ToNSString(kUserAgent)]); | 372 containsString:base::SysUTF8ToNSString(kUserAgent)]); |
340 EXPECT_TRUE([[delegate_ responseBody] containsString:@"CFNetwork"]); | 373 EXPECT_TRUE([[delegate_ responseBody] containsString:@"CFNetwork"]); |
341 } | 374 } |
342 | 375 |
343 } // namespace cronet | 376 } // namespace cronet |
OLD | NEW |