summaryrefslogtreecommitdiffstats
path: root/ppapi/tests
diff options
context:
space:
mode:
authorygorshenin@chromium.org <ygorshenin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-21 10:08:37 +0000
committerygorshenin@chromium.org <ygorshenin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-21 10:08:37 +0000
commit0f8a16cf49ce0bdae4afbcff65198fe7f53d17a2 (patch)
treef8fb87651b87362b631cdc9d31d6a619d4a89bd0 /ppapi/tests
parentc958f909490cf530b26305473ab1598fff94d90e (diff)
downloadchromium_src-0f8a16cf49ce0bdae4afbcff65198fe7f53d17a2.zip
chromium_src-0f8a16cf49ce0bdae4afbcff65198fe7f53d17a2.tar.gz
chromium_src-0f8a16cf49ce0bdae4afbcff65198fe7f53d17a2.tar.bz2
Added C++ wrappers for PPB_HostResolver_Private interface.
BUG=114225 TEST=*HostResolverPrivate Review URL: http://codereview.chromium.org/9701024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127929 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/tests')
-rw-r--r--ppapi/tests/test_host_resolver_private.cc118
-rw-r--r--ppapi/tests/test_host_resolver_private.h13
2 files changed, 45 insertions, 86 deletions
diff --git a/ppapi/tests/test_host_resolver_private.cc b/ppapi/tests/test_host_resolver_private.cc
index efba09e..8de75b3 100644
--- a/ppapi/tests/test_host_resolver_private.cc
+++ b/ppapi/tests/test_host_resolver_private.cc
@@ -5,8 +5,8 @@
#include "ppapi/tests/test_host_resolver_private.h"
#include "ppapi/c/private/ppb_net_address_private.h"
-#include "ppapi/cpp/module.h"
-#include "ppapi/cpp/pass_ref.h"
+#include "ppapi/cpp/module_impl.h"
+#include "ppapi/cpp/private/host_resolver_private.h"
#include "ppapi/cpp/private/tcp_socket_private.h"
#include "ppapi/cpp/var.h"
#include "ppapi/tests/test_utils.h"
@@ -19,27 +19,21 @@ TestHostResolverPrivate::TestHostResolverPrivate(TestingInstance* instance)
}
bool TestHostResolverPrivate::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");
- host_resolver_private_interface_ =
- static_cast<const PPB_HostResolver_Private*>(
- pp::Module::Get()->GetBrowserInterface(
- PPB_HOSTRESOLVER_PRIVATE_INTERFACE));
+ bool host_resolver_private_is_available =
+ pp::HostResolverPrivate::IsAvailable();
+ if (!host_resolver_private_is_available)
+ instance_->AppendError("PPB_HostResolver_Private interface not available");
+
bool tcp_socket_private_is_available = pp::TCPSocketPrivate::IsAvailable();
if (!tcp_socket_private_is_available)
instance_->AppendError("PPB_TCPSocket_Private interface not available");
- if (!host_resolver_private_interface_)
- instance_->AppendError("PPB_HostResolver_Private interface not available");
- bool init_host_port = GetLocalHostPort(
- instance_->pp_instance(), &host_, &port_);
+ bool init_host_port =
+ GetLocalHostPort(instance_->pp_instance(), &host_, &port_);
if (!init_host_port)
instance_->AppendError("Can't init host and port");
- return core_interface_ &&
- host_resolver_private_interface_ &&
+ return host_resolver_private_is_available &&
tcp_socket_private_is_available &&
init_host_port &&
CheckTestingInterface() &&
@@ -47,7 +41,7 @@ bool TestHostResolverPrivate::Init() {
}
void TestHostResolverPrivate::RunTests(const std::string& filter) {
- RUN_TEST(Create, filter);
+ RUN_TEST(Empty, filter);
RUN_TEST_FORCEASYNC_AND_NOT(Resolve, filter);
RUN_TEST_FORCEASYNC_AND_NOT(ResolveIPv4, filter);
}
@@ -115,16 +109,11 @@ std::string TestHostResolverPrivate::CheckHTTPResponse(
const std::string& request,
const std::string& response) {
int32_t rv = 0;
- std::string error_message;
-
- error_message = SyncWrite(socket, request.c_str(), request.size(), &rv);
- if (!error_message.empty())
- return error_message;
-
+ ASSERT_SUBTEST_SUCCESS(
+ SyncWrite(socket, request.c_str(), request.size(), &rv));
std::vector<char> response_buffer(response.size());
- error_message = SyncRead(socket, &response_buffer[0], response.size(), &rv);
- if (!error_message.empty())
- return error_message;
+ ASSERT_SUBTEST_SUCCESS(
+ SyncRead(socket, &response_buffer[0], response.size(), &rv));
std::string actual_response(&response_buffer[0], rv);
if (response != actual_response) {
return "CheckHTTPResponse failed, expected: " + response +
@@ -134,17 +123,12 @@ std::string TestHostResolverPrivate::CheckHTTPResponse(
}
std::string TestHostResolverPrivate::SyncResolve(
- PP_Resource host_resolver,
+ pp::HostResolverPrivate* host_resolver,
const std::string& host,
uint16_t port,
const PP_HostResolver_Private_Hint& hint) {
TestCompletionCallback callback(instance_->pp_instance(), force_async_);
- int32_t rv = host_resolver_private_interface_->Resolve(
- host_resolver,
- host.c_str(),
- port,
- &hint,
- static_cast<pp::CompletionCallback>(callback).pp_completion_callback());
+ int32_t rv = host_resolver->Resolve(host, port, hint, callback);
if (force_async_ && rv != PP_OK_COMPLETIONPENDING)
return ReportError("PPB_HostResolver_Private::Resolve force_async", rv);
if (rv == PP_OK_COMPLETIONPENDING)
@@ -154,72 +138,48 @@ std::string TestHostResolverPrivate::SyncResolve(
PASS();
}
-std::string TestHostResolverPrivate::TestCreate() {
- PP_Resource host_resolver = host_resolver_private_interface_->Create(0);
- ASSERT_EQ(0, host_resolver);
-
- host_resolver =
- host_resolver_private_interface_->Create(instance_->pp_instance());
- ASSERT_NE(0, host_resolver);
- ASSERT_TRUE(host_resolver_private_interface_->IsHostResolver(host_resolver));
- ASSERT_EQ(0, host_resolver_private_interface_->GetSize(host_resolver));
-
+std::string TestHostResolverPrivate::TestEmpty() {
+ pp::HostResolverPrivate host_resolver(instance_);
+ ASSERT_EQ(0, host_resolver.GetSize());
PP_NetAddress_Private address;
- ASSERT_FALSE(host_resolver_private_interface_->GetNetAddress(host_resolver,
- 0,
- &address));
- core_interface_->ReleaseResource(host_resolver);
+ ASSERT_FALSE(host_resolver.GetNetAddress(0, &address));
+
PASS();
}
std::string TestHostResolverPrivate::ParametrizedTestResolve(
const PP_HostResolver_Private_Hint &hint) {
- PP_Resource host_resolver =
- host_resolver_private_interface_->Create(instance_->pp_instance());
- ASSERT_NE(0, host_resolver);
- ASSERT_TRUE(host_resolver_private_interface_->IsHostResolver(host_resolver));
+ pp::HostResolverPrivate host_resolver(instance_);
- std::string error_message = SyncResolve(host_resolver, host_, port_, hint);
- if (!error_message.empty())
- return error_message;
+ ASSERT_SUBTEST_SUCCESS(SyncResolve(&host_resolver, host_, port_, hint));
- const size_t size = host_resolver_private_interface_->GetSize(host_resolver);
+ const size_t size = host_resolver.GetSize();
ASSERT_TRUE(size >= 1);
PP_NetAddress_Private address;
for (size_t i = 0; i < size; ++i) {
- ASSERT_TRUE(host_resolver_private_interface_->GetNetAddress(host_resolver,
- i,
- &address));
+ ASSERT_TRUE(host_resolver.GetNetAddress(i, &address));
+
pp::TCPSocketPrivate socket(instance_);
- error_message = SyncConnect(&socket, address);
- error_message =
- CheckHTTPResponse(&socket, "GET / HTTP/1.0\r\n\r\n", "HTTP/1.0");
- if (!error_message.empty())
- return error_message;
+ ASSERT_SUBTEST_SUCCESS(SyncConnect(&socket, address));
+ ASSERT_SUBTEST_SUCCESS(CheckHTTPResponse(&socket,
+ "GET / HTTP/1.0\r\n\r\n",
+ "HTTP"));
socket.Disconnect();
}
- ASSERT_FALSE(host_resolver_private_interface_->GetNetAddress(host_resolver,
- size,
- &address));
- PP_Var pp_var =
- host_resolver_private_interface_->GetCanonicalName(host_resolver);
- pp::Var canonical_name(pp::PassRef(), pp_var);
+ ASSERT_FALSE(host_resolver.GetNetAddress(size, &address));
+ pp::Var canonical_name = host_resolver.GetCanonicalName();
ASSERT_TRUE(canonical_name.is_string());
pp::TCPSocketPrivate socket(instance_);
- error_message = SyncConnect(&socket,
- canonical_name.AsString().c_str(),
- port_);
- if (!error_message.empty())
- return error_message;
- error_message = CheckHTTPResponse(&socket,
- "GET / HTTP/1.0\r\n\r\n", "HTTP");
- if (!error_message.empty())
- return error_message;
+ ASSERT_SUBTEST_SUCCESS(SyncConnect(&socket,
+ canonical_name.AsString(),
+ port_));
+ ASSERT_SUBTEST_SUCCESS(CheckHTTPResponse(&socket,
+ "GET / HTTP/1.0\r\n\r\n",
+ "HTTP"));
socket.Disconnect();
- core_interface_->ReleaseResource(host_resolver);
PASS();
}
diff --git a/ppapi/tests/test_host_resolver_private.h b/ppapi/tests/test_host_resolver_private.h
index 23f3acf..52f1f27 100644
--- a/ppapi/tests/test_host_resolver_private.h
+++ b/ppapi/tests/test_host_resolver_private.h
@@ -7,12 +7,14 @@
#include <string>
-#include "ppapi/c/ppb_core.h"
-#include "ppapi/c/private/ppb_host_resolver_private.h"
#include "ppapi/tests/test_case.h"
+struct PP_HostResolver_Private_Hint;
+struct PP_NetAddress_Private;
+
namespace pp {
+class HostResolverPrivate;
class TCPSocketPrivate;
} // namespace pp
@@ -42,19 +44,16 @@ class TestHostResolverPrivate : public TestCase {
std::string CheckHTTPResponse(pp::TCPSocketPrivate* socket,
const std::string& request,
const std::string& response);
- std::string SyncResolve(PP_Resource host_resolver,
+ std::string SyncResolve(pp::HostResolverPrivate* host_resolver,
const std::string& host,
uint16_t port,
const PP_HostResolver_Private_Hint& hint);
std::string ParametrizedTestResolve(const PP_HostResolver_Private_Hint& hint);
- std::string TestCreate();
+ std::string TestEmpty();
std::string TestResolve();
std::string TestResolveIPv4();
- const PPB_Core* core_interface_;
- const PPB_HostResolver_Private* host_resolver_private_interface_;
-
std::string host_;
uint16_t port_;
};