Chromium Code Reviews| Index: net/spdy/spdy_session_spdy2_unittest.cc |
| diff --git a/net/spdy/spdy_session_spdy2_unittest.cc b/net/spdy/spdy_session_spdy2_unittest.cc |
| index 50e8524bed738c310f304cc20133b9cc97ea8bcf..3222b029bcc1ecc4e5e86fe2c19c8bde49a8dfc6 100644 |
| --- a/net/spdy/spdy_session_spdy2_unittest.cc |
| +++ b/net/spdy/spdy_session_spdy2_unittest.cc |
| @@ -1386,4 +1386,141 @@ TEST_F(SpdySessionSpdy2Test, CancelStream) { |
| spdy_stream2 = NULL; |
| } |
| +namespace { |
|
Ryan Sleevi
2012/07/30 06:36:15
drive by nit:
According to http://www.chromium.or
Ryan Hamilton
2012/07/30 16:21:13
Done. I had thought it made more sense to put the
|
| + |
| +class ClosingDelegate : public SpdyStream::Delegate { |
| + public: |
| + ClosingDelegate(SpdyStream* stream) : stream_(stream) {} |
| + |
| + virtual bool OnSendHeadersComplete(int status) { |
|
Ryan Sleevi
2012/07/30 06:36:15
comment nit:
// SpdyStream::Delegate implementatio
Ryan Hamilton
2012/07/30 16:21:13
Done.
|
| + return false; |
| + } |
| + virtual int OnSendBody() { |
| + return OK; |
| + } |
| + virtual int OnSendBodyComplete(int status, bool* eof) { |
| + return OK; |
| + } |
| + virtual int OnResponseReceived(const SpdyHeaderBlock& response, |
| + base::Time response_time, |
| + int status) { |
| + return OK; |
| + } |
| + virtual void OnDataReceived(const char* data, int length) {} |
| + virtual void OnDataSent(int length) {} |
| + virtual void OnClose(int status) { |
| + stream_->Close(); |
| + } |
| + private: |
| + SpdyStream* stream_; |
| +}; |
| + |
| +} // namespace |
| + |
| +TEST_F(SpdySessionSpdy2Test, CloseSessionWithTwoCreatedStreams) { |
|
Ryan Sleevi
2012/07/30 06:36:15
minor nit: Comment about what the test tests ;-)
Ryan Hamilton
2012/07/30 16:21:13
Done.
|
| + MockConnect connect_data(SYNCHRONOUS, OK); |
| + // Request 1, at HIGHEST priority, will be cancelled before it writes data. |
| + // Request 2, at LOWEST priority, will be a full request and will be id 1. |
|
Ryan Sleevi
2012/07/30 06:36:15
BUG? I don't see where you test ID EQ 1 (see below
Ryan Hamilton
2012/07/30 16:21:13
Sorry, I copied this test from the previous test a
|
| + scoped_ptr<SpdyFrame> req2(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
| + MockWrite writes[] = { |
| + CreateMockWrite(*req2, 0), |
| + }; |
| + |
| + scoped_ptr<SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| + scoped_ptr<SpdyFrame> body2(ConstructSpdyBodyFrame(1, true)); |
| + MockRead reads[] = { |
| + CreateMockRead(*resp2, 1), |
| + CreateMockRead(*body2, 2), |
| + MockRead(ASYNC, 0, 3) // EOF |
| + }; |
| + |
| + SpdySessionDependencies session_deps; |
| + session_deps.host_resolver->set_synchronous_mode(true); |
| + |
| + DeterministicSocketData data(reads, arraysize(reads), |
| + writes, arraysize(writes)); |
| + data.set_connect_data(connect_data); |
| + session_deps.deterministic_socket_factory->AddSocketDataProvider(&data); |
| + |
| + SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| + session_deps.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); |
| + |
| + scoped_refptr<HttpNetworkSession> http_session( |
| + SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps)); |
| + |
| + const std::string kTestHost("www.foo.com"); |
| + const int kTestPort = 80; |
| + HostPortPair test_host_port_pair(kTestHost, kTestPort); |
| + HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct()); |
| + |
| + SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); |
| + |
| + // Create a session. |
| + EXPECT_FALSE(spdy_session_pool->HasSession(pair)); |
| + scoped_refptr<SpdySession> session = |
| + spdy_session_pool->Get(pair, BoundNetLog()); |
| + ASSERT_TRUE(spdy_session_pool->HasSession(pair)); |
| + |
| + scoped_refptr<TransportSocketParams> transport_params( |
| + new TransportSocketParams(test_host_port_pair, |
| + MEDIUM, |
| + false, |
| + false, |
| + OnHostResolutionCallback())); |
| + scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); |
| + EXPECT_EQ(OK, connection->Init(test_host_port_pair.ToString(), |
| + transport_params, MEDIUM, CompletionCallback(), |
| + http_session->GetTransportSocketPool( |
| + HttpNetworkSession::NORMAL_SOCKET_POOL), |
| + BoundNetLog())); |
| + EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); |
| + |
| + scoped_refptr<SpdyStream> spdy_stream1; |
| + TestCompletionCallback callback1; |
| + GURL url1("http://www.google.com"); |
| + EXPECT_EQ(OK, session->CreateStream(url1, HIGHEST, &spdy_stream1, |
| + BoundNetLog(), callback1.callback())); |
| + EXPECT_EQ(0u, spdy_stream1->stream_id()); |
| + |
| + scoped_refptr<SpdyStream> spdy_stream2; |
| + TestCompletionCallback callback2; |
| + GURL url2("http://www.google.com"); |
| + EXPECT_EQ(OK, session->CreateStream(url2, LOWEST, &spdy_stream2, |
| + BoundNetLog(), callback2.callback())); |
| + EXPECT_EQ(0u, spdy_stream2->stream_id()); |
|
Ryan Sleevi
2012/07/30 06:36:15
BUG? - Comment suggests it should be EQ 1
Ryan Hamilton
2012/07/30 16:21:13
No, the comment was bogus :<
|
| + |
| + scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock); |
| + (*headers)["method"] = "GET"; |
| + (*headers)["scheme"] = url1.scheme(); |
| + (*headers)["host"] = url1.host(); |
| + (*headers)["url"] = url1.path(); |
| + (*headers)["version"] = "HTTP/1.1"; |
| + scoped_ptr<SpdyHeaderBlock> headers2(new SpdyHeaderBlock); |
| + *headers2 = *headers; |
| + |
| + spdy_stream1->set_spdy_headers(headers.Pass()); |
| + EXPECT_TRUE(spdy_stream1->HasUrl()); |
| + ClosingDelegate delegate1(spdy_stream1.get()); |
| + spdy_stream1->SetDelegate(&delegate1); |
| + |
| + spdy_stream2->set_spdy_headers(headers2.Pass()); |
| + EXPECT_TRUE(spdy_stream2->HasUrl()); |
| + ClosingDelegate delegate2(spdy_stream2.get()); |
| + spdy_stream2->SetDelegate(&delegate2); |
| + |
| + spdy_stream1->SendRequest(false); |
| + spdy_stream2->SendRequest(false); |
| + |
| + EXPECT_EQ(0u, spdy_stream1->stream_id()); |
| + EXPECT_EQ(0u, spdy_stream2->stream_id()); |
| + |
| + session->CloseSessionOnError(ERR_ABORTED, true, ""); |
| + |
| + EXPECT_EQ(0u, spdy_stream1->stream_id()); |
| + EXPECT_EQ(0u, spdy_stream2->stream_id()); |
|
Ryan Sleevi
2012/07/30 06:36:15
Seems like the EXPECT_EQ here and on lines 1514-15
Ryan Hamilton
2012/07/30 16:21:13
I've revised this and added a comment that explain
|
| + |
| + spdy_stream1 = NULL; |
| + spdy_stream2 = NULL; |
| +} |
| + |
| } // namespace net |