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