| 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 net::HttpNetworkLayer factory(net::ProxyService::CreateNull()); |
| 26 net::HttpNetworkLayer factory(&proxy_service); | |
| 27 | |
| 28 scoped_ptr<net::HttpTransaction> trans(factory.CreateTransaction()); | 25 scoped_ptr<net::HttpTransaction> trans(factory.CreateTransaction()); |
| 29 } | 26 } |
| 30 | 27 |
| 31 TEST_F(HttpNetworkLayerTest, Suspend) { | 28 TEST_F(HttpNetworkLayerTest, Suspend) { |
| 32 net::ProxyService proxy_service(new net::ProxyResolverNull); | 29 net::HttpNetworkLayer factory(net::ProxyService::CreateNull()); |
| 33 net::HttpNetworkLayer factory(&proxy_service); | |
| 34 | 30 |
| 35 scoped_ptr<net::HttpTransaction> trans(factory.CreateTransaction()); | 31 scoped_ptr<net::HttpTransaction> trans(factory.CreateTransaction()); |
| 36 trans.reset(); | 32 trans.reset(); |
| 37 | 33 |
| 38 factory.Suspend(true); | 34 factory.Suspend(true); |
| 39 | 35 |
| 40 trans.reset(factory.CreateTransaction()); | 36 trans.reset(factory.CreateTransaction()); |
| 41 ASSERT_TRUE(trans == NULL); | 37 ASSERT_TRUE(trans == NULL); |
| 42 | 38 |
| 43 factory.Suspend(false); | 39 factory.Suspend(false); |
| 44 | 40 |
| 45 trans.reset(factory.CreateTransaction()); | 41 trans.reset(factory.CreateTransaction()); |
| 46 } | 42 } |
| 47 | 43 |
| 48 TEST_F(HttpNetworkLayerTest, GoogleGET) { | 44 TEST_F(HttpNetworkLayerTest, GoogleGET) { |
| 49 net::ProxyService proxy_service(new net::ProxyResolverNull); | 45 net::HttpNetworkLayer factory(net::ProxyService::CreateNull()); |
| 50 net::HttpNetworkLayer factory(&proxy_service); | |
| 51 | 46 |
| 52 TestCompletionCallback callback; | 47 TestCompletionCallback callback; |
| 53 | 48 |
| 54 scoped_ptr<net::HttpTransaction> trans(factory.CreateTransaction()); | 49 scoped_ptr<net::HttpTransaction> trans(factory.CreateTransaction()); |
| 55 | 50 |
| 56 net::HttpRequestInfo request_info; | 51 net::HttpRequestInfo request_info; |
| 57 request_info.url = GURL("http://www.google.com/"); | 52 request_info.url = GURL("http://www.google.com/"); |
| 58 request_info.method = "GET"; | 53 request_info.method = "GET"; |
| 59 request_info.user_agent = "Foo/1.0"; | 54 request_info.user_agent = "Foo/1.0"; |
| 60 request_info.load_flags = net::LOAD_NORMAL; | 55 request_info.load_flags = net::LOAD_NORMAL; |
| 61 | 56 |
| 62 int rv = trans->Start(&request_info, &callback); | 57 int rv = trans->Start(&request_info, &callback); |
| 63 if (rv == net::ERR_IO_PENDING) | 58 if (rv == net::ERR_IO_PENDING) |
| 64 rv = callback.WaitForResult(); | 59 rv = callback.WaitForResult(); |
| 65 EXPECT_EQ(net::OK, rv); | 60 EXPECT_EQ(net::OK, rv); |
| 66 | 61 |
| 67 std::string contents; | 62 std::string contents; |
| 68 rv = ReadTransaction(trans.get(), &contents); | 63 rv = ReadTransaction(trans.get(), &contents); |
| 69 EXPECT_EQ(net::OK, rv); | 64 EXPECT_EQ(net::OK, rv); |
| 70 } | 65 } |
| 71 | 66 |
| OLD | NEW |