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

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

Issue 2510463002: [Cronet] Retain block passed to setRequestFilterBlock on iOS. (Closed)
Patch Set: Address comment. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/cronet/ios/Cronet.mm ('k') | components/cronet/ios/test/test_server.cc » ('j') | 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 89e64a2422d9b01f83fcc0154ca2b68784ad1062..36923e623a6d47a1e42db8a116aa53b87190d019 100644
--- a/components/cronet/ios/test/cronet_http_test.mm
+++ b/components/cronet/ios/test/cronet_http_test.mm
@@ -122,7 +122,11 @@ class HttpTest : public ::testing::Test {
grpc_support::StartQuicTestServer();
TestServer::Start();
+ [Cronet setRequestFilterBlock:^(NSURLRequest* request) {
+ return YES;
+ }];
StartCronetIfNecessary(grpc_support::GetQuicTestServerPort());
+ [Cronet registerHttpProtocolHandler];
NSURLSessionConfiguration* config =
[NSURLSessionConfiguration ephemeralSessionConfiguration];
[Cronet installIntoSessionConfiguration:config];
@@ -155,8 +159,15 @@ class HttpTest : public ::testing::Test {
TEST_F(HttpTest, NSURLSessionReceivesData) {
NSURL* url = net::NSURLWithGURL(GURL(grpc_support::kTestServerUrl));
+ __block BOOL block_used = NO;
NSURLSessionDataTask* task = [session_ dataTaskWithURL:url];
+ [Cronet setRequestFilterBlock:^(NSURLRequest* request) {
+ block_used = YES;
+ EXPECT_EQ([request URL], url);
+ return YES;
+ }];
StartDataTaskAndWaitForCompletion(task);
+ EXPECT_TRUE(block_used);
EXPECT_EQ(nil, [delegate_ error]);
EXPECT_STREQ(grpc_support::kHelloBodyValue,
base::SysNSStringToUTF8([delegate_ responseBody]).c_str());
@@ -197,10 +208,29 @@ TEST_F(HttpTest, NSURLSessionAcceptLanguage) {
TEST_F(HttpTest, SetUserAgentIsExact) {
NSURL* url =
net::NSURLWithGURL(GURL(TestServer::GetEchoHeaderURL("User-Agent")));
+ [Cronet setRequestFilterBlock:nil];
NSURLSessionDataTask* task = [session_ dataTaskWithURL:url];
StartDataTaskAndWaitForCompletion(task);
EXPECT_EQ(nil, [delegate_ error]);
EXPECT_STREQ(kUserAgent, [[delegate_ responseBody] UTF8String]);
}
+TEST_F(HttpTest, FilterOutRequest) {
+ NSURL* url =
+ net::NSURLWithGURL(GURL(TestServer::GetEchoHeaderURL("User-Agent")));
+ __block BOOL block_used = NO;
+ NSURLSessionDataTask* task = [session_ dataTaskWithURL:url];
+ [Cronet setRequestFilterBlock:^(NSURLRequest* request) {
+ block_used = YES;
+ EXPECT_EQ([request URL], url);
+ return NO;
+ }];
+ StartDataTaskAndWaitForCompletion(task);
+ EXPECT_TRUE(block_used);
+ EXPECT_EQ(nil, [delegate_ error]);
+ EXPECT_FALSE([[delegate_ responseBody]
+ containsString:base::SysUTF8ToNSString(kUserAgent)]);
+ EXPECT_TRUE([[delegate_ responseBody] containsString:@"CFNetwork"]);
+}
+
} // namespace cronet
« no previous file with comments | « components/cronet/ios/Cronet.mm ('k') | components/cronet/ios/test/test_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698