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

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

Powered by Google App Engine
This is Rietveld 408576698