Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(440)

Unified Diff: net/spdy/spdy_http_stream_unittest.cc

Issue 1309663003: Implemented SpdyHttpStream::GetTotalSentBytes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@http_stream_sent_bytes
Patch Set: Addressed comments Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/spdy/spdy_http_stream.cc ('k') | net/spdy/spdy_session.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/spdy/spdy_http_stream_unittest.cc
diff --git a/net/spdy/spdy_http_stream_unittest.cc b/net/spdy/spdy_http_stream_unittest.cc
index 09e4fcc542d855d7778d038c3bf718b45f04512b..69ad12c8474946bc4ee29286c4e615c992febce3 100644
--- a/net/spdy/spdy_http_stream_unittest.cc
+++ b/net/spdy/spdy_http_stream_unittest.cc
@@ -4,6 +4,8 @@
#include "net/spdy/spdy_http_stream.h"
+#include <stdint.h>
+
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
@@ -186,6 +188,11 @@ TEST_P(SpdyHttpStreamTest, SendRequest) {
// Test that there's no crash when trying to get the load timing after the
// stream has been closed.
TestLoadTimingNotReused(*http_stream);
+
+ EXPECT_EQ(static_cast<int64_t>(req->size()),
+ http_stream->GetTotalSentBytes());
+ EXPECT_EQ(static_cast<int64_t>(resp->size()),
+ http_stream->GetTotalReceivedBytes());
}
TEST_P(SpdyHttpStreamTest, LoadTimingTwoRequests) {
@@ -273,8 +280,19 @@ TEST_P(SpdyHttpStreamTest, LoadTimingTwoRequests) {
// Stream 1 has been read to completion.
TestLoadTimingNotReused(*http_stream1);
+
+ EXPECT_EQ(static_cast<int64_t>(req1->size()),
+ http_stream1->GetTotalSentBytes());
+ EXPECT_EQ(static_cast<int64_t>(resp1->size() + body1->size()),
+ http_stream1->GetTotalReceivedBytes());
+
// Stream 2 still has queued body data.
TestLoadTimingReused(*http_stream2);
+
+ EXPECT_EQ(static_cast<int64_t>(req2->size()),
+ http_stream2->GetTotalSentBytes());
+ EXPECT_EQ(static_cast<int64_t>(resp2->size() + body2->size()),
+ http_stream2->GetTotalReceivedBytes());
}
TEST_P(SpdyHttpStreamTest, SendChunkedPost) {
@@ -331,6 +349,11 @@ TEST_P(SpdyHttpStreamTest, SendChunkedPost) {
EXPECT_EQ(OK, callback.WaitForResult());
+ EXPECT_EQ(static_cast<int64_t>(req->size() + body->size()),
+ http_stream.GetTotalSentBytes());
+ EXPECT_EQ(static_cast<int64_t>(resp->size() + body->size()),
+ http_stream.GetTotalReceivedBytes());
+
// Because the server closed the connection, we there shouldn't be a session
// in the pool anymore.
EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key));
@@ -383,6 +406,10 @@ TEST_P(SpdyHttpStreamTest, ConnectionClosedDuringChunkedPost) {
EXPECT_EQ(OK, callback.WaitForResult());
+ EXPECT_EQ(static_cast<int64_t>(req->size() + body->size()),
+ http_stream.GetTotalSentBytes());
+ EXPECT_EQ(0, http_stream.GetTotalReceivedBytes());
+
// Because the server closed the connection, we there shouldn't be a session
// in the pool anymore.
EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key));
@@ -392,6 +419,11 @@ TEST_P(SpdyHttpStreamTest, ConnectionClosedDuringChunkedPost) {
// Appending data is currently done synchronously, but seems best to be
// paranoid.
base::RunLoop().RunUntilIdle();
+
+ // The total sent and received bytes should be unchanged.
+ EXPECT_EQ(static_cast<int64_t>(req->size() + body->size()),
+ http_stream.GetTotalSentBytes());
+ EXPECT_EQ(0, http_stream.GetTotalReceivedBytes());
}
// Test to ensure the SpdyStream state machine does not get confused when a
@@ -461,6 +493,13 @@ TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPost) {
// Finish writing all the chunks and do all reads.
base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size() + chunk2->size() +
+ chunk3->size()),
+ http_stream->GetTotalSentBytes());
+ EXPECT_EQ(static_cast<int64_t>(resp->size() + chunk1->size() +
+ chunk2->size() + chunk3->size()),
+ http_stream->GetTotalReceivedBytes());
+
// Check response headers.
ASSERT_EQ(OK, http_stream->ReadResponseHeaders(callback.callback()));
@@ -543,6 +582,10 @@ TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPostWithEmptyFinalDataFrame) {
ASSERT_TRUE(callback.have_result());
EXPECT_EQ(OK, callback.WaitForResult());
+ EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size()),
+ http_stream->GetTotalSentBytes());
+ EXPECT_EQ(0, http_stream->GetTotalReceivedBytes());
+
// Now end the stream with an empty data frame and the FIN set.
upload_stream.AppendData(NULL, 0, true);
@@ -552,6 +595,12 @@ TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPostWithEmptyFinalDataFrame) {
// Check response headers.
ASSERT_EQ(OK, http_stream->ReadResponseHeaders(callback.callback()));
+ EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size() + chunk2->size()),
+ http_stream->GetTotalSentBytes());
+ EXPECT_EQ(
+ static_cast<int64_t>(resp->size() + chunk1->size() + chunk2->size()),
+ http_stream->GetTotalReceivedBytes());
+
// Check |chunk1| response.
scoped_refptr<IOBuffer> buf1(new IOBuffer(kUploadDataSize));
ASSERT_EQ(kUploadDataSize,
@@ -619,6 +668,11 @@ TEST_P(SpdyHttpStreamTest, ChunkedPostWithEmptyPayload) {
ASSERT_TRUE(callback.have_result());
EXPECT_EQ(OK, callback.WaitForResult());
+ EXPECT_EQ(static_cast<int64_t>(req->size() + chunk->size()),
+ http_stream->GetTotalSentBytes());
+ EXPECT_EQ(static_cast<int64_t>(resp->size() + chunk->size()),
+ http_stream->GetTotalReceivedBytes());
+
// Check response headers.
ASSERT_EQ(OK, http_stream->ReadResponseHeaders(callback.callback()));
@@ -670,6 +724,11 @@ TEST_P(SpdyHttpStreamTest, SpdyURLTest) {
callback.WaitForResult();
+ EXPECT_EQ(static_cast<int64_t>(req->size()),
+ http_stream->GetTotalSentBytes());
+ EXPECT_EQ(static_cast<int64_t>(resp->size()),
+ http_stream->GetTotalReceivedBytes());
+
// Because we abandoned the stream, we don't expect to find a session in the
// pool anymore.
EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key));
@@ -729,6 +788,10 @@ TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPostWithWindowUpdate) {
ASSERT_TRUE(callback.have_result());
EXPECT_EQ(OK, callback.WaitForResult());
+ EXPECT_EQ(static_cast<int64_t>(req->size()),
+ http_stream->GetTotalSentBytes());
+ EXPECT_EQ(0, http_stream->GetTotalReceivedBytes());
+
upload_stream.AppendData(kUploadData, kUploadDataSize, true);
// Verify that the window size has decreased.
@@ -740,6 +803,11 @@ TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPostWithWindowUpdate) {
// Read window update.
base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size()),
+ http_stream->GetTotalSentBytes());
+ // The window update is not counted in the total received bytes.
+ EXPECT_EQ(0, http_stream->GetTotalReceivedBytes());
+
// Verify the window update.
ASSERT_TRUE(http_stream->stream() != NULL);
EXPECT_EQ(static_cast<int>(
@@ -750,6 +818,11 @@ TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPostWithWindowUpdate) {
sequenced_data_->CompleteRead();
base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size()),
+ http_stream->GetTotalSentBytes());
+ EXPECT_EQ(static_cast<int64_t>(resp->size() + chunk1->size()),
+ http_stream->GetTotalReceivedBytes());
+
// Check response headers.
ASSERT_EQ(OK, http_stream->ReadResponseHeaders(callback.callback()));
« no previous file with comments | « net/spdy/spdy_http_stream.cc ('k') | net/spdy/spdy_session.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698