OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/websockets/websocket_throttle.h" | 5 #include "net/websockets/websocket_throttle.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "net/base/address_list.h" | 10 #include "net/base/address_list.h" |
11 #include "net/base/test_completion_callback.h" | 11 #include "net/base/test_completion_callback.h" |
12 #include "net/socket_stream/socket_stream.h" | 12 #include "net/socket_stream/socket_stream.h" |
13 #include "net/url_request/url_request_test_util.h" | 13 #include "net/url_request/url_request_test_util.h" |
14 #include "net/websockets/websocket_job.h" | 14 #include "net/websockets/websocket_job.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "testing/platform_test.h" | 16 #include "testing/platform_test.h" |
17 #include "url/gurl.h" | 17 #include "url/gurl.h" |
18 | 18 |
19 class DummySocketStreamDelegate : public net::SocketStream::Delegate { | 19 class DummySocketStreamDelegate : public net::SocketStream::Delegate { |
20 public: | 20 public: |
21 DummySocketStreamDelegate() {} | 21 DummySocketStreamDelegate() {} |
22 virtual ~DummySocketStreamDelegate() {} | 22 virtual ~DummySocketStreamDelegate() {} |
23 virtual void OnConnected( | 23 virtual void OnConnected(net::SocketStream* socket, |
24 net::SocketStream* socket, int max_pending_send_allowed) OVERRIDE {} | 24 int max_pending_send_allowed) OVERRIDE {} |
25 virtual void OnSentData(net::SocketStream* socket, | 25 virtual void OnSentData(net::SocketStream* socket, int amount_sent) OVERRIDE { |
26 int amount_sent) OVERRIDE {} | 26 } |
27 virtual void OnReceivedData(net::SocketStream* socket, | 27 virtual void OnReceivedData(net::SocketStream* socket, |
28 const char* data, int len) OVERRIDE {} | 28 const char* data, |
| 29 int len) OVERRIDE {} |
29 virtual void OnClose(net::SocketStream* socket) OVERRIDE {} | 30 virtual void OnClose(net::SocketStream* socket) OVERRIDE {} |
30 }; | 31 }; |
31 | 32 |
32 namespace net { | 33 namespace net { |
33 | 34 |
34 class WebSocketThrottleTest : public PlatformTest { | 35 class WebSocketThrottleTest : public PlatformTest { |
35 protected: | 36 protected: |
36 static IPEndPoint MakeAddr(int a1, int a2, int a3, int a4) { | 37 static IPEndPoint MakeAddr(int a1, int a2, int a3, int a4) { |
37 IPAddressNumber ip; | 38 IPAddressNumber ip; |
38 ip.push_back(a1); | 39 ip.push_back(a1); |
39 ip.push_back(a2); | 40 ip.push_back(a2); |
40 ip.push_back(a3); | 41 ip.push_back(a3); |
41 ip.push_back(a4); | 42 ip.push_back(a4); |
42 return IPEndPoint(ip, 0); | 43 return IPEndPoint(ip, 0); |
43 } | 44 } |
44 | 45 |
45 static void MockSocketStreamConnect( | 46 static void MockSocketStreamConnect(SocketStream* socket, |
46 SocketStream* socket, const AddressList& list) { | 47 const AddressList& list) { |
47 socket->set_addresses(list); | 48 socket->set_addresses(list); |
48 // TODO(toyoshim): We should introduce additional tests on cases via proxy. | 49 // TODO(toyoshim): We should introduce additional tests on cases via proxy. |
49 socket->proxy_info_.UseDirect(); | 50 socket->proxy_info_.UseDirect(); |
50 // In SocketStream::Connect(), it adds reference to socket, which is | 51 // In SocketStream::Connect(), it adds reference to socket, which is |
51 // balanced with SocketStream::Finish() that is finally called from | 52 // balanced with SocketStream::Finish() that is finally called from |
52 // SocketStream::Close() or SocketStream::DetachDelegate(), when | 53 // SocketStream::Close() or SocketStream::DetachDelegate(), when |
53 // next_state_ is not STATE_NONE. | 54 // next_state_ is not STATE_NONE. |
54 // If next_state_ is STATE_NONE, SocketStream::Close() or | 55 // If next_state_ is STATE_NONE, SocketStream::Close() or |
55 // SocketStream::DetachDelegate() won't call SocketStream::Finish(), | 56 // SocketStream::DetachDelegate() won't call SocketStream::Finish(), |
56 // so Release() won't be called. Thus, we don't need socket->AddRef() | 57 // so Release() won't be called. Thus, we don't need socket->AddRef() |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 DVLOG(1) << "closing socket1"; | 338 DVLOG(1) << "closing socket1"; |
338 w1->OnClose(s1.get()); | 339 w1->OnClose(s1.get()); |
339 s1->DetachDelegate(); | 340 s1->DetachDelegate(); |
340 | 341 |
341 DVLOG(1) << "closing socket2"; | 342 DVLOG(1) << "closing socket2"; |
342 w2->OnClose(s2.get()); | 343 w2->OnClose(s2.get()); |
343 s2->DetachDelegate(); | 344 s2->DetachDelegate(); |
344 DVLOG(1) << "Done"; | 345 DVLOG(1) << "Done"; |
345 base::MessageLoopForIO::current()->RunUntilIdle(); | 346 base::MessageLoopForIO::current()->RunUntilIdle(); |
346 } | 347 } |
347 | |
348 } | 348 } |
OLD | NEW |