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

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

Issue 2563273002: Change the net_task_runner to use a TestMockTimeTaskRunner in unittests so that (Closed)
Patch Set: address rch's comments Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/http/http_server_properties_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/http/http_server_properties_manager.h" 5 #include "net/http/http_server_properties_manager.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
11 #include "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
17 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
19 #include "base/test/test_mock_time_task_runner.h"
19 #include "base/test/test_simple_task_runner.h" 20 #include "base/test/test_simple_task_runner.h"
20 #include "base/threading/thread_task_runner_handle.h" 21 #include "base/threading/thread_task_runner_handle.h"
21 #include "base/values.h" 22 #include "base/values.h"
22 #include "net/base/ip_address.h" 23 #include "net/base/ip_address.h"
23 #include "testing/gmock/include/gmock/gmock.h" 24 #include "testing/gmock/include/gmock/gmock.h"
24 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
25 #include "url/gurl.h" 26 #include "url/gurl.h"
26 27
27 namespace net { 28 namespace net {
28 29
29 namespace { 30 namespace {
30 31
31 using base::StringPrintf; 32 using base::StringPrintf;
33 using base::TestMockTimeTaskRunner;
32 using ::testing::_; 34 using ::testing::_;
33 using ::testing::Invoke; 35 using ::testing::Invoke;
34 using ::testing::Mock; 36 using ::testing::Mock;
35 using ::testing::StrictMock; 37 using ::testing::StrictMock;
36 38
37 class MockPrefDelegate : public net::HttpServerPropertiesManager::PrefDelegate { 39 class MockPrefDelegate : public net::HttpServerPropertiesManager::PrefDelegate {
38 public: 40 public:
39 MockPrefDelegate() {} 41 MockPrefDelegate() {}
40 ~MockPrefDelegate() override {} 42 ~MockPrefDelegate() override {}
41 43
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 }; 144 };
143 145
144 } // namespace 146 } // namespace
145 147
146 // TODO(rtenneti): After we stop supporting version 3 and everyone has migrated 148 // TODO(rtenneti): After we stop supporting version 3 and everyone has migrated
147 // to version 4, delete the following code. 149 // to version 4, delete the following code.
148 static const int kHttpServerPropertiesVersions[] = {3, 4, 5}; 150 static const int kHttpServerPropertiesVersions[] = {3, 4, 5};
149 151
150 class HttpServerPropertiesManagerTest : public testing::TestWithParam<int> { 152 class HttpServerPropertiesManagerTest : public testing::TestWithParam<int> {
151 protected: 153 protected:
152 HttpServerPropertiesManagerTest() {} 154 HttpServerPropertiesManagerTest()
155 : net_test_task_runner_(new TestMockTimeTaskRunner()) {}
153 156
154 void SetUp() override { 157 void SetUp() override {
155 one_day_from_now_ = base::Time::Now() + base::TimeDelta::FromDays(1); 158 one_day_from_now_ = base::Time::Now() + base::TimeDelta::FromDays(1);
156 pref_delegate_ = new MockPrefDelegate; 159 pref_delegate_ = new MockPrefDelegate;
157 http_server_props_manager_.reset( 160 http_server_props_manager_.reset(
158 new StrictMock<TestingHttpServerPropertiesManager>( 161 new StrictMock<TestingHttpServerPropertiesManager>(
159 pref_delegate_, base::ThreadTaskRunnerHandle::Get())); 162 pref_delegate_, net_test_task_runner_));
163
160 ExpectCacheUpdate(); 164 ExpectCacheUpdate();
161 base::RunLoop().RunUntilIdle(); 165 base::RunLoop().RunUntilIdle();
162 } 166 }
163 167
164 void TearDown() override { 168 void TearDown() override {
165 if (http_server_props_manager_.get()) 169 if (http_server_props_manager_.get())
166 http_server_props_manager_->ShutdownOnPrefThread(); 170 http_server_props_manager_->ShutdownOnPrefThread();
167 base::RunLoop().RunUntilIdle(); 171 base::RunLoop().RunUntilIdle();
168 http_server_props_manager_.reset(); 172 http_server_props_manager_.reset();
169 } 173 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 bool HasAlternativeService(const url::SchemeHostPort& server) { 215 bool HasAlternativeService(const url::SchemeHostPort& server) {
212 const AlternativeServiceVector alternative_service_vector = 216 const AlternativeServiceVector alternative_service_vector =
213 http_server_props_manager_->GetAlternativeServices(server); 217 http_server_props_manager_->GetAlternativeServices(server);
214 return !alternative_service_vector.empty(); 218 return !alternative_service_vector.empty();
215 } 219 }
216 220
217 MockPrefDelegate* pref_delegate_; // Owned by HttpServerPropertiesManager. 221 MockPrefDelegate* pref_delegate_; // Owned by HttpServerPropertiesManager.
218 std::unique_ptr<TestingHttpServerPropertiesManager> 222 std::unique_ptr<TestingHttpServerPropertiesManager>
219 http_server_props_manager_; 223 http_server_props_manager_;
220 base::Time one_day_from_now_; 224 base::Time one_day_from_now_;
225 scoped_refptr<TestMockTimeTaskRunner> net_test_task_runner_;
221 226
222 private: 227 private:
223 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManagerTest); 228 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManagerTest);
224 }; 229 };
225 230
226 INSTANTIATE_TEST_CASE_P(Tests, 231 INSTANTIATE_TEST_CASE_P(Tests,
227 HttpServerPropertiesManagerTest, 232 HttpServerPropertiesManagerTest,
228 ::testing::ValuesIn(kHttpServerPropertiesVersions)); 233 ::testing::ValuesIn(kHttpServerPropertiesVersions));
229 234
230 TEST_P(HttpServerPropertiesManagerTest, 235 TEST_P(HttpServerPropertiesManagerTest,
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 quic_servers_dict->SetWithoutPathExpansion(play_quic_server_id.ToString(), 355 quic_servers_dict->SetWithoutPathExpansion(play_quic_server_id.ToString(),
351 quic_server_pref_dict3); 356 quic_server_pref_dict3);
352 http_server_properties_dict.SetWithoutPathExpansion("quic_servers", 357 http_server_properties_dict.SetWithoutPathExpansion("quic_servers",
353 quic_servers_dict); 358 quic_servers_dict);
354 359
355 // Set the same value for kHttpServerProperties multiple times. 360 // Set the same value for kHttpServerProperties multiple times.
356 pref_delegate_->SetPrefs(http_server_properties_dict); 361 pref_delegate_->SetPrefs(http_server_properties_dict);
357 pref_delegate_->SetPrefs(http_server_properties_dict); 362 pref_delegate_->SetPrefs(http_server_properties_dict);
358 363
359 base::RunLoop().RunUntilIdle(); 364 base::RunLoop().RunUntilIdle();
365 net_test_task_runner_->FastForwardUntilNoTasksRemain();
366
360 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 367 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
361 368
362 // Verify SupportsSpdy. 369 // Verify SupportsSpdy.
363 EXPECT_TRUE( 370 EXPECT_TRUE(
364 http_server_props_manager_->SupportsRequestPriority(google_server)); 371 http_server_props_manager_->SupportsRequestPriority(google_server));
365 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(mail_server)); 372 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(mail_server));
366 HostPortPair foo_host_port_pair = 373 HostPortPair foo_host_port_pair =
367 HostPortPair::FromString("foo.google.com:1337"); 374 HostPortPair::FromString("foo.google.com:1337");
368 url::SchemeHostPort foo_server("http", foo_host_port_pair.host(), 375 url::SchemeHostPort foo_server("http", foo_host_port_pair.host(),
369 foo_host_port_pair.port()); 376 foo_host_port_pair.port());
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 google_quic_server_id)); 447 google_quic_server_id));
441 EXPECT_EQ(quic_server_info2, *http_server_props_manager_->GetQuicServerInfo( 448 EXPECT_EQ(quic_server_info2, *http_server_props_manager_->GetQuicServerInfo(
442 mail_quic_server_id)); 449 mail_quic_server_id));
443 EXPECT_EQ(quic_server_info3, *http_server_props_manager_->GetQuicServerInfo( 450 EXPECT_EQ(quic_server_info3, *http_server_props_manager_->GetQuicServerInfo(
444 play_quic_server_id)); 451 play_quic_server_id));
445 */ 452 */
446 } 453 }
447 454
448 TEST_P(HttpServerPropertiesManagerTest, BadCachedHostPortPair) { 455 TEST_P(HttpServerPropertiesManagerTest, BadCachedHostPortPair) {
449 ExpectCacheUpdate(); 456 ExpectCacheUpdate();
450 // The prefs are automaticalls updated in the case corruption is detected. 457 // The prefs are automatically updated in the case corruption is detected.
451 ExpectPrefsUpdate(); 458 ExpectPrefsUpdate();
452 ExpectScheduleUpdatePrefsOnNetworkThread(); 459 ExpectScheduleUpdatePrefsOnNetworkThread();
453 460
454 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; 461 base::DictionaryValue* server_pref_dict = new base::DictionaryValue;
455 462
456 // Set supports_spdy for www.google.com:65536. 463 // Set supports_spdy for www.google.com:65536.
457 server_pref_dict->SetBoolean("supports_spdy", true); 464 server_pref_dict->SetBoolean("supports_spdy", true);
458 465
459 // Set up alternative_service for www.google.com:65536. 466 // Set up alternative_service for www.google.com:65536.
460 std::unique_ptr<base::DictionaryValue> alternative_service_dict( 467 std::unique_ptr<base::DictionaryValue> alternative_service_dict(
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 quic_servers_dict->SetWithoutPathExpansion("http://mail.google.com:65536", 509 quic_servers_dict->SetWithoutPathExpansion("http://mail.google.com:65536",
503 quic_server_pref_dict1); 510 quic_server_pref_dict1);
504 511
505 http_server_properties_dict.SetWithoutPathExpansion("quic_servers", 512 http_server_properties_dict.SetWithoutPathExpansion("quic_servers",
506 quic_servers_dict); 513 quic_servers_dict);
507 514
508 // Set up the pref. 515 // Set up the pref.
509 pref_delegate_->SetPrefs(http_server_properties_dict); 516 pref_delegate_->SetPrefs(http_server_properties_dict);
510 517
511 base::RunLoop().RunUntilIdle(); 518 base::RunLoop().RunUntilIdle();
519 net_test_task_runner_->FastForwardUntilNoTasksRemain();
520
512 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 521 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
513 522
514 // Verify that nothing is set. 523 // Verify that nothing is set.
515 HostPortPair google_host_port_pair = 524 HostPortPair google_host_port_pair =
516 HostPortPair::FromString("www.google.com:65536"); 525 HostPortPair::FromString("www.google.com:65536");
517 url::SchemeHostPort gooler_server("http", google_host_port_pair.host(), 526 url::SchemeHostPort gooler_server("http", google_host_port_pair.host(),
518 google_host_port_pair.port()); 527 google_host_port_pair.port());
519 528
520 EXPECT_FALSE( 529 EXPECT_FALSE(
521 http_server_props_manager_->SupportsRequestPriority(gooler_server)); 530 http_server_props_manager_->SupportsRequestPriority(gooler_server));
522 EXPECT_FALSE(HasAlternativeService(gooler_server)); 531 EXPECT_FALSE(HasAlternativeService(gooler_server));
523 const ServerNetworkStats* stats1 = 532 const ServerNetworkStats* stats1 =
524 http_server_props_manager_->GetServerNetworkStats(gooler_server); 533 http_server_props_manager_->GetServerNetworkStats(gooler_server);
525 EXPECT_EQ(nullptr, stats1); 534 EXPECT_EQ(nullptr, stats1);
526 EXPECT_EQ(0u, http_server_props_manager_->quic_server_info_map().size()); 535 EXPECT_EQ(0u, http_server_props_manager_->quic_server_info_map().size());
527 } 536 }
528 537
529 TEST_P(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { 538 TEST_P(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) {
530 ExpectCacheUpdate(); 539 ExpectCacheUpdate();
531 // The prefs are automaticalls updated in the case corruption is detected. 540 // The prefs are automatically updated in the case corruption is detected.
532 ExpectPrefsUpdate(); 541 ExpectPrefsUpdate();
533 ExpectScheduleUpdatePrefsOnNetworkThread(); 542 ExpectScheduleUpdatePrefsOnNetworkThread();
534 543
535 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; 544 base::DictionaryValue* server_pref_dict = new base::DictionaryValue;
536 545
537 // Set supports_spdy for www.google.com:80. 546 // Set supports_spdy for www.google.com:80.
538 server_pref_dict->SetBoolean("supports_spdy", true); 547 server_pref_dict->SetBoolean("supports_spdy", true);
539 548
540 // Set up alternative_service for www.google.com:80. 549 // Set up alternative_service for www.google.com:80.
541 std::unique_ptr<base::DictionaryValue> alternative_service_dict( 550 std::unique_ptr<base::DictionaryValue> alternative_service_dict(
(...skipping 24 matching lines...) Expand all
566 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, 575 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict,
567 GetParam()); 576 GetParam());
568 http_server_properties_dict.SetWithoutPathExpansion( 577 http_server_properties_dict.SetWithoutPathExpansion(
569 "servers", std::move(servers_dict)); 578 "servers", std::move(servers_dict));
570 } 579 }
571 580
572 // Set up the pref. 581 // Set up the pref.
573 pref_delegate_->SetPrefs(http_server_properties_dict); 582 pref_delegate_->SetPrefs(http_server_properties_dict);
574 583
575 base::RunLoop().RunUntilIdle(); 584 base::RunLoop().RunUntilIdle();
585 net_test_task_runner_->FastForwardUntilNoTasksRemain();
586
576 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 587 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
577 588
578 // Verify alternative service is not set. 589 // Verify alternative service is not set.
579 EXPECT_FALSE( 590 EXPECT_FALSE(
580 HasAlternativeService(url::SchemeHostPort("http", "www.google.com", 80))); 591 HasAlternativeService(url::SchemeHostPort("http", "www.google.com", 80)));
581 } 592 }
582 593
583 TEST_P(HttpServerPropertiesManagerTest, SupportsSpdy) { 594 TEST_P(HttpServerPropertiesManagerTest, SupportsSpdy) {
584 ExpectPrefsUpdate(); 595 ExpectPrefsUpdate();
585 ExpectScheduleUpdatePrefsOnNetworkThread(); 596 ExpectScheduleUpdatePrefsOnNetworkThread();
586 597
587 // Post an update task to the network thread. SetSupportsSpdy calls 598 // Post an update task to the network thread. SetSupportsSpdy calls
588 // ScheduleUpdatePrefsOnNetworkThread. 599 // ScheduleUpdatePrefsOnNetworkThread.
589 600
590 // Add mail.google.com:443 as a supporting spdy server. 601 // Add mail.google.com:443 as a supporting spdy server.
591 url::SchemeHostPort spdy_server("https", "mail.google.com", 443); 602 url::SchemeHostPort spdy_server("https", "mail.google.com", 443);
592 EXPECT_FALSE( 603 EXPECT_FALSE(
593 http_server_props_manager_->SupportsRequestPriority(spdy_server)); 604 http_server_props_manager_->SupportsRequestPriority(spdy_server));
594 http_server_props_manager_->SetSupportsSpdy(spdy_server, true); 605 http_server_props_manager_->SetSupportsSpdy(spdy_server, true);
595 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. 606 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once.
596 http_server_props_manager_->SetSupportsSpdy(spdy_server, true); 607 http_server_props_manager_->SetSupportsSpdy(spdy_server, true);
597 608
598 // Run the task. 609 // Run the task.
599 base::RunLoop().RunUntilIdle(); 610 base::RunLoop().RunUntilIdle();
611 net_test_task_runner_->FastForwardUntilNoTasksRemain();
600 612
601 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(spdy_server)); 613 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(spdy_server));
602 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 614 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
603 } 615 }
604 616
605 TEST_P(HttpServerPropertiesManagerTest, GetAlternativeServices) { 617 TEST_P(HttpServerPropertiesManagerTest, GetAlternativeServices) {
606 ExpectPrefsUpdate(); 618 ExpectPrefsUpdate();
607 ExpectScheduleUpdatePrefsOnNetworkThread(); 619 ExpectScheduleUpdatePrefsOnNetworkThread();
608 620
609 url::SchemeHostPort spdy_server_mail("http", "mail.google.com", 80); 621 url::SchemeHostPort spdy_server_mail("http", "mail.google.com", 80);
610 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); 622 EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
611 const AlternativeService alternative_service(kProtoHTTP2, "mail.google.com", 623 const AlternativeService alternative_service(kProtoHTTP2, "mail.google.com",
612 443); 624 443);
613 http_server_props_manager_->SetAlternativeService( 625 http_server_props_manager_->SetAlternativeService(
614 spdy_server_mail, alternative_service, one_day_from_now_); 626 spdy_server_mail, alternative_service, one_day_from_now_);
615 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. 627 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once.
616 http_server_props_manager_->SetAlternativeService( 628 http_server_props_manager_->SetAlternativeService(
617 spdy_server_mail, alternative_service, one_day_from_now_); 629 spdy_server_mail, alternative_service, one_day_from_now_);
618 630
619 // Run the task. 631 // Run the task.
620 base::RunLoop().RunUntilIdle(); 632 base::RunLoop().RunUntilIdle();
633 net_test_task_runner_->FastForwardUntilNoTasksRemain();
634
621 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 635 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
622 636
623 AlternativeServiceVector alternative_service_vector = 637 AlternativeServiceVector alternative_service_vector =
624 http_server_props_manager_->GetAlternativeServices(spdy_server_mail); 638 http_server_props_manager_->GetAlternativeServices(spdy_server_mail);
625 ASSERT_EQ(1u, alternative_service_vector.size()); 639 ASSERT_EQ(1u, alternative_service_vector.size());
626 EXPECT_EQ(alternative_service, alternative_service_vector[0]); 640 EXPECT_EQ(alternative_service, alternative_service_vector[0]);
627 } 641 }
628 642
629 TEST_P(HttpServerPropertiesManagerTest, SetAlternativeServices) { 643 TEST_P(HttpServerPropertiesManagerTest, SetAlternativeServices) {
630 ExpectPrefsUpdate(); 644 ExpectPrefsUpdate();
(...skipping 11 matching lines...) Expand all
642 alternative_service_info_vector.push_back( 656 alternative_service_info_vector.push_back(
643 AlternativeServiceInfo(alternative_service2, one_day_from_now_)); 657 AlternativeServiceInfo(alternative_service2, one_day_from_now_));
644 http_server_props_manager_->SetAlternativeServices( 658 http_server_props_manager_->SetAlternativeServices(
645 spdy_server_mail, alternative_service_info_vector); 659 spdy_server_mail, alternative_service_info_vector);
646 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. 660 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once.
647 http_server_props_manager_->SetAlternativeServices( 661 http_server_props_manager_->SetAlternativeServices(
648 spdy_server_mail, alternative_service_info_vector); 662 spdy_server_mail, alternative_service_info_vector);
649 663
650 // Run the task. 664 // Run the task.
651 base::RunLoop().RunUntilIdle(); 665 base::RunLoop().RunUntilIdle();
666 net_test_task_runner_->FastForwardUntilNoTasksRemain();
667
652 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 668 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
653 669
654 AlternativeServiceVector alternative_service_vector = 670 AlternativeServiceVector alternative_service_vector =
655 http_server_props_manager_->GetAlternativeServices(spdy_server_mail); 671 http_server_props_manager_->GetAlternativeServices(spdy_server_mail);
656 ASSERT_EQ(2u, alternative_service_vector.size()); 672 ASSERT_EQ(2u, alternative_service_vector.size());
657 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); 673 EXPECT_EQ(alternative_service1, alternative_service_vector[0]);
658 EXPECT_EQ(alternative_service2, alternative_service_vector[1]); 674 EXPECT_EQ(alternative_service2, alternative_service_vector[1]);
659 } 675 }
660 676
661 TEST_P(HttpServerPropertiesManagerTest, SetAlternativeServicesEmpty) { 677 TEST_P(HttpServerPropertiesManagerTest, SetAlternativeServicesEmpty) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 alternative_service)); 721 alternative_service));
706 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. 722 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once.
707 http_server_props_manager_->ConfirmAlternativeService(alternative_service); 723 http_server_props_manager_->ConfirmAlternativeService(alternative_service);
708 EXPECT_FALSE(http_server_props_manager_->IsAlternativeServiceBroken( 724 EXPECT_FALSE(http_server_props_manager_->IsAlternativeServiceBroken(
709 alternative_service)); 725 alternative_service));
710 EXPECT_FALSE(http_server_props_manager_->WasAlternativeServiceRecentlyBroken( 726 EXPECT_FALSE(http_server_props_manager_->WasAlternativeServiceRecentlyBroken(
711 alternative_service)); 727 alternative_service));
712 728
713 // Run the task. 729 // Run the task.
714 base::RunLoop().RunUntilIdle(); 730 base::RunLoop().RunUntilIdle();
731 net_test_task_runner_->FastForwardUntilNoTasksRemain();
732
715 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 733 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
716 734
717 EXPECT_FALSE(http_server_props_manager_->IsAlternativeServiceBroken( 735 EXPECT_FALSE(http_server_props_manager_->IsAlternativeServiceBroken(
718 alternative_service)); 736 alternative_service));
719 EXPECT_FALSE(http_server_props_manager_->WasAlternativeServiceRecentlyBroken( 737 EXPECT_FALSE(http_server_props_manager_->WasAlternativeServiceRecentlyBroken(
720 alternative_service)); 738 alternative_service));
721 } 739 }
722 740
723 TEST_P(HttpServerPropertiesManagerTest, SupportsQuic) { 741 TEST_P(HttpServerPropertiesManagerTest, SupportsQuic) {
724 ExpectPrefsUpdate(); 742 ExpectPrefsUpdate();
725 ExpectScheduleUpdatePrefsOnNetworkThread(); 743 ExpectScheduleUpdatePrefsOnNetworkThread();
726 744
727 IPAddress address; 745 IPAddress address;
728 EXPECT_FALSE(http_server_props_manager_->GetSupportsQuic(&address)); 746 EXPECT_FALSE(http_server_props_manager_->GetSupportsQuic(&address));
729 747
730 IPAddress actual_address(127, 0, 0, 1); 748 IPAddress actual_address(127, 0, 0, 1);
731 http_server_props_manager_->SetSupportsQuic(true, actual_address); 749 http_server_props_manager_->SetSupportsQuic(true, actual_address);
732 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. 750 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once.
733 http_server_props_manager_->SetSupportsQuic(true, actual_address); 751 http_server_props_manager_->SetSupportsQuic(true, actual_address);
734 752
735 // Run the task. 753 // Run the task.
736 base::RunLoop().RunUntilIdle(); 754 base::RunLoop().RunUntilIdle();
755 net_test_task_runner_->FastForwardUntilNoTasksRemain();
756
737 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 757 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
738 758
739 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); 759 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address));
740 EXPECT_EQ(actual_address, address); 760 EXPECT_EQ(actual_address, address);
741 } 761 }
742 762
743 TEST_P(HttpServerPropertiesManagerTest, ServerNetworkStats) { 763 TEST_P(HttpServerPropertiesManagerTest, ServerNetworkStats) {
744 ExpectPrefsUpdate(); 764 ExpectPrefsUpdate();
745 ExpectScheduleUpdatePrefsOnNetworkThread(); 765 ExpectScheduleUpdatePrefsOnNetworkThread();
746 766
747 url::SchemeHostPort mail_server("http", "mail.google.com", 80); 767 url::SchemeHostPort mail_server("http", "mail.google.com", 80);
748 const ServerNetworkStats* stats = 768 const ServerNetworkStats* stats =
749 http_server_props_manager_->GetServerNetworkStats(mail_server); 769 http_server_props_manager_->GetServerNetworkStats(mail_server);
750 EXPECT_EQ(nullptr, stats); 770 EXPECT_EQ(nullptr, stats);
751 ServerNetworkStats stats1; 771 ServerNetworkStats stats1;
752 stats1.srtt = base::TimeDelta::FromMicroseconds(10); 772 stats1.srtt = base::TimeDelta::FromMicroseconds(10);
753 http_server_props_manager_->SetServerNetworkStats(mail_server, stats1); 773 http_server_props_manager_->SetServerNetworkStats(mail_server, stats1);
754 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. 774 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once.
755 http_server_props_manager_->SetServerNetworkStats(mail_server, stats1); 775 http_server_props_manager_->SetServerNetworkStats(mail_server, stats1);
756 776
757 // Run the task. 777 // Run the task.
758 base::RunLoop().RunUntilIdle(); 778 base::RunLoop().RunUntilIdle();
779 net_test_task_runner_->FastForwardUntilNoTasksRemain();
780
759 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 781 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
760 782
761 const ServerNetworkStats* stats2 = 783 const ServerNetworkStats* stats2 =
762 http_server_props_manager_->GetServerNetworkStats(mail_server); 784 http_server_props_manager_->GetServerNetworkStats(mail_server);
763 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); 785 EXPECT_EQ(10, stats2->srtt.ToInternalValue());
764 } 786 }
765 787
766 TEST_P(HttpServerPropertiesManagerTest, QuicServerInfo) { 788 TEST_P(HttpServerPropertiesManagerTest, QuicServerInfo) {
767 ExpectPrefsUpdate(); 789 ExpectPrefsUpdate();
768 ExpectScheduleUpdatePrefsOnNetworkThread(); 790 ExpectScheduleUpdatePrefsOnNetworkThread();
769 791
770 QuicServerId mail_quic_server_id("mail.google.com", 80); 792 QuicServerId mail_quic_server_id("mail.google.com", 80);
771 EXPECT_EQ(nullptr, 793 EXPECT_EQ(nullptr,
772 http_server_props_manager_->GetQuicServerInfo(mail_quic_server_id)); 794 http_server_props_manager_->GetQuicServerInfo(mail_quic_server_id));
773 std::string quic_server_info1("quic_server_info1"); 795 std::string quic_server_info1("quic_server_info1");
774 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id, 796 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id,
775 quic_server_info1); 797 quic_server_info1);
776 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. 798 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once.
777 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id, 799 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id,
778 quic_server_info1); 800 quic_server_info1);
779 801
780 // Run the task. 802 // Run the task.
781 base::RunLoop().RunUntilIdle(); 803 base::RunLoop().RunUntilIdle();
804 net_test_task_runner_->FastForwardUntilNoTasksRemain();
805
782 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 806 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
783 807
784 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo( 808 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo(
785 mail_quic_server_id)); 809 mail_quic_server_id));
786 } 810 }
787 811
788 TEST_P(HttpServerPropertiesManagerTest, Clear) { 812 TEST_P(HttpServerPropertiesManagerTest, Clear) {
789 ExpectPrefsUpdate(); 813 ExpectPrefsUpdate();
790 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); 814 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly();
791 815
792 url::SchemeHostPort spdy_server("https", "mail.google.com", 443); 816 url::SchemeHostPort spdy_server("https", "mail.google.com", 443);
793 http_server_props_manager_->SetSupportsSpdy(spdy_server, true); 817 http_server_props_manager_->SetSupportsSpdy(spdy_server, true);
794 AlternativeService alternative_service(kProtoHTTP2, "mail.google.com", 1234); 818 AlternativeService alternative_service(kProtoHTTP2, "mail.google.com", 1234);
795 http_server_props_manager_->SetAlternativeService( 819 http_server_props_manager_->SetAlternativeService(
796 spdy_server, alternative_service, one_day_from_now_); 820 spdy_server, alternative_service, one_day_from_now_);
797 IPAddress actual_address(127, 0, 0, 1); 821 IPAddress actual_address(127, 0, 0, 1);
798 http_server_props_manager_->SetSupportsQuic(true, actual_address); 822 http_server_props_manager_->SetSupportsQuic(true, actual_address);
799 ServerNetworkStats stats; 823 ServerNetworkStats stats;
800 stats.srtt = base::TimeDelta::FromMicroseconds(10); 824 stats.srtt = base::TimeDelta::FromMicroseconds(10);
801 http_server_props_manager_->SetServerNetworkStats(spdy_server, stats); 825 http_server_props_manager_->SetServerNetworkStats(spdy_server, stats);
802 826
803 QuicServerId mail_quic_server_id("mail.google.com", 80); 827 QuicServerId mail_quic_server_id("mail.google.com", 80);
804 std::string quic_server_info1("quic_server_info1"); 828 std::string quic_server_info1("quic_server_info1");
805 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id, 829 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id,
806 quic_server_info1); 830 quic_server_info1);
807 831
808 // Run the task. 832 // Run the task.
809 base::RunLoop().RunUntilIdle(); 833 base::RunLoop().RunUntilIdle();
834 net_test_task_runner_->FastForwardUntilNoTasksRemain();
810 835
811 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(spdy_server)); 836 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(spdy_server));
812 EXPECT_TRUE(HasAlternativeService(spdy_server)); 837 EXPECT_TRUE(HasAlternativeService(spdy_server));
813 IPAddress address; 838 IPAddress address;
814 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); 839 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address));
815 EXPECT_EQ(actual_address, address); 840 EXPECT_EQ(actual_address, address);
816 const ServerNetworkStats* stats1 = 841 const ServerNetworkStats* stats1 =
817 http_server_props_manager_->GetServerNetworkStats(spdy_server); 842 http_server_props_manager_->GetServerNetworkStats(spdy_server);
818 EXPECT_EQ(10, stats1->srtt.ToInternalValue()); 843 EXPECT_EQ(10, stats1->srtt.ToInternalValue());
819 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo( 844 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo(
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 base::DictionaryValue* supports_quic = new base::DictionaryValue; 930 base::DictionaryValue* supports_quic = new base::DictionaryValue;
906 supports_quic->SetBoolean("used_quic", true); 931 supports_quic->SetBoolean("used_quic", true);
907 supports_quic->SetString("address", "127.0.0.1"); 932 supports_quic->SetString("address", "127.0.0.1");
908 http_server_properties_dict.SetWithoutPathExpansion("supports_quic", 933 http_server_properties_dict.SetWithoutPathExpansion("supports_quic",
909 supports_quic); 934 supports_quic);
910 935
911 // Set up the pref. 936 // Set up the pref.
912 pref_delegate_->SetPrefs(http_server_properties_dict); 937 pref_delegate_->SetPrefs(http_server_properties_dict);
913 938
914 base::RunLoop().RunUntilIdle(); 939 base::RunLoop().RunUntilIdle();
940 net_test_task_runner_->FastForwardUntilNoTasksRemain();
941
915 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 942 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
916 943
917 // Verify alternative service. 944 // Verify alternative service.
918 for (int i = 1; i <= 200; ++i) { 945 for (int i = 1; i <= 200; ++i) {
919 GURL server_gurl; 946 GURL server_gurl;
920 if (GetParam() >= 5) { 947 if (GetParam() >= 5) {
921 server_gurl = GURL(StringPrintf("https://www.google.com:%d", i)); 948 server_gurl = GURL(StringPrintf("https://www.google.com:%d", i));
922 } else { 949 } else {
923 server_gurl = GURL(StringPrintf("https://www.google.com:%d", i)); 950 server_gurl = GURL(StringPrintf("https://www.google.com:%d", i));
924 } 951 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 quic_server_info1); 1003 quic_server_info1);
977 1004
978 // Set SupportsQuic. 1005 // Set SupportsQuic.
979 IPAddress actual_address(127, 0, 0, 1); 1006 IPAddress actual_address(127, 0, 0, 1);
980 http_server_props_manager_->SetSupportsQuic(true, actual_address); 1007 http_server_props_manager_->SetSupportsQuic(true, actual_address);
981 1008
982 // Update cache. 1009 // Update cache.
983 ExpectPrefsUpdate(); 1010 ExpectPrefsUpdate();
984 ExpectCacheUpdate(); 1011 ExpectCacheUpdate();
985 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); 1012 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread();
1013
1014 net_test_task_runner_->FastForwardUntilNoTasksRemain();
986 base::RunLoop().RunUntilIdle(); 1015 base::RunLoop().RunUntilIdle();
987 1016
988 // Verify preferences. 1017 // Verify preferences.
989 const char expected_json[] = 1018 const char expected_json[] =
990 "{\"quic_servers\":{\"https://" 1019 "{\"quic_servers\":{\"https://"
991 "mail.google.com:80\":{\"server_info\":\"quic_server_info1\"}}," 1020 "mail.google.com:80\":{\"server_info\":\"quic_server_info1\"}},"
992 "\"servers\":[" 1021 "\"servers\":["
993 "{\"http://www.google.com\":{" 1022 "{\"http://www.google.com\":{"
994 "\"alternative_service\":[{\"expiration\":\"13756212000000000\"," 1023 "\"alternative_service\":[{\"expiration\":\"13756212000000000\","
995 "\"port\":443,\"protocol_str\":\"h2\"}," 1024 "\"port\":443,\"protocol_str\":\"h2\"},"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 AlternativeServiceInfo(valid_alternative_service, time_one_day_later)); 1136 AlternativeServiceInfo(valid_alternative_service, time_one_day_later));
1108 1137
1109 const url::SchemeHostPort server("https", "www.example.com", 443); 1138 const url::SchemeHostPort server("https", "www.example.com", 443);
1110 http_server_props_manager_->SetAlternativeServices( 1139 http_server_props_manager_->SetAlternativeServices(
1111 server, alternative_service_info_vector); 1140 server, alternative_service_info_vector);
1112 1141
1113 // Update cache. 1142 // Update cache.
1114 ExpectPrefsUpdate(); 1143 ExpectPrefsUpdate();
1115 ExpectCacheUpdate(); 1144 ExpectCacheUpdate();
1116 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); 1145 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread();
1146
1147 net_test_task_runner_->FastForwardUntilNoTasksRemain();
1117 base::RunLoop().RunUntilIdle(); 1148 base::RunLoop().RunUntilIdle();
1118 1149
1119 const base::DictionaryValue& pref_dict = 1150 const base::DictionaryValue& pref_dict =
1120 pref_delegate_->GetServerProperties(); 1151 pref_delegate_->GetServerProperties();
1121 1152
1122 const base::ListValue* servers_list = nullptr; 1153 const base::ListValue* servers_list = nullptr;
1123 ASSERT_TRUE(pref_dict.GetListWithoutPathExpansion("servers", &servers_list)); 1154 ASSERT_TRUE(pref_dict.GetListWithoutPathExpansion("servers", &servers_list));
1124 base::ListValue::const_iterator it = servers_list->begin(); 1155 base::ListValue::const_iterator it = servers_list->begin();
1125 const base::DictionaryValue* server_pref_dict; 1156 const base::DictionaryValue* server_pref_dict;
1126 ASSERT_TRUE((*it)->GetAsDictionary(&server_pref_dict)); 1157 ASSERT_TRUE((*it)->GetAsDictionary(&server_pref_dict));
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1234 base::RunLoop().RunUntilIdle(); 1265 base::RunLoop().RunUntilIdle();
1235 } 1266 }
1236 1267
1237 TEST_P(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdatePrefs1) { 1268 TEST_P(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdatePrefs1) {
1238 ExpectPrefsUpdate(); 1269 ExpectPrefsUpdate();
1239 // Post an update task. 1270 // Post an update task.
1240 http_server_props_manager_->ScheduleUpdatePrefsOnNetworkThread(); 1271 http_server_props_manager_->ScheduleUpdatePrefsOnNetworkThread();
1241 // Shutdown comes before the task is executed. 1272 // Shutdown comes before the task is executed.
1242 http_server_props_manager_->ShutdownOnPrefThread(); 1273 http_server_props_manager_->ShutdownOnPrefThread();
1243 // Run the task after shutdown, but before deletion. 1274 // Run the task after shutdown, but before deletion.
1275 net_test_task_runner_->FastForwardUntilNoTasksRemain();
1244 base::RunLoop().RunUntilIdle(); 1276 base::RunLoop().RunUntilIdle();
1277
1245 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 1278 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
1246 http_server_props_manager_.reset(); 1279 http_server_props_manager_.reset();
1247 base::RunLoop().RunUntilIdle(); 1280 base::RunLoop().RunUntilIdle();
1248 } 1281 }
1249 1282
1250 TEST_P(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdatePrefs2) { 1283 TEST_P(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdatePrefs2) {
1251 // This posts a task to the UI thread. 1284 // This posts a task to the UI thread.
1252 http_server_props_manager_->UpdatePrefsFromCacheOnNetworkThreadConcrete( 1285 http_server_props_manager_->UpdatePrefsFromCacheOnNetworkThreadConcrete(
1253 base::Closure()); 1286 base::Closure());
1254 // Shutdown comes before the task is executed. 1287 // Shutdown comes before the task is executed.
1255 http_server_props_manager_->ShutdownOnPrefThread(); 1288 http_server_props_manager_->ShutdownOnPrefThread();
1256 // Run the task after shutdown, but before deletion. 1289 // Run the task after shutdown, but before deletion.
1257 base::RunLoop().RunUntilIdle(); 1290 base::RunLoop().RunUntilIdle();
1258 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 1291 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
1259 http_server_props_manager_.reset(); 1292 http_server_props_manager_.reset();
1260 base::RunLoop().RunUntilIdle(); 1293 base::RunLoop().RunUntilIdle();
1261 } 1294 }
1262 1295
1263 } // namespace net 1296 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_server_properties_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698