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

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

Issue 2831103002: Move shared constants to //components/chrome_cleaner (Closed)
Patch Set: Created 3 years, 8 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 "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/chrome_cleaner/public/constants/constants.h"
26 #include "components/variations/variations_params_manager.h" 27 #include "components/variations/variations_params_manager.h"
27 #include "content/public/test/test_browser_thread_bundle.h" 28 #include "content/public/test/test_browser_thread_bundle.h"
28 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
29 30
30 namespace component_updater { 31 namespace component_updater {
31 32
32 namespace { 33 namespace {
33 34
34 constexpr char kExperimentGroupName[] = "my_test_engine_group"; 35 constexpr char kExperimentGroupName[] = "my_test_engine_group";
35 36
36 constexpr char kEngineExperimentGroupSwitch[] = "engine-experiment-group";
37 constexpr char kRegistrySuffixSwitch[] = "registry-suffix";
38 constexpr char kSessionIdSwitch[] = "session-id";
39
40 constexpr char kErrorHistogramName[] = "SoftwareReporter.ExperimentErrors"; 37 constexpr char kErrorHistogramName[] = "SoftwareReporter.ExperimentErrors";
41 constexpr char kExperimentTag[] = "experiment_tag"; 38 constexpr char kExperimentTag[] = "experiment_tag";
42 constexpr char kMissingTag[] = "missing_tag"; 39 constexpr char kMissingTag[] = "missing_tag";
43 40
44 using safe_browsing::SwReporterInvocation; 41 using safe_browsing::SwReporterInvocation;
45 42
46 } // namespace 43 } // namespace
47 44
48 class SwReporterInstallerTest : public ::testing::Test { 45 class SwReporterInstallerTest : public ::testing::Test {
49 public: 46 public:
(...skipping 28 matching lines...) Expand all
78 // Expects that the SwReporter was launched exactly once, with a session-id 75 // Expects that the SwReporter was launched exactly once, with a session-id
79 // switch. 76 // switch.
80 void ExpectDefaultInvocation() const { 77 void ExpectDefaultInvocation() const {
81 EXPECT_EQ(default_version_, launched_version_); 78 EXPECT_EQ(default_version_, launched_version_);
82 ASSERT_EQ(1U, launched_invocations_.size()); 79 ASSERT_EQ(1U, launched_invocations_.size());
83 80
84 const SwReporterInvocation& invocation = launched_invocations_.front(); 81 const SwReporterInvocation& invocation = launched_invocations_.front();
85 EXPECT_EQ(MakeTestFilePath(default_path_), 82 EXPECT_EQ(MakeTestFilePath(default_path_),
86 invocation.command_line.GetProgram()); 83 invocation.command_line.GetProgram());
87 EXPECT_EQ(1U, invocation.command_line.GetSwitches().size()); 84 EXPECT_EQ(1U, invocation.command_line.GetSwitches().size());
88 EXPECT_EQ( 85 EXPECT_EQ(40U, invocation.command_line
89 40U, 86 .GetSwitchValueASCII(chrome_cleaner::kSessionIdSwitch)
90 invocation.command_line.GetSwitchValueASCII(kSessionIdSwitch).size()); 87 .size());
91 EXPECT_TRUE(invocation.command_line.GetArgs().empty()); 88 EXPECT_TRUE(invocation.command_line.GetArgs().empty());
92 EXPECT_TRUE(invocation.suffix.empty()); 89 EXPECT_TRUE(invocation.suffix.empty());
93 EXPECT_EQ(SwReporterInvocation::BEHAVIOUR_LOG_EXIT_CODE_TO_PREFS | 90 EXPECT_EQ(SwReporterInvocation::BEHAVIOUR_LOG_EXIT_CODE_TO_PREFS |
94 SwReporterInvocation::BEHAVIOUR_TRIGGER_PROMPT | 91 SwReporterInvocation::BEHAVIOUR_TRIGGER_PROMPT |
95 SwReporterInvocation::BEHAVIOUR_ALLOW_SEND_REPORTER_LOGS, 92 SwReporterInvocation::BEHAVIOUR_ALLOW_SEND_REPORTER_LOGS,
96 invocation.supported_behaviours); 93 invocation.supported_behaviours);
97 } 94 }
98 95
99 // |ComponentReady| asserts that it is run on the UI thread, so we must 96 // |ComponentReady| asserts that it is run on the UI thread, so we must
100 // create test threads before calling it. 97 // create test threads before calling it.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 // arguments and switches in this function.) 164 // arguments and switches in this function.)
168 void ExpectExperimentalInvocation( 165 void ExpectExperimentalInvocation(
169 const std::string& expected_suffix, 166 const std::string& expected_suffix,
170 const base::string16& expected_additional_argument) { 167 const base::string16& expected_additional_argument) {
171 EXPECT_EQ(default_version_, launched_version_); 168 EXPECT_EQ(default_version_, launched_version_);
172 ASSERT_EQ(1U, launched_invocations_.size()); 169 ASSERT_EQ(1U, launched_invocations_.size());
173 170
174 const SwReporterInvocation& invocation = launched_invocations_.front(); 171 const SwReporterInvocation& invocation = launched_invocations_.front();
175 EXPECT_EQ(MakeTestFilePath(default_path_), 172 EXPECT_EQ(MakeTestFilePath(default_path_),
176 invocation.command_line.GetProgram()); 173 invocation.command_line.GetProgram());
177 EXPECT_EQ( 174 EXPECT_EQ(40U, invocation.command_line
178 40U, 175 .GetSwitchValueASCII(chrome_cleaner::kSessionIdSwitch)
179 invocation.command_line.GetSwitchValueASCII(kSessionIdSwitch).size()); 176 .size());
180 EXPECT_EQ(kExperimentGroupName, invocation.command_line.GetSwitchValueASCII( 177 EXPECT_EQ(kExperimentGroupName,
181 kEngineExperimentGroupSwitch)); 178 invocation.command_line.GetSwitchValueASCII(
179 chrome_cleaner::kEngineExperimentGroupSwitch));
182 180
183 if (expected_suffix.empty()) { 181 if (expected_suffix.empty()) {
184 EXPECT_EQ(2U, invocation.command_line.GetSwitches().size()); 182 EXPECT_EQ(2U, invocation.command_line.GetSwitches().size());
185 EXPECT_TRUE(invocation.suffix.empty()); 183 EXPECT_TRUE(invocation.suffix.empty());
186 } else { 184 } else {
187 EXPECT_EQ(3U, invocation.command_line.GetSwitches().size()); 185 EXPECT_EQ(3U, invocation.command_line.GetSwitches().size());
188 EXPECT_EQ(expected_suffix, invocation.command_line.GetSwitchValueASCII( 186 EXPECT_EQ(expected_suffix, invocation.command_line.GetSwitchValueASCII(
189 kRegistrySuffixSwitch)); 187 chrome_cleaner::kRegistrySuffixSwitch));
190 EXPECT_EQ(expected_suffix, invocation.suffix); 188 EXPECT_EQ(expected_suffix, invocation.suffix);
191 } 189 }
192 190
193 if (expected_additional_argument.empty()) { 191 if (expected_additional_argument.empty()) {
194 EXPECT_TRUE(invocation.command_line.GetArgs().empty()); 192 EXPECT_TRUE(invocation.command_line.GetArgs().empty());
195 } else { 193 } else {
196 EXPECT_EQ(1U, invocation.command_line.GetArgs().size()); 194 EXPECT_EQ(1U, invocation.command_line.GetArgs().size());
197 EXPECT_EQ(expected_additional_argument, 195 EXPECT_EQ(expected_additional_argument,
198 invocation.command_line.GetArgs()[0]); 196 invocation.command_line.GetArgs()[0]);
199 } 197 }
(...skipping 14 matching lines...) Expand all
214 SwReporterInvocation invocation = launched_invocations_.front(); 212 SwReporterInvocation invocation = launched_invocations_.front();
215 launched_invocations_.pop(); 213 launched_invocations_.pop();
216 EXPECT_EQ(MakeTestFilePath(default_path_), 214 EXPECT_EQ(MakeTestFilePath(default_path_),
217 invocation.command_line.GetProgram()); 215 invocation.command_line.GetProgram());
218 // There should be one switch added from the manifest, plus registry-suffix 216 // There should be one switch added from the manifest, plus registry-suffix
219 // added automatically. 217 // added automatically.
220 EXPECT_EQ(4U, invocation.command_line.GetSwitches().size()); 218 EXPECT_EQ(4U, invocation.command_line.GetSwitches().size());
221 EXPECT_EQ(expected_engine, 219 EXPECT_EQ(expected_engine,
222 invocation.command_line.GetSwitchValueASCII("engine")); 220 invocation.command_line.GetSwitchValueASCII("engine"));
223 EXPECT_EQ(expected_suffix, invocation.command_line.GetSwitchValueASCII( 221 EXPECT_EQ(expected_suffix, invocation.command_line.GetSwitchValueASCII(
224 kRegistrySuffixSwitch)); 222 chrome_cleaner::kRegistrySuffixSwitch));
225 *out_session_id = 223 *out_session_id = invocation.command_line.GetSwitchValueASCII(
226 invocation.command_line.GetSwitchValueASCII(kSessionIdSwitch); 224 chrome_cleaner::kSessionIdSwitch);
227 EXPECT_EQ(40U, out_session_id->size()); 225 EXPECT_EQ(40U, out_session_id->size());
228 EXPECT_EQ(kExperimentGroupName, invocation.command_line.GetSwitchValueASCII( 226 EXPECT_EQ(kExperimentGroupName,
229 kEngineExperimentGroupSwitch)); 227 invocation.command_line.GetSwitchValueASCII(
228 chrome_cleaner::kEngineExperimentGroupSwitch));
230 ASSERT_TRUE(invocation.command_line.GetArgs().empty()); 229 ASSERT_TRUE(invocation.command_line.GetArgs().empty());
231 EXPECT_EQ(expected_suffix, invocation.suffix); 230 EXPECT_EQ(expected_suffix, invocation.suffix);
232 EXPECT_EQ(expected_behaviours, invocation.supported_behaviours); 231 EXPECT_EQ(expected_behaviours, invocation.supported_behaviours);
233 } 232 }
234 233
235 void ExpectLaunchError() { 234 void ExpectLaunchError() {
236 // The SwReporter should not be launched, and an error should be logged. 235 // The SwReporter should not be launched, and an error should be logged.
237 EXPECT_TRUE(launched_invocations_.empty()); 236 EXPECT_TRUE(launched_invocations_.empty());
238 histograms_.ExpectUniqueSample(kErrorHistogramName, 237 histograms_.ExpectUniqueSample(kErrorHistogramName,
239 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1); 238 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 // The SwReporter should be launched once with the given arguments. 328 // The SwReporter should be launched once with the given arguments.
330 EXPECT_EQ(default_version_, launched_version_); 329 EXPECT_EQ(default_version_, launched_version_);
331 ASSERT_EQ(1U, launched_invocations_.size()); 330 ASSERT_EQ(1U, launched_invocations_.size());
332 331
333 const SwReporterInvocation& invocation = launched_invocations_.front(); 332 const SwReporterInvocation& invocation = launched_invocations_.front();
334 EXPECT_EQ(MakeTestFilePath(default_path_), 333 EXPECT_EQ(MakeTestFilePath(default_path_),
335 invocation.command_line.GetProgram()); 334 invocation.command_line.GetProgram());
336 EXPECT_EQ(4U, invocation.command_line.GetSwitches().size()); 335 EXPECT_EQ(4U, invocation.command_line.GetSwitches().size());
337 EXPECT_EQ("experimental", 336 EXPECT_EQ("experimental",
338 invocation.command_line.GetSwitchValueASCII("engine")); 337 invocation.command_line.GetSwitchValueASCII("engine"));
339 EXPECT_EQ("TestSuffix", 338 EXPECT_EQ("TestSuffix", invocation.command_line.GetSwitchValueASCII(
340 invocation.command_line.GetSwitchValueASCII(kRegistrySuffixSwitch)); 339 chrome_cleaner::kRegistrySuffixSwitch));
341 EXPECT_EQ( 340 EXPECT_EQ(40U, invocation.command_line
342 40U, 341 .GetSwitchValueASCII(chrome_cleaner::kSessionIdSwitch)
343 invocation.command_line.GetSwitchValueASCII(kSessionIdSwitch).size()); 342 .size());
344 EXPECT_EQ(kExperimentGroupName, invocation.command_line.GetSwitchValueASCII( 343 EXPECT_EQ(kExperimentGroupName,
345 kEngineExperimentGroupSwitch)); 344 invocation.command_line.GetSwitchValueASCII(
345 chrome_cleaner::kEngineExperimentGroupSwitch));
346 ASSERT_EQ(1U, invocation.command_line.GetArgs().size()); 346 ASSERT_EQ(1U, invocation.command_line.GetArgs().size());
347 EXPECT_EQ(L"random argument", invocation.command_line.GetArgs()[0]); 347 EXPECT_EQ(L"random argument", invocation.command_line.GetArgs()[0]);
348 EXPECT_EQ("TestSuffix", invocation.suffix); 348 EXPECT_EQ("TestSuffix", invocation.suffix);
349 EXPECT_EQ(0U, invocation.supported_behaviours); 349 EXPECT_EQ(0U, invocation.supported_behaviours);
350 histograms_.ExpectTotalCount(kErrorHistogramName, 0); 350 histograms_.ExpectTotalCount(kErrorHistogramName, 0);
351 } 351 }
352 352
353 TEST_F(ExperimentalSwReporterInstallerTest, MultipleInvocations) { 353 TEST_F(ExperimentalSwReporterInstallerTest, MultipleInvocations) {
354 SwReporterInstallerTraits traits(launched_callback_, true); 354 SwReporterInstallerTraits traits(launched_callback_, true);
355 CreateFeatureWithTag(kExperimentTag); 355 CreateFeatureWithTag(kExperimentTag);
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 traits.ComponentReady( 729 traits.ComponentReady(
730 default_version_, default_path_, 730 default_version_, default_path_,
731 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); 731 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest)));
732 732
733 // 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.
734 EXPECT_TRUE(launched_invocations_.empty()); 734 EXPECT_TRUE(launched_invocations_.empty());
735 histograms_.ExpectUniqueSample(kErrorHistogramName, 735 histograms_.ExpectUniqueSample(kErrorHistogramName,
736 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1); 736 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1);
737 } 737 }
738 } // namespace component_updater 738 } // namespace component_updater
OLDNEW
« no previous file with comments | « chrome/browser/component_updater/sw_reporter_installer_win.cc ('k') | components/chrome_cleaner/public/constants/constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698