summaryrefslogtreecommitdiffstats
path: root/ppapi/tests
diff options
context:
space:
mode:
authorraymes@chromium.org <raymes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-22 00:49:29 +0000
committerraymes@chromium.org <raymes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-22 00:49:29 +0000
commit8ffeeeb4fa3963d346f767780b7cb676bc04484a (patch)
tree960c2a6c13926a55857855bdac83d94afb6574f6 /ppapi/tests
parent80069fb5628ee22952c279653ef37bd809369261 (diff)
downloadchromium_src-8ffeeeb4fa3963d346f767780b7cb676bc04484a.zip
chromium_src-8ffeeeb4fa3963d346f767780b7cb676bc04484a.tar.gz
chromium_src-8ffeeeb4fa3963d346f767780b7cb676bc04484a.tar.bz2
Removed redundant TestTCPSocketPrivateShared. Renamed TestUDPSocketPrivateShared->TestUDPSocketPrivate.
-Removed TestTCPSocketPrivateShared. As far as I can tell it performs the exact same tests as TestTCPSocketPrivate. -Renamed TestUDPSocketPrivateShared to conform to the naming conventions of other files. -Enabled in-process tests for TCP/UDP as they appear to be working. BUG=None TEST=Ran browser_tests Review URL: http://codereview.chromium.org/9769015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128120 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/tests')
-rw-r--r--ppapi/tests/test_tcp_socket_private.cc40
-rw-r--r--ppapi/tests/test_tcp_socket_private_shared.cc247
-rw-r--r--ppapi/tests/test_tcp_socket_private_shared.h48
-rw-r--r--ppapi/tests/test_udp_socket_private.cc (renamed from ppapi/tests/test_udp_socket_private_shared.cc)26
-rw-r--r--ppapi/tests/test_udp_socket_private.h (renamed from ppapi/tests/test_udp_socket_private_shared.h)12
5 files changed, 18 insertions, 355 deletions
diff --git a/ppapi/tests/test_tcp_socket_private.cc b/ppapi/tests/test_tcp_socket_private.cc
index bcd749d..ee2d71f 100644
--- a/ppapi/tests/test_tcp_socket_private.cc
+++ b/ppapi/tests/test_tcp_socket_private.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// 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.
@@ -6,10 +6,7 @@
#include <stdlib.h>
-#include "ppapi/c/dev/ppb_url_util_dev.h"
-#include "ppapi/cpp/dev/url_util_dev.h"
#include "ppapi/cpp/private/tcp_socket_private.h"
-#include "ppapi/cpp/var.h"
#include "ppapi/tests/testing_instance.h"
#include "ppapi/tests/test_utils.h"
@@ -35,46 +32,13 @@ bool TestTCPSocketPrivate::Init() {
if (!pp::TCPSocketPrivate::IsAvailable())
return false;
- // This test currently only works out-of-process (since the API is really only
- // implemented in that case).
- const PPB_Testing_Dev* testing = GetTestingInterface();
- if (!testing)
- return false;
- if (!testing->IsOutOfProcess())
- return false;
-
// We need something to connect to, so we connect to the HTTP server whence we
// came. Grab the host and port.
if (!EnsureRunningOverHTTP())
return false;
- PP_URLComponents_Dev components;
- pp::Var pp_url = pp::URLUtil_Dev::Get()->GetDocumentURL(instance_,
- &components);
- if (!pp_url.is_string())
- return false;
- std::string url = pp_url.AsString();
-
- // Double-check that we're running on HTTP.
- if (components.scheme.len < 0)
+ if (!GetLocalHostPort(instance_->pp_instance(), &host_, &port_))
return false;
- if (url.substr(components.scheme.begin, components.scheme.len) != "http")
- return false;
-
- // Get host.
- if (components.host.len < 0)
- return false;
- host_ = url.substr(components.host.begin, components.host.len);
-
- // Get port (it's optional).
- port_ = 80; // Default value.
- if (components.port.len > 0) {
- int i = atoi(url.substr(components.port.begin,
- components.port.len).c_str());
- if (i < 0 || i > 65535)
- return false;
- port_ = static_cast<uint16_t>(i);
- }
return true;
}
diff --git a/ppapi/tests/test_tcp_socket_private_shared.cc b/ppapi/tests/test_tcp_socket_private_shared.cc
deleted file mode 100644
index adb62f3..0000000
--- a/ppapi/tests/test_tcp_socket_private_shared.cc
+++ /dev/null
@@ -1,247 +0,0 @@
-// 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_socket_private_shared.h"
-
-#include <vector>
-
-#include "ppapi/cpp/module.h"
-#include "ppapi/tests/test_utils.h"
-#include "ppapi/tests/testing_instance.h"
-
-REGISTER_TEST_CASE(TCPSocketPrivateShared);
-
-TestTCPSocketPrivateShared::TestTCPSocketPrivateShared(
- TestingInstance* instance)
- : TestCase(instance), tcp_socket_private_interface_(NULL) {
-}
-
-bool TestTCPSocketPrivateShared::Init() {
- tcp_socket_private_interface_ = static_cast<const PPB_TCPSocket_Private*>(
- pp::Module::Get()->GetBrowserInterface(PPB_TCPSOCKET_PRIVATE_INTERFACE));
- if (!tcp_socket_private_interface_)
- instance_->AppendError("TCPSocketPrivate interface not available");
-
- bool init_host_port = false;
- if (!GetLocalHostPort(instance_->pp_instance(), &host_, &port_))
- instance_->AppendError("Can't init host and port");
- else
- init_host_port = true;
-
- return tcp_socket_private_interface_ &&
- init_host_port &&
- CheckTestingInterface();
-}
-
-void TestTCPSocketPrivateShared::RunTests(const std::string& filter) {
- RUN_TEST(Create, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(GetAddress, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(Connect, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(Reconnect, filter);
-}
-
-void TestTCPSocketPrivateShared::QuitMessageLoop() {
- testing_interface_->QuitMessageLoop(instance_->pp_instance());
-}
-
-std::string TestTCPSocketPrivateShared::CreateSocket(PP_Resource* socket) {
- *socket = tcp_socket_private_interface_->Create(instance_->pp_instance());
- if (0 == *socket)
- return "PPB_TCPSocket_Private::Create failed";
- if (!tcp_socket_private_interface_->IsTCPSocket(*socket))
- return "PPB_TCPSocket_Private::IsTCPSocket failed";
- PASS();
-}
-
-std::string TestTCPSocketPrivateShared::SyncConnect(PP_Resource socket,
- const std::string& host,
- uint16_t port) {
- TestCompletionCallback callback(instance_->pp_instance(), force_async_);
-
- int32_t rv = tcp_socket_private_interface_->Connect(
- socket, host.c_str(), port,
- static_cast<pp::CompletionCallback>(callback).pp_completion_callback());
-
- if (force_async_ && rv != PP_OK_COMPLETIONPENDING)
- return ReportError("PPB_TCPSocket_Private::Connect force_async", rv);
- if (rv == PP_OK_COMPLETIONPENDING)
- rv = callback.WaitForResult();
- if (rv != PP_OK)
- return ReportError("PPB_TCPSocket_Private::Connect", rv);
- PASS();
-}
-
-std::string TestTCPSocketPrivateShared::SyncConnectWithNetAddress(
- PP_Resource socket, const PP_NetAddress_Private& addr) {
- TestCompletionCallback callback(instance_->pp_instance(), force_async_);
-
- int32_t rv = tcp_socket_private_interface_->ConnectWithNetAddress(
- socket, &addr,
- static_cast<pp::CompletionCallback>(callback).pp_completion_callback());
-
- if (force_async_ && rv != PP_OK_COMPLETIONPENDING)
- return ReportError(
- "PPB_TCPSocket_Private::ConnectWithNetAddress force_async", rv);
- if (rv == PP_OK_COMPLETIONPENDING)
- rv = callback.WaitForResult();
- if (rv != PP_OK)
- return ReportError("PPB_TCPSocket_Private::ConnectWithNetAddress", rv);
- PASS();
-}
-
-std::string TestTCPSocketPrivateShared::SyncRead(PP_Resource socket,
- char* buffer,
- int32_t num_bytes,
- int32_t* bytes_read) {
- TestCompletionCallback callback(instance_->pp_instance(), force_async_);
-
- int32_t rv = tcp_socket_private_interface_->Read(
- socket, buffer, num_bytes,
- static_cast<pp::CompletionCallback>(callback).pp_completion_callback());
-
- if (force_async_ && rv != PP_OK_COMPLETIONPENDING)
- return ReportError("PPB_TCPSocket_Private::Read force_async", rv);
- if (rv == PP_OK_COMPLETIONPENDING)
- rv = callback.WaitForResult();
-
- if (num_bytes != rv)
- return ReportError("PPB_TCPSocket_Private::Read", rv);
-
- *bytes_read = rv;
- PASS();
-}
-
-std::string TestTCPSocketPrivateShared::SyncWrite(PP_Resource socket,
- const char* buffer,
- int32_t num_bytes,
- int32_t* bytes_wrote) {
- TestCompletionCallback callback(instance_->pp_instance(), force_async_);
- int32_t rv = tcp_socket_private_interface_->Write(
- socket, buffer, num_bytes,
- static_cast<pp::CompletionCallback>(callback).pp_completion_callback());
-
- if (force_async_ && rv != PP_OK_COMPLETIONPENDING)
- return ReportError("PPB_TCPSocket_Private::Write force_async", rv);
- if (rv == PP_OK_COMPLETIONPENDING)
- rv = callback.WaitForResult();
- if (num_bytes != rv)
- return ReportError("PPB_TCPSocket_Private::Write", rv);
-
- *bytes_wrote = rv;
- PASS();
-}
-
-std::string TestTCPSocketPrivateShared::CheckHTTPResponse(
- PP_Resource socket,
- 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;
-
- std::vector<char> response_buffer(response.size());
- error_message = SyncRead(socket, &response_buffer[0], response.size(), &rv);
- if (!error_message.empty())
- return error_message;
-
- std::string actual_response(&response_buffer[0], rv);
-
- if (response != actual_response)
- return "CheckHTTPResponse failed, expected: " + response +
- ", actual: " + actual_response;
- PASS();
-}
-
-std::string TestTCPSocketPrivateShared::TestCreate() {
- PP_Resource socket = tcp_socket_private_interface_->Create(0);
- if (0 != socket)
- return "PPB_TCPSocket_Private::Create returns valid socket " \
- "for invalid instance";
-
- return CreateSocket(&socket);
-}
-
-std::string TestTCPSocketPrivateShared::TestGetAddress() {
- PP_Resource socket;
- std::string error_message;
-
- error_message = CreateSocket(&socket);
- if (!error_message.empty())
- return error_message;
-
- error_message = SyncConnect(socket, host_, port_);
- if (!error_message.empty())
- return error_message;
-
- PP_NetAddress_Private local_address, remote_address;
-
- if (PP_TRUE != tcp_socket_private_interface_->GetLocalAddress(
- socket, &local_address))
- return "PPB_TCPSocketPrivate::GetLocalAddress failed";
- if (PP_TRUE != tcp_socket_private_interface_->GetRemoteAddress(
- socket, &remote_address))
- return "PPB_TCPSocketPrivate::GetRemoteAddress failed";
-
- tcp_socket_private_interface_->Disconnect(socket);
-
- PASS();
-}
-
-std::string TestTCPSocketPrivateShared::TestConnect() {
- PP_Resource socket;
- std::string error_message;
-
- error_message = CreateSocket(&socket);
- if (!error_message.empty())
- return error_message;
- error_message = SyncConnect(socket, host_, port_);
- if (!error_message.empty())
- return error_message;
- error_message =
- CheckHTTPResponse(socket, "GET / HTTP/1.0\r\n\r\n", "HTTP/1.0 200 OK");
- if (!error_message.empty())
- return error_message;
- tcp_socket_private_interface_->Disconnect(socket);
-
- PASS();
-}
-
-std::string TestTCPSocketPrivateShared::TestReconnect() {
- PP_Resource socket;
- std::string error_message;
-
- error_message = CreateSocket(&socket);
- if (!error_message.empty())
- return error_message;
- error_message = SyncConnect(socket, host_, port_);
- if (!error_message.empty())
- return error_message;
-
- PP_NetAddress_Private remote_address;
- if (PP_TRUE !=
- tcp_socket_private_interface_->GetRemoteAddress(socket,
- &remote_address))
- return "PPB_TCPSocketPrivate::GetRemoteAddress failed";
- tcp_socket_private_interface_->Disconnect(socket);
-
- error_message = CreateSocket(&socket);
- if (!error_message.empty())
- return error_message;
- error_message = SyncConnectWithNetAddress(socket, remote_address);
- if (!error_message.empty())
- return error_message;
- error_message = CheckHTTPResponse(socket,
- "GET / HTTP/1.0\r\n\r\n",
- "HTTP/1.0 200 OK");
- if (!error_message.empty())
- return error_message;
- tcp_socket_private_interface_->Disconnect(socket);
-
- PASS();
-}
-
-// TODO(ygorshenin): test SSLHandshake somehow
diff --git a/ppapi/tests/test_tcp_socket_private_shared.h b/ppapi/tests/test_tcp_socket_private_shared.h
deleted file mode 100644
index 1285102..0000000
--- a/ppapi/tests/test_tcp_socket_private_shared.h
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright (c) 2011 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_SOCKET_PRIVATE_SHARED_H_
-#define PPAPI_TESTS_TEST_TCP_SOCKET_PRIVATE_SHARED_H_
-
-#include <string>
-
-#include "ppapi/c/pp_stdint.h"
-#include "ppapi/cpp/private/tcp_socket_private.h"
-#include "ppapi/tests/test_case.h"
-
-class TestTCPSocketPrivateShared : public TestCase {
- public:
- explicit TestTCPSocketPrivateShared(TestingInstance* instance);
-
- // TestCase implementation.
- virtual bool Init();
- virtual void RunTests(const std::string& filter);
-
- void QuitMessageLoop();
-
- private:
- std::string CreateSocket(PP_Resource* socket);
- std::string SyncConnect(PP_Resource socket,
- const std::string& host, uint16_t port);
- std::string SyncConnectWithNetAddress(PP_Resource socket,
- const PP_NetAddress_Private& addr);
- std::string SyncRead(PP_Resource socket, char* buffer, int32_t num_bytes,
- int32_t* bytes_read);
- std::string SyncWrite(PP_Resource socket, const char* buffer,
- int32_t num_bytes, int32_t* bytes_wrote);
- std::string CheckHTTPResponse(PP_Resource socket,
- const std::string& request,
- const std::string& response);
-
- std::string TestCreate();
- std::string TestGetAddress();
- std::string TestConnect();
- std::string TestReconnect();
-
- const PPB_TCPSocket_Private* tcp_socket_private_interface_;
- std::string host_;
- uint16_t port_;
-};
-
-#endif // PPAPI_TESTS_TEST_TCP_SOCKET_PRIVATE_SHARED_H_
diff --git a/ppapi/tests/test_udp_socket_private_shared.cc b/ppapi/tests/test_udp_socket_private.cc
index a0cef72..182e683 100644
--- a/ppapi/tests/test_udp_socket_private_shared.cc
+++ b/ppapi/tests/test_udp_socket_private.cc
@@ -5,20 +5,20 @@
#include <string.h>
#include "ppapi/cpp/module.h"
-#include "ppapi/tests/test_udp_socket_private_shared.h"
+#include "ppapi/tests/test_udp_socket_private.h"
#include "ppapi/tests/test_utils.h"
#include "ppapi/tests/testing_instance.h"
-REGISTER_TEST_CASE(UDPSocketPrivateShared);
+REGISTER_TEST_CASE(UDPSocketPrivate);
-TestUDPSocketPrivateShared::TestUDPSocketPrivateShared(
+TestUDPSocketPrivate::TestUDPSocketPrivate(
TestingInstance* instance)
: TestCase(instance),
tcp_socket_private_interface_(NULL),
udp_socket_private_interface_(NULL) {
}
-bool TestUDPSocketPrivateShared::Init() {
+bool TestUDPSocketPrivate::Init() {
tcp_socket_private_interface_ = static_cast<const PPB_TCPSocket_Private*>(
pp::Module::Get()->GetBrowserInterface(PPB_TCPSOCKET_PRIVATE_INTERFACE));
if (!tcp_socket_private_interface_)
@@ -41,17 +41,13 @@ bool TestUDPSocketPrivateShared::Init() {
CheckTestingInterface();
}
-void TestUDPSocketPrivateShared::RunTests(const std::string& filter) {
+void TestUDPSocketPrivate::RunTests(const std::string& filter) {
RUN_TEST(Create, filter);
RUN_TEST_FORCEASYNC_AND_NOT(Connect, filter);
RUN_TEST_FORCEASYNC_AND_NOT(ConnectFailure, filter);
}
-void TestUDPSocketPrivateShared::QuitMessageLoop() {
- testing_interface_->QuitMessageLoop(instance_->pp_instance());
-}
-
-std::string TestUDPSocketPrivateShared::GenerateNetAddress(
+std::string TestUDPSocketPrivate::GenerateNetAddress(
PP_Resource* socket, PP_NetAddress_Private* address) {
*socket = tcp_socket_private_interface_->Create(instance_->pp_instance());
if (0 == *socket)
@@ -75,7 +71,7 @@ std::string TestUDPSocketPrivateShared::GenerateNetAddress(
PASS();
}
-std::string TestUDPSocketPrivateShared::CreateAndBindUDPSocket(
+std::string TestUDPSocketPrivate::CreateAndBindUDPSocket(
PP_NetAddress_Private *address,
PP_Resource *socket) {
*socket = udp_socket_private_interface_->Create(instance_->pp_instance());
@@ -102,7 +98,7 @@ std::string TestUDPSocketPrivateShared::CreateAndBindUDPSocket(
PASS();
}
-std::string TestUDPSocketPrivateShared::BindUDPSocketFailure(
+std::string TestUDPSocketPrivate::BindUDPSocketFailure(
PP_NetAddress_Private *address,
PP_Resource *socket) {
*socket = udp_socket_private_interface_->Create(instance_->pp_instance());
@@ -129,7 +125,7 @@ std::string TestUDPSocketPrivateShared::BindUDPSocketFailure(
PASS();
}
-std::string TestUDPSocketPrivateShared::TestCreate() {
+std::string TestUDPSocketPrivate::TestCreate() {
PP_Resource udp_socket;
std::string error_message;
@@ -147,7 +143,7 @@ std::string TestUDPSocketPrivateShared::TestCreate() {
PASS();
}
-std::string TestUDPSocketPrivateShared::TestConnect() {
+std::string TestUDPSocketPrivate::TestConnect() {
PP_NetAddress_Private server_address, client_address;
PP_Resource tcp_socket_server, tcp_socket_client;
std::string error_message;
@@ -216,7 +212,7 @@ std::string TestUDPSocketPrivateShared::TestConnect() {
PASS();
}
-std::string TestUDPSocketPrivateShared::TestConnectFailure() {
+std::string TestUDPSocketPrivate::TestConnectFailure() {
std::string error_message;
PP_NetAddress_Private invalid_address = { 0 };
PP_Resource socket;
diff --git a/ppapi/tests/test_udp_socket_private_shared.h b/ppapi/tests/test_udp_socket_private.h
index 2f74965..45cd642 100644
--- a/ppapi/tests/test_udp_socket_private_shared.h
+++ b/ppapi/tests/test_udp_socket_private.h
@@ -2,23 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef PPAPI_TESTS_TEST_UDP_SOCKET_PRIVATE_SHARED_H_
-#define PPAPI_TESTS_TEST_UDP_SOCKET_PRIVATE_SHARED_H_
+#ifndef PPAPI_TESTS_TEST_UDP_SOCKET_PRIVATE_H_
+#define PPAPI_TESTS_TEST_UDP_SOCKET_PRIVATE_H_
#include "ppapi/cpp/private/tcp_socket_private.h"
#include "ppapi/cpp/private/udp_socket_private.h"
#include "ppapi/tests/test_case.h"
-class TestUDPSocketPrivateShared : public TestCase {
+class TestUDPSocketPrivate : public TestCase {
public:
- explicit TestUDPSocketPrivateShared(TestingInstance* instance);
+ explicit TestUDPSocketPrivate(TestingInstance* instance);
// TestCase implementation.
virtual bool Init();
virtual void RunTests(const std::string& filter);
- void QuitMessageLoop();
-
private:
// Creates tcp_socket and connects to www.google.com:80. After that,
// stores into |address| local address and returns created
@@ -41,4 +39,4 @@ class TestUDPSocketPrivateShared : public TestCase {
uint16_t port_;
};
-#endif // PPAPI_TESTS_TEST_UDP_SOCKET_PRIVATE_SHARED_H_
+#endif // PPAPI_TESTS_TEST_UDP_SOCKET_PRIVATE_H_