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

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: Review comments, document INPROGRESS error in IDL. Created 6 years, 2 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
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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 ASSERT_EQ(PP_OK, callback.result()); 310 ASSERT_EQ(PP_OK, callback.result());
310 311
311 callback.WaitForResult(socket.SetOption( 312 callback.WaitForResult(socket.SetOption(
312 PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE, pp::Var(1024), 313 PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE, pp::Var(1024),
313 callback.GetCallback())); 314 callback.GetCallback()));
314 CHECK_CALLBACK_BEHAVIOR(callback); 315 CHECK_CALLBACK_BEHAVIOR(callback);
315 ASSERT_EQ(PP_OK, callback.result()); 316 ASSERT_EQ(PP_OK, callback.result());
316 317
317 PASS(); 318 PASS();
318 } 319 }
320
321 std::string TestUDPSocket::TestParallelSend() {
322 // This test only makes sense when callbacks are optional.
323 if (callback_type() != PP_OPTIONAL)
324 PASS();
325
326 pp::UDPSocket server_socket(instance_), client_socket(instance_);
327 pp::NetAddress server_address, client_address;
328
329 ASSERT_SUBTEST_SUCCESS(
330 LookupPortAndBindUDPSocket(&server_socket, &server_address));
331 ASSERT_SUBTEST_SUCCESS(
332 LookupPortAndBindUDPSocket(&client_socket, &client_address));
333 const std::string message = "Simple message that will be sent via UDP";
334 pp::NetAddress recvfrom_address;
335
336 const size_t kParallelSends = 10;
337 std::vector<TestCompletionCallback*> sendto_callbacks(kParallelSends);
338 std::vector<int32_t> sendto_results(kParallelSends);
339 size_t pending = 0;
340 for (size_t i = 0; i < kParallelSends; i++) {
341 sendto_callbacks[i] =
342 new TestCompletionCallback(instance_->pp_instance(), callback_type());
343 sendto_results[i] =
344 client_socket.SendTo(message.c_str(),
345 message.size(),
346 server_address,
347 sendto_callbacks[i]->GetCallback());
348
349 if (sendto_results[i] == PP_ERROR_INPROGRESS) {
350 // Run a pending send to completion to free a slot for the current send.
351 ASSERT_GT(i, pending);
352 sendto_callbacks[pending]->WaitForResult(sendto_results[pending]);
353 CHECK_CALLBACK_BEHAVIOR(*sendto_callbacks[pending]);
354 ASSERT_EQ(message.size(),
355 static_cast<size_t>(sendto_callbacks[pending]->result()));
356 pending++;
357 // Try to send the message again.
358 sendto_results[i] =
359 client_socket.SendTo(message.c_str(),
360 message.size(),
361 server_address,
362 sendto_callbacks[i]->GetCallback());
363 ASSERT_NE(PP_ERROR_INPROGRESS, sendto_results[i]);
364 }
365 }
366
367 // Finish all pending sends.
368 for (size_t i = pending; i < kParallelSends; i++) {
369 sendto_callbacks[i]->WaitForResult(sendto_results[i]);
370 CHECK_CALLBACK_BEHAVIOR(*sendto_callbacks[i]);
371 ASSERT_EQ(message.size(),
372 static_cast<size_t>(sendto_callbacks[i]->result()));
373 }
374
375 for (size_t i = 0; i < kParallelSends; ++i)
376 delete sendto_callbacks[i];
377
378 for (size_t i = 0; i < kParallelSends; i++) {
379 std::string str;
380 ASSERT_SUBTEST_SUCCESS(
381 ReadSocket(&server_socket, &recvfrom_address, message.size(), &str));
382 ASSERT_EQ(message, str);
383 }
384
385 server_socket.Close();
386 client_socket.Close();
387
388 PASS();
389 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698