| 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_tcp_socket_private_disallowed.h" | 5 #include "ppapi/tests/test_tcp_socket_private_disallowed.h" |
| 6 | 6 |
| 7 #include "ppapi/cpp/module.h" | 7 #include "ppapi/cpp/module.h" |
| 8 #include "ppapi/tests/test_utils.h" |
| 8 #include "ppapi/tests/testing_instance.h" | 9 #include "ppapi/tests/testing_instance.h" |
| 9 | 10 |
| 11 namespace { |
| 12 |
| 13 const char kServerName[] = "www.google.com"; |
| 14 const int kPort = 80; |
| 15 |
| 16 } |
| 17 |
| 10 REGISTER_TEST_CASE(TCPSocketPrivateDisallowed); | 18 REGISTER_TEST_CASE(TCPSocketPrivateDisallowed); |
| 11 | 19 |
| 12 TestTCPSocketPrivateDisallowed::TestTCPSocketPrivateDisallowed( | 20 TestTCPSocketPrivateDisallowed::TestTCPSocketPrivateDisallowed( |
| 13 TestingInstance* instance) | 21 TestingInstance* instance) |
| 14 : TestCase(instance), tcp_socket_private_interface_(NULL) { | 22 : TestCase(instance), tcp_socket_private_interface_(NULL) { |
| 15 } | 23 } |
| 16 | 24 |
| 17 bool TestTCPSocketPrivateDisallowed::Init() { | 25 bool TestTCPSocketPrivateDisallowed::Init() { |
| 18 tcp_socket_private_interface_ = static_cast<const PPB_TCPSocket_Private*>( | 26 tcp_socket_private_interface_ = static_cast<const PPB_TCPSocket_Private*>( |
| 19 pp::Module::Get()->GetBrowserInterface(PPB_TCPSOCKET_PRIVATE_INTERFACE)); | 27 pp::Module::Get()->GetBrowserInterface(PPB_TCPSOCKET_PRIVATE_INTERFACE)); |
| 20 if (!tcp_socket_private_interface_) | 28 if (!tcp_socket_private_interface_) |
| 21 instance_->AppendError("TCPSocketPrivate interface not available"); | 29 instance_->AppendError("TCPSocketPrivate interface not available"); |
| 22 return tcp_socket_private_interface_ && CheckTestingInterface(); | 30 return tcp_socket_private_interface_ && CheckTestingInterface(); |
| 23 } | 31 } |
| 24 | 32 |
| 25 void TestTCPSocketPrivateDisallowed::RunTests(const std::string& filter) { | 33 void TestTCPSocketPrivateDisallowed::RunTests(const std::string& filter) { |
| 26 RUN_TEST(Create, filter); | 34 RUN_TEST(Connect, filter); |
| 27 } | 35 } |
| 28 | 36 |
| 29 std::string TestTCPSocketPrivateDisallowed::TestCreate() { | 37 std::string TestTCPSocketPrivateDisallowed::TestConnect() { |
| 30 PP_Resource socket = | 38 PP_Resource socket = |
| 31 tcp_socket_private_interface_->Create(instance_->pp_instance()); | 39 tcp_socket_private_interface_->Create(instance_->pp_instance()); |
| 32 if (0 != socket) { | 40 if (0 != socket) { |
| 33 return "PPB_TCPSocket_Private::Create returns valid socket " \ | 41 TestCompletionCallback callback(instance_->pp_instance()); |
| 34 "without allowing switch"; | 42 int32_t rv = tcp_socket_private_interface_->Connect( |
| 43 socket, kServerName, kPort, |
| 44 static_cast<pp::CompletionCallback>(callback).pp_completion_callback()); |
| 45 |
| 46 if (PP_OK_COMPLETIONPENDING == rv) |
| 47 rv = callback.WaitForResult(); |
| 48 |
| 49 if (PP_ERROR_FAILED != rv) |
| 50 return "PPB_TCPSocket_Private can connect without allowing switch"; |
| 35 } | 51 } |
| 36 PASS(); | 52 PASS(); |
| 37 } | 53 } |
| OLD | NEW |