OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/spdy/spdy_session.h" | 5 #include "net/spdy/spdy_session.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 2977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2988 EXPECT_FALSE(stream->send_stalled_by_flow_control()); | 2988 EXPECT_FALSE(stream->send_stalled_by_flow_control()); |
2989 | 2989 |
2990 data.RunFor(3); | 2990 data.RunFor(3); |
2991 | 2991 |
2992 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); | 2992 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); |
2993 | 2993 |
2994 EXPECT_TRUE(delegate.send_headers_completed()); | 2994 EXPECT_TRUE(delegate.send_headers_completed()); |
2995 EXPECT_EQ("200", delegate.GetResponseHeaderValue(":status")); | 2995 EXPECT_EQ("200", delegate.GetResponseHeaderValue(":status")); |
2996 EXPECT_EQ("HTTP/1.1", delegate.GetResponseHeaderValue(":version")); | 2996 EXPECT_EQ("HTTP/1.1", delegate.GetResponseHeaderValue(":version")); |
2997 EXPECT_EQ(std::string(), delegate.TakeReceivedData()); | 2997 EXPECT_EQ(std::string(), delegate.TakeReceivedData()); |
2998 EXPECT_EQ(static_cast<int>(kBodyDataSize), delegate.body_data_sent()); | 2998 EXPECT_TRUE(data.at_write_eof()); |
2999 } | 2999 } |
3000 | 3000 |
3001 // Run the resume-after-unstall test with all possible stall and | 3001 // Run the resume-after-unstall test with all possible stall and |
3002 // unstall sequences. | 3002 // unstall sequences. |
3003 | 3003 |
3004 TEST_F(SpdySessionSpdy3Test, ResumeAfterUnstallSession31) { | 3004 TEST_F(SpdySessionSpdy3Test, ResumeAfterUnstallSession31) { |
3005 RunResumeAfterUnstallTest31( | 3005 RunResumeAfterUnstallTest31( |
3006 base::Bind(&SpdySessionSpdy3Test::StallSessionOnly, | 3006 base::Bind(&SpdySessionSpdy3Test::StallSessionOnly, |
3007 base::Unretained(this)), | 3007 base::Unretained(this)), |
3008 base::Bind(&SpdySessionSpdy3Test::UnstallSessionOnly, | 3008 base::Bind(&SpdySessionSpdy3Test::UnstallSessionOnly, |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3171 | 3171 |
3172 data.RunFor(4); | 3172 data.RunFor(4); |
3173 | 3173 |
3174 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate1.WaitForClose()); | 3174 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate1.WaitForClose()); |
3175 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate2.WaitForClose()); | 3175 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate2.WaitForClose()); |
3176 | 3176 |
3177 EXPECT_TRUE(delegate1.send_headers_completed()); | 3177 EXPECT_TRUE(delegate1.send_headers_completed()); |
3178 EXPECT_EQ("200", delegate1.GetResponseHeaderValue(":status")); | 3178 EXPECT_EQ("200", delegate1.GetResponseHeaderValue(":status")); |
3179 EXPECT_EQ("HTTP/1.1", delegate1.GetResponseHeaderValue(":version")); | 3179 EXPECT_EQ("HTTP/1.1", delegate1.GetResponseHeaderValue(":version")); |
3180 EXPECT_EQ(std::string(), delegate1.TakeReceivedData()); | 3180 EXPECT_EQ(std::string(), delegate1.TakeReceivedData()); |
3181 EXPECT_EQ(static_cast<int>(kBodyDataSize), delegate1.body_data_sent()); | |
3182 | 3181 |
3183 EXPECT_TRUE(delegate2.send_headers_completed()); | 3182 EXPECT_TRUE(delegate2.send_headers_completed()); |
3184 EXPECT_EQ("200", delegate2.GetResponseHeaderValue(":status")); | 3183 EXPECT_EQ("200", delegate2.GetResponseHeaderValue(":status")); |
3185 EXPECT_EQ("HTTP/1.1", delegate2.GetResponseHeaderValue(":version")); | 3184 EXPECT_EQ("HTTP/1.1", delegate2.GetResponseHeaderValue(":version")); |
3186 EXPECT_EQ(std::string(), delegate2.TakeReceivedData()); | 3185 EXPECT_EQ(std::string(), delegate2.TakeReceivedData()); |
3187 EXPECT_EQ(static_cast<int>(kBodyDataSize), delegate2.body_data_sent()); | 3186 |
| 3187 EXPECT_TRUE(data.at_write_eof()); |
3188 } | 3188 } |
3189 | 3189 |
3190 // Delegate that closes a given stream after sending its body. | 3190 // Delegate that closes a given stream after sending its body. |
3191 class StreamClosingDelegate : public test::StreamDelegateWithBody { | 3191 class StreamClosingDelegate : public test::StreamDelegateWithBody { |
3192 public: | 3192 public: |
3193 StreamClosingDelegate(const base::WeakPtr<SpdyStream>& stream, | 3193 StreamClosingDelegate(const base::WeakPtr<SpdyStream>& stream, |
3194 base::StringPiece data) | 3194 base::StringPiece data) |
3195 : StreamDelegateWithBody(stream, data) {} | 3195 : StreamDelegateWithBody(stream, data) {} |
3196 | 3196 |
3197 virtual ~StreamClosingDelegate() {} | 3197 virtual ~StreamClosingDelegate() {} |
3198 | 3198 |
3199 void set_stream_to_close(const base::WeakPtr<SpdyStream>& stream_to_close) { | 3199 void set_stream_to_close(const base::WeakPtr<SpdyStream>& stream_to_close) { |
3200 stream_to_close_ = stream_to_close; | 3200 stream_to_close_ = stream_to_close; |
3201 } | 3201 } |
3202 | 3202 |
3203 virtual void OnSendBody() OVERRIDE { | 3203 virtual SpdySendStatus OnSendBodyComplete() OVERRIDE { |
3204 test::StreamDelegateWithBody::OnSendBody(); | 3204 SpdySendStatus status = test::StreamDelegateWithBody::OnSendBodyComplete(); |
3205 if (stream_to_close_) { | 3205 if (stream_to_close_) { |
3206 stream_to_close_->Close(); | 3206 stream_to_close_->Close(); |
3207 EXPECT_EQ(NULL, stream_to_close_.get()); | 3207 EXPECT_EQ(NULL, stream_to_close_.get()); |
3208 } | 3208 } |
| 3209 return status; |
3209 } | 3210 } |
3210 | 3211 |
3211 private: | 3212 private: |
3212 base::WeakPtr<SpdyStream> stream_to_close_; | 3213 base::WeakPtr<SpdyStream> stream_to_close_; |
3213 }; | 3214 }; |
3214 | 3215 |
3215 // Cause a stall by reducing the flow control send window to | 3216 // Cause a stall by reducing the flow control send window to |
3216 // 0. Unstalling the session should properly handle deleted streams. | 3217 // 0. Unstalling the session should properly handle deleted streams. |
3217 TEST_F(SpdySessionSpdy3Test, SendWindowSizeIncreaseWithDeletedStreams31) { | 3218 TEST_F(SpdySessionSpdy3Test, SendWindowSizeIncreaseWithDeletedStreams31) { |
3218 const char kStreamUrl[] = "http://www.google.com/"; | 3219 const char kStreamUrl[] = "http://www.google.com/"; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3335 session->CloseActiveStream(stream_id1, ERR_CONNECTION_CLOSED); | 3336 session->CloseActiveStream(stream_id1, ERR_CONNECTION_CLOSED); |
3336 EXPECT_EQ(NULL, stream1.get()); | 3337 EXPECT_EQ(NULL, stream1.get()); |
3337 | 3338 |
3338 EXPECT_FALSE(session->IsStreamActive(stream_id1)); | 3339 EXPECT_FALSE(session->IsStreamActive(stream_id1)); |
3339 EXPECT_TRUE(session->IsStreamActive(stream_id2)); | 3340 EXPECT_TRUE(session->IsStreamActive(stream_id2)); |
3340 EXPECT_TRUE(session->IsStreamActive(stream_id3)); | 3341 EXPECT_TRUE(session->IsStreamActive(stream_id3)); |
3341 | 3342 |
3342 // Unstall stream2, which should then close stream3. | 3343 // Unstall stream2, which should then close stream3. |
3343 delegate2.set_stream_to_close(stream3); | 3344 delegate2.set_stream_to_close(stream3); |
3344 UnstallSessionSend(session, kBodyDataSize); | 3345 UnstallSessionSend(session, kBodyDataSize); |
| 3346 |
| 3347 data.RunFor(1); |
3345 EXPECT_EQ(NULL, stream3.get()); | 3348 EXPECT_EQ(NULL, stream3.get()); |
3346 | 3349 |
3347 EXPECT_FALSE(stream2->send_stalled_by_flow_control()); | 3350 EXPECT_FALSE(stream2->send_stalled_by_flow_control()); |
3348 EXPECT_FALSE(session->IsStreamActive(stream_id1)); | 3351 EXPECT_FALSE(session->IsStreamActive(stream_id1)); |
3349 EXPECT_TRUE(session->IsStreamActive(stream_id2)); | 3352 EXPECT_TRUE(session->IsStreamActive(stream_id2)); |
3350 EXPECT_FALSE(session->IsStreamActive(stream_id3)); | 3353 EXPECT_FALSE(session->IsStreamActive(stream_id3)); |
3351 | 3354 |
3352 data.RunFor(3); | 3355 data.RunFor(2); |
3353 EXPECT_EQ(NULL, stream2.get()); | 3356 EXPECT_EQ(NULL, stream2.get()); |
3354 | 3357 |
3355 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate1.WaitForClose()); | 3358 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate1.WaitForClose()); |
3356 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate2.WaitForClose()); | 3359 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate2.WaitForClose()); |
3357 EXPECT_EQ(OK, delegate3.WaitForClose()); | 3360 EXPECT_EQ(OK, delegate3.WaitForClose()); |
3358 | 3361 |
3359 EXPECT_TRUE(delegate1.send_headers_completed()); | 3362 EXPECT_TRUE(delegate1.send_headers_completed()); |
3360 EXPECT_EQ(std::string(), delegate1.TakeReceivedData()); | 3363 EXPECT_EQ(std::string(), delegate1.TakeReceivedData()); |
3361 EXPECT_EQ(0, delegate1.body_data_sent()); | |
3362 | 3364 |
3363 EXPECT_TRUE(delegate2.send_headers_completed()); | 3365 EXPECT_TRUE(delegate2.send_headers_completed()); |
3364 EXPECT_EQ("200", delegate2.GetResponseHeaderValue(":status")); | 3366 EXPECT_EQ("200", delegate2.GetResponseHeaderValue(":status")); |
3365 EXPECT_EQ("HTTP/1.1", delegate2.GetResponseHeaderValue(":version")); | 3367 EXPECT_EQ("HTTP/1.1", delegate2.GetResponseHeaderValue(":version")); |
3366 EXPECT_EQ(std::string(), delegate2.TakeReceivedData()); | 3368 EXPECT_EQ(std::string(), delegate2.TakeReceivedData()); |
3367 EXPECT_EQ(static_cast<int>(kBodyDataSize), delegate2.body_data_sent()); | |
3368 | 3369 |
3369 EXPECT_TRUE(delegate3.send_headers_completed()); | 3370 EXPECT_TRUE(delegate3.send_headers_completed()); |
3370 EXPECT_EQ(std::string(), delegate3.TakeReceivedData()); | 3371 EXPECT_EQ(std::string(), delegate3.TakeReceivedData()); |
3371 EXPECT_EQ(0, delegate3.body_data_sent()); | 3372 |
| 3373 EXPECT_TRUE(data.at_write_eof()); |
3372 } | 3374 } |
3373 | 3375 |
3374 // Cause a stall by reducing the flow control send window to | 3376 // Cause a stall by reducing the flow control send window to |
3375 // 0. Unstalling the session should properly handle the session itself | 3377 // 0. Unstalling the session should properly handle the session itself |
3376 // being closed. | 3378 // being closed. |
3377 TEST_F(SpdySessionSpdy3Test, SendWindowSizeIncreaseWithDeletedSession31) { | 3379 TEST_F(SpdySessionSpdy3Test, SendWindowSizeIncreaseWithDeletedSession31) { |
3378 const char kStreamUrl[] = "http://www.google.com/"; | 3380 const char kStreamUrl[] = "http://www.google.com/"; |
3379 GURL url(kStreamUrl); | 3381 GURL url(kStreamUrl); |
3380 | 3382 |
3381 session_deps_.protocol = kProtoSPDY31; | 3383 session_deps_.protocol = kProtoSPDY31; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3470 session->CloseSessionOnError(ERR_CONNECTION_CLOSED, true, "Closing session"); | 3472 session->CloseSessionOnError(ERR_CONNECTION_CLOSED, true, "Closing session"); |
3471 session = NULL; | 3473 session = NULL; |
3472 | 3474 |
3473 EXPECT_FALSE(spdy_session_pool_->HasSession(key_)); | 3475 EXPECT_FALSE(spdy_session_pool_->HasSession(key_)); |
3474 | 3476 |
3475 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate1.WaitForClose()); | 3477 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate1.WaitForClose()); |
3476 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate2.WaitForClose()); | 3478 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate2.WaitForClose()); |
3477 | 3479 |
3478 EXPECT_TRUE(delegate1.send_headers_completed()); | 3480 EXPECT_TRUE(delegate1.send_headers_completed()); |
3479 EXPECT_EQ(std::string(), delegate1.TakeReceivedData()); | 3481 EXPECT_EQ(std::string(), delegate1.TakeReceivedData()); |
3480 EXPECT_EQ(0, delegate1.body_data_sent()); | |
3481 | 3482 |
3482 EXPECT_TRUE(delegate2.send_headers_completed()); | 3483 EXPECT_TRUE(delegate2.send_headers_completed()); |
3483 EXPECT_EQ(std::string(), delegate2.TakeReceivedData()); | 3484 EXPECT_EQ(std::string(), delegate2.TakeReceivedData()); |
3484 EXPECT_EQ(0, delegate2.body_data_sent()); | 3485 |
| 3486 EXPECT_TRUE(data.at_write_eof()); |
3485 } | 3487 } |
3486 | 3488 |
3487 // Tests the case of a non-SPDY request closing an idle SPDY session when no | 3489 // Tests the case of a non-SPDY request closing an idle SPDY session when no |
3488 // pointers to the idle session are currently held. | 3490 // pointers to the idle session are currently held. |
3489 TEST_F(SpdySessionSpdy3Test, CloseOneIdleConnection) { | 3491 TEST_F(SpdySessionSpdy3Test, CloseOneIdleConnection) { |
3490 ClientSocketPoolManager::set_max_sockets_per_group( | 3492 ClientSocketPoolManager::set_max_sockets_per_group( |
3491 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); | 3493 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
3492 ClientSocketPoolManager::set_max_sockets_per_pool( | 3494 ClientSocketPoolManager::set_max_sockets_per_pool( |
3493 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); | 3495 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
3494 | 3496 |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3717 spdy_session_pool_->Remove(session_privacy_enabled); | 3719 spdy_session_pool_->Remove(session_privacy_enabled); |
3718 EXPECT_FALSE(spdy_session_pool_->HasSession(key_privacy_enabled)); | 3720 EXPECT_FALSE(spdy_session_pool_->HasSession(key_privacy_enabled)); |
3719 EXPECT_TRUE(spdy_session_pool_->HasSession(key_privacy_disabled)); | 3721 EXPECT_TRUE(spdy_session_pool_->HasSession(key_privacy_disabled)); |
3720 | 3722 |
3721 spdy_session_pool_->Remove(session_privacy_disabled); | 3723 spdy_session_pool_->Remove(session_privacy_disabled); |
3722 EXPECT_FALSE(spdy_session_pool_->HasSession(key_privacy_enabled)); | 3724 EXPECT_FALSE(spdy_session_pool_->HasSession(key_privacy_enabled)); |
3723 EXPECT_FALSE(spdy_session_pool_->HasSession(key_privacy_disabled)); | 3725 EXPECT_FALSE(spdy_session_pool_->HasSession(key_privacy_disabled)); |
3724 } | 3726 } |
3725 | 3727 |
3726 } // namespace net | 3728 } // namespace net |
OLD | NEW |