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

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

Issue 2801603003: Add SpdyString alias for std::string in net/spdy. (Closed)
Patch Set: Created 3 years, 8 months 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
« no previous file with comments | « net/spdy/spdy_session_pool.cc ('k') | net/spdy/spdy_session_test_util.h » ('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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_pool.h" 5 #include "net/spdy/spdy_session_pool.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 #include <memory> 8 #include <memory>
9 #include <string>
10 #include <utility> 9 #include <utility>
11 10
12 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
13 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
14 #include "base/run_loop.h" 13 #include "base/run_loop.h"
15 #include "base/test/histogram_tester.h" 14 #include "base/test/histogram_tester.h"
16 #include "base/trace_event/memory_allocator_dump.h" 15 #include "base/trace_event/memory_allocator_dump.h"
17 #include "base/trace_event/process_memory_dump.h" 16 #include "base/trace_event/process_memory_dump.h"
18 #include "base/trace_event/trace_event_argument.h" 17 #include "base/trace_event/trace_event_argument.h"
19 #include "net/dns/host_cache.h" 18 #include "net/dns/host_cache.h"
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 data1.set_connect_data(connect_data); 162 data1.set_connect_data(connect_data);
164 session_deps_.socket_factory->AddSocketDataProvider(&data1); 163 session_deps_.socket_factory->AddSocketDataProvider(&data1);
165 164
166 AddSSLSocketData(); 165 AddSSLSocketData();
167 AddSSLSocketData(); 166 AddSSLSocketData();
168 AddSSLSocketData(); 167 AddSSLSocketData();
169 168
170 CreateNetworkSession(); 169 CreateNetworkSession();
171 170
172 // Set up session 1 171 // Set up session 1
173 const std::string kTestHost1("www.example.org"); 172 const SpdyString kTestHost1("www.example.org");
174 HostPortPair test_host_port_pair1(kTestHost1, 80); 173 HostPortPair test_host_port_pair1(kTestHost1, 80);
175 SpdySessionKey key1(test_host_port_pair1, ProxyServer::Direct(), 174 SpdySessionKey key1(test_host_port_pair1, ProxyServer::Direct(),
176 PRIVACY_MODE_DISABLED); 175 PRIVACY_MODE_DISABLED);
177 base::WeakPtr<SpdySession> session1 = 176 base::WeakPtr<SpdySession> session1 =
178 CreateSecureSpdySession(http_session_.get(), key1, NetLogWithSource()); 177 CreateSecureSpdySession(http_session_.get(), key1, NetLogWithSource());
179 GURL url1(kTestHost1); 178 GURL url1(kTestHost1);
180 base::WeakPtr<SpdyStream> spdy_stream1 = CreateStreamSynchronously( 179 base::WeakPtr<SpdyStream> spdy_stream1 = CreateStreamSynchronously(
181 SPDY_BIDIRECTIONAL_STREAM, session1, url1, MEDIUM, NetLogWithSource()); 180 SPDY_BIDIRECTIONAL_STREAM, session1, url1, MEDIUM, NetLogWithSource());
182 ASSERT_TRUE(spdy_stream1); 181 ASSERT_TRUE(spdy_stream1);
183 182
184 // Set up session 2 183 // Set up session 2
185 StaticSocketDataProvider data2(reads, arraysize(reads), nullptr, 0); 184 StaticSocketDataProvider data2(reads, arraysize(reads), nullptr, 0);
186 data2.set_connect_data(connect_data); 185 data2.set_connect_data(connect_data);
187 session_deps_.socket_factory->AddSocketDataProvider(&data2); 186 session_deps_.socket_factory->AddSocketDataProvider(&data2);
188 const std::string kTestHost2("mail.example.org"); 187 const SpdyString kTestHost2("mail.example.org");
189 HostPortPair test_host_port_pair2(kTestHost2, 80); 188 HostPortPair test_host_port_pair2(kTestHost2, 80);
190 SpdySessionKey key2(test_host_port_pair2, ProxyServer::Direct(), 189 SpdySessionKey key2(test_host_port_pair2, ProxyServer::Direct(),
191 PRIVACY_MODE_DISABLED); 190 PRIVACY_MODE_DISABLED);
192 base::WeakPtr<SpdySession> session2 = 191 base::WeakPtr<SpdySession> session2 =
193 CreateSecureSpdySession(http_session_.get(), key2, NetLogWithSource()); 192 CreateSecureSpdySession(http_session_.get(), key2, NetLogWithSource());
194 GURL url2(kTestHost2); 193 GURL url2(kTestHost2);
195 base::WeakPtr<SpdyStream> spdy_stream2 = CreateStreamSynchronously( 194 base::WeakPtr<SpdyStream> spdy_stream2 = CreateStreamSynchronously(
196 SPDY_BIDIRECTIONAL_STREAM, session2, url2, MEDIUM, NetLogWithSource()); 195 SPDY_BIDIRECTIONAL_STREAM, session2, url2, MEDIUM, NetLogWithSource());
197 ASSERT_TRUE(spdy_stream2); 196 ASSERT_TRUE(spdy_stream2);
198 197
199 // Set up session 3 198 // Set up session 3
200 StaticSocketDataProvider data3(reads, arraysize(reads), nullptr, 0); 199 StaticSocketDataProvider data3(reads, arraysize(reads), nullptr, 0);
201 data3.set_connect_data(connect_data); 200 data3.set_connect_data(connect_data);
202 session_deps_.socket_factory->AddSocketDataProvider(&data3); 201 session_deps_.socket_factory->AddSocketDataProvider(&data3);
203 const std::string kTestHost3("mail.example.com"); 202 const SpdyString kTestHost3("mail.example.com");
204 HostPortPair test_host_port_pair3(kTestHost3, 80); 203 HostPortPair test_host_port_pair3(kTestHost3, 80);
205 SpdySessionKey key3(test_host_port_pair3, ProxyServer::Direct(), 204 SpdySessionKey key3(test_host_port_pair3, ProxyServer::Direct(),
206 PRIVACY_MODE_DISABLED); 205 PRIVACY_MODE_DISABLED);
207 base::WeakPtr<SpdySession> session3 = 206 base::WeakPtr<SpdySession> session3 =
208 CreateSecureSpdySession(http_session_.get(), key3, NetLogWithSource()); 207 CreateSecureSpdySession(http_session_.get(), key3, NetLogWithSource());
209 GURL url3(kTestHost3); 208 GURL url3(kTestHost3);
210 base::WeakPtr<SpdyStream> spdy_stream3 = CreateStreamSynchronously( 209 base::WeakPtr<SpdyStream> spdy_stream3 = CreateStreamSynchronously(
211 SPDY_BIDIRECTIONAL_STREAM, session3, url3, MEDIUM, NetLogWithSource()); 210 SPDY_BIDIRECTIONAL_STREAM, session3, url3, MEDIUM, NetLogWithSource());
212 ASSERT_TRUE(spdy_stream3); 211 ASSERT_TRUE(spdy_stream3);
213 212
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 // If |clean_via_close_current_sessions| is SPDY_POOL_CLOSE_SESSIONS_MANUALLY, 326 // If |clean_via_close_current_sessions| is SPDY_POOL_CLOSE_SESSIONS_MANUALLY,
328 // the sessions are closed manually, calling SpdySessionPool::Remove() directly. 327 // the sessions are closed manually, calling SpdySessionPool::Remove() directly.
329 // If |clean_via_close_current_sessions| is SPDY_POOL_CLOSE_CURRENT_SESSIONS, 328 // If |clean_via_close_current_sessions| is SPDY_POOL_CLOSE_CURRENT_SESSIONS,
330 // sessions are closed with SpdySessionPool::CloseCurrentSessions(). 329 // sessions are closed with SpdySessionPool::CloseCurrentSessions().
331 // If |clean_via_close_current_sessions| is SPDY_POOL_CLOSE_IDLE_SESSIONS, 330 // If |clean_via_close_current_sessions| is SPDY_POOL_CLOSE_IDLE_SESSIONS,
332 // sessions are closed with SpdySessionPool::CloseIdleSessions(). 331 // sessions are closed with SpdySessionPool::CloseIdleSessions().
333 void SpdySessionPoolTest::RunIPPoolingTest( 332 void SpdySessionPoolTest::RunIPPoolingTest(
334 SpdyPoolCloseSessionsType close_sessions_type) { 333 SpdyPoolCloseSessionsType close_sessions_type) {
335 const int kTestPort = 80; 334 const int kTestPort = 80;
336 struct TestHosts { 335 struct TestHosts {
337 std::string url; 336 SpdyString url;
338 std::string name; 337 SpdyString name;
339 std::string iplist; 338 SpdyString iplist;
340 SpdySessionKey key; 339 SpdySessionKey key;
341 AddressList addresses; 340 AddressList addresses;
342 } test_hosts[] = { 341 } test_hosts[] = {
343 {"http:://www.example.org", "www.example.org", 342 {"http:://www.example.org", "www.example.org",
344 "192.0.2.33,192.168.0.1,192.168.0.5"}, 343 "192.0.2.33,192.168.0.1,192.168.0.5"},
345 {"http://mail.example.org", "mail.example.org", 344 {"http://mail.example.org", "mail.example.org",
346 "192.168.0.2,192.168.0.3,192.168.0.5,192.0.2.33"}, 345 "192.168.0.2,192.168.0.3,192.168.0.5,192.0.2.33"},
347 {"http://mail.example.com", "mail.example.com", 346 {"http://mail.example.com", "mail.example.com",
348 "192.168.0.4,192.168.0.3"}, 347 "192.168.0.4,192.168.0.3"},
349 }; 348 };
350 349
351 session_deps_.host_resolver->set_synchronous_mode(true); 350 session_deps_.host_resolver->set_synchronous_mode(true);
352 std::unique_ptr<HostResolver::Request> request[arraysize(test_hosts)]; 351 std::unique_ptr<HostResolver::Request> request[arraysize(test_hosts)];
353 for (size_t i = 0; i < arraysize(test_hosts); i++) { 352 for (size_t i = 0; i < arraysize(test_hosts); i++) {
354 session_deps_.host_resolver->rules()->AddIPLiteralRule( 353 session_deps_.host_resolver->rules()->AddIPLiteralRule(
355 test_hosts[i].name, test_hosts[i].iplist, std::string()); 354 test_hosts[i].name, test_hosts[i].iplist, SpdyString());
356 355
357 // This test requires that the HostResolver cache be populated. Normal 356 // This test requires that the HostResolver cache be populated. Normal
358 // code would have done this already, but we do it manually. 357 // code would have done this already, but we do it manually.
359 HostResolver::RequestInfo info(HostPortPair(test_hosts[i].name, kTestPort)); 358 HostResolver::RequestInfo info(HostPortPair(test_hosts[i].name, kTestPort));
360 session_deps_.host_resolver->Resolve( 359 session_deps_.host_resolver->Resolve(
361 info, DEFAULT_PRIORITY, &test_hosts[i].addresses, CompletionCallback(), 360 info, DEFAULT_PRIORITY, &test_hosts[i].addresses, CompletionCallback(),
362 &request[i], NetLogWithSource()); 361 &request[i], NetLogWithSource());
363 362
364 // Setup a SpdySessionKey 363 // Setup a SpdySessionKey
365 test_hosts[i].key = SpdySessionKey( 364 test_hosts[i].key = SpdySessionKey(
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 pool_peer.RemoveAliases(test_hosts[1].key); 438 pool_peer.RemoveAliases(test_hosts[1].key);
440 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); 439 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key));
441 440
442 // Expire the host cache 441 // Expire the host cache
443 session_deps_.host_resolver->GetHostCache()->clear(); 442 session_deps_.host_resolver->GetHostCache()->clear();
444 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); 443 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key));
445 444
446 // Cleanup the sessions. 445 // Cleanup the sessions.
447 switch (close_sessions_type) { 446 switch (close_sessions_type) {
448 case SPDY_POOL_CLOSE_SESSIONS_MANUALLY: 447 case SPDY_POOL_CLOSE_SESSIONS_MANUALLY:
449 session->CloseSessionOnError(ERR_ABORTED, std::string()); 448 session->CloseSessionOnError(ERR_ABORTED, SpdyString());
450 session2->CloseSessionOnError(ERR_ABORTED, std::string()); 449 session2->CloseSessionOnError(ERR_ABORTED, SpdyString());
451 base::RunLoop().RunUntilIdle(); 450 base::RunLoop().RunUntilIdle();
452 EXPECT_FALSE(session); 451 EXPECT_FALSE(session);
453 EXPECT_FALSE(session2); 452 EXPECT_FALSE(session2);
454 break; 453 break;
455 case SPDY_POOL_CLOSE_CURRENT_SESSIONS: 454 case SPDY_POOL_CLOSE_CURRENT_SESSIONS:
456 spdy_session_pool_->CloseCurrentSessions(ERR_ABORTED); 455 spdy_session_pool_->CloseCurrentSessions(ERR_ABORTED);
457 break; 456 break;
458 case SPDY_POOL_CLOSE_IDLE_SESSIONS: 457 case SPDY_POOL_CLOSE_IDLE_SESSIONS:
459 GURL url(test_hosts[0].url); 458 GURL url(test_hosts[0].url);
460 base::WeakPtr<SpdyStream> spdy_stream = CreateStreamSynchronously( 459 base::WeakPtr<SpdyStream> spdy_stream = CreateStreamSynchronously(
(...skipping 30 matching lines...) Expand all
491 EXPECT_FALSE(session); 490 EXPECT_FALSE(session);
492 EXPECT_FALSE(session1); 491 EXPECT_FALSE(session1);
493 EXPECT_TRUE(session2->is_active()); 492 EXPECT_TRUE(session2->is_active());
494 EXPECT_TRUE(session2->IsAvailable()); 493 EXPECT_TRUE(session2->IsAvailable());
495 494
496 spdy_stream2->Cancel(); 495 spdy_stream2->Cancel();
497 EXPECT_FALSE(spdy_stream); 496 EXPECT_FALSE(spdy_stream);
498 EXPECT_FALSE(spdy_stream1); 497 EXPECT_FALSE(spdy_stream1);
499 EXPECT_FALSE(spdy_stream2); 498 EXPECT_FALSE(spdy_stream2);
500 499
501 session2->CloseSessionOnError(ERR_ABORTED, std::string()); 500 session2->CloseSessionOnError(ERR_ABORTED, SpdyString());
502 base::RunLoop().RunUntilIdle(); 501 base::RunLoop().RunUntilIdle();
503 EXPECT_FALSE(session2); 502 EXPECT_FALSE(session2);
504 break; 503 break;
505 } 504 }
506 505
507 // Verify that the map is all cleaned up. 506 // Verify that the map is all cleaned up.
508 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[0].key)); 507 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[0].key));
509 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); 508 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[1].key));
510 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[2].key)); 509 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[2].key));
511 } 510 }
512 511
513 TEST_F(SpdySessionPoolTest, IPPooling) { 512 TEST_F(SpdySessionPoolTest, IPPooling) {
514 RunIPPoolingTest(SPDY_POOL_CLOSE_SESSIONS_MANUALLY); 513 RunIPPoolingTest(SPDY_POOL_CLOSE_SESSIONS_MANUALLY);
515 } 514 }
516 515
517 TEST_F(SpdySessionPoolTest, IPPoolingCloseCurrentSessions) { 516 TEST_F(SpdySessionPoolTest, IPPoolingCloseCurrentSessions) {
518 RunIPPoolingTest(SPDY_POOL_CLOSE_CURRENT_SESSIONS); 517 RunIPPoolingTest(SPDY_POOL_CLOSE_CURRENT_SESSIONS);
519 } 518 }
520 519
521 TEST_F(SpdySessionPoolTest, IPPoolingCloseIdleSessions) { 520 TEST_F(SpdySessionPoolTest, IPPoolingCloseIdleSessions) {
522 RunIPPoolingTest(SPDY_POOL_CLOSE_IDLE_SESSIONS); 521 RunIPPoolingTest(SPDY_POOL_CLOSE_IDLE_SESSIONS);
523 } 522 }
524 523
525 // Regression test for https://crbug.com/643025. 524 // Regression test for https://crbug.com/643025.
526 TEST_F(SpdySessionPoolTest, IPPoolingNetLog) { 525 TEST_F(SpdySessionPoolTest, IPPoolingNetLog) {
527 // Define two hosts with identical IP address. 526 // Define two hosts with identical IP address.
528 const int kTestPort = 443; 527 const int kTestPort = 443;
529 struct TestHosts { 528 struct TestHosts {
530 std::string name; 529 SpdyString name;
531 std::string iplist; 530 SpdyString iplist;
532 SpdySessionKey key; 531 SpdySessionKey key;
533 AddressList addresses; 532 AddressList addresses;
534 std::unique_ptr<HostResolver::Request> request; 533 std::unique_ptr<HostResolver::Request> request;
535 } test_hosts[] = { 534 } test_hosts[] = {
536 {"www.example.org", "192.168.0.1"}, {"mail.example.org", "192.168.0.1"}, 535 {"www.example.org", "192.168.0.1"}, {"mail.example.org", "192.168.0.1"},
537 }; 536 };
538 537
539 // Populate the HostResolver cache. 538 // Populate the HostResolver cache.
540 session_deps_.host_resolver->set_synchronous_mode(true); 539 session_deps_.host_resolver->set_synchronous_mode(true);
541 for (size_t i = 0; i < arraysize(test_hosts); i++) { 540 for (size_t i = 0; i < arraysize(test_hosts); i++) {
542 session_deps_.host_resolver->rules()->AddIPLiteralRule( 541 session_deps_.host_resolver->rules()->AddIPLiteralRule(
543 test_hosts[i].name, test_hosts[i].iplist, std::string()); 542 test_hosts[i].name, test_hosts[i].iplist, SpdyString());
544 543
545 HostResolver::RequestInfo info(HostPortPair(test_hosts[i].name, kTestPort)); 544 HostResolver::RequestInfo info(HostPortPair(test_hosts[i].name, kTestPort));
546 session_deps_.host_resolver->Resolve( 545 session_deps_.host_resolver->Resolve(
547 info, DEFAULT_PRIORITY, &test_hosts[i].addresses, CompletionCallback(), 546 info, DEFAULT_PRIORITY, &test_hosts[i].addresses, CompletionCallback(),
548 &test_hosts[i].request, NetLogWithSource()); 547 &test_hosts[i].request, NetLogWithSource());
549 548
550 test_hosts[i].key = 549 test_hosts[i].key =
551 SpdySessionKey(HostPortPair(test_hosts[i].name, kTestPort), 550 SpdySessionKey(HostPortPair(test_hosts[i].name, kTestPort),
552 ProxyServer::Direct(), PRIVACY_MODE_DISABLED); 551 ProxyServer::Direct(), PRIVACY_MODE_DISABLED);
553 } 552 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 599
601 // Both FindAvailableSession() calls should log histogram entries 600 // Both FindAvailableSession() calls should log histogram entries
602 // indicating IP pooling. 601 // indicating IP pooling.
603 histogram_tester.ExpectUniqueSample("Net.SpdySessionGet", 2, 2); 602 histogram_tester.ExpectUniqueSample("Net.SpdySessionGet", 2, 2);
604 } 603 }
605 604
606 TEST_F(SpdySessionPoolTest, IPPoolingDisabled) { 605 TEST_F(SpdySessionPoolTest, IPPoolingDisabled) {
607 // Define two hosts with identical IP address. 606 // Define two hosts with identical IP address.
608 const int kTestPort = 443; 607 const int kTestPort = 443;
609 struct TestHosts { 608 struct TestHosts {
610 std::string name; 609 SpdyString name;
611 std::string iplist; 610 SpdyString iplist;
612 SpdySessionKey key; 611 SpdySessionKey key;
613 AddressList addresses; 612 AddressList addresses;
614 std::unique_ptr<HostResolver::Request> request; 613 std::unique_ptr<HostResolver::Request> request;
615 } test_hosts[] = { 614 } test_hosts[] = {
616 {"www.example.org", "192.168.0.1"}, {"mail.example.org", "192.168.0.1"}, 615 {"www.example.org", "192.168.0.1"}, {"mail.example.org", "192.168.0.1"},
617 }; 616 };
618 617
619 // Populate the HostResolver cache. 618 // Populate the HostResolver cache.
620 session_deps_.host_resolver->set_synchronous_mode(true); 619 session_deps_.host_resolver->set_synchronous_mode(true);
621 for (size_t i = 0; i < arraysize(test_hosts); i++) { 620 for (size_t i = 0; i < arraysize(test_hosts); i++) {
622 session_deps_.host_resolver->rules()->AddIPLiteralRule( 621 session_deps_.host_resolver->rules()->AddIPLiteralRule(
623 test_hosts[i].name, test_hosts[i].iplist, std::string()); 622 test_hosts[i].name, test_hosts[i].iplist, SpdyString());
624 623
625 HostResolver::RequestInfo info(HostPortPair(test_hosts[i].name, kTestPort)); 624 HostResolver::RequestInfo info(HostPortPair(test_hosts[i].name, kTestPort));
626 session_deps_.host_resolver->Resolve( 625 session_deps_.host_resolver->Resolve(
627 info, DEFAULT_PRIORITY, &test_hosts[i].addresses, CompletionCallback(), 626 info, DEFAULT_PRIORITY, &test_hosts[i].addresses, CompletionCallback(),
628 &test_hosts[i].request, NetLogWithSource()); 627 &test_hosts[i].request, NetLogWithSource());
629 628
630 test_hosts[i].key = 629 test_hosts[i].key =
631 SpdySessionKey(HostPortPair(test_hosts[i].name, kTestPort), 630 SpdySessionKey(HostPortPair(test_hosts[i].name, kTestPort),
632 ProxyServer::Direct(), PRIVACY_MODE_DISABLED); 631 ProxyServer::Direct(), PRIVACY_MODE_DISABLED);
633 } 632 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 StaticSocketDataProvider dataA(reads, arraysize(reads), writes, 697 StaticSocketDataProvider dataA(reads, arraysize(reads), writes,
699 arraysize(writes)); 698 arraysize(writes));
700 dataA.set_connect_data(connect_data); 699 dataA.set_connect_data(connect_data);
701 session_deps_.socket_factory->AddSocketDataProvider(&dataA); 700 session_deps_.socket_factory->AddSocketDataProvider(&dataA);
702 701
703 AddSSLSocketData(); 702 AddSSLSocketData();
704 703
705 CreateNetworkSession(); 704 CreateNetworkSession();
706 705
707 // Set up session A: Going away, but with an active stream. 706 // Set up session A: Going away, but with an active stream.
708 const std::string kTestHostA("www.example.org"); 707 const SpdyString kTestHostA("www.example.org");
709 HostPortPair test_host_port_pairA(kTestHostA, 80); 708 HostPortPair test_host_port_pairA(kTestHostA, 80);
710 SpdySessionKey keyA( 709 SpdySessionKey keyA(
711 test_host_port_pairA, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); 710 test_host_port_pairA, ProxyServer::Direct(), PRIVACY_MODE_DISABLED);
712 base::WeakPtr<SpdySession> sessionA = 711 base::WeakPtr<SpdySession> sessionA =
713 CreateSecureSpdySession(http_session_.get(), keyA, NetLogWithSource()); 712 CreateSecureSpdySession(http_session_.get(), keyA, NetLogWithSource());
714 713
715 GURL urlA("http://www.example.org"); 714 GURL urlA("http://www.example.org");
716 base::WeakPtr<SpdyStream> spdy_streamA = CreateStreamSynchronously( 715 base::WeakPtr<SpdyStream> spdy_streamA = CreateStreamSynchronously(
717 SPDY_BIDIRECTIONAL_STREAM, sessionA, urlA, MEDIUM, NetLogWithSource()); 716 SPDY_BIDIRECTIONAL_STREAM, sessionA, urlA, MEDIUM, NetLogWithSource());
718 test::StreamDelegateDoNothing delegateA(spdy_streamA); 717 test::StreamDelegateDoNothing delegateA(spdy_streamA);
(...skipping 10 matching lines...) Expand all
729 EXPECT_FALSE(delegateA.StreamIsClosed()); 728 EXPECT_FALSE(delegateA.StreamIsClosed());
730 729
731 // Set up session B: Available, with a created stream. 730 // Set up session B: Available, with a created stream.
732 StaticSocketDataProvider dataB(reads, arraysize(reads), writes, 731 StaticSocketDataProvider dataB(reads, arraysize(reads), writes,
733 arraysize(writes)); 732 arraysize(writes));
734 dataB.set_connect_data(connect_data); 733 dataB.set_connect_data(connect_data);
735 session_deps_.socket_factory->AddSocketDataProvider(&dataB); 734 session_deps_.socket_factory->AddSocketDataProvider(&dataB);
736 735
737 AddSSLSocketData(); 736 AddSSLSocketData();
738 737
739 const std::string kTestHostB("mail.example.org"); 738 const SpdyString kTestHostB("mail.example.org");
740 HostPortPair test_host_port_pairB(kTestHostB, 80); 739 HostPortPair test_host_port_pairB(kTestHostB, 80);
741 SpdySessionKey keyB( 740 SpdySessionKey keyB(
742 test_host_port_pairB, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); 741 test_host_port_pairB, ProxyServer::Direct(), PRIVACY_MODE_DISABLED);
743 base::WeakPtr<SpdySession> sessionB = 742 base::WeakPtr<SpdySession> sessionB =
744 CreateSecureSpdySession(http_session_.get(), keyB, NetLogWithSource()); 743 CreateSecureSpdySession(http_session_.get(), keyB, NetLogWithSource());
745 EXPECT_TRUE(sessionB->IsAvailable()); 744 EXPECT_TRUE(sessionB->IsAvailable());
746 745
747 GURL urlB("http://mail.example.org"); 746 GURL urlB("http://mail.example.org");
748 base::WeakPtr<SpdyStream> spdy_streamB = CreateStreamSynchronously( 747 base::WeakPtr<SpdyStream> spdy_streamB = CreateStreamSynchronously(
749 SPDY_BIDIRECTIONAL_STREAM, sessionB, urlB, MEDIUM, NetLogWithSource()); 748 SPDY_BIDIRECTIONAL_STREAM, sessionB, urlB, MEDIUM, NetLogWithSource());
750 test::StreamDelegateDoNothing delegateB(spdy_streamB); 749 test::StreamDelegateDoNothing delegateB(spdy_streamB);
751 spdy_streamB->SetDelegate(&delegateB); 750 spdy_streamB->SetDelegate(&delegateB);
752 751
753 // Set up session C: Draining. 752 // Set up session C: Draining.
754 StaticSocketDataProvider dataC(reads, arraysize(reads), writes, 753 StaticSocketDataProvider dataC(reads, arraysize(reads), writes,
755 arraysize(writes)); 754 arraysize(writes));
756 dataC.set_connect_data(connect_data); 755 dataC.set_connect_data(connect_data);
757 session_deps_.socket_factory->AddSocketDataProvider(&dataC); 756 session_deps_.socket_factory->AddSocketDataProvider(&dataC);
758 757
759 AddSSLSocketData(); 758 AddSSLSocketData();
760 759
761 const std::string kTestHostC("mail.example.com"); 760 const SpdyString kTestHostC("mail.example.com");
762 HostPortPair test_host_port_pairC(kTestHostC, 80); 761 HostPortPair test_host_port_pairC(kTestHostC, 80);
763 SpdySessionKey keyC( 762 SpdySessionKey keyC(
764 test_host_port_pairC, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); 763 test_host_port_pairC, ProxyServer::Direct(), PRIVACY_MODE_DISABLED);
765 base::WeakPtr<SpdySession> sessionC = 764 base::WeakPtr<SpdySession> sessionC =
766 CreateSecureSpdySession(http_session_.get(), keyC, NetLogWithSource()); 765 CreateSecureSpdySession(http_session_.get(), keyC, NetLogWithSource());
767 766
768 sessionC->CloseSessionOnError(ERR_SPDY_PROTOCOL_ERROR, "Error!"); 767 sessionC->CloseSessionOnError(ERR_SPDY_PROTOCOL_ERROR, "Error!");
769 EXPECT_TRUE(sessionC->IsDraining()); 768 EXPECT_TRUE(sessionC->IsDraining());
770 769
771 spdy_session_pool_->OnIPAddressChanged(); 770 spdy_session_pool_->OnIPAddressChanged();
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 process_memory_dump->CreateAllocatorDump( 878 process_memory_dump->CreateAllocatorDump(
880 "net/http_network_session_0x123"); 879 "net/http_network_session_0x123");
881 spdy_session_pool_->DumpMemoryStats(process_memory_dump.get(), 880 spdy_session_pool_->DumpMemoryStats(process_memory_dump.get(),
882 parent_dump->absolute_name()); 881 parent_dump->absolute_name());
883 882
884 // Whether SpdySession::DumpMemoryStats() is invoked. 883 // Whether SpdySession::DumpMemoryStats() is invoked.
885 bool did_dump = false; 884 bool did_dump = false;
886 const base::trace_event::ProcessMemoryDump::AllocatorDumpsMap& 885 const base::trace_event::ProcessMemoryDump::AllocatorDumpsMap&
887 allocator_dumps = process_memory_dump->allocator_dumps(); 886 allocator_dumps = process_memory_dump->allocator_dumps();
888 for (const auto& pair : allocator_dumps) { 887 for (const auto& pair : allocator_dumps) {
889 const std::string& dump_name = pair.first; 888 const SpdyString& dump_name = pair.first;
890 if (dump_name.find("spdy_session_pool") == std::string::npos) 889 if (dump_name.find("spdy_session_pool") == SpdyString::npos)
891 continue; 890 continue;
892 std::unique_ptr<base::Value> raw_attrs = 891 std::unique_ptr<base::Value> raw_attrs =
893 pair.second->attributes_for_testing()->ToBaseValue(); 892 pair.second->attributes_for_testing()->ToBaseValue();
894 base::DictionaryValue* attrs; 893 base::DictionaryValue* attrs;
895 ASSERT_TRUE(raw_attrs->GetAsDictionary(&attrs)); 894 ASSERT_TRUE(raw_attrs->GetAsDictionary(&attrs));
896 base::DictionaryValue* active_session_count_attr; 895 base::DictionaryValue* active_session_count_attr;
897 ASSERT_TRUE(attrs->GetDictionary("active_session_count", 896 ASSERT_TRUE(attrs->GetDictionary("active_session_count",
898 &active_session_count_attr)); 897 &active_session_count_attr));
899 std::string active_session_count; 898 SpdyString active_session_count;
900 ASSERT_TRUE( 899 ASSERT_TRUE(
901 active_session_count_attr->GetString("value", &active_session_count)); 900 active_session_count_attr->GetString("value", &active_session_count));
902 // No created stream so the session should be idle. 901 // No created stream so the session should be idle.
903 ASSERT_EQ("0", active_session_count); 902 ASSERT_EQ("0", active_session_count);
904 did_dump = true; 903 did_dump = true;
905 } 904 }
906 EXPECT_TRUE(did_dump); 905 EXPECT_TRUE(did_dump);
907 spdy_session_pool_->CloseCurrentSessions(ERR_ABORTED); 906 spdy_session_pool_->CloseCurrentSessions(ERR_ABORTED);
908 } 907 }
909 908
910 } // namespace net 909 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_session_pool.cc ('k') | net/spdy/spdy_session_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698