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