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