Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ppapi/tests/test_tcp_server_socket_private_disallowed.h" | |
| 6 | |
| 7 #include <cstddef> | |
| 8 | |
| 9 #include "ppapi/cpp/module.h" | |
| 10 #include "ppapi/cpp/private/net_address_private.h" | |
| 11 #include "ppapi/tests/test_utils.h" | |
| 12 #include "ppapi/tests/testing_instance.h" | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 const uint16_t kPortScanFrom = 1024; | |
| 17 const uint16_t kPortScanTo = 1280; | |
| 18 | |
| 19 } // namespace | |
| 20 | |
| 21 REGISTER_TEST_CASE(TCPServerSocketPrivateDisallowed); | |
| 22 | |
| 23 TestTCPServerSocketPrivateDisallowed::TestTCPServerSocketPrivateDisallowed( | |
| 24 TestingInstance* instance) | |
| 25 : TestCase(instance), tcp_server_socket_private_interface_(NULL) { | |
|
yzshen1
2012/02/29 19:21:09
Please also init core_interface_
ygorshenin1
2012/03/01 08:09:41
Done.
| |
| 26 } | |
| 27 | |
| 28 bool TestTCPServerSocketPrivateDisallowed::Init() { | |
| 29 core_interface_ = static_cast<const PPB_Core*>( | |
| 30 pp::Module::Get()->GetBrowserInterface(PPB_CORE_INTERFACE)); | |
| 31 if (!core_interface_) | |
| 32 instance_->AppendError("PPB_Core interface not available"); | |
| 33 | |
| 34 tcp_server_socket_private_interface_ = | |
| 35 static_cast<const PPB_TCPServerSocket_Private*>( | |
| 36 pp::Module::Get()->GetBrowserInterface( | |
| 37 PPB_TCPSERVERSOCKET_PRIVATE_INTERFACE)); | |
| 38 if (!tcp_server_socket_private_interface_) { | |
| 39 instance_->AppendError( | |
| 40 "PPB_TCPServerSocket_Private interface not available"); | |
| 41 } | |
| 42 | |
| 43 bool net_address_private_is_available = pp::NetAddressPrivate::IsAvailable(); | |
| 44 if (!net_address_private_is_available) | |
| 45 instance_->AppendError("PPB_NetAddress_Private interface not available"); | |
| 46 | |
| 47 return core_interface_ && | |
| 48 tcp_server_socket_private_interface_ && | |
| 49 net_address_private_is_available && | |
| 50 CheckTestingInterface(); | |
| 51 } | |
| 52 | |
| 53 void TestTCPServerSocketPrivateDisallowed::RunTests(const std::string& filter) { | |
| 54 RUN_TEST_FORCEASYNC_AND_NOT(Listen, filter); | |
| 55 } | |
| 56 | |
| 57 std::string TestTCPServerSocketPrivateDisallowed::TestListen() { | |
| 58 PP_Resource socket = | |
| 59 tcp_server_socket_private_interface_->Create(instance_->pp_instance()); | |
| 60 ASSERT_TRUE(socket != 0); | |
| 61 ASSERT_TRUE(tcp_server_socket_private_interface_->IsTCPServerSocket(socket)); | |
| 62 | |
| 63 PP_NetAddress_Private base_address, current_address; | |
| 64 pp::NetAddressPrivate::GetAnyAddress(false, &base_address); | |
| 65 | |
| 66 for (uint16_t port = kPortScanFrom; port < kPortScanTo; ++port) { | |
| 67 ASSERT_TRUE(pp::NetAddressPrivate::ReplacePort(base_address, | |
| 68 port, | |
| 69 ¤t_address)); | |
| 70 TestCompletionCallback callback(instance_->pp_instance(), force_async_); | |
| 71 int32_t rv = tcp_server_socket_private_interface_->Listen( | |
| 72 socket, | |
| 73 ¤t_address, | |
| 74 1, | |
| 75 static_cast<pp::CompletionCallback>( | |
| 76 callback).pp_completion_callback()); | |
| 77 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) | |
| 78 return ReportError("PPB_TCPServerSocket_Private::Listen force_async", rv); | |
| 79 if (rv == PP_OK_COMPLETIONPENDING) | |
| 80 rv = callback.WaitForResult(); | |
| 81 ASSERT_NE(PP_OK, rv); | |
| 82 } | |
| 83 | |
| 84 PASS(); | |
| 85 } | |
| OLD | NEW |