| 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 "ppapi/tests/test_udp_socket_private_disallowed.h" | 5 #include "ppapi/tests/test_udp_socket_private_disallowed.h" |
| 6 | 6 |
| 7 #include "ppapi/cpp/module.h" | 7 #include "ppapi/cpp/module.h" |
| 8 #include "ppapi/cpp/private/net_address_private.h" |
| 8 #include "ppapi/tests/testing_instance.h" | 9 #include "ppapi/tests/testing_instance.h" |
| 10 #include "ppapi/tests/test_utils.h" |
| 9 | 11 |
| 10 REGISTER_TEST_CASE(UDPSocketPrivateDisallowed); | 12 REGISTER_TEST_CASE(UDPSocketPrivateDisallowed); |
| 11 | 13 |
| 12 TestUDPSocketPrivateDisallowed::TestUDPSocketPrivateDisallowed( | 14 TestUDPSocketPrivateDisallowed::TestUDPSocketPrivateDisallowed( |
| 13 TestingInstance* instance) | 15 TestingInstance* instance) |
| 14 : TestCase(instance), udp_socket_private_interface_(NULL) { | 16 : TestCase(instance), udp_socket_private_interface_(NULL) { |
| 15 } | 17 } |
| 16 | 18 |
| 17 bool TestUDPSocketPrivateDisallowed::Init() { | 19 bool TestUDPSocketPrivateDisallowed::Init() { |
| 18 udp_socket_private_interface_ = static_cast<const PPB_UDPSocket_Private*>( | 20 udp_socket_private_interface_ = static_cast<const PPB_UDPSocket_Private*>( |
| 19 pp::Module::Get()->GetBrowserInterface(PPB_UDPSOCKET_PRIVATE_INTERFACE)); | 21 pp::Module::Get()->GetBrowserInterface(PPB_UDPSOCKET_PRIVATE_INTERFACE)); |
| 20 if (!udp_socket_private_interface_) | 22 if (!udp_socket_private_interface_) |
| 21 instance_->AppendError("UDPSocketPrivate interface not available"); | 23 instance_->AppendError("UDPSocketPrivate interface not available"); |
| 22 return udp_socket_private_interface_ && CheckTestingInterface(); | 24 return udp_socket_private_interface_ && CheckTestingInterface(); |
| 23 } | 25 } |
| 24 | 26 |
| 25 void TestUDPSocketPrivateDisallowed::RunTests(const std::string& filter) { | 27 void TestUDPSocketPrivateDisallowed::RunTests(const std::string& filter) { |
| 26 RUN_TEST(Create, filter); | 28 RUN_TEST(Bind, filter); |
| 27 } | 29 } |
| 28 | 30 |
| 29 std::string TestUDPSocketPrivateDisallowed::TestCreate() { | 31 std::string TestUDPSocketPrivateDisallowed::TestBind() { |
| 30 PP_Resource socket = | 32 PP_Resource socket = |
| 31 udp_socket_private_interface_->Create(instance_->pp_instance()); | 33 udp_socket_private_interface_->Create(instance_->pp_instance()); |
| 32 if (0 != socket) { | 34 if (0 != socket) { |
| 33 return "PPB_UDPSocket_Private::Create returns valid socket " \ | 35 PP_NetAddress_Private addr; |
| 34 "without allowing switch"; | 36 pp::NetAddressPrivate::GetAnyAddress(false, &addr); |
| 37 |
| 38 TestCompletionCallback callback(instance_->pp_instance()); |
| 39 int32_t rv = udp_socket_private_interface_->Bind(socket, &addr, |
| 40 static_cast<pp::CompletionCallback>(callback).pp_completion_callback()); |
| 41 |
| 42 if (PP_OK_COMPLETIONPENDING == rv) |
| 43 rv = callback.WaitForResult(); |
| 44 |
| 45 if (PP_ERROR_FAILED != rv) |
| 46 return "PPB_UDPSocket_Private can bind without allowing switch"; |
| 35 } | 47 } |
| 36 PASS(); | 48 PASS(); |
| 37 } | 49 } |
| OLD | NEW |