| 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 HttpTest() {} | 123 HttpTest() {} |
| 124 ~HttpTest() override {} | 124 ~HttpTest() override {} |
| 125 | 125 |
| 126 void SetUp() override { | 126 void SetUp() override { |
| 127 grpc_support::StartQuicTestServer(); | 127 grpc_support::StartQuicTestServer(); |
| 128 TestServer::Start(); | 128 TestServer::Start(); |
| 129 | 129 |
| 130 [Cronet setRequestFilterBlock:^(NSURLRequest* request) { | 130 [Cronet setRequestFilterBlock:^(NSURLRequest* request) { |
| 131 return YES; | 131 return YES; |
| 132 }]; | 132 }]; |
| 133 StartCronetIfNecessary(grpc_support::GetQuicTestServerPort()); | 133 StartCronet(grpc_support::GetQuicTestServerPort()); |
| 134 [Cronet registerHttpProtocolHandler]; | 134 [Cronet registerHttpProtocolHandler]; |
| 135 NSURLSessionConfiguration* config = | 135 NSURLSessionConfiguration* config = |
| 136 [NSURLSessionConfiguration ephemeralSessionConfiguration]; | 136 [NSURLSessionConfiguration ephemeralSessionConfiguration]; |
| 137 [Cronet installIntoSessionConfiguration:config]; | 137 [Cronet installIntoSessionConfiguration:config]; |
| 138 delegate_.reset([[TestDelegate alloc] init]); | 138 delegate_.reset([[TestDelegate alloc] init]); |
| 139 NSURLSession* session = [NSURLSession sessionWithConfiguration:config | 139 NSURLSession* session = [NSURLSession sessionWithConfiguration:config |
| 140 delegate:delegate_ | 140 delegate:delegate_ |
| 141 delegateQueue:nil]; | 141 delegateQueue:nil]; |
| 142 // Take a reference to the session and store it so it doesn't get | 142 // Take a reference to the session and store it so it doesn't get |
| 143 // deallocated until this object does. | 143 // deallocated until this object does. |
| 144 session_.reset([session retain]); | 144 session_.reset([session retain]); |
| 145 } | 145 } |
| 146 | 146 |
| 147 void TearDown() override { | 147 void TearDown() override { |
| 148 grpc_support::ShutdownQuicTestServer(); | 148 grpc_support::ShutdownQuicTestServer(); |
| 149 TestServer::Shutdown(); | 149 TestServer::Shutdown(); |
| 150 |
| 151 [Cronet stopNetLog]; |
| 150 } | 152 } |
| 151 | 153 |
| 152 // Launches the supplied |task| and blocks until it completes, with a timeout | 154 // Launches the supplied |task| and blocks until it completes, with a timeout |
| 153 // of 1 second. | 155 // of 1 second. |
| 154 void StartDataTaskAndWaitForCompletion(NSURLSessionDataTask* task) { | 156 void StartDataTaskAndWaitForCompletion(NSURLSessionDataTask* task) { |
| 155 [delegate_ reset]; | 157 [delegate_ reset]; |
| 156 [task resume]; | 158 [task resume]; |
| 157 int64_t deadline_ns = 1 * ns_in_second; | 159 int64_t deadline_ns = 1 * ns_in_second; |
| 158 dispatch_semaphore_wait([delegate_ semaphore], | 160 dispatch_semaphore_wait([delegate_ semaphore], |
| 159 dispatch_time(DISPATCH_TIME_NOW, deadline_ns)); | 161 dispatch_time(DISPATCH_TIME_NOW, deadline_ns)); |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 [Cronet setRequestFilterBlock:^(NSURLRequest* request) { | 411 [Cronet setRequestFilterBlock:^(NSURLRequest* request) { |
| 410 EXPECT_TRUE(false) << "Block should not be called for unsupported requests"; | 412 EXPECT_TRUE(false) << "Block should not be called for unsupported requests"; |
| 411 return YES; | 413 return YES; |
| 412 }]; | 414 }]; |
| 413 StartDataTaskAndWaitForCompletion(task); | 415 StartDataTaskAndWaitForCompletion(task); |
| 414 EXPECT_EQ(nil, [delegate_ error]); | 416 EXPECT_EQ(nil, [delegate_ error]); |
| 415 EXPECT_TRUE([[delegate_ responseBody] containsString:testString]); | 417 EXPECT_TRUE([[delegate_ responseBody] containsString:testString]); |
| 416 } | 418 } |
| 417 | 419 |
| 418 } // namespace cronet | 420 } // namespace cronet |
| OLD | NEW |