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

Unified Diff: ppapi/tests/test_udp_socket.cc

Issue 704133005: Pepper: Add support for multicast in PPB_UDPSocket API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unit tests, thunk code auto generated Created 5 years, 10 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 89ea0363a95be9ff6a4021a00232ccbc8ee1a8bd..9a7a279d907c123222eb804d1e1c8b2db3b20f5f 100644
--- a/ppapi/tests/test_udp_socket.cc
+++ b/ppapi/tests/test_udp_socket.cc
@@ -47,7 +47,11 @@ pp::NetAddress ReplacePort(const pp::InstanceHandle& instance,
} // namespace
-TestUDPSocket::TestUDPSocket(TestingInstance* instance) : TestCase(instance) {
+TestUDPSocket::TestUDPSocket(TestingInstance* instance)
+ : TestCase(instance),
+ socket_interface_1_0_(NULL),
+ socket_interface_1_1_(NULL),
+ has_interface_1_2_(false) {
}
bool TestUDPSocket::Init() {
@@ -71,19 +75,41 @@ bool TestUDPSocket::Init() {
if (!init_address)
instance_->AppendError("Can't init address");
+ socket_interface_1_0_ =
+ static_cast<const PPB_UDPSocket_1_0*>(
+ pp::Module::Get()->GetBrowserInterface(PPB_UDPSOCKET_INTERFACE_1_0));
+ if (!socket_interface_1_0_)
+ instance_->AppendError("PPB_UDPSocket_1_0 interface not available");
+
+ socket_interface_1_1_ =
+ static_cast<const PPB_UDPSocket_1_1*>(
+ pp::Module::Get()->GetBrowserInterface(PPB_UDPSOCKET_INTERFACE_1_1));
+ if (!socket_interface_1_1_)
+ instance_->AppendError("PPB_UDPSocket_1_1 interface not available");
+
+ const PPB_UDPSocket_1_2* iface_1_2 =
+ static_cast<const PPB_UDPSocket_1_2*>(
+ pp::Module::Get()->GetBrowserInterface(PPB_UDPSOCKET_INTERFACE_1_2));
+ has_interface_1_2_ = iface_1_2 != NULL;
+
etrunko 2015/02/23 22:22:15 I did not find an easier way to check for specific
bbudge 2015/03/02 16:03:08 This is fine. You don't need to test for 1.2 thoug
return tcp_socket_is_available &&
udp_socket_is_available &&
net_address_is_available &&
init_address &&
CheckTestingInterface() &&
- EnsureRunningOverHTTP();
+ EnsureRunningOverHTTP() &&
+ socket_interface_1_0_ != NULL &&
+ socket_interface_1_1_ != NULL;
}
void TestUDPSocket::RunTests(const std::string& filter) {
RUN_CALLBACK_TEST(TestUDPSocket, ReadWrite, filter);
RUN_CALLBACK_TEST(TestUDPSocket, Broadcast, filter);
+ RUN_CALLBACK_TEST(TestUDPSocket, SetOption_1_0, filter);
+ RUN_CALLBACK_TEST(TestUDPSocket, SetOption_1_1, filter);
RUN_CALLBACK_TEST(TestUDPSocket, SetOption, filter);
RUN_CALLBACK_TEST(TestUDPSocket, ParallelSend, filter);
+ RUN_CALLBACK_TEST(TestUDPSocket, Multicast, filter);
}
std::string TestUDPSocket::GetLocalAddress(pp::NetAddress* address) {
@@ -188,6 +214,24 @@ std::string TestUDPSocket::PassMessage(pp::UDPSocket* target,
PASS();
}
+std::string TestUDPSocket::SetMulticastOptions(pp::UDPSocket* socket) {
+ int32_t expected = has_interface_1_2_ ? PP_OK : PP_ERROR_BADARGUMENT;
+
+ TestCompletionCallback callback(instance_->pp_instance(), callback_type());
+ callback.WaitForResult(socket->SetOption(
+ PP_UDPSOCKET_OPTION_MULTICAST_LOOP, pp::Var(true),
+ callback.GetCallback()));
+ CHECK_CALLBACK_BEHAVIOR(callback);
+ ASSERT_EQ(expected, callback.result());
+
+ callback.WaitForResult(socket->SetOption(
+ PP_UDPSOCKET_OPTION_MULTICAST_TTL, pp::Var(1), callback.GetCallback()));
+ CHECK_CALLBACK_BEHAVIOR(callback);
+ ASSERT_EQ(expected, callback.result());
+
+ PASS();
+}
+
std::string TestUDPSocket::TestReadWrite() {
pp::UDPSocket server_socket(instance_), client_socket(instance_);
pp::NetAddress server_address, client_address;
@@ -258,10 +302,77 @@ std::string TestUDPSocket::TestBroadcast() {
PASS();
}
+int32_t TestUDPSocket::SetOptionValue(UDPSocketSetOption func,
+ PP_Resource socket,
+ PP_UDPSocket_Option option,
+ struct PP_Var value) {
+ PP_TimeTicks start_time(NowInTimeTicks());
+ TestCompletionCallback cb(instance_->pp_instance(), callback_type());
+ cb.WaitForResult(func(socket, option, value,
+ cb.GetCallback().pp_completion_callback()));
+
+ // Expanded from CHECK_CALLBACK_BEHAVIOR macro.
+ if (cb.failed()) {
+ std::string msg = MakeFailureMessage(__FILE__, __LINE__,
+ cb.errors().c_str());
+
+ instance_->LogTest("SetOptionValue", msg, start_time);
+ return PP_ERROR_FAILED;
+ }
+ return cb.result();
+}
+
+std::string TestUDPSocket::TestSetOption_1_0() {
+ PP_Resource socket = socket_interface_1_0_->Create(instance_->pp_instance());
+ ASSERT_NE(0, socket);
+
+ // Multicast options are not supported in interface 1.0.
+ ASSERT_EQ(PP_ERROR_BADARGUMENT,
+ SetOptionValue(socket_interface_1_0_->SetOption,
+ socket,
+ PP_UDPSOCKET_OPTION_MULTICAST_LOOP,
+ PP_MakeBool(PP_FromBool(true))));
+
+ ASSERT_EQ(PP_ERROR_BADARGUMENT,
+ SetOptionValue(socket_interface_1_0_->SetOption,
+ socket,
+ PP_UDPSOCKET_OPTION_MULTICAST_TTL,
+ PP_MakeInt32(1)));
+
+ socket_interface_1_0_->Close(socket);
+ pp::Module::Get()->core()->ReleaseResource(socket);
+
+ PASS();
+}
+
+std::string TestUDPSocket::TestSetOption_1_1() {
+ PP_Resource socket = socket_interface_1_1_->Create(instance_->pp_instance());
+ ASSERT_NE(0, socket);
+
+ // Multicast options are not supported in interface 1.1.
+ ASSERT_EQ(PP_ERROR_BADARGUMENT,
+ SetOptionValue(socket_interface_1_1_->SetOption,
+ socket,
+ PP_UDPSOCKET_OPTION_MULTICAST_LOOP,
+ PP_MakeBool(PP_FromBool(true))));
+
+ ASSERT_EQ(PP_ERROR_BADARGUMENT,
+ SetOptionValue(socket_interface_1_1_->SetOption,
+ socket,
+ PP_UDPSOCKET_OPTION_MULTICAST_TTL,
+ PP_MakeInt32(1)));
+
+ socket_interface_1_1_->Close(socket);
+ pp::Module::Get()->core()->ReleaseResource(socket);
+
+ PASS();
+}
+
std::string TestUDPSocket::TestSetOption() {
pp::UDPSocket socket(instance_);
ASSERT_SUBTEST_SUCCESS(SetBroadcastOptions(&socket));
+ ASSERT_SUBTEST_SUCCESS(SetMulticastOptions(&socket));
// Try to pass incorrect option value's type.
TestCompletionCallback callback(instance_->pp_instance(), callback_type());
@@ -270,6 +381,17 @@ std::string TestUDPSocket::TestSetOption() {
CHECK_CALLBACK_BEHAVIOR(callback);
ASSERT_EQ(PP_ERROR_BADARGUMENT, callback.result());
+ // Invalid multicast TTL values (less than 0 and greater than 255).
+ callback.WaitForResult(socket.SetOption(
+ PP_UDPSOCKET_OPTION_MULTICAST_TTL, pp::Var(-1), callback.GetCallback()));
+ CHECK_CALLBACK_BEHAVIOR(callback);
+ ASSERT_EQ(PP_ERROR_BADARGUMENT, callback.result());
+
+ callback.WaitForResult(socket.SetOption(
+ PP_UDPSOCKET_OPTION_MULTICAST_TTL, pp::Var(256), callback.GetCallback()));
+ CHECK_CALLBACK_BEHAVIOR(callback);
+ ASSERT_EQ(PP_ERROR_BADARGUMENT, callback.result());
+
callback.WaitForResult(socket.SetOption(
PP_UDPSOCKET_OPTION_BROADCAST, pp::Var(false), callback.GetCallback()));
CHECK_CALLBACK_BEHAVIOR(callback);
@@ -388,3 +510,17 @@ std::string TestUDPSocket::TestParallelSend() {
PASS();
}
+
+std::string TestUDPSocket::TestMulticast() {
+ pp::UDPSocket server1(instance_), server2(instance_);
+
+ ASSERT_SUBTEST_SUCCESS(SetMulticastOptions(&server1));
+ ASSERT_SUBTEST_SUCCESS(SetMulticastOptions(&server2));
+
+ server1.Close();
+ server2.Close();
+
+ if (!has_interface_1_2_)
+ PASS();
etrunko 2015/02/23 22:22:15 Again, if there is a better way to check for inter
bbudge 2015/03/02 16:03:08 You don't have to check for 1.2 (see comment above
+ PASS();
+}

Powered by Google App Engine
This is Rietveld 408576698