| 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/mock_host_resolver.h" | 5 #include "net/base/mock_host_resolver.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_service.h" | 8 #include "net/proxy/proxy_service.h" |
| 9 #include "net/socket/socket_test_util.h" | 9 #include "net/socket/socket_test_util.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 }; | 14 }; |
| 15 | 15 |
| 16 TEST_F(HttpNetworkLayerTest, CreateAndDestroy) { | 16 TEST_F(HttpNetworkLayerTest, CreateAndDestroy) { |
| 17 scoped_ptr<net::ProxyService> proxy_service(net::ProxyService::CreateNull()); | |
| 18 net::HttpNetworkLayer factory( | 17 net::HttpNetworkLayer factory( |
| 19 NULL, new net::MockHostResolver, proxy_service.get()); | 18 NULL, new net::MockHostResolver, net::ProxyService::CreateNull()); |
| 20 | 19 |
| 21 scoped_ptr<net::HttpTransaction> trans(factory.CreateTransaction()); | 20 scoped_ptr<net::HttpTransaction> trans(factory.CreateTransaction()); |
| 22 } | 21 } |
| 23 | 22 |
| 24 TEST_F(HttpNetworkLayerTest, Suspend) { | 23 TEST_F(HttpNetworkLayerTest, Suspend) { |
| 25 scoped_ptr<net::ProxyService> proxy_service(net::ProxyService::CreateNull()); | |
| 26 net::HttpNetworkLayer factory( | 24 net::HttpNetworkLayer factory( |
| 27 NULL, new net::MockHostResolver, proxy_service.get()); | 25 NULL, new net::MockHostResolver, net::ProxyService::CreateNull()); |
| 28 | 26 |
| 29 scoped_ptr<net::HttpTransaction> trans(factory.CreateTransaction()); | 27 scoped_ptr<net::HttpTransaction> trans(factory.CreateTransaction()); |
| 30 trans.reset(); | 28 trans.reset(); |
| 31 | 29 |
| 32 factory.Suspend(true); | 30 factory.Suspend(true); |
| 33 | 31 |
| 34 trans.reset(factory.CreateTransaction()); | 32 trans.reset(factory.CreateTransaction()); |
| 35 ASSERT_TRUE(trans == NULL); | 33 ASSERT_TRUE(trans == NULL); |
| 36 | 34 |
| 37 factory.Suspend(false); | 35 factory.Suspend(false); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 48 }; | 46 }; |
| 49 net::MockWrite data_writes[] = { | 47 net::MockWrite data_writes[] = { |
| 50 net::MockWrite("GET / HTTP/1.1\r\n" | 48 net::MockWrite("GET / HTTP/1.1\r\n" |
| 51 "Host: www.google.com\r\n" | 49 "Host: www.google.com\r\n" |
| 52 "Connection: keep-alive\r\n" | 50 "Connection: keep-alive\r\n" |
| 53 "User-Agent: Foo/1.0\r\n\r\n"), | 51 "User-Agent: Foo/1.0\r\n\r\n"), |
| 54 }; | 52 }; |
| 55 net::StaticMockSocket data(data_reads, data_writes); | 53 net::StaticMockSocket data(data_reads, data_writes); |
| 56 mock_socket_factory.AddMockSocket(&data); | 54 mock_socket_factory.AddMockSocket(&data); |
| 57 | 55 |
| 58 scoped_ptr<net::ProxyService> proxy_service(net::ProxyService::CreateNull()); | |
| 59 net::HttpNetworkLayer factory(&mock_socket_factory, new net::MockHostResolver, | 56 net::HttpNetworkLayer factory(&mock_socket_factory, new net::MockHostResolver, |
| 60 proxy_service.get()); | 57 net::ProxyService::CreateNull()); |
| 61 | 58 |
| 62 TestCompletionCallback callback; | 59 TestCompletionCallback callback; |
| 63 | 60 |
| 64 scoped_ptr<net::HttpTransaction> trans(factory.CreateTransaction()); | 61 scoped_ptr<net::HttpTransaction> trans(factory.CreateTransaction()); |
| 65 | 62 |
| 66 net::HttpRequestInfo request_info; | 63 net::HttpRequestInfo request_info; |
| 67 request_info.url = GURL("http://www.google.com/"); | 64 request_info.url = GURL("http://www.google.com/"); |
| 68 request_info.method = "GET"; | 65 request_info.method = "GET"; |
| 69 request_info.user_agent = "Foo/1.0"; | 66 request_info.user_agent = "Foo/1.0"; |
| 70 request_info.load_flags = net::LOAD_NORMAL; | 67 request_info.load_flags = net::LOAD_NORMAL; |
| 71 | 68 |
| 72 int rv = trans->Start(&request_info, &callback, NULL); | 69 int rv = trans->Start(&request_info, &callback, NULL); |
| 73 if (rv == net::ERR_IO_PENDING) | 70 if (rv == net::ERR_IO_PENDING) |
| 74 rv = callback.WaitForResult(); | 71 rv = callback.WaitForResult(); |
| 75 ASSERT_EQ(net::OK, rv); | 72 ASSERT_EQ(net::OK, rv); |
| 76 | 73 |
| 77 std::string contents; | 74 std::string contents; |
| 78 rv = ReadTransaction(trans.get(), &contents); | 75 rv = ReadTransaction(trans.get(), &contents); |
| 79 EXPECT_EQ(net::OK, rv); | 76 EXPECT_EQ(net::OK, rv); |
| 80 EXPECT_EQ("hello world", contents); | 77 EXPECT_EQ("hello world", contents); |
| 81 } | 78 } |
| OLD | NEW |