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/base/ssl_config_service_defaults.h" | 6 #include "net/base/ssl_config_service_defaults.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 "net/socket/socket_test_util.h" | 10 #include "net/socket/socket_test_util.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 net::MockRead("HTTP/1.0 200 OK\r\n\r\n"), | 55 net::MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
56 net::MockRead("hello world"), | 56 net::MockRead("hello world"), |
57 net::MockRead(false, net::OK), | 57 net::MockRead(false, net::OK), |
58 }; | 58 }; |
59 net::MockWrite data_writes[] = { | 59 net::MockWrite data_writes[] = { |
60 net::MockWrite("GET / HTTP/1.1\r\n" | 60 net::MockWrite("GET / HTTP/1.1\r\n" |
61 "Host: www.google.com\r\n" | 61 "Host: www.google.com\r\n" |
62 "Connection: keep-alive\r\n" | 62 "Connection: keep-alive\r\n" |
63 "User-Agent: Foo/1.0\r\n\r\n"), | 63 "User-Agent: Foo/1.0\r\n\r\n"), |
64 }; | 64 }; |
65 net::StaticSocketDataProvider data(data_reads, data_writes); | 65 net::StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 66 data_writes, arraysize(data_reads)); |
66 mock_socket_factory.AddSocketDataProvider(&data); | 67 mock_socket_factory.AddSocketDataProvider(&data); |
67 | 68 |
68 net::HttpNetworkLayer factory(&mock_socket_factory, NULL, | 69 net::HttpNetworkLayer factory(&mock_socket_factory, NULL, |
69 new net::MockHostResolver, | 70 new net::MockHostResolver, |
70 net::ProxyService::CreateNull(), | 71 net::ProxyService::CreateNull(), |
71 new net::SSLConfigServiceDefaults); | 72 new net::SSLConfigServiceDefaults); |
72 | 73 |
73 TestCompletionCallback callback; | 74 TestCompletionCallback callback; |
74 | 75 |
75 scoped_ptr<net::HttpTransaction> trans; | 76 scoped_ptr<net::HttpTransaction> trans; |
76 int rv = factory.CreateTransaction(&trans); | 77 int rv = factory.CreateTransaction(&trans); |
77 EXPECT_EQ(net::OK, rv); | 78 EXPECT_EQ(net::OK, rv); |
78 | 79 |
79 net::HttpRequestInfo request_info; | 80 net::HttpRequestInfo request_info; |
80 request_info.url = GURL("http://www.google.com/"); | 81 request_info.url = GURL("http://www.google.com/"); |
81 request_info.method = "GET"; | 82 request_info.method = "GET"; |
82 request_info.user_agent = "Foo/1.0"; | 83 request_info.user_agent = "Foo/1.0"; |
83 request_info.load_flags = net::LOAD_NORMAL; | 84 request_info.load_flags = net::LOAD_NORMAL; |
84 | 85 |
85 rv = trans->Start(&request_info, &callback, NULL); | 86 rv = trans->Start(&request_info, &callback, NULL); |
86 if (rv == net::ERR_IO_PENDING) | 87 if (rv == net::ERR_IO_PENDING) |
87 rv = callback.WaitForResult(); | 88 rv = callback.WaitForResult(); |
88 ASSERT_EQ(net::OK, rv); | 89 ASSERT_EQ(net::OK, rv); |
89 | 90 |
90 std::string contents; | 91 std::string contents; |
91 rv = ReadTransaction(trans.get(), &contents); | 92 rv = ReadTransaction(trans.get(), &contents); |
92 EXPECT_EQ(net::OK, rv); | 93 EXPECT_EQ(net::OK, rv); |
93 EXPECT_EQ("hello world", contents); | 94 EXPECT_EQ("hello world", contents); |
94 } | 95 } |
OLD | NEW |