OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "net/http/http_network_layer.h" | 5 #include "net/http/http_network_layer.h" |
6 | 6 |
7 #include "net/base/mock_cert_verifier.h" | 7 #include "net/base/mock_cert_verifier.h" |
8 #include "net/base/net_log.h" | 8 #include "net/base/net_log.h" |
9 #include "net/dns/mock_host_resolver.h" | 9 #include "net/dns/mock_host_resolver.h" |
10 #include "net/http/http_network_session.h" | 10 #include "net/http/http_network_session.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 } | 81 } |
82 | 82 |
83 TEST_F(HttpNetworkLayerTest, GET) { | 83 TEST_F(HttpNetworkLayerTest, GET) { |
84 MockRead data_reads[] = { | 84 MockRead data_reads[] = { |
85 MockRead("HTTP/1.0 200 OK\r\n\r\n"), | 85 MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
86 MockRead("hello world"), | 86 MockRead("hello world"), |
87 MockRead(SYNCHRONOUS, OK), | 87 MockRead(SYNCHRONOUS, OK), |
88 }; | 88 }; |
89 MockWrite data_writes[] = { | 89 MockWrite data_writes[] = { |
90 MockWrite("GET / HTTP/1.1\r\n" | 90 MockWrite("GET / HTTP/1.1\r\n" |
91 "Host: www.google.com\r\n" | 91 "Host: www.google.com\r\n" |
92 "Connection: keep-alive\r\n" | 92 "Connection: keep-alive\r\n" |
93 "User-Agent: Foo/1.0\r\n\r\n"), | 93 "User-Agent: Foo/1.0\r\n\r\n"), |
94 }; | 94 }; |
95 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | 95 StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
96 data_writes, arraysize(data_writes)); | 96 data_writes, arraysize(data_writes)); |
97 mock_socket_factory_.AddSocketDataProvider(&data); | 97 mock_socket_factory_.AddSocketDataProvider(&data); |
98 | 98 |
99 TestCompletionCallback callback; | 99 TestCompletionCallback callback; |
100 | 100 |
101 HttpRequestInfo request_info; | 101 HttpRequestInfo request_info; |
102 request_info.url = GURL("http://www.google.com/"); | 102 request_info.url = GURL("http://www.google.com/"); |
103 request_info.method = "GET"; | 103 request_info.method = "GET"; |
104 request_info.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, | 104 request_info.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
105 "Foo/1.0"); | 105 "Foo/1.0"); |
106 request_info.load_flags = LOAD_NORMAL; | 106 request_info.load_flags = LOAD_NORMAL; |
107 | 107 |
108 scoped_ptr<HttpTransaction> trans; | 108 scoped_ptr<HttpTransaction> trans; |
109 int rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans, NULL); | 109 int rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans, NULL); |
110 EXPECT_EQ(OK, rv); | 110 EXPECT_EQ(OK, rv); |
111 | 111 |
112 rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); | 112 rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
113 if (rv == ERR_IO_PENDING) | 113 rv = callback.GetResult(rv); |
114 rv = callback.WaitForResult(); | |
115 ASSERT_EQ(OK, rv); | 114 ASSERT_EQ(OK, rv); |
116 | 115 |
117 std::string contents; | 116 std::string contents; |
118 rv = ReadTransaction(trans.get(), &contents); | 117 rv = ReadTransaction(trans.get(), &contents); |
119 EXPECT_EQ(OK, rv); | 118 EXPECT_EQ(OK, rv); |
120 EXPECT_EQ("hello world", contents); | 119 EXPECT_EQ("hello world", contents); |
121 } | 120 } |
122 | 121 |
123 TEST_F(HttpNetworkLayerTest, ServerFallback) { | 122 TEST_F(HttpNetworkLayerTest, ServerFallback) { |
124 // Verify that a Connection: Proxy-Bypass header induces proxy fallback to | 123 // Verify that a Connection: Proxy-Bypass header induces proxy fallback to |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
283 // We should have read the original page data. | 282 // We should have read the original page data. |
284 std::string contents; | 283 std::string contents; |
285 rv = ReadTransaction(trans.get(), &contents); | 284 rv = ReadTransaction(trans.get(), &contents); |
286 EXPECT_EQ(OK, rv); | 285 EXPECT_EQ(OK, rv); |
287 EXPECT_EQ("Bypass message", contents); | 286 EXPECT_EQ("Bypass message", contents); |
288 | 287 |
289 // We should have no entries in our bad proxy list. | 288 // We should have no entries in our bad proxy list. |
290 ASSERT_EQ(0u, proxy_service_->proxy_retry_info().size()); | 289 ASSERT_EQ(0u, proxy_service_->proxy_retry_info().size()); |
291 } | 290 } |
292 | 291 |
292 TEST_F(HttpNetworkLayerTest, NetworkVerified) { | |
293 MockRead data_reads[] = { | |
294 MockRead("HTTP/1.0 200 OK\r\n\r\n"), | |
295 MockRead("hello world"), | |
296 MockRead(SYNCHRONOUS, OK), | |
297 }; | |
298 MockWrite data_writes[] = { | |
299 MockWrite("GET / HTTP/1.1\r\n" | |
300 "Host: www.google.com\r\n" | |
301 "Connection: keep-alive\r\n" | |
302 "User-Agent: Foo/1.0\r\n\r\n"), | |
303 }; | |
304 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | |
305 data_writes, arraysize(data_writes)); | |
306 mock_socket_factory_.AddSocketDataProvider(&data); | |
307 | |
308 TestCompletionCallback callback; | |
309 | |
310 HttpRequestInfo request_info; | |
311 request_info.url = GURL("http://www.google.com/"); | |
312 request_info.method = "GET"; | |
313 request_info.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, | |
314 "Foo/1.0"); | |
315 request_info.load_flags = LOAD_NORMAL; | |
316 | |
317 scoped_ptr<HttpTransaction> trans; | |
318 int rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans, NULL); | |
319 EXPECT_EQ(OK, rv); | |
320 | |
321 rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); | |
322 rv = callback.GetResult(rv); | |
323 ASSERT_EQ(OK, rv); | |
rvargas (doing something else)
2013/04/08 21:54:46
nit: merge this line with the previous one.
Randy Smith (Not in Mondays)
2013/04/08 22:00:14
Done.
| |
324 | |
325 EXPECT_TRUE(trans->GetResponseInfo()->network_accessed); | |
326 } | |
327 | |
328 TEST_F(HttpNetworkLayerTest, NetworkUnVerified) { | |
329 MockRead data_reads[] = { | |
330 MockRead(ASYNC, ERR_CONNECTION_RESET), | |
331 }; | |
332 MockWrite data_writes[] = { | |
333 MockWrite("GET / HTTP/1.1\r\n" | |
334 "Host: www.google.com\r\n" | |
335 "Connection: keep-alive\r\n" | |
336 "User-Agent: Foo/1.0\r\n\r\n"), | |
337 }; | |
338 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | |
339 data_writes, arraysize(data_writes)); | |
340 mock_socket_factory_.AddSocketDataProvider(&data); | |
341 | |
342 TestCompletionCallback callback; | |
343 | |
344 HttpRequestInfo request_info; | |
345 request_info.url = GURL("http://www.google.com/"); | |
346 request_info.method = "GET"; | |
347 request_info.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, | |
348 "Foo/1.0"); | |
349 request_info.load_flags = LOAD_NORMAL; | |
350 | |
351 scoped_ptr<HttpTransaction> trans; | |
352 int rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans, NULL); | |
353 EXPECT_EQ(OK, rv); | |
354 | |
355 rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); | |
356 rv = callback.GetResult(rv); | |
357 ASSERT_EQ(ERR_CONNECTION_RESET, rv); | |
358 | |
359 // If the response info is null, that means that any consumer won't | |
360 // see the network accessed bit set. | |
361 EXPECT_EQ(NULL, trans->GetResponseInfo()); | |
362 } | |
363 | |
293 } // namespace | 364 } // namespace |
294 | 365 |
295 } // namespace net | 366 } // namespace net |
OLD | NEW |