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

Side by Side Diff: components/cronet/ios/test/cronet_http_test.mm

Issue 2513023002: [Cronet] Add CookieStoreIOS. (Closed)
Patch Set: . Created 4 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « components/cronet/ios/cronet_environment.mm ('k') | components/cronet/ios/test/test_server.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 return self; 50 return self;
51 } 51 }
52 52
53 - (void)dealloc { 53 - (void)dealloc {
54 dispatch_release(_semaphore); 54 dispatch_release(_semaphore);
55 [_error release]; 55 [_error release];
56 _error = nil; 56 _error = nil;
57 [super dealloc]; 57 [super dealloc];
58 } 58 }
59 59
60 - (void)reset {
61 _responseBody = nil;
62 _error = nil;
63 }
64
60 - (void)URLSession:(NSURLSession*)session 65 - (void)URLSession:(NSURLSession*)session
61 didBecomeInvalidWithError:(NSError*)error { 66 didBecomeInvalidWithError:(NSError*)error {
62 } 67 }
63 68
64 - (void)URLSession:(NSURLSession*)session 69 - (void)URLSession:(NSURLSession*)session
65 task:(NSURLSessionTask*)task 70 task:(NSURLSessionTask*)task
66 didCompleteWithError:(NSError*)error { 71 didCompleteWithError:(NSError*)error {
67 [self setError:error]; 72 [self setError:error];
68 dispatch_semaphore_signal(_semaphore); 73 dispatch_semaphore_signal(_semaphore);
69 } 74 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 } 145 }
141 146
142 void TearDown() override { 147 void TearDown() override {
143 grpc_support::ShutdownQuicTestServer(); 148 grpc_support::ShutdownQuicTestServer();
144 TestServer::Shutdown(); 149 TestServer::Shutdown();
145 } 150 }
146 151
147 // Launches the supplied |task| and blocks until it completes, with a timeout 152 // Launches the supplied |task| and blocks until it completes, with a timeout
148 // of 1 second. 153 // of 1 second.
149 void StartDataTaskAndWaitForCompletion(NSURLSessionDataTask* task) { 154 void StartDataTaskAndWaitForCompletion(NSURLSessionDataTask* task) {
155 [delegate_ reset];
150 [task resume]; 156 [task resume];
151 int64_t deadline_ns = 1 * ns_in_second; 157 int64_t deadline_ns = 1 * ns_in_second;
152 dispatch_semaphore_wait([delegate_ semaphore], 158 dispatch_semaphore_wait([delegate_ semaphore],
153 dispatch_time(DISPATCH_TIME_NOW, deadline_ns)); 159 dispatch_time(DISPATCH_TIME_NOW, deadline_ns));
154 } 160 }
155 161
156 base::scoped_nsobject<NSURLSession> session_; 162 base::scoped_nsobject<NSURLSession> session_;
157 base::scoped_nsobject<TestDelegate> delegate_; 163 base::scoped_nsobject<TestDelegate> delegate_;
158 }; 164 };
159 165
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 TEST_F(HttpTest, SetUserAgentIsExact) { 214 TEST_F(HttpTest, SetUserAgentIsExact) {
209 NSURL* url = 215 NSURL* url =
210 net::NSURLWithGURL(GURL(TestServer::GetEchoHeaderURL("User-Agent"))); 216 net::NSURLWithGURL(GURL(TestServer::GetEchoHeaderURL("User-Agent")));
211 [Cronet setRequestFilterBlock:nil]; 217 [Cronet setRequestFilterBlock:nil];
212 NSURLSessionDataTask* task = [session_ dataTaskWithURL:url]; 218 NSURLSessionDataTask* task = [session_ dataTaskWithURL:url];
213 StartDataTaskAndWaitForCompletion(task); 219 StartDataTaskAndWaitForCompletion(task);
214 EXPECT_EQ(nil, [delegate_ error]); 220 EXPECT_EQ(nil, [delegate_ error]);
215 EXPECT_STREQ(kUserAgent, [[delegate_ responseBody] UTF8String]); 221 EXPECT_STREQ(kUserAgent, [[delegate_ responseBody] UTF8String]);
216 } 222 }
217 223
224 TEST_F(HttpTest, SetCookie) {
225 const char kCookieHeader[] = "Cookie";
226 const char kCookieLine[] = "aaaa=bbb";
227 NSURL* echoCookieUrl =
228 net::NSURLWithGURL(GURL(TestServer::GetEchoHeaderURL(kCookieHeader)));
229 StartDataTaskAndWaitForCompletion([session_ dataTaskWithURL:echoCookieUrl]);
230 EXPECT_EQ(nil, [delegate_ error]);
231 EXPECT_EQ(nil, [delegate_ responseBody]);
232
233 NSURL* setCookieUrl =
234 net::NSURLWithGURL(GURL(TestServer::GetSetCookieURL(kCookieLine)));
235 StartDataTaskAndWaitForCompletion([session_ dataTaskWithURL:setCookieUrl]);
236 EXPECT_EQ(nil, [delegate_ error]);
237 EXPECT_TRUE([[delegate_ responseBody]
238 containsString:base::SysUTF8ToNSString(kCookieLine)]);
239
240 StartDataTaskAndWaitForCompletion([session_ dataTaskWithURL:echoCookieUrl]);
241 EXPECT_EQ(nil, [delegate_ error]);
242 EXPECT_TRUE([[delegate_ responseBody]
243 containsString:base::SysUTF8ToNSString(kCookieLine)]);
244 }
245
218 TEST_F(HttpTest, FilterOutRequest) { 246 TEST_F(HttpTest, FilterOutRequest) {
219 NSURL* url = 247 NSURL* url =
220 net::NSURLWithGURL(GURL(TestServer::GetEchoHeaderURL("User-Agent"))); 248 net::NSURLWithGURL(GURL(TestServer::GetEchoHeaderURL("User-Agent")));
221 __block BOOL block_used = NO; 249 __block BOOL block_used = NO;
222 NSURLSessionDataTask* task = [session_ dataTaskWithURL:url]; 250 NSURLSessionDataTask* task = [session_ dataTaskWithURL:url];
223 [Cronet setRequestFilterBlock:^(NSURLRequest* request) { 251 [Cronet setRequestFilterBlock:^(NSURLRequest* request) {
224 block_used = YES; 252 block_used = YES;
225 EXPECT_EQ([request URL], url); 253 EXPECT_EQ([request URL], url);
226 return NO; 254 return NO;
227 }]; 255 }];
228 StartDataTaskAndWaitForCompletion(task); 256 StartDataTaskAndWaitForCompletion(task);
229 EXPECT_TRUE(block_used); 257 EXPECT_TRUE(block_used);
230 EXPECT_EQ(nil, [delegate_ error]); 258 EXPECT_EQ(nil, [delegate_ error]);
231 EXPECT_FALSE([[delegate_ responseBody] 259 EXPECT_FALSE([[delegate_ responseBody]
232 containsString:base::SysUTF8ToNSString(kUserAgent)]); 260 containsString:base::SysUTF8ToNSString(kUserAgent)]);
233 EXPECT_TRUE([[delegate_ responseBody] containsString:@"CFNetwork"]); 261 EXPECT_TRUE([[delegate_ responseBody] containsString:@"CFNetwork"]);
234 } 262 }
235 263
236 } // namespace cronet 264 } // namespace cronet
OLDNEW
« no previous file with comments | « components/cronet/ios/cronet_environment.mm ('k') | components/cronet/ios/test/test_server.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698