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

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: Add a separate test for parallel SendTo. 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 side-by-side diff with in-line comments
Download patch
Index: ppapi/tests/test_udp_socket.cc
diff --git a/ppapi/tests/test_udp_socket.cc b/ppapi/tests/test_udp_socket.cc
index e0b76f47728b3ae9100378f9f5fe42b57ebdeb30..4e7c07572daa65cacb3e1c16bccfbab7b9503382 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) {
@@ -316,3 +317,71 @@ std::string TestUDPSocket::TestSetOption() {
PASS();
}
+
+std::string TestUDPSocket::TestParallelSend() {
+ // This test only makes sense when callbacks are optional.
+ if (callback_type() == PP_OPTIONAL) {
dmichael (off chromium) 2014/10/08 17:20:46 Maybe it would be cleaner to do: if (callback_type
bbudge 2014/10/08 21:44:35 Done.
+ 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());
+
+ while (sendto_results[i] == PP_ERROR_INPROGRESS) {
+ // Run pending sends to completion until we can send successfully.
+ 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());
dmichael (off chromium) 2014/10/08 17:20:46 At this point, I don't think sendto_results[i] sho
bbudge 2014/10/08 21:44:35 OK, I think it's probably good to constrain this b
+ }
+ }
+
+ // 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();
+}

Powered by Google App Engine
This is Rietveld 408576698