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