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

Side by Side Diff: components/network_time/network_time_tracker_unittest.cc

Issue 2448943004: Add experimental feature info to certificate reports (Closed)
Patch Set: battre comment Created 4 years, 1 month 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 "components/network_time/network_time_tracker.h" 5 #include "components/network_time/network_time_tracker.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 clock_(new base::SimpleTestClock), 50 clock_(new base::SimpleTestClock),
51 tick_clock_(new base::SimpleTestTickClock), 51 tick_clock_(new base::SimpleTestTickClock),
52 test_server_(new net::EmbeddedTestServer) { 52 test_server_(new net::EmbeddedTestServer) {
53 base::Thread::Options thread_options; 53 base::Thread::Options thread_options;
54 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; 54 thread_options.message_loop_type = base::MessageLoop::TYPE_IO;
55 EXPECT_TRUE(io_thread_.StartWithOptions(thread_options)); 55 EXPECT_TRUE(io_thread_.StartWithOptions(thread_options));
56 NetworkTimeTracker::RegisterPrefs(pref_service_.registry()); 56 NetworkTimeTracker::RegisterPrefs(pref_service_.registry());
57 57
58 field_trial_test_->SetNetworkQueriesWithVariationsService( 58 field_trial_test_->SetNetworkQueriesWithVariationsService(
59 true, 0.0 /* query probability */, 59 true, 0.0 /* query probability */,
60 FieldTrialTest::FETCHES_IN_BACKGROUND_AND_ON_DEMAND); 60 NetworkTimeTracker::FETCHES_IN_BACKGROUND_AND_ON_DEMAND);
61 61
62 tracker_.reset(new NetworkTimeTracker( 62 tracker_.reset(new NetworkTimeTracker(
63 std::unique_ptr<base::Clock>(clock_), 63 std::unique_ptr<base::Clock>(clock_),
64 std::unique_ptr<base::TickClock>(tick_clock_), &pref_service_, 64 std::unique_ptr<base::TickClock>(tick_clock_), &pref_service_,
65 new net::TestURLRequestContextGetter(io_thread_.task_runner()))); 65 new net::TestURLRequestContextGetter(io_thread_.task_runner())));
66 66
67 // Do this to be sure that |is_null| returns false. 67 // Do this to be sure that |is_null| returns false.
68 clock_->Advance(base::TimeDelta::FromDays(111)); 68 clock_->Advance(base::TimeDelta::FromDays(111));
69 tick_clock_->Advance(base::TimeDelta::FromDays(222)); 69 tick_clock_->Advance(base::TimeDelta::FromDays(222));
70 70
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 548
549 // No query should be started so long as NetworkTimeTracker is synced. 549 // No query should be started so long as NetworkTimeTracker is synced.
550 base::RunLoop run_loop; 550 base::RunLoop run_loop;
551 EXPECT_FALSE(tracker_->StartTimeFetch(run_loop.QuitClosure())); 551 EXPECT_FALSE(tracker_->StartTimeFetch(run_loop.QuitClosure()));
552 } 552 }
553 553
554 // Tests that StartTimeFetch() returns false if the field trial 554 // Tests that StartTimeFetch() returns false if the field trial
555 // is not configured to allow on-demand time fetches. 555 // is not configured to allow on-demand time fetches.
556 TEST_F(NetworkTimeTrackerTest, StartTimeFetchWithoutVariationsParam) { 556 TEST_F(NetworkTimeTrackerTest, StartTimeFetchWithoutVariationsParam) {
557 field_trial_test_->SetNetworkQueriesWithVariationsService( 557 field_trial_test_->SetNetworkQueriesWithVariationsService(
558 true, 0.0, FieldTrialTest::FETCHES_IN_BACKGROUND_ONLY); 558 true, 0.0, NetworkTimeTracker::FETCHES_IN_BACKGROUND_ONLY);
559 test_server_->RegisterRequestHandler(base::Bind(&GoodTimeResponseHandler)); 559 test_server_->RegisterRequestHandler(base::Bind(&GoodTimeResponseHandler));
560 EXPECT_TRUE(test_server_->Start()); 560 EXPECT_TRUE(test_server_->Start());
561 tracker_->SetTimeServerURLForTesting(test_server_->GetURL("/")); 561 tracker_->SetTimeServerURLForTesting(test_server_->GetURL("/"));
562 562
563 base::Time out_network_time; 563 base::Time out_network_time;
564 EXPECT_EQ(NetworkTimeTracker::NETWORK_TIME_NO_SYNC_ATTEMPT, 564 EXPECT_EQ(NetworkTimeTracker::NETWORK_TIME_NO_SYNC_ATTEMPT,
565 tracker_->GetNetworkTime(&out_network_time, nullptr)); 565 tracker_->GetNetworkTime(&out_network_time, nullptr));
566 566
567 base::RunLoop run_loop; 567 base::RunLoop run_loop;
568 EXPECT_FALSE(tracker_->StartTimeFetch(run_loop.QuitClosure())); 568 EXPECT_FALSE(tracker_->StartTimeFetch(run_loop.QuitClosure()));
569 } 569 }
570 570
571 TEST_F(NetworkTimeTrackerTest, NoNetworkQueryWhileSynced) { 571 TEST_F(NetworkTimeTrackerTest, NoNetworkQueryWhileSynced) {
572 test_server_->RegisterRequestHandler(base::Bind(&GoodTimeResponseHandler)); 572 test_server_->RegisterRequestHandler(base::Bind(&GoodTimeResponseHandler));
573 EXPECT_TRUE(test_server_->Start()); 573 EXPECT_TRUE(test_server_->Start());
574 tracker_->SetTimeServerURLForTesting(test_server_->GetURL("/")); 574 tracker_->SetTimeServerURLForTesting(test_server_->GetURL("/"));
575 575
576 field_trial_test_->SetNetworkQueriesWithVariationsService( 576 field_trial_test_->SetNetworkQueriesWithVariationsService(
577 true, 0.0, FieldTrialTest::FETCHES_IN_BACKGROUND_AND_ON_DEMAND); 577 true, 0.0, NetworkTimeTracker::FETCHES_IN_BACKGROUND_AND_ON_DEMAND);
578 base::Time in_network_time = clock_->Now(); 578 base::Time in_network_time = clock_->Now();
579 UpdateNetworkTime(in_network_time, resolution_, latency_, 579 UpdateNetworkTime(in_network_time, resolution_, latency_,
580 tick_clock_->NowTicks()); 580 tick_clock_->NowTicks());
581 581
582 // No query should be started so long as NetworkTimeTracker is synced, but the 582 // No query should be started so long as NetworkTimeTracker is synced, but the
583 // next check should happen soon. 583 // next check should happen soon.
584 EXPECT_FALSE(tracker_->QueryTimeServiceForTesting()); 584 EXPECT_FALSE(tracker_->QueryTimeServiceForTesting());
585 EXPECT_EQ(base::TimeDelta::FromMinutes(6), 585 EXPECT_EQ(base::TimeDelta::FromMinutes(6),
586 tracker_->GetTimerDelayForTesting()); 586 tracker_->GetTimerDelayForTesting());
587 587
588 field_trial_test_->SetNetworkQueriesWithVariationsService( 588 field_trial_test_->SetNetworkQueriesWithVariationsService(
589 true, 1.0, FieldTrialTest::FETCHES_IN_BACKGROUND_AND_ON_DEMAND); 589 true, 1.0, NetworkTimeTracker::FETCHES_IN_BACKGROUND_AND_ON_DEMAND);
590 EXPECT_TRUE(tracker_->QueryTimeServiceForTesting()); 590 EXPECT_TRUE(tracker_->QueryTimeServiceForTesting());
591 tracker_->WaitForFetchForTesting(123123123); 591 tracker_->WaitForFetchForTesting(123123123);
592 EXPECT_EQ(base::TimeDelta::FromMinutes(60), 592 EXPECT_EQ(base::TimeDelta::FromMinutes(60),
593 tracker_->GetTimerDelayForTesting()); 593 tracker_->GetTimerDelayForTesting());
594 } 594 }
595 595
596 TEST_F(NetworkTimeTrackerTest, NoNetworkQueryWhileFeatureDisabled) { 596 TEST_F(NetworkTimeTrackerTest, NoNetworkQueryWhileFeatureDisabled) {
597 // Disable network time queries and check that a query is not sent. 597 // Disable network time queries and check that a query is not sent.
598 field_trial_test_->SetNetworkQueriesWithVariationsService( 598 field_trial_test_->SetNetworkQueriesWithVariationsService(
599 false, 0.0, FieldTrialTest::FETCHES_IN_BACKGROUND_AND_ON_DEMAND); 599 false, 0.0, NetworkTimeTracker::FETCHES_IN_BACKGROUND_AND_ON_DEMAND);
600 EXPECT_FALSE(tracker_->QueryTimeServiceForTesting()); 600 EXPECT_FALSE(tracker_->QueryTimeServiceForTesting());
601 // The timer is not started when the feature is disabled. 601 // The timer is not started when the feature is disabled.
602 EXPECT_EQ(base::TimeDelta::FromMinutes(0), 602 EXPECT_EQ(base::TimeDelta::FromMinutes(0),
603 tracker_->GetTimerDelayForTesting()); 603 tracker_->GetTimerDelayForTesting());
604 604
605 // Enable time queries and check that a query is sent. 605 // Enable time queries and check that a query is sent.
606 field_trial_test_->SetNetworkQueriesWithVariationsService( 606 field_trial_test_->SetNetworkQueriesWithVariationsService(
607 true, 0.0, FieldTrialTest::FETCHES_IN_BACKGROUND_AND_ON_DEMAND); 607 true, 0.0, NetworkTimeTracker::FETCHES_IN_BACKGROUND_AND_ON_DEMAND);
608 EXPECT_TRUE(tracker_->QueryTimeServiceForTesting()); 608 EXPECT_TRUE(tracker_->QueryTimeServiceForTesting());
609 tracker_->WaitForFetchForTesting(123123123); 609 tracker_->WaitForFetchForTesting(123123123);
610 } 610 }
611 611
612 TEST_F(NetworkTimeTrackerTest, UpdateFromNetworkBadSignature) { 612 TEST_F(NetworkTimeTrackerTest, UpdateFromNetworkBadSignature) {
613 base::HistogramTester histograms; 613 base::HistogramTester histograms;
614 histograms.ExpectTotalCount(kFetchFailedHistogram, 0); 614 histograms.ExpectTotalCount(kFetchFailedHistogram, 0);
615 histograms.ExpectTotalCount(kFetchValidHistogram, 0); 615 histograms.ExpectTotalCount(kFetchValidHistogram, 0);
616 616
617 test_server_->RegisterRequestHandler( 617 test_server_->RegisterRequestHandler(
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 EXPECT_EQ(NetworkTimeTracker::NETWORK_TIME_SUBSEQUENT_SYNC_PENDING, 807 EXPECT_EQ(NetworkTimeTracker::NETWORK_TIME_SUBSEQUENT_SYNC_PENDING,
808 tracker_->GetNetworkTime(&out_network_time, nullptr)); 808 tracker_->GetNetworkTime(&out_network_time, nullptr));
809 histograms.ExpectTotalCount(kFetchFailedHistogram, 0); 809 histograms.ExpectTotalCount(kFetchFailedHistogram, 0);
810 histograms.ExpectTotalCount(kFetchValidHistogram, 1); 810 histograms.ExpectTotalCount(kFetchValidHistogram, 1);
811 histograms.ExpectBucketCount(kFetchValidHistogram, false, 1); 811 histograms.ExpectBucketCount(kFetchValidHistogram, false, 1);
812 812
813 tracker_->WaitForFetchForTesting(123123123); 813 tracker_->WaitForFetchForTesting(123123123);
814 } 814 }
815 815
816 } // namespace network_time 816 } // namespace network_time
OLDNEW
« no previous file with comments | « components/network_time/network_time_tracker.cc ('k') | components/ssl_errors/error_classification_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698