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 "net/spdy/spdy_session.h" | 5 #include "net/spdy/spdy_session.h" |
6 | 6 |
| 7 #include "net/base/ip_endpoint.h" |
7 #include "net/spdy/spdy_io_buffer.h" | 8 #include "net/spdy/spdy_io_buffer.h" |
8 #include "net/spdy/spdy_session_pool.h" | 9 #include "net/spdy/spdy_session_pool.h" |
9 #include "net/spdy/spdy_stream.h" | 10 #include "net/spdy/spdy_stream.h" |
10 #include "net/spdy/spdy_test_util.h" | 11 #include "net/spdy/spdy_test_util.h" |
11 #include "testing/platform_test.h" | 12 #include "testing/platform_test.h" |
12 | 13 |
13 namespace net { | 14 namespace net { |
14 | 15 |
15 // TODO(cbentzel): Expose compression setter/getter in public SpdySession | 16 // TODO(cbentzel): Expose compression setter/getter in public SpdySession |
16 // interface rather than going through all these contortions. | 17 // interface rather than going through all these contortions. |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 // This test has two variants, one for each style of closing the connection. | 410 // This test has two variants, one for each style of closing the connection. |
410 // If |clean_via_close_current_sessions| is false, the sessions are closed | 411 // If |clean_via_close_current_sessions| is false, the sessions are closed |
411 // manually, calling SpdySessionPool::Remove() directly. If it is true, | 412 // manually, calling SpdySessionPool::Remove() directly. If it is true, |
412 // sessions are closed with SpdySessionPool::CloseCurrentSessions(). | 413 // sessions are closed with SpdySessionPool::CloseCurrentSessions(). |
413 void IPPoolingTest(bool clean_via_close_current_sessions) { | 414 void IPPoolingTest(bool clean_via_close_current_sessions) { |
414 const int kTestPort = 80; | 415 const int kTestPort = 80; |
415 struct TestHosts { | 416 struct TestHosts { |
416 std::string name; | 417 std::string name; |
417 std::string iplist; | 418 std::string iplist; |
418 HostPortProxyPair pair; | 419 HostPortProxyPair pair; |
| 420 AddressList addresses; |
419 } test_hosts[] = { | 421 } test_hosts[] = { |
420 { "www.foo.com", "192.168.0.1,192.168.0.5" }, | 422 { "www.foo.com", "192.0.2.33,192.168.0.1,192.168.0.5" }, |
421 { "images.foo.com", "192.168.0.2,192.168.0.3,192.168.0.5" }, | 423 { "images.foo.com", "192.168.0.2,192.168.0.3,192.168.0.5,192.0.2.33" }, |
422 { "js.foo.com", "192.168.0.4,192.168.0.3" }, | 424 { "js.foo.com", "192.168.0.4,192.168.0.3" }, |
423 }; | 425 }; |
424 | 426 |
425 SpdySessionDependencies session_deps; | 427 SpdySessionDependencies session_deps; |
426 session_deps.host_resolver->set_synchronous_mode(true); | 428 session_deps.host_resolver->set_synchronous_mode(true); |
427 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_hosts); i++) { | 429 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_hosts); i++) { |
428 session_deps.host_resolver->rules()->AddIPLiteralRule(test_hosts[i].name, | 430 session_deps.host_resolver->rules()->AddIPLiteralRule(test_hosts[i].name, |
429 test_hosts[i].iplist, ""); | 431 test_hosts[i].iplist, ""); |
430 | 432 |
431 // This test requires that the HostResolver cache be populated. Normal | 433 // This test requires that the HostResolver cache be populated. Normal |
432 // code would have done this already, but we do it manually. | 434 // code would have done this already, but we do it manually. |
433 HostResolver::RequestInfo info(HostPortPair(test_hosts[i].name, kTestPort)); | 435 HostResolver::RequestInfo info(HostPortPair(test_hosts[i].name, kTestPort)); |
434 AddressList result; | |
435 session_deps.host_resolver->Resolve( | 436 session_deps.host_resolver->Resolve( |
436 info, &result, NULL, NULL, BoundNetLog()); | 437 info, &test_hosts[i].addresses, NULL, NULL, BoundNetLog()); |
437 | 438 |
438 // Setup a HostPortProxyPair | 439 // Setup a HostPortProxyPair |
439 test_hosts[i].pair = HostPortProxyPair( | 440 test_hosts[i].pair = HostPortProxyPair( |
440 HostPortPair(test_hosts[i].name, kTestPort), ProxyServer::Direct()); | 441 HostPortPair(test_hosts[i].name, kTestPort), ProxyServer::Direct()); |
441 } | 442 } |
442 | 443 |
443 MockConnect connect_data(false, OK); | 444 MockConnect connect_data(false, OK); |
444 MockRead reads[] = { | 445 MockRead reads[] = { |
445 MockRead(false, ERR_IO_PENDING) // Stall forever. | 446 MockRead(false, ERR_IO_PENDING) // Stall forever. |
446 }; | 447 }; |
(...skipping 23 matching lines...) Expand all Loading... |
470 false, | 471 false, |
471 false)); | 472 false)); |
472 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); | 473 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); |
473 EXPECT_EQ(OK, | 474 EXPECT_EQ(OK, |
474 connection->Init(test_host_port_pair.ToString(), | 475 connection->Init(test_host_port_pair.ToString(), |
475 transport_params, MEDIUM, | 476 transport_params, MEDIUM, |
476 NULL, http_session->transport_socket_pool(), | 477 NULL, http_session->transport_socket_pool(), |
477 BoundNetLog())); | 478 BoundNetLog())); |
478 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); | 479 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); |
479 | 480 |
| 481 // TODO(rtenneti): MockClientSocket::GetPeerAddress return's 0 as the port |
| 482 // number. Fix it to return port 80 and then use GetPeerAddress to AddAlias. |
| 483 const addrinfo* address = test_hosts[0].addresses.head(); |
| 484 SpdySessionPoolPeer pool_peer(spdy_session_pool); |
| 485 pool_peer.AddAlias(address, test_hosts[0].pair); |
| 486 |
480 // Flush the SpdySession::OnReadComplete() task. | 487 // Flush the SpdySession::OnReadComplete() task. |
481 MessageLoop::current()->RunAllPending(); | 488 MessageLoop::current()->RunAllPending(); |
482 | 489 |
483 // The third host has no overlap with the first, so it can't pool IPs. | 490 // The third host has no overlap with the first, so it can't pool IPs. |
484 EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[2].pair)); | 491 EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[2].pair)); |
485 | 492 |
486 // The second host overlaps with the first, and should IP pool. | 493 // The second host overlaps with the first, and should IP pool. |
487 EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[1].pair)); | 494 EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[1].pair)); |
488 | 495 |
489 // Verify that the second host, through a proxy, won't share the IP. | 496 // Verify that the second host, through a proxy, won't share the IP. |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 | 573 |
567 test_settings_storage->Set(test_host_port_pair, test_settings); | 574 test_settings_storage->Set(test_host_port_pair, test_settings); |
568 EXPECT_NE(0u, test_settings_storage->Get(test_host_port_pair).size()); | 575 EXPECT_NE(0u, test_settings_storage->Get(test_host_port_pair).size()); |
569 spdy_session_pool->OnIPAddressChanged(); | 576 spdy_session_pool->OnIPAddressChanged(); |
570 EXPECT_EQ(0u, test_settings_storage->Get(test_host_port_pair).size()); | 577 EXPECT_EQ(0u, test_settings_storage->Get(test_host_port_pair).size()); |
571 } | 578 } |
572 | 579 |
573 } // namespace | 580 } // namespace |
574 | 581 |
575 } // namespace net | 582 } // namespace net |
OLD | NEW |