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

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

Issue 1860343002: SHP 1: Change SupportsSpdy dict to use SchemeHostPort as the key. No change to Pref data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
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/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 226
227 TEST_P(HttpServerPropertiesManagerTest, 227 TEST_P(HttpServerPropertiesManagerTest,
228 SingleUpdateForTwoSpdyServerPrefChanges) { 228 SingleUpdateForTwoSpdyServerPrefChanges) {
229 ExpectCacheUpdate(); 229 ExpectCacheUpdate();
230 230
231 // Set up the prefs for www.google.com:80 and mail.google.com:80 and then set 231 // Set up the prefs for www.google.com:80 and mail.google.com:80 and then set
232 // it twice. Only expect a single cache update. 232 // it twice. Only expect a single cache update.
233 233
234 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; 234 base::DictionaryValue* server_pref_dict = new base::DictionaryValue;
235 HostPortPair google_server("www.google.com", 80); 235 HostPortPair google_server("www.google.com", 80);
236 url::SchemeHostPort google_scheme_host_port("http", "www.google.com", 80);
236 HostPortPair mail_server("mail.google.com", 80); 237 HostPortPair mail_server("mail.google.com", 80);
238 url::SchemeHostPort mail_scheme_host_port("http", "mail.google.com", 80);
237 239
238 // Set supports_spdy for www.google.com:80. 240 // Set supports_spdy for www.google.com:80.
239 server_pref_dict->SetBoolean("supports_spdy", true); 241 server_pref_dict->SetBoolean("supports_spdy", true);
240 242
241 // Set up alternative_services for www.google.com:80. 243 // Set up alternative_services for www.google.com:80.
242 base::DictionaryValue* alternative_service_dict0 = new base::DictionaryValue; 244 base::DictionaryValue* alternative_service_dict0 = new base::DictionaryValue;
243 alternative_service_dict0->SetInteger("port", 443); 245 alternative_service_dict0->SetInteger("port", 443);
244 alternative_service_dict0->SetString("protocol_str", "npn-h2"); 246 alternative_service_dict0->SetString("protocol_str", "npn-h2");
245 base::DictionaryValue* alternative_service_dict1 = new base::DictionaryValue; 247 base::DictionaryValue* alternative_service_dict1 = new base::DictionaryValue;
246 alternative_service_dict1->SetInteger("port", 1234); 248 alternative_service_dict1->SetInteger("port", 1234);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 quic_servers_dict); 342 quic_servers_dict);
341 343
342 // Set the same value for kHttpServerProperties multiple times. 344 // Set the same value for kHttpServerProperties multiple times.
343 pref_delegate_->SetPrefs(http_server_properties_dict); 345 pref_delegate_->SetPrefs(http_server_properties_dict);
344 pref_delegate_->SetPrefs(http_server_properties_dict); 346 pref_delegate_->SetPrefs(http_server_properties_dict);
345 347
346 base::RunLoop().RunUntilIdle(); 348 base::RunLoop().RunUntilIdle();
347 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 349 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
348 350
349 // Verify SupportsSpdy. 351 // Verify SupportsSpdy.
350 EXPECT_TRUE( 352 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(
351 http_server_props_manager_->SupportsRequestPriority(google_server)); 353 google_scheme_host_port));
352 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(mail_server)); 354 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(
355 mail_scheme_host_port));
356 HostPortPair foo_server = HostPortPair::FromString("foo.google.com:1337");
357 url::SchemeHostPort foo_scheme_host_port("http", foo_server.host(),
358 foo_server.port());
359
353 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( 360 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority(
354 HostPortPair::FromString("foo.google.com:1337"))); 361 foo_scheme_host_port));
355 362
356 // Verify alternative service. 363 // Verify alternative service.
357 if (GetParam() == 4) { 364 if (GetParam() == 4) {
358 const AlternativeServiceMap& map = 365 const AlternativeServiceMap& map =
359 http_server_props_manager_->alternative_service_map(); 366 http_server_props_manager_->alternative_service_map();
360 ASSERT_EQ(2u, map.size()); 367 ASSERT_EQ(2u, map.size());
361 368
362 AlternativeServiceMap::const_iterator map_it = map.begin(); 369 AlternativeServiceMap::const_iterator map_it = map.begin();
363 EXPECT_EQ("mail.google.com", map_it->first.host()); 370 EXPECT_EQ("mail.google.com", map_it->first.host());
364 ASSERT_EQ(1u, map_it->second.size()); 371 ASSERT_EQ(1u, map_it->second.size());
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 http_server_properties_dict.SetWithoutPathExpansion("quic_servers", 488 http_server_properties_dict.SetWithoutPathExpansion("quic_servers",
482 quic_servers_dict); 489 quic_servers_dict);
483 490
484 // Set up the pref. 491 // Set up the pref.
485 pref_delegate_->SetPrefs(http_server_properties_dict); 492 pref_delegate_->SetPrefs(http_server_properties_dict);
486 493
487 base::RunLoop().RunUntilIdle(); 494 base::RunLoop().RunUntilIdle();
488 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 495 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
489 496
490 // Verify that nothing is set. 497 // Verify that nothing is set.
498 HostPortPair google_server = HostPortPair::FromString("www.google.com:65536");
499 url::SchemeHostPort google_scheme_host_port("http", google_server.host(),
500 google_server.port());
501
491 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( 502 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority(
492 HostPortPair::FromString("www.google.com:65536"))); 503 google_scheme_host_port));
493 EXPECT_FALSE( 504 EXPECT_FALSE(
494 HasAlternativeService(HostPortPair::FromString("www.google.com:65536"))); 505 HasAlternativeService(HostPortPair::FromString("www.google.com:65536")));
495 const ServerNetworkStats* stats1 = 506 const ServerNetworkStats* stats1 =
496 http_server_props_manager_->GetServerNetworkStats( 507 http_server_props_manager_->GetServerNetworkStats(
497 HostPortPair::FromString("www.google.com:65536")); 508 HostPortPair::FromString("www.google.com:65536"));
498 EXPECT_EQ(nullptr, stats1); 509 EXPECT_EQ(nullptr, stats1);
499 EXPECT_EQ(0u, http_server_props_manager_->quic_server_info_map().size()); 510 EXPECT_EQ(0u, http_server_props_manager_->quic_server_info_map().size());
500 } 511 }
501 512
502 TEST_P(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { 513 TEST_P(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 561
551 TEST_P(HttpServerPropertiesManagerTest, SupportsSpdy) { 562 TEST_P(HttpServerPropertiesManagerTest, SupportsSpdy) {
552 ExpectPrefsUpdate(); 563 ExpectPrefsUpdate();
553 ExpectScheduleUpdatePrefsOnNetworkThread(); 564 ExpectScheduleUpdatePrefsOnNetworkThread();
554 565
555 // Post an update task to the network thread. SetSupportsSpdy calls 566 // Post an update task to the network thread. SetSupportsSpdy calls
556 // ScheduleUpdatePrefsOnNetworkThread. 567 // ScheduleUpdatePrefsOnNetworkThread.
557 568
558 // Add mail.google.com:443 as a supporting spdy server. 569 // Add mail.google.com:443 as a supporting spdy server.
559 HostPortPair spdy_server_mail("mail.google.com", 443); 570 HostPortPair spdy_server_mail("mail.google.com", 443);
571 url::SchemeHostPort spdy_server("https", "mail.google.com", 443);
560 EXPECT_FALSE( 572 EXPECT_FALSE(
561 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); 573 http_server_props_manager_->SupportsRequestPriority(spdy_server));
562 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); 574 http_server_props_manager_->SetSupportsSpdy(spdy_server, true);
563 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. 575 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once.
564 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); 576 http_server_props_manager_->SetSupportsSpdy(spdy_server, true);
565 577
566 // Run the task. 578 // Run the task.
567 base::RunLoop().RunUntilIdle(); 579 base::RunLoop().RunUntilIdle();
568 580
569 EXPECT_TRUE( 581 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(spdy_server));
570 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail));
571 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 582 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
572 } 583 }
573 584
574 TEST_P(HttpServerPropertiesManagerTest, SetSpdySetting) { 585 TEST_P(HttpServerPropertiesManagerTest, SetSpdySetting) {
575 ExpectPrefsUpdate(); 586 ExpectPrefsUpdate();
576 ExpectScheduleUpdatePrefsOnNetworkThread(); 587 ExpectScheduleUpdatePrefsOnNetworkThread();
577 588
578 // Add SpdySetting for mail.google.com:443. 589 // Add SpdySetting for mail.google.com:443.
579 HostPortPair spdy_server_mail("mail.google.com", 443); 590 HostPortPair spdy_server_mail("mail.google.com", 443);
580 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; 591 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH;
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 887
877 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo( 888 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo(
878 mail_quic_server_id)); 889 mail_quic_server_id));
879 } 890 }
880 891
881 TEST_P(HttpServerPropertiesManagerTest, Clear) { 892 TEST_P(HttpServerPropertiesManagerTest, Clear) {
882 ExpectPrefsUpdate(); 893 ExpectPrefsUpdate();
883 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); 894 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly();
884 895
885 HostPortPair spdy_server_mail("mail.google.com", 443); 896 HostPortPair spdy_server_mail("mail.google.com", 443);
886 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); 897 url::SchemeHostPort spdy_server("https", "mail.google.com", 443);
898 http_server_props_manager_->SetSupportsSpdy(spdy_server, true);
887 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 1234); 899 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 1234);
888 http_server_props_manager_->SetAlternativeService( 900 http_server_props_manager_->SetAlternativeService(
889 spdy_server_mail, alternative_service, one_day_from_now_); 901 spdy_server_mail, alternative_service, one_day_from_now_);
890 IPAddress actual_address(127, 0, 0, 1); 902 IPAddress actual_address(127, 0, 0, 1);
891 http_server_props_manager_->SetSupportsQuic(true, actual_address); 903 http_server_props_manager_->SetSupportsQuic(true, actual_address);
892 ServerNetworkStats stats; 904 ServerNetworkStats stats;
893 stats.srtt = base::TimeDelta::FromMicroseconds(10); 905 stats.srtt = base::TimeDelta::FromMicroseconds(10);
894 http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats); 906 http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats);
895 907
896 QuicServerId mail_quic_server_id("mail.google.com", 80); 908 QuicServerId mail_quic_server_id("mail.google.com", 80);
897 std::string quic_server_info1("quic_server_info1"); 909 std::string quic_server_info1("quic_server_info1");
898 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id, 910 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id,
899 quic_server_info1); 911 quic_server_info1);
900 912
901 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; 913 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH;
902 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; 914 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST;
903 const uint32_t value1 = 31337; 915 const uint32_t value1 = 31337;
904 http_server_props_manager_->SetSpdySetting(spdy_server_mail, id1, flags1, 916 http_server_props_manager_->SetSpdySetting(spdy_server_mail, id1, flags1,
905 value1); 917 value1);
906 918
907 // Run the task. 919 // Run the task.
908 base::RunLoop().RunUntilIdle(); 920 base::RunLoop().RunUntilIdle();
909 921
910 EXPECT_TRUE( 922 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(spdy_server));
911 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail));
912 EXPECT_TRUE(HasAlternativeService(spdy_server_mail)); 923 EXPECT_TRUE(HasAlternativeService(spdy_server_mail));
913 IPAddress address; 924 IPAddress address;
914 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); 925 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address));
915 EXPECT_EQ(actual_address, address); 926 EXPECT_EQ(actual_address, address);
916 const ServerNetworkStats* stats1 = 927 const ServerNetworkStats* stats1 =
917 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); 928 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail);
918 EXPECT_EQ(10, stats1->srtt.ToInternalValue()); 929 EXPECT_EQ(10, stats1->srtt.ToInternalValue());
919 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo( 930 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo(
920 mail_quic_server_id)); 931 mail_quic_server_id));
921 932
922 // Check SPDY settings values. 933 // Check SPDY settings values.
923 const SettingsMap& settings_map1_ret = 934 const SettingsMap& settings_map1_ret =
924 http_server_props_manager_->GetSpdySettings(spdy_server_mail); 935 http_server_props_manager_->GetSpdySettings(spdy_server_mail);
925 ASSERT_EQ(1U, settings_map1_ret.size()); 936 ASSERT_EQ(1U, settings_map1_ret.size());
926 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); 937 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1);
927 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); 938 EXPECT_TRUE(it1_ret != settings_map1_ret.end());
928 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; 939 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second;
929 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); 940 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first);
930 EXPECT_EQ(value1, flags_and_value1_ret.second); 941 EXPECT_EQ(value1, flags_and_value1_ret.second);
931 942
932 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 943 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
933 944
934 ExpectPrefsUpdate(); 945 ExpectPrefsUpdate();
935 946
936 // Clear http server data, time out if we do not get a completion callback. 947 // Clear http server data, time out if we do not get a completion callback.
937 http_server_props_manager_->Clear(base::MessageLoop::QuitWhenIdleClosure()); 948 http_server_props_manager_->Clear(base::MessageLoop::QuitWhenIdleClosure());
938 base::RunLoop().Run(); 949 base::RunLoop().Run();
939 950
940 EXPECT_FALSE( 951 EXPECT_FALSE(
941 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); 952 http_server_props_manager_->SupportsRequestPriority(spdy_server));
942 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); 953 EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
943 EXPECT_FALSE(http_server_props_manager_->GetSupportsQuic(&address)); 954 EXPECT_FALSE(http_server_props_manager_->GetSupportsQuic(&address));
944 const ServerNetworkStats* stats2 = 955 const ServerNetworkStats* stats2 =
945 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); 956 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail);
946 EXPECT_EQ(nullptr, stats2); 957 EXPECT_EQ(nullptr, stats2);
947 EXPECT_EQ(nullptr, 958 EXPECT_EQ(nullptr,
948 http_server_props_manager_->GetQuicServerInfo(mail_quic_server_id)); 959 http_server_props_manager_->GetQuicServerInfo(mail_quic_server_id));
949 960
950 const SettingsMap& settings_map2_ret = 961 const SettingsMap& settings_map2_ret =
951 http_server_props_manager_->GetSpdySettings(spdy_server_mail); 962 http_server_props_manager_->GetSpdySettings(spdy_server_mail);
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
1335 // Shutdown comes before the task is executed. 1346 // Shutdown comes before the task is executed.
1336 http_server_props_manager_->ShutdownOnPrefThread(); 1347 http_server_props_manager_->ShutdownOnPrefThread();
1337 // Run the task after shutdown, but before deletion. 1348 // Run the task after shutdown, but before deletion.
1338 base::RunLoop().RunUntilIdle(); 1349 base::RunLoop().RunUntilIdle();
1339 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 1350 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
1340 http_server_props_manager_.reset(); 1351 http_server_props_manager_.reset();
1341 base::RunLoop().RunUntilIdle(); 1352 base::RunLoop().RunUntilIdle();
1342 } 1353 }
1343 1354
1344 } // namespace net 1355 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698