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