| 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 HttpTest() {} | 133 HttpTest() {} |
| 134 ~HttpTest() override {} | 134 ~HttpTest() override {} |
| 135 | 135 |
| 136 void SetUp() override { | 136 void SetUp() override { |
| 137 grpc_support::StartQuicTestServer(); | 137 grpc_support::StartQuicTestServer(); |
| 138 TestServer::Start(); | 138 TestServer::Start(); |
| 139 | 139 |
| 140 [Cronet setRequestFilterBlock:^(NSURLRequest* request) { | 140 [Cronet setRequestFilterBlock:^(NSURLRequest* request) { |
| 141 return YES; | 141 return YES; |
| 142 }]; | 142 }]; |
| 143 StartCronetIfNecessary(grpc_support::GetQuicTestServerPort()); | 143 StartCronet(grpc_support::GetQuicTestServerPort()); |
| 144 [Cronet registerHttpProtocolHandler]; | 144 [Cronet registerHttpProtocolHandler]; |
| 145 NSURLSessionConfiguration* config = | 145 NSURLSessionConfiguration* config = |
| 146 [NSURLSessionConfiguration ephemeralSessionConfiguration]; | 146 [NSURLSessionConfiguration ephemeralSessionConfiguration]; |
| 147 [Cronet installIntoSessionConfiguration:config]; | 147 [Cronet installIntoSessionConfiguration:config]; |
| 148 delegate_.reset([[TestDelegate alloc] init]); | 148 delegate_.reset([[TestDelegate alloc] init]); |
| 149 NSURLSession* session = [NSURLSession sessionWithConfiguration:config | 149 NSURLSession* session = [NSURLSession sessionWithConfiguration:config |
| 150 delegate:delegate_ | 150 delegate:delegate_ |
| 151 delegateQueue:nil]; | 151 delegateQueue:nil]; |
| 152 // Take a reference to the session and store it so it doesn't get | 152 // Take a reference to the session and store it so it doesn't get |
| 153 // deallocated until this object does. | 153 // deallocated until this object does. |
| 154 session_.reset([session retain]); | 154 session_.reset([session retain]); |
| 155 } | 155 } |
| 156 | 156 |
| 157 void TearDown() override { | 157 void TearDown() override { |
| 158 grpc_support::ShutdownQuicTestServer(); | 158 grpc_support::ShutdownQuicTestServer(); |
| 159 TestServer::Shutdown(); | 159 TestServer::Shutdown(); |
| 160 |
| 161 [Cronet stopNetLog]; |
| 162 [Cronet shutdown]; |
| 160 } | 163 } |
| 161 | 164 |
| 162 // Launches the supplied |task| and blocks until it completes, with a timeout | 165 // Launches the supplied |task| and blocks until it completes, with a timeout |
| 163 // of 1 second. | 166 // of 1 second. |
| 164 void StartDataTaskAndWaitForCompletion(NSURLSessionDataTask* task) { | 167 void StartDataTaskAndWaitForCompletion(NSURLSessionDataTask* task) { |
| 165 [delegate_ reset]; | 168 [delegate_ reset]; |
| 166 [task resume]; | 169 [task resume]; |
| 167 int64_t deadline_ns = 20 * ns_in_second; | 170 int64_t deadline_ns = 20 * ns_in_second; |
| 168 ASSERT_EQ(0, dispatch_semaphore_wait( | 171 ASSERT_EQ(0, dispatch_semaphore_wait( |
| 169 [delegate_ semaphore], | 172 [delegate_ semaphore], |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 [Cronet setRequestFilterBlock:^(NSURLRequest* request) { | 454 [Cronet setRequestFilterBlock:^(NSURLRequest* request) { |
| 452 EXPECT_TRUE(false) << "Block should not be called for unsupported requests"; | 455 EXPECT_TRUE(false) << "Block should not be called for unsupported requests"; |
| 453 return YES; | 456 return YES; |
| 454 }]; | 457 }]; |
| 455 StartDataTaskAndWaitForCompletion(task); | 458 StartDataTaskAndWaitForCompletion(task); |
| 456 EXPECT_EQ(nil, [delegate_ error]); | 459 EXPECT_EQ(nil, [delegate_ error]); |
| 457 EXPECT_TRUE([[delegate_ responseBody] containsString:testString]); | 460 EXPECT_TRUE([[delegate_ responseBody] containsString:testString]); |
| 458 } | 461 } |
| 459 | 462 |
| 460 } // namespace cronet | 463 } // namespace cronet |
| OLD | NEW |