summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authormbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-12 15:24:04 +0000
committermbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-12 15:24:04 +0000
commita01076ab38b57005e040da62d6dd37074c38a8cf (patch)
tree062b8e5ee5c5ab3d0026e7a734df5cb81c848669 /net
parent1c62e33701298c0964af870476100d03558b5e92 (diff)
downloadchromium_src-a01076ab38b57005e040da62d6dd37074c38a8cf.zip
chromium_src-a01076ab38b57005e040da62d6dd37074c38a8cf.tar.gz
chromium_src-a01076ab38b57005e040da62d6dd37074c38a8cf.tar.bz2
Rework the tcp_client_socket_unittest to be a generic
transport_client_socket_test. This allows us to create new tests which test against all transports. For now, that is just TCP. Soon we'll add SCTP. BUG=none TEST=none Review URL: http://codereview.chromium.org/6822022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81251 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/net.gyp2
-rw-r--r--net/socket/transport_client_socket_unittest.cc (renamed from net/socket/tcp_client_socket_unittest.cc)50
2 files changed, 36 insertions, 16 deletions
diff --git a/net/net.gyp b/net/net.gyp
index 50616f6..50c9a37 100644
--- a/net/net.gyp
+++ b/net/net.gyp
@@ -991,8 +991,8 @@
'socket/ssl_client_socket_unittest.cc',
'socket/ssl_client_socket_pool_unittest.cc',
'socket/ssl_server_socket_unittest.cc',
- 'socket/tcp_client_socket_unittest.cc',
'socket/transport_client_socket_pool_unittest.cc',
+ 'socket/transport_client_socket_unittest.cc',
'socket_stream/socket_stream_metrics_unittest.cc',
'socket_stream/socket_stream_unittest.cc',
'spdy/spdy_framer_test.cc',
diff --git a/net/socket/tcp_client_socket_unittest.cc b/net/socket/transport_client_socket_unittest.cc
index 2ed9441..26e0f14 100644
--- a/net/socket/tcp_client_socket_unittest.cc
+++ b/net/socket/transport_client_socket_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// 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.
@@ -14,6 +14,7 @@
#include "net/base/net_errors.h"
#include "net/base/test_completion_callback.h"
#include "net/base/winsock_init.h"
+#include "net/socket/client_socket_factory.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
@@ -23,12 +24,22 @@ namespace {
const char kServerReply[] = "HTTP/1.1 404 Not Found";
-class TCPClientSocketTest
- : public PlatformTest, public ListenSocket::ListenSocketDelegate {
+enum ClientSocketTestTypes {
+ TCP,
+ SCTP
+};
+
+class TransportClientSocketTest
+ : public ListenSocket::ListenSocketDelegate,
+ public ::testing::TestWithParam<ClientSocketTestTypes> {
public:
- TCPClientSocketTest()
+ TransportClientSocketTest()
: listen_port_(0),
- net_log_(CapturingNetLog::kUnbounded) {
+ net_log_(CapturingNetLog::kUnbounded),
+ socket_factory_(ClientSocketFactory::GetDefaultFactory()) {
+ }
+
+ ~TransportClientSocketTest() {
}
// Implement ListenSocketDelegate methods
@@ -62,15 +73,16 @@ class TCPClientSocketTest
protected:
int listen_port_;
CapturingNetLog net_log_;
- scoped_ptr<TCPClientSocket> sock_;
+ ClientSocketFactory* const socket_factory_;
+ scoped_ptr<ClientSocket> sock_;
private:
scoped_refptr<ListenSocket> listen_sock_;
scoped_refptr<ListenSocket> connected_sock_;
};
-void TCPClientSocketTest::SetUp() {
- PlatformTest::SetUp();
+void TransportClientSocketTest::SetUp() {
+ ::testing::TestWithParam<ClientSocketTestTypes>::SetUp();
// Find a free port to listen on
ListenSocket *sock = NULL;
@@ -97,10 +109,18 @@ void TCPClientSocketTest::SetUp() {
HostResolver::RequestInfo info(HostPortPair("localhost", listen_port_));
int rv = resolver->Resolve(info, &addr, NULL, NULL, BoundNetLog());
CHECK_EQ(rv, OK);
- sock_.reset(new TCPClientSocket(addr, &net_log_, NetLog::Source()));
+ sock_.reset(
+ socket_factory_->CreateTransportClientSocket(addr,
+ &net_log_,
+ NetLog::Source()));
}
-TEST_F(TCPClientSocketTest, Connect) {
+// TODO(leighton): Add SCTP to this list when it is ready.
+INSTANTIATE_TEST_CASE_P(ClientSocket,
+ TransportClientSocketTest,
+ ::testing::Values(TCP));
+
+TEST_P(TransportClientSocketTest, Connect) {
TestCompletionCallback callback;
EXPECT_FALSE(sock_->IsConnected());
@@ -131,7 +151,7 @@ TEST_F(TCPClientSocketTest, Connect) {
// - Server closes a connection.
// - Server sends data unexpectedly.
-TEST_F(TCPClientSocketTest, Read) {
+TEST_P(TransportClientSocketTest, Read) {
TestCompletionCallback callback;
int rv = sock_->Connect(&callback);
if (rv != OK) {
@@ -176,7 +196,7 @@ TEST_F(TCPClientSocketTest, Read) {
EXPECT_EQ(0, callback.WaitForResult());
}
-TEST_F(TCPClientSocketTest, Read_SmallChunks) {
+TEST_P(TransportClientSocketTest, Read_SmallChunks) {
TestCompletionCallback callback;
int rv = sock_->Connect(&callback);
if (rv != OK) {
@@ -221,7 +241,7 @@ TEST_F(TCPClientSocketTest, Read_SmallChunks) {
EXPECT_EQ(0, callback.WaitForResult());
}
-TEST_F(TCPClientSocketTest, Read_Interrupted) {
+TEST_P(TransportClientSocketTest, Read_Interrupted) {
TestCompletionCallback callback;
int rv = sock_->Connect(&callback);
if (rv != OK) {
@@ -255,7 +275,7 @@ TEST_F(TCPClientSocketTest, Read_Interrupted) {
EXPECT_NE(0, rv);
}
-TEST_F(TCPClientSocketTest, DISABLED_FullDuplex_ReadFirst) {
+TEST_P(TransportClientSocketTest, DISABLED_FullDuplex_ReadFirst) {
TestCompletionCallback callback;
int rv = sock_->Connect(&callback);
if (rv != OK) {
@@ -297,7 +317,7 @@ TEST_F(TCPClientSocketTest, DISABLED_FullDuplex_ReadFirst) {
EXPECT_GE(rv, 0);
}
-TEST_F(TCPClientSocketTest, DISABLED_FullDuplex_WriteFirst) {
+TEST_P(TransportClientSocketTest, DISABLED_FullDuplex_WriteFirst) {
TestCompletionCallback callback;
int rv = sock_->Connect(&callback);
if (rv != OK) {