| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/network_time/network_time_tracker.h" | 5 #include "components/network_time/network_time_tracker.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/feature_list.h" | 13 #include "base/feature_list.h" |
| 14 #include "base/memory/ptr_util.h" |
| 14 #include "base/metrics/field_trial.h" | 15 #include "base/metrics/field_trial.h" |
| 15 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 17 #include "base/test/histogram_tester.h" | 18 #include "base/test/histogram_tester.h" |
| 18 #include "base/test/mock_entropy_provider.h" | 19 #include "base/test/mock_entropy_provider.h" |
| 19 #include "base/test/scoped_feature_list.h" | 20 #include "base/test/scoped_feature_list.h" |
| 20 #include "base/test/simple_test_clock.h" | 21 #include "base/test/simple_test_clock.h" |
| 21 #include "base/test/simple_test_tick_clock.h" | 22 #include "base/test/simple_test_tick_clock.h" |
| 22 #include "components/client_update_protocol/ecdsa.h" | 23 #include "components/client_update_protocol/ecdsa.h" |
| 23 #include "components/network_time/network_time_pref_names.h" | 24 #include "components/network_time/network_time_pref_names.h" |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 // FeatureList. Don't get confused! The FieldTrial is reference-counted, | 198 // FeatureList. Don't get confused! The FieldTrial is reference-counted, |
| 198 // and a reference is held by the FieldTrialList. The FieldTrialList and | 199 // and a reference is held by the FieldTrialList. The FieldTrialList and |
| 199 // FeatureList are both singletons. The authorized way to reset the former | 200 // FeatureList are both singletons. The authorized way to reset the former |
| 200 // for testing is to destruct it (above). The latter, by contrast, should | 201 // for testing is to destruct it (above). The latter, by contrast, should |
| 201 // should already start in a clean state and can be manipulated via the | 202 // should already start in a clean state and can be manipulated via the |
| 202 // ScopedFeatureList helper class. If this comment was useful to you | 203 // ScopedFeatureList helper class. If this comment was useful to you |
| 203 // please send me a postcard. | 204 // please send me a postcard. |
| 204 | 205 |
| 205 field_trial_list_.reset(); // Averts a CHECK fail in constructor below. | 206 field_trial_list_.reset(); // Averts a CHECK fail in constructor below. |
| 206 field_trial_list_.reset( | 207 field_trial_list_.reset( |
| 207 new base::FieldTrialList(new base::MockEntropyProvider())); | 208 new base::FieldTrialList( |
| 209 base::MakeUnique<base::MockEntropyProvider>())); |
| 208 // refcounted, and reference held by field_trial_list_. | 210 // refcounted, and reference held by field_trial_list_. |
| 209 base::FieldTrial* trial = base::FieldTrialList::FactoryGetFieldTrial( | 211 base::FieldTrial* trial = base::FieldTrialList::FactoryGetFieldTrial( |
| 210 kTrialName, 100, kGroupName, 1971, 1, 1, | 212 kTrialName, 100, kGroupName, 1971, 1, 1, |
| 211 base::FieldTrial::SESSION_RANDOMIZED, | 213 base::FieldTrial::SESSION_RANDOMIZED, |
| 212 nullptr /* default_group_number */); | 214 nullptr /* default_group_number */); |
| 213 ASSERT_TRUE( | 215 ASSERT_TRUE( |
| 214 variations::AssociateVariationParams(kTrialName, kGroupName, params)); | 216 variations::AssociateVariationParams(kTrialName, kGroupName, params)); |
| 215 | 217 |
| 216 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | 218 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| 217 feature_list->RegisterFieldTrialOverride( | 219 feature_list->RegisterFieldTrialOverride( |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 tracker_->WaitForFetchForTesting(123123123); | 728 tracker_->WaitForFetchForTesting(123123123); |
| 727 EXPECT_EQ(NetworkTimeTracker::NETWORK_TIME_AVAILABLE, | 729 EXPECT_EQ(NetworkTimeTracker::NETWORK_TIME_AVAILABLE, |
| 728 tracker_->GetNetworkTime(&out_network_time, nullptr)); | 730 tracker_->GetNetworkTime(&out_network_time, nullptr)); |
| 729 | 731 |
| 730 histograms.ExpectTotalCount(kFetchFailedHistogram, 1); | 732 histograms.ExpectTotalCount(kFetchFailedHistogram, 1); |
| 731 histograms.ExpectTotalCount(kFetchValidHistogram, 1); | 733 histograms.ExpectTotalCount(kFetchValidHistogram, 1); |
| 732 histograms.ExpectBucketCount(kFetchValidHistogram, true, 1); | 734 histograms.ExpectBucketCount(kFetchValidHistogram, true, 1); |
| 733 } | 735 } |
| 734 | 736 |
| 735 } // namespace network_time | 737 } // namespace network_time |
| OLD | NEW |