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 "base/message_loop.h" | 5 #include "base/message_loop.h" |
6 #include "net/base/client_socket.h" | 6 #include "net/base/client_socket.h" |
7 #include "net/base/client_socket_handle.h" | 7 #include "net/base/client_socket_handle.h" |
8 #include "net/base/client_socket_pool.h" | 8 #include "net/base/client_socket_pool.h" |
9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 } | 28 } |
29 virtual int ReconnectIgnoringLastError(net::CompletionCallback* callback) { | 29 virtual int ReconnectIgnoringLastError(net::CompletionCallback* callback) { |
30 return net::ERR_FAILED; | 30 return net::ERR_FAILED; |
31 } | 31 } |
32 virtual void Disconnect() { | 32 virtual void Disconnect() { |
33 connected_ = false; | 33 connected_ = false; |
34 } | 34 } |
35 virtual bool IsConnected() const { | 35 virtual bool IsConnected() const { |
36 return connected_; | 36 return connected_; |
37 } | 37 } |
| 38 virtual bool IsConnectedAndIdle() const { |
| 39 return connected_; |
| 40 } |
38 | 41 |
39 // Socket methods: | 42 // Socket methods: |
40 virtual int Read(char* buf, int buf_len, | 43 virtual int Read(char* buf, int buf_len, |
41 net::CompletionCallback* callback) { | 44 net::CompletionCallback* callback) { |
42 return net::ERR_FAILED; | 45 return net::ERR_FAILED; |
43 } | 46 } |
44 virtual int Write(const char* buf, int buf_len, | 47 virtual int Write(const char* buf, int buf_len, |
45 net::CompletionCallback* callback) { | 48 net::CompletionCallback* callback) { |
46 return net::ERR_FAILED; | 49 return net::ERR_FAILED; |
47 } | 50 } |
48 | 51 |
49 static int allocation_count; | 52 static int allocation_count; |
50 | 53 |
51 private: | 54 private: |
52 bool connected_; | 55 bool connected_; |
53 }; | 56 }; |
54 | 57 |
55 int MockClientSocket::allocation_count = 0; | 58 int MockClientSocket::allocation_count = 0; |
56 | 59 |
57 class TestSocketRequest : public CallbackRunner< Tuple1<int> > { | 60 class TestSocketRequest : public CallbackRunner< Tuple1<int> > { |
58 public: | 61 public: |
59 TestSocketRequest(net::ClientSocketPool* pool) : handle(pool) {} | 62 explicit TestSocketRequest(net::ClientSocketPool* pool) : handle(pool) {} |
60 | 63 |
61 net::ClientSocketHandle handle; | 64 net::ClientSocketHandle handle; |
62 | 65 |
63 void EnsureSocket() { | 66 void EnsureSocket() { |
64 DCHECK(handle.is_initialized()); | 67 DCHECK(handle.is_initialized()); |
65 if (!handle.socket()) { | 68 if (!handle.socket()) { |
66 handle.set_socket(new MockClientSocket()); | 69 handle.set_socket(new MockClientSocket()); |
67 handle.socket()->Connect(NULL); | 70 handle.socket()->Connect(NULL); |
68 } | 71 } |
69 } | 72 } |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 MessageLoop::current()->RunAllPending(); | 242 MessageLoop::current()->RunAllPending(); |
240 released_one = true; | 243 released_one = true; |
241 } | 244 } |
242 } | 245 } |
243 } while (released_one); | 246 } while (released_one); |
244 | 247 |
245 EXPECT_EQ(kMaxSocketsPerGroup, MockClientSocket::allocation_count); | 248 EXPECT_EQ(kMaxSocketsPerGroup, MockClientSocket::allocation_count); |
246 EXPECT_EQ(9, TestSocketRequest::completion_count); | 249 EXPECT_EQ(9, TestSocketRequest::completion_count); |
247 } | 250 } |
248 | 251 |
OLD | NEW |