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 #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_sender.h" | 11 #include "ipc/ipc_sender.h" |
12 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
13 #include "net/socket/stream_socket.h" | 13 #include "net/socket/stream_socket.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 const char kTestLocalIpAddress[] = "123.44.22.4"; | 17 const char kTestLocalIpAddress[] = "123.44.22.4"; |
18 const char kTestIpAddress1[] = "123.44.22.31"; | 18 const char kTestIpAddress1[] = "123.44.22.31"; |
19 const int kTestPort1 = 234; | 19 const uint16 kTestPort1 = 234; |
20 const char kTestIpAddress2[] = "133.11.22.33"; | 20 const char kTestIpAddress2[] = "133.11.22.33"; |
21 const int kTestPort2 = 543; | 21 const uint16 kTestPort2 = 543; |
22 | 22 |
23 class MockIPCSender : public IPC::Sender { | 23 class MockIPCSender : public IPC::Sender { |
24 public: | 24 public: |
25 MockIPCSender(); | 25 MockIPCSender(); |
26 virtual ~MockIPCSender(); | 26 virtual ~MockIPCSender(); |
27 | 27 |
28 MOCK_METHOD1(Send, bool(IPC::Message* msg)); | 28 MOCK_METHOD1(Send, bool(IPC::Message* msg)); |
29 }; | 29 }; |
30 | 30 |
31 class FakeSocket : public net::StreamSocket { | 31 class FakeSocket : public net::StreamSocket { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 net::IPEndPoint local_address_; | 84 net::IPEndPoint local_address_; |
85 | 85 |
86 net::BoundNetLog net_log_; | 86 net::BoundNetLog net_log_; |
87 }; | 87 }; |
88 | 88 |
89 void CreateRandomPacket(std::vector<char>* packet); | 89 void CreateRandomPacket(std::vector<char>* packet); |
90 void CreateStunRequest(std::vector<char>* packet); | 90 void CreateStunRequest(std::vector<char>* packet); |
91 void CreateStunResponse(std::vector<char>* packet); | 91 void CreateStunResponse(std::vector<char>* packet); |
92 void CreateStunError(std::vector<char>* packet); | 92 void CreateStunError(std::vector<char>* packet); |
93 | 93 |
94 net::IPEndPoint ParseAddress(const std::string ip_str, int port); | 94 net::IPEndPoint ParseAddress(const std::string ip_str, uint16 port); |
95 | 95 |
96 MATCHER_P(MatchMessage, type, "") { | 96 MATCHER_P(MatchMessage, type, "") { |
97 return arg->type() == type; | 97 return arg->type() == type; |
98 } | 98 } |
99 | 99 |
100 MATCHER_P(MatchPacketMessage, packet_content, "") { | 100 MATCHER_P(MatchPacketMessage, packet_content, "") { |
101 if (arg->type() != P2PMsg_OnDataReceived::ID) | 101 if (arg->type() != P2PMsg_OnDataReceived::ID) |
102 return false; | 102 return false; |
103 P2PMsg_OnDataReceived::Param params; | 103 P2PMsg_OnDataReceived::Param params; |
104 P2PMsg_OnDataReceived::Read(arg, ¶ms); | 104 P2PMsg_OnDataReceived::Read(arg, ¶ms); |
105 return params.c == packet_content; | 105 return params.c == packet_content; |
106 } | 106 } |
107 | 107 |
108 MATCHER_P(MatchIncomingSocketMessage, address, "") { | 108 MATCHER_P(MatchIncomingSocketMessage, address, "") { |
109 if (arg->type() != P2PMsg_OnIncomingTcpConnection::ID) | 109 if (arg->type() != P2PMsg_OnIncomingTcpConnection::ID) |
110 return false; | 110 return false; |
111 P2PMsg_OnIncomingTcpConnection::Param params; | 111 P2PMsg_OnIncomingTcpConnection::Param params; |
112 P2PMsg_OnIncomingTcpConnection::Read( | 112 P2PMsg_OnIncomingTcpConnection::Read( |
113 arg, ¶ms); | 113 arg, ¶ms); |
114 return params.b == address; | 114 return params.b == address; |
115 } | 115 } |
116 | 116 |
117 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TEST_UTILS_H_ | 117 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TEST_UTILS_H_ |
OLD | NEW |