summaryrefslogtreecommitdiffstats
path: root/net/tools
diff options
context:
space:
mode:
authorrch <rch@chromium.org>2015-03-21 22:13:58 -0700
committerCommit bot <commit-bot@chromium.org>2015-03-22 05:14:29 +0000
commita6d42cd433e067ca3a35b0a09ea8512be769477c (patch)
treee64a833bed40bd8a526022b3487a378dfc5234fd /net/tools
parente28e5618dfc74f02bb7d26b1fbe02c22f26e3ef2 (diff)
downloadchromium_src-a6d42cd433e067ca3a35b0a09ea8512be769477c.zip
chromium_src-a6d42cd433e067ca3a35b0a09ea8512be769477c.tar.gz
chromium_src-a6d42cd433e067ca3a35b0a09ea8512be769477c.tar.bz2
Implement working tests for the simple QUIC client classes.
Review URL: https://codereview.chromium.org/1017973002 Cr-Commit-Position: refs/heads/master@{#321704}
Diffstat (limited to 'net/tools')
-rw-r--r--net/tools/quic/quic_simple_client_session_test.cc29
-rw-r--r--net/tools/quic/quic_simple_client_stream_test.cc43
-rw-r--r--net/tools/quic/quic_simple_client_test.cc57
3 files changed, 43 insertions, 86 deletions
diff --git a/net/tools/quic/quic_simple_client_session_test.cc b/net/tools/quic/quic_simple_client_session_test.cc
index c7d1f09..866ff91 100644
--- a/net/tools/quic/quic_simple_client_session_test.cc
+++ b/net/tools/quic/quic_simple_client_session_test.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "net/tools/quic/quic_client_session.h"
+#include "net/tools/quic/quic_simple_client_session.h"
#include <vector>
@@ -12,7 +12,7 @@
#include "net/quic/test_tools/crypto_test_utils.h"
#include "net/quic/test_tools/quic_session_peer.h"
#include "net/quic/test_tools/quic_test_utils.h"
-#include "net/tools/quic/quic_spdy_client_stream.h"
+#include "net/tools/quic/quic_simple_client_stream.h"
#include "testing/gtest/include/gtest/gtest.h"
using net::test::CryptoTestUtils;
@@ -35,13 +35,14 @@ namespace {
const char kServerHostname[] = "www.example.org";
const uint16 kPort = 80;
-class ToolsQuicClientSessionTest
+class QuicSimpleClientSessionTest
: public ::testing::TestWithParam<QuicVersion> {
protected:
- ToolsQuicClientSessionTest()
+ QuicSimpleClientSessionTest()
: connection_(new PacketSavingConnection(Perspective::IS_CLIENT,
SupportedVersions(GetParam()))) {
- session_.reset(new QuicClientSession(DefaultQuicConfig(), connection_));
+ session_.reset(new QuicSimpleClientSession(DefaultQuicConfig(),
+ connection_));
session_->InitializeSession(
QuicServerId(kServerHostname, kPort, false, PRIVACY_MODE_DISABLED),
&crypto_config_);
@@ -56,24 +57,24 @@ class ToolsQuicClientSessionTest
}
PacketSavingConnection* connection_;
- scoped_ptr<QuicClientSession> session_;
+ scoped_ptr<QuicSimpleClientSession> session_;
QuicCryptoClientConfig crypto_config_;
};
-INSTANTIATE_TEST_CASE_P(Tests, ToolsQuicClientSessionTest,
+INSTANTIATE_TEST_CASE_P(Tests, QuicSimpleClientSessionTest,
::testing::ValuesIn(QuicSupportedVersions()));
-TEST_P(ToolsQuicClientSessionTest, CryptoConnect) {
+TEST_P(QuicSimpleClientSessionTest, CryptoConnect) {
CompleteCryptoHandshake();
}
-TEST_P(ToolsQuicClientSessionTest, MaxNumStreams) {
+TEST_P(QuicSimpleClientSessionTest, MaxNumStreams) {
session_->config()->SetMaxStreamsPerConnection(1, 1);
// Initialize crypto before the client session will create a stream.
CompleteCryptoHandshake();
- QuicSpdyClientStream* stream = session_->CreateOutgoingDataStream();
+ QuicSimpleClientStream* stream = session_->CreateOutgoingDataStream();
ASSERT_TRUE(stream);
EXPECT_FALSE(session_->CreateOutgoingDataStream());
@@ -83,7 +84,7 @@ TEST_P(ToolsQuicClientSessionTest, MaxNumStreams) {
EXPECT_TRUE(stream);
}
-TEST_P(ToolsQuicClientSessionTest, GoAwayReceived) {
+TEST_P(QuicSimpleClientSessionTest, GoAwayReceived) {
CompleteCryptoHandshake();
// After receiving a GoAway, I should no longer be able to create outgoing
@@ -92,7 +93,7 @@ TEST_P(ToolsQuicClientSessionTest, GoAwayReceived) {
EXPECT_EQ(nullptr, session_->CreateOutgoingDataStream());
}
-TEST_P(ToolsQuicClientSessionTest, SetFecProtectionFromConfig) {
+TEST_P(QuicSimpleClientSessionTest, SetFecProtectionFromConfig) {
ValueRestore<bool> old_flag(&FLAGS_enable_quic_fec, true);
// Set FEC config in client's connection options.
@@ -107,13 +108,13 @@ TEST_P(ToolsQuicClientSessionTest, SetFecProtectionFromConfig) {
// optionally protected.
EXPECT_EQ(FEC_PROTECT_ALWAYS,
QuicSessionPeer::GetHeadersStream(session_.get())->fec_policy());
- QuicSpdyClientStream* stream = session_->CreateOutgoingDataStream();
+ QuicSimpleClientStream* stream = session_->CreateOutgoingDataStream();
ASSERT_TRUE(stream);
EXPECT_EQ(FEC_PROTECT_OPTIONAL, stream->fec_policy());
}
// Regression test for b/17206611.
-TEST_P(ToolsQuicClientSessionTest, InvalidPacketReceived) {
+TEST_P(QuicSimpleClientSessionTest, InvalidPacketReceived) {
// Create Packet with 0 length.
QuicEncryptedPacket invalid_packet(nullptr, 0, false);
IPEndPoint server_address(TestPeerIPAddress(), kTestPort);
diff --git a/net/tools/quic/quic_simple_client_stream_test.cc b/net/tools/quic/quic_simple_client_stream_test.cc
index 323018e..d753514 100644
--- a/net/tools/quic/quic_simple_client_stream_test.cc
+++ b/net/tools/quic/quic_simple_client_stream_test.cc
@@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "net/tools/quic/quic_spdy_client_stream.h"
+#include "net/tools/quic/quic_simple_client_stream.h"
#include "base/strings/string_number_conversions.h"
#include "net/quic/quic_utils.h"
#include "net/quic/test_tools/quic_test_utils.h"
-#include "net/tools/quic/quic_client_session.h"
-#include "net/tools/quic/quic_spdy_client_stream.h"
+#include "net/spdy/spdy_http_utils.h"
+#include "net/tools/quic/quic_simple_client_session.h"
#include "net/tools/quic/spdy_utils.h"
#include "net/tools/quic/test_tools/quic_test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -26,22 +26,25 @@ namespace tools {
namespace test {
namespace {
-class QuicSpdyClientStreamTest : public TestWithParam<QuicVersion> {
+class QuicSimpleClientStreamTest : public TestWithParam<QuicVersion> {
public:
- QuicSpdyClientStreamTest()
+ QuicSimpleClientStreamTest()
: connection_(
new StrictMock<MockConnection>(Perspective::IS_CLIENT,
SupportedVersions(GetParam()))),
session_(DefaultQuicConfig(), connection_),
+ headers_(new HttpResponseHeaders("")),
body_("hello world") {
session_.InitializeSession(
QuicServerId("example.com", 80, false, PRIVACY_MODE_DISABLED),
&crypto_config_);
- headers_.SetResponseFirstlineFromStringPieces("HTTP/1.1", "200", "Ok");
- headers_.ReplaceOrAppendHeader("content-length", "11");
+ headers_->ReplaceStatusLine("HTTP/1.1 200 Ok");
+ headers_->AddHeader("content-length: 11");
- headers_string_ = SpdyUtils::SerializeResponseHeaders(headers_);
+ SpdyHeaderBlock header_block;
+ CreateSpdyHeadersFromHttpResponse(*headers_, SPDY3, &header_block);
+ headers_string_ = SpdyUtils::SerializeUncompressedHeaders(header_block);
// New streams rely on having the peer's flow control receive window
// negotiated in the config.
@@ -49,47 +52,47 @@ class QuicSpdyClientStreamTest : public TestWithParam<QuicVersion> {
kInitialStreamFlowControlWindowForTest);
session_.config()->SetInitialSessionFlowControlWindowToSend(
kInitialSessionFlowControlWindowForTest);
- stream_.reset(new QuicSpdyClientStream(3, &session_));
+ stream_.reset(new QuicSimpleClientStream(3, &session_));
}
StrictMock<MockConnection>* connection_;
- QuicClientSession session_;
- scoped_ptr<QuicSpdyClientStream> stream_;
- BalsaHeaders headers_;
+ QuicSimpleClientSession session_;
+ scoped_ptr<QuicSimpleClientStream> stream_;
+ scoped_refptr<HttpResponseHeaders> headers_;
string headers_string_;
string body_;
QuicCryptoClientConfig crypto_config_;
};
-INSTANTIATE_TEST_CASE_P(Tests, QuicSpdyClientStreamTest,
+INSTANTIATE_TEST_CASE_P(Tests, QuicSimpleClientStreamTest,
::testing::ValuesIn(QuicSupportedVersions()));
-TEST_P(QuicSpdyClientStreamTest, TestFraming) {
+TEST_P(QuicSimpleClientStreamTest, TestFraming) {
EXPECT_EQ(headers_string_.size(), stream_->ProcessData(
headers_string_.c_str(), headers_string_.size()));
EXPECT_EQ(body_.size(),
stream_->ProcessData(body_.c_str(), body_.size()));
- EXPECT_EQ(200u, stream_->headers().parsed_response_code());
+ EXPECT_EQ(200, stream_->headers()->response_code());
EXPECT_EQ(body_, stream_->data());
}
-TEST_P(QuicSpdyClientStreamTest, TestFramingOnePacket) {
+TEST_P(QuicSimpleClientStreamTest, TestFramingOnePacket) {
string message = headers_string_ + body_;
EXPECT_EQ(message.size(), stream_->ProcessData(
message.c_str(), message.size()));
- EXPECT_EQ(200u, stream_->headers().parsed_response_code());
+ EXPECT_EQ(200, stream_->headers()->response_code());
EXPECT_EQ(body_, stream_->data());
}
-TEST_P(QuicSpdyClientStreamTest, DISABLED_TestFramingExtraData) {
+TEST_P(QuicSimpleClientStreamTest, DISABLED_TestFramingExtraData) {
string large_body = "hello world!!!!!!";
EXPECT_EQ(headers_string_.size(), stream_->ProcessData(
headers_string_.c_str(), headers_string_.size()));
// The headers should parse successfully.
EXPECT_EQ(QUIC_STREAM_NO_ERROR, stream_->stream_error());
- EXPECT_EQ(200u, stream_->headers().parsed_response_code());
+ EXPECT_EQ(200, stream_->headers()->response_code());
EXPECT_CALL(*connection_,
SendRstStream(stream_->id(), QUIC_BAD_APPLICATION_PAYLOAD, 0));
@@ -98,7 +101,7 @@ TEST_P(QuicSpdyClientStreamTest, DISABLED_TestFramingExtraData) {
EXPECT_NE(QUIC_STREAM_NO_ERROR, stream_->stream_error());
}
-TEST_P(QuicSpdyClientStreamTest, TestNoBidirectionalStreaming) {
+TEST_P(QuicSimpleClientStreamTest, TestNoBidirectionalStreaming) {
QuicStreamFrame frame(3, false, 3, MakeIOVector("asd"));
EXPECT_FALSE(stream_->write_side_closed());
diff --git a/net/tools/quic/quic_simple_client_test.cc b/net/tools/quic/quic_simple_client_test.cc
index a72041c..e57cebb 100644
--- a/net/tools/quic/quic_simple_client_test.cc
+++ b/net/tools/quic/quic_simple_client_test.cc
@@ -2,73 +2,26 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include <dirent.h>
-#include <stdio.h>
+#include "net/tools/quic/quic_simple_client.h"
#include "base/basictypes.h"
#include "base/strings/string_util.h"
#include "net/quic/test_tools/quic_test_utils.h"
-#include "net/tools/epoll_server/epoll_server.h"
-#include "net/tools/quic/quic_client.h"
#include "testing/gtest/include/gtest/gtest.h"
-using net::EpollServer;
-
namespace net {
namespace tools {
namespace test {
-namespace {
-
-int NumOpenFDs() {
- int number_of_open_fds = 0;
- char buf[256];
- struct dirent* dp;
-
- base::snprintf(buf, arraysize(buf), "/proc/%i/fd/", getpid());
- DIR* dir = opendir(buf);
- while ((dp = readdir(dir)) != NULL)
- number_of_open_fds++;
- closedir(dir);
- return number_of_open_fds;
-}
-
-// Creates a new QuicClient and Initializes it. Caller is responsible for
-// deletion.
-QuicClient* CreateAndInitializeQuicClient(EpollServer* eps, uint16 port) {
- IPEndPoint server_address(IPEndPoint(net::test::Loopback4(), port));
+TEST(QuicSimpleClientTest, Initialize) {
+ IPEndPoint server_address(IPEndPoint(net::test::Loopback4(), 80));
QuicServerId server_id("hostname", server_address.port(), false,
PRIVACY_MODE_DISABLED);
QuicVersionVector versions = QuicSupportedVersions();
- QuicClient* client = new QuicClient(server_address, server_id, versions, eps);
- EXPECT_TRUE(client->Initialize());
- return client;
-}
-
-TEST(QuicClientTest, DoNotLeakFDs) {
- // Make sure that the QuicClient doesn't leak FDs. Doing so could cause port
- // exhaustion in long running processes which repeatedly create clients.
-
- // Record initial number of FDs, after creation of EpollServer.
- EpollServer eps;
- int number_of_open_fds = NumOpenFDs();
-
- // Create a number of clients, initialize them, and verify this has resulted
- // in additional FDs being opened.
- const int kNumClients = 5;
- for (int i = 0; i < kNumClients; ++i) {
- std::unique_ptr<QuicClient> client(
- CreateAndInitializeQuicClient(&eps, net::test::kTestPort + i));
-
- // Initializing the client will create a new FD.
- EXPECT_LT(number_of_open_fds, NumOpenFDs());
- }
-
- // The FDs created by the QuicClients should now be closed.
- EXPECT_EQ(number_of_open_fds, NumOpenFDs());
+ QuicSimpleClient client(server_address, server_id, versions);
+ EXPECT_TRUE(client.Initialize());
}
-} // namespace
} // namespace test
} // namespace tools
} // namespace net