Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: net/spdy/spdy_session_spdy2_unittest.cc

Issue 11415219: Move a number of static variables SPDY to HttpNetworkSession::Params. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moar cleanup Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/host_cache.h" 7 #include "net/base/host_cache.h"
8 #include "net/base/ip_endpoint.h" 8 #include "net/base/ip_endpoint.h"
9 #include "net/base/net_log_unittest.h" 9 #include "net/base/net_log_unittest.h"
10 #include "net/spdy/spdy_io_buffer.h" 10 #include "net/spdy/spdy_io_buffer.h"
11 #include "net/spdy/spdy_session_pool.h" 11 #include "net/spdy/spdy_session_pool.h"
12 #include "net/spdy/spdy_stream.h" 12 #include "net/spdy/spdy_stream.h"
13 #include "net/spdy/spdy_test_util_spdy2.h" 13 #include "net/spdy/spdy_test_util_spdy2.h"
14 #include "testing/platform_test.h" 14 #include "testing/platform_test.h"
15 15
16 using namespace net::test_spdy2; 16 using namespace net::test_spdy2;
17 17
18 namespace net { 18 namespace net {
19 19
20 namespace { 20 namespace {
21 21
22 static int g_delta_seconds = 0;
22 base::TimeTicks the_near_future() { 23 base::TimeTicks the_near_future() {
23 return base::TimeTicks::Now() + 24 return base::TimeTicks::Now() + base::TimeDelta::FromSeconds(g_delta_seconds);
24 base::TimeDelta::FromSeconds(301);
25 } 25 }
26 26
27 class ClosingDelegate : public SpdyStream::Delegate { 27 class ClosingDelegate : public SpdyStream::Delegate {
28 public: 28 public:
29 ClosingDelegate(SpdyStream* stream) : stream_(stream) {} 29 ClosingDelegate(SpdyStream* stream) : stream_(stream) {}
30 30
31 // SpdyStream::Delegate implementation: 31 // SpdyStream::Delegate implementation:
32 virtual bool OnSendHeadersComplete(int status) OVERRIDE { 32 virtual bool OnSendHeadersComplete(int status) OVERRIDE {
33 return true; 33 return true;
34 } 34 }
(...skipping 15 matching lines...) Expand all
50 virtual void OnDataSent(int length) OVERRIDE {} 50 virtual void OnDataSent(int length) OVERRIDE {}
51 virtual void OnClose(int status) OVERRIDE { 51 virtual void OnClose(int status) OVERRIDE {
52 stream_->Close(); 52 stream_->Close();
53 } 53 }
54 private: 54 private:
55 SpdyStream* stream_; 55 SpdyStream* stream_;
56 }; 56 };
57 57
58 } // namespace 58 } // namespace
59 59
60 // TODO(cbentzel): Expose compression setter/getter in public SpdySession
61 // interface rather than going through all these contortions.
62 class SpdySessionSpdy2Test : public PlatformTest { 60 class SpdySessionSpdy2Test : public PlatformTest {
63 protected:
64 virtual void SetUp() {
65 SpdySession::set_default_protocol(kProtoSPDY2);
66 }
67
68 private:
69 SpdyTestStateHelper spdy_state_;
70 }; 61 };
71 62
72 class TestSpdyStreamDelegate : public net::SpdyStream::Delegate { 63 class TestSpdyStreamDelegate : public net::SpdyStream::Delegate {
73 public: 64 public:
74 explicit TestSpdyStreamDelegate(const CompletionCallback& callback) 65 explicit TestSpdyStreamDelegate(const CompletionCallback& callback)
75 : callback_(callback) {} 66 : callback_(callback) {}
76 virtual ~TestSpdyStreamDelegate() {} 67 virtual ~TestSpdyStreamDelegate() {}
77 68
78 virtual bool OnSendHeadersComplete(int status) OVERRIDE { return true; } 69 virtual bool OnSendHeadersComplete(int status) OVERRIDE { return true; }
79 70
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 MEDIUM, 255 MEDIUM,
265 &spdy_stream1, 256 &spdy_stream1,
266 BoundNetLog(), 257 BoundNetLog(),
267 callback1.callback())); 258 callback1.callback()));
268 scoped_ptr<TestSpdyStreamDelegate> delegate( 259 scoped_ptr<TestSpdyStreamDelegate> delegate(
269 new TestSpdyStreamDelegate(callback1.callback())); 260 new TestSpdyStreamDelegate(callback1.callback()));
270 spdy_stream1->SetDelegate(delegate.get()); 261 spdy_stream1->SetDelegate(delegate.get());
271 262
272 base::TimeTicks before_ping_time = base::TimeTicks::Now(); 263 base::TimeTicks before_ping_time = base::TimeTicks::Now();
273 264
274 // Enable sending of PING.
275 SpdySession::set_enable_ping_based_connection_checking(true);
276 session->set_connection_at_risk_of_loss_time(base::TimeDelta::FromSeconds(0)); 265 session->set_connection_at_risk_of_loss_time(base::TimeDelta::FromSeconds(0));
277 session->set_hung_interval(base::TimeDelta::FromMilliseconds(50)); 266 session->set_hung_interval(base::TimeDelta::FromMilliseconds(50));
278 267
279 session->SendPrefacePingIfNoneInFlight(); 268 session->SendPrefacePingIfNoneInFlight();
280 269
281 EXPECT_EQ(OK, callback1.WaitForResult()); 270 EXPECT_EQ(OK, callback1.WaitForResult());
282 271
283 session->CheckPingStatus(before_ping_time); 272 session->CheckPingStatus(before_ping_time);
284 273
285 EXPECT_EQ(0, session->pings_in_flight()); 274 EXPECT_EQ(0, session->pings_in_flight());
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 // Delete the session. 354 // Delete the session.
366 session = NULL; 355 session = NULL;
367 } 356 }
368 357
369 TEST_F(SpdySessionSpdy2Test, DeleteExpiredPushStreams) { 358 TEST_F(SpdySessionSpdy2Test, DeleteExpiredPushStreams) {
370 SpdySessionDependencies session_deps; 359 SpdySessionDependencies session_deps;
371 session_deps.host_resolver->set_synchronous_mode(true); 360 session_deps.host_resolver->set_synchronous_mode(true);
372 361
373 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 362 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
374 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl); 363 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl);
364 session_deps.time_func = the_near_future;
375 365
376 scoped_refptr<HttpNetworkSession> http_session( 366 scoped_refptr<HttpNetworkSession> http_session(
377 SpdySessionDependencies::SpdyCreateSession(&session_deps)); 367 SpdySessionDependencies::SpdyCreateSession(&session_deps));
378 368
379 const std::string kTestHost("www.google.com"); 369 const std::string kTestHost("www.google.com");
380 const int kTestPort = 80; 370 const int kTestPort = 80;
381 HostPortPair test_host_port_pair(kTestHost, kTestPort); 371 HostPortPair test_host_port_pair(kTestHost, kTestPort);
382 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct()); 372 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct());
383 373
384 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); 374 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool());
385 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); 375 EXPECT_FALSE(spdy_session_pool->HasSession(pair));
386 scoped_refptr<SpdySession> session = 376 scoped_refptr<SpdySession> session =
387 spdy_session_pool->Get(pair, BoundNetLog()); 377 spdy_session_pool->Get(pair, BoundNetLog());
388 EXPECT_TRUE(spdy_session_pool->HasSession(pair)); 378 EXPECT_TRUE(spdy_session_pool->HasSession(pair));
389 379
390 // Give the session a SPDY2 framer. 380 // Give the session a SPDY2 framer.
391 session->buffered_spdy_framer_.reset(new BufferedSpdyFramer(2)); 381 session->buffered_spdy_framer_.reset(new BufferedSpdyFramer(2, false));
392 382
393 // Create the associated stream and add to active streams. 383 // Create the associated stream and add to active streams.
394 scoped_ptr<SpdyHeaderBlock> request_headers(new SpdyHeaderBlock); 384 scoped_ptr<SpdyHeaderBlock> request_headers(new SpdyHeaderBlock);
395 (*request_headers)["scheme"] = "http"; 385 (*request_headers)["scheme"] = "http";
396 (*request_headers)["host"] = "www.google.com"; 386 (*request_headers)["host"] = "www.google.com";
397 (*request_headers)["url"] = "/"; 387 (*request_headers)["url"] = "/";
398 388
399 scoped_refptr<SpdyStream> stream( 389 scoped_refptr<SpdyStream> stream(
400 new SpdyStream(session, false, session->net_log_)); 390 new SpdyStream(session, false, session->net_log_));
401 stream->set_spdy_headers(request_headers.Pass()); 391 stream->set_spdy_headers(request_headers.Pass());
402 session->ActivateStream(stream); 392 session->ActivateStream(stream);
403 393
404 SpdyHeaderBlock headers; 394 SpdyHeaderBlock headers;
405 headers["url"] = "http://www.google.com/a.dat"; 395 headers["url"] = "http://www.google.com/a.dat";
406 session->OnSynStream(2, 1, 0, 0, true, false, headers); 396 session->OnSynStream(2, 1, 0, 0, true, false, headers);
407 397
408 // Verify that there is one unclaimed push stream. 398 // Verify that there is one unclaimed push stream.
409 EXPECT_EQ(1u, session->num_unclaimed_pushed_streams()); 399 EXPECT_EQ(1u, session->num_unclaimed_pushed_streams());
410 SpdySession::PushedStreamMap::iterator iter = 400 SpdySession::PushedStreamMap::iterator iter =
411 session->unclaimed_pushed_streams_.find("http://www.google.com/a.dat"); 401 session->unclaimed_pushed_streams_.find("http://www.google.com/a.dat");
412 EXPECT_TRUE(session->unclaimed_pushed_streams_.end() != iter); 402 EXPECT_TRUE(session->unclaimed_pushed_streams_.end() != iter);
413 403
414 // Shift time. 404 // Shift time.
415 SpdySession::set_time_func(the_near_future); 405 g_delta_seconds = 301;
416 406
417 headers["url"] = "http://www.google.com/b.dat"; 407 headers["url"] = "http://www.google.com/b.dat";
418 session->OnSynStream(4, 1, 0, 0, true, false, headers); 408 session->OnSynStream(4, 1, 0, 0, true, false, headers);
419 409
420 // Verify that the second pushed stream evicted the first pushed stream. 410 // Verify that the second pushed stream evicted the first pushed stream.
421 EXPECT_EQ(1u, session->num_unclaimed_pushed_streams()); 411 EXPECT_EQ(1u, session->num_unclaimed_pushed_streams());
422 iter = session->unclaimed_pushed_streams_.find("http://www.google.com/b.dat"); 412 iter = session->unclaimed_pushed_streams_.find("http://www.google.com/b.dat");
423 EXPECT_TRUE(session->unclaimed_pushed_streams_.end() != iter); 413 EXPECT_TRUE(session->unclaimed_pushed_streams_.end() != iter);
424 414
425 // Delete the session. 415 // Delete the session.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 TestCompletionCallback callback1; 473 TestCompletionCallback callback1;
484 EXPECT_EQ(OK, session->CreateStream(url, 474 EXPECT_EQ(OK, session->CreateStream(url,
485 MEDIUM, 475 MEDIUM,
486 &spdy_stream1, 476 &spdy_stream1,
487 BoundNetLog(), 477 BoundNetLog(),
488 callback1.callback())); 478 callback1.callback()));
489 scoped_ptr<TestSpdyStreamDelegate> delegate( 479 scoped_ptr<TestSpdyStreamDelegate> delegate(
490 new TestSpdyStreamDelegate(callback1.callback())); 480 new TestSpdyStreamDelegate(callback1.callback()));
491 spdy_stream1->SetDelegate(delegate.get()); 481 spdy_stream1->SetDelegate(delegate.get());
492 482
493 // Enable sending of PING.
494 SpdySession::set_enable_ping_based_connection_checking(true);
495 session->set_connection_at_risk_of_loss_time(base::TimeDelta::FromSeconds(0)); 483 session->set_connection_at_risk_of_loss_time(base::TimeDelta::FromSeconds(0));
496 session->set_hung_interval(base::TimeDelta::FromSeconds(0)); 484 session->set_hung_interval(base::TimeDelta::FromSeconds(0));
497 485
498 // Send a PING frame. 486 // Send a PING frame.
499 session->WritePingFrame(1); 487 session->WritePingFrame(1);
500 EXPECT_LT(0, session->pings_in_flight()); 488 EXPECT_LT(0, session->pings_in_flight());
501 EXPECT_GE(session->next_ping_id(), static_cast<uint32>(1)); 489 EXPECT_GE(session->next_ping_id(), static_cast<uint32>(1));
502 EXPECT_TRUE(session->check_ping_status_pending()); 490 EXPECT_TRUE(session->check_ping_status_pending());
503 491
504 // Assert session is not closed. 492 // Assert session is not closed.
(...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after
1588 session->CloseSessionOnError(ERR_ABORTED, true, ""); 1576 session->CloseSessionOnError(ERR_ABORTED, true, "");
1589 1577
1590 EXPECT_TRUE(spdy_stream1->closed()); 1578 EXPECT_TRUE(spdy_stream1->closed());
1591 EXPECT_TRUE(spdy_stream2->closed()); 1579 EXPECT_TRUE(spdy_stream2->closed());
1592 1580
1593 spdy_stream1 = NULL; 1581 spdy_stream1 = NULL;
1594 spdy_stream2 = NULL; 1582 spdy_stream2 = NULL;
1595 } 1583 }
1596 1584
1597 } // namespace net 1585 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698