| OLD | NEW |
| 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 Loading... |
| 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 kFeatureAndTrialName[] = "ExperimentalSwReporterEngine"; |
| 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 kFeatureAndTrialName, // trial_name |
| 150 | 151 params_with_group, |
| 151 // Create a feature list containing only the field trial for this group, | 152 std::set<std::string>{kFeatureAndTrialName}); // associated_features |
| 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 } | 153 } |
| 160 | 154 |
| 161 void ExpectAttributesWithTag(const SwReporterInstallerTraits& traits, | 155 void ExpectAttributesWithTag(const SwReporterInstallerTraits& traits, |
| 162 const std::string& tag) { | 156 const std::string& tag) { |
| 163 update_client::InstallerAttributes attributes = | 157 update_client::InstallerAttributes attributes = |
| 164 traits.GetInstallerAttributes(); | 158 traits.GetInstallerAttributes(); |
| 165 EXPECT_EQ(1U, attributes.size()); | 159 EXPECT_EQ(1U, attributes.size()); |
| 166 EXPECT_EQ(tag, attributes["tag"]); | 160 EXPECT_EQ(tag, attributes["tag"]); |
| 167 } | 161 } |
| 168 | 162 |
| (...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 736 traits.ComponentReady( | 730 traits.ComponentReady( |
| 737 default_version_, default_path_, | 731 default_version_, default_path_, |
| 738 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); | 732 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); |
| 739 | 733 |
| 740 // The SwReporter should not be launched, and an error should be logged. | 734 // The SwReporter should not be launched, and an error should be logged. |
| 741 EXPECT_TRUE(launched_invocations_.empty()); | 735 EXPECT_TRUE(launched_invocations_.empty()); |
| 742 histograms_.ExpectUniqueSample(kErrorHistogramName, | 736 histograms_.ExpectUniqueSample(kErrorHistogramName, |
| 743 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1); | 737 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1); |
| 744 } | 738 } |
| 745 } // namespace component_updater | 739 } // namespace component_updater |
| OLD | NEW |