| Index: net/spdy/spdy_stream_spdy2_unittest.cc
|
| diff --git a/net/spdy/spdy_stream_spdy2_unittest.cc b/net/spdy/spdy_stream_spdy2_unittest.cc
|
| index a27cacc78e99671a8d5042c0a071a8a8acfd430d..67461d5d5149ce5ca4b987972c11b71974a59193 100644
|
| --- a/net/spdy/spdy_stream_spdy2_unittest.cc
|
| +++ b/net/spdy/spdy_stream_spdy2_unittest.cc
|
| @@ -2,6 +2,9 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| +#include <cstddef>
|
| +#include <string>
|
| +
|
| #include "base/memory/ref_counted.h"
|
| #include "base/memory/scoped_ptr.h"
|
| #include "net/base/completion_callback.h"
|
| @@ -27,51 +30,9 @@ namespace test {
|
|
|
| namespace {
|
|
|
| -const SpdyHeaderInfo kSynStartHeader = {
|
| - SYN_STREAM,
|
| - 1,
|
| - 0,
|
| - ConvertRequestPriorityToSpdyPriority(LOWEST, 2),
|
| - CONTROL_FLAG_NONE,
|
| - false,
|
| - RST_STREAM_INVALID,
|
| - NULL,
|
| - 0,
|
| - DATA_FLAG_NONE
|
| -};
|
| -
|
| -const char* const kGetHeaders[] = {
|
| - "method",
|
| - "GET",
|
| - "scheme",
|
| - "http",
|
| - "host",
|
| - "www.google.com",
|
| - "url",
|
| - "/",
|
| - "version",
|
| - "HTTP/1.1",
|
| -};
|
| -
|
| -scoped_ptr<SpdyFrame> ConstructSpdyGetRequest() {
|
| - return scoped_ptr<SpdyFrame>(
|
| - ConstructSpdyPacket(
|
| - kSynStartHeader, NULL, 0, kGetHeaders, arraysize(kGetHeaders) / 2));
|
| -}
|
| -
|
| -scoped_ptr<SpdyHeaderBlock> ConstructSpdyGetHeaderBlock() {
|
| - scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock);
|
| - for (size_t i = 0; i < arraysize(kGetHeaders) / 2; ++i) {
|
| - (*headers)[kGetHeaders[2*i]] = kGetHeaders[2*i+1];
|
| - }
|
| - return headers.Pass();
|
| -}
|
| -
|
| -scoped_ptr<SpdyFrame> ConstructSpdyBodyFrame(const char* data, int length) {
|
| - BufferedSpdyFramer framer(kSpdyVersion2, false);
|
| - return scoped_ptr<SpdyFrame>(
|
| - framer.CreateDataFrame(1, data, length, DATA_FLAG_NONE));
|
| -}
|
| +const char kStreamUrl[] = "http://www.google.com/";
|
| +const char kPostBody[] = "\0hello!\xff";
|
| +const size_t kPostBodyLength = arraysize(kPostBody);
|
|
|
| class SpdyStreamSpdy2Test : public testing::Test {
|
| protected:
|
| @@ -110,10 +71,14 @@ class SpdyStreamSpdy2Test : public testing::Test {
|
| };
|
|
|
| TEST_F(SpdyStreamSpdy2Test, SendDataAfterOpen) {
|
| + GURL url(kStreamUrl);
|
| +
|
| session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_);
|
|
|
| - scoped_ptr<SpdyFrame> req = ConstructSpdyGetRequest();
|
| - scoped_ptr<SpdyFrame> msg = ConstructSpdyBodyFrame("\0hello!\xff", 8);
|
| + scoped_ptr<SpdyFrame> req(
|
| + ConstructSpdyPost(kStreamUrl, kPostBodyLength, NULL, 0));
|
| + scoped_ptr<SpdyFrame> msg(
|
| + ConstructSpdyBodyFrame(1, kPostBody, kPostBodyLength, false));
|
| MockWrite writes[] = {
|
| CreateMockWrite(*req),
|
| CreateMockWrite(*msg),
|
| @@ -121,9 +86,9 @@ TEST_F(SpdyStreamSpdy2Test, SendDataAfterOpen) {
|
| writes[0].sequence_number = 0;
|
| writes[1].sequence_number = 2;
|
|
|
| - scoped_ptr<SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1));
|
| + scoped_ptr<SpdyFrame> resp(ConstructSpdyPostSynReply(NULL, 0));
|
| scoped_ptr<SpdyFrame> echo(
|
| - ConstructSpdyBodyFrame("\0hello!\xff", 8));
|
| + ConstructSpdyBodyFrame(1, kPostBody, kPostBodyLength, false));
|
| MockRead reads[] = {
|
| CreateMockRead(*resp),
|
| CreateMockRead(*echo),
|
| @@ -141,16 +106,14 @@ TEST_F(SpdyStreamSpdy2Test, SendDataAfterOpen) {
|
| session_deps_.socket_factory->AddSocketDataProvider(&data);
|
|
|
| scoped_refptr<SpdySession> session(CreateSpdySession());
|
| - const char kStreamUrl[] = "http://www.google.com/";
|
| - GURL url(kStreamUrl);
|
|
|
| InitializeSpdySession(session, host_port_pair_);
|
|
|
| scoped_refptr<SpdyStream> stream =
|
| CreateStreamSynchronously(session, url, LOWEST, BoundNetLog());
|
| ASSERT_TRUE(stream.get() != NULL);
|
| - scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(8));
|
| - memcpy(buf->data(), "\0hello!\xff", 8);
|
| + scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(kPostBodyLength));
|
| + memcpy(buf->data(), kPostBody, kPostBodyLength);
|
|
|
| StreamDelegateSendImmediate delegate(
|
| stream.get(), scoped_ptr<SpdyHeaderBlock>(), buf.get());
|
| @@ -158,7 +121,8 @@ TEST_F(SpdyStreamSpdy2Test, SendDataAfterOpen) {
|
|
|
| EXPECT_FALSE(stream->HasUrl());
|
|
|
| - stream->set_spdy_headers(ConstructSpdyGetHeaderBlock());
|
| + stream->set_spdy_headers(
|
| + ConstructPostHeaderBlock(kStreamUrl, kPostBodyLength));
|
| EXPECT_TRUE(stream->HasUrl());
|
| EXPECT_EQ(kStreamUrl, stream->GetUrl().spec());
|
|
|
| @@ -169,8 +133,8 @@ TEST_F(SpdyStreamSpdy2Test, SendDataAfterOpen) {
|
| EXPECT_TRUE(delegate.send_headers_completed());
|
| EXPECT_EQ("200", delegate.GetResponseHeaderValue("status"));
|
| EXPECT_EQ("HTTP/1.1", delegate.GetResponseHeaderValue("version"));
|
| - EXPECT_EQ(std::string("\0hello!\xff", 8), delegate.received_data());
|
| - EXPECT_EQ(8, delegate.data_sent());
|
| + EXPECT_EQ(std::string(kPostBody, kPostBodyLength), delegate.received_data());
|
| + EXPECT_EQ(static_cast<int>(kPostBodyLength), delegate.data_sent());
|
| }
|
|
|
| TEST_F(SpdyStreamSpdy2Test, SendHeaderAndDataAfterOpen) {
|
| @@ -183,7 +147,8 @@ TEST_F(SpdyStreamSpdy2Test, SendHeaderAndDataAfterOpen) {
|
| "http://example.com"));
|
| scoped_ptr<SpdyFrame> expected_headers(ConstructSpdyWebSocketHeadersFrame(
|
| 1, "6", true));
|
| - scoped_ptr<SpdyFrame> expected_message = ConstructSpdyBodyFrame("hello!", 6);
|
| + scoped_ptr<SpdyFrame> expected_message(
|
| + ConstructSpdyBodyFrame(1, "hello!", 6, false));
|
| MockWrite writes[] = {
|
| CreateMockWrite(*expected_request),
|
| CreateMockWrite(*expected_headers),
|
| @@ -210,8 +175,7 @@ TEST_F(SpdyStreamSpdy2Test, SendHeaderAndDataAfterOpen) {
|
| session_deps_.socket_factory->AddSocketDataProvider(&data);
|
|
|
| scoped_refptr<SpdySession> session(CreateSpdySession());
|
| - const char kStreamUrl[] = "ws://server.example.com/chat";
|
| - GURL url(kStreamUrl);
|
| + GURL url("ws://server.example.com/chat");
|
|
|
| HostPortPair host_port_pair("server.example.com", 80);
|
| InitializeSpdySession(session, host_port_pair);
|
| @@ -253,8 +217,6 @@ TEST_F(SpdyStreamSpdy2Test, SendHeaderAndDataAfterOpen) {
|
| }
|
|
|
| TEST_F(SpdyStreamSpdy2Test, PushedStream) {
|
| - const char kStreamUrl[] = "http://www.google.com/";
|
| -
|
| SpdySessionDependencies session_deps;
|
| session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_);
|
| scoped_refptr<SpdySession> spdy_session(CreateSpdySession());
|
| @@ -298,11 +260,14 @@ TEST_F(SpdyStreamSpdy2Test, PushedStream) {
|
| }
|
|
|
| TEST_F(SpdyStreamSpdy2Test, StreamError) {
|
| + GURL url(kStreamUrl);
|
| +
|
| session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_);
|
|
|
| - scoped_ptr<SpdyFrame> req = ConstructSpdyGetRequest();
|
| + scoped_ptr<SpdyFrame> req(
|
| + ConstructSpdyPost(kStreamUrl, kPostBodyLength, NULL, 0));
|
| scoped_ptr<SpdyFrame> msg(
|
| - ConstructSpdyBodyFrame("\0hello!\xff", 8));
|
| + ConstructSpdyBodyFrame(1, kPostBody, kPostBodyLength, false));
|
| MockWrite writes[] = {
|
| CreateMockWrite(*req),
|
| CreateMockWrite(*msg),
|
| @@ -312,7 +277,7 @@ TEST_F(SpdyStreamSpdy2Test, StreamError) {
|
|
|
| scoped_ptr<SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1));
|
| scoped_ptr<SpdyFrame> echo(
|
| - ConstructSpdyBodyFrame("\0hello!\xff", 8));
|
| + ConstructSpdyBodyFrame(1, kPostBody, kPostBodyLength, false));
|
| MockRead reads[] = {
|
| CreateMockRead(*resp),
|
| CreateMockRead(*echo),
|
| @@ -332,16 +297,14 @@ TEST_F(SpdyStreamSpdy2Test, StreamError) {
|
| session_deps_.socket_factory->AddSocketDataProvider(&data);
|
|
|
| scoped_refptr<SpdySession> session(CreateSpdySession());
|
| - const char kStreamUrl[] = "http://www.google.com/";
|
| - GURL url(kStreamUrl);
|
|
|
| InitializeSpdySession(session, host_port_pair_);
|
|
|
| scoped_refptr<SpdyStream> stream =
|
| CreateStreamSynchronously(session, url, LOWEST, log.bound());
|
| ASSERT_TRUE(stream.get() != NULL);
|
| - scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(8));
|
| - memcpy(buf->data(), "\0hello!\xff", 8);
|
| + scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(kPostBodyLength));
|
| + memcpy(buf->data(), kPostBody, kPostBodyLength);
|
|
|
| StreamDelegateSendImmediate delegate(
|
| stream.get(), scoped_ptr<SpdyHeaderBlock>(), buf.get());
|
| @@ -349,7 +312,8 @@ TEST_F(SpdyStreamSpdy2Test, StreamError) {
|
|
|
| EXPECT_FALSE(stream->HasUrl());
|
|
|
| - stream->set_spdy_headers(ConstructSpdyGetHeaderBlock());
|
| + stream->set_spdy_headers(
|
| + ConstructPostHeaderBlock(kStreamUrl, kPostBodyLength));
|
| EXPECT_TRUE(stream->HasUrl());
|
| EXPECT_EQ(kStreamUrl, stream->GetUrl().spec());
|
|
|
| @@ -362,8 +326,8 @@ TEST_F(SpdyStreamSpdy2Test, StreamError) {
|
| EXPECT_TRUE(delegate.send_headers_completed());
|
| EXPECT_EQ("200", delegate.GetResponseHeaderValue("status"));
|
| EXPECT_EQ("HTTP/1.1", delegate.GetResponseHeaderValue("version"));
|
| - EXPECT_EQ(std::string("\0hello!\xff", 8), delegate.received_data());
|
| - EXPECT_EQ(8, delegate.data_sent());
|
| + EXPECT_EQ(std::string(kPostBody, kPostBodyLength), delegate.received_data());
|
| + EXPECT_EQ(static_cast<int>(kPostBodyLength), delegate.data_sent());
|
|
|
| // Check that the NetLog was filled reasonably.
|
| net::CapturingNetLog::CapturedEntryList entries;
|
|
|