Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1221)

Side by Side Diff: trunk/src/content/browser/renderer_host/p2p/socket_host_tcp_unittest.cc

Issue 177603002: Revert 252408 "Adding talk_base::PacketOptions to P2P IPC Send m..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 }; 85 };
86 86
87 // Verify that we can send STUN message and that they are formatted 87 // Verify that we can send STUN message and that they are formatted
88 // properly. 88 // properly.
89 TEST_F(P2PSocketHostTcpTest, SendStunNoAuth) { 89 TEST_F(P2PSocketHostTcpTest, SendStunNoAuth) {
90 EXPECT_CALL(sender_, Send( 90 EXPECT_CALL(sender_, Send(
91 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) 91 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID))))
92 .Times(3) 92 .Times(3)
93 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true))); 93 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true)));
94 94
95 talk_base::PacketOptions options;
96 std::vector<char> packet1; 95 std::vector<char> packet1;
97 CreateStunRequest(&packet1); 96 CreateStunRequest(&packet1);
98 socket_host_->Send(dest_, packet1, options, 0); 97 socket_host_->Send(dest_, packet1, net::DSCP_NO_CHANGE, 0);
99 98
100 std::vector<char> packet2; 99 std::vector<char> packet2;
101 CreateStunResponse(&packet2); 100 CreateStunResponse(&packet2);
102 socket_host_->Send(dest_, packet2, options, 0); 101 socket_host_->Send(dest_, packet2, net::DSCP_NO_CHANGE, 0);
103 102
104 std::vector<char> packet3; 103 std::vector<char> packet3;
105 CreateStunError(&packet3); 104 CreateStunError(&packet3);
106 socket_host_->Send(dest_, packet3, options, 0); 105 socket_host_->Send(dest_, packet3, net::DSCP_NO_CHANGE, 0);
107 106
108 std::string expected_data; 107 std::string expected_data;
109 expected_data.append(IntToSize(packet1.size())); 108 expected_data.append(IntToSize(packet1.size()));
110 expected_data.append(packet1.begin(), packet1.end()); 109 expected_data.append(packet1.begin(), packet1.end());
111 expected_data.append(IntToSize(packet2.size())); 110 expected_data.append(IntToSize(packet2.size()));
112 expected_data.append(packet2.begin(), packet2.end()); 111 expected_data.append(packet2.begin(), packet2.end());
113 expected_data.append(IntToSize(packet3.size())); 112 expected_data.append(IntToSize(packet3.size()));
114 expected_data.append(packet3.begin(), packet3.end()); 113 expected_data.append(packet3.begin(), packet3.end());
115 114
116 EXPECT_EQ(expected_data, sent_data_); 115 EXPECT_EQ(expected_data, sent_data_);
117 } 116 }
118 117
119 // Verify that we can receive STUN messages from the socket, and that 118 // Verify that we can receive STUN messages from the socket, and that
120 // the messages are parsed properly. 119 // the messages are parsed properly.
121 TEST_F(P2PSocketHostTcpTest, ReceiveStun) { 120 TEST_F(P2PSocketHostTcpTest, ReceiveStun) {
122 EXPECT_CALL(sender_, Send( 121 EXPECT_CALL(sender_, Send(
123 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) 122 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID))))
124 .Times(3) 123 .Times(3)
125 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true))); 124 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true)));
126 125
127 talk_base::PacketOptions options;
128 std::vector<char> packet1; 126 std::vector<char> packet1;
129 CreateStunRequest(&packet1); 127 CreateStunRequest(&packet1);
130 socket_host_->Send(dest_, packet1, options, 0); 128 socket_host_->Send(dest_, packet1, net::DSCP_NO_CHANGE, 0);
131 129
132 std::vector<char> packet2; 130 std::vector<char> packet2;
133 CreateStunResponse(&packet2); 131 CreateStunResponse(&packet2);
134 socket_host_->Send(dest_, packet2, options, 0); 132 socket_host_->Send(dest_, packet2, net::DSCP_NO_CHANGE, 0);
135 133
136 std::vector<char> packet3; 134 std::vector<char> packet3;
137 CreateStunError(&packet3); 135 CreateStunError(&packet3);
138 socket_host_->Send(dest_, packet3, options, 0); 136 socket_host_->Send(dest_, packet3, net::DSCP_NO_CHANGE, 0);
139 137
140 std::string received_data; 138 std::string received_data;
141 received_data.append(IntToSize(packet1.size())); 139 received_data.append(IntToSize(packet1.size()));
142 received_data.append(packet1.begin(), packet1.end()); 140 received_data.append(packet1.begin(), packet1.end());
143 received_data.append(IntToSize(packet2.size())); 141 received_data.append(IntToSize(packet2.size()));
144 received_data.append(packet2.begin(), packet2.end()); 142 received_data.append(packet2.begin(), packet2.end());
145 received_data.append(IntToSize(packet3.size())); 143 received_data.append(IntToSize(packet3.size()));
146 received_data.append(packet3.begin(), packet3.end()); 144 received_data.append(packet3.begin(), packet3.end());
147 145
148 EXPECT_CALL(sender_, Send(MatchPacketMessage(packet1))) 146 EXPECT_CALL(sender_, Send(MatchPacketMessage(packet1)))
(...skipping 15 matching lines...) Expand all
164 } 162 }
165 } 163 }
166 164
167 // Verify that we can't send data before we've received STUN response 165 // Verify that we can't send data before we've received STUN response
168 // from the other side. 166 // from the other side.
169 TEST_F(P2PSocketHostTcpTest, SendDataNoAuth) { 167 TEST_F(P2PSocketHostTcpTest, SendDataNoAuth) {
170 EXPECT_CALL(sender_, Send( 168 EXPECT_CALL(sender_, Send(
171 MatchMessage(static_cast<uint32>(P2PMsg_OnError::ID)))) 169 MatchMessage(static_cast<uint32>(P2PMsg_OnError::ID))))
172 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 170 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
173 171
174 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_, packet, net::DSCP_NO_CHANGE, 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 talk_base::PacketOptions options;
186 // Receive packet from |dest_|. 182 // Receive packet from |dest_|.
187 std::vector<char> request_packet; 183 std::vector<char> request_packet;
188 CreateStunRequest(&request_packet); 184 CreateStunRequest(&request_packet);
189 185
190 std::string received_data; 186 std::string received_data;
191 received_data.append(IntToSize(request_packet.size())); 187 received_data.append(IntToSize(request_packet.size()));
192 received_data.append(request_packet.begin(), request_packet.end()); 188 received_data.append(request_packet.begin(), request_packet.end());
193 189
194 EXPECT_CALL(sender_, Send( 190 EXPECT_CALL(sender_, Send(
195 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) 191 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID))))
196 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 192 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
197 EXPECT_CALL(sender_, Send(MatchPacketMessage(request_packet))) 193 EXPECT_CALL(sender_, Send(MatchPacketMessage(request_packet)))
198 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 194 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
199 socket_->AppendInputData(&received_data[0], received_data.size()); 195 socket_->AppendInputData(&received_data[0], received_data.size());
200 196
201 // Now we should be able to send any data to |dest_|. 197 // Now we should be able to send any data to |dest_|.
202 std::vector<char> packet; 198 std::vector<char> packet;
203 CreateRandomPacket(&packet); 199 CreateRandomPacket(&packet);
204 socket_host_->Send(dest_, packet, options, 0); 200 socket_host_->Send(dest_, packet, net::DSCP_NO_CHANGE, 0);
205 201
206 std::string expected_data; 202 std::string expected_data;
207 expected_data.append(IntToSize(packet.size())); 203 expected_data.append(IntToSize(packet.size()));
208 expected_data.append(packet.begin(), packet.end()); 204 expected_data.append(packet.begin(), packet.end());
209 205
210 EXPECT_EQ(expected_data, sent_data_); 206 EXPECT_EQ(expected_data, sent_data_);
211 } 207 }
212 208
213 // Verify that asynchronous writes are handled correctly. 209 // Verify that asynchronous writes are handled correctly.
214 TEST_F(P2PSocketHostTcpTest, AsyncWrites) { 210 TEST_F(P2PSocketHostTcpTest, AsyncWrites) {
215 base::MessageLoop message_loop; 211 base::MessageLoop message_loop;
216 talk_base::PacketOptions options;
217 212
218 socket_->set_async_write(true); 213 socket_->set_async_write(true);
219 214
220 EXPECT_CALL(sender_, Send( 215 EXPECT_CALL(sender_, Send(
221 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) 216 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID))))
222 .Times(2) 217 .Times(2)
223 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true))); 218 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true)));
224 219
225 std::vector<char> packet1; 220 std::vector<char> packet1;
226 CreateStunRequest(&packet1); 221 CreateStunRequest(&packet1);
227 222
228 socket_host_->Send(dest_, packet1, options, 0); 223 socket_host_->Send(dest_, packet1, net::DSCP_NO_CHANGE, 0);
229 224
230 std::vector<char> packet2; 225 std::vector<char> packet2;
231 CreateStunResponse(&packet2); 226 CreateStunResponse(&packet2);
232 socket_host_->Send(dest_, packet2, options, 0); 227 socket_host_->Send(dest_, packet2, net::DSCP_NO_CHANGE, 0);
233 228
234 message_loop.RunUntilIdle(); 229 message_loop.RunUntilIdle();
235 230
236 std::string expected_data; 231 std::string expected_data;
237 expected_data.append(IntToSize(packet1.size())); 232 expected_data.append(IntToSize(packet1.size()));
238 expected_data.append(packet1.begin(), packet1.end()); 233 expected_data.append(packet1.begin(), packet1.end());
239 expected_data.append(IntToSize(packet2.size())); 234 expected_data.append(IntToSize(packet2.size()));
240 expected_data.append(packet2.begin(), packet2.end()); 235 expected_data.append(packet2.begin(), packet2.end());
241 236
242 EXPECT_EQ(expected_data, sent_data_); 237 EXPECT_EQ(expected_data, sent_data_);
243 } 238 }
244 239
245 // Verify that we can send STUN message and that they are formatted 240 // Verify that we can send STUN message and that they are formatted
246 // properly. 241 // properly.
247 TEST_F(P2PSocketHostStunTcpTest, SendStunNoAuth) { 242 TEST_F(P2PSocketHostStunTcpTest, SendStunNoAuth) {
248 EXPECT_CALL(sender_, Send( 243 EXPECT_CALL(sender_, Send(
249 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) 244 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID))))
250 .Times(3) 245 .Times(3)
251 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true))); 246 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true)));
252 247
253 talk_base::PacketOptions options;
254 std::vector<char> packet1; 248 std::vector<char> packet1;
255 CreateStunRequest(&packet1); 249 CreateStunRequest(&packet1);
256 socket_host_->Send(dest_, packet1, options, 0); 250 socket_host_->Send(dest_, packet1, net::DSCP_NO_CHANGE, 0);
257 251
258 std::vector<char> packet2; 252 std::vector<char> packet2;
259 CreateStunResponse(&packet2); 253 CreateStunResponse(&packet2);
260 socket_host_->Send(dest_, packet2, options, 0); 254 socket_host_->Send(dest_, packet2, net::DSCP_NO_CHANGE, 0);
261 255
262 std::vector<char> packet3; 256 std::vector<char> packet3;
263 CreateStunError(&packet3); 257 CreateStunError(&packet3);
264 socket_host_->Send(dest_, packet3, options, 0); 258 socket_host_->Send(dest_, packet3, net::DSCP_NO_CHANGE, 0);
265 259
266 std::string expected_data; 260 std::string expected_data;
267 expected_data.append(packet1.begin(), packet1.end()); 261 expected_data.append(packet1.begin(), packet1.end());
268 expected_data.append(packet2.begin(), packet2.end()); 262 expected_data.append(packet2.begin(), packet2.end());
269 expected_data.append(packet3.begin(), packet3.end()); 263 expected_data.append(packet3.begin(), packet3.end());
270 264
271 EXPECT_EQ(expected_data, sent_data_); 265 EXPECT_EQ(expected_data, sent_data_);
272 } 266 }
273 267
274 // Verify that we can receive STUN messages from the socket, and that 268 // Verify that we can receive STUN messages from the socket, and that
275 // the messages are parsed properly. 269 // the messages are parsed properly.
276 TEST_F(P2PSocketHostStunTcpTest, ReceiveStun) { 270 TEST_F(P2PSocketHostStunTcpTest, ReceiveStun) {
277 EXPECT_CALL(sender_, Send( 271 EXPECT_CALL(sender_, Send(
278 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) 272 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID))))
279 .Times(3) 273 .Times(3)
280 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true))); 274 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true)));
281 275
282 talk_base::PacketOptions options;
283 std::vector<char> packet1; 276 std::vector<char> packet1;
284 CreateStunRequest(&packet1); 277 CreateStunRequest(&packet1);
285 socket_host_->Send(dest_, packet1, options, 0); 278 socket_host_->Send(dest_, packet1, net::DSCP_NO_CHANGE, 0);
286 279
287 std::vector<char> packet2; 280 std::vector<char> packet2;
288 CreateStunResponse(&packet2); 281 CreateStunResponse(&packet2);
289 socket_host_->Send(dest_, packet2, options, 0); 282 socket_host_->Send(dest_, packet2, net::DSCP_NO_CHANGE, 0);
290 283
291 std::vector<char> packet3; 284 std::vector<char> packet3;
292 CreateStunError(&packet3); 285 CreateStunError(&packet3);
293 socket_host_->Send(dest_, packet3, options, 0); 286 socket_host_->Send(dest_, packet3, net::DSCP_NO_CHANGE, 0);
294 287
295 std::string received_data; 288 std::string received_data;
296 received_data.append(packet1.begin(), packet1.end()); 289 received_data.append(packet1.begin(), packet1.end());
297 received_data.append(packet2.begin(), packet2.end()); 290 received_data.append(packet2.begin(), packet2.end());
298 received_data.append(packet3.begin(), packet3.end()); 291 received_data.append(packet3.begin(), packet3.end());
299 292
300 EXPECT_CALL(sender_, Send(MatchPacketMessage(packet1))) 293 EXPECT_CALL(sender_, Send(MatchPacketMessage(packet1)))
301 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 294 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
302 EXPECT_CALL(sender_, Send(MatchPacketMessage(packet2))) 295 EXPECT_CALL(sender_, Send(MatchPacketMessage(packet2)))
303 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 296 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
(...skipping 12 matching lines...) Expand all
316 } 309 }
317 } 310 }
318 311
319 // Verify that we can't send data before we've received STUN response 312 // Verify that we can't send data before we've received STUN response
320 // from the other side. 313 // from the other side.
321 TEST_F(P2PSocketHostStunTcpTest, SendDataNoAuth) { 314 TEST_F(P2PSocketHostStunTcpTest, SendDataNoAuth) {
322 EXPECT_CALL(sender_, Send( 315 EXPECT_CALL(sender_, Send(
323 MatchMessage(static_cast<uint32>(P2PMsg_OnError::ID)))) 316 MatchMessage(static_cast<uint32>(P2PMsg_OnError::ID))))
324 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 317 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
325 318
326 talk_base::PacketOptions options;
327 std::vector<char> packet; 319 std::vector<char> packet;
328 CreateRandomPacket(&packet); 320 CreateRandomPacket(&packet);
329 socket_host_->Send(dest_, packet, options, 0); 321 socket_host_->Send(dest_, packet, net::DSCP_NO_CHANGE, 0);
330 322
331 EXPECT_EQ(0U, sent_data_.size()); 323 EXPECT_EQ(0U, sent_data_.size());
332 } 324 }
333 325
334 // Verify that asynchronous writes are handled correctly. 326 // Verify that asynchronous writes are handled correctly.
335 TEST_F(P2PSocketHostStunTcpTest, AsyncWrites) { 327 TEST_F(P2PSocketHostStunTcpTest, AsyncWrites) {
336 base::MessageLoop message_loop; 328 base::MessageLoop message_loop;
337 329
338 socket_->set_async_write(true); 330 socket_->set_async_write(true);
339 331
340 EXPECT_CALL(sender_, Send( 332 EXPECT_CALL(sender_, Send(
341 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) 333 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID))))
342 .Times(2) 334 .Times(2)
343 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true))); 335 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true)));
344 336
345 talk_base::PacketOptions options;
346 std::vector<char> packet1; 337 std::vector<char> packet1;
347 CreateStunRequest(&packet1); 338 CreateStunRequest(&packet1);
348 socket_host_->Send(dest_, packet1, options, 0); 339 socket_host_->Send(dest_, packet1, net::DSCP_NO_CHANGE,0);
349 340
350 std::vector<char> packet2; 341 std::vector<char> packet2;
351 CreateStunResponse(&packet2); 342 CreateStunResponse(&packet2);
352 socket_host_->Send(dest_, packet2, options, 0); 343 socket_host_->Send(dest_, packet2, net::DSCP_NO_CHANGE, 0);
353 344
354 message_loop.RunUntilIdle(); 345 message_loop.RunUntilIdle();
355 346
356 std::string expected_data; 347 std::string expected_data;
357 expected_data.append(packet1.begin(), packet1.end()); 348 expected_data.append(packet1.begin(), packet1.end());
358 expected_data.append(packet2.begin(), packet2.end()); 349 expected_data.append(packet2.begin(), packet2.end());
359 350
360 EXPECT_EQ(expected_data, sent_data_); 351 EXPECT_EQ(expected_data, sent_data_);
361 } 352 }
362 353
363 } // namespace content 354 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698