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/base64.h" | 7 #include "base/base64.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 } | 200 } |
201 | 201 |
202 namespace { | 202 namespace { |
203 | 203 |
204 // A helper class that vends a callback that, when fired, destroys a | 204 // A helper class that vends a callback that, when fired, destroys a |
205 // given SpdyStreamRequest. | 205 // given SpdyStreamRequest. |
206 class StreamRequestDestroyingCallback : public TestCompletionCallbackBase { | 206 class StreamRequestDestroyingCallback : public TestCompletionCallbackBase { |
207 public: | 207 public: |
208 StreamRequestDestroyingCallback() {} | 208 StreamRequestDestroyingCallback() {} |
209 | 209 |
210 virtual ~StreamRequestDestroyingCallback() {} | 210 ~StreamRequestDestroyingCallback() override {} |
211 | 211 |
212 void SetRequestToDestroy(scoped_ptr<SpdyStreamRequest> request) { | 212 void SetRequestToDestroy(scoped_ptr<SpdyStreamRequest> request) { |
213 request_ = request.Pass(); | 213 request_ = request.Pass(); |
214 } | 214 } |
215 | 215 |
216 CompletionCallback MakeCallback() { | 216 CompletionCallback MakeCallback() { |
217 return base::Bind(&StreamRequestDestroyingCallback::OnComplete, | 217 return base::Bind(&StreamRequestDestroyingCallback::OnComplete, |
218 base::Unretained(this)); | 218 base::Unretained(this)); |
219 } | 219 } |
220 | 220 |
(...skipping 2075 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2296 } | 2296 } |
2297 | 2297 |
2298 // Delegate that closes a given session when the stream is closed. | 2298 // Delegate that closes a given session when the stream is closed. |
2299 class SessionClosingDelegate : public test::StreamDelegateDoNothing { | 2299 class SessionClosingDelegate : public test::StreamDelegateDoNothing { |
2300 public: | 2300 public: |
2301 SessionClosingDelegate(const base::WeakPtr<SpdyStream>& stream, | 2301 SessionClosingDelegate(const base::WeakPtr<SpdyStream>& stream, |
2302 const base::WeakPtr<SpdySession>& session_to_close) | 2302 const base::WeakPtr<SpdySession>& session_to_close) |
2303 : StreamDelegateDoNothing(stream), | 2303 : StreamDelegateDoNothing(stream), |
2304 session_to_close_(session_to_close) {} | 2304 session_to_close_(session_to_close) {} |
2305 | 2305 |
2306 virtual ~SessionClosingDelegate() {} | 2306 ~SessionClosingDelegate() override {} |
2307 | 2307 |
2308 virtual void OnClose(int status) override { | 2308 void OnClose(int status) override { |
2309 session_to_close_->CloseSessionOnError(ERR_SPDY_PROTOCOL_ERROR, "Error"); | 2309 session_to_close_->CloseSessionOnError(ERR_SPDY_PROTOCOL_ERROR, "Error"); |
2310 } | 2310 } |
2311 | 2311 |
2312 private: | 2312 private: |
2313 base::WeakPtr<SpdySession> session_to_close_; | 2313 base::WeakPtr<SpdySession> session_to_close_; |
2314 }; | 2314 }; |
2315 | 2315 |
2316 // Close an activated stream that closes its session. Nothing should | 2316 // Close an activated stream that closes its session. Nothing should |
2317 // blow up. This is a regression test for http://crbug.com/263691 . | 2317 // blow up. This is a regression test for http://crbug.com/263691 . |
2318 TEST_P(SpdySessionTest, CloseActivatedStreamThatClosesSession) { | 2318 TEST_P(SpdySessionTest, CloseActivatedStreamThatClosesSession) { |
(...skipping 1053 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3372 } | 3372 } |
3373 | 3373 |
3374 // Delegate that creates another stream when its stream is closed. | 3374 // Delegate that creates another stream when its stream is closed. |
3375 class StreamCreatingDelegate : public test::StreamDelegateDoNothing { | 3375 class StreamCreatingDelegate : public test::StreamDelegateDoNothing { |
3376 public: | 3376 public: |
3377 StreamCreatingDelegate(const base::WeakPtr<SpdyStream>& stream, | 3377 StreamCreatingDelegate(const base::WeakPtr<SpdyStream>& stream, |
3378 const base::WeakPtr<SpdySession>& session) | 3378 const base::WeakPtr<SpdySession>& session) |
3379 : StreamDelegateDoNothing(stream), | 3379 : StreamDelegateDoNothing(stream), |
3380 session_(session) {} | 3380 session_(session) {} |
3381 | 3381 |
3382 virtual ~StreamCreatingDelegate() {} | 3382 ~StreamCreatingDelegate() override {} |
3383 | 3383 |
3384 virtual void OnClose(int status) override { | 3384 void OnClose(int status) override { |
3385 GURL url(kDefaultURL); | 3385 GURL url(kDefaultURL); |
3386 ignore_result( | 3386 ignore_result( |
3387 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, | 3387 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, |
3388 session_, url, MEDIUM, BoundNetLog())); | 3388 session_, url, MEDIUM, BoundNetLog())); |
3389 } | 3389 } |
3390 | 3390 |
3391 private: | 3391 private: |
3392 const base::WeakPtr<SpdySession> session_; | 3392 const base::WeakPtr<SpdySession> session_; |
3393 }; | 3393 }; |
3394 | 3394 |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3651 data.RunFor(1); | 3651 data.RunFor(1); |
3652 } | 3652 } |
3653 | 3653 |
3654 // A delegate that drops any received data. | 3654 // A delegate that drops any received data. |
3655 class DropReceivedDataDelegate : public test::StreamDelegateSendImmediate { | 3655 class DropReceivedDataDelegate : public test::StreamDelegateSendImmediate { |
3656 public: | 3656 public: |
3657 DropReceivedDataDelegate(const base::WeakPtr<SpdyStream>& stream, | 3657 DropReceivedDataDelegate(const base::WeakPtr<SpdyStream>& stream, |
3658 base::StringPiece data) | 3658 base::StringPiece data) |
3659 : StreamDelegateSendImmediate(stream, data) {} | 3659 : StreamDelegateSendImmediate(stream, data) {} |
3660 | 3660 |
3661 virtual ~DropReceivedDataDelegate() {} | 3661 ~DropReceivedDataDelegate() override {} |
3662 | 3662 |
3663 // Drop any received data. | 3663 // Drop any received data. |
3664 virtual void OnDataReceived(scoped_ptr<SpdyBuffer> buffer) override {} | 3664 void OnDataReceived(scoped_ptr<SpdyBuffer> buffer) override {} |
3665 }; | 3665 }; |
3666 | 3666 |
3667 // Send data back and forth but use a delegate that drops its received | 3667 // Send data back and forth but use a delegate that drops its received |
3668 // data. The receive window should still increase to its original | 3668 // data. The receive window should still increase to its original |
3669 // value, i.e. we shouldn't "leak" receive window bytes. | 3669 // value, i.e. we shouldn't "leak" receive window bytes. |
3670 TEST_P(SpdySessionTest, SessionFlowControlNoReceiveLeaks) { | 3670 TEST_P(SpdySessionTest, SessionFlowControlNoReceiveLeaks) { |
3671 if (GetParam() < kProtoSPDY31) | 3671 if (GetParam() < kProtoSPDY31) |
3672 return; | 3672 return; |
3673 | 3673 |
3674 const char kStreamUrl[] = "http://www.google.com/"; | 3674 const char kStreamUrl[] = "http://www.google.com/"; |
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4236 EXPECT_TRUE(data.at_write_eof()); | 4236 EXPECT_TRUE(data.at_write_eof()); |
4237 } | 4237 } |
4238 | 4238 |
4239 // Delegate that closes a given stream after sending its body. | 4239 // Delegate that closes a given stream after sending its body. |
4240 class StreamClosingDelegate : public test::StreamDelegateWithBody { | 4240 class StreamClosingDelegate : public test::StreamDelegateWithBody { |
4241 public: | 4241 public: |
4242 StreamClosingDelegate(const base::WeakPtr<SpdyStream>& stream, | 4242 StreamClosingDelegate(const base::WeakPtr<SpdyStream>& stream, |
4243 base::StringPiece data) | 4243 base::StringPiece data) |
4244 : StreamDelegateWithBody(stream, data) {} | 4244 : StreamDelegateWithBody(stream, data) {} |
4245 | 4245 |
4246 virtual ~StreamClosingDelegate() {} | 4246 ~StreamClosingDelegate() override {} |
4247 | 4247 |
4248 void set_stream_to_close(const base::WeakPtr<SpdyStream>& stream_to_close) { | 4248 void set_stream_to_close(const base::WeakPtr<SpdyStream>& stream_to_close) { |
4249 stream_to_close_ = stream_to_close; | 4249 stream_to_close_ = stream_to_close; |
4250 } | 4250 } |
4251 | 4251 |
4252 virtual void OnDataSent() override { | 4252 void OnDataSent() override { |
4253 test::StreamDelegateWithBody::OnDataSent(); | 4253 test::StreamDelegateWithBody::OnDataSent(); |
4254 if (stream_to_close_.get()) { | 4254 if (stream_to_close_.get()) { |
4255 stream_to_close_->Close(); | 4255 stream_to_close_->Close(); |
4256 EXPECT_EQ(NULL, stream_to_close_.get()); | 4256 EXPECT_EQ(NULL, stream_to_close_.get()); |
4257 } | 4257 } |
4258 } | 4258 } |
4259 | 4259 |
4260 private: | 4260 private: |
4261 base::WeakPtr<SpdyStream> stream_to_close_; | 4261 base::WeakPtr<SpdyStream> stream_to_close_; |
4262 }; | 4262 }; |
(...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5135 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), | 5135 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), |
5136 "spdy_pooling.pem"); | 5136 "spdy_pooling.pem"); |
5137 ssl_info.is_issued_by_known_root = true; | 5137 ssl_info.is_issued_by_known_root = true; |
5138 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin)); | 5138 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin)); |
5139 | 5139 |
5140 EXPECT_TRUE(SpdySession::CanPool( | 5140 EXPECT_TRUE(SpdySession::CanPool( |
5141 &tss, ssl_info, "www.example.org", "mail.example.org")); | 5141 &tss, ssl_info, "www.example.org", "mail.example.org")); |
5142 } | 5142 } |
5143 | 5143 |
5144 } // namespace net | 5144 } // namespace net |
OLD | NEW |