| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "jingle/notifier/base/proxy_resolving_client_socket.h" | 5 #include "jingle/notifier/base/proxy_resolving_client_socket.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "net/base/mock_host_resolver.h" | 9 #include "net/base/mock_host_resolver.h" |
| 10 #include "net/base/test_completion_callback.h" | 10 #include "net/base/test_completion_callback.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 // ERR_ADDRESS_INVALID for a 0 IP address. | 83 // ERR_ADDRESS_INVALID for a 0 IP address. |
| 84 EXPECT_EQ(net::ERR_ADDRESS_INVALID, status); | 84 EXPECT_EQ(net::ERR_ADDRESS_INVALID, status); |
| 85 } | 85 } |
| 86 | 86 |
| 87 TEST_F(ProxyResolvingClientSocketTest, ReportsBadProxies) { | 87 TEST_F(ProxyResolvingClientSocketTest, ReportsBadProxies) { |
| 88 net::HostPortPair dest("example.com", 443); | 88 net::HostPortPair dest("example.com", 443); |
| 89 net::MockClientSocketFactory socket_factory; | 89 net::MockClientSocketFactory socket_factory; |
| 90 | 90 |
| 91 net::StaticSocketDataProvider socket_data1; | 91 net::StaticSocketDataProvider socket_data1; |
| 92 socket_data1.set_connect_data( | 92 socket_data1.set_connect_data( |
| 93 net::MockConnect(true, net::ERR_ADDRESS_UNREACHABLE)); | 93 net::MockConnect(net::ASYNC, net::ERR_ADDRESS_UNREACHABLE)); |
| 94 socket_factory.AddSocketDataProvider(&socket_data1); | 94 socket_factory.AddSocketDataProvider(&socket_data1); |
| 95 | 95 |
| 96 net::MockRead reads[] = { | 96 net::MockRead reads[] = { |
| 97 net::MockRead("HTTP/1.1 200 Success\r\n\r\n") | 97 net::MockRead("HTTP/1.1 200 Success\r\n\r\n") |
| 98 }; | 98 }; |
| 99 net::MockWrite writes[] = { | 99 net::MockWrite writes[] = { |
| 100 net::MockWrite("CONNECT example.com:443 HTTP/1.1\r\n" | 100 net::MockWrite("CONNECT example.com:443 HTTP/1.1\r\n" |
| 101 "Host: example.com:443\r\n" | 101 "Host: example.com:443\r\n" |
| 102 "Proxy-Connection: keep-alive\r\n\r\n") | 102 "Proxy-Connection: keep-alive\r\n\r\n") |
| 103 }; | 103 }; |
| 104 net::StaticSocketDataProvider socket_data2(reads, arraysize(reads), | 104 net::StaticSocketDataProvider socket_data2(reads, arraysize(reads), |
| 105 writes, arraysize(writes)); | 105 writes, arraysize(writes)); |
| 106 socket_data2.set_connect_data(net::MockConnect(true, net::OK)); | 106 socket_data2.set_connect_data(net::MockConnect(net::ASYNC, net::OK)); |
| 107 socket_factory.AddSocketDataProvider(&socket_data2); | 107 socket_factory.AddSocketDataProvider(&socket_data2); |
| 108 | 108 |
| 109 ProxyResolvingClientSocket proxy_resolving_socket( | 109 ProxyResolvingClientSocket proxy_resolving_socket( |
| 110 &socket_factory, | 110 &socket_factory, |
| 111 url_request_context_getter_, | 111 url_request_context_getter_, |
| 112 net::SSLConfig(), | 112 net::SSLConfig(), |
| 113 dest); | 113 dest); |
| 114 | 114 |
| 115 net::TestCompletionCallback callback; | 115 net::TestCompletionCallback callback; |
| 116 int status = proxy_resolving_socket.Connect(callback.callback()); | 116 int status = proxy_resolving_socket.Connect(callback.callback()); |
| 117 EXPECT_EQ(net::ERR_IO_PENDING, status); | 117 EXPECT_EQ(net::ERR_IO_PENDING, status); |
| 118 status = callback.WaitForResult(); | 118 status = callback.WaitForResult(); |
| 119 EXPECT_EQ(net::OK, status); | 119 EXPECT_EQ(net::OK, status); |
| 120 | 120 |
| 121 net::URLRequestContext* context = | 121 net::URLRequestContext* context = |
| 122 url_request_context_getter_->GetURLRequestContext(); | 122 url_request_context_getter_->GetURLRequestContext(); |
| 123 const net::ProxyRetryInfoMap& retry_info = | 123 const net::ProxyRetryInfoMap& retry_info = |
| 124 context->proxy_service()->proxy_retry_info(); | 124 context->proxy_service()->proxy_retry_info(); |
| 125 | 125 |
| 126 EXPECT_EQ(1u, retry_info.size()); | 126 EXPECT_EQ(1u, retry_info.size()); |
| 127 net::ProxyRetryInfoMap::const_iterator iter = retry_info.find("bad:99"); | 127 net::ProxyRetryInfoMap::const_iterator iter = retry_info.find("bad:99"); |
| 128 EXPECT_TRUE(iter != retry_info.end()); | 128 EXPECT_TRUE(iter != retry_info.end()); |
| 129 } | 129 } |
| 130 | 130 |
| 131 // TODO(sanjeevr): Add more unit-tests. | 131 // TODO(sanjeevr): Add more unit-tests. |
| 132 } // namespace notifier | 132 } // namespace notifier |
| OLD | NEW |