summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
authorygorshenin@chromium.org <ygorshenin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-11 11:07:12 +0000
committerygorshenin@chromium.org <ygorshenin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-11 11:07:12 +0000
commit50da420e19f5039a441126440273cc36f132e1b6 (patch)
tree2cfe2c263a9ae104e87806a6b3ed220b98650c23 /ppapi
parent28ab28774f9add97332ab1f702c1bdab834f767e (diff)
downloadchromium_src-50da420e19f5039a441126440273cc36f132e1b6.zip
chromium_src-50da420e19f5039a441126440273cc36f132e1b6.tar.gz
chromium_src-50da420e19f5039a441126440273cc36f132e1b6.tar.bz2
Added test for disallowed tcp server socket API.
BUG= TEST=PPAPINaClTestDisallowedSockets.TCPServerSocketPrivateDisallowed Review URL: http://codereview.chromium.org/9491007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126068 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r--ppapi/ppapi_sources.gypi1
-rw-r--r--ppapi/tests/test_tcp_server_socket_private_disallowed.cc87
-rw-r--r--ppapi/tests/test_tcp_server_socket_private_disallowed.h30
3 files changed, 118 insertions, 0 deletions
diff --git a/ppapi/ppapi_sources.gypi b/ppapi/ppapi_sources.gypi
index 498f2f4..20d093e 100644
--- a/ppapi/ppapi_sources.gypi
+++ b/ppapi/ppapi_sources.gypi
@@ -335,6 +335,7 @@
'tests/test_paint_aggregator.cc',
'tests/test_post_message.cc',
'tests/test_scrollbar.cc',
+ 'tests/test_tcp_server_socket_private_disallowed.cc',
'tests/test_tcp_socket_private_disallowed.cc',
'tests/test_udp_socket_private_disallowed.cc',
'tests/test_url_loader.cc',
diff --git a/ppapi/tests/test_tcp_server_socket_private_disallowed.cc b/ppapi/tests/test_tcp_server_socket_private_disallowed.cc
new file mode 100644
index 0000000..86036d7
--- /dev/null
+++ b/ppapi/tests/test_tcp_server_socket_private_disallowed.cc
@@ -0,0 +1,87 @@
+// 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,
+ &current_address));
+ TestCompletionCallback callback(instance_->pp_instance(), force_async_);
+ int32_t rv = tcp_server_socket_private_interface_->Listen(
+ socket,
+ &current_address,
+ 1,
+ static_cast<pp::CompletionCallback>(
+ callback).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();
+}
diff --git a/ppapi/tests/test_tcp_server_socket_private_disallowed.h b/ppapi/tests/test_tcp_server_socket_private_disallowed.h
new file mode 100644
index 0000000..3d4f7c3
--- /dev/null
+++ b/ppapi/tests/test_tcp_server_socket_private_disallowed.h
@@ -0,0 +1,30 @@
+// 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.
+
+#ifndef PPAPI_TESTS_TEST_TCP_SERVER_SOCKET_PRIVATE_DISALLOWED_H_
+#define PPAPI_TESTS_TEST_TCP_SERVER_SOCKET_PRIVATE_DISALLOWED_H_
+
+#include <string>
+
+#include "ppapi/c/pp_stdint.h"
+#include "ppapi/c/ppb_core.h"
+#include "ppapi/c/private/ppb_tcp_server_socket_private.h"
+#include "ppapi/tests/test_case.h"
+
+class TestTCPServerSocketPrivateDisallowed : public TestCase {
+ public:
+ explicit TestTCPServerSocketPrivateDisallowed(TestingInstance* instance);
+
+ // TestCase implementation.
+ virtual bool Init();
+ virtual void RunTests(const std::string& filter);
+
+ private:
+ std::string TestListen();
+
+ const PPB_Core* core_interface_;
+ const PPB_TCPServerSocket_Private* tcp_server_socket_private_interface_;
+};
+
+#endif // PPAPI_TESTS_TEST_TCP_SERVER_SOCKET_PRIVATE_DISALLOWED_H_