src/net/spdy/spdy_stream_unittest.cc
TEST_F(SpdyStreamTest, SendLargeDataAfterOpenBidirectional) {
  spdy::SpdySerializedFrame req(spdy_util_.ConstructSpdyPost(
      kDefaultUrl, 1, kPostBodyLength, LOWEST, nullptr, 0));
  AddWrite(req);

  spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyPostReply(nullptr, 0));
  AddRead(resp);

  std::string chunk_data(kMaxSpdyFrameChunkSize, 'x');
  spdy::SpdySerializedFrame chunk(
      spdy_util_.ConstructSpdyDataFrame(1, chunk_data, false));
  AddWrite(chunk);
  AddWrite(chunk);
  AddWrite(chunk);

  AddReadEOF();

  SequencedSocketData data(GetReads(), GetWrites());
  MockConnect connect_data(SYNCHRONOUS, OK);
  data.set_connect_data(connect_data);
  session_deps_.socket_factory->AddSocketDataProvider(&data);

  AddSSLSocketData();

  base::WeakPtr<SpdySession> session(CreateDefaultSpdySession());

  base::WeakPtr<SpdyStream> stream = CreateStreamSynchronously(
      SPDY_BIDIRECTIONAL_STREAM, session, url_, LOWEST, NetLogWithSource());
  ASSERT_TRUE(stream);
  EXPECT_EQ(kDefaultUrl, stream->url().spec());

  std::string body_data(3 * kMaxSpdyFrameChunkSize, 'x');
  StreamDelegateSendImmediate delegate(stream, body_data);
  stream->SetDelegate(&delegate);

  spdy::SpdyHeaderBlock headers(
      spdy_util_.ConstructPostHeaderBlock(kDefaultUrl, kPostBodyLength));
  EXPECT_THAT(stream->SendRequestHeaders(std::move(headers), MORE_DATA_TO_SEND),
              IsError(ERR_IO_PENDING));

  EXPECT_THAT(delegate.WaitForClose(), IsError(ERR_CONNECTION_CLOSED));

  EXPECT_TRUE(delegate.send_headers_completed());
  EXPECT_EQ("200", delegate.GetResponseHeaderValue(spdy::kHttp2StatusHeader));
  EXPECT_EQ(std::string(), delegate.TakeReceivedData());
  EXPECT_TRUE(data.AllWriteDataConsumed());
}
// Make sure that large blocks of data are properly split up into frame-sized
// chunks for a bidirectional (i.e., non-HTTP-like) stream.
Make sure that large blocks of data are properly split up into frame-sized
chunks for a bidirectional  stream.
Make sure that large blocks of data are properly split up into frame - sized chunks for a bidirectional stream .
TEST_F(SpdyStreamTest, SendLargeDataAfterOpenBidirectional) {
  spdy::SpdySerializedFrame req(spdy_util_.ConstructSpdyPost(
      kDefaultUrl, 1, kPostBodyLength, LOWEST, nullptr, 0));
  AddWrite(req);
  spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyPostReply(nullptr, 0));
  AddRead(resp);
  std::string chunk_data(kMaxSpdyFrameChunkSize, 'x');
  spdy::SpdySerializedFrame chunk(
      spdy_util_.ConstructSpdyDataFrame(1, chunk_data, false));
  AddWrite(chunk);
  AddWrite(chunk);
  AddWrite(chunk);
  AddReadEOF();
  SequencedSocketData data(GetReads(), GetWrites());
  MockConnect connect_data(SYNCHRONOUS, OK);
  data.set_connect_data(connect_data);
  session_deps_.socket_factory->AddSocketDataProvider(&data);
  AddSSLSocketData();
  base::WeakPtr<SpdySession> session(CreateDefaultSpdySession());
  base::WeakPtr<SpdyStream> stream = CreateStreamSynchronously(
      SPDY_BIDIRECTIONAL_STREAM, session, url_, LOWEST, NetLogWithSource());
  ASSERT_TRUE(stream);
  EXPECT_EQ(kDefaultUrl, stream->url().spec());
  std::string body_data(3 * kMaxSpdyFrameChunkSize, 'x');
  StreamDelegateSendImmediate delegate(stream, body_data);
  stream->SetDelegate(&delegate);
  spdy::SpdyHeaderBlock headers(
      spdy_util_.ConstructPostHeaderBlock(kDefaultUrl, kPostBodyLength));
  EXPECT_THAT(stream->SendRequestHeaders(std::move(headers), MORE_DATA_TO_SEND),
              IsError(ERR_IO_PENDING));
  EXPECT_THAT(delegate.WaitForClose(), IsError(ERR_CONNECTION_CLOSED));
  EXPECT_TRUE(delegate.send_headers_completed());
  EXPECT_EQ("200", delegate.GetResponseHeaderValue(spdy::kHttp2StatusHeader));
  EXPECT_EQ(std::string(), delegate.TakeReceivedData());
  EXPECT_TRUE(data.AllWriteDataConsumed());
}
TEST_F ( SpdyStreamTest , SendLargeDataAfterOpenBidirectional ) { spdy :: SpdySerializedFrame req ( spdy_util_ . ConstructSpdyPost ( kDefaultUrl , 1 , kPostBodyLength , LOWEST , nullptr , 0 ) ) ; AddWrite ( req ) ; spdy :: SpdySerializedFrame resp ( spdy_util_ . ConstructSpdyPostReply ( nullptr , 0 ) ) ; AddRead ( resp ) ; std :: string chunk_data ( kMaxSpdyFrameChunkSize , ' ' ) ; spdy :: SpdySerializedFrame chunk ( spdy_util_ . ConstructSpdyDataFrame ( 1 , chunk_data , false ) ) ; AddWrite ( chunk ) ; AddWrite ( chunk ) ; AddWrite ( chunk ) ; AddReadEOF ( ) ; SequencedSocketData data ( GetReads ( ) , GetWrites ( ) ) ; MockConnect connect_data ( SYNCHRONOUS , OK ) ; data . set_connect_data ( connect_data ) ; session_deps_ . socket_factory -> AddSocketDataProvider ( & data ) ; AddSSLSocketData ( ) ; base :: WeakPtr < SpdySession > session ( CreateDefaultSpdySession ( ) ) ; base :: WeakPtr < SpdyStream > stream = CreateStreamSynchronously ( SPDY_BIDIRECTIONAL_STREAM , session , url_ , LOWEST , NetLogWithSource ( ) ) ; ASSERT_TRUE ( stream ) ; EXPECT_EQ ( kDefaultUrl , stream -> url ( ) . spec ( ) ) ; std :: string body_data ( 3 * kMaxSpdyFrameChunkSize , ' ' ) ; StreamDelegateSendImmediate delegate ( stream , body_data ) ; stream -> SetDelegate ( & delegate ) ; spdy :: SpdyHeaderBlock headers ( spdy_util_ . ConstructPostHeaderBlock ( kDefaultUrl , kPostBodyLength ) ) ; EXPECT_THAT ( stream -> SendRequestHeaders ( std :: move ( headers ) , MORE_DATA_TO_SEND ) , IsError ( ERR_IO_PENDING ) ) ; EXPECT_THAT ( delegate . WaitForClose ( ) , IsError ( ERR_CONNECTION_CLOSED ) ) ; EXPECT_TRUE ( delegate . send_headers_completed ( ) ) ; EXPECT_EQ ( " " , delegate . GetResponseHeaderValue ( spdy :: kHttp2StatusHeader ) ) ; EXPECT_EQ ( std :: string ( ) , delegate . TakeReceivedData ( ) ) ; EXPECT_TRUE ( data . AllWriteDataConsumed ( ) ) ; }
Make sure that large blocks of data are properly split up into frame-sized
chunks for a bidirectional (i.e., non-HTTP-like) stream.
Make sure that large blocks of data are properly split up into frame - sized chunks for a bidirectional ( i . e . non - HTTP - like ) stream .