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

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

Powered by Google App Engine
This is Rietveld 408576698