OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/socket/client_socket_pool_base.h" | 5 #include "net/socket/client_socket_pool_base.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 base_.CancelRequest(group_name, handle); | 469 base_.CancelRequest(group_name, handle); |
470 } | 470 } |
471 | 471 |
472 virtual void ReleaseSocket( | 472 virtual void ReleaseSocket( |
473 const std::string& group_name, | 473 const std::string& group_name, |
474 StreamSocket* socket, | 474 StreamSocket* socket, |
475 int id) OVERRIDE { | 475 int id) OVERRIDE { |
476 base_.ReleaseSocket(group_name, socket, id); | 476 base_.ReleaseSocket(group_name, socket, id); |
477 } | 477 } |
478 | 478 |
479 virtual void Flush() OVERRIDE { | 479 virtual void FlushWithError(int error) OVERRIDE { |
480 base_.Flush(); | 480 base_.FlushWithError(error); |
481 } | 481 } |
482 | 482 |
483 virtual bool IsStalled() const OVERRIDE { | 483 virtual bool IsStalled() const OVERRIDE { |
484 return base_.IsStalled(); | 484 return base_.IsStalled(); |
485 } | 485 } |
486 | 486 |
487 virtual void CloseIdleSockets() OVERRIDE { | 487 virtual void CloseIdleSockets() OVERRIDE { |
488 base_.CloseIdleSockets(); | 488 base_.CloseIdleSockets(); |
489 } | 489 } |
490 | 490 |
(...skipping 1988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2479 | 2479 |
2480 ClientSocketHandle handle; | 2480 ClientSocketHandle handle; |
2481 TestCompletionCallback callback; | 2481 TestCompletionCallback callback; |
2482 EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", | 2482 EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", |
2483 params_, | 2483 params_, |
2484 kDefaultPriority, | 2484 kDefaultPriority, |
2485 callback.callback(), | 2485 callback.callback(), |
2486 pool_.get(), | 2486 pool_.get(), |
2487 BoundNetLog())); | 2487 BoundNetLog())); |
2488 | 2488 |
2489 pool_->Flush(); | 2489 pool_->FlushWithError(ERR_NETWORK_CHANGED); |
2490 | 2490 |
2491 // We'll call back into this now. | 2491 // We'll call back into this now. |
2492 callback.WaitForResult(); | 2492 callback.WaitForResult(); |
2493 } | 2493 } |
2494 | 2494 |
2495 TEST_F(ClientSocketPoolBaseTest, DoNotReuseSocketAfterFlush) { | 2495 TEST_F(ClientSocketPoolBaseTest, DoNotReuseSocketAfterFlush) { |
2496 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 2496 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
2497 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); | 2497 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
2498 | 2498 |
2499 ClientSocketHandle handle; | 2499 ClientSocketHandle handle; |
2500 TestCompletionCallback callback; | 2500 TestCompletionCallback callback; |
2501 EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", | 2501 EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", |
2502 params_, | 2502 params_, |
2503 kDefaultPriority, | 2503 kDefaultPriority, |
2504 callback.callback(), | 2504 callback.callback(), |
2505 pool_.get(), | 2505 pool_.get(), |
2506 BoundNetLog())); | 2506 BoundNetLog())); |
2507 EXPECT_EQ(OK, callback.WaitForResult()); | 2507 EXPECT_EQ(OK, callback.WaitForResult()); |
2508 EXPECT_EQ(ClientSocketHandle::UNUSED, handle.reuse_type()); | 2508 EXPECT_EQ(ClientSocketHandle::UNUSED, handle.reuse_type()); |
2509 | 2509 |
2510 pool_->Flush(); | 2510 pool_->FlushWithError(ERR_NETWORK_CHANGED); |
2511 | 2511 |
2512 handle.Reset(); | 2512 handle.Reset(); |
2513 MessageLoop::current()->RunUntilIdle(); | 2513 MessageLoop::current()->RunUntilIdle(); |
2514 | 2514 |
2515 EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", | 2515 EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", |
2516 params_, | 2516 params_, |
2517 kDefaultPriority, | 2517 kDefaultPriority, |
2518 callback.callback(), | 2518 callback.callback(), |
2519 pool_.get(), | 2519 pool_.get(), |
2520 BoundNetLog())); | 2520 BoundNetLog())); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2577 EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", | 2577 EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", |
2578 params_, | 2578 params_, |
2579 kDefaultPriority, | 2579 kDefaultPriority, |
2580 callback.callback(), | 2580 callback.callback(), |
2581 pool_.get(), | 2581 pool_.get(), |
2582 BoundNetLog())); | 2582 BoundNetLog())); |
2583 | 2583 |
2584 // Second job will be started during the first callback, and will | 2584 // Second job will be started during the first callback, and will |
2585 // asynchronously complete with OK. | 2585 // asynchronously complete with OK. |
2586 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); | 2586 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
2587 pool_->Flush(); | 2587 pool_->FlushWithError(ERR_NETWORK_CHANGED); |
2588 EXPECT_EQ(ERR_ABORTED, callback.WaitForResult()); | 2588 EXPECT_EQ(ERR_NETWORK_CHANGED, callback.WaitForResult()); |
2589 EXPECT_EQ(OK, callback.WaitForNestedResult()); | 2589 EXPECT_EQ(OK, callback.WaitForNestedResult()); |
2590 } | 2590 } |
2591 | 2591 |
2592 // Cancel a pending socket request while we're at max sockets, | 2592 // Cancel a pending socket request while we're at max sockets, |
2593 // and verify that the backup socket firing doesn't cause a crash. | 2593 // and verify that the backup socket firing doesn't cause a crash. |
2594 TEST_F(ClientSocketPoolBaseTest, BackupSocketCancelAtMaxSockets) { | 2594 TEST_F(ClientSocketPoolBaseTest, BackupSocketCancelAtMaxSockets) { |
2595 // Max 4 sockets globally, max 4 sockets per group. | 2595 // Max 4 sockets globally, max 4 sockets per group. |
2596 CreatePool(kDefaultMaxSockets, kDefaultMaxSockets); | 2596 CreatePool(kDefaultMaxSockets, kDefaultMaxSockets); |
2597 pool_->EnableConnectBackupJobs(); | 2597 pool_->EnableConnectBackupJobs(); |
2598 | 2598 |
(...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3524 // complete. | 3524 // complete. |
3525 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a")); | 3525 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a")); |
3526 EXPECT_EQ(0, pool_->NumUnassignedConnectJobsInGroup("a")); | 3526 EXPECT_EQ(0, pool_->NumUnassignedConnectJobsInGroup("a")); |
3527 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); | 3527 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); |
3528 EXPECT_EQ(1, pool_->NumActiveSocketsInGroup("a")); | 3528 EXPECT_EQ(1, pool_->NumActiveSocketsInGroup("a")); |
3529 } | 3529 } |
3530 | 3530 |
3531 } // namespace | 3531 } // namespace |
3532 | 3532 |
3533 } // namespace net | 3533 } // namespace net |
OLD | NEW |