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 <Foundation/Foundation.h> | 5 #import <Foundation/Foundation.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #import "CrNet.h" | 8 #import "CrNet.h" |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 } | 187 } |
188 | 188 |
189 base::scoped_nsobject<NSURLSession> session_; | 189 base::scoped_nsobject<NSURLSession> session_; |
190 base::scoped_nsobject<TestDelegate> delegate_; | 190 base::scoped_nsobject<TestDelegate> delegate_; |
191 | 191 |
192 private: | 192 private: |
193 base::scoped_nsobject<GCDWebServer> web_server_; | 193 base::scoped_nsobject<GCDWebServer> web_server_; |
194 GURL server_root_; | 194 GURL server_root_; |
195 }; | 195 }; |
196 | 196 |
197 TEST_F(HttpTest, NSURLConnectionReceivesData) { | |
198 const char kData[] = "foobar"; | |
199 const char kPath[] = "/foo"; | |
200 RegisterPathText(kPath, kData); | |
201 StartWebServer(); | |
202 | |
203 NSURL* url = net::NSURLWithGURL(GetURL(kPath)); | |
204 NSURLRequest* req = [NSURLRequest requestWithURL:url]; | |
205 NSURLResponse* resp = nil; | |
206 NSData* received = [NSURLConnection sendSynchronousRequest:req | |
207 returningResponse:&resp | |
208 error:nullptr]; | |
pkl (ping after 24h if needed)
2016/02/09 21:44:14
Note: +sendSynchronousRequest:returningResponse:er
Elly Fong-Jones
2016/02/10 13:44:12
You are probably fine to delete these tests, if yo
| |
209 EXPECT_EQ(0, memcmp([received bytes], kData, sizeof(kData))); | |
210 } | |
211 | |
212 TEST_F(HttpTest, NSURLSessionReceivesData) { | 197 TEST_F(HttpTest, NSURLSessionReceivesData) { |
213 const char kPath[] = "/foo"; | 198 const char kPath[] = "/foo"; |
214 const char kData[] = "foobar"; | 199 const char kData[] = "foobar"; |
215 RegisterPathText(kPath, kData); | 200 RegisterPathText(kPath, kData); |
216 StartWebServer(); | 201 StartWebServer(); |
217 | 202 |
218 NSURL* url = net::NSURLWithGURL(GetURL(kPath)); | 203 NSURL* url = net::NSURLWithGURL(GetURL(kPath)); |
219 NSURLSessionDataTask* task = [session_ dataTaskWithURL:url]; | 204 NSURLSessionDataTask* task = [session_ dataTaskWithURL:url]; |
220 StartDataTaskAndWaitForCompletion(task); | 205 StartDataTaskAndWaitForCompletion(task); |
221 EXPECT_EQ(nil, [delegate_ error]); | 206 EXPECT_EQ(nil, [delegate_ error]); |
222 EXPECT_EQ(strlen(kData), [delegate_ receivedBytes]); | 207 EXPECT_EQ(strlen(kData), [delegate_ receivedBytes]); |
223 } | 208 } |
224 | 209 |
225 TEST_F(HttpTest, SdchDisabledByDefault) { | 210 TEST_F(HttpTest, SdchDisabledByDefault) { |
226 const char kPath[] = "/foo"; | 211 const char kPath[] = "/foo"; |
227 RegisterPathHandler(kPath, | 212 RegisterPathHandler(kPath, |
228 ^GCDWebServerResponse* (GCDWebServerRequest* req) { | 213 ^GCDWebServerResponse* (GCDWebServerRequest* req) { |
229 EXPECT_FALSE(HeaderValueContains(req, "Accept-Encoding", "sdch")); | 214 EXPECT_FALSE(HeaderValueContains(req, "Accept-Encoding", "sdch")); |
230 return nil; | 215 return nil; |
231 }); | 216 }); |
232 StartWebServer(); | 217 StartWebServer(); |
233 NSURL* url = net::NSURLWithGURL(GetURL(kPath)); | 218 NSURL* url = net::NSURLWithGURL(GetURL(kPath)); |
234 NSURLRequest* req = [NSURLRequest requestWithURL:url]; | 219 NSURLSessionDataTask* task = [session_ dataTaskWithURL:url]; |
235 NSURLResponse* resp = nil; | 220 StartDataTaskAndWaitForCompletion(task); |
236 NSError* error = nil; | 221 EXPECT_EQ(nil, [delegate_ error]); |
237 NSData* received = [NSURLConnection sendSynchronousRequest:req | 222 EXPECT_TRUE([delegate_ receivedBytes]); |
238 returningResponse:&resp | |
239 error:&error]; | |
240 DCHECK(received); | |
241 } | 223 } |
242 | 224 |
243 // TODO(ellyjones): There needs to be a test that enabling SDCH works, but | 225 // TODO(ellyjones): There needs to be a test that enabling SDCH works, but |
244 // because CrNet is static and 'uninstall' only disables it, there is no way to | 226 // because CrNet is static and 'uninstall' only disables it, there is no way to |
245 // have an individual test enable or disable SDCH. | 227 // have an individual test enable or disable SDCH. |
246 // Probably there is a way to get gtest tests to run in a separate process, but | 228 // Probably there is a way to get gtest tests to run in a separate process, but |
247 // I'm not sure what it is. | 229 // I'm not sure what it is. |
OLD | NEW |