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 "net/base/cert_test_util.h" | 7 #include "net/base/cert_test_util.h" |
8 #include "net/base/host_cache.h" | 8 #include "net/base/host_cache.h" |
9 #include "net/base/ip_endpoint.h" | 9 #include "net/base/ip_endpoint.h" |
10 #include "net/base/net_log_unittest.h" | 10 #include "net/base/net_log_unittest.h" |
11 #include "net/base/test_data_directory.h" | 11 #include "net/base/test_data_directory.h" |
12 #include "net/spdy/spdy_io_buffer.h" | 12 #include "net/spdy/spdy_io_buffer.h" |
13 #include "net/spdy/spdy_session_pool.h" | 13 #include "net/spdy/spdy_session_pool.h" |
14 #include "net/spdy/spdy_stream.h" | 14 #include "net/spdy/spdy_stream.h" |
15 #include "net/spdy/spdy_test_util_spdy3.h" | 15 #include "net/spdy/spdy_test_util_spdy3.h" |
16 #include "testing/platform_test.h" | 16 #include "testing/platform_test.h" |
17 | 17 |
18 using namespace net::test_spdy3; | 18 using namespace net::test_spdy3; |
19 | 19 |
20 namespace net { | 20 namespace net { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 base::TimeTicks the_near_future() { | 24 static int g_delta_seconds = 0; |
25 return base::TimeTicks::Now() + | 25 base::TimeTicks TheNearFuture() { |
26 base::TimeDelta::FromSeconds(301); | 26 return base::TimeTicks::Now() + base::TimeDelta::FromSeconds(g_delta_seconds); |
27 } | 27 } |
28 | 28 |
29 class ClosingDelegate : public SpdyStream::Delegate { | 29 class ClosingDelegate : public SpdyStream::Delegate { |
30 public: | 30 public: |
31 ClosingDelegate(SpdyStream* stream) : stream_(stream) {} | 31 ClosingDelegate(SpdyStream* stream) : stream_(stream) {} |
32 | 32 |
33 // SpdyStream::Delegate implementation: | 33 // SpdyStream::Delegate implementation: |
34 virtual bool OnSendHeadersComplete(int status) OVERRIDE { | 34 virtual bool OnSendHeadersComplete(int status) OVERRIDE { |
35 return true; | 35 return true; |
36 } | 36 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 callback_.Reset(); | 92 callback_.Reset(); |
93 callback.Run(OK); | 93 callback.Run(OK); |
94 } | 94 } |
95 | 95 |
96 private: | 96 private: |
97 CompletionCallback callback_; | 97 CompletionCallback callback_; |
98 }; | 98 }; |
99 | 99 |
100 } // namespace | 100 } // namespace |
101 | 101 |
102 // TODO(cbentzel): Expose compression setter/getter in public SpdySession | |
103 // interface rather than going through all these contortions. | |
104 class SpdySessionSpdy3Test : public PlatformTest { | 102 class SpdySessionSpdy3Test : public PlatformTest { |
105 protected: | 103 protected: |
106 virtual void SetUp() { | 104 void SetUp() { |
107 SpdySession::set_default_protocol(kProtoSPDY3); | 105 g_delta_seconds = 0; |
108 } | 106 } |
| 107 }; |
109 | 108 |
110 private: | |
111 SpdyTestStateHelper spdy_state_; | |
112 }; | |
113 // Test the SpdyIOBuffer class. | 109 // Test the SpdyIOBuffer class. |
114 TEST_F(SpdySessionSpdy3Test, SpdyIOBuffer) { | 110 TEST_F(SpdySessionSpdy3Test, SpdyIOBuffer) { |
115 std::priority_queue<SpdyIOBuffer> queue_; | 111 std::priority_queue<SpdyIOBuffer> queue_; |
116 const size_t kQueueSize = 100; | 112 const size_t kQueueSize = 100; |
117 | 113 |
118 // Insert items with random priority and increasing buffer size | 114 // Insert items with random priority and increasing buffer size |
119 for (size_t index = 0; index < kQueueSize; ++index) { | 115 for (size_t index = 0; index < kQueueSize; ++index) { |
120 queue_.push(SpdyIOBuffer( | 116 queue_.push(SpdyIOBuffer( |
121 new IOBufferWithSize(index + 1), | 117 new IOBufferWithSize(index + 1), |
122 index + 1, | 118 index + 1, |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 // Delete the first session. | 197 // Delete the first session. |
202 session = NULL; | 198 session = NULL; |
203 | 199 |
204 // Delete the second session. | 200 // Delete the second session. |
205 spdy_session_pool->Remove(session2); | 201 spdy_session_pool->Remove(session2); |
206 session2 = NULL; | 202 session2 = NULL; |
207 } | 203 } |
208 | 204 |
209 TEST_F(SpdySessionSpdy3Test, ClientPing) { | 205 TEST_F(SpdySessionSpdy3Test, ClientPing) { |
210 SpdySessionDependencies session_deps; | 206 SpdySessionDependencies session_deps; |
| 207 session_deps.enable_ping = true; |
211 session_deps.host_resolver->set_synchronous_mode(true); | 208 session_deps.host_resolver->set_synchronous_mode(true); |
212 | 209 |
213 MockConnect connect_data(SYNCHRONOUS, OK); | 210 MockConnect connect_data(SYNCHRONOUS, OK); |
214 scoped_ptr<SpdyFrame> read_ping(ConstructSpdyPing(1)); | 211 scoped_ptr<SpdyFrame> read_ping(ConstructSpdyPing(1)); |
215 MockRead reads[] = { | 212 MockRead reads[] = { |
216 CreateMockRead(*read_ping), | 213 CreateMockRead(*read_ping), |
217 MockRead(SYNCHRONOUS, 0, 0) // EOF | 214 MockRead(SYNCHRONOUS, 0, 0) // EOF |
218 }; | 215 }; |
219 scoped_ptr<SpdyFrame> write_ping(ConstructSpdyPing(1)); | 216 scoped_ptr<SpdyFrame> write_ping(ConstructSpdyPing(1)); |
220 MockWrite writes[] = { | 217 MockWrite writes[] = { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 MEDIUM, | 262 MEDIUM, |
266 &spdy_stream1, | 263 &spdy_stream1, |
267 BoundNetLog(), | 264 BoundNetLog(), |
268 callback1.callback())); | 265 callback1.callback())); |
269 scoped_ptr<TestSpdyStreamDelegate> delegate( | 266 scoped_ptr<TestSpdyStreamDelegate> delegate( |
270 new TestSpdyStreamDelegate(callback1.callback())); | 267 new TestSpdyStreamDelegate(callback1.callback())); |
271 spdy_stream1->SetDelegate(delegate.get()); | 268 spdy_stream1->SetDelegate(delegate.get()); |
272 | 269 |
273 base::TimeTicks before_ping_time = base::TimeTicks::Now(); | 270 base::TimeTicks before_ping_time = base::TimeTicks::Now(); |
274 | 271 |
275 // Enable sending of PING. | |
276 SpdySession::set_enable_ping_based_connection_checking(true); | |
277 session->set_connection_at_risk_of_loss_time(base::TimeDelta::FromSeconds(0)); | 272 session->set_connection_at_risk_of_loss_time(base::TimeDelta::FromSeconds(0)); |
278 session->set_hung_interval(base::TimeDelta::FromMilliseconds(50)); | 273 session->set_hung_interval(base::TimeDelta::FromMilliseconds(50)); |
279 | 274 |
280 session->SendPrefacePingIfNoneInFlight(); | 275 session->SendPrefacePingIfNoneInFlight(); |
281 | 276 |
282 EXPECT_EQ(OK, callback1.WaitForResult()); | 277 EXPECT_EQ(OK, callback1.WaitForResult()); |
283 | 278 |
284 session->CheckPingStatus(before_ping_time); | 279 session->CheckPingStatus(before_ping_time); |
285 | 280 |
286 EXPECT_EQ(0, session->pings_in_flight()); | 281 EXPECT_EQ(0, session->pings_in_flight()); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 // Delete the session. | 361 // Delete the session. |
367 session = NULL; | 362 session = NULL; |
368 } | 363 } |
369 | 364 |
370 TEST_F(SpdySessionSpdy3Test, DeleteExpiredPushStreams) { | 365 TEST_F(SpdySessionSpdy3Test, DeleteExpiredPushStreams) { |
371 SpdySessionDependencies session_deps; | 366 SpdySessionDependencies session_deps; |
372 session_deps.host_resolver->set_synchronous_mode(true); | 367 session_deps.host_resolver->set_synchronous_mode(true); |
373 | 368 |
374 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 369 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
375 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl); | 370 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 371 session_deps.time_func = TheNearFuture; |
376 | 372 |
377 scoped_refptr<HttpNetworkSession> http_session( | 373 scoped_refptr<HttpNetworkSession> http_session( |
378 SpdySessionDependencies::SpdyCreateSession(&session_deps)); | 374 SpdySessionDependencies::SpdyCreateSession(&session_deps)); |
379 | 375 |
380 const std::string kTestHost("www.google.com"); | 376 const std::string kTestHost("www.google.com"); |
381 const int kTestPort = 80; | 377 const int kTestPort = 80; |
382 HostPortPair test_host_port_pair(kTestHost, kTestPort); | 378 HostPortPair test_host_port_pair(kTestHost, kTestPort); |
383 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct()); | 379 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct()); |
384 | 380 |
385 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); | 381 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); |
386 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); | 382 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); |
387 scoped_refptr<SpdySession> session = | 383 scoped_refptr<SpdySession> session = |
388 spdy_session_pool->Get(pair, BoundNetLog()); | 384 spdy_session_pool->Get(pair, BoundNetLog()); |
389 EXPECT_TRUE(spdy_session_pool->HasSession(pair)); | 385 EXPECT_TRUE(spdy_session_pool->HasSession(pair)); |
390 | 386 |
391 // Give the session a SPDY3 framer. | 387 // Give the session a SPDY3 framer. |
392 session->buffered_spdy_framer_.reset(new BufferedSpdyFramer(3)); | 388 session->buffered_spdy_framer_.reset(new BufferedSpdyFramer(3, false)); |
393 | 389 |
394 // Create the associated stream and add to active streams. | 390 // Create the associated stream and add to active streams. |
395 scoped_ptr<SpdyHeaderBlock> request_headers(new SpdyHeaderBlock); | 391 scoped_ptr<SpdyHeaderBlock> request_headers(new SpdyHeaderBlock); |
396 (*request_headers)[":scheme"] = "http"; | 392 (*request_headers)[":scheme"] = "http"; |
397 (*request_headers)[":host"] = "www.google.com"; | 393 (*request_headers)[":host"] = "www.google.com"; |
398 (*request_headers)[":path"] = "/"; | 394 (*request_headers)[":path"] = "/"; |
399 | 395 |
400 scoped_refptr<SpdyStream> stream( | 396 scoped_refptr<SpdyStream> stream( |
401 new SpdyStream(session, false, session->net_log_)); | 397 new SpdyStream(session, false, session->net_log_)); |
402 stream->set_spdy_headers(request_headers.Pass()); | 398 stream->set_spdy_headers(request_headers.Pass()); |
403 session->ActivateStream(stream); | 399 session->ActivateStream(stream); |
404 | 400 |
405 SpdyHeaderBlock headers; | 401 SpdyHeaderBlock headers; |
406 headers[":scheme"] = "http"; | 402 headers[":scheme"] = "http"; |
407 headers[":host"] = "www.google.com"; | 403 headers[":host"] = "www.google.com"; |
408 headers[":path"] = "/a.dat"; | 404 headers[":path"] = "/a.dat"; |
409 session->OnSynStream(2, 1, 0, 0, true, false, headers); | 405 session->OnSynStream(2, 1, 0, 0, true, false, headers); |
410 | 406 |
411 // Verify that there is one unclaimed push stream. | 407 // Verify that there is one unclaimed push stream. |
412 EXPECT_EQ(1u, session->num_unclaimed_pushed_streams()); | 408 EXPECT_EQ(1u, session->num_unclaimed_pushed_streams()); |
413 SpdySession::PushedStreamMap::iterator iter = | 409 SpdySession::PushedStreamMap::iterator iter = |
414 session->unclaimed_pushed_streams_.find("http://www.google.com/a.dat"); | 410 session->unclaimed_pushed_streams_.find("http://www.google.com/a.dat"); |
415 EXPECT_TRUE(session->unclaimed_pushed_streams_.end() != iter); | 411 EXPECT_TRUE(session->unclaimed_pushed_streams_.end() != iter); |
416 | 412 |
417 // Shift time. | 413 // Shift time. |
418 SpdySession::set_time_func(the_near_future); | 414 g_delta_seconds = 301; |
419 | 415 |
420 headers[":scheme"] = "http"; | 416 headers[":scheme"] = "http"; |
421 headers[":host"] = "www.google.com"; | 417 headers[":host"] = "www.google.com"; |
422 headers[":path"] = "/b.dat"; | 418 headers[":path"] = "/b.dat"; |
423 session->OnSynStream(4, 1, 0, 0, true, false, headers); | 419 session->OnSynStream(4, 1, 0, 0, true, false, headers); |
424 | 420 |
425 // Verify that the second pushed stream evicted the first pushed stream. | 421 // Verify that the second pushed stream evicted the first pushed stream. |
426 EXPECT_EQ(1u, session->num_unclaimed_pushed_streams()); | 422 EXPECT_EQ(1u, session->num_unclaimed_pushed_streams()); |
427 iter = session->unclaimed_pushed_streams_.find("http://www.google.com/b.dat"); | 423 iter = session->unclaimed_pushed_streams_.find("http://www.google.com/b.dat"); |
428 EXPECT_TRUE(session->unclaimed_pushed_streams_.end() != iter); | 424 EXPECT_TRUE(session->unclaimed_pushed_streams_.end() != iter); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 TestCompletionCallback callback1; | 484 TestCompletionCallback callback1; |
489 EXPECT_EQ(OK, session->CreateStream(url, | 485 EXPECT_EQ(OK, session->CreateStream(url, |
490 MEDIUM, | 486 MEDIUM, |
491 &spdy_stream1, | 487 &spdy_stream1, |
492 BoundNetLog(), | 488 BoundNetLog(), |
493 callback1.callback())); | 489 callback1.callback())); |
494 scoped_ptr<TestSpdyStreamDelegate> delegate( | 490 scoped_ptr<TestSpdyStreamDelegate> delegate( |
495 new TestSpdyStreamDelegate(callback1.callback())); | 491 new TestSpdyStreamDelegate(callback1.callback())); |
496 spdy_stream1->SetDelegate(delegate.get()); | 492 spdy_stream1->SetDelegate(delegate.get()); |
497 | 493 |
498 // Enable sending of PING. | |
499 SpdySession::set_enable_ping_based_connection_checking(true); | |
500 session->set_connection_at_risk_of_loss_time(base::TimeDelta::FromSeconds(0)); | 494 session->set_connection_at_risk_of_loss_time(base::TimeDelta::FromSeconds(0)); |
501 session->set_hung_interval(base::TimeDelta::FromSeconds(0)); | 495 session->set_hung_interval(base::TimeDelta::FromSeconds(0)); |
502 | 496 |
503 // Send a PING frame. | 497 // Send a PING frame. |
504 session->WritePingFrame(1); | 498 session->WritePingFrame(1); |
505 EXPECT_LT(0, session->pings_in_flight()); | 499 EXPECT_LT(0, session->pings_in_flight()); |
506 EXPECT_GE(session->next_ping_id(), static_cast<uint32>(1)); | 500 EXPECT_GE(session->next_ping_id(), static_cast<uint32>(1)); |
507 EXPECT_TRUE(session->check_ping_status_pending()); | 501 EXPECT_TRUE(session->check_ping_status_pending()); |
508 | 502 |
509 // Assert session is not closed. | 503 // Assert session is not closed. |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 const uint32 kInitialRecvWindowSize = 10 * 1024 * 1024; | 854 const uint32 kInitialRecvWindowSize = 10 * 1024 * 1024; |
861 settings[kSpdySettingsIds1] = | 855 settings[kSpdySettingsIds1] = |
862 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kMaxConcurrentPushedStreams); | 856 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kMaxConcurrentPushedStreams); |
863 settings[kSpdySettingsIds2] = | 857 settings[kSpdySettingsIds2] = |
864 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kInitialRecvWindowSize); | 858 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kInitialRecvWindowSize); |
865 MockConnect connect_data(SYNCHRONOUS, OK); | 859 MockConnect connect_data(SYNCHRONOUS, OK); |
866 scoped_ptr<SpdyFrame> settings_frame(ConstructSpdySettings(settings)); | 860 scoped_ptr<SpdyFrame> settings_frame(ConstructSpdySettings(settings)); |
867 MockWrite writes[] = { | 861 MockWrite writes[] = { |
868 CreateMockWrite(*settings_frame), | 862 CreateMockWrite(*settings_frame), |
869 }; | 863 }; |
870 SpdySession::set_default_initial_recv_window_size(kInitialRecvWindowSize); | 864 session_deps.initial_recv_window_size = kInitialRecvWindowSize; |
871 | 865 |
872 StaticSocketDataProvider data( | 866 StaticSocketDataProvider data( |
873 reads, arraysize(reads), writes, arraysize(writes)); | 867 reads, arraysize(reads), writes, arraysize(writes)); |
874 data.set_connect_data(connect_data); | 868 data.set_connect_data(connect_data); |
875 session_deps.socket_factory->AddSocketDataProvider(&data); | 869 session_deps.socket_factory->AddSocketDataProvider(&data); |
876 | 870 |
877 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 871 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
878 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl); | 872 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl); |
879 | 873 |
880 scoped_refptr<HttpNetworkSession> http_session( | 874 scoped_refptr<HttpNetworkSession> http_session( |
(...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1920 BoundNetLog())); | 1914 BoundNetLog())); |
1921 | 1915 |
1922 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); | 1916 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); |
1923 EXPECT_TRUE(session->VerifyDomainAuthentication("www.example.org")); | 1917 EXPECT_TRUE(session->VerifyDomainAuthentication("www.example.org")); |
1924 EXPECT_TRUE(session->VerifyDomainAuthentication("mail.example.org")); | 1918 EXPECT_TRUE(session->VerifyDomainAuthentication("mail.example.org")); |
1925 EXPECT_FALSE(session->VerifyDomainAuthentication("mail.example.com")); | 1919 EXPECT_FALSE(session->VerifyDomainAuthentication("mail.example.com")); |
1926 EXPECT_FALSE(session->VerifyDomainAuthentication("mail.google.com")); | 1920 EXPECT_FALSE(session->VerifyDomainAuthentication("mail.google.com")); |
1927 } | 1921 } |
1928 | 1922 |
1929 } // namespace net | 1923 } // namespace net |
OLD | NEW |