| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <string.h> | 5 #include <string.h> |
| 6 | 6 |
| 7 #include "ppapi/cpp/module.h" | 7 #include "ppapi/cpp/module.h" |
| 8 #include "ppapi/tests/test_udp_socket_private_shared.h" | 8 #include "ppapi/tests/test_udp_socket_private_shared.h" |
| 9 #include "ppapi/tests/test_utils.h" | 9 #include "ppapi/tests/test_utils.h" |
| 10 #include "ppapi/tests/testing_instance.h" | 10 #include "ppapi/tests/testing_instance.h" |
| 11 | 11 |
| 12 REGISTER_TEST_CASE(UDPSocketPrivateShared); | 12 REGISTER_TEST_CASE(UDPSocketPrivateShared); |
| 13 | 13 |
| 14 // TODO(ygorshenin): get rid of using external server in tests, | |
| 15 // http://crbug.com/105863 | |
| 16 const char* const TestUDPSocketPrivateShared::kHost = "www.google.com"; | |
| 17 | |
| 18 TestUDPSocketPrivateShared::TestUDPSocketPrivateShared( | 14 TestUDPSocketPrivateShared::TestUDPSocketPrivateShared( |
| 19 TestingInstance* instance) | 15 TestingInstance* instance) |
| 20 : TestCase(instance), | 16 : TestCase(instance), |
| 21 tcp_socket_private_interface_(NULL), | 17 tcp_socket_private_interface_(NULL), |
| 22 udp_socket_private_interface_(NULL) { | 18 udp_socket_private_interface_(NULL) { |
| 23 } | 19 } |
| 24 | 20 |
| 25 bool TestUDPSocketPrivateShared::Init() { | 21 bool TestUDPSocketPrivateShared::Init() { |
| 26 tcp_socket_private_interface_ = | 22 tcp_socket_private_interface_ = |
| 27 reinterpret_cast<PPB_TCPSocket_Private const*>( | 23 reinterpret_cast<PPB_TCPSocket_Private const*>( |
| 28 pp::Module::Get()->GetBrowserInterface( | 24 pp::Module::Get()->GetBrowserInterface( |
| 29 PPB_TCPSOCKET_PRIVATE_INTERFACE)); | 25 PPB_TCPSOCKET_PRIVATE_INTERFACE)); |
| 30 if (!tcp_socket_private_interface_) | 26 if (!tcp_socket_private_interface_) |
| 31 instance_->AppendError("TCPSocketPrivate interface not available"); | 27 instance_->AppendError("TCPSocketPrivate interface not available"); |
| 32 | 28 |
| 33 udp_socket_private_interface_ = | 29 udp_socket_private_interface_ = |
| 34 reinterpret_cast<PPB_UDPSocket_Private const*>( | 30 reinterpret_cast<PPB_UDPSocket_Private const*>( |
| 35 pp::Module::Get()->GetBrowserInterface( | 31 pp::Module::Get()->GetBrowserInterface( |
| 36 PPB_UDPSOCKET_PRIVATE_INTERFACE)); | 32 PPB_UDPSOCKET_PRIVATE_INTERFACE)); |
| 37 if (!udp_socket_private_interface_) | 33 if (!udp_socket_private_interface_) |
| 38 instance_->AppendError("UDPSocketPrivate interface not available"); | 34 instance_->AppendError("UDPSocketPrivate interface not available"); |
| 39 | 35 |
| 40 return tcp_socket_private_interface_ && udp_socket_private_interface_ && | 36 bool init_host_port = false; |
| 37 if (!GetLocalHostPort(instance_->pp_instance(), &host_, &port_)) |
| 38 instance_->AppendError("Can't init host and port"); |
| 39 else |
| 40 init_host_port = true; |
| 41 |
| 42 return tcp_socket_private_interface_ && |
| 43 udp_socket_private_interface_ && |
| 44 init_host_port && |
| 41 InitTestingInterface(); | 45 InitTestingInterface(); |
| 42 } | 46 } |
| 43 | 47 |
| 44 void TestUDPSocketPrivateShared::RunTests(const std::string& filter) { | 48 void TestUDPSocketPrivateShared::RunTests(const std::string& filter) { |
| 45 RUN_TEST(Create, filter); | 49 RUN_TEST(Create, filter); |
| 46 RUN_TEST_FORCEASYNC_AND_NOT(Connect, filter); | 50 RUN_TEST_FORCEASYNC_AND_NOT(Connect, filter); |
| 47 } | 51 } |
| 48 | 52 |
| 49 void TestUDPSocketPrivateShared::QuitMessageLoop() { | 53 void TestUDPSocketPrivateShared::QuitMessageLoop() { |
| 50 testing_interface_->QuitMessageLoop(instance_->pp_instance()); | 54 testing_interface_->QuitMessageLoop(instance_->pp_instance()); |
| 51 } | 55 } |
| 52 | 56 |
| 53 std::string TestUDPSocketPrivateShared::GenerateNetAddress( | 57 std::string TestUDPSocketPrivateShared::GenerateNetAddress( |
| 54 PP_Resource* socket, PP_NetAddress_Private* address) { | 58 PP_Resource* socket, PP_NetAddress_Private* address) { |
| 55 *socket = tcp_socket_private_interface_->Create(instance_->pp_instance()); | 59 *socket = tcp_socket_private_interface_->Create(instance_->pp_instance()); |
| 56 if (0 == *socket) | 60 if (0 == *socket) |
| 57 return "PPB_TCPSocket_Private::Create failed"; | 61 return "PPB_TCPSocket_Private::Create failed"; |
| 58 | 62 |
| 59 TestCompletionCallback callback(instance_->pp_instance(), force_async_); | 63 TestCompletionCallback callback(instance_->pp_instance(), force_async_); |
| 60 int32_t rv = tcp_socket_private_interface_->Connect( | 64 int32_t rv = tcp_socket_private_interface_->Connect( |
| 61 *socket, kHost, kPort, | 65 *socket, host_.c_str(), port_, |
| 62 static_cast<pp::CompletionCallback>(callback).pp_completion_callback()); | 66 static_cast<pp::CompletionCallback>(callback).pp_completion_callback()); |
| 63 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) | 67 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 64 return ReportError("PPB_TCPSocket_Private::Connect force_async", rv); | 68 return ReportError("PPB_TCPSocket_Private::Connect force_async", rv); |
| 65 if (rv == PP_OK_COMPLETIONPENDING) | 69 if (rv == PP_OK_COMPLETIONPENDING) |
| 66 rv = callback.WaitForResult(); | 70 rv = callback.WaitForResult(); |
| 67 if (rv != PP_OK) | 71 if (rv != PP_OK) |
| 68 return ReportError("PPB_TCPSocket_Private::Connect", rv); | 72 return ReportError("PPB_TCPSocket_Private::Connect", rv); |
| 69 | 73 |
| 70 rv = tcp_socket_private_interface_->GetLocalAddress(*socket, address); | 74 rv = tcp_socket_private_interface_->GetLocalAddress(*socket, address); |
| 71 if (rv != PP_TRUE) | 75 if (rv != PP_TRUE) |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 ASSERT_EQ(0, strncmp(kMessage, message_buffer, strlen(kMessage))); | 177 ASSERT_EQ(0, strncmp(kMessage, message_buffer, strlen(kMessage))); |
| 174 | 178 |
| 175 udp_socket_private_interface_->Close(socket_server); | 179 udp_socket_private_interface_->Close(socket_server); |
| 176 udp_socket_private_interface_->Close(socket_client); | 180 udp_socket_private_interface_->Close(socket_client); |
| 177 | 181 |
| 178 tcp_socket_private_interface_->Disconnect(tcp_socket_server); | 182 tcp_socket_private_interface_->Disconnect(tcp_socket_server); |
| 179 tcp_socket_private_interface_->Disconnect(tcp_socket_client); | 183 tcp_socket_private_interface_->Disconnect(tcp_socket_client); |
| 180 | 184 |
| 181 PASS(); | 185 PASS(); |
| 182 } | 186 } |
| OLD | NEW |