OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/http/http_network_session.h" |
| 6 |
| 7 #include "base/ref_counted.h" |
| 8 #include "net/base/mock_host_resolver.h" |
| 9 #include "net/base/mock_network_change_notifier.h" |
| 10 #include "net/base/ssl_config_service_defaults.h" |
| 11 #include "net/base/test_completion_callback.h" |
| 12 #include "net/http/http_auth_handler_factory.h" |
| 13 #include "net/proxy/proxy_service.h" |
| 14 #include "net/socket/client_socket_handle.h" |
| 15 #include "net/socket/socket_test_util.h" |
| 16 #include "net/socket/tcp_client_socket_pool.h" |
| 17 #include "net/spdy/spdy_session.h" |
| 18 #include "net/spdy/spdy_session_pool.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 |
| 21 namespace net { |
| 22 namespace { |
| 23 |
| 24 TEST(HttpNetworkSessionTest, FlushOnNetworkChange) { |
| 25 MockNetworkChangeNotifier mock_notifier; |
| 26 scoped_refptr<MockCachingHostResolver> mock_resolver( |
| 27 new MockCachingHostResolver); |
| 28 MockClientSocketFactory mock_factory; |
| 29 scoped_ptr<HttpAuthHandlerFactory> auth_handler_factory( |
| 30 HttpAuthHandlerFactory::CreateDefault()); |
| 31 scoped_refptr<HttpNetworkSession> session( |
| 32 new HttpNetworkSession(&mock_notifier, |
| 33 mock_resolver, |
| 34 ProxyService::CreateNull(), |
| 35 &mock_factory, |
| 36 new SSLConfigServiceDefaults, |
| 37 auth_handler_factory.get())); |
| 38 |
| 39 scoped_refptr<TCPClientSocketPool> tcp_socket_pool( |
| 40 session->tcp_socket_pool()); |
| 41 |
| 42 StaticSocketDataProvider data; |
| 43 mock_factory.AddSocketDataProvider(&data); |
| 44 |
| 45 TestCompletionCallback callback; |
| 46 ClientSocketHandle handle; |
| 47 TCPSocketParams dest("www.google.com", 80, LOW, GURL(), false); |
| 48 int rv = handle.Init("a", dest, LOW, &callback, tcp_socket_pool, NULL); |
| 49 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 50 EXPECT_FALSE(handle.is_initialized()); |
| 51 EXPECT_FALSE(handle.socket()); |
| 52 |
| 53 EXPECT_EQ(OK, callback.WaitForResult()); |
| 54 EXPECT_TRUE(handle.is_initialized()); |
| 55 EXPECT_TRUE(handle.socket()); |
| 56 |
| 57 handle.Reset(); |
| 58 |
| 59 // Need to run all pending to release the socket back to the pool. |
| 60 MessageLoop::current()->RunAllPending(); |
| 61 |
| 62 // Now we should have 1 idle socket. |
| 63 EXPECT_EQ(1, tcp_socket_pool->IdleSocketCount()); |
| 64 |
| 65 HostPortPair host_port_pair("www.google.com", 80); |
| 66 |
| 67 scoped_refptr<SpdySession> spdy_session(session->spdy_session_pool()->Get( |
| 68 host_port_pair, session)); |
| 69 |
| 70 EXPECT_TRUE(session->spdy_session_pool()->HasSession(host_port_pair)); |
| 71 |
| 72 EXPECT_EQ(1u, mock_resolver->cache()->size()); |
| 73 |
| 74 // After an IP address change, we should have 0 idle sockets. |
| 75 mock_notifier.NotifyIPAddressChange(); |
| 76 EXPECT_EQ(0, tcp_socket_pool->IdleSocketCount()); |
| 77 EXPECT_FALSE(session->spdy_session_pool()->HasSession(host_port_pair)); |
| 78 EXPECT_EQ(0u, mock_resolver->cache()->size()); |
| 79 } |
| 80 |
| 81 } // namespace |
| 82 } // namespace net |
OLD | NEW |