| 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..7f96b5fa69d1f1da50fc6cecd244d1b6aa0d2c32 100644
|
| --- a/net/spdy/spdy_session_spdy2_unittest.cc
|
| +++ b/net/spdy/spdy_session_spdy2_unittest.cc
|
| @@ -15,6 +15,8 @@
|
|
|
| using namespace net::test_spdy2;
|
|
|
| +namespace net {
|
| +
|
| namespace {
|
|
|
| base::TimeTicks the_near_future() {
|
| @@ -22,9 +24,35 @@ base::TimeTicks the_near_future() {
|
| base::TimeDelta::FromSeconds(301);
|
| }
|
|
|
| -} // namespace
|
| +class ClosingDelegate : public SpdyStream::Delegate {
|
| + public:
|
| + ClosingDelegate(SpdyStream* stream) : stream_(stream) {}
|
|
|
| -namespace net {
|
| + // SpdyStream::Delegate implementation:
|
| + virtual bool OnSendHeadersComplete(int status) OVERRIDE {
|
| + return true;
|
| + }
|
| + virtual int OnSendBody() OVERRIDE {
|
| + return OK;
|
| + }
|
| + virtual int OnSendBodyComplete(int status, bool* eof) OVERRIDE {
|
| + return OK;
|
| + }
|
| + virtual int OnResponseReceived(const SpdyHeaderBlock& response,
|
| + base::Time response_time,
|
| + int status) OVERRIDE {
|
| + return OK;
|
| + }
|
| + virtual void OnDataReceived(const char* data, int length) OVERRIDE {}
|
| + virtual void OnDataSent(int length) OVERRIDE {}
|
| + virtual void OnClose(int status) OVERRIDE {
|
| + stream_->Close();
|
| + }
|
| + private:
|
| + SpdyStream* stream_;
|
| +};
|
| +
|
| +} // namespace
|
|
|
| // TODO(cbentzel): Expose compression setter/getter in public SpdySession
|
| // interface rather than going through all these contortions.
|
| @@ -1386,4 +1414,107 @@ TEST_F(SpdySessionSpdy2Test, CancelStream) {
|
| spdy_stream2 = NULL;
|
| }
|
|
|
| +TEST_F(SpdySessionSpdy2Test, CloseSessionWithTwoCreatedStreams) {
|
| + // Test that if a sesion is closed with two created streams pending,
|
| + // it does not crash. http://crbug.com/139518
|
| + MockConnect connect_data(SYNCHRONOUS, OK);
|
| + SpdySessionDependencies session_deps;
|
| + session_deps.host_resolver->set_synchronous_mode(true);
|
| +
|
| + // No actual data will be sent.
|
| + MockWrite writes[] = {
|
| + MockWrite(ASYNC, 0, 1) // EOF
|
| + };
|
| +
|
| + MockRead reads[] = {
|
| + MockRead(ASYNC, 0, 0) // EOF
|
| + };
|
| + 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());
|
| +
|
| + 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);
|
| +
|
| + // Ensure that the streams have not yet been activated and assigned an id.
|
| + EXPECT_EQ(0u, spdy_stream1->stream_id());
|
| + EXPECT_EQ(0u, spdy_stream2->stream_id());
|
| +
|
| + // Ensure we don't crash while closing the session.
|
| + session->CloseSessionOnError(ERR_ABORTED, true, "");
|
| +
|
| + EXPECT_TRUE(spdy_stream1->closed());
|
| + EXPECT_TRUE(spdy_stream2->closed());
|
| +
|
| + spdy_stream1 = NULL;
|
| + spdy_stream2 = NULL;
|
| +}
|
| +
|
| } // namespace net
|
|
|