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

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: Fix flip_in_mem_edsm_server 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
« no previous file with comments | « net/spdy/spdy_session_pool.cc ('k') | net/spdy/spdy_session_spdy3_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 base::TimeTicks the_near_future() { 22 static int g_delta_seconds = 0;
23 return base::TimeTicks::Now() + 23 base::TimeTicks TheNearFuture() {
24 base::TimeDelta::FromSeconds(301); 24 return base::TimeTicks::Now() + base::TimeDelta::FromSeconds(g_delta_seconds);
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: 61 protected:
64 virtual void SetUp() { 62 void SetUp() {
65 SpdySession::set_default_protocol(kProtoSPDY2); 63 g_delta_seconds = 0;
66 } 64 }
67
68 private:
69 SpdyTestStateHelper spdy_state_;
70 }; 65 };
71 66
72 class TestSpdyStreamDelegate : public net::SpdyStream::Delegate { 67 class TestSpdyStreamDelegate : public net::SpdyStream::Delegate {
73 public: 68 public:
74 explicit TestSpdyStreamDelegate(const CompletionCallback& callback) 69 explicit TestSpdyStreamDelegate(const CompletionCallback& callback)
75 : callback_(callback) {} 70 : callback_(callback) {}
76 virtual ~TestSpdyStreamDelegate() {} 71 virtual ~TestSpdyStreamDelegate() {}
77 72
78 virtual bool OnSendHeadersComplete(int status) OVERRIDE { return true; } 73 virtual bool OnSendHeadersComplete(int status) OVERRIDE { return true; }
79 74
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 MEDIUM, 259 MEDIUM,
265 &spdy_stream1, 260 &spdy_stream1,
266 BoundNetLog(), 261 BoundNetLog(),
267 callback1.callback())); 262 callback1.callback()));
268 scoped_ptr<TestSpdyStreamDelegate> delegate( 263 scoped_ptr<TestSpdyStreamDelegate> delegate(
269 new TestSpdyStreamDelegate(callback1.callback())); 264 new TestSpdyStreamDelegate(callback1.callback()));
270 spdy_stream1->SetDelegate(delegate.get()); 265 spdy_stream1->SetDelegate(delegate.get());
271 266
272 base::TimeTicks before_ping_time = base::TimeTicks::Now(); 267 base::TimeTicks before_ping_time = base::TimeTicks::Now();
273 268
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)); 269 session->set_connection_at_risk_of_loss_time(base::TimeDelta::FromSeconds(0));
277 session->set_hung_interval(base::TimeDelta::FromMilliseconds(50)); 270 session->set_hung_interval(base::TimeDelta::FromMilliseconds(50));
278 271
279 session->SendPrefacePingIfNoneInFlight(); 272 session->SendPrefacePingIfNoneInFlight();
280 273
281 EXPECT_EQ(OK, callback1.WaitForResult()); 274 EXPECT_EQ(OK, callback1.WaitForResult());
282 275
283 session->CheckPingStatus(before_ping_time); 276 session->CheckPingStatus(before_ping_time);
284 277
285 EXPECT_EQ(0, session->pings_in_flight()); 278 EXPECT_EQ(0, session->pings_in_flight());
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 // Delete the session. 358 // Delete the session.
366 session = NULL; 359 session = NULL;
367 } 360 }
368 361
369 TEST_F(SpdySessionSpdy2Test, DeleteExpiredPushStreams) { 362 TEST_F(SpdySessionSpdy2Test, DeleteExpiredPushStreams) {
370 SpdySessionDependencies session_deps; 363 SpdySessionDependencies session_deps;
371 session_deps.host_resolver->set_synchronous_mode(true); 364 session_deps.host_resolver->set_synchronous_mode(true);
372 365
373 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 366 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
374 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl); 367 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl);
368 session_deps.time_func = TheNearFuture;
375 369
376 scoped_refptr<HttpNetworkSession> http_session( 370 scoped_refptr<HttpNetworkSession> http_session(
377 SpdySessionDependencies::SpdyCreateSession(&session_deps)); 371 SpdySessionDependencies::SpdyCreateSession(&session_deps));
378 372
379 const std::string kTestHost("www.google.com"); 373 const std::string kTestHost("www.google.com");
380 const int kTestPort = 80; 374 const int kTestPort = 80;
381 HostPortPair test_host_port_pair(kTestHost, kTestPort); 375 HostPortPair test_host_port_pair(kTestHost, kTestPort);
382 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct()); 376 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct());
383 377
384 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); 378 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool());
385 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); 379 EXPECT_FALSE(spdy_session_pool->HasSession(pair));
386 scoped_refptr<SpdySession> session = 380 scoped_refptr<SpdySession> session =
387 spdy_session_pool->Get(pair, BoundNetLog()); 381 spdy_session_pool->Get(pair, BoundNetLog());
388 EXPECT_TRUE(spdy_session_pool->HasSession(pair)); 382 EXPECT_TRUE(spdy_session_pool->HasSession(pair));
389 383
390 // Give the session a SPDY2 framer. 384 // Give the session a SPDY2 framer.
391 session->buffered_spdy_framer_.reset(new BufferedSpdyFramer(2)); 385 session->buffered_spdy_framer_.reset(new BufferedSpdyFramer(2, false));
392 386
393 // Create the associated stream and add to active streams. 387 // Create the associated stream and add to active streams.
394 scoped_ptr<SpdyHeaderBlock> request_headers(new SpdyHeaderBlock); 388 scoped_ptr<SpdyHeaderBlock> request_headers(new SpdyHeaderBlock);
395 (*request_headers)["scheme"] = "http"; 389 (*request_headers)["scheme"] = "http";
396 (*request_headers)["host"] = "www.google.com"; 390 (*request_headers)["host"] = "www.google.com";
397 (*request_headers)["url"] = "/"; 391 (*request_headers)["url"] = "/";
398 392
399 scoped_refptr<SpdyStream> stream( 393 scoped_refptr<SpdyStream> stream(
400 new SpdyStream(session, false, session->net_log_)); 394 new SpdyStream(session, false, session->net_log_));
401 stream->set_spdy_headers(request_headers.Pass()); 395 stream->set_spdy_headers(request_headers.Pass());
402 session->ActivateStream(stream); 396 session->ActivateStream(stream);
403 397
404 SpdyHeaderBlock headers; 398 SpdyHeaderBlock headers;
405 headers["url"] = "http://www.google.com/a.dat"; 399 headers["url"] = "http://www.google.com/a.dat";
406 session->OnSynStream(2, 1, 0, 0, true, false, headers); 400 session->OnSynStream(2, 1, 0, 0, true, false, headers);
407 401
408 // Verify that there is one unclaimed push stream. 402 // Verify that there is one unclaimed push stream.
409 EXPECT_EQ(1u, session->num_unclaimed_pushed_streams()); 403 EXPECT_EQ(1u, session->num_unclaimed_pushed_streams());
410 SpdySession::PushedStreamMap::iterator iter = 404 SpdySession::PushedStreamMap::iterator iter =
411 session->unclaimed_pushed_streams_.find("http://www.google.com/a.dat"); 405 session->unclaimed_pushed_streams_.find("http://www.google.com/a.dat");
412 EXPECT_TRUE(session->unclaimed_pushed_streams_.end() != iter); 406 EXPECT_TRUE(session->unclaimed_pushed_streams_.end() != iter);
413 407
414 // Shift time. 408 // Shift time.
415 SpdySession::set_time_func(the_near_future); 409 g_delta_seconds = 301;
416 410
417 headers["url"] = "http://www.google.com/b.dat"; 411 headers["url"] = "http://www.google.com/b.dat";
418 session->OnSynStream(4, 1, 0, 0, true, false, headers); 412 session->OnSynStream(4, 1, 0, 0, true, false, headers);
419 413
420 // Verify that the second pushed stream evicted the first pushed stream. 414 // Verify that the second pushed stream evicted the first pushed stream.
421 EXPECT_EQ(1u, session->num_unclaimed_pushed_streams()); 415 EXPECT_EQ(1u, session->num_unclaimed_pushed_streams());
422 iter = session->unclaimed_pushed_streams_.find("http://www.google.com/b.dat"); 416 iter = session->unclaimed_pushed_streams_.find("http://www.google.com/b.dat");
423 EXPECT_TRUE(session->unclaimed_pushed_streams_.end() != iter); 417 EXPECT_TRUE(session->unclaimed_pushed_streams_.end() != iter);
424 418
425 // Delete the session. 419 // Delete the session.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 TestCompletionCallback callback1; 477 TestCompletionCallback callback1;
484 EXPECT_EQ(OK, session->CreateStream(url, 478 EXPECT_EQ(OK, session->CreateStream(url,
485 MEDIUM, 479 MEDIUM,
486 &spdy_stream1, 480 &spdy_stream1,
487 BoundNetLog(), 481 BoundNetLog(),
488 callback1.callback())); 482 callback1.callback()));
489 scoped_ptr<TestSpdyStreamDelegate> delegate( 483 scoped_ptr<TestSpdyStreamDelegate> delegate(
490 new TestSpdyStreamDelegate(callback1.callback())); 484 new TestSpdyStreamDelegate(callback1.callback()));
491 spdy_stream1->SetDelegate(delegate.get()); 485 spdy_stream1->SetDelegate(delegate.get());
492 486
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)); 487 session->set_connection_at_risk_of_loss_time(base::TimeDelta::FromSeconds(0));
496 session->set_hung_interval(base::TimeDelta::FromSeconds(0)); 488 session->set_hung_interval(base::TimeDelta::FromSeconds(0));
497 489
498 // Send a PING frame. 490 // Send a PING frame.
499 session->WritePingFrame(1); 491 session->WritePingFrame(1);
500 EXPECT_LT(0, session->pings_in_flight()); 492 EXPECT_LT(0, session->pings_in_flight());
501 EXPECT_GE(session->next_ping_id(), static_cast<uint32>(1)); 493 EXPECT_GE(session->next_ping_id(), static_cast<uint32>(1));
502 EXPECT_TRUE(session->check_ping_status_pending()); 494 EXPECT_TRUE(session->check_ping_status_pending());
503 495
504 // Assert session is not closed. 496 // Assert session is not closed.
(...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after
1588 session->CloseSessionOnError(ERR_ABORTED, true, ""); 1580 session->CloseSessionOnError(ERR_ABORTED, true, "");
1589 1581
1590 EXPECT_TRUE(spdy_stream1->closed()); 1582 EXPECT_TRUE(spdy_stream1->closed());
1591 EXPECT_TRUE(spdy_stream2->closed()); 1583 EXPECT_TRUE(spdy_stream2->closed());
1592 1584
1593 spdy_stream1 = NULL; 1585 spdy_stream1 = NULL;
1594 spdy_stream2 = NULL; 1586 spdy_stream2 = NULL;
1595 } 1587 }
1596 1588
1597 } // namespace net 1589 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_session_pool.cc ('k') | net/spdy/spdy_session_spdy3_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698