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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ppapi/tests/test_udp_socket.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/tests/test_udp_socket.cc
diff --git a/ppapi/tests/test_udp_socket.cc b/ppapi/tests/test_udp_socket.cc
index 8972e4e94385efc53fc5e3112dca417ddc4e7623..2b0568244e30001b37e5670f41a4799e733e7af6 100644
--- a/ppapi/tests/test_udp_socket.cc
+++ b/ppapi/tests/test_udp_socket.cc
@@ -83,6 +83,7 @@ void TestUDPSocket::RunTests(const std::string& filter) {
RUN_CALLBACK_TEST(TestUDPSocket, ReadWrite, filter);
RUN_CALLBACK_TEST(TestUDPSocket, Broadcast, filter);
RUN_CALLBACK_TEST(TestUDPSocket, SetOption, filter);
+ RUN_CALLBACK_TEST(TestUDPSocket, ParallelSend, filter);
}
std::string TestUDPSocket::GetLocalAddress(pp::NetAddress* address) {
@@ -315,3 +316,73 @@ std::string TestUDPSocket::TestSetOption() {
PASS();
}
+
+std::string TestUDPSocket::TestParallelSend() {
+ // This test only makes sense when callbacks are optional.
+ if (callback_type() != PP_OPTIONAL)
+ PASS();
+
+ pp::UDPSocket server_socket(instance_), client_socket(instance_);
+ pp::NetAddress server_address, client_address;
+
+ ASSERT_SUBTEST_SUCCESS(
+ LookupPortAndBindUDPSocket(&server_socket, &server_address));
+ ASSERT_SUBTEST_SUCCESS(
+ LookupPortAndBindUDPSocket(&client_socket, &client_address));
+ const std::string message = "Simple message that will be sent via UDP";
+ pp::NetAddress recvfrom_address;
+
+ const size_t kParallelSends = 10;
+ std::vector<TestCompletionCallback*> sendto_callbacks(kParallelSends);
+ std::vector<int32_t> sendto_results(kParallelSends);
+ size_t pending = 0;
+ for (size_t i = 0; i < kParallelSends; i++) {
+ sendto_callbacks[i] =
+ new TestCompletionCallback(instance_->pp_instance(), callback_type());
+ sendto_results[i] =
+ client_socket.SendTo(message.c_str(),
+ message.size(),
+ server_address,
+ sendto_callbacks[i]->GetCallback());
+
+ if (sendto_results[i] == PP_ERROR_INPROGRESS) {
+ // Run a pending send to completion to free a slot for the current send.
+ ASSERT_GT(i, pending);
+ sendto_callbacks[pending]->WaitForResult(sendto_results[pending]);
+ CHECK_CALLBACK_BEHAVIOR(*sendto_callbacks[pending]);
+ ASSERT_EQ(message.size(),
+ static_cast<size_t>(sendto_callbacks[pending]->result()));
+ pending++;
+ // Try to send the message again.
+ sendto_results[i] =
+ client_socket.SendTo(message.c_str(),
+ message.size(),
+ server_address,
+ sendto_callbacks[i]->GetCallback());
+ ASSERT_NE(PP_ERROR_INPROGRESS, sendto_results[i]);
+ }
+ }
+
+ // Finish all pending sends.
+ for (size_t i = pending; i < kParallelSends; i++) {
+ sendto_callbacks[i]->WaitForResult(sendto_results[i]);
+ CHECK_CALLBACK_BEHAVIOR(*sendto_callbacks[i]);
+ ASSERT_EQ(message.size(),
+ static_cast<size_t>(sendto_callbacks[i]->result()));
+ }
+
+ for (size_t i = 0; i < kParallelSends; ++i)
+ delete sendto_callbacks[i];
+
+ for (size_t i = 0; i < kParallelSends; i++) {
+ std::string str;
+ ASSERT_SUBTEST_SUCCESS(
+ ReadSocket(&server_socket, &recvfrom_address, message.size(), &str));
+ ASSERT_EQ(message, str);
+ }
+
+ server_socket.Close();
+ client_socket.Close();
+
+ PASS();
+}
« 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