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.
5 #include "ppapi/tests/test_tcp_server_socket_private_disallowed.h"
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"
16 const uint16_t kPortScanFrom
= 1024;
17 const uint16_t kPortScanTo
= 1280;
21 REGISTER_TEST_CASE(TCPServerSocketPrivateDisallowed
);
23 TestTCPServerSocketPrivateDisallowed::TestTCPServerSocketPrivateDisallowed(
24 TestingInstance
* instance
)
26 core_interface_(NULL
),
27 tcp_server_socket_private_interface_(NULL
) {
30 bool TestTCPServerSocketPrivateDisallowed::Init() {
31 core_interface_
= static_cast<const PPB_Core
*>(
32 pp::Module::Get()->GetBrowserInterface(PPB_CORE_INTERFACE
));
34 instance_
->AppendError("PPB_Core interface not available");
36 tcp_server_socket_private_interface_
=
37 static_cast<const PPB_TCPServerSocket_Private
*>(
38 pp::Module::Get()->GetBrowserInterface(
39 PPB_TCPSERVERSOCKET_PRIVATE_INTERFACE
));
40 if (!tcp_server_socket_private_interface_
) {
41 instance_
->AppendError(
42 "PPB_TCPServerSocket_Private interface not available");
45 bool net_address_private_is_available
= pp::NetAddressPrivate::IsAvailable();
46 if (!net_address_private_is_available
)
47 instance_
->AppendError("PPB_NetAddress_Private interface not available");
49 return core_interface_
&&
50 tcp_server_socket_private_interface_
&&
51 net_address_private_is_available
&&
52 CheckTestingInterface();
55 void TestTCPServerSocketPrivateDisallowed::RunTests(const std::string
& filter
) {
56 RUN_CALLBACK_TEST(TestTCPServerSocketPrivateDisallowed
, Listen
, filter
);
59 std::string
TestTCPServerSocketPrivateDisallowed::TestListen() {
61 tcp_server_socket_private_interface_
->Create(instance_
->pp_instance());
62 ASSERT_TRUE(socket
!= 0);
63 ASSERT_TRUE(tcp_server_socket_private_interface_
->IsTCPServerSocket(socket
));
65 PP_NetAddress_Private base_address
, address
;
66 pp::NetAddressPrivate::GetAnyAddress(false, &base_address
);
67 ASSERT_TRUE(pp::NetAddressPrivate::ReplacePort(
68 base_address
, 0, &address
));
69 TestCompletionCallback
callback(instance_
->pp_instance());
70 callback
.WaitForResult(tcp_server_socket_private_interface_
->Listen(
74 callback
.GetCallback().pp_completion_callback()));
75 CHECK_CALLBACK_BEHAVIOR(callback
);
76 ASSERT_NE(PP_OK
, callback
.result());