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

Side by Side Diff: chrome/browser/component_updater/sw_reporter_installer_win_unittest.cc

Issue 2321273003: Extend VariationParamsManager to support feature associations. (Closed)
Patch Set: Fixing windows build? 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
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 "chrome/browser/component_updater/sw_reporter_installer_win.h" 5 #include "chrome/browser/component_updater/sw_reporter_installer_win.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/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/feature_list.h" 15 #include "base/feature_list.h"
16 #include "base/files/file_path.h" 16 #include "base/files/file_path.h"
17 #include "base/json/json_reader.h" 17 #include "base/json/json_reader.h"
18 #include "base/macros.h" 18 #include "base/macros.h"
19 #include "base/metrics/field_trial.h" 19 #include "base/metrics/field_trial.h"
20 #include "base/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
21 #include "base/test/histogram_tester.h" 21 #include "base/test/histogram_tester.h"
22 #include "base/test/scoped_feature_list.h" 22 #include "base/test/scoped_feature_list.h"
23 #include "base/values.h" 23 #include "base/values.h"
24 #include "base/version.h" 24 #include "base/version.h"
25 #include "chrome/browser/safe_browsing/srt_fetcher_win.h" 25 #include "chrome/browser/safe_browsing/srt_fetcher_win.h"
26 #include "components/variations/variations_associated_data.h" 26 #include "components/variations/variations_params_manager.h"
27 #include "content/public/test/test_browser_thread_bundle.h" 27 #include "content/public/test/test_browser_thread_bundle.h"
28 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
29 29
30 namespace component_updater { 30 namespace component_updater {
31 31
32 namespace { 32 namespace {
33 33
34 constexpr char kExperimentGroupName[] = "my_test_engine_group"; 34 constexpr char kExperimentGroupName[] = "my_test_engine_group";
35 35
36 constexpr char kEngineExperimentGroupSwitch[] = "engine-experiment-group"; 36 constexpr char kEngineExperimentGroupSwitch[] = "engine-experiment-group";
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 } 130 }
131 131
132 void CreateFeatureWithTag(const std::string& tag) { 132 void CreateFeatureWithTag(const std::string& tag) {
133 std::map<std::string, std::string> params; 133 std::map<std::string, std::string> params;
134 params["tag"] = tag; 134 params["tag"] = tag;
135 CreateFeatureWithParams(params); 135 CreateFeatureWithParams(params);
136 } 136 }
137 137
138 void CreateFeatureWithParams( 138 void CreateFeatureWithParams(
139 const std::map<std::string, std::string>& params) { 139 const std::map<std::string, std::string>& params) {
140 constexpr char kFeatureName[] = "ExperimentalSwReporterEngine"; 140 constexpr char kFeatureName[] = "ExperimentalSwReporterEngine";
Alexei Svitkine (slow) 2016/11/24 19:29:40 Nit: Rename to kFeatureAndTrialName
jkrcal 2016/11/25 13:23:37 Done.
141 141
142 std::map<std::string, std::string> params_with_group = params; 142 std::map<std::string, std::string> params_with_group = params;
143 params_with_group["experiment_group_for_reporting"] = kExperimentGroupName; 143 params_with_group["experiment_group_for_reporting"] = kExperimentGroupName;
144 144
145 // Assign the given variation params to the experiment group until 145 // Assign the given variation params to the experiment group until
146 // |variations_| goes out of scope when the test exits. This will also 146 // |variations_| goes out of scope when the test exits. This will also
147 // create a FieldTrial for this group. 147 // create a FieldTrial for this group and associate the params with the
148 // feature.
148 variations_ = std::make_unique<variations::testing::VariationParamsManager>( 149 variations_ = std::make_unique<variations::testing::VariationParamsManager>(
149 kFeatureName, params_with_group); 150 kFeatureName /*trial_name*/, params_with_group,
150 151 std::set<std::string>{kFeatureName} /*associated_features*/);
151 // Create a feature list containing only the field trial for this group,
152 // and enable it for the length of the test.
153 base::FieldTrial* trial = base::FieldTrialList::Find(kFeatureName);
154 ASSERT_TRUE(trial);
155 auto feature_list = std::make_unique<base::FeatureList>();
156 feature_list->RegisterFieldTrialOverride(
157 kFeatureName, base::FeatureList::OVERRIDE_ENABLE_FEATURE, trial);
158 scoped_feature_list_.InitWithFeatureList(std::move(feature_list));
159 } 152 }
160 153
161 void ExpectAttributesWithTag(const SwReporterInstallerTraits& traits, 154 void ExpectAttributesWithTag(const SwReporterInstallerTraits& traits,
162 const std::string& tag) { 155 const std::string& tag) {
163 update_client::InstallerAttributes attributes = 156 update_client::InstallerAttributes attributes =
164 traits.GetInstallerAttributes(); 157 traits.GetInstallerAttributes();
165 EXPECT_EQ(1U, attributes.size()); 158 EXPECT_EQ(1U, attributes.size());
166 EXPECT_EQ(tag, attributes["tag"]); 159 EXPECT_EQ(tag, attributes["tag"]);
167 } 160 }
168 161
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 traits.ComponentReady( 729 traits.ComponentReady(
737 default_version_, default_path_, 730 default_version_, default_path_,
738 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); 731 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest)));
739 732
740 // The SwReporter should not be launched, and an error should be logged. 733 // The SwReporter should not be launched, and an error should be logged.
741 EXPECT_TRUE(launched_invocations_.empty()); 734 EXPECT_TRUE(launched_invocations_.empty());
742 histograms_.ExpectUniqueSample(kErrorHistogramName, 735 histograms_.ExpectUniqueSample(kErrorHistogramName,
743 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1); 736 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1);
744 } 737 }
745 } // namespace component_updater 738 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698