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

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

Issue 2653443002: Update NetworkTimeQueries field trial config (Closed)
Patch Set: meacer suggestion: configure finch via command line Created 3 years, 11 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 2016 The Chromium Authors. All rights reserved. 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 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_test_utils.h" 5 #include "components/network_time/network_time_test_utils.h"
6 6
7 #include "base/feature_list.h" 7 #include "base/feature_list.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 const net::test_server::HttpRequest& request) { 42 const net::test_server::HttpRequest& request) {
43 net::test_server::BasicHttpResponse* response = 43 net::test_server::BasicHttpResponse* response =
44 new net::test_server::BasicHttpResponse(); 44 new net::test_server::BasicHttpResponse();
45 response->set_code(net::HTTP_OK); 45 response->set_code(net::HTTP_OK);
46 response->set_content(kGoodTimeResponseBody); 46 response->set_content(kGoodTimeResponseBody);
47 response->AddCustomHeader("x-cup-server-proof", 47 response->AddCustomHeader("x-cup-server-proof",
48 kGoodTimeResponseServerProofHeader); 48 kGoodTimeResponseServerProofHeader);
49 return std::unique_ptr<net::test_server::HttpResponse>(response); 49 return std::unique_ptr<net::test_server::HttpResponse>(response);
50 } 50 }
51 51
52 FieldTrialTest::FieldTrialTest() {}
53
52 FieldTrialTest::~FieldTrialTest() {} 54 FieldTrialTest::~FieldTrialTest() {}
53 55
54 FieldTrialTest* FieldTrialTest::CreateForUnitTest() {
55 FieldTrialTest* test = new FieldTrialTest();
56 test->create_field_trial_list_ = true;
57 return test;
58 }
59
60 FieldTrialTest* FieldTrialTest::CreateForBrowserTest() {
61 FieldTrialTest* test = new FieldTrialTest();
62 test->create_field_trial_list_ = false;
63 return test;
64 }
65
66 void FieldTrialTest::SetNetworkQueriesWithVariationsService( 56 void FieldTrialTest::SetNetworkQueriesWithVariationsService(
67 bool enable, 57 bool enable,
68 float query_probability, 58 float query_probability,
69 NetworkTimeTracker::FetchBehavior fetch_behavior) { 59 NetworkTimeTracker::FetchBehavior fetch_behavior) {
70 const std::string kTrialName = "Trial"; 60 const std::string kTrialName = "Trial";
71 const std::string kGroupName = "group"; 61 const std::string kGroupName = "group";
72 const base::Feature kFeature{"NetworkTimeServiceQuerying", 62 const base::Feature kFeature{"NetworkTimeServiceQuerying",
73 base::FEATURE_DISABLED_BY_DEFAULT}; 63 base::FEATURE_DISABLED_BY_DEFAULT};
74 64
75 // Clear all the things. 65 // Clear all the things.
(...skipping 22 matching lines...) Expand all
98 88
99 // There are 3 things here: a FieldTrial, a FieldTrialList, and a 89 // There are 3 things here: a FieldTrial, a FieldTrialList, and a
100 // FeatureList. Don't get confused! The FieldTrial is reference-counted, 90 // FeatureList. Don't get confused! The FieldTrial is reference-counted,
101 // and a reference is held by the FieldTrialList. The FieldTrialList and 91 // and a reference is held by the FieldTrialList. The FieldTrialList and
102 // FeatureList are both singletons. The authorized way to reset the former 92 // FeatureList are both singletons. The authorized way to reset the former
103 // for testing is to destruct it (above). The latter, by contrast, should 93 // for testing is to destruct it (above). The latter, by contrast, should
104 // should already start in a clean state and can be manipulated via the 94 // should already start in a clean state and can be manipulated via the
105 // ScopedFeatureList helper class. If this comment was useful to you 95 // ScopedFeatureList helper class. If this comment was useful to you
106 // please send me a postcard. 96 // please send me a postcard.
107 97
108 if (create_field_trial_list_) { 98 field_trial_list_.reset(); // Averts a CHECK fail in constructor below.
meacer 2017/01/23 21:35:54 nit: Is this still needed?
estark 2017/01/23 23:42:38 Err. Probably. I'll try removing it and see if the
109 field_trial_list_.reset(); // Averts a CHECK fail in constructor below. 99 field_trial_list_.reset(
110 field_trial_list_.reset(new base::FieldTrialList( 100 new base::FieldTrialList(base::MakeUnique<base::MockEntropyProvider>()));
111 base::MakeUnique<base::MockEntropyProvider>())); 101
112 }
113 // refcounted, and reference held by the singleton FieldTrialList. 102 // refcounted, and reference held by the singleton FieldTrialList.
114 base::FieldTrial* trial = base::FieldTrialList::FactoryGetFieldTrial( 103 base::FieldTrial* trial = base::FieldTrialList::FactoryGetFieldTrial(
115 kTrialName, 100, kGroupName, 1971, 1, 1, 104 kTrialName, 100, kGroupName, 1971, 1, 1,
116 base::FieldTrial::SESSION_RANDOMIZED, nullptr /* default_group_number */); 105 base::FieldTrial::SESSION_RANDOMIZED, nullptr /* default_group_number */);
117 ASSERT_TRUE( 106 ASSERT_TRUE(
118 variations::AssociateVariationParams(kTrialName, kGroupName, params)); 107 variations::AssociateVariationParams(kTrialName, kGroupName, params));
119 108
120 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); 109 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
121 feature_list->RegisterFieldTrialOverride( 110 feature_list->RegisterFieldTrialOverride(
122 kFeature.name, enable ? base::FeatureList::OVERRIDE_ENABLE_FEATURE 111 kFeature.name, enable ? base::FeatureList::OVERRIDE_ENABLE_FEATURE
123 : base::FeatureList::OVERRIDE_DISABLE_FEATURE, 112 : base::FeatureList::OVERRIDE_DISABLE_FEATURE,
124 trial); 113 trial);
125 scoped_feature_list_.reset(new base::test::ScopedFeatureList); 114 scoped_feature_list_.reset(new base::test::ScopedFeatureList);
126 scoped_feature_list_->InitWithFeatureList(std::move(feature_list)); 115 scoped_feature_list_->InitWithFeatureList(std::move(feature_list));
127 } 116 }
128 117
129 FieldTrialTest::FieldTrialTest() {}
130
131 } // namespace network_time 118 } // 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