OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/base/mock_host_resolver.h" | 5 #include "net/base/mock_host_resolver.h" |
6 #include "net/base/net_log.h" | 6 #include "net/base/net_log.h" |
7 #include "net/base/ssl_config_service_defaults.h" | 7 #include "net/base/ssl_config_service_defaults.h" |
8 #include "net/http/http_network_layer.h" | 8 #include "net/http/http_network_layer.h" |
9 #include "net/http/http_transaction_unittest.h" | 9 #include "net/http/http_transaction_unittest.h" |
10 #include "net/proxy/proxy_service.h" | 10 #include "net/proxy/proxy_service.h" |
11 #include "net/socket/socket_test_util.h" | 11 #include "net/socket/socket_test_util.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "testing/platform_test.h" | 13 #include "testing/platform_test.h" |
14 | 14 |
15 class HttpNetworkLayerTest : public PlatformTest { | 15 class HttpNetworkLayerTest : public PlatformTest { |
16 }; | 16 }; |
17 | 17 |
18 TEST_F(HttpNetworkLayerTest, CreateAndDestroy) { | 18 TEST_F(HttpNetworkLayerTest, CreateAndDestroy) { |
19 net::HttpNetworkLayer factory( | 19 net::HttpNetworkLayer factory( |
20 NULL, NULL, new net::MockHostResolver, net::ProxyService::CreateNull(), | 20 NULL, NULL, new net::MockHostResolver, net::ProxyService::CreateNull(), |
21 new net::SSLConfigServiceDefaults, NULL); | 21 new net::SSLConfigServiceDefaults, NULL, NULL); |
22 | 22 |
23 scoped_ptr<net::HttpTransaction> trans; | 23 scoped_ptr<net::HttpTransaction> trans; |
24 int rv = factory.CreateTransaction(&trans); | 24 int rv = factory.CreateTransaction(&trans); |
25 EXPECT_EQ(net::OK, rv); | 25 EXPECT_EQ(net::OK, rv); |
26 EXPECT_TRUE(trans.get() != NULL); | 26 EXPECT_TRUE(trans.get() != NULL); |
27 } | 27 } |
28 | 28 |
29 TEST_F(HttpNetworkLayerTest, Suspend) { | 29 TEST_F(HttpNetworkLayerTest, Suspend) { |
30 net::HttpNetworkLayer factory( | 30 net::HttpNetworkLayer factory( |
31 NULL, NULL, new net::MockHostResolver, net::ProxyService::CreateNull(), | 31 NULL, NULL, new net::MockHostResolver, net::ProxyService::CreateNull(), |
32 new net::SSLConfigServiceDefaults, NULL); | 32 new net::SSLConfigServiceDefaults, NULL, NULL); |
33 | 33 |
34 scoped_ptr<net::HttpTransaction> trans; | 34 scoped_ptr<net::HttpTransaction> trans; |
35 int rv = factory.CreateTransaction(&trans); | 35 int rv = factory.CreateTransaction(&trans); |
36 EXPECT_EQ(net::OK, rv); | 36 EXPECT_EQ(net::OK, rv); |
37 | 37 |
38 trans.reset(); | 38 trans.reset(); |
39 | 39 |
40 factory.Suspend(true); | 40 factory.Suspend(true); |
41 | 41 |
42 rv = factory.CreateTransaction(&trans); | 42 rv = factory.CreateTransaction(&trans); |
(...skipping 21 matching lines...) Expand all Loading... |
64 "User-Agent: Foo/1.0\r\n\r\n"), | 64 "User-Agent: Foo/1.0\r\n\r\n"), |
65 }; | 65 }; |
66 net::StaticSocketDataProvider data(data_reads, arraysize(data_reads), | 66 net::StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
67 data_writes, arraysize(data_reads)); | 67 data_writes, arraysize(data_reads)); |
68 mock_socket_factory.AddSocketDataProvider(&data); | 68 mock_socket_factory.AddSocketDataProvider(&data); |
69 | 69 |
70 net::HttpNetworkLayer factory(&mock_socket_factory, NULL, | 70 net::HttpNetworkLayer factory(&mock_socket_factory, NULL, |
71 new net::MockHostResolver, | 71 new net::MockHostResolver, |
72 net::ProxyService::CreateNull(), | 72 net::ProxyService::CreateNull(), |
73 new net::SSLConfigServiceDefaults, | 73 new net::SSLConfigServiceDefaults, |
74 NULL); | 74 NULL, NULL); |
75 | 75 |
76 TestCompletionCallback callback; | 76 TestCompletionCallback callback; |
77 | 77 |
78 scoped_ptr<net::HttpTransaction> trans; | 78 scoped_ptr<net::HttpTransaction> trans; |
79 int rv = factory.CreateTransaction(&trans); | 79 int rv = factory.CreateTransaction(&trans); |
80 EXPECT_EQ(net::OK, rv); | 80 EXPECT_EQ(net::OK, rv); |
81 | 81 |
82 net::HttpRequestInfo request_info; | 82 net::HttpRequestInfo request_info; |
83 request_info.url = GURL("http://www.google.com/"); | 83 request_info.url = GURL("http://www.google.com/"); |
84 request_info.method = "GET"; | 84 request_info.method = "GET"; |
85 request_info.extra_headers.SetHeader(net::HttpRequestHeaders::kUserAgent, | 85 request_info.extra_headers.SetHeader(net::HttpRequestHeaders::kUserAgent, |
86 "Foo/1.0"); | 86 "Foo/1.0"); |
87 request_info.load_flags = net::LOAD_NORMAL; | 87 request_info.load_flags = net::LOAD_NORMAL; |
88 | 88 |
89 rv = trans->Start(&request_info, &callback, net::BoundNetLog()); | 89 rv = trans->Start(&request_info, &callback, net::BoundNetLog()); |
90 if (rv == net::ERR_IO_PENDING) | 90 if (rv == net::ERR_IO_PENDING) |
91 rv = callback.WaitForResult(); | 91 rv = callback.WaitForResult(); |
92 ASSERT_EQ(net::OK, rv); | 92 ASSERT_EQ(net::OK, rv); |
93 | 93 |
94 std::string contents; | 94 std::string contents; |
95 rv = ReadTransaction(trans.get(), &contents); | 95 rv = ReadTransaction(trans.get(), &contents); |
96 EXPECT_EQ(net::OK, rv); | 96 EXPECT_EQ(net::OK, rv); |
97 EXPECT_EQ("hello world", contents); | 97 EXPECT_EQ("hello world", contents); |
98 } | 98 } |
OLD | NEW |