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

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

Issue 2421143002: Fix broken clockstate.network2 histogram and add unit test (Closed)
Patch Set: meacer suggestion: move field trial into test util Created 4 years, 2 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/network_time/network_time_test_utils.h"
6
7 #include "base/feature_list.h"
8 #include "base/memory/ptr_util.h"
9 #include "base/metrics/field_trial.h"
10 #include "base/strings/string_number_conversions.h"
11 #include "base/test/mock_entropy_provider.h"
12 #include "base/test/scoped_feature_list.h"
13 #include "components/variations/variations_associated_data.h"
14
15 namespace network_time {
16
17 FieldTrialTest::FieldTrialTest() : ::testing::Test() {}
18 FieldTrialTest::~FieldTrialTest() {}
19
20 void FieldTrialTest::SetNetworkQueriesWithVariationsService(
21 bool enable,
22 float query_probability) {
23 const std::string kTrialName = "Trial";
24 const std::string kGroupName = "group";
25 const base::Feature kFeature{"NetworkTimeServiceQuerying",
26 base::FEATURE_DISABLED_BY_DEFAULT};
27
28 // Clear all the things.
29 variations::testing::ClearAllVariationParams();
30
31 std::map<std::string, std::string> params;
32 params["RandomQueryProbability"] = base::DoubleToString(query_probability);
33 params["CheckTimeIntervalSeconds"] = base::Int64ToString(360);
34
35 // There are 3 things here: a FieldTrial, a FieldTrialList, and a
36 // FeatureList. Don't get confused! The FieldTrial is reference-counted,
37 // and a reference is held by the FieldTrialList. The FieldTrialList and
38 // FeatureList are both singletons. The authorized way to reset the former
39 // for testing is to destruct it (above). The latter, by contrast, should
40 // should already start in a clean state and can be manipulated via the
41 // ScopedFeatureList helper class. If this comment was useful to you
42 // please send me a postcard.
43
44 field_trial_list_.reset(); // Averts a CHECK fail in constructor below.
45 field_trial_list_.reset(
46 new base::FieldTrialList(base::MakeUnique<base::MockEntropyProvider>()));
47 // refcounted, and reference held by field_trial_list_.
48 base::FieldTrial* trial = base::FieldTrialList::FactoryGetFieldTrial(
49 kTrialName, 100, kGroupName, 1971, 1, 1,
50 base::FieldTrial::SESSION_RANDOMIZED, nullptr /* default_group_number */);
51 ASSERT_TRUE(
52 variations::AssociateVariationParams(kTrialName, kGroupName, params));
53
54 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
55 feature_list->RegisterFieldTrialOverride(
56 kFeature.name, enable ? base::FeatureList::OVERRIDE_ENABLE_FEATURE
57 : base::FeatureList::OVERRIDE_DISABLE_FEATURE,
58 trial);
59 scoped_feature_list_.reset(new base::test::ScopedFeatureList);
60 scoped_feature_list_->InitWithFeatureList(std::move(feature_list));
61 }
62
63 } // namespace network_time
OLDNEW
« no previous file with comments | « components/network_time/network_time_test_utils.h ('k') | components/network_time/network_time_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698