| 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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 SpdySessionTest, | 183 SpdySessionTest, |
| 184 testing::Values(kProtoDeprecatedSPDY2, | 184 testing::Values(kProtoDeprecatedSPDY2, |
| 185 kProtoSPDY3, kProtoSPDY31, kProtoSPDY4a2, | 185 kProtoSPDY3, kProtoSPDY31, kProtoSPDY4a2, |
| 186 kProtoHTTP2Draft04)); | 186 kProtoHTTP2Draft04)); |
| 187 | 187 |
| 188 // Try to create a SPDY session that will fail during | 188 // Try to create a SPDY session that will fail during |
| 189 // initialization. Nothing should blow up. | 189 // initialization. Nothing should blow up. |
| 190 TEST_P(SpdySessionTest, InitialReadError) { | 190 TEST_P(SpdySessionTest, InitialReadError) { |
| 191 CreateDeterministicNetworkSession(); | 191 CreateDeterministicNetworkSession(); |
| 192 | 192 |
| 193 base::WeakPtr<SpdySession> session = TryCreateFakeSpdySessionExpectingFailure( | 193 TryCreateFakeSpdySessionExpectingFailure( |
| 194 spdy_session_pool_, key_, ERR_FAILED); | 194 spdy_session_pool_, key_, ERR_FAILED); |
| 195 EXPECT_TRUE(session); | |
| 196 // Flush the read. | |
| 197 base::RunLoop().RunUntilIdle(); | |
| 198 EXPECT_FALSE(session); | |
| 199 } | 195 } |
| 200 | 196 |
| 201 namespace { | 197 namespace { |
| 202 | 198 |
| 203 // A helper class that vends a callback that, when fired, destroys a | 199 // A helper class that vends a callback that, when fired, destroys a |
| 204 // given SpdyStreamRequest. | 200 // given SpdyStreamRequest. |
| 205 class StreamRequestDestroyingCallback : public TestCompletionCallbackBase { | 201 class StreamRequestDestroyingCallback : public TestCompletionCallbackBase { |
| 206 public: | 202 public: |
| 207 StreamRequestDestroyingCallback() {} | 203 StreamRequestDestroyingCallback() {} |
| 208 | 204 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 test_url_, | 270 test_url_, |
| 275 MEDIUM, | 271 MEDIUM, |
| 276 BoundNetLog(), | 272 BoundNetLog(), |
| 277 callback2.callback())); | 273 callback2.callback())); |
| 278 | 274 |
| 279 callback1.SetRequestToDestroy(request2.Pass()); | 275 callback1.SetRequestToDestroy(request2.Pass()); |
| 280 | 276 |
| 281 session->CloseSessionOnError(ERR_ABORTED, "Aborting session"); | 277 session->CloseSessionOnError(ERR_ABORTED, "Aborting session"); |
| 282 | 278 |
| 283 EXPECT_EQ(ERR_ABORTED, callback1.WaitForResult()); | 279 EXPECT_EQ(ERR_ABORTED, callback1.WaitForResult()); |
| 280 |
| 281 data.RunFor(1); |
| 284 } | 282 } |
| 285 | 283 |
| 286 // A session receiving a GOAWAY frame with no active streams should | 284 // A session receiving a GOAWAY frame with no active streams should |
| 287 // immediately close. | 285 // immediately close. |
| 288 TEST_P(SpdySessionTest, GoAwayWithNoActiveStreams) { | 286 TEST_P(SpdySessionTest, GoAwayWithNoActiveStreams) { |
| 289 session_deps_.host_resolver->set_synchronous_mode(true); | 287 session_deps_.host_resolver->set_synchronous_mode(true); |
| 290 | 288 |
| 291 MockConnect connect_data(SYNCHRONOUS, OK); | 289 MockConnect connect_data(SYNCHRONOUS, OK); |
| 292 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway(1)); | 290 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway(1)); |
| 293 MockRead reads[] = { | 291 MockRead reads[] = { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 CreateMockRead(*goaway, 0, SYNCHRONOUS), | 323 CreateMockRead(*goaway, 0, SYNCHRONOUS), |
| 326 }; | 324 }; |
| 327 DeterministicSocketData data(reads, arraysize(reads), NULL, 0); | 325 DeterministicSocketData data(reads, arraysize(reads), NULL, 0); |
| 328 data.set_connect_data(connect_data); | 326 data.set_connect_data(connect_data); |
| 329 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); | 327 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); |
| 330 | 328 |
| 331 CreateDeterministicNetworkSession(); | 329 CreateDeterministicNetworkSession(); |
| 332 | 330 |
| 333 data.StopAfter(1); | 331 data.StopAfter(1); |
| 334 | 332 |
| 335 base::WeakPtr<SpdySession> session = | 333 TryCreateInsecureSpdySessionExpectingFailure( |
| 336 TryCreateInsecureSpdySessionExpectingFailure( | 334 http_session_, key_, ERR_CONNECTION_CLOSED, BoundNetLog()); |
| 337 http_session_, key_, ERR_CONNECTION_CLOSED, BoundNetLog()); | |
| 338 base::RunLoop().RunUntilIdle(); | |
| 339 | 335 |
| 340 EXPECT_FALSE(session); | |
| 341 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_)); | 336 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_)); |
| 342 } | 337 } |
| 343 | 338 |
| 344 // A session receiving a GOAWAY frame with active streams should close | 339 // A session receiving a GOAWAY frame with active streams should close |
| 345 // when the last active stream is closed. | 340 // when the last active stream is closed. |
| 346 TEST_P(SpdySessionTest, GoAwayWithActiveStreams) { | 341 TEST_P(SpdySessionTest, GoAwayWithActiveStreams) { |
| 347 session_deps_.host_resolver->set_synchronous_mode(true); | 342 session_deps_.host_resolver->set_synchronous_mode(true); |
| 348 | 343 |
| 349 MockConnect connect_data(SYNCHRONOUS, OK); | 344 MockConnect connect_data(SYNCHRONOUS, OK); |
| 350 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway(1)); | 345 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway(1)); |
| (...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1043 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key_)); | 1038 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key_)); |
| 1044 | 1039 |
| 1045 // We set last time we have received any data in 1 sec less than now. | 1040 // We set last time we have received any data in 1 sec less than now. |
| 1046 // CheckPingStatus will trigger timeout because hung interval is zero. | 1041 // CheckPingStatus will trigger timeout because hung interval is zero. |
| 1047 base::TimeTicks now = base::TimeTicks::Now(); | 1042 base::TimeTicks now = base::TimeTicks::Now(); |
| 1048 session->last_activity_time_ = now - base::TimeDelta::FromSeconds(1); | 1043 session->last_activity_time_ = now - base::TimeDelta::FromSeconds(1); |
| 1049 session->CheckPingStatus(now); | 1044 session->CheckPingStatus(now); |
| 1050 | 1045 |
| 1051 EXPECT_TRUE(session == NULL); | 1046 EXPECT_TRUE(session == NULL); |
| 1052 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_)); | 1047 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_)); |
| 1048 |
| 1049 data.RunFor(1); |
| 1053 EXPECT_EQ(NULL, spdy_stream1.get()); | 1050 EXPECT_EQ(NULL, spdy_stream1.get()); |
| 1054 } | 1051 } |
| 1055 | 1052 |
| 1056 // Request kInitialMaxConcurrentStreams + 1 streams. Receive a | 1053 // Request kInitialMaxConcurrentStreams + 1 streams. Receive a |
| 1057 // settings frame increasing the max concurrent streams by 1. Make | 1054 // settings frame increasing the max concurrent streams by 1. Make |
| 1058 // sure nothing blows up. This is a regression test for | 1055 // sure nothing blows up. This is a regression test for |
| 1059 // http://crbug.com/57331 . | 1056 // http://crbug.com/57331 . |
| 1060 TEST_P(SpdySessionTest, OnSettings) { | 1057 TEST_P(SpdySessionTest, OnSettings) { |
| 1061 session_deps_.host_resolver->set_synchronous_mode(true); | 1058 session_deps_.host_resolver->set_synchronous_mode(true); |
| 1062 | 1059 |
| (...skipping 3076 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4139 TEST(MapRstStreamStatusToProtocolError, MapsValues) { | 4136 TEST(MapRstStreamStatusToProtocolError, MapsValues) { |
| 4140 CHECK_EQ(STATUS_CODE_PROTOCOL_ERROR, | 4137 CHECK_EQ(STATUS_CODE_PROTOCOL_ERROR, |
| 4141 MapRstStreamStatusToProtocolError( | 4138 MapRstStreamStatusToProtocolError( |
| 4142 RST_STREAM_PROTOCOL_ERROR)); | 4139 RST_STREAM_PROTOCOL_ERROR)); |
| 4143 CHECK_EQ(STATUS_CODE_FRAME_TOO_LARGE, | 4140 CHECK_EQ(STATUS_CODE_FRAME_TOO_LARGE, |
| 4144 MapRstStreamStatusToProtocolError( | 4141 MapRstStreamStatusToProtocolError( |
| 4145 RST_STREAM_FRAME_TOO_LARGE)); | 4142 RST_STREAM_FRAME_TOO_LARGE)); |
| 4146 } | 4143 } |
| 4147 | 4144 |
| 4148 } // namespace net | 4145 } // namespace net |
| OLD | NEW |