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 #ifndef CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TEST_UTILS_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TEST_UTILS_H_ |
6 #define CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TEST_UTILS_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TEST_UTILS_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "content/common/p2p_messages.h" | 10 #include "content/common/p2p_messages.h" |
11 #include "ipc/ipc_message.h" | 11 #include "ipc/ipc_message.h" |
12 #include "ipc/ipc_message_utils.h" | 12 #include "ipc/ipc_message_utils.h" |
13 #include "net/base/address_list.h" | 13 #include "net/base/address_list.h" |
14 #include "net/base/completion_callback.h" | 14 #include "net/base/completion_callback.h" |
15 #include "net/base/io_buffer.h" | 15 #include "net/base/io_buffer.h" |
16 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
17 #include "net/base/sys_byteorder.h" | 17 #include "net/base/sys_byteorder.h" |
18 #include "net/socket/client_socket.h" | 18 #include "net/socket/stream_socket.h" |
19 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 const char kTestLocalIpAddress[] = "123.44.22.4"; | 24 const char kTestLocalIpAddress[] = "123.44.22.4"; |
25 const char kTestIpAddress1[] = "123.44.22.31"; | 25 const char kTestIpAddress1[] = "123.44.22.31"; |
26 const int kTestPort1 = 234; | 26 const int kTestPort1 = 234; |
27 const char kTestIpAddress2[] = "133.11.22.33"; | 27 const char kTestIpAddress2[] = "133.11.22.33"; |
28 const int kTestPort2 = 543; | 28 const int kTestPort2 = 543; |
29 | 29 |
30 const int kStunHeaderSize = 20; | 30 const int kStunHeaderSize = 20; |
31 const uint16 kStunBindingRequest = 0x0001; | 31 const uint16 kStunBindingRequest = 0x0001; |
32 const uint16 kStunBindingResponse = 0x0102; | 32 const uint16 kStunBindingResponse = 0x0102; |
33 const uint16 kStunBindingError = 0x0111; | 33 const uint16 kStunBindingError = 0x0111; |
34 const uint32 kStunMagicCookie = 0x2112A442; | 34 const uint32 kStunMagicCookie = 0x2112A442; |
35 | 35 |
36 class MockIPCSender : public IPC::Message::Sender { | 36 class MockIPCSender : public IPC::Message::Sender { |
37 public: | 37 public: |
38 MockIPCSender(); | 38 MockIPCSender(); |
39 virtual ~MockIPCSender(); | 39 virtual ~MockIPCSender(); |
40 | 40 |
41 MOCK_METHOD1(Send, bool(IPC::Message* msg)); | 41 MOCK_METHOD1(Send, bool(IPC::Message* msg)); |
42 }; | 42 }; |
43 | 43 |
44 MockIPCSender::MockIPCSender() { } | 44 MockIPCSender::MockIPCSender() { } |
45 MockIPCSender::~MockIPCSender() { } | 45 MockIPCSender::~MockIPCSender() { } |
46 | 46 |
47 class FakeSocket : public net::ClientSocket { | 47 class FakeSocket : public net::StreamSocket { |
48 public: | 48 public: |
49 FakeSocket(std::string* written_data); | 49 FakeSocket(std::string* written_data); |
50 virtual ~FakeSocket(); | 50 virtual ~FakeSocket(); |
51 | 51 |
52 void AppendInputData(const char* data, int data_size); | 52 void AppendInputData(const char* data, int data_size); |
53 int input_pos() const { return input_pos_; } | 53 int input_pos() const { return input_pos_; } |
54 bool read_pending() const { return read_pending_; } | 54 bool read_pending() const { return read_pending_; } |
55 void SetPeerAddress(const net::IPEndPoint& peer_address); | 55 void SetPeerAddress(const net::IPEndPoint& peer_address); |
56 void SetLocalAddress(const net::IPEndPoint& local_address); | 56 void SetLocalAddress(const net::IPEndPoint& local_address); |
57 | 57 |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 return false; | 263 return false; |
264 P2PMsg_OnIncomingTcpConnection::Param params; | 264 P2PMsg_OnIncomingTcpConnection::Param params; |
265 IPC::MessageWithTuple<P2PMsg_OnIncomingTcpConnection::Param>::Read( | 265 IPC::MessageWithTuple<P2PMsg_OnIncomingTcpConnection::Param>::Read( |
266 arg, ¶ms); | 266 arg, ¶ms); |
267 return params.b == address; | 267 return params.b == address; |
268 } | 268 } |
269 | 269 |
270 } // namespace | 270 } // namespace |
271 | 271 |
272 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TEST_UTILS_H_ | 272 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TEST_UTILS_H_ |
OLD | NEW |