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 #include "content/browser/renderer_host/p2p/socket_host_tcp.h" | 5 #include "content/browser/renderer_host/p2p/socket_host_tcp.h" |
6 | 6 |
7 #include <deque> | 7 #include <deque> |
8 | 8 |
9 #include "base/sys_byteorder.h" | 9 #include "base/sys_byteorder.h" |
10 #include "content/browser/renderer_host/p2p/socket_host_test_utils.h" | 10 #include "content/browser/renderer_host/p2p/socket_host_test_utils.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 &sender_, 0, P2P_SOCKET_TCP_CLIENT, NULL)); | 35 &sender_, 0, P2P_SOCKET_TCP_CLIENT, NULL)); |
36 } else { | 36 } else { |
37 socket_host_.reset(new P2PSocketHostStunTcp( | 37 socket_host_.reset(new P2PSocketHostStunTcp( |
38 &sender_, 0, P2P_SOCKET_STUN_TCP_CLIENT, NULL)); | 38 &sender_, 0, P2P_SOCKET_STUN_TCP_CLIENT, NULL)); |
39 } | 39 } |
40 | 40 |
41 socket_ = new FakeSocket(&sent_data_); | 41 socket_ = new FakeSocket(&sent_data_); |
42 socket_->SetLocalAddress(ParseAddress(kTestLocalIpAddress, kTestPort1)); | 42 socket_->SetLocalAddress(ParseAddress(kTestLocalIpAddress, kTestPort1)); |
43 socket_host_->socket_.reset(socket_); | 43 socket_host_->socket_.reset(socket_); |
44 | 44 |
45 dest_ = ParseAddress(kTestIpAddress1, kTestPort1); | 45 dest_.ip_address = ParseAddress(kTestIpAddress1, kTestPort1); |
46 | 46 |
47 local_address_ = ParseAddress(kTestLocalIpAddress, kTestPort1); | 47 local_address_ = ParseAddress(kTestLocalIpAddress, kTestPort1); |
48 | 48 |
49 socket_host_->remote_address_ = dest_; | 49 socket_host_->remote_address_ = dest_; |
50 socket_host_->state_ = P2PSocketHost::STATE_CONNECTING; | 50 socket_host_->state_ = P2PSocketHost::STATE_CONNECTING; |
51 socket_host_->OnConnected(net::OK); | 51 socket_host_->OnConnected(net::OK); |
52 } | 52 } |
53 | 53 |
54 std::string IntToSize(int size) { | 54 std::string IntToSize(int size) { |
55 std::string result; | 55 std::string result; |
56 uint16 size16 = base::HostToNet16(size); | 56 uint16 size16 = base::HostToNet16(size); |
57 result.resize(sizeof(size16)); | 57 result.resize(sizeof(size16)); |
58 memcpy(&result[0], &size16, sizeof(size16)); | 58 memcpy(&result[0], &size16, sizeof(size16)); |
59 return result; | 59 return result; |
60 } | 60 } |
61 | 61 |
62 std::string sent_data_; | 62 std::string sent_data_; |
63 FakeSocket* socket_; // Owned by |socket_host_|. | 63 FakeSocket* socket_; // Owned by |socket_host_|. |
64 scoped_ptr<P2PSocketHostTcpBase> socket_host_; | 64 scoped_ptr<P2PSocketHostTcpBase> socket_host_; |
65 MockIPCSender sender_; | 65 MockIPCSender sender_; |
66 | 66 |
67 net::IPEndPoint local_address_; | 67 net::IPEndPoint local_address_; |
68 | 68 P2PHostAndIPEndPoint dest_; |
69 net::IPEndPoint dest_; | |
70 net::IPEndPoint dest2_; | |
71 | |
72 P2PSocketType socket_type_; | 69 P2PSocketType socket_type_; |
73 }; | 70 }; |
74 | 71 |
75 class P2PSocketHostTcpTest : public P2PSocketHostTcpTestBase { | 72 class P2PSocketHostTcpTest : public P2PSocketHostTcpTestBase { |
76 protected: | 73 protected: |
77 P2PSocketHostTcpTest() : P2PSocketHostTcpTestBase(P2P_SOCKET_TCP_CLIENT) { } | 74 P2PSocketHostTcpTest() : P2PSocketHostTcpTestBase(P2P_SOCKET_TCP_CLIENT) { } |
78 }; | 75 }; |
79 | 76 |
80 class P2PSocketHostStunTcpTest : public P2PSocketHostTcpTestBase { | 77 class P2PSocketHostStunTcpTest : public P2PSocketHostTcpTestBase { |
81 protected: | 78 protected: |
82 P2PSocketHostStunTcpTest() | 79 P2PSocketHostStunTcpTest() |
83 : P2PSocketHostTcpTestBase(P2P_SOCKET_STUN_TCP_CLIENT) { | 80 : P2PSocketHostTcpTestBase(P2P_SOCKET_STUN_TCP_CLIENT) { |
84 } | 81 } |
85 }; | 82 }; |
86 | 83 |
87 // Verify that we can send STUN message and that they are formatted | 84 // Verify that we can send STUN message and that they are formatted |
88 // properly. | 85 // properly. |
89 TEST_F(P2PSocketHostTcpTest, SendStunNoAuth) { | 86 TEST_F(P2PSocketHostTcpTest, SendStunNoAuth) { |
90 EXPECT_CALL(sender_, Send( | 87 EXPECT_CALL(sender_, Send( |
91 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) | 88 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) |
92 .Times(3) | 89 .Times(3) |
93 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true))); | 90 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true))); |
94 | 91 |
95 talk_base::PacketOptions options; | 92 talk_base::PacketOptions options; |
96 std::vector<char> packet1; | 93 std::vector<char> packet1; |
97 CreateStunRequest(&packet1); | 94 CreateStunRequest(&packet1); |
98 socket_host_->Send(dest_, packet1, options, 0); | 95 socket_host_->Send(dest_.ip_address, packet1, options, 0); |
99 | 96 |
100 std::vector<char> packet2; | 97 std::vector<char> packet2; |
101 CreateStunResponse(&packet2); | 98 CreateStunResponse(&packet2); |
102 socket_host_->Send(dest_, packet2, options, 0); | 99 socket_host_->Send(dest_.ip_address, packet2, options, 0); |
103 | 100 |
104 std::vector<char> packet3; | 101 std::vector<char> packet3; |
105 CreateStunError(&packet3); | 102 CreateStunError(&packet3); |
106 socket_host_->Send(dest_, packet3, options, 0); | 103 socket_host_->Send(dest_.ip_address, packet3, options, 0); |
107 | 104 |
108 std::string expected_data; | 105 std::string expected_data; |
109 expected_data.append(IntToSize(packet1.size())); | 106 expected_data.append(IntToSize(packet1.size())); |
110 expected_data.append(packet1.begin(), packet1.end()); | 107 expected_data.append(packet1.begin(), packet1.end()); |
111 expected_data.append(IntToSize(packet2.size())); | 108 expected_data.append(IntToSize(packet2.size())); |
112 expected_data.append(packet2.begin(), packet2.end()); | 109 expected_data.append(packet2.begin(), packet2.end()); |
113 expected_data.append(IntToSize(packet3.size())); | 110 expected_data.append(IntToSize(packet3.size())); |
114 expected_data.append(packet3.begin(), packet3.end()); | 111 expected_data.append(packet3.begin(), packet3.end()); |
115 | 112 |
116 EXPECT_EQ(expected_data, sent_data_); | 113 EXPECT_EQ(expected_data, sent_data_); |
117 } | 114 } |
118 | 115 |
119 // Verify that we can receive STUN messages from the socket, and that | 116 // Verify that we can receive STUN messages from the socket, and that |
120 // the messages are parsed properly. | 117 // the messages are parsed properly. |
121 TEST_F(P2PSocketHostTcpTest, ReceiveStun) { | 118 TEST_F(P2PSocketHostTcpTest, ReceiveStun) { |
122 EXPECT_CALL(sender_, Send( | 119 EXPECT_CALL(sender_, Send( |
123 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) | 120 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) |
124 .Times(3) | 121 .Times(3) |
125 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true))); | 122 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true))); |
126 | 123 |
127 talk_base::PacketOptions options; | 124 talk_base::PacketOptions options; |
128 std::vector<char> packet1; | 125 std::vector<char> packet1; |
129 CreateStunRequest(&packet1); | 126 CreateStunRequest(&packet1); |
130 socket_host_->Send(dest_, packet1, options, 0); | 127 socket_host_->Send(dest_.ip_address, packet1, options, 0); |
131 | 128 |
132 std::vector<char> packet2; | 129 std::vector<char> packet2; |
133 CreateStunResponse(&packet2); | 130 CreateStunResponse(&packet2); |
134 socket_host_->Send(dest_, packet2, options, 0); | 131 socket_host_->Send(dest_.ip_address, packet2, options, 0); |
135 | 132 |
136 std::vector<char> packet3; | 133 std::vector<char> packet3; |
137 CreateStunError(&packet3); | 134 CreateStunError(&packet3); |
138 socket_host_->Send(dest_, packet3, options, 0); | 135 socket_host_->Send(dest_.ip_address, packet3, options, 0); |
139 | 136 |
140 std::string received_data; | 137 std::string received_data; |
141 received_data.append(IntToSize(packet1.size())); | 138 received_data.append(IntToSize(packet1.size())); |
142 received_data.append(packet1.begin(), packet1.end()); | 139 received_data.append(packet1.begin(), packet1.end()); |
143 received_data.append(IntToSize(packet2.size())); | 140 received_data.append(IntToSize(packet2.size())); |
144 received_data.append(packet2.begin(), packet2.end()); | 141 received_data.append(packet2.begin(), packet2.end()); |
145 received_data.append(IntToSize(packet3.size())); | 142 received_data.append(IntToSize(packet3.size())); |
146 received_data.append(packet3.begin(), packet3.end()); | 143 received_data.append(packet3.begin(), packet3.end()); |
147 | 144 |
148 EXPECT_CALL(sender_, Send(MatchPacketMessage(packet1))) | 145 EXPECT_CALL(sender_, Send(MatchPacketMessage(packet1))) |
(...skipping 18 matching lines...) Expand all Loading... |
167 // Verify that we can't send data before we've received STUN response | 164 // Verify that we can't send data before we've received STUN response |
168 // from the other side. | 165 // from the other side. |
169 TEST_F(P2PSocketHostTcpTest, SendDataNoAuth) { | 166 TEST_F(P2PSocketHostTcpTest, SendDataNoAuth) { |
170 EXPECT_CALL(sender_, Send( | 167 EXPECT_CALL(sender_, Send( |
171 MatchMessage(static_cast<uint32>(P2PMsg_OnError::ID)))) | 168 MatchMessage(static_cast<uint32>(P2PMsg_OnError::ID)))) |
172 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); | 169 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); |
173 | 170 |
174 talk_base::PacketOptions options; | 171 talk_base::PacketOptions options; |
175 std::vector<char> packet; | 172 std::vector<char> packet; |
176 CreateRandomPacket(&packet); | 173 CreateRandomPacket(&packet); |
177 socket_host_->Send(dest_, packet, options, 0); | 174 socket_host_->Send(dest_.ip_address, packet, options, 0); |
178 | 175 |
179 EXPECT_EQ(0U, sent_data_.size()); | 176 EXPECT_EQ(0U, sent_data_.size()); |
180 } | 177 } |
181 | 178 |
182 // Verify that we can send data after we've received STUN response | 179 // Verify that we can send data after we've received STUN response |
183 // from the other side. | 180 // from the other side. |
184 TEST_F(P2PSocketHostTcpTest, SendAfterStunRequest) { | 181 TEST_F(P2PSocketHostTcpTest, SendAfterStunRequest) { |
185 // Receive packet from |dest_|. | 182 // Receive packet from |dest_|. |
186 std::vector<char> request_packet; | 183 std::vector<char> request_packet; |
187 CreateStunRequest(&request_packet); | 184 CreateStunRequest(&request_packet); |
188 | 185 |
189 std::string received_data; | 186 std::string received_data; |
190 received_data.append(IntToSize(request_packet.size())); | 187 received_data.append(IntToSize(request_packet.size())); |
191 received_data.append(request_packet.begin(), request_packet.end()); | 188 received_data.append(request_packet.begin(), request_packet.end()); |
192 | 189 |
193 EXPECT_CALL(sender_, Send( | 190 EXPECT_CALL(sender_, Send( |
194 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) | 191 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) |
195 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); | 192 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); |
196 EXPECT_CALL(sender_, Send(MatchPacketMessage(request_packet))) | 193 EXPECT_CALL(sender_, Send(MatchPacketMessage(request_packet))) |
197 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); | 194 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); |
198 socket_->AppendInputData(&received_data[0], received_data.size()); | 195 socket_->AppendInputData(&received_data[0], received_data.size()); |
199 | 196 |
200 talk_base::PacketOptions options; | 197 talk_base::PacketOptions options; |
201 // Now we should be able to send any data to |dest_|. | 198 // Now we should be able to send any data to |dest_|. |
202 std::vector<char> packet; | 199 std::vector<char> packet; |
203 CreateRandomPacket(&packet); | 200 CreateRandomPacket(&packet); |
204 socket_host_->Send(dest_, packet, options, 0); | 201 socket_host_->Send(dest_.ip_address, packet, options, 0); |
205 | 202 |
206 std::string expected_data; | 203 std::string expected_data; |
207 expected_data.append(IntToSize(packet.size())); | 204 expected_data.append(IntToSize(packet.size())); |
208 expected_data.append(packet.begin(), packet.end()); | 205 expected_data.append(packet.begin(), packet.end()); |
209 | 206 |
210 EXPECT_EQ(expected_data, sent_data_); | 207 EXPECT_EQ(expected_data, sent_data_); |
211 } | 208 } |
212 | 209 |
213 // Verify that asynchronous writes are handled correctly. | 210 // Verify that asynchronous writes are handled correctly. |
214 TEST_F(P2PSocketHostTcpTest, AsyncWrites) { | 211 TEST_F(P2PSocketHostTcpTest, AsyncWrites) { |
215 base::MessageLoop message_loop; | 212 base::MessageLoop message_loop; |
216 | 213 |
217 socket_->set_async_write(true); | 214 socket_->set_async_write(true); |
218 | 215 |
219 EXPECT_CALL(sender_, Send( | 216 EXPECT_CALL(sender_, Send( |
220 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) | 217 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) |
221 .Times(2) | 218 .Times(2) |
222 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true))); | 219 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true))); |
223 | 220 |
224 talk_base::PacketOptions options; | 221 talk_base::PacketOptions options; |
225 std::vector<char> packet1; | 222 std::vector<char> packet1; |
226 CreateStunRequest(&packet1); | 223 CreateStunRequest(&packet1); |
227 | 224 |
228 socket_host_->Send(dest_, packet1, options, 0); | 225 socket_host_->Send(dest_.ip_address, packet1, options, 0); |
229 | 226 |
230 std::vector<char> packet2; | 227 std::vector<char> packet2; |
231 CreateStunResponse(&packet2); | 228 CreateStunResponse(&packet2); |
232 socket_host_->Send(dest_, packet2, options, 0); | 229 socket_host_->Send(dest_.ip_address, packet2, options, 0); |
233 | 230 |
234 message_loop.RunUntilIdle(); | 231 message_loop.RunUntilIdle(); |
235 | 232 |
236 std::string expected_data; | 233 std::string expected_data; |
237 expected_data.append(IntToSize(packet1.size())); | 234 expected_data.append(IntToSize(packet1.size())); |
238 expected_data.append(packet1.begin(), packet1.end()); | 235 expected_data.append(packet1.begin(), packet1.end()); |
239 expected_data.append(IntToSize(packet2.size())); | 236 expected_data.append(IntToSize(packet2.size())); |
240 expected_data.append(packet2.begin(), packet2.end()); | 237 expected_data.append(packet2.begin(), packet2.end()); |
241 | 238 |
242 EXPECT_EQ(expected_data, sent_data_); | 239 EXPECT_EQ(expected_data, sent_data_); |
243 } | 240 } |
244 | 241 |
245 // Verify that we can send STUN message and that they are formatted | 242 // Verify that we can send STUN message and that they are formatted |
246 // properly. | 243 // properly. |
247 TEST_F(P2PSocketHostStunTcpTest, SendStunNoAuth) { | 244 TEST_F(P2PSocketHostStunTcpTest, SendStunNoAuth) { |
248 EXPECT_CALL(sender_, Send( | 245 EXPECT_CALL(sender_, Send( |
249 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) | 246 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) |
250 .Times(3) | 247 .Times(3) |
251 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true))); | 248 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true))); |
252 | 249 |
253 talk_base::PacketOptions options; | 250 talk_base::PacketOptions options; |
254 std::vector<char> packet1; | 251 std::vector<char> packet1; |
255 CreateStunRequest(&packet1); | 252 CreateStunRequest(&packet1); |
256 socket_host_->Send(dest_, packet1, options, 0); | 253 socket_host_->Send(dest_.ip_address, packet1, options, 0); |
257 | 254 |
258 std::vector<char> packet2; | 255 std::vector<char> packet2; |
259 CreateStunResponse(&packet2); | 256 CreateStunResponse(&packet2); |
260 socket_host_->Send(dest_, packet2, options, 0); | 257 socket_host_->Send(dest_.ip_address, packet2, options, 0); |
261 | 258 |
262 std::vector<char> packet3; | 259 std::vector<char> packet3; |
263 CreateStunError(&packet3); | 260 CreateStunError(&packet3); |
264 socket_host_->Send(dest_, packet3, options, 0); | 261 socket_host_->Send(dest_.ip_address, packet3, options, 0); |
265 | 262 |
266 std::string expected_data; | 263 std::string expected_data; |
267 expected_data.append(packet1.begin(), packet1.end()); | 264 expected_data.append(packet1.begin(), packet1.end()); |
268 expected_data.append(packet2.begin(), packet2.end()); | 265 expected_data.append(packet2.begin(), packet2.end()); |
269 expected_data.append(packet3.begin(), packet3.end()); | 266 expected_data.append(packet3.begin(), packet3.end()); |
270 | 267 |
271 EXPECT_EQ(expected_data, sent_data_); | 268 EXPECT_EQ(expected_data, sent_data_); |
272 } | 269 } |
273 | 270 |
274 // Verify that we can receive STUN messages from the socket, and that | 271 // Verify that we can receive STUN messages from the socket, and that |
275 // the messages are parsed properly. | 272 // the messages are parsed properly. |
276 TEST_F(P2PSocketHostStunTcpTest, ReceiveStun) { | 273 TEST_F(P2PSocketHostStunTcpTest, ReceiveStun) { |
277 EXPECT_CALL(sender_, Send( | 274 EXPECT_CALL(sender_, Send( |
278 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) | 275 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) |
279 .Times(3) | 276 .Times(3) |
280 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true))); | 277 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true))); |
281 | 278 |
282 talk_base::PacketOptions options; | 279 talk_base::PacketOptions options; |
283 std::vector<char> packet1; | 280 std::vector<char> packet1; |
284 CreateStunRequest(&packet1); | 281 CreateStunRequest(&packet1); |
285 socket_host_->Send(dest_, packet1, options, 0); | 282 socket_host_->Send(dest_.ip_address, packet1, options, 0); |
286 | 283 |
287 std::vector<char> packet2; | 284 std::vector<char> packet2; |
288 CreateStunResponse(&packet2); | 285 CreateStunResponse(&packet2); |
289 socket_host_->Send(dest_, packet2, options, 0); | 286 socket_host_->Send(dest_.ip_address, packet2, options, 0); |
290 | 287 |
291 std::vector<char> packet3; | 288 std::vector<char> packet3; |
292 CreateStunError(&packet3); | 289 CreateStunError(&packet3); |
293 socket_host_->Send(dest_, packet3, options, 0); | 290 socket_host_->Send(dest_.ip_address, packet3, options, 0); |
294 | 291 |
295 std::string received_data; | 292 std::string received_data; |
296 received_data.append(packet1.begin(), packet1.end()); | 293 received_data.append(packet1.begin(), packet1.end()); |
297 received_data.append(packet2.begin(), packet2.end()); | 294 received_data.append(packet2.begin(), packet2.end()); |
298 received_data.append(packet3.begin(), packet3.end()); | 295 received_data.append(packet3.begin(), packet3.end()); |
299 | 296 |
300 EXPECT_CALL(sender_, Send(MatchPacketMessage(packet1))) | 297 EXPECT_CALL(sender_, Send(MatchPacketMessage(packet1))) |
301 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); | 298 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); |
302 EXPECT_CALL(sender_, Send(MatchPacketMessage(packet2))) | 299 EXPECT_CALL(sender_, Send(MatchPacketMessage(packet2))) |
303 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); | 300 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); |
(...skipping 15 matching lines...) Expand all Loading... |
319 // Verify that we can't send data before we've received STUN response | 316 // Verify that we can't send data before we've received STUN response |
320 // from the other side. | 317 // from the other side. |
321 TEST_F(P2PSocketHostStunTcpTest, SendDataNoAuth) { | 318 TEST_F(P2PSocketHostStunTcpTest, SendDataNoAuth) { |
322 EXPECT_CALL(sender_, Send( | 319 EXPECT_CALL(sender_, Send( |
323 MatchMessage(static_cast<uint32>(P2PMsg_OnError::ID)))) | 320 MatchMessage(static_cast<uint32>(P2PMsg_OnError::ID)))) |
324 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); | 321 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); |
325 | 322 |
326 talk_base::PacketOptions options; | 323 talk_base::PacketOptions options; |
327 std::vector<char> packet; | 324 std::vector<char> packet; |
328 CreateRandomPacket(&packet); | 325 CreateRandomPacket(&packet); |
329 socket_host_->Send(dest_, packet, options, 0); | 326 socket_host_->Send(dest_.ip_address, packet, options, 0); |
330 | 327 |
331 EXPECT_EQ(0U, sent_data_.size()); | 328 EXPECT_EQ(0U, sent_data_.size()); |
332 } | 329 } |
333 | 330 |
334 // Verify that asynchronous writes are handled correctly. | 331 // Verify that asynchronous writes are handled correctly. |
335 TEST_F(P2PSocketHostStunTcpTest, AsyncWrites) { | 332 TEST_F(P2PSocketHostStunTcpTest, AsyncWrites) { |
336 base::MessageLoop message_loop; | 333 base::MessageLoop message_loop; |
337 | 334 |
338 socket_->set_async_write(true); | 335 socket_->set_async_write(true); |
339 | 336 |
340 EXPECT_CALL(sender_, Send( | 337 EXPECT_CALL(sender_, Send( |
341 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) | 338 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) |
342 .Times(2) | 339 .Times(2) |
343 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true))); | 340 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true))); |
344 | 341 |
345 talk_base::PacketOptions options; | 342 talk_base::PacketOptions options; |
346 std::vector<char> packet1; | 343 std::vector<char> packet1; |
347 CreateStunRequest(&packet1); | 344 CreateStunRequest(&packet1); |
348 socket_host_->Send(dest_, packet1, options, 0); | 345 socket_host_->Send(dest_.ip_address, packet1, options, 0); |
349 | 346 |
350 std::vector<char> packet2; | 347 std::vector<char> packet2; |
351 CreateStunResponse(&packet2); | 348 CreateStunResponse(&packet2); |
352 socket_host_->Send(dest_, packet2, options, 0); | 349 socket_host_->Send(dest_.ip_address, packet2, options, 0); |
353 | 350 |
354 message_loop.RunUntilIdle(); | 351 message_loop.RunUntilIdle(); |
355 | 352 |
356 std::string expected_data; | 353 std::string expected_data; |
357 expected_data.append(packet1.begin(), packet1.end()); | 354 expected_data.append(packet1.begin(), packet1.end()); |
358 expected_data.append(packet2.begin(), packet2.end()); | 355 expected_data.append(packet2.begin(), packet2.end()); |
359 | 356 |
360 EXPECT_EQ(expected_data, sent_data_); | 357 EXPECT_EQ(expected_data, sent_data_); |
361 } | 358 } |
362 | 359 |
363 } // namespace content | 360 } // namespace content |
OLD | NEW |