| 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 2962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2973 EXPECT_EQ(kStreamUrl, stream->GetUrl().spec()); | 2973 EXPECT_EQ(kStreamUrl, stream->GetUrl().spec()); |
| 2974 | 2974 |
| 2975 EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(true)); | 2975 EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(true)); |
| 2976 | 2976 |
| 2977 data.RunFor(3); | 2977 data.RunFor(3); |
| 2978 | 2978 |
| 2979 EXPECT_FALSE(stream->send_stalled_by_flow_control()); | 2979 EXPECT_FALSE(stream->send_stalled_by_flow_control()); |
| 2980 | 2980 |
| 2981 stall_fn.Run(session, stream); | 2981 stall_fn.Run(session, stream); |
| 2982 | 2982 |
| 2983 EXPECT_EQ(ERR_IO_PENDING, delegate.OnSendBody()); | 2983 delegate.OnSendBody(); |
| 2984 | 2984 |
| 2985 EXPECT_TRUE(stream->send_stalled_by_flow_control()); | 2985 EXPECT_TRUE(stream->send_stalled_by_flow_control()); |
| 2986 | 2986 |
| 2987 unstall_fn.Run(session, stream, kBodyDataSize); | 2987 unstall_fn.Run(session, stream, kBodyDataSize); |
| 2988 | 2988 |
| 2989 EXPECT_FALSE(stream->send_stalled_by_flow_control()); | 2989 EXPECT_FALSE(stream->send_stalled_by_flow_control()); |
| 2990 | 2990 |
| 2991 data.RunFor(3); | 2991 data.RunFor(3); |
| 2992 | 2992 |
| 2993 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); | 2993 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3150 EXPECT_EQ(ERR_IO_PENDING, stream2->SendRequest(true)); | 3150 EXPECT_EQ(ERR_IO_PENDING, stream2->SendRequest(true)); |
| 3151 | 3151 |
| 3152 data.RunFor(2); | 3152 data.RunFor(2); |
| 3153 EXPECT_EQ(3u, stream2->stream_id()); | 3153 EXPECT_EQ(3u, stream2->stream_id()); |
| 3154 | 3154 |
| 3155 EXPECT_FALSE(stream1->send_stalled_by_flow_control()); | 3155 EXPECT_FALSE(stream1->send_stalled_by_flow_control()); |
| 3156 EXPECT_FALSE(stream2->send_stalled_by_flow_control()); | 3156 EXPECT_FALSE(stream2->send_stalled_by_flow_control()); |
| 3157 | 3157 |
| 3158 StallSessionSend(session); | 3158 StallSessionSend(session); |
| 3159 | 3159 |
| 3160 EXPECT_EQ(ERR_IO_PENDING, delegate1.OnSendBody()); | 3160 delegate1.OnSendBody(); |
| 3161 EXPECT_EQ(ERR_IO_PENDING, delegate2.OnSendBody()); | 3161 delegate2.OnSendBody(); |
| 3162 | 3162 |
| 3163 EXPECT_TRUE(stream1->send_stalled_by_flow_control()); | 3163 EXPECT_TRUE(stream1->send_stalled_by_flow_control()); |
| 3164 EXPECT_TRUE(stream2->send_stalled_by_flow_control()); | 3164 EXPECT_TRUE(stream2->send_stalled_by_flow_control()); |
| 3165 | 3165 |
| 3166 // This should unstall only stream2. | 3166 // This should unstall only stream2. |
| 3167 UnstallSessionSend(session, kBodyDataSize); | 3167 UnstallSessionSend(session, kBodyDataSize); |
| 3168 | 3168 |
| 3169 EXPECT_TRUE(stream1->send_stalled_by_flow_control()); | 3169 EXPECT_TRUE(stream1->send_stalled_by_flow_control()); |
| 3170 EXPECT_FALSE(stream2->send_stalled_by_flow_control()); | 3170 EXPECT_FALSE(stream2->send_stalled_by_flow_control()); |
| 3171 | 3171 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3204 StreamClosingDelegate(const base::WeakPtr<SpdyStream>& stream, | 3204 StreamClosingDelegate(const base::WeakPtr<SpdyStream>& stream, |
| 3205 base::StringPiece data) | 3205 base::StringPiece data) |
| 3206 : StreamDelegateWithBody(stream, data) {} | 3206 : StreamDelegateWithBody(stream, data) {} |
| 3207 | 3207 |
| 3208 virtual ~StreamClosingDelegate() {} | 3208 virtual ~StreamClosingDelegate() {} |
| 3209 | 3209 |
| 3210 void set_stream_to_close(const base::WeakPtr<SpdyStream>& stream_to_close) { | 3210 void set_stream_to_close(const base::WeakPtr<SpdyStream>& stream_to_close) { |
| 3211 stream_to_close_ = stream_to_close; | 3211 stream_to_close_ = stream_to_close; |
| 3212 } | 3212 } |
| 3213 | 3213 |
| 3214 virtual int OnSendBody() OVERRIDE { | 3214 virtual void OnSendBody() OVERRIDE { |
| 3215 int rv = test::StreamDelegateWithBody::OnSendBody(); | 3215 test::StreamDelegateWithBody::OnSendBody(); |
| 3216 if (stream_to_close_) { | 3216 if (stream_to_close_) { |
| 3217 stream_to_close_->Close(); | 3217 stream_to_close_->Close(); |
| 3218 EXPECT_EQ(NULL, stream_to_close_.get()); | 3218 EXPECT_EQ(NULL, stream_to_close_.get()); |
| 3219 } | 3219 } |
| 3220 return rv; | |
| 3221 } | 3220 } |
| 3222 | 3221 |
| 3223 private: | 3222 private: |
| 3224 base::WeakPtr<SpdyStream> stream_to_close_; | 3223 base::WeakPtr<SpdyStream> stream_to_close_; |
| 3225 }; | 3224 }; |
| 3226 | 3225 |
| 3227 // Cause a stall by reducing the flow control send window to | 3226 // Cause a stall by reducing the flow control send window to |
| 3228 // 0. Unstalling the session should properly handle deleted streams. | 3227 // 0. Unstalling the session should properly handle deleted streams. |
| 3229 TEST_F(SpdySessionSpdy3Test, SendWindowSizeIncreaseWithDeletedStreams31) { | 3228 TEST_F(SpdySessionSpdy3Test, SendWindowSizeIncreaseWithDeletedStreams31) { |
| 3230 const char kStreamUrl[] = "http://www.google.com/"; | 3229 const char kStreamUrl[] = "http://www.google.com/"; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3336 | 3335 |
| 3337 data.RunFor(2); | 3336 data.RunFor(2); |
| 3338 EXPECT_EQ(5u, stream3->stream_id()); | 3337 EXPECT_EQ(5u, stream3->stream_id()); |
| 3339 | 3338 |
| 3340 EXPECT_FALSE(stream1->send_stalled_by_flow_control()); | 3339 EXPECT_FALSE(stream1->send_stalled_by_flow_control()); |
| 3341 EXPECT_FALSE(stream2->send_stalled_by_flow_control()); | 3340 EXPECT_FALSE(stream2->send_stalled_by_flow_control()); |
| 3342 EXPECT_FALSE(stream3->send_stalled_by_flow_control()); | 3341 EXPECT_FALSE(stream3->send_stalled_by_flow_control()); |
| 3343 | 3342 |
| 3344 StallSessionSend(session); | 3343 StallSessionSend(session); |
| 3345 | 3344 |
| 3346 EXPECT_EQ(ERR_IO_PENDING, delegate1.OnSendBody()); | 3345 delegate1.OnSendBody(); |
| 3347 EXPECT_EQ(ERR_IO_PENDING, delegate2.OnSendBody()); | 3346 delegate2.OnSendBody(); |
| 3348 EXPECT_EQ(ERR_IO_PENDING, delegate3.OnSendBody()); | 3347 delegate3.OnSendBody(); |
| 3349 | 3348 |
| 3350 EXPECT_TRUE(stream1->send_stalled_by_flow_control()); | 3349 EXPECT_TRUE(stream1->send_stalled_by_flow_control()); |
| 3351 EXPECT_TRUE(stream2->send_stalled_by_flow_control()); | 3350 EXPECT_TRUE(stream2->send_stalled_by_flow_control()); |
| 3352 EXPECT_TRUE(stream3->send_stalled_by_flow_control()); | 3351 EXPECT_TRUE(stream3->send_stalled_by_flow_control()); |
| 3353 | 3352 |
| 3354 SpdyStreamId stream_id1 = stream1->stream_id(); | 3353 SpdyStreamId stream_id1 = stream1->stream_id(); |
| 3355 SpdyStreamId stream_id2 = stream2->stream_id(); | 3354 SpdyStreamId stream_id2 = stream2->stream_id(); |
| 3356 SpdyStreamId stream_id3 = stream3->stream_id(); | 3355 SpdyStreamId stream_id3 = stream3->stream_id(); |
| 3357 | 3356 |
| 3358 // Close stream1 preemptively. | 3357 // Close stream1 preemptively. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3406 base::StringPiece data) | 3405 base::StringPiece data) |
| 3407 : StreamDelegateWithBody(stream, data) {} | 3406 : StreamDelegateWithBody(stream, data) {} |
| 3408 | 3407 |
| 3409 virtual ~SessionClosingDelegate() {} | 3408 virtual ~SessionClosingDelegate() {} |
| 3410 | 3409 |
| 3411 void set_session_to_close( | 3410 void set_session_to_close( |
| 3412 const scoped_refptr<SpdySession>& session_to_close) { | 3411 const scoped_refptr<SpdySession>& session_to_close) { |
| 3413 session_to_close_ = session_to_close; | 3412 session_to_close_ = session_to_close; |
| 3414 } | 3413 } |
| 3415 | 3414 |
| 3416 virtual int OnSendBody() OVERRIDE { | 3415 virtual void OnSendBody() OVERRIDE { |
| 3417 int rv = test::StreamDelegateWithBody::OnSendBody(); | 3416 test::StreamDelegateWithBody::OnSendBody(); |
| 3418 if (session_to_close_) { | 3417 if (session_to_close_) { |
| 3419 MessageLoop::current()->PostTask( | 3418 MessageLoop::current()->PostTask( |
| 3420 FROM_HERE, | 3419 FROM_HERE, |
| 3421 base::Bind(&SpdySession::CloseSessionOnError, | 3420 base::Bind(&SpdySession::CloseSessionOnError, |
| 3422 session_to_close_, | 3421 session_to_close_, |
| 3423 ERR_CONNECTION_CLOSED, | 3422 ERR_CONNECTION_CLOSED, |
| 3424 true, | 3423 true, |
| 3425 "Closed by SessionClosingDelegate")); | 3424 "Closed by SessionClosingDelegate")); |
| 3426 session_to_close_ = NULL; | 3425 session_to_close_ = NULL; |
| 3427 } | 3426 } |
| 3428 return rv; | |
| 3429 } | 3427 } |
| 3430 | 3428 |
| 3431 private: | 3429 private: |
| 3432 scoped_refptr<SpdySession> session_to_close_; | 3430 scoped_refptr<SpdySession> session_to_close_; |
| 3433 }; | 3431 }; |
| 3434 | 3432 |
| 3435 // Cause a stall by reducing the flow control send window to | 3433 // Cause a stall by reducing the flow control send window to |
| 3436 // 0. Unstalling the session should properly handle the session itself | 3434 // 0. Unstalling the session should properly handle the session itself |
| 3437 // being closed. | 3435 // being closed. |
| 3438 TEST_F(SpdySessionSpdy3Test, SendWindowSizeIncreaseWithDeletedSession31) { | 3436 TEST_F(SpdySessionSpdy3Test, SendWindowSizeIncreaseWithDeletedSession31) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3517 EXPECT_EQ(ERR_IO_PENDING, stream2->SendRequest(true)); | 3515 EXPECT_EQ(ERR_IO_PENDING, stream2->SendRequest(true)); |
| 3518 | 3516 |
| 3519 data.RunFor(2); | 3517 data.RunFor(2); |
| 3520 EXPECT_EQ(3u, stream2->stream_id()); | 3518 EXPECT_EQ(3u, stream2->stream_id()); |
| 3521 | 3519 |
| 3522 EXPECT_FALSE(stream1->send_stalled_by_flow_control()); | 3520 EXPECT_FALSE(stream1->send_stalled_by_flow_control()); |
| 3523 EXPECT_FALSE(stream2->send_stalled_by_flow_control()); | 3521 EXPECT_FALSE(stream2->send_stalled_by_flow_control()); |
| 3524 | 3522 |
| 3525 StallSessionSend(session); | 3523 StallSessionSend(session); |
| 3526 | 3524 |
| 3527 EXPECT_EQ(ERR_IO_PENDING, delegate1.OnSendBody()); | 3525 delegate1.OnSendBody(); |
| 3528 EXPECT_EQ(ERR_IO_PENDING, delegate2.OnSendBody()); | 3526 delegate2.OnSendBody(); |
| 3529 | 3527 |
| 3530 EXPECT_TRUE(stream1->send_stalled_by_flow_control()); | 3528 EXPECT_TRUE(stream1->send_stalled_by_flow_control()); |
| 3531 EXPECT_TRUE(stream2->send_stalled_by_flow_control()); | 3529 EXPECT_TRUE(stream2->send_stalled_by_flow_control()); |
| 3532 | 3530 |
| 3533 EXPECT_TRUE(spdy_session_pool_->HasSession(key_)); | 3531 EXPECT_TRUE(spdy_session_pool_->HasSession(key_)); |
| 3534 | 3532 |
| 3535 // Unstall stream1, which should then post a task to close the | 3533 // Unstall stream1, which should then post a task to close the |
| 3536 // session. | 3534 // session. |
| 3537 delegate1.set_session_to_close(session); | 3535 delegate1.set_session_to_close(session); |
| 3538 UnstallSessionSend(session, kBodyDataSize); | 3536 UnstallSessionSend(session, kBodyDataSize); |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3792 spdy_session_pool_->Remove(session_privacy_enabled); | 3790 spdy_session_pool_->Remove(session_privacy_enabled); |
| 3793 EXPECT_FALSE(spdy_session_pool_->HasSession(key_privacy_enabled)); | 3791 EXPECT_FALSE(spdy_session_pool_->HasSession(key_privacy_enabled)); |
| 3794 EXPECT_TRUE(spdy_session_pool_->HasSession(key_privacy_disabled)); | 3792 EXPECT_TRUE(spdy_session_pool_->HasSession(key_privacy_disabled)); |
| 3795 | 3793 |
| 3796 spdy_session_pool_->Remove(session_privacy_disabled); | 3794 spdy_session_pool_->Remove(session_privacy_disabled); |
| 3797 EXPECT_FALSE(spdy_session_pool_->HasSession(key_privacy_enabled)); | 3795 EXPECT_FALSE(spdy_session_pool_->HasSession(key_privacy_enabled)); |
| 3798 EXPECT_FALSE(spdy_session_pool_->HasSession(key_privacy_disabled)); | 3796 EXPECT_FALSE(spdy_session_pool_->HasSession(key_privacy_disabled)); |
| 3799 } | 3797 } |
| 3800 | 3798 |
| 3801 } // namespace net | 3799 } // namespace net |
| OLD | NEW |