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

Side by Side Diff: ppapi/tests/test_udp_socket.cc

Issue 632113003: Pepper: Allow plugins to call PPB_UDP_Socket::SendTo multiple times. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix rebase weirdness. Created 5 years, 11 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
« no previous file with comments | « ppapi/tests/test_udp_socket.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ppapi/tests/test_udp_socket.h" 5 #include "ppapi/tests/test_udp_socket.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "ppapi/cpp/pass_ref.h" 9 #include "ppapi/cpp/pass_ref.h"
10 #include "ppapi/cpp/tcp_socket.h" 10 #include "ppapi/cpp/tcp_socket.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 net_address_is_available && 76 net_address_is_available &&
77 init_address && 77 init_address &&
78 CheckTestingInterface() && 78 CheckTestingInterface() &&
79 EnsureRunningOverHTTP(); 79 EnsureRunningOverHTTP();
80 } 80 }
81 81
82 void TestUDPSocket::RunTests(const std::string& filter) { 82 void TestUDPSocket::RunTests(const std::string& filter) {
83 RUN_CALLBACK_TEST(TestUDPSocket, ReadWrite, filter); 83 RUN_CALLBACK_TEST(TestUDPSocket, ReadWrite, filter);
84 RUN_CALLBACK_TEST(TestUDPSocket, Broadcast, filter); 84 RUN_CALLBACK_TEST(TestUDPSocket, Broadcast, filter);
85 RUN_CALLBACK_TEST(TestUDPSocket, SetOption, filter); 85 RUN_CALLBACK_TEST(TestUDPSocket, SetOption, filter);
86 RUN_CALLBACK_TEST(TestUDPSocket, ParallelSend, filter);
86 } 87 }
87 88
88 std::string TestUDPSocket::GetLocalAddress(pp::NetAddress* address) { 89 std::string TestUDPSocket::GetLocalAddress(pp::NetAddress* address) {
89 pp::TCPSocket socket(instance_); 90 pp::TCPSocket socket(instance_);
90 TestCompletionCallback callback(instance_->pp_instance(), callback_type()); 91 TestCompletionCallback callback(instance_->pp_instance(), callback_type());
91 callback.WaitForResult(socket.Connect(address_, callback.GetCallback())); 92 callback.WaitForResult(socket.Connect(address_, callback.GetCallback()));
92 CHECK_CALLBACK_BEHAVIOR(callback); 93 CHECK_CALLBACK_BEHAVIOR(callback);
93 ASSERT_EQ(PP_OK, callback.result()); 94 ASSERT_EQ(PP_OK, callback.result());
94 *address = socket.GetLocalAddress(); 95 *address = socket.GetLocalAddress();
95 ASSERT_NE(0, address->pp_resource()); 96 ASSERT_NE(0, address->pp_resource());
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 ASSERT_EQ(PP_OK, callback.result()); 309 ASSERT_EQ(PP_OK, callback.result());
309 310
310 callback.WaitForResult(socket.SetOption( 311 callback.WaitForResult(socket.SetOption(
311 PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE, pp::Var(1024), 312 PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE, pp::Var(1024),
312 callback.GetCallback())); 313 callback.GetCallback()));
313 CHECK_CALLBACK_BEHAVIOR(callback); 314 CHECK_CALLBACK_BEHAVIOR(callback);
314 ASSERT_EQ(PP_OK, callback.result()); 315 ASSERT_EQ(PP_OK, callback.result());
315 316
316 PASS(); 317 PASS();
317 } 318 }
319
320 std::string TestUDPSocket::TestParallelSend() {
321 // This test only makes sense when callbacks are optional.
322 if (callback_type() != PP_OPTIONAL)
323 PASS();
324
325 pp::UDPSocket server_socket(instance_), client_socket(instance_);
326 pp::NetAddress server_address, client_address;
327
328 ASSERT_SUBTEST_SUCCESS(
329 LookupPortAndBindUDPSocket(&server_socket, &server_address));
330 ASSERT_SUBTEST_SUCCESS(
331 LookupPortAndBindUDPSocket(&client_socket, &client_address));
332 const std::string message = "Simple message that will be sent via UDP";
333 pp::NetAddress recvfrom_address;
334
335 const size_t kParallelSends = 10;
336 std::vector<TestCompletionCallback*> sendto_callbacks(kParallelSends);
337 std::vector<int32_t> sendto_results(kParallelSends);
338 size_t pending = 0;
339 for (size_t i = 0; i < kParallelSends; i++) {
340 sendto_callbacks[i] =
341 new TestCompletionCallback(instance_->pp_instance(), callback_type());
342 sendto_results[i] =
343 client_socket.SendTo(message.c_str(),
344 message.size(),
345 server_address,
346 sendto_callbacks[i]->GetCallback());
347
348 if (sendto_results[i] == PP_ERROR_INPROGRESS) {
349 // Run a pending send to completion to free a slot for the current send.
350 ASSERT_GT(i, pending);
351 sendto_callbacks[pending]->WaitForResult(sendto_results[pending]);
352 CHECK_CALLBACK_BEHAVIOR(*sendto_callbacks[pending]);
353 ASSERT_EQ(message.size(),
354 static_cast<size_t>(sendto_callbacks[pending]->result()));
355 pending++;
356 // Try to send the message again.
357 sendto_results[i] =
358 client_socket.SendTo(message.c_str(),
359 message.size(),
360 server_address,
361 sendto_callbacks[i]->GetCallback());
362 ASSERT_NE(PP_ERROR_INPROGRESS, sendto_results[i]);
363 }
364 }
365
366 // Finish all pending sends.
367 for (size_t i = pending; i < kParallelSends; i++) {
368 sendto_callbacks[i]->WaitForResult(sendto_results[i]);
369 CHECK_CALLBACK_BEHAVIOR(*sendto_callbacks[i]);
370 ASSERT_EQ(message.size(),
371 static_cast<size_t>(sendto_callbacks[i]->result()));
372 }
373
374 for (size_t i = 0; i < kParallelSends; ++i)
375 delete sendto_callbacks[i];
376
377 for (size_t i = 0; i < kParallelSends; i++) {
378 std::string str;
379 ASSERT_SUBTEST_SUCCESS(
380 ReadSocket(&server_socket, &recvfrom_address, message.size(), &str));
381 ASSERT_EQ(message, str);
382 }
383
384 server_socket.Close();
385 client_socket.Close();
386
387 PASS();
388 }
OLDNEW
« no previous file with comments | « ppapi/tests/test_udp_socket.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698