Chromium Code Reviews| Index: net/spdy/spdy_http_stream_spdy2_unittest.cc |
| =================================================================== |
| --- net/spdy/spdy_http_stream_spdy2_unittest.cc (revision 144839) |
| +++ net/spdy/spdy_http_stream_spdy2_unittest.cc (working copy) |
| @@ -124,14 +124,14 @@ |
| scoped_ptr<SpdyFrame> chunk1(ConstructSpdyBodyFrame(1, false)); |
| scoped_ptr<SpdyFrame> chunk2(ConstructSpdyBodyFrame(1, true)); |
| MockWrite writes[] = { |
| - CreateMockWrite(*req.get(), 1), |
| - CreateMockWrite(*chunk1, 2), // POST upload frames |
| - CreateMockWrite(*chunk2, 3), |
| + CreateMockWrite(*req.get(), 0), |
| + CreateMockWrite(*chunk1, 1), // POST upload frames |
| + CreateMockWrite(*chunk2, 2), |
| }; |
| scoped_ptr<SpdyFrame> resp(ConstructSpdyPostSynReply(NULL, 0)); |
| MockRead reads[] = { |
| - CreateMockRead(*resp, 4), |
| - CreateMockRead(*chunk1, 5), |
| + CreateMockRead(*resp, 3), |
| + CreateMockRead(*chunk1, 4), |
| CreateMockRead(*chunk2, 5), |
| MockRead(SYNCHRONOUS, 0, 6) // EOF |
| }; |
| @@ -178,6 +178,109 @@ |
| EXPECT_TRUE(data()->at_write_eof()); |
| } |
| +TEST_F(SpdyHttpStreamSpdy2Test, DelayedSendChunkedPost) { |
|
Ryan Hamilton
2012/07/02 22:34:32
Does this test fail when run w/o your changes to t
ramant (doing other things)
2012/07/04 21:04:33
It doesn't fail. IMO, it is just new test.
|
| + UploadDataStream::set_merge_chunks(false); |
| + |
| + scoped_ptr<SpdyFrame> req(ConstructChunkedSpdyPost(NULL, 0)); |
| + scoped_ptr<SpdyFrame> chunk1(ConstructSpdyBodyFrame(1, false)); |
| + scoped_ptr<SpdyFrame> chunk2(ConstructSpdyBodyFrame(1, true)); |
| + MockWrite writes[] = { |
| + CreateMockWrite(*req.get(), 0), |
| + CreateMockWrite(*chunk1, 1), // POST upload frames |
| + CreateMockWrite(*chunk2, 2), |
| + }; |
| + scoped_ptr<SpdyFrame> resp(ConstructSpdyPostSynReply(NULL, 0)); |
| + MockRead reads[] = { |
| + CreateMockRead(*resp, 3), |
| + CreateMockRead(*chunk1, 4), |
| + CreateMockRead(*chunk2, 5), |
| + MockRead(ASYNC, 0, 6) // EOF |
| + }; |
| + |
| + HostPortPair host_port_pair("www.google.com", 80); |
| + HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); |
| + |
| + scoped_refptr<DeterministicSocketData> data( |
| + new DeterministicSocketData(reads, arraysize(reads), |
| + writes, arraysize(writes))); |
| + |
| + DeterministicMockClientSocketFactory* socket_factory = |
| + session_deps_.deterministic_socket_factory.get(); |
| + socket_factory->AddSocketDataProvider(data.get()); |
| + |
| + http_session_ = SpdySessionDependencies::SpdyCreateSessionDeterministic( |
| + &session_deps_); |
| + session_ = http_session_->spdy_session_pool()->Get(pair, BoundNetLog()); |
| + transport_params_ = new TransportSocketParams(host_port_pair, |
| + MEDIUM, false, false, |
| + OnHostResolutionCallback()); |
| + |
| + TestCompletionCallback callback0; |
| + scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); |
| + |
| + EXPECT_EQ(ERR_IO_PENDING, |
| + connection->Init(host_port_pair.ToString(), |
| + transport_params_, |
| + MEDIUM, |
| + callback0.callback(), |
| + http_session_->GetTransportSocketPool( |
| + HttpNetworkSession::NORMAL_SOCKET_POOL), |
| + BoundNetLog())); |
| + |
| + callback0.WaitForResult(); |
| + EXPECT_EQ(OK, |
| + session_->InitializeWithSocket(connection.release(), false, OK)); |
| + |
| + HttpRequestInfo request; |
| + request.method = "POST"; |
| + request.url = GURL("http://www.google.com/"); |
| + request.upload_data = new UploadData(); |
| + request.upload_data->set_is_chunked(true); |
| + |
| + BoundNetLog net_log; |
| + scoped_ptr<SpdyHttpStream> http_stream( |
| + new SpdyHttpStream(session_.get(), true)); |
| + ASSERT_EQ( |
| + OK, |
| + http_stream->InitializeStream(&request, net_log, CompletionCallback())); |
| + |
| + scoped_ptr<UploadDataStream> upload_stream( |
| + new UploadDataStream(request.upload_data)); |
| + ASSERT_EQ(OK, upload_stream->Init()); |
| + |
| + request.upload_data->AppendChunk(kUploadData, kUploadDataSize, false); |
| + |
| + TestCompletionCallback callback; |
| + HttpRequestHeaders headers; |
| + HttpResponseInfo response; |
| + // This will attempt to Write() the initial request and headers, which will |
| + // complete asynchronously. |
| + EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest( |
| + headers, upload_stream.Pass(), &response, callback.callback())); |
| + EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(pair)); |
| + |
| + // Complete the initial request write. Additionally, this should enqueue the |
| + // first chunk. |
| + data->RunFor(1); |
| + |
| + // Now append final chunk. This will enqueue another write. |
| + request.upload_data->AppendChunk(kUploadData, kUploadDataSize, true); |
| + |
| + // Finalize writing the last chunk, which will enqueue the trailer. |
| + data->RunFor(3); |
| + int rv = callback.WaitForResult(); |
| + EXPECT_GT(rv, 0); |
| + |
| + data->RunFor(2); |
| + EXPECT_EQ(OK, http_stream->ReadResponseHeaders(callback.callback())); |
| + |
| + data->RunFor(1); |
| + ASSERT_TRUE(response.headers.get() != NULL); |
| + ASSERT_EQ(200, response.headers->response_code()); |
| + EXPECT_TRUE(data->at_read_eof()); |
| + EXPECT_TRUE(data->at_write_eof()); |
| +} |
| + |
| // Test case for bug: http://code.google.com/p/chromium/issues/detail?id=50058 |
| TEST_F(SpdyHttpStreamSpdy2Test, SpdyURLTest) { |
| const char * const full_url = "http://www.google.com/foo?query=what#anchor"; |