OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/ref_counted.h" | 5 #include "base/ref_counted.h" |
6 #include "net/base/host_resolver_unittest.h" | 6 #include "net/base/host_resolver_unittest.h" |
7 #include "net/http/http_network_layer.h" | 7 #include "net/http/http_network_layer.h" |
8 #include "net/http/http_transaction_unittest.h" | 8 #include "net/http/http_transaction_unittest.h" |
9 #include "net/proxy/proxy_service.h" | 9 #include "net/proxy/proxy_service.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "testing/platform_test.h" | 11 #include "testing/platform_test.h" |
12 | 12 |
13 class HttpNetworkLayerTest : public PlatformTest { | 13 class HttpNetworkLayerTest : public PlatformTest { |
14 public: | 14 public: |
15 HttpNetworkLayerTest() | 15 HttpNetworkLayerTest() |
16 : host_mapper_(new net::RuleBasedHostMapper()), | 16 : host_mapper_(new net::RuleBasedHostMapper()), |
17 scoped_host_mapper_(host_mapper_.get()) { | 17 scoped_host_mapper_(host_mapper_.get()) { |
18 // TODO(darin): kill this exception once we have a way to test out the | 18 // TODO(darin): kill this exception once we have a way to test out the |
19 // HttpNetworkLayer class using loopback connections. | 19 // HttpNetworkLayer class using loopback connections. |
20 host_mapper_->AllowDirectLookup("www.google.com"); | 20 host_mapper_->AllowDirectLookup("www.google.com"); |
21 } | 21 } |
22 | 22 |
23 private: | 23 private: |
24 scoped_refptr<net::RuleBasedHostMapper> host_mapper_; | 24 scoped_refptr<net::RuleBasedHostMapper> host_mapper_; |
25 net::ScopedHostMapper scoped_host_mapper_; | 25 net::ScopedHostMapper scoped_host_mapper_; |
26 }; | 26 }; |
27 | 27 |
28 TEST_F(HttpNetworkLayerTest, CreateAndDestroy) { | 28 TEST_F(HttpNetworkLayerTest, CreateAndDestroy) { |
| 29 net::HostResolver host_resolver; |
29 scoped_ptr<net::ProxyService> proxy_service(net::ProxyService::CreateNull()); | 30 scoped_ptr<net::ProxyService> proxy_service(net::ProxyService::CreateNull()); |
30 net::HttpNetworkLayer factory(proxy_service.get()); | 31 net::HttpNetworkLayer factory(&host_resolver, proxy_service.get()); |
31 | 32 |
32 scoped_ptr<net::HttpTransaction> trans(factory.CreateTransaction()); | 33 scoped_ptr<net::HttpTransaction> trans(factory.CreateTransaction()); |
33 } | 34 } |
34 | 35 |
35 TEST_F(HttpNetworkLayerTest, Suspend) { | 36 TEST_F(HttpNetworkLayerTest, Suspend) { |
| 37 net::HostResolver host_resolver; |
36 scoped_ptr<net::ProxyService> proxy_service(net::ProxyService::CreateNull()); | 38 scoped_ptr<net::ProxyService> proxy_service(net::ProxyService::CreateNull()); |
37 net::HttpNetworkLayer factory(proxy_service.get()); | 39 net::HttpNetworkLayer factory(&host_resolver, proxy_service.get()); |
38 | 40 |
39 scoped_ptr<net::HttpTransaction> trans(factory.CreateTransaction()); | 41 scoped_ptr<net::HttpTransaction> trans(factory.CreateTransaction()); |
40 trans.reset(); | 42 trans.reset(); |
41 | 43 |
42 factory.Suspend(true); | 44 factory.Suspend(true); |
43 | 45 |
44 trans.reset(factory.CreateTransaction()); | 46 trans.reset(factory.CreateTransaction()); |
45 ASSERT_TRUE(trans == NULL); | 47 ASSERT_TRUE(trans == NULL); |
46 | 48 |
47 factory.Suspend(false); | 49 factory.Suspend(false); |
48 | 50 |
49 trans.reset(factory.CreateTransaction()); | 51 trans.reset(factory.CreateTransaction()); |
50 } | 52 } |
51 | 53 |
52 TEST_F(HttpNetworkLayerTest, GoogleGET) { | 54 TEST_F(HttpNetworkLayerTest, GoogleGET) { |
| 55 net::HostResolver host_resolver; |
53 scoped_ptr<net::ProxyService> proxy_service(net::ProxyService::CreateNull()); | 56 scoped_ptr<net::ProxyService> proxy_service(net::ProxyService::CreateNull()); |
54 net::HttpNetworkLayer factory(proxy_service.get()); | 57 net::HttpNetworkLayer factory(&host_resolver, proxy_service.get()); |
55 | 58 |
56 TestCompletionCallback callback; | 59 TestCompletionCallback callback; |
57 | 60 |
58 scoped_ptr<net::HttpTransaction> trans(factory.CreateTransaction()); | 61 scoped_ptr<net::HttpTransaction> trans(factory.CreateTransaction()); |
59 | 62 |
60 net::HttpRequestInfo request_info; | 63 net::HttpRequestInfo request_info; |
61 request_info.url = GURL("http://www.google.com/"); | 64 request_info.url = GURL("http://www.google.com/"); |
62 request_info.method = "GET"; | 65 request_info.method = "GET"; |
63 request_info.user_agent = "Foo/1.0"; | 66 request_info.user_agent = "Foo/1.0"; |
64 request_info.load_flags = net::LOAD_NORMAL; | 67 request_info.load_flags = net::LOAD_NORMAL; |
65 | 68 |
66 int rv = trans->Start(&request_info, &callback); | 69 int rv = trans->Start(&request_info, &callback); |
67 if (rv == net::ERR_IO_PENDING) | 70 if (rv == net::ERR_IO_PENDING) |
68 rv = callback.WaitForResult(); | 71 rv = callback.WaitForResult(); |
69 EXPECT_EQ(net::OK, rv); | 72 EXPECT_EQ(net::OK, rv); |
70 | 73 |
71 std::string contents; | 74 std::string contents; |
72 rv = ReadTransaction(trans.get(), &contents); | 75 rv = ReadTransaction(trans.get(), &contents); |
73 EXPECT_EQ(net::OK, rv); | 76 EXPECT_EQ(net::OK, rv); |
74 } | 77 } |
OLD | NEW |