| OLD | NEW |
| 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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 | 199 |
| 200 void ExpectPrefsUpdateRepeatedly() { | 200 void ExpectPrefsUpdateRepeatedly() { |
| 201 EXPECT_CALL(*http_server_props_manager_, | 201 EXPECT_CALL(*http_server_props_manager_, |
| 202 UpdatePrefsFromCacheOnNetworkThread(_)) | 202 UpdatePrefsFromCacheOnNetworkThread(_)) |
| 203 .WillRepeatedly( | 203 .WillRepeatedly( |
| 204 Invoke(http_server_props_manager_.get(), | 204 Invoke(http_server_props_manager_.get(), |
| 205 &TestingHttpServerPropertiesManager:: | 205 &TestingHttpServerPropertiesManager:: |
| 206 UpdatePrefsFromCacheOnNetworkThreadConcrete)); | 206 UpdatePrefsFromCacheOnNetworkThreadConcrete)); |
| 207 } | 207 } |
| 208 | 208 |
| 209 bool HasAlternativeService(const HostPortPair& server) { | 209 bool HasAlternativeService(const SchemeOriginPair& server) { |
| 210 const AlternativeServiceVector alternative_service_vector = | 210 const AlternativeServiceVector alternative_service_vector = |
| 211 http_server_props_manager_->GetAlternativeServices(server); | 211 http_server_props_manager_->GetAlternativeServices(server); |
| 212 return !alternative_service_vector.empty(); | 212 return !alternative_service_vector.empty(); |
| 213 } | 213 } |
| 214 | 214 |
| 215 MockPrefDelegate* pref_delegate_; // Owned by HttpServerPropertiesManager. | 215 MockPrefDelegate* pref_delegate_; // Owned by HttpServerPropertiesManager. |
| 216 scoped_ptr<TestingHttpServerPropertiesManager> http_server_props_manager_; | 216 scoped_ptr<TestingHttpServerPropertiesManager> http_server_props_manager_; |
| 217 base::Time one_day_from_now_; | 217 base::Time one_day_from_now_; |
| 218 | 218 |
| 219 private: | 219 private: |
| 220 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManagerTest); | 220 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManagerTest); |
| 221 }; | 221 }; |
| 222 | 222 |
| 223 INSTANTIATE_TEST_CASE_P(Tests, | 223 INSTANTIATE_TEST_CASE_P(Tests, |
| 224 HttpServerPropertiesManagerTest, | 224 HttpServerPropertiesManagerTest, |
| 225 ::testing::ValuesIn(kHttpServerPropertiesVersions)); | 225 ::testing::ValuesIn(kHttpServerPropertiesVersions)); |
| 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 SchemeOriginPair google_scheme_origin_pair("https", google_server); |
| 236 HostPortPair mail_server("mail.google.com", 80); | 237 HostPortPair mail_server("mail.google.com", 80); |
| 238 SchemeOriginPair mail_scheme_origin_pair("https", mail_server); |
| 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 Loading... |
| 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_origin_pair)); |
| 352 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(mail_server)); | 354 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority( |
| 353 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( | 355 mail_scheme_origin_pair)); |
| 354 HostPortPair::FromString("foo.google.com:1337"))); | 356 EXPECT_FALSE( |
| 357 http_server_props_manager_->SupportsRequestPriority(SchemeOriginPair( |
| 358 "http", HostPortPair::FromString("foo.google.com:1337")))); |
| 355 | 359 |
| 356 // Verify alternative service. | 360 // Verify alternative service. |
| 357 if (GetParam() == 4) { | 361 if (GetParam() == 4) { |
| 358 const AlternativeServiceMap& map = | 362 const AlternativeServiceMap& map = |
| 359 http_server_props_manager_->alternative_service_map(); | 363 http_server_props_manager_->alternative_service_map(); |
| 360 ASSERT_EQ(2u, map.size()); | 364 ASSERT_EQ(2u, map.size()); |
| 361 | 365 |
| 362 AlternativeServiceMap::const_iterator map_it = map.begin(); | 366 AlternativeServiceMap::const_iterator map_it = map.begin(); |
| 363 EXPECT_EQ("mail.google.com", map_it->first.host()); | 367 EXPECT_EQ("mail.google.com", map_it->first.host()); |
| 364 ASSERT_EQ(1u, map_it->second.size()); | 368 ASSERT_EQ(1u, map_it->second.size()); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 http_server_properties_dict.SetWithoutPathExpansion("quic_servers", | 485 http_server_properties_dict.SetWithoutPathExpansion("quic_servers", |
| 482 quic_servers_dict); | 486 quic_servers_dict); |
| 483 | 487 |
| 484 // Set up the pref. | 488 // Set up the pref. |
| 485 pref_delegate_->SetPrefs(http_server_properties_dict); | 489 pref_delegate_->SetPrefs(http_server_properties_dict); |
| 486 | 490 |
| 487 base::RunLoop().RunUntilIdle(); | 491 base::RunLoop().RunUntilIdle(); |
| 488 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 492 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 489 | 493 |
| 490 // Verify that nothing is set. | 494 // Verify that nothing is set. |
| 491 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( | 495 HostPortPair host_port_pair = |
| 492 HostPortPair::FromString("www.google.com:65536"))); | 496 HostPortPair::FromString("www.google.com:65536"); |
| 497 SchemeOriginPair scheme_origin("https", host_port_pair); |
| 493 EXPECT_FALSE( | 498 EXPECT_FALSE( |
| 494 HasAlternativeService(HostPortPair::FromString("www.google.com:65536"))); | 499 http_server_props_manager_->SupportsRequestPriority(scheme_origin)); |
| 500 |
| 501 EXPECT_FALSE(HasAlternativeService(scheme_origin)); |
| 495 const ServerNetworkStats* stats1 = | 502 const ServerNetworkStats* stats1 = |
| 496 http_server_props_manager_->GetServerNetworkStats( | 503 http_server_props_manager_->GetServerNetworkStats(host_port_pair); |
| 497 HostPortPair::FromString("www.google.com:65536")); | |
| 498 EXPECT_EQ(nullptr, stats1); | 504 EXPECT_EQ(nullptr, stats1); |
| 499 EXPECT_EQ(0u, http_server_props_manager_->quic_server_info_map().size()); | 505 EXPECT_EQ(0u, http_server_props_manager_->quic_server_info_map().size()); |
| 500 } | 506 } |
| 501 | 507 |
| 502 TEST_P(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { | 508 TEST_P(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { |
| 503 ExpectCacheUpdate(); | 509 ExpectCacheUpdate(); |
| 504 // The prefs are automaticalls updated in the case corruption is detected. | 510 // The prefs are automaticalls updated in the case corruption is detected. |
| 505 ExpectPrefsUpdate(); | 511 ExpectPrefsUpdate(); |
| 506 ExpectScheduleUpdatePrefsOnNetworkThread(); | 512 ExpectScheduleUpdatePrefsOnNetworkThread(); |
| 507 | 513 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 537 servers_dict); | 543 servers_dict); |
| 538 } | 544 } |
| 539 | 545 |
| 540 // Set up the pref. | 546 // Set up the pref. |
| 541 pref_delegate_->SetPrefs(http_server_properties_dict); | 547 pref_delegate_->SetPrefs(http_server_properties_dict); |
| 542 | 548 |
| 543 base::RunLoop().RunUntilIdle(); | 549 base::RunLoop().RunUntilIdle(); |
| 544 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 550 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 545 | 551 |
| 546 // Verify alternative service is not set. | 552 // Verify alternative service is not set. |
| 547 EXPECT_FALSE( | 553 SchemeOriginPair scheme_origin("http", |
| 548 HasAlternativeService(HostPortPair::FromString("www.google.com:80"))); | 554 HostPortPair::FromString("www.google.com:80")); |
| 555 EXPECT_FALSE(HasAlternativeService(scheme_origin)); |
| 549 } | 556 } |
| 550 | 557 |
| 551 TEST_P(HttpServerPropertiesManagerTest, SupportsSpdy) { | 558 TEST_P(HttpServerPropertiesManagerTest, SupportsSpdy) { |
| 552 ExpectPrefsUpdate(); | 559 ExpectPrefsUpdate(); |
| 553 ExpectScheduleUpdatePrefsOnNetworkThread(); | 560 ExpectScheduleUpdatePrefsOnNetworkThread(); |
| 554 | 561 |
| 555 // Post an update task to the network thread. SetSupportsSpdy calls | 562 // Post an update task to the network thread. SetSupportsSpdy calls |
| 556 // ScheduleUpdatePrefsOnNetworkThread. | 563 // ScheduleUpdatePrefsOnNetworkThread. |
| 557 | 564 |
| 558 // Add mail.google.com:443 as a supporting spdy server. | 565 // Add mail.google.com:443 as a supporting spdy server. |
| 559 HostPortPair spdy_server_mail("mail.google.com", 443); | 566 HostPortPair spdy_server_mail("mail.google.com", 443); |
| 567 SchemeOriginPair scheme_origin("https", spdy_server_mail); |
| 560 EXPECT_FALSE( | 568 EXPECT_FALSE( |
| 561 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); | 569 http_server_props_manager_->SupportsRequestPriority(scheme_origin)); |
| 562 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); | 570 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); |
| 563 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. | 571 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. |
| 564 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); | 572 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); |
| 565 | 573 |
| 566 // Run the task. | 574 // Run the task. |
| 567 base::RunLoop().RunUntilIdle(); | 575 base::RunLoop().RunUntilIdle(); |
| 568 | 576 |
| 569 EXPECT_TRUE( | 577 EXPECT_TRUE( |
| 570 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); | 578 http_server_props_manager_->SupportsRequestPriority(scheme_origin)); |
| 571 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 579 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 572 } | 580 } |
| 573 | 581 |
| 574 TEST_P(HttpServerPropertiesManagerTest, SetSpdySetting) { | 582 TEST_P(HttpServerPropertiesManagerTest, SetSpdySetting) { |
| 575 ExpectPrefsUpdate(); | 583 ExpectPrefsUpdate(); |
| 576 ExpectScheduleUpdatePrefsOnNetworkThread(); | 584 ExpectScheduleUpdatePrefsOnNetworkThread(); |
| 577 | 585 |
| 578 // Add SpdySetting for mail.google.com:443. | 586 // Add SpdySetting for mail.google.com:443. |
| 579 HostPortPair spdy_server_mail("mail.google.com", 443); | 587 HostPortPair spdy_server_mail("mail.google.com", 443); |
| 580 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; | 588 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 http_server_props_manager_->spdy_settings_map(); | 680 http_server_props_manager_->spdy_settings_map(); |
| 673 ASSERT_EQ(0U, spdy_settings_map2_ret.size()); | 681 ASSERT_EQ(0U, spdy_settings_map2_ret.size()); |
| 674 | 682 |
| 675 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 683 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 676 } | 684 } |
| 677 | 685 |
| 678 TEST_P(HttpServerPropertiesManagerTest, GetAlternativeServices) { | 686 TEST_P(HttpServerPropertiesManagerTest, GetAlternativeServices) { |
| 679 ExpectPrefsUpdate(); | 687 ExpectPrefsUpdate(); |
| 680 ExpectScheduleUpdatePrefsOnNetworkThread(); | 688 ExpectScheduleUpdatePrefsOnNetworkThread(); |
| 681 | 689 |
| 682 HostPortPair spdy_server_mail("mail.google.com", 80); | 690 SchemeOriginPair scheme_origin("http", "mail.google.com", 80); |
| 683 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); | 691 EXPECT_FALSE(HasAlternativeService(scheme_origin)); |
| 684 const AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", | 692 const AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", |
| 685 443); | 693 443); |
| 686 http_server_props_manager_->SetAlternativeService( | 694 http_server_props_manager_->SetAlternativeService( |
| 687 spdy_server_mail, alternative_service, 1.0, one_day_from_now_); | 695 scheme_origin, alternative_service, 1.0, one_day_from_now_); |
| 688 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. | 696 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. |
| 689 http_server_props_manager_->SetAlternativeService( | 697 http_server_props_manager_->SetAlternativeService( |
| 690 spdy_server_mail, alternative_service, 1.0, one_day_from_now_); | 698 scheme_origin, alternative_service, 1.0, one_day_from_now_); |
| 691 | 699 |
| 692 // Run the task. | 700 // Run the task. |
| 693 base::RunLoop().RunUntilIdle(); | 701 base::RunLoop().RunUntilIdle(); |
| 694 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 702 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 695 | 703 |
| 696 AlternativeServiceVector alternative_service_vector = | 704 AlternativeServiceVector alternative_service_vector = |
| 697 http_server_props_manager_->GetAlternativeServices(spdy_server_mail); | 705 http_server_props_manager_->GetAlternativeServices(scheme_origin); |
| 698 ASSERT_EQ(1u, alternative_service_vector.size()); | 706 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 699 EXPECT_EQ(alternative_service, alternative_service_vector[0]); | 707 EXPECT_EQ(alternative_service, alternative_service_vector[0]); |
| 700 } | 708 } |
| 701 | 709 |
| 702 TEST_P(HttpServerPropertiesManagerTest, SetAlternativeServices) { | 710 TEST_P(HttpServerPropertiesManagerTest, SetAlternativeServices) { |
| 703 ExpectPrefsUpdate(); | 711 ExpectPrefsUpdate(); |
| 704 ExpectScheduleUpdatePrefsOnNetworkThread(); | 712 ExpectScheduleUpdatePrefsOnNetworkThread(); |
| 705 | 713 |
| 706 HostPortPair spdy_server_mail("mail.google.com", 80); | 714 SchemeOriginPair scheme_origin("http", "mail.google.com", 80); |
| 707 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); | 715 EXPECT_FALSE(HasAlternativeService(scheme_origin)); |
| 708 AlternativeServiceInfoVector alternative_service_info_vector; | 716 AlternativeServiceInfoVector alternative_service_info_vector; |
| 709 const AlternativeService alternative_service1(NPN_HTTP_2, "mail.google.com", | 717 const AlternativeService alternative_service1(NPN_HTTP_2, "mail.google.com", |
| 710 443); | 718 443); |
| 711 alternative_service_info_vector.push_back( | 719 alternative_service_info_vector.push_back( |
| 712 AlternativeServiceInfo(alternative_service1, 1.0, one_day_from_now_)); | 720 AlternativeServiceInfo(alternative_service1, 1.0, one_day_from_now_)); |
| 713 const AlternativeService alternative_service2(QUIC, "mail.google.com", 1234); | 721 const AlternativeService alternative_service2(QUIC, "mail.google.com", 1234); |
| 714 alternative_service_info_vector.push_back( | 722 alternative_service_info_vector.push_back( |
| 715 AlternativeServiceInfo(alternative_service2, 1.0, one_day_from_now_)); | 723 AlternativeServiceInfo(alternative_service2, 1.0, one_day_from_now_)); |
| 716 http_server_props_manager_->SetAlternativeServices( | 724 http_server_props_manager_->SetAlternativeServices( |
| 717 spdy_server_mail, alternative_service_info_vector); | 725 scheme_origin, alternative_service_info_vector); |
| 718 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. | 726 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. |
| 719 http_server_props_manager_->SetAlternativeServices( | 727 http_server_props_manager_->SetAlternativeServices( |
| 720 spdy_server_mail, alternative_service_info_vector); | 728 scheme_origin, alternative_service_info_vector); |
| 721 | 729 |
| 722 // Run the task. | 730 // Run the task. |
| 723 base::RunLoop().RunUntilIdle(); | 731 base::RunLoop().RunUntilIdle(); |
| 724 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 732 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 725 | 733 |
| 726 AlternativeServiceVector alternative_service_vector = | 734 AlternativeServiceVector alternative_service_vector = |
| 727 http_server_props_manager_->GetAlternativeServices(spdy_server_mail); | 735 http_server_props_manager_->GetAlternativeServices(scheme_origin); |
| 728 ASSERT_EQ(2u, alternative_service_vector.size()); | 736 ASSERT_EQ(2u, alternative_service_vector.size()); |
| 729 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); | 737 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); |
| 730 EXPECT_EQ(alternative_service2, alternative_service_vector[1]); | 738 EXPECT_EQ(alternative_service2, alternative_service_vector[1]); |
| 731 } | 739 } |
| 732 | 740 |
| 733 TEST_P(HttpServerPropertiesManagerTest, SetAlternativeServicesEmpty) { | 741 TEST_P(HttpServerPropertiesManagerTest, SetAlternativeServicesEmpty) { |
| 734 HostPortPair spdy_server_mail("mail.google.com", 80); | 742 SchemeOriginPair scheme_origin("http", "mail.google.com", 80); |
| 735 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); | 743 EXPECT_FALSE(HasAlternativeService(scheme_origin)); |
| 736 const AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", | 744 const AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", |
| 737 443); | 745 443); |
| 738 http_server_props_manager_->SetAlternativeServices( | 746 http_server_props_manager_->SetAlternativeServices( |
| 739 spdy_server_mail, AlternativeServiceInfoVector()); | 747 scheme_origin, AlternativeServiceInfoVector()); |
| 740 // ExpectScheduleUpdatePrefsOnNetworkThread() should not be called. | 748 // ExpectScheduleUpdatePrefsOnNetworkThread() should not be called. |
| 741 | 749 |
| 742 // Run the task. | 750 // Run the task. |
| 743 base::RunLoop().RunUntilIdle(); | 751 base::RunLoop().RunUntilIdle(); |
| 744 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 752 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 745 | 753 |
| 746 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); | 754 EXPECT_FALSE(HasAlternativeService(scheme_origin)); |
| 747 } | 755 } |
| 748 | 756 |
| 749 TEST_P(HttpServerPropertiesManagerTest, ClearAlternativeServices) { | 757 TEST_P(HttpServerPropertiesManagerTest, ClearAlternativeServices) { |
| 750 ExpectPrefsUpdate(); | 758 ExpectPrefsUpdate(); |
| 751 ExpectScheduleUpdatePrefsOnNetworkThread(); | 759 ExpectScheduleUpdatePrefsOnNetworkThread(); |
| 752 | 760 |
| 753 HostPortPair spdy_server_mail("mail.google.com", 80); | 761 SchemeOriginPair scheme_origin("http", "mail.google.com", 80); |
| 754 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); | 762 EXPECT_FALSE(HasAlternativeService(scheme_origin)); |
| 755 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 443); | 763 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 443); |
| 756 http_server_props_manager_->SetAlternativeService( | 764 http_server_props_manager_->SetAlternativeService( |
| 757 spdy_server_mail, alternative_service, 1.0, one_day_from_now_); | 765 scheme_origin, alternative_service, 1.0, one_day_from_now_); |
| 758 ExpectScheduleUpdatePrefsOnNetworkThread(); | 766 ExpectScheduleUpdatePrefsOnNetworkThread(); |
| 759 http_server_props_manager_->ClearAlternativeServices(spdy_server_mail); | 767 http_server_props_manager_->ClearAlternativeServices(scheme_origin); |
| 760 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. | 768 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. |
| 761 http_server_props_manager_->ClearAlternativeServices(spdy_server_mail); | 769 http_server_props_manager_->ClearAlternativeServices(scheme_origin); |
| 762 | 770 |
| 763 // Run the task. | 771 // Run the task. |
| 764 base::RunLoop().RunUntilIdle(); | 772 base::RunLoop().RunUntilIdle(); |
| 765 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 773 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 766 | 774 |
| 767 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); | 775 EXPECT_FALSE(HasAlternativeService(scheme_origin)); |
| 768 } | 776 } |
| 769 | 777 |
| 770 TEST_P(HttpServerPropertiesManagerTest, ConfirmAlternativeService) { | 778 TEST_P(HttpServerPropertiesManagerTest, ConfirmAlternativeService) { |
| 771 ExpectPrefsUpdate(); | 779 ExpectPrefsUpdate(); |
| 772 | 780 |
| 773 HostPortPair spdy_server_mail("mail.google.com", 80); | 781 SchemeOriginPair scheme_origin("http", "mail.google.com", 80); |
| 774 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); | 782 EXPECT_FALSE(HasAlternativeService(scheme_origin)); |
| 775 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 443); | 783 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 443); |
| 776 | 784 |
| 777 ExpectScheduleUpdatePrefsOnNetworkThread(); | 785 ExpectScheduleUpdatePrefsOnNetworkThread(); |
| 778 http_server_props_manager_->SetAlternativeService( | 786 http_server_props_manager_->SetAlternativeService( |
| 779 spdy_server_mail, alternative_service, 1.0, one_day_from_now_); | 787 scheme_origin, alternative_service, 1.0, one_day_from_now_); |
| 780 | 788 |
| 781 EXPECT_FALSE(http_server_props_manager_->IsAlternativeServiceBroken( | 789 EXPECT_FALSE(http_server_props_manager_->IsAlternativeServiceBroken( |
| 782 alternative_service)); | 790 alternative_service)); |
| 783 EXPECT_FALSE(http_server_props_manager_->WasAlternativeServiceRecentlyBroken( | 791 EXPECT_FALSE(http_server_props_manager_->WasAlternativeServiceRecentlyBroken( |
| 784 alternative_service)); | 792 alternative_service)); |
| 785 | 793 |
| 786 ExpectScheduleUpdatePrefsOnNetworkThread(); | 794 ExpectScheduleUpdatePrefsOnNetworkThread(); |
| 787 http_server_props_manager_->MarkAlternativeServiceBroken(alternative_service); | 795 http_server_props_manager_->MarkAlternativeServiceBroken(alternative_service); |
| 788 EXPECT_TRUE(http_server_props_manager_->IsAlternativeServiceBroken( | 796 EXPECT_TRUE(http_server_props_manager_->IsAlternativeServiceBroken( |
| 789 alternative_service)); | 797 alternative_service)); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 876 | 884 |
| 877 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo( | 885 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo( |
| 878 mail_quic_server_id)); | 886 mail_quic_server_id)); |
| 879 } | 887 } |
| 880 | 888 |
| 881 TEST_P(HttpServerPropertiesManagerTest, Clear) { | 889 TEST_P(HttpServerPropertiesManagerTest, Clear) { |
| 882 ExpectPrefsUpdate(); | 890 ExpectPrefsUpdate(); |
| 883 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); | 891 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); |
| 884 | 892 |
| 885 HostPortPair spdy_server_mail("mail.google.com", 443); | 893 HostPortPair spdy_server_mail("mail.google.com", 443); |
| 894 SchemeOriginPair scheme_origin("http", spdy_server_mail); |
| 886 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); | 895 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); |
| 887 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 1234); | 896 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 1234); |
| 888 http_server_props_manager_->SetAlternativeService( | 897 http_server_props_manager_->SetAlternativeService( |
| 889 spdy_server_mail, alternative_service, 1.0, one_day_from_now_); | 898 scheme_origin, alternative_service, 1.0, one_day_from_now_); |
| 890 IPAddress actual_address(127, 0, 0, 1); | 899 IPAddress actual_address(127, 0, 0, 1); |
| 891 http_server_props_manager_->SetSupportsQuic(true, actual_address); | 900 http_server_props_manager_->SetSupportsQuic(true, actual_address); |
| 892 ServerNetworkStats stats; | 901 ServerNetworkStats stats; |
| 893 stats.srtt = base::TimeDelta::FromMicroseconds(10); | 902 stats.srtt = base::TimeDelta::FromMicroseconds(10); |
| 894 http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats); | 903 http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats); |
| 895 | 904 |
| 896 QuicServerId mail_quic_server_id("mail.google.com", 80); | 905 QuicServerId mail_quic_server_id("mail.google.com", 80); |
| 897 std::string quic_server_info1("quic_server_info1"); | 906 std::string quic_server_info1("quic_server_info1"); |
| 898 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id, | 907 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id, |
| 899 quic_server_info1); | 908 quic_server_info1); |
| 900 | 909 |
| 901 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; | 910 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; |
| 902 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; | 911 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; |
| 903 const uint32_t value1 = 31337; | 912 const uint32_t value1 = 31337; |
| 904 http_server_props_manager_->SetSpdySetting(spdy_server_mail, id1, flags1, | 913 http_server_props_manager_->SetSpdySetting(spdy_server_mail, id1, flags1, |
| 905 value1); | 914 value1); |
| 906 | 915 |
| 907 // Run the task. | 916 // Run the task. |
| 908 base::RunLoop().RunUntilIdle(); | 917 base::RunLoop().RunUntilIdle(); |
| 909 | 918 |
| 910 EXPECT_TRUE( | 919 EXPECT_TRUE( |
| 911 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); | 920 http_server_props_manager_->SupportsRequestPriority(scheme_origin)); |
| 912 EXPECT_TRUE(HasAlternativeService(spdy_server_mail)); | 921 EXPECT_TRUE(HasAlternativeService(scheme_origin)); |
| 913 IPAddress address; | 922 IPAddress address; |
| 914 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); | 923 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); |
| 915 EXPECT_EQ(actual_address, address); | 924 EXPECT_EQ(actual_address, address); |
| 916 const ServerNetworkStats* stats1 = | 925 const ServerNetworkStats* stats1 = |
| 917 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); | 926 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); |
| 918 EXPECT_EQ(10, stats1->srtt.ToInternalValue()); | 927 EXPECT_EQ(10, stats1->srtt.ToInternalValue()); |
| 919 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo( | 928 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo( |
| 920 mail_quic_server_id)); | 929 mail_quic_server_id)); |
| 921 | 930 |
| 922 // Check SPDY settings values. | 931 // Check SPDY settings values. |
| 923 const SettingsMap& settings_map1_ret = | 932 const SettingsMap& settings_map1_ret = |
| 924 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 933 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
| 925 ASSERT_EQ(1U, settings_map1_ret.size()); | 934 ASSERT_EQ(1U, settings_map1_ret.size()); |
| 926 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); | 935 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); |
| 927 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); | 936 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); |
| 928 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; | 937 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; |
| 929 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); | 938 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); |
| 930 EXPECT_EQ(value1, flags_and_value1_ret.second); | 939 EXPECT_EQ(value1, flags_and_value1_ret.second); |
| 931 | 940 |
| 932 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 941 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 933 | 942 |
| 934 ExpectPrefsUpdate(); | 943 ExpectPrefsUpdate(); |
| 935 | 944 |
| 936 // Clear http server data, time out if we do not get a completion callback. | 945 // Clear http server data, time out if we do not get a completion callback. |
| 937 http_server_props_manager_->Clear(base::MessageLoop::QuitWhenIdleClosure()); | 946 http_server_props_manager_->Clear(base::MessageLoop::QuitWhenIdleClosure()); |
| 938 base::RunLoop().Run(); | 947 base::RunLoop().Run(); |
| 939 | 948 |
| 940 EXPECT_FALSE( | 949 EXPECT_FALSE( |
| 941 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); | 950 http_server_props_manager_->SupportsRequestPriority(scheme_origin)); |
| 942 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); | 951 EXPECT_FALSE(HasAlternativeService(scheme_origin)); |
| 943 EXPECT_FALSE(http_server_props_manager_->GetSupportsQuic(&address)); | 952 EXPECT_FALSE(http_server_props_manager_->GetSupportsQuic(&address)); |
| 944 const ServerNetworkStats* stats2 = | 953 const ServerNetworkStats* stats2 = |
| 945 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); | 954 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); |
| 946 EXPECT_EQ(nullptr, stats2); | 955 EXPECT_EQ(nullptr, stats2); |
| 947 EXPECT_EQ(nullptr, | 956 EXPECT_EQ(nullptr, |
| 948 http_server_props_manager_->GetQuicServerInfo(mail_quic_server_id)); | 957 http_server_props_manager_->GetQuicServerInfo(mail_quic_server_id)); |
| 949 | 958 |
| 950 const SettingsMap& settings_map2_ret = | 959 const SettingsMap& settings_map2_ret = |
| 951 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 960 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
| 952 EXPECT_EQ(0U, settings_map2_ret.size()); | 961 EXPECT_EQ(0U, settings_map2_ret.size()); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1017 pref_delegate_->SetPrefs(http_server_properties_dict); | 1026 pref_delegate_->SetPrefs(http_server_properties_dict); |
| 1018 | 1027 |
| 1019 base::RunLoop().RunUntilIdle(); | 1028 base::RunLoop().RunUntilIdle(); |
| 1020 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 1029 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 1021 | 1030 |
| 1022 // Verify alternative service. | 1031 // Verify alternative service. |
| 1023 for (int i = 0; i < 200; ++i) { | 1032 for (int i = 0; i < 200; ++i) { |
| 1024 std::string server = StringPrintf("www.google.com:%d", i); | 1033 std::string server = StringPrintf("www.google.com:%d", i); |
| 1025 AlternativeServiceVector alternative_service_vector = | 1034 AlternativeServiceVector alternative_service_vector = |
| 1026 http_server_props_manager_->GetAlternativeServices( | 1035 http_server_props_manager_->GetAlternativeServices( |
| 1027 HostPortPair::FromString(server)); | 1036 SchemeOriginPair("https", HostPortPair::FromString(server))); |
| 1028 ASSERT_EQ(1u, alternative_service_vector.size()); | 1037 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 1029 EXPECT_EQ(QUIC, alternative_service_vector[0].protocol); | 1038 EXPECT_EQ(QUIC, alternative_service_vector[0].protocol); |
| 1030 EXPECT_EQ(i, alternative_service_vector[0].port); | 1039 EXPECT_EQ(i, alternative_service_vector[0].port); |
| 1031 } | 1040 } |
| 1032 | 1041 |
| 1033 // Verify SupportsQuic. | 1042 // Verify SupportsQuic. |
| 1034 IPAddress address; | 1043 IPAddress address; |
| 1035 ASSERT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); | 1044 ASSERT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); |
| 1036 EXPECT_EQ("127.0.0.1", address.ToString()); | 1045 EXPECT_EQ("127.0.0.1", address.ToString()); |
| 1037 } | 1046 } |
| 1038 | 1047 |
| 1039 TEST_P(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) { | 1048 TEST_P(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) { |
| 1040 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); | 1049 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); |
| 1041 | 1050 |
| 1042 const HostPortPair server_www("www.google.com", 80); | 1051 SchemeOriginPair server_www("http", "www.google.com", 80); |
| 1043 const HostPortPair server_mail("mail.google.com", 80); | 1052 const HostPortPair server_mail("mail.google.com", 80); |
| 1053 SchemeOriginPair mail_server("http", server_mail); |
| 1044 | 1054 |
| 1045 // Set alternate protocol. | 1055 // Set alternate protocol. |
| 1046 AlternativeServiceInfoVector alternative_service_info_vector; | 1056 AlternativeServiceInfoVector alternative_service_info_vector; |
| 1047 AlternativeService www_alternative_service1(NPN_HTTP_2, "", 443); | 1057 AlternativeService www_alternative_service1(NPN_HTTP_2, "", 443); |
| 1048 base::Time expiration1; | 1058 base::Time expiration1; |
| 1049 ASSERT_TRUE(base::Time::FromUTCString("2036-12-01 10:00:00", &expiration1)); | 1059 ASSERT_TRUE(base::Time::FromUTCString("2036-12-01 10:00:00", &expiration1)); |
| 1050 alternative_service_info_vector.push_back( | 1060 alternative_service_info_vector.push_back( |
| 1051 AlternativeServiceInfo(www_alternative_service1, 1.0, expiration1)); | 1061 AlternativeServiceInfo(www_alternative_service1, 1.0, expiration1)); |
| 1052 AlternativeService www_alternative_service2(NPN_HTTP_2, "www.google.com", | 1062 AlternativeService www_alternative_service2(NPN_HTTP_2, "www.google.com", |
| 1053 1234); | 1063 1234); |
| 1054 base::Time expiration2; | 1064 base::Time expiration2; |
| 1055 ASSERT_TRUE(base::Time::FromUTCString("2036-12-31 10:00:00", &expiration2)); | 1065 ASSERT_TRUE(base::Time::FromUTCString("2036-12-31 10:00:00", &expiration2)); |
| 1056 alternative_service_info_vector.push_back( | 1066 alternative_service_info_vector.push_back( |
| 1057 AlternativeServiceInfo(www_alternative_service2, 0.7, expiration2)); | 1067 AlternativeServiceInfo(www_alternative_service2, 0.7, expiration2)); |
| 1058 http_server_props_manager_->SetAlternativeServices( | 1068 http_server_props_manager_->SetAlternativeServices( |
| 1059 server_www, alternative_service_info_vector); | 1069 server_www, alternative_service_info_vector); |
| 1060 | 1070 |
| 1061 AlternativeService mail_alternative_service(NPN_SPDY_3_1, "foo.google.com", | 1071 AlternativeService mail_alternative_service(NPN_SPDY_3_1, "foo.google.com", |
| 1062 444); | 1072 444); |
| 1063 base::Time expiration3 = base::Time::Max(); | 1073 base::Time expiration3 = base::Time::Max(); |
| 1064 http_server_props_manager_->SetAlternativeService( | 1074 http_server_props_manager_->SetAlternativeService( |
| 1065 server_mail, mail_alternative_service, 0.2, expiration3); | 1075 mail_server, mail_alternative_service, 0.2, expiration3); |
| 1066 | 1076 |
| 1067 // Set ServerNetworkStats. | 1077 // Set ServerNetworkStats. |
| 1068 ServerNetworkStats stats; | 1078 ServerNetworkStats stats; |
| 1069 stats.srtt = base::TimeDelta::FromInternalValue(42); | 1079 stats.srtt = base::TimeDelta::FromInternalValue(42); |
| 1070 http_server_props_manager_->SetServerNetworkStats(server_mail, stats); | 1080 http_server_props_manager_->SetServerNetworkStats(server_mail, stats); |
| 1071 | 1081 |
| 1072 // Set quic_server_info string. | 1082 // Set quic_server_info string. |
| 1073 QuicServerId mail_quic_server_id("mail.google.com", 80); | 1083 QuicServerId mail_quic_server_id("mail.google.com", 80); |
| 1074 std::string quic_server_info1("quic_server_info1"); | 1084 std::string quic_server_info1("quic_server_info1"); |
| 1075 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id, | 1085 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1115 scoped_ptr<base::Value> server_value = base::JSONReader::Read( | 1125 scoped_ptr<base::Value> server_value = base::JSONReader::Read( |
| 1116 "{\"alternative_service\":[{\"port\":443,\"protocol_str\":\"npn-h2\"}," | 1126 "{\"alternative_service\":[{\"port\":443,\"protocol_str\":\"npn-h2\"}," |
| 1117 "{\"port\":123,\"protocol_str\":\"quic\",\"probability\":0.7," | 1127 "{\"port\":123,\"protocol_str\":\"quic\",\"probability\":0.7," |
| 1118 "\"expiration\":\"9223372036854775807\"},{\"host\":\"example.org\"," | 1128 "\"expiration\":\"9223372036854775807\"},{\"host\":\"example.org\"," |
| 1119 "\"port\":1234,\"protocol_str\":\"npn-h2\",\"probability\":0.2," | 1129 "\"port\":1234,\"protocol_str\":\"npn-h2\",\"probability\":0.2," |
| 1120 "\"expiration\":\"13758804000000000\"}]}"); | 1130 "\"expiration\":\"13758804000000000\"}]}"); |
| 1121 ASSERT_TRUE(server_value); | 1131 ASSERT_TRUE(server_value); |
| 1122 base::DictionaryValue* server_dict; | 1132 base::DictionaryValue* server_dict; |
| 1123 ASSERT_TRUE(server_value->GetAsDictionary(&server_dict)); | 1133 ASSERT_TRUE(server_value->GetAsDictionary(&server_dict)); |
| 1124 | 1134 |
| 1125 const HostPortPair host_port_pair("example.com", 443); | 1135 SchemeOriginPair scheme_origin("https", "example.com", 443); |
| 1126 AlternativeServiceMap alternative_service_map(/*max_size=*/5); | 1136 AlternativeServiceMap alternative_service_map(/*max_size=*/5); |
| 1127 EXPECT_TRUE(http_server_props_manager_->AddToAlternativeServiceMap( | 1137 EXPECT_TRUE(http_server_props_manager_->AddToAlternativeServiceMap( |
| 1128 host_port_pair, *server_dict, &alternative_service_map)); | 1138 scheme_origin, *server_dict, &alternative_service_map)); |
| 1129 | 1139 |
| 1130 AlternativeServiceMap::iterator it = | 1140 AlternativeServiceMap::iterator it = |
| 1131 alternative_service_map.Get(host_port_pair); | 1141 alternative_service_map.Get(scheme_origin); |
| 1132 ASSERT_NE(alternative_service_map.end(), it); | 1142 ASSERT_NE(alternative_service_map.end(), it); |
| 1133 AlternativeServiceInfoVector alternative_service_info_vector = it->second; | 1143 AlternativeServiceInfoVector alternative_service_info_vector = it->second; |
| 1134 ASSERT_EQ(3u, alternative_service_info_vector.size()); | 1144 ASSERT_EQ(3u, alternative_service_info_vector.size()); |
| 1135 | 1145 |
| 1136 EXPECT_EQ(NPN_HTTP_2, | 1146 EXPECT_EQ(NPN_HTTP_2, |
| 1137 alternative_service_info_vector[0].alternative_service.protocol); | 1147 alternative_service_info_vector[0].alternative_service.protocol); |
| 1138 EXPECT_EQ("", alternative_service_info_vector[0].alternative_service.host); | 1148 EXPECT_EQ("", alternative_service_info_vector[0].alternative_service.host); |
| 1139 EXPECT_EQ(443, alternative_service_info_vector[0].alternative_service.port); | 1149 EXPECT_EQ(443, alternative_service_info_vector[0].alternative_service.port); |
| 1140 // Probability defaults to 1.0. | 1150 // Probability defaults to 1.0. |
| 1141 EXPECT_DOUBLE_EQ(1.0, alternative_service_info_vector[0].probability); | 1151 EXPECT_DOUBLE_EQ(1.0, alternative_service_info_vector[0].probability); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1186 const base::Time time_one_day_ago = | 1196 const base::Time time_one_day_ago = |
| 1187 base::Time::Now() - base::TimeDelta::FromDays(1); | 1197 base::Time::Now() - base::TimeDelta::FromDays(1); |
| 1188 alternative_service_info_vector.push_back(AlternativeServiceInfo( | 1198 alternative_service_info_vector.push_back(AlternativeServiceInfo( |
| 1189 expired_alternative_service, 1.0, time_one_day_ago)); | 1199 expired_alternative_service, 1.0, time_one_day_ago)); |
| 1190 | 1200 |
| 1191 const AlternativeService valid_alternative_service(NPN_HTTP_2, | 1201 const AlternativeService valid_alternative_service(NPN_HTTP_2, |
| 1192 "valid.example.com", 443); | 1202 "valid.example.com", 443); |
| 1193 alternative_service_info_vector.push_back(AlternativeServiceInfo( | 1203 alternative_service_info_vector.push_back(AlternativeServiceInfo( |
| 1194 valid_alternative_service, 1.0, time_one_day_later)); | 1204 valid_alternative_service, 1.0, time_one_day_later)); |
| 1195 | 1205 |
| 1196 const HostPortPair host_port_pair("www.example.com", 443); | 1206 SchemeOriginPair scheme_origin("https", "www.example.com", 443); |
| 1197 http_server_props_manager_->SetAlternativeServices( | 1207 http_server_props_manager_->SetAlternativeServices( |
| 1198 host_port_pair, alternative_service_info_vector); | 1208 scheme_origin, alternative_service_info_vector); |
| 1199 | 1209 |
| 1200 // Update cache. | 1210 // Update cache. |
| 1201 ExpectPrefsUpdate(); | 1211 ExpectPrefsUpdate(); |
| 1202 ExpectCacheUpdate(); | 1212 ExpectCacheUpdate(); |
| 1203 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); | 1213 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); |
| 1204 base::RunLoop().RunUntilIdle(); | 1214 base::RunLoop().RunUntilIdle(); |
| 1205 | 1215 |
| 1206 const base::DictionaryValue& pref_dict = | 1216 const base::DictionaryValue& pref_dict = |
| 1207 pref_delegate_->GetServerProperties(); | 1217 pref_delegate_->GetServerProperties(); |
| 1208 | 1218 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1249 valid_dict->SetInteger("port", 443); | 1259 valid_dict->SetInteger("port", 443); |
| 1250 valid_dict->SetDouble("probability", 1.0); | 1260 valid_dict->SetDouble("probability", 1.0); |
| 1251 valid_dict->SetString( | 1261 valid_dict->SetString( |
| 1252 "expiration", base::Int64ToString(one_day_from_now_.ToInternalValue())); | 1262 "expiration", base::Int64ToString(one_day_from_now_.ToInternalValue())); |
| 1253 alternative_service_list->Append(valid_dict); | 1263 alternative_service_list->Append(valid_dict); |
| 1254 | 1264 |
| 1255 base::DictionaryValue server_pref_dict; | 1265 base::DictionaryValue server_pref_dict; |
| 1256 server_pref_dict.SetWithoutPathExpansion("alternative_service", | 1266 server_pref_dict.SetWithoutPathExpansion("alternative_service", |
| 1257 alternative_service_list.release()); | 1267 alternative_service_list.release()); |
| 1258 | 1268 |
| 1259 const HostPortPair host_port_pair("example.com", 443); | 1269 SchemeOriginPair scheme_origin("https", "example.com", 443); |
| 1260 AlternativeServiceMap alternative_service_map(/*max_size=*/5); | 1270 AlternativeServiceMap alternative_service_map(/*max_size=*/5); |
| 1261 ASSERT_TRUE(http_server_props_manager_->AddToAlternativeServiceMap( | 1271 ASSERT_TRUE(http_server_props_manager_->AddToAlternativeServiceMap( |
| 1262 host_port_pair, server_pref_dict, &alternative_service_map)); | 1272 scheme_origin, server_pref_dict, &alternative_service_map)); |
| 1263 | 1273 |
| 1264 AlternativeServiceMap::iterator it = | 1274 AlternativeServiceMap::iterator it = |
| 1265 alternative_service_map.Get(host_port_pair); | 1275 alternative_service_map.Get(scheme_origin); |
| 1266 ASSERT_NE(alternative_service_map.end(), it); | 1276 ASSERT_NE(alternative_service_map.end(), it); |
| 1267 AlternativeServiceInfoVector alternative_service_info_vector = it->second; | 1277 AlternativeServiceInfoVector alternative_service_info_vector = it->second; |
| 1268 ASSERT_EQ(1u, alternative_service_info_vector.size()); | 1278 ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 1269 | 1279 |
| 1270 EXPECT_EQ(NPN_HTTP_2, | 1280 EXPECT_EQ(NPN_HTTP_2, |
| 1271 alternative_service_info_vector[0].alternative_service.protocol); | 1281 alternative_service_info_vector[0].alternative_service.protocol); |
| 1272 EXPECT_EQ("valid.example.com", | 1282 EXPECT_EQ("valid.example.com", |
| 1273 alternative_service_info_vector[0].alternative_service.host); | 1283 alternative_service_info_vector[0].alternative_service.host); |
| 1274 EXPECT_EQ(443, alternative_service_info_vector[0].alternative_service.port); | 1284 EXPECT_EQ(443, alternative_service_info_vector[0].alternative_service.port); |
| 1275 EXPECT_DOUBLE_EQ(1.0, alternative_service_info_vector[0].probability); | 1285 EXPECT_DOUBLE_EQ(1.0, alternative_service_info_vector[0].probability); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1342 // Shutdown comes before the task is executed. | 1352 // Shutdown comes before the task is executed. |
| 1343 http_server_props_manager_->ShutdownOnPrefThread(); | 1353 http_server_props_manager_->ShutdownOnPrefThread(); |
| 1344 // Run the task after shutdown, but before deletion. | 1354 // Run the task after shutdown, but before deletion. |
| 1345 base::RunLoop().RunUntilIdle(); | 1355 base::RunLoop().RunUntilIdle(); |
| 1346 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 1356 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 1347 http_server_props_manager_.reset(); | 1357 http_server_props_manager_.reset(); |
| 1348 base::RunLoop().RunUntilIdle(); | 1358 base::RunLoop().RunUntilIdle(); |
| 1349 } | 1359 } |
| 1350 | 1360 |
| 1351 } // namespace net | 1361 } // namespace net |
| OLD | NEW |