| 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/socket/tcp_client_socket_pool.h" | 5 #include "net/socket/tcp_client_socket_pool.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.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/net_errors.h" | 10 #include "net/base/net_errors.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 const int kMaxSockets = 32; | 22 const int kMaxSockets = 32; |
| 23 const int kMaxSocketsPerGroup = 6; | 23 const int kMaxSocketsPerGroup = 6; |
| 24 const int kDefaultPriority = 5; | 24 const int kDefaultPriority = 5; |
| 25 | 25 |
| 26 class MockClientSocket : public ClientSocket { | 26 class MockClientSocket : public ClientSocket { |
| 27 public: | 27 public: |
| 28 MockClientSocket() : connected_(false) {} | 28 MockClientSocket() : connected_(false) {} |
| 29 | 29 |
| 30 // ClientSocket methods: | 30 // ClientSocket methods: |
| 31 virtual int Connect(CompletionCallback* callback) { | 31 virtual int Connect(CompletionCallback* callback, LoadLog* /* load_log */) { |
| 32 connected_ = true; | 32 connected_ = true; |
| 33 return OK; | 33 return OK; |
| 34 } | 34 } |
| 35 virtual void Disconnect() { | 35 virtual void Disconnect() { |
| 36 connected_ = false; | 36 connected_ = false; |
| 37 } | 37 } |
| 38 virtual bool IsConnected() const { | 38 virtual bool IsConnected() const { |
| 39 return connected_; | 39 return connected_; |
| 40 } | 40 } |
| 41 virtual bool IsConnectedAndIdle() const { | 41 virtual bool IsConnectedAndIdle() const { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 56 | 56 |
| 57 private: | 57 private: |
| 58 bool connected_; | 58 bool connected_; |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 class MockFailingClientSocket : public ClientSocket { | 61 class MockFailingClientSocket : public ClientSocket { |
| 62 public: | 62 public: |
| 63 MockFailingClientSocket() {} | 63 MockFailingClientSocket() {} |
| 64 | 64 |
| 65 // ClientSocket methods: | 65 // ClientSocket methods: |
| 66 virtual int Connect(CompletionCallback* callback) { | 66 virtual int Connect(CompletionCallback* callback, LoadLog* /* load_log */) { |
| 67 return ERR_CONNECTION_FAILED; | 67 return ERR_CONNECTION_FAILED; |
| 68 } | 68 } |
| 69 | 69 |
| 70 virtual void Disconnect() {} | 70 virtual void Disconnect() {} |
| 71 | 71 |
| 72 virtual bool IsConnected() const { | 72 virtual bool IsConnected() const { |
| 73 return false; | 73 return false; |
| 74 } | 74 } |
| 75 virtual bool IsConnectedAndIdle() const { | 75 virtual bool IsConnectedAndIdle() const { |
| 76 return false; | 76 return false; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 class MockPendingClientSocket : public ClientSocket { | 93 class MockPendingClientSocket : public ClientSocket { |
| 94 public: | 94 public: |
| 95 MockPendingClientSocket(bool should_connect) | 95 MockPendingClientSocket(bool should_connect) |
| 96 : method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 96 : method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 97 should_connect_(should_connect), | 97 should_connect_(should_connect), |
| 98 is_connected_(false) {} | 98 is_connected_(false) {} |
| 99 | 99 |
| 100 // ClientSocket methods: | 100 // ClientSocket methods: |
| 101 virtual int Connect(CompletionCallback* callback) { | 101 virtual int Connect(CompletionCallback* callback, LoadLog* /* load_log */) { |
| 102 MessageLoop::current()->PostTask( | 102 MessageLoop::current()->PostTask( |
| 103 FROM_HERE, | 103 FROM_HERE, |
| 104 method_factory_.NewRunnableMethod( | 104 method_factory_.NewRunnableMethod( |
| 105 &MockPendingClientSocket::DoCallback, callback)); | 105 &MockPendingClientSocket::DoCallback, callback)); |
| 106 return ERR_IO_PENDING; | 106 return ERR_IO_PENDING; |
| 107 } | 107 } |
| 108 | 108 |
| 109 virtual void Disconnect() {} | 109 virtual void Disconnect() {} |
| 110 | 110 |
| 111 virtual bool IsConnected() const { | 111 virtual bool IsConnected() const { |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 for (int i = 0; i < kNumRequests; i++) | 576 for (int i = 0; i < kNumRequests; i++) |
| 577 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); | 577 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
| 578 | 578 |
| 579 for (int i = 0; i < kNumRequests; i++) | 579 for (int i = 0; i < kNumRequests; i++) |
| 580 EXPECT_EQ(ERR_CONNECTION_FAILED, requests_[i]->WaitForResult()); | 580 EXPECT_EQ(ERR_CONNECTION_FAILED, requests_[i]->WaitForResult()); |
| 581 } | 581 } |
| 582 | 582 |
| 583 } // namespace | 583 } // namespace |
| 584 | 584 |
| 585 } // namespace net | 585 } // namespace net |
| OLD | NEW |