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

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

Issue 1878143005: SHP 4: Change AlternativeServiceMap to use SchemeHostPort as the key. No change to Pref data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@SHP_3
Patch Set: fix cronet && SpdyNetworkTransactionUnittests Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/http/http_server_properties_manager.h" 5 #include "net/http/http_server_properties_manager.h"
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "base/test/test_simple_task_runner.h" 15 #include "base/test/test_simple_task_runner.h"
16 #include "base/thread_task_runner_handle.h" 16 #include "base/thread_task_runner_handle.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "net/base/ip_address.h" 18 #include "net/base/ip_address.h"
19 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "url/gurl.h"
21 22
22 namespace net { 23 namespace net {
23 24
24 namespace { 25 namespace {
25 26
26 using base::StringPrintf; 27 using base::StringPrintf;
27 using ::testing::_; 28 using ::testing::_;
28 using ::testing::Invoke; 29 using ::testing::Invoke;
29 using ::testing::Mock; 30 using ::testing::Mock;
30 using ::testing::StrictMock; 31 using ::testing::StrictMock;
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 199
199 void ExpectPrefsUpdateRepeatedly() { 200 void ExpectPrefsUpdateRepeatedly() {
200 EXPECT_CALL(*http_server_props_manager_, 201 EXPECT_CALL(*http_server_props_manager_,
201 UpdatePrefsFromCacheOnNetworkThread(_)) 202 UpdatePrefsFromCacheOnNetworkThread(_))
202 .WillRepeatedly( 203 .WillRepeatedly(
203 Invoke(http_server_props_manager_.get(), 204 Invoke(http_server_props_manager_.get(),
204 &TestingHttpServerPropertiesManager:: 205 &TestingHttpServerPropertiesManager::
205 UpdatePrefsFromCacheOnNetworkThreadConcrete)); 206 UpdatePrefsFromCacheOnNetworkThreadConcrete));
206 } 207 }
207 208
208 bool HasAlternativeService(const HostPortPair& server) { 209 bool HasAlternativeService(const url::SchemeHostPort& server) {
209 const AlternativeServiceVector alternative_service_vector = 210 const AlternativeServiceVector alternative_service_vector =
210 http_server_props_manager_->GetAlternativeServices(server); 211 http_server_props_manager_->GetAlternativeServices(server);
211 return !alternative_service_vector.empty(); 212 return !alternative_service_vector.empty();
212 } 213 }
213 214
214 MockPrefDelegate* pref_delegate_; // Owned by HttpServerPropertiesManager. 215 MockPrefDelegate* pref_delegate_; // Owned by HttpServerPropertiesManager.
215 std::unique_ptr<TestingHttpServerPropertiesManager> 216 std::unique_ptr<TestingHttpServerPropertiesManager>
216 http_server_props_manager_; 217 http_server_props_manager_;
217 base::Time one_day_from_now_; 218 base::Time one_day_from_now_;
218 219
219 private: 220 private:
220 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManagerTest); 221 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManagerTest);
221 }; 222 };
222 223
223 INSTANTIATE_TEST_CASE_P(Tests, 224 INSTANTIATE_TEST_CASE_P(Tests,
224 HttpServerPropertiesManagerTest, 225 HttpServerPropertiesManagerTest,
225 ::testing::ValuesIn(kHttpServerPropertiesVersions)); 226 ::testing::ValuesIn(kHttpServerPropertiesVersions));
226 227
227 TEST_P(HttpServerPropertiesManagerTest, 228 TEST_P(HttpServerPropertiesManagerTest,
228 SingleUpdateForTwoSpdyServerPrefChanges) { 229 SingleUpdateForTwoSpdyServerPrefChanges) {
229 ExpectCacheUpdate(); 230 ExpectCacheUpdate();
230 231
231 // Set up the prefs for www.google.com:80 and mail.google.com:80 and then set 232 // 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. 233 // it twice. Only expect a single cache update.
233 234
234 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; 235 base::DictionaryValue* server_pref_dict = new base::DictionaryValue;
235 HostPortPair google_server("www.google.com", 80);
236 // TODO(zhongyi): change scheme to http once Pref data is also migrated 236 // TODO(zhongyi): change scheme to http once Pref data is also migrated
237 // SchemeHostPort. 237 // SchemeHostPort.
238 url::SchemeHostPort google_scheme_host_port("https", "www.google.com", 80); 238 url::SchemeHostPort google_server("https", "www.google.com", 80);
239 url::SchemeHostPort mail_scheme_host_port("https", "mail.google.com", 80); 239 url::SchemeHostPort mail_server("https", "mail.google.com", 80);
240 HostPortPair mail_server("mail.google.com", 80);
241 240
242 // Set supports_spdy for www.google.com:80. 241 // Set supports_spdy for www.google.com:80.
243 server_pref_dict->SetBoolean("supports_spdy", true); 242 server_pref_dict->SetBoolean("supports_spdy", true);
244 243
245 // Set up alternative_services for www.google.com:80. 244 // Set up alternative_services for www.google.com:80.
246 base::DictionaryValue* alternative_service_dict0 = new base::DictionaryValue; 245 base::DictionaryValue* alternative_service_dict0 = new base::DictionaryValue;
247 alternative_service_dict0->SetInteger("port", 443); 246 alternative_service_dict0->SetInteger("port", 443);
248 alternative_service_dict0->SetString("protocol_str", "npn-h2"); 247 alternative_service_dict0->SetString("protocol_str", "npn-h2");
249 base::DictionaryValue* alternative_service_dict1 = new base::DictionaryValue; 248 base::DictionaryValue* alternative_service_dict1 = new base::DictionaryValue;
250 alternative_service_dict1->SetInteger("port", 1234); 249 alternative_service_dict1->SetInteger("port", 1234);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 quic_servers_dict); 343 quic_servers_dict);
345 344
346 // Set the same value for kHttpServerProperties multiple times. 345 // Set the same value for kHttpServerProperties multiple times.
347 pref_delegate_->SetPrefs(http_server_properties_dict); 346 pref_delegate_->SetPrefs(http_server_properties_dict);
348 pref_delegate_->SetPrefs(http_server_properties_dict); 347 pref_delegate_->SetPrefs(http_server_properties_dict);
349 348
350 base::RunLoop().RunUntilIdle(); 349 base::RunLoop().RunUntilIdle();
351 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 350 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
352 351
353 // Verify SupportsSpdy. 352 // Verify SupportsSpdy.
354 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority( 353 EXPECT_TRUE(
355 google_scheme_host_port)); 354 http_server_props_manager_->SupportsRequestPriority(google_server));
356 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority( 355 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(mail_server));
357 mail_scheme_host_port)); 356 HostPortPair foo_host_port_pair =
358 HostPortPair foo_server = HostPortPair::FromString("foo.google.com:1337"); 357 HostPortPair::FromString("foo.google.com:1337");
359 url::SchemeHostPort foo_scheme_host_port("http", foo_server.host(), 358 url::SchemeHostPort foo_server("http", foo_host_port_pair.host(),
360 foo_server.port()); 359 foo_host_port_pair.port());
361 360
362 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( 361 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority(foo_server));
363 foo_scheme_host_port));
364 362
365 // Verify alternative service. 363 // Verify alternative service.
366 if (GetParam() == 4) { 364 if (GetParam() == 4) {
367 const AlternativeServiceMap& map = 365 const AlternativeServiceMap& map =
368 http_server_props_manager_->alternative_service_map(); 366 http_server_props_manager_->alternative_service_map();
369 ASSERT_EQ(2u, map.size()); 367 ASSERT_EQ(2u, map.size());
370 368
371 AlternativeServiceMap::const_iterator map_it = map.begin(); 369 AlternativeServiceMap::const_iterator map_it = map.begin();
372 EXPECT_EQ("mail.google.com", map_it->first.host()); 370 EXPECT_EQ("mail.google.com", map_it->first.host());
373 ASSERT_EQ(1u, map_it->second.size()); 371 ASSERT_EQ(1u, map_it->second.size());
(...skipping 30 matching lines...) Expand all
404 EXPECT_EQ(444, map_it->second[0].alternative_service.port); 402 EXPECT_EQ(444, map_it->second[0].alternative_service.port);
405 } 403 }
406 404
407 // Verify SupportsQuic. 405 // Verify SupportsQuic.
408 IPAddress last_address; 406 IPAddress last_address;
409 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&last_address)); 407 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&last_address));
410 EXPECT_EQ("127.0.0.1", last_address.ToString()); 408 EXPECT_EQ("127.0.0.1", last_address.ToString());
411 409
412 // Verify ServerNetworkStats. 410 // Verify ServerNetworkStats.
413 const ServerNetworkStats* stats2 = 411 const ServerNetworkStats* stats2 =
414 http_server_props_manager_->GetServerNetworkStats( 412 http_server_props_manager_->GetServerNetworkStats(google_server);
415 google_scheme_host_port);
416 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); 413 EXPECT_EQ(10, stats2->srtt.ToInternalValue());
417 const ServerNetworkStats* stats3 = 414 const ServerNetworkStats* stats3 =
418 http_server_props_manager_->GetServerNetworkStats(mail_scheme_host_port); 415 http_server_props_manager_->GetServerNetworkStats(mail_server);
419 EXPECT_EQ(20, stats3->srtt.ToInternalValue()); 416 EXPECT_EQ(20, stats3->srtt.ToInternalValue());
420 417
421 // Verify QuicServerInfo. 418 // Verify QuicServerInfo.
422 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo( 419 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo(
423 google_quic_server_id)); 420 google_quic_server_id));
424 EXPECT_EQ(quic_server_info2, *http_server_props_manager_->GetQuicServerInfo( 421 EXPECT_EQ(quic_server_info2, *http_server_props_manager_->GetQuicServerInfo(
425 mail_quic_server_id)); 422 mail_quic_server_id));
426 EXPECT_EQ(quic_server_info3, *http_server_props_manager_->GetQuicServerInfo( 423 EXPECT_EQ(quic_server_info3, *http_server_props_manager_->GetQuicServerInfo(
427 play_quic_server_id)); 424 play_quic_server_id));
428 425
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 http_server_properties_dict.SetWithoutPathExpansion("quic_servers", 488 http_server_properties_dict.SetWithoutPathExpansion("quic_servers",
492 quic_servers_dict); 489 quic_servers_dict);
493 490
494 // Set up the pref. 491 // Set up the pref.
495 pref_delegate_->SetPrefs(http_server_properties_dict); 492 pref_delegate_->SetPrefs(http_server_properties_dict);
496 493
497 base::RunLoop().RunUntilIdle(); 494 base::RunLoop().RunUntilIdle();
498 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 495 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
499 496
500 // Verify that nothing is set. 497 // Verify that nothing is set.
501 HostPortPair google_server = HostPortPair::FromString("www.google.com:65536"); 498 HostPortPair google_host_port_pair =
502 url::SchemeHostPort google_scheme_host_port("http", google_server.host(), 499 HostPortPair::FromString("www.google.com:65536");
503 google_server.port()); 500 url::SchemeHostPort gooler_server("http", google_host_port_pair.host(),
501 google_host_port_pair.port());
504 502
505 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority(
506 google_scheme_host_port));
507 EXPECT_FALSE( 503 EXPECT_FALSE(
508 HasAlternativeService(HostPortPair::FromString("www.google.com:65536"))); 504 http_server_props_manager_->SupportsRequestPriority(gooler_server));
505 EXPECT_FALSE(HasAlternativeService(gooler_server));
509 const ServerNetworkStats* stats1 = 506 const ServerNetworkStats* stats1 =
510 http_server_props_manager_->GetServerNetworkStats( 507 http_server_props_manager_->GetServerNetworkStats(gooler_server);
511 google_scheme_host_port);
512 EXPECT_EQ(nullptr, stats1); 508 EXPECT_EQ(nullptr, stats1);
513 EXPECT_EQ(0u, http_server_props_manager_->quic_server_info_map().size()); 509 EXPECT_EQ(0u, http_server_props_manager_->quic_server_info_map().size());
514 } 510 }
515 511
516 TEST_P(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { 512 TEST_P(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) {
517 ExpectCacheUpdate(); 513 ExpectCacheUpdate();
518 // The prefs are automaticalls updated in the case corruption is detected. 514 // The prefs are automaticalls updated in the case corruption is detected.
519 ExpectPrefsUpdate(); 515 ExpectPrefsUpdate();
520 ExpectScheduleUpdatePrefsOnNetworkThread(); 516 ExpectScheduleUpdatePrefsOnNetworkThread();
521 517
(...skipping 30 matching lines...) Expand all
552 } 548 }
553 549
554 // Set up the pref. 550 // Set up the pref.
555 pref_delegate_->SetPrefs(http_server_properties_dict); 551 pref_delegate_->SetPrefs(http_server_properties_dict);
556 552
557 base::RunLoop().RunUntilIdle(); 553 base::RunLoop().RunUntilIdle();
558 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 554 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
559 555
560 // Verify alternative service is not set. 556 // Verify alternative service is not set.
561 EXPECT_FALSE( 557 EXPECT_FALSE(
562 HasAlternativeService(HostPortPair::FromString("www.google.com:80"))); 558 HasAlternativeService(url::SchemeHostPort("http", "www.google.com", 80)));
563 } 559 }
564 560
565 TEST_P(HttpServerPropertiesManagerTest, SupportsSpdy) { 561 TEST_P(HttpServerPropertiesManagerTest, SupportsSpdy) {
566 ExpectPrefsUpdate(); 562 ExpectPrefsUpdate();
567 ExpectScheduleUpdatePrefsOnNetworkThread(); 563 ExpectScheduleUpdatePrefsOnNetworkThread();
568 564
569 // Post an update task to the network thread. SetSupportsSpdy calls 565 // Post an update task to the network thread. SetSupportsSpdy calls
570 // ScheduleUpdatePrefsOnNetworkThread. 566 // ScheduleUpdatePrefsOnNetworkThread.
571 567
572 // Add mail.google.com:443 as a supporting spdy server. 568 // Add mail.google.com:443 as a supporting spdy server.
573 HostPortPair spdy_server_mail("mail.google.com", 443);
574 url::SchemeHostPort spdy_server("https", "mail.google.com", 443); 569 url::SchemeHostPort spdy_server("https", "mail.google.com", 443);
575 EXPECT_FALSE( 570 EXPECT_FALSE(
576 http_server_props_manager_->SupportsRequestPriority(spdy_server)); 571 http_server_props_manager_->SupportsRequestPriority(spdy_server));
577 http_server_props_manager_->SetSupportsSpdy(spdy_server, true); 572 http_server_props_manager_->SetSupportsSpdy(spdy_server, true);
578 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. 573 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once.
579 http_server_props_manager_->SetSupportsSpdy(spdy_server, true); 574 http_server_props_manager_->SetSupportsSpdy(spdy_server, true);
580 575
581 // Run the task. 576 // Run the task.
582 base::RunLoop().RunUntilIdle(); 577 base::RunLoop().RunUntilIdle();
583 578
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 http_server_props_manager_->spdy_settings_map(); 681 http_server_props_manager_->spdy_settings_map();
687 ASSERT_EQ(0U, spdy_settings_map2_ret.size()); 682 ASSERT_EQ(0U, spdy_settings_map2_ret.size());
688 683
689 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 684 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
690 } 685 }
691 686
692 TEST_P(HttpServerPropertiesManagerTest, GetAlternativeServices) { 687 TEST_P(HttpServerPropertiesManagerTest, GetAlternativeServices) {
693 ExpectPrefsUpdate(); 688 ExpectPrefsUpdate();
694 ExpectScheduleUpdatePrefsOnNetworkThread(); 689 ExpectScheduleUpdatePrefsOnNetworkThread();
695 690
696 HostPortPair spdy_server_mail("mail.google.com", 80); 691 url::SchemeHostPort spdy_server_mail("http", "mail.google.com", 80);
697 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); 692 EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
698 const AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 693 const AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com",
699 443); 694 443);
700 http_server_props_manager_->SetAlternativeService( 695 http_server_props_manager_->SetAlternativeService(
701 spdy_server_mail, alternative_service, one_day_from_now_); 696 spdy_server_mail, alternative_service, one_day_from_now_);
702 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. 697 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once.
703 http_server_props_manager_->SetAlternativeService( 698 http_server_props_manager_->SetAlternativeService(
704 spdy_server_mail, alternative_service, one_day_from_now_); 699 spdy_server_mail, alternative_service, one_day_from_now_);
705 700
706 // Run the task. 701 // Run the task.
707 base::RunLoop().RunUntilIdle(); 702 base::RunLoop().RunUntilIdle();
708 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 703 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
709 704
710 AlternativeServiceVector alternative_service_vector = 705 AlternativeServiceVector alternative_service_vector =
711 http_server_props_manager_->GetAlternativeServices(spdy_server_mail); 706 http_server_props_manager_->GetAlternativeServices(spdy_server_mail);
712 ASSERT_EQ(1u, alternative_service_vector.size()); 707 ASSERT_EQ(1u, alternative_service_vector.size());
713 EXPECT_EQ(alternative_service, alternative_service_vector[0]); 708 EXPECT_EQ(alternative_service, alternative_service_vector[0]);
714 } 709 }
715 710
716 TEST_P(HttpServerPropertiesManagerTest, SetAlternativeServices) { 711 TEST_P(HttpServerPropertiesManagerTest, SetAlternativeServices) {
717 ExpectPrefsUpdate(); 712 ExpectPrefsUpdate();
718 ExpectScheduleUpdatePrefsOnNetworkThread(); 713 ExpectScheduleUpdatePrefsOnNetworkThread();
719 714
720 HostPortPair spdy_server_mail("mail.google.com", 80); 715 url::SchemeHostPort spdy_server_mail("http", "mail.google.com", 80);
721 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); 716 EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
722 AlternativeServiceInfoVector alternative_service_info_vector; 717 AlternativeServiceInfoVector alternative_service_info_vector;
723 const AlternativeService alternative_service1(NPN_HTTP_2, "mail.google.com", 718 const AlternativeService alternative_service1(NPN_HTTP_2, "mail.google.com",
724 443); 719 443);
725 alternative_service_info_vector.push_back( 720 alternative_service_info_vector.push_back(
726 AlternativeServiceInfo(alternative_service1, one_day_from_now_)); 721 AlternativeServiceInfo(alternative_service1, one_day_from_now_));
727 const AlternativeService alternative_service2(QUIC, "mail.google.com", 1234); 722 const AlternativeService alternative_service2(QUIC, "mail.google.com", 1234);
728 alternative_service_info_vector.push_back( 723 alternative_service_info_vector.push_back(
729 AlternativeServiceInfo(alternative_service2, one_day_from_now_)); 724 AlternativeServiceInfo(alternative_service2, one_day_from_now_));
730 http_server_props_manager_->SetAlternativeServices( 725 http_server_props_manager_->SetAlternativeServices(
731 spdy_server_mail, alternative_service_info_vector); 726 spdy_server_mail, alternative_service_info_vector);
732 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. 727 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once.
733 http_server_props_manager_->SetAlternativeServices( 728 http_server_props_manager_->SetAlternativeServices(
734 spdy_server_mail, alternative_service_info_vector); 729 spdy_server_mail, alternative_service_info_vector);
735 730
736 // Run the task. 731 // Run the task.
737 base::RunLoop().RunUntilIdle(); 732 base::RunLoop().RunUntilIdle();
738 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 733 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
739 734
740 AlternativeServiceVector alternative_service_vector = 735 AlternativeServiceVector alternative_service_vector =
741 http_server_props_manager_->GetAlternativeServices(spdy_server_mail); 736 http_server_props_manager_->GetAlternativeServices(spdy_server_mail);
742 ASSERT_EQ(2u, alternative_service_vector.size()); 737 ASSERT_EQ(2u, alternative_service_vector.size());
743 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); 738 EXPECT_EQ(alternative_service1, alternative_service_vector[0]);
744 EXPECT_EQ(alternative_service2, alternative_service_vector[1]); 739 EXPECT_EQ(alternative_service2, alternative_service_vector[1]);
745 } 740 }
746 741
747 TEST_P(HttpServerPropertiesManagerTest, SetAlternativeServicesEmpty) { 742 TEST_P(HttpServerPropertiesManagerTest, SetAlternativeServicesEmpty) {
748 HostPortPair spdy_server_mail("mail.google.com", 80); 743 url::SchemeHostPort spdy_server_mail("http", "mail.google.com", 80);
749 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); 744 EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
750 const AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 745 const AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com",
751 443); 746 443);
752 http_server_props_manager_->SetAlternativeServices( 747 http_server_props_manager_->SetAlternativeServices(
753 spdy_server_mail, AlternativeServiceInfoVector()); 748 spdy_server_mail, AlternativeServiceInfoVector());
754 // ExpectScheduleUpdatePrefsOnNetworkThread() should not be called. 749 // ExpectScheduleUpdatePrefsOnNetworkThread() should not be called.
755 750
756 // Run the task. 751 // Run the task.
757 base::RunLoop().RunUntilIdle(); 752 base::RunLoop().RunUntilIdle();
758 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 753 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
759 754
760 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); 755 EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
761 } 756 }
762 757
763 TEST_P(HttpServerPropertiesManagerTest, ClearAlternativeServices) { 758 TEST_P(HttpServerPropertiesManagerTest, ClearAlternativeServices) {
764 ExpectPrefsUpdate(); 759 ExpectPrefsUpdate();
765 ExpectScheduleUpdatePrefsOnNetworkThread(); 760 ExpectScheduleUpdatePrefsOnNetworkThread();
766 761
767 HostPortPair spdy_server_mail("mail.google.com", 80); 762 url::SchemeHostPort spdy_server_mail("http", "mail.google.com", 80);
768 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); 763 EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
769 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 443); 764 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 443);
770 http_server_props_manager_->SetAlternativeService( 765 http_server_props_manager_->SetAlternativeService(
771 spdy_server_mail, alternative_service, one_day_from_now_); 766 spdy_server_mail, alternative_service, one_day_from_now_);
772 ExpectScheduleUpdatePrefsOnNetworkThread(); 767 ExpectScheduleUpdatePrefsOnNetworkThread();
773 http_server_props_manager_->ClearAlternativeServices(spdy_server_mail); 768 http_server_props_manager_->ClearAlternativeServices(spdy_server_mail);
774 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. 769 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once.
775 http_server_props_manager_->ClearAlternativeServices(spdy_server_mail); 770 http_server_props_manager_->ClearAlternativeServices(spdy_server_mail);
776 771
777 // Run the task. 772 // Run the task.
778 base::RunLoop().RunUntilIdle(); 773 base::RunLoop().RunUntilIdle();
779 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 774 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
780 775
781 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); 776 EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
782 } 777 }
783 778
784 TEST_P(HttpServerPropertiesManagerTest, ConfirmAlternativeService) { 779 TEST_P(HttpServerPropertiesManagerTest, ConfirmAlternativeService) {
785 ExpectPrefsUpdate(); 780 ExpectPrefsUpdate();
786 781
787 HostPortPair spdy_server_mail("mail.google.com", 80); 782 url::SchemeHostPort spdy_server_mail("http", "mail.google.com", 80);
788 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); 783 EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
789 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 443); 784 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 443);
790 785
791 ExpectScheduleUpdatePrefsOnNetworkThread(); 786 ExpectScheduleUpdatePrefsOnNetworkThread();
792 http_server_props_manager_->SetAlternativeService( 787 http_server_props_manager_->SetAlternativeService(
793 spdy_server_mail, alternative_service, one_day_from_now_); 788 spdy_server_mail, alternative_service, one_day_from_now_);
794 789
795 EXPECT_FALSE(http_server_props_manager_->IsAlternativeServiceBroken( 790 EXPECT_FALSE(http_server_props_manager_->IsAlternativeServiceBroken(
796 alternative_service)); 791 alternative_service));
797 EXPECT_FALSE(http_server_props_manager_->WasAlternativeServiceRecentlyBroken( 792 EXPECT_FALSE(http_server_props_manager_->WasAlternativeServiceRecentlyBroken(
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 884 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
890 885
891 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo( 886 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo(
892 mail_quic_server_id)); 887 mail_quic_server_id));
893 } 888 }
894 889
895 TEST_P(HttpServerPropertiesManagerTest, Clear) { 890 TEST_P(HttpServerPropertiesManagerTest, Clear) {
896 ExpectPrefsUpdate(); 891 ExpectPrefsUpdate();
897 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); 892 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly();
898 893
899 HostPortPair spdy_server_mail("mail.google.com", 443);
900 url::SchemeHostPort spdy_server("https", "mail.google.com", 443); 894 url::SchemeHostPort spdy_server("https", "mail.google.com", 443);
901 http_server_props_manager_->SetSupportsSpdy(spdy_server, true); 895 http_server_props_manager_->SetSupportsSpdy(spdy_server, true);
902 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 1234); 896 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 1234);
903 http_server_props_manager_->SetAlternativeService( 897 http_server_props_manager_->SetAlternativeService(
904 spdy_server_mail, alternative_service, one_day_from_now_); 898 spdy_server, alternative_service, one_day_from_now_);
905 IPAddress actual_address(127, 0, 0, 1); 899 IPAddress actual_address(127, 0, 0, 1);
906 http_server_props_manager_->SetSupportsQuic(true, actual_address); 900 http_server_props_manager_->SetSupportsQuic(true, actual_address);
907 ServerNetworkStats stats; 901 ServerNetworkStats stats;
908 stats.srtt = base::TimeDelta::FromMicroseconds(10); 902 stats.srtt = base::TimeDelta::FromMicroseconds(10);
909 http_server_props_manager_->SetServerNetworkStats(spdy_server, stats); 903 http_server_props_manager_->SetServerNetworkStats(spdy_server, stats);
910 904
911 QuicServerId mail_quic_server_id("mail.google.com", 80); 905 QuicServerId mail_quic_server_id("mail.google.com", 80);
912 std::string quic_server_info1("quic_server_info1"); 906 std::string quic_server_info1("quic_server_info1");
913 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id, 907 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id,
914 quic_server_info1); 908 quic_server_info1);
915 909
916 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; 910 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH;
917 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; 911 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST;
918 const uint32_t value1 = 31337; 912 const uint32_t value1 = 31337;
919 http_server_props_manager_->SetSpdySetting(spdy_server, id1, flags1, value1); 913 http_server_props_manager_->SetSpdySetting(spdy_server, id1, flags1, value1);
920 914
921 // Run the task. 915 // Run the task.
922 base::RunLoop().RunUntilIdle(); 916 base::RunLoop().RunUntilIdle();
923 917
924 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(spdy_server)); 918 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(spdy_server));
925 EXPECT_TRUE(HasAlternativeService(spdy_server_mail)); 919 EXPECT_TRUE(HasAlternativeService(spdy_server));
926 IPAddress address; 920 IPAddress address;
927 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); 921 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address));
928 EXPECT_EQ(actual_address, address); 922 EXPECT_EQ(actual_address, address);
929 const ServerNetworkStats* stats1 = 923 const ServerNetworkStats* stats1 =
930 http_server_props_manager_->GetServerNetworkStats(spdy_server); 924 http_server_props_manager_->GetServerNetworkStats(spdy_server);
931 EXPECT_EQ(10, stats1->srtt.ToInternalValue()); 925 EXPECT_EQ(10, stats1->srtt.ToInternalValue());
932 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo( 926 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo(
933 mail_quic_server_id)); 927 mail_quic_server_id));
934 928
935 // Check SPDY settings values. 929 // Check SPDY settings values.
936 const SettingsMap& settings_map1_ret = 930 const SettingsMap& settings_map1_ret =
937 http_server_props_manager_->GetSpdySettings(spdy_server); 931 http_server_props_manager_->GetSpdySettings(spdy_server);
938 ASSERT_EQ(1U, settings_map1_ret.size()); 932 ASSERT_EQ(1U, settings_map1_ret.size());
939 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); 933 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1);
940 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); 934 EXPECT_TRUE(it1_ret != settings_map1_ret.end());
941 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; 935 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second;
942 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); 936 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first);
943 EXPECT_EQ(value1, flags_and_value1_ret.second); 937 EXPECT_EQ(value1, flags_and_value1_ret.second);
944 938
945 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 939 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
946 940
947 ExpectPrefsUpdate(); 941 ExpectPrefsUpdate();
948 942
949 // Clear http server data, time out if we do not get a completion callback. 943 // Clear http server data, time out if we do not get a completion callback.
950 http_server_props_manager_->Clear(base::MessageLoop::QuitWhenIdleClosure()); 944 http_server_props_manager_->Clear(base::MessageLoop::QuitWhenIdleClosure());
951 base::RunLoop().Run(); 945 base::RunLoop().Run();
952 946
953 EXPECT_FALSE( 947 EXPECT_FALSE(
954 http_server_props_manager_->SupportsRequestPriority(spdy_server)); 948 http_server_props_manager_->SupportsRequestPriority(spdy_server));
955 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); 949 EXPECT_FALSE(HasAlternativeService(spdy_server));
956 EXPECT_FALSE(http_server_props_manager_->GetSupportsQuic(&address)); 950 EXPECT_FALSE(http_server_props_manager_->GetSupportsQuic(&address));
957 const ServerNetworkStats* stats2 = 951 const ServerNetworkStats* stats2 =
958 http_server_props_manager_->GetServerNetworkStats(spdy_server); 952 http_server_props_manager_->GetServerNetworkStats(spdy_server);
959 EXPECT_EQ(nullptr, stats2); 953 EXPECT_EQ(nullptr, stats2);
960 EXPECT_EQ(nullptr, 954 EXPECT_EQ(nullptr,
961 http_server_props_manager_->GetQuicServerInfo(mail_quic_server_id)); 955 http_server_props_manager_->GetQuicServerInfo(mail_quic_server_id));
962 956
963 const SettingsMap& settings_map2_ret = 957 const SettingsMap& settings_map2_ret =
964 http_server_props_manager_->GetSpdySettings(spdy_server); 958 http_server_props_manager_->GetSpdySettings(spdy_server);
965 EXPECT_EQ(0U, settings_map2_ret.size()); 959 EXPECT_EQ(0U, settings_map2_ret.size());
966 960
967 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 961 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
968 } 962 }
969 963
970 // https://crbug.com/444956: Add 200 alternative_service servers followed by 964 // https://crbug.com/444956: Add 200 alternative_service servers followed by
971 // supports_quic and verify we have read supports_quic from prefs. 965 // supports_quic and verify we have read supports_quic from prefs.
972 TEST_P(HttpServerPropertiesManagerTest, BadSupportsQuic) { 966 TEST_P(HttpServerPropertiesManagerTest, BadSupportsQuic) {
973 ExpectCacheUpdate(); 967 ExpectCacheUpdate();
974 968
975 base::DictionaryValue* servers_dict = new base::DictionaryValue; 969 base::DictionaryValue* servers_dict = new base::DictionaryValue;
976 base::ListValue* servers_list = nullptr; 970 base::ListValue* servers_list = nullptr;
977 if (GetParam() == 4) 971 if (GetParam() == 4)
978 servers_list = new base::ListValue; 972 servers_list = new base::ListValue;
979 973
980 for (int i = 0; i < 200; ++i) { 974 for (int i = 1; i <= 200; ++i) {
981 // Set up alternative_service for www.google.com:i. 975 // Set up alternative_service for www.google.com:i.
982 base::DictionaryValue* alternative_service_dict = new base::DictionaryValue; 976 base::DictionaryValue* alternative_service_dict = new base::DictionaryValue;
983 alternative_service_dict->SetString("protocol_str", "quic"); 977 alternative_service_dict->SetString("protocol_str", "quic");
984 alternative_service_dict->SetInteger("port", i); 978 alternative_service_dict->SetInteger("port", i);
985 base::ListValue* alternative_service_list = new base::ListValue; 979 base::ListValue* alternative_service_list = new base::ListValue;
986 alternative_service_list->Append(alternative_service_dict); 980 alternative_service_list->Append(alternative_service_dict);
987 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; 981 base::DictionaryValue* server_pref_dict = new base::DictionaryValue;
988 server_pref_dict->SetWithoutPathExpansion("alternative_service", 982 server_pref_dict->SetWithoutPathExpansion("alternative_service",
989 alternative_service_list); 983 alternative_service_list);
990 if (GetParam() == 4) { 984 if (GetParam() == 4) {
985 // TODO(zhongyi): add scheme once disc data is migrated.
991 servers_dict->SetWithoutPathExpansion( 986 servers_dict->SetWithoutPathExpansion(
992 StringPrintf("www.google.com:%d", i), server_pref_dict); 987 StringPrintf("www.google.com:%d", i), server_pref_dict);
993 // |servers_list| takes ownership of |servers_dict|. 988 // |servers_list| takes ownership of |servers_dict|.
994 servers_list->AppendIfNotPresent(servers_dict); 989 servers_list->AppendIfNotPresent(servers_dict);
995 servers_dict = new base::DictionaryValue; 990 servers_dict = new base::DictionaryValue;
996 } else { 991 } else {
992 // TODO(zhongyi): add scheme once disc data is migrated.
997 servers_dict->SetWithoutPathExpansion( 993 servers_dict->SetWithoutPathExpansion(
998 StringPrintf("www.google.com:%d", i), server_pref_dict); 994 StringPrintf("www.google.com:%d", i), server_pref_dict);
999 } 995 }
1000 } 996 }
1001 997
1002 // Set the preference for mail.google.com server. 998 // Set the preference for mail.google.com server.
1003 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; 999 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue;
1004 1000
1005 // Set the server preference for mail.google.com:80. 1001 // Set the server preference for mail.google.com:80.
1002 // TODO(zhongyi): add scheme once disc data is migrated.
1006 servers_dict->SetWithoutPathExpansion("mail.google.com:80", 1003 servers_dict->SetWithoutPathExpansion("mail.google.com:80",
1007 server_pref_dict1); 1004 server_pref_dict1);
1008 base::DictionaryValue http_server_properties_dict; 1005 base::DictionaryValue http_server_properties_dict;
1009 if (GetParam() == 4) { 1006 if (GetParam() == 4) {
1010 // |servers_list| takes ownership of |servers_dict|. 1007 // |servers_list| takes ownership of |servers_dict|.
1011 servers_list->AppendIfNotPresent(servers_dict); 1008 servers_list->AppendIfNotPresent(servers_dict);
1012 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1); 1009 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1);
1013 http_server_properties_dict.SetWithoutPathExpansion("servers", 1010 http_server_properties_dict.SetWithoutPathExpansion("servers",
1014 servers_list); 1011 servers_list);
1015 } else { 1012 } else {
(...skipping 10 matching lines...) Expand all
1026 http_server_properties_dict.SetWithoutPathExpansion("supports_quic", 1023 http_server_properties_dict.SetWithoutPathExpansion("supports_quic",
1027 supports_quic); 1024 supports_quic);
1028 1025
1029 // Set up the pref. 1026 // Set up the pref.
1030 pref_delegate_->SetPrefs(http_server_properties_dict); 1027 pref_delegate_->SetPrefs(http_server_properties_dict);
1031 1028
1032 base::RunLoop().RunUntilIdle(); 1029 base::RunLoop().RunUntilIdle();
1033 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 1030 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
1034 1031
1035 // Verify alternative service. 1032 // Verify alternative service.
1036 for (int i = 0; i < 200; ++i) { 1033 for (int i = 1; i <= 200; ++i) {
1037 std::string server = StringPrintf("www.google.com:%d", i); 1034 // TODO(zhongyi): remove hardcoded scheme once disc data is migrated.
1035 GURL server_gurl(StringPrintf("https://www.google.com:%d", i));
1036 url::SchemeHostPort server(server_gurl);
1038 AlternativeServiceVector alternative_service_vector = 1037 AlternativeServiceVector alternative_service_vector =
1039 http_server_props_manager_->GetAlternativeServices( 1038 http_server_props_manager_->GetAlternativeServices(server);
1040 HostPortPair::FromString(server));
1041 ASSERT_EQ(1u, alternative_service_vector.size()); 1039 ASSERT_EQ(1u, alternative_service_vector.size());
1042 EXPECT_EQ(QUIC, alternative_service_vector[0].protocol); 1040 EXPECT_EQ(QUIC, alternative_service_vector[0].protocol);
1043 EXPECT_EQ(i, alternative_service_vector[0].port); 1041 EXPECT_EQ(i, alternative_service_vector[0].port);
1044 } 1042 }
1045 1043
1046 // Verify SupportsQuic. 1044 // Verify SupportsQuic.
1047 IPAddress address; 1045 IPAddress address;
1048 ASSERT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); 1046 ASSERT_TRUE(http_server_props_manager_->GetSupportsQuic(&address));
1049 EXPECT_EQ("127.0.0.1", address.ToString()); 1047 EXPECT_EQ("127.0.0.1", address.ToString());
1050 } 1048 }
1051 1049
1052 TEST_P(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) { 1050 TEST_P(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) {
1053 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); 1051 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly();
1054 1052
1055 const HostPortPair server_www("www.google.com", 80); 1053 const url::SchemeHostPort server_www("http", "www.google.com", 80);
1056 const url::SchemeHostPort server_mail("http", "mail.google.com", 80); 1054 const url::SchemeHostPort server_mail("http", "mail.google.com", 80);
1057 1055
1058 // Set alternate protocol. 1056 // Set alternate protocol.
1059 AlternativeServiceInfoVector alternative_service_info_vector; 1057 AlternativeServiceInfoVector alternative_service_info_vector;
1060 AlternativeService www_alternative_service1(NPN_HTTP_2, "", 443); 1058 AlternativeService www_alternative_service1(NPN_HTTP_2, "", 443);
1061 base::Time expiration1; 1059 base::Time expiration1;
1062 ASSERT_TRUE(base::Time::FromUTCString("2036-12-01 10:00:00", &expiration1)); 1060 ASSERT_TRUE(base::Time::FromUTCString("2036-12-01 10:00:00", &expiration1));
1063 alternative_service_info_vector.push_back( 1061 alternative_service_info_vector.push_back(
1064 AlternativeServiceInfo(www_alternative_service1, expiration1)); 1062 AlternativeServiceInfo(www_alternative_service1, expiration1));
1065 AlternativeService www_alternative_service2(NPN_HTTP_2, "www.google.com", 1063 AlternativeService www_alternative_service2(NPN_HTTP_2, "www.google.com",
1066 1234); 1064 1234);
1067 base::Time expiration2; 1065 base::Time expiration2;
1068 ASSERT_TRUE(base::Time::FromUTCString("2036-12-31 10:00:00", &expiration2)); 1066 ASSERT_TRUE(base::Time::FromUTCString("2036-12-31 10:00:00", &expiration2));
1069 alternative_service_info_vector.push_back( 1067 alternative_service_info_vector.push_back(
1070 AlternativeServiceInfo(www_alternative_service2, expiration2)); 1068 AlternativeServiceInfo(www_alternative_service2, expiration2));
1071 http_server_props_manager_->SetAlternativeServices( 1069 http_server_props_manager_->SetAlternativeServices(
1072 server_www, alternative_service_info_vector); 1070 server_www, alternative_service_info_vector);
1073 1071
1074 AlternativeService mail_alternative_service(NPN_SPDY_3_1, "foo.google.com", 1072 AlternativeService mail_alternative_service(NPN_SPDY_3_1, "foo.google.com",
1075 444); 1073 444);
1076 base::Time expiration3 = base::Time::Max(); 1074 base::Time expiration3 = base::Time::Max();
1077 http_server_props_manager_->SetAlternativeService( 1075 http_server_props_manager_->SetAlternativeService(
1078 HostPortPair(server_mail.host(), server_mail.port()), 1076 server_mail, mail_alternative_service, expiration3);
1079 mail_alternative_service, expiration3);
1080 1077
1081 // Set ServerNetworkStats. 1078 // Set ServerNetworkStats.
1082 ServerNetworkStats stats; 1079 ServerNetworkStats stats;
1083 stats.srtt = base::TimeDelta::FromInternalValue(42); 1080 stats.srtt = base::TimeDelta::FromInternalValue(42);
1084 http_server_props_manager_->SetServerNetworkStats(server_mail, stats); 1081 http_server_props_manager_->SetServerNetworkStats(server_mail, stats);
1085 1082
1086 // Set quic_server_info string. 1083 // Set quic_server_info string.
1087 QuicServerId mail_quic_server_id("mail.google.com", 80); 1084 QuicServerId mail_quic_server_id("mail.google.com", 80);
1088 std::string quic_server_info1("quic_server_info1"); 1085 std::string quic_server_info1("quic_server_info1");
1089 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id, 1086 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 std::unique_ptr<base::Value> server_value = base::JSONReader::Read( 1126 std::unique_ptr<base::Value> server_value = base::JSONReader::Read(
1130 "{\"alternative_service\":[{\"port\":443,\"protocol_str\":\"npn-h2\"}," 1127 "{\"alternative_service\":[{\"port\":443,\"protocol_str\":\"npn-h2\"},"
1131 "{\"port\":123,\"protocol_str\":\"quic\"," 1128 "{\"port\":123,\"protocol_str\":\"quic\","
1132 "\"expiration\":\"9223372036854775807\"},{\"host\":\"example.org\"," 1129 "\"expiration\":\"9223372036854775807\"},{\"host\":\"example.org\","
1133 "\"port\":1234,\"protocol_str\":\"npn-h2\"," 1130 "\"port\":1234,\"protocol_str\":\"npn-h2\","
1134 "\"expiration\":\"13758804000000000\"}]}"); 1131 "\"expiration\":\"13758804000000000\"}]}");
1135 ASSERT_TRUE(server_value); 1132 ASSERT_TRUE(server_value);
1136 base::DictionaryValue* server_dict; 1133 base::DictionaryValue* server_dict;
1137 ASSERT_TRUE(server_value->GetAsDictionary(&server_dict)); 1134 ASSERT_TRUE(server_value->GetAsDictionary(&server_dict));
1138 1135
1139 const HostPortPair host_port_pair("example.com", 443); 1136 const url::SchemeHostPort server("https", "example.com", 443);
1140 AlternativeServiceMap alternative_service_map(/*max_size=*/5); 1137 AlternativeServiceMap alternative_service_map(/*max_size=*/5);
1141 EXPECT_TRUE(http_server_props_manager_->AddToAlternativeServiceMap( 1138 EXPECT_TRUE(http_server_props_manager_->AddToAlternativeServiceMap(
1142 host_port_pair, *server_dict, &alternative_service_map)); 1139 server, *server_dict, &alternative_service_map));
1143 1140
1144 AlternativeServiceMap::iterator it = 1141 AlternativeServiceMap::iterator it = alternative_service_map.Get(server);
1145 alternative_service_map.Get(host_port_pair);
1146 ASSERT_NE(alternative_service_map.end(), it); 1142 ASSERT_NE(alternative_service_map.end(), it);
1147 AlternativeServiceInfoVector alternative_service_info_vector = it->second; 1143 AlternativeServiceInfoVector alternative_service_info_vector = it->second;
1148 ASSERT_EQ(3u, alternative_service_info_vector.size()); 1144 ASSERT_EQ(3u, alternative_service_info_vector.size());
1149 1145
1150 EXPECT_EQ(NPN_HTTP_2, 1146 EXPECT_EQ(NPN_HTTP_2,
1151 alternative_service_info_vector[0].alternative_service.protocol); 1147 alternative_service_info_vector[0].alternative_service.protocol);
1152 EXPECT_EQ("", alternative_service_info_vector[0].alternative_service.host); 1148 EXPECT_EQ("", alternative_service_info_vector[0].alternative_service.host);
1153 EXPECT_EQ(443, alternative_service_info_vector[0].alternative_service.port); 1149 EXPECT_EQ(443, alternative_service_info_vector[0].alternative_service.port);
1154 // Expiration defaults to one day from now, testing with tolerance. 1150 // Expiration defaults to one day from now, testing with tolerance.
1155 const base::Time now = base::Time::Now(); 1151 const base::Time now = base::Time::Now();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1196 const base::Time time_one_day_ago = 1192 const base::Time time_one_day_ago =
1197 base::Time::Now() - base::TimeDelta::FromDays(1); 1193 base::Time::Now() - base::TimeDelta::FromDays(1);
1198 alternative_service_info_vector.push_back( 1194 alternative_service_info_vector.push_back(
1199 AlternativeServiceInfo(expired_alternative_service, time_one_day_ago)); 1195 AlternativeServiceInfo(expired_alternative_service, time_one_day_ago));
1200 1196
1201 const AlternativeService valid_alternative_service(NPN_HTTP_2, 1197 const AlternativeService valid_alternative_service(NPN_HTTP_2,
1202 "valid.example.com", 443); 1198 "valid.example.com", 443);
1203 alternative_service_info_vector.push_back( 1199 alternative_service_info_vector.push_back(
1204 AlternativeServiceInfo(valid_alternative_service, time_one_day_later)); 1200 AlternativeServiceInfo(valid_alternative_service, time_one_day_later));
1205 1201
1206 const HostPortPair host_port_pair("www.example.com", 443); 1202 const url::SchemeHostPort server("https", "www.example.com", 443);
1207 http_server_props_manager_->SetAlternativeServices( 1203 http_server_props_manager_->SetAlternativeServices(
1208 host_port_pair, alternative_service_info_vector); 1204 server, alternative_service_info_vector);
1209 1205
1210 // Update cache. 1206 // Update cache.
1211 ExpectPrefsUpdate(); 1207 ExpectPrefsUpdate();
1212 ExpectCacheUpdate(); 1208 ExpectCacheUpdate();
1213 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); 1209 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread();
1214 base::RunLoop().RunUntilIdle(); 1210 base::RunLoop().RunUntilIdle();
1215 1211
1216 const base::DictionaryValue& pref_dict = 1212 const base::DictionaryValue& pref_dict =
1217 pref_delegate_->GetServerProperties(); 1213 pref_delegate_->GetServerProperties();
1218 1214
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1258 valid_dict->SetString("host", "valid.example.com"); 1254 valid_dict->SetString("host", "valid.example.com");
1259 valid_dict->SetInteger("port", 443); 1255 valid_dict->SetInteger("port", 443);
1260 valid_dict->SetString( 1256 valid_dict->SetString(
1261 "expiration", base::Int64ToString(one_day_from_now_.ToInternalValue())); 1257 "expiration", base::Int64ToString(one_day_from_now_.ToInternalValue()));
1262 alternative_service_list->Append(valid_dict); 1258 alternative_service_list->Append(valid_dict);
1263 1259
1264 base::DictionaryValue server_pref_dict; 1260 base::DictionaryValue server_pref_dict;
1265 server_pref_dict.SetWithoutPathExpansion("alternative_service", 1261 server_pref_dict.SetWithoutPathExpansion("alternative_service",
1266 alternative_service_list.release()); 1262 alternative_service_list.release());
1267 1263
1268 const HostPortPair host_port_pair("example.com", 443); 1264 const url::SchemeHostPort server("https", "example.com", 443);
1269 AlternativeServiceMap alternative_service_map(/*max_size=*/5); 1265 AlternativeServiceMap alternative_service_map(/*max_size=*/5);
1270 ASSERT_TRUE(http_server_props_manager_->AddToAlternativeServiceMap( 1266 ASSERT_TRUE(http_server_props_manager_->AddToAlternativeServiceMap(
1271 host_port_pair, server_pref_dict, &alternative_service_map)); 1267 server, server_pref_dict, &alternative_service_map));
1272 1268
1273 AlternativeServiceMap::iterator it = 1269 AlternativeServiceMap::iterator it = alternative_service_map.Get(server);
1274 alternative_service_map.Get(host_port_pair);
1275 ASSERT_NE(alternative_service_map.end(), it); 1270 ASSERT_NE(alternative_service_map.end(), it);
1276 AlternativeServiceInfoVector alternative_service_info_vector = it->second; 1271 AlternativeServiceInfoVector alternative_service_info_vector = it->second;
1277 ASSERT_EQ(1u, alternative_service_info_vector.size()); 1272 ASSERT_EQ(1u, alternative_service_info_vector.size());
1278 1273
1279 EXPECT_EQ(NPN_HTTP_2, 1274 EXPECT_EQ(NPN_HTTP_2,
1280 alternative_service_info_vector[0].alternative_service.protocol); 1275 alternative_service_info_vector[0].alternative_service.protocol);
1281 EXPECT_EQ("valid.example.com", 1276 EXPECT_EQ("valid.example.com",
1282 alternative_service_info_vector[0].alternative_service.host); 1277 alternative_service_info_vector[0].alternative_service.host);
1283 EXPECT_EQ(443, alternative_service_info_vector[0].alternative_service.port); 1278 EXPECT_EQ(443, alternative_service_info_vector[0].alternative_service.port);
1284 EXPECT_EQ(one_day_from_now_, alternative_service_info_vector[0].expiration); 1279 EXPECT_EQ(one_day_from_now_, alternative_service_info_vector[0].expiration);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1350 // Shutdown comes before the task is executed. 1345 // Shutdown comes before the task is executed.
1351 http_server_props_manager_->ShutdownOnPrefThread(); 1346 http_server_props_manager_->ShutdownOnPrefThread();
1352 // Run the task after shutdown, but before deletion. 1347 // Run the task after shutdown, but before deletion.
1353 base::RunLoop().RunUntilIdle(); 1348 base::RunLoop().RunUntilIdle();
1354 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 1349 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
1355 http_server_props_manager_.reset(); 1350 http_server_props_manager_.reset();
1356 base::RunLoop().RunUntilIdle(); 1351 base::RunLoop().RunUntilIdle();
1357 } 1352 }
1358 1353
1359 } // namespace net 1354 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698