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

Side by Side Diff: net/http/http_server_properties_manager_unittest.cc

Issue 895853003: Update from https://crrev.com/314320 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 10 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/http/http_server_properties_manager.cc ('k') | net/http/http_stream_factory_impl.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/http/http_server_properties_manager.h" 5 #include "net/http/http_server_properties_manager.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/prefs/pref_registry_simple.h" 9 #include "base/prefs/pref_registry_simple.h"
10 #include "base/prefs/testing_pref_service.h" 10 #include "base/prefs/testing_pref_service.h"
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 http_server_properties_dict); 216 http_server_properties_dict);
217 base::DictionaryValue* http_server_properties_dict2 = 217 base::DictionaryValue* http_server_properties_dict2 =
218 http_server_properties_dict->DeepCopy(); 218 http_server_properties_dict->DeepCopy();
219 pref_service_.SetManagedPref(kTestHttpServerProperties, 219 pref_service_.SetManagedPref(kTestHttpServerProperties,
220 http_server_properties_dict2); 220 http_server_properties_dict2);
221 221
222 base::RunLoop().RunUntilIdle(); 222 base::RunLoop().RunUntilIdle();
223 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 223 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
224 224
225 // Verify SupportsSpdy. 225 // Verify SupportsSpdy.
226 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(google_server)); 226 EXPECT_TRUE(
227 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(mail_server)); 227 http_server_props_manager_->SupportsRequestPriority(google_server));
228 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy( 228 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(mail_server));
229 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority(
229 HostPortPair::FromString("foo.google.com:1337"))); 230 HostPortPair::FromString("foo.google.com:1337")));
230 231
231 // Verify AlternateProtocol. 232 // Verify AlternateProtocol.
232 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(google_server)); 233 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(google_server));
233 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(mail_server)); 234 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(mail_server));
234 AlternateProtocolInfo port_alternate_protocol = 235 AlternateProtocolInfo port_alternate_protocol =
235 http_server_props_manager_->GetAlternateProtocol(google_server); 236 http_server_props_manager_->GetAlternateProtocol(google_server);
236 EXPECT_EQ(443, port_alternate_protocol.port); 237 EXPECT_EQ(443, port_alternate_protocol.port);
237 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); 238 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol);
238 port_alternate_protocol = 239 port_alternate_protocol =
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); 298 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict);
298 299
299 // Set up the pref. 300 // Set up the pref.
300 pref_service_.SetManagedPref(kTestHttpServerProperties, 301 pref_service_.SetManagedPref(kTestHttpServerProperties,
301 http_server_properties_dict); 302 http_server_properties_dict);
302 303
303 base::RunLoop().RunUntilIdle(); 304 base::RunLoop().RunUntilIdle();
304 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 305 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
305 306
306 // Verify that nothing is set. 307 // Verify that nothing is set.
307 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy( 308 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority(
308 HostPortPair::FromString("www.google.com:65536"))); 309 HostPortPair::FromString("www.google.com:65536")));
309 EXPECT_FALSE(http_server_props_manager_->HasAlternateProtocol( 310 EXPECT_FALSE(http_server_props_manager_->HasAlternateProtocol(
310 HostPortPair::FromString("www.google.com:65536"))); 311 HostPortPair::FromString("www.google.com:65536")));
311 SupportsQuic supports_quic2 = http_server_props_manager_->GetSupportsQuic( 312 SupportsQuic supports_quic2 = http_server_props_manager_->GetSupportsQuic(
312 HostPortPair::FromString("www.google.com:65536")); 313 HostPortPair::FromString("www.google.com:65536"));
313 EXPECT_FALSE(supports_quic2.used_quic); 314 EXPECT_FALSE(supports_quic2.used_quic);
314 const ServerNetworkStats* stats1 = 315 const ServerNetworkStats* stats1 =
315 http_server_props_manager_->GetServerNetworkStats( 316 http_server_props_manager_->GetServerNetworkStats(
316 HostPortPair::FromString("www.google.com:65536")); 317 HostPortPair::FromString("www.google.com:65536"));
317 EXPECT_EQ(NULL, stats1); 318 EXPECT_EQ(NULL, stats1);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 } 357 }
357 358
358 TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) { 359 TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) {
359 ExpectPrefsUpdate(); 360 ExpectPrefsUpdate();
360 361
361 // Post an update task to the network thread. SetSupportsSpdy calls 362 // Post an update task to the network thread. SetSupportsSpdy calls
362 // ScheduleUpdatePrefsOnNetworkThread. 363 // ScheduleUpdatePrefsOnNetworkThread.
363 364
364 // Add mail.google.com:443 as a supporting spdy server. 365 // Add mail.google.com:443 as a supporting spdy server.
365 HostPortPair spdy_server_mail("mail.google.com", 443); 366 HostPortPair spdy_server_mail("mail.google.com", 443);
366 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); 367 EXPECT_FALSE(
368 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail));
367 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); 369 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true);
368 370
369 // Run the task. 371 // Run the task.
370 base::RunLoop().RunUntilIdle(); 372 base::RunLoop().RunUntilIdle();
371 373
372 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); 374 EXPECT_TRUE(
375 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail));
373 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 376 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
374 } 377 }
375 378
376 TEST_F(HttpServerPropertiesManagerTest, SetSpdySetting) { 379 TEST_F(HttpServerPropertiesManagerTest, SetSpdySetting) {
377 ExpectPrefsUpdate(); 380 ExpectPrefsUpdate();
378 381
379 // Add SpdySetting for mail.google.com:443. 382 // Add SpdySetting for mail.google.com:443.
380 HostPortPair spdy_server_mail("mail.google.com", 443); 383 HostPortPair spdy_server_mail("mail.google.com", 443);
381 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; 384 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH;
382 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; 385 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 477 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
475 } 478 }
476 479
477 TEST_F(HttpServerPropertiesManagerTest, HasAlternateProtocol) { 480 TEST_F(HttpServerPropertiesManagerTest, HasAlternateProtocol) {
478 ExpectPrefsUpdate(); 481 ExpectPrefsUpdate();
479 482
480 HostPortPair spdy_server_mail("mail.google.com", 80); 483 HostPortPair spdy_server_mail("mail.google.com", 80);
481 EXPECT_FALSE( 484 EXPECT_FALSE(
482 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); 485 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail));
483 http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443, 486 http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443,
484 NPN_SPDY_3, 1); 487 NPN_SPDY_3, 1.0);
485 488
486 // Run the task. 489 // Run the task.
487 base::RunLoop().RunUntilIdle(); 490 base::RunLoop().RunUntilIdle();
488 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 491 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
489 492
490 ASSERT_TRUE( 493 ASSERT_TRUE(
491 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); 494 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail));
492 AlternateProtocolInfo port_alternate_protocol = 495 AlternateProtocolInfo port_alternate_protocol =
493 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); 496 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail);
494 EXPECT_EQ(443, port_alternate_protocol.port); 497 EXPECT_EQ(443, port_alternate_protocol.port);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 http_server_props_manager_->GetServerNetworkStats(mail_server); 537 http_server_props_manager_->GetServerNetworkStats(mail_server);
535 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); 538 EXPECT_EQ(10, stats2->srtt.ToInternalValue());
536 } 539 }
537 540
538 TEST_F(HttpServerPropertiesManagerTest, Clear) { 541 TEST_F(HttpServerPropertiesManagerTest, Clear) {
539 ExpectPrefsUpdate(); 542 ExpectPrefsUpdate();
540 543
541 HostPortPair spdy_server_mail("mail.google.com", 443); 544 HostPortPair spdy_server_mail("mail.google.com", 443);
542 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); 545 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true);
543 http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443, 546 http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443,
544 NPN_SPDY_3, 1); 547 NPN_SPDY_3, 1.0);
545 http_server_props_manager_->SetSupportsQuic(spdy_server_mail, true, "foo"); 548 http_server_props_manager_->SetSupportsQuic(spdy_server_mail, true, "foo");
546 ServerNetworkStats stats; 549 ServerNetworkStats stats;
547 stats.srtt = base::TimeDelta::FromMicroseconds(10); 550 stats.srtt = base::TimeDelta::FromMicroseconds(10);
548 http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats); 551 http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats);
549 552
550 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; 553 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH;
551 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; 554 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST;
552 const uint32 value1 = 31337; 555 const uint32 value1 = 31337;
553 http_server_props_manager_->SetSpdySetting( 556 http_server_props_manager_->SetSpdySetting(
554 spdy_server_mail, id1, flags1, value1); 557 spdy_server_mail, id1, flags1, value1);
555 558
556 // Run the task. 559 // Run the task.
557 base::RunLoop().RunUntilIdle(); 560 base::RunLoop().RunUntilIdle();
558 561
559 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); 562 EXPECT_TRUE(
563 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail));
560 EXPECT_TRUE( 564 EXPECT_TRUE(
561 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); 565 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail));
562 SupportsQuic supports_quic = 566 SupportsQuic supports_quic =
563 http_server_props_manager_->GetSupportsQuic(spdy_server_mail); 567 http_server_props_manager_->GetSupportsQuic(spdy_server_mail);
564 EXPECT_TRUE(supports_quic.used_quic); 568 EXPECT_TRUE(supports_quic.used_quic);
565 EXPECT_EQ("foo", supports_quic.address); 569 EXPECT_EQ("foo", supports_quic.address);
566 const ServerNetworkStats* stats1 = 570 const ServerNetworkStats* stats1 =
567 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); 571 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail);
568 EXPECT_EQ(10, stats1->srtt.ToInternalValue()); 572 EXPECT_EQ(10, stats1->srtt.ToInternalValue());
569 573
570 // Check SPDY settings values. 574 // Check SPDY settings values.
571 const SettingsMap& settings_map1_ret = 575 const SettingsMap& settings_map1_ret =
572 http_server_props_manager_->GetSpdySettings(spdy_server_mail); 576 http_server_props_manager_->GetSpdySettings(spdy_server_mail);
573 ASSERT_EQ(1U, settings_map1_ret.size()); 577 ASSERT_EQ(1U, settings_map1_ret.size());
574 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); 578 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1);
575 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); 579 EXPECT_TRUE(it1_ret != settings_map1_ret.end());
576 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; 580 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second;
577 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); 581 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first);
578 EXPECT_EQ(value1, flags_and_value1_ret.second); 582 EXPECT_EQ(value1, flags_and_value1_ret.second);
579 583
580 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 584 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
581 585
582 ExpectPrefsUpdate(); 586 ExpectPrefsUpdate();
583 587
584 // Clear http server data, time out if we do not get a completion callback. 588 // Clear http server data, time out if we do not get a completion callback.
585 http_server_props_manager_->Clear(base::MessageLoop::QuitClosure()); 589 http_server_props_manager_->Clear(base::MessageLoop::QuitClosure());
586 base::RunLoop().Run(); 590 base::RunLoop().Run();
587 591
588 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); 592 EXPECT_FALSE(
593 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail));
589 EXPECT_FALSE( 594 EXPECT_FALSE(
590 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); 595 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail));
591 SupportsQuic supports_quic1 = 596 SupportsQuic supports_quic1 =
592 http_server_props_manager_->GetSupportsQuic(spdy_server_mail); 597 http_server_props_manager_->GetSupportsQuic(spdy_server_mail);
593 EXPECT_FALSE(supports_quic1.used_quic); 598 EXPECT_FALSE(supports_quic1.used_quic);
594 EXPECT_EQ("", supports_quic1.address); 599 EXPECT_EQ("", supports_quic1.address);
595 const ServerNetworkStats* stats2 = 600 const ServerNetworkStats* stats2 =
596 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); 601 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail);
597 EXPECT_EQ(NULL, stats2); 602 EXPECT_EQ(NULL, stats2);
598 603
599 const SettingsMap& settings_map2_ret = 604 const SettingsMap& settings_map2_ret =
600 http_server_props_manager_->GetSpdySettings(spdy_server_mail); 605 http_server_props_manager_->GetSpdySettings(spdy_server_mail);
601 EXPECT_EQ(0U, settings_map2_ret.size()); 606 EXPECT_EQ(0U, settings_map2_ret.size());
602 607
603 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 608 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
604 } 609 }
605 610
606 // crbug.com/444956: Add 200 alternate_protocol servers followed by 611 // https://crbug.com/444956: Add 200 alternate_protocol servers followed by
607 // supports_quic and verify we have read supports_quic from prefs. 612 // supports_quic and verify we have read supports_quic from prefs.
608 TEST_F(HttpServerPropertiesManagerTest, BadSupportsQuic) { 613 TEST_F(HttpServerPropertiesManagerTest, BadSupportsQuic) {
609 ExpectCacheUpdate(); 614 ExpectCacheUpdate();
610 615
611 base::DictionaryValue* servers_dict = new base::DictionaryValue; 616 base::DictionaryValue* servers_dict = new base::DictionaryValue;
612 617
613 for (int i = 0; i < 200; ++i) { 618 for (int i = 0; i < 200; ++i) {
614 // Set up alternate_protocol for www.google.com:i. 619 // Set up alternate_protocol for www.google.com:i.
615 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; 620 base::DictionaryValue* alternate_protocol = new base::DictionaryValue;
616 alternate_protocol->SetInteger("port", i); 621 alternate_protocol->SetInteger("port", i);
(...skipping 26 matching lines...) Expand all
643 pref_service_.SetManagedPref(kTestHttpServerProperties, 648 pref_service_.SetManagedPref(kTestHttpServerProperties,
644 http_server_properties_dict); 649 http_server_properties_dict);
645 650
646 base::RunLoop().RunUntilIdle(); 651 base::RunLoop().RunUntilIdle();
647 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 652 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
648 653
649 // Verify AlternateProtocol. 654 // Verify AlternateProtocol.
650 for (int i = 0; i < 200; ++i) { 655 for (int i = 0; i < 200; ++i) {
651 std::string server = StringPrintf("www.google.com:%d", i); 656 std::string server = StringPrintf("www.google.com:%d", i);
652 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol( 657 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(
653 net::HostPortPair::FromString(server))); 658 HostPortPair::FromString(server)));
654 net::AlternateProtocolInfo port_alternate_protocol = 659 AlternateProtocolInfo port_alternate_protocol =
655 http_server_props_manager_->GetAlternateProtocol( 660 http_server_props_manager_->GetAlternateProtocol(
656 net::HostPortPair::FromString(server)); 661 HostPortPair::FromString(server));
657 EXPECT_EQ(i, port_alternate_protocol.port); 662 EXPECT_EQ(i, port_alternate_protocol.port);
658 EXPECT_EQ(net::NPN_SPDY_3, port_alternate_protocol.protocol); 663 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol);
659 } 664 }
660 665
661 // Verify SupportsQuic. 666 // Verify SupportsQuic.
662 net::SupportsQuic supports_quic1 = 667 SupportsQuic supports_quic1 = http_server_props_manager_->GetSupportsQuic(
663 http_server_props_manager_->GetSupportsQuic( 668 HostPortPair::FromString("mail.google.com:80"));
664 net::HostPortPair::FromString("mail.google.com:80"));
665 EXPECT_TRUE(supports_quic1.used_quic); 669 EXPECT_TRUE(supports_quic1.used_quic);
666 EXPECT_EQ("bar", supports_quic1.address); 670 EXPECT_EQ("bar", supports_quic1.address);
667 } 671 }
668 672
669 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) { 673 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) {
670 // Post an update task to the UI thread. 674 // Post an update task to the UI thread.
671 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); 675 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread();
672 // Shutdown comes before the task is executed. 676 // Shutdown comes before the task is executed.
673 http_server_props_manager_->ShutdownOnPrefThread(); 677 http_server_props_manager_->ShutdownOnPrefThread();
674 http_server_props_manager_.reset(); 678 http_server_props_manager_.reset();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 // Run the task after shutdown, but before deletion. 738 // Run the task after shutdown, but before deletion.
735 base::RunLoop().RunUntilIdle(); 739 base::RunLoop().RunUntilIdle();
736 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 740 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
737 http_server_props_manager_.reset(); 741 http_server_props_manager_.reset();
738 base::RunLoop().RunUntilIdle(); 742 base::RunLoop().RunUntilIdle();
739 } 743 }
740 744
741 } // namespace 745 } // namespace
742 746
743 } // namespace net 747 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_server_properties_manager.cc ('k') | net/http/http_stream_factory_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698