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> |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 void ExpectDefaultInvocation() const { | 74 void ExpectDefaultInvocation() const { |
75 EXPECT_EQ(default_version_, launched_version_); | 75 EXPECT_EQ(default_version_, launched_version_); |
76 ASSERT_EQ(1U, launched_invocations_.size()); | 76 ASSERT_EQ(1U, launched_invocations_.size()); |
77 | 77 |
78 const SwReporterInvocation& invocation = launched_invocations_.front(); | 78 const SwReporterInvocation& invocation = launched_invocations_.front(); |
79 EXPECT_EQ(MakeTestFilePath(default_path_), | 79 EXPECT_EQ(MakeTestFilePath(default_path_), |
80 invocation.command_line.GetProgram()); | 80 invocation.command_line.GetProgram()); |
81 EXPECT_TRUE(invocation.command_line.GetSwitches().empty()); | 81 EXPECT_TRUE(invocation.command_line.GetSwitches().empty()); |
82 EXPECT_TRUE(invocation.command_line.GetArgs().empty()); | 82 EXPECT_TRUE(invocation.command_line.GetArgs().empty()); |
83 EXPECT_TRUE(invocation.suffix.empty()); | 83 EXPECT_TRUE(invocation.suffix.empty()); |
84 EXPECT_EQ(SwReporterInvocation::FLAG_LOG_TO_RAPPOR | | 84 EXPECT_EQ(SwReporterInvocation::BEHAVIOUR_LOG_TO_RAPPOR | |
85 SwReporterInvocation::FLAG_LOG_EXIT_CODE_TO_PREFS | | 85 SwReporterInvocation::BEHAVIOUR_LOG_EXIT_CODE_TO_PREFS | |
86 SwReporterInvocation::FLAG_TRIGGER_PROMPT | | 86 SwReporterInvocation::BEHAVIOUR_TRIGGER_PROMPT | |
87 SwReporterInvocation::FLAG_SEND_REPORTER_LOGS, | 87 SwReporterInvocation::BEHAVIOUR_ALLOW_SEND_REPORTER_LOGS, |
88 invocation.flags); | 88 invocation.supported_behaviours); |
89 } | 89 } |
90 | 90 |
91 // |ComponentReady| asserts that it is run on the UI thread, so we must | 91 // |ComponentReady| asserts that it is run on the UI thread, so we must |
92 // create test threads before calling it. | 92 // create test threads before calling it. |
93 content::TestBrowserThreadBundle threads_; | 93 content::TestBrowserThreadBundle threads_; |
94 | 94 |
95 // Bound callback to the |SwReporterLaunched| method. | 95 // Bound callback to the |SwReporterLaunched| method. |
96 SwReporterRunner launched_callback_; | 96 SwReporterRunner launched_callback_; |
97 | 97 |
98 // Default parameters for |ComponentReady|. | 98 // Default parameters for |ComponentReady|. |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 } | 181 } |
182 | 182 |
183 if (expected_additional_argument.empty()) { | 183 if (expected_additional_argument.empty()) { |
184 EXPECT_TRUE(invocation.command_line.GetArgs().empty()); | 184 EXPECT_TRUE(invocation.command_line.GetArgs().empty()); |
185 } else { | 185 } else { |
186 EXPECT_EQ(1U, invocation.command_line.GetArgs().size()); | 186 EXPECT_EQ(1U, invocation.command_line.GetArgs().size()); |
187 EXPECT_EQ(expected_additional_argument, | 187 EXPECT_EQ(expected_additional_argument, |
188 invocation.command_line.GetArgs()[0]); | 188 invocation.command_line.GetArgs()[0]); |
189 } | 189 } |
190 | 190 |
191 EXPECT_EQ(0U, invocation.flags); | 191 EXPECT_EQ(0U, invocation.supported_behaviours); |
192 histograms_.ExpectTotalCount(kErrorHistogramName, 0); | 192 histograms_.ExpectTotalCount(kErrorHistogramName, 0); |
193 } | 193 } |
194 | 194 |
195 void ExpectLaunchError() { | 195 void ExpectLaunchError() { |
196 // The SwReporter should not be launched, and an error should be logged. | 196 // The SwReporter should not be launched, and an error should be logged. |
197 EXPECT_TRUE(launched_invocations_.empty()); | 197 EXPECT_TRUE(launched_invocations_.empty()); |
198 histograms_.ExpectUniqueSample(kErrorHistogramName, | 198 histograms_.ExpectUniqueSample(kErrorHistogramName, |
199 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1); | 199 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1); |
200 } | 200 } |
201 | 201 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 EXPECT_EQ(MakeTestFilePath(default_path_), | 294 EXPECT_EQ(MakeTestFilePath(default_path_), |
295 invocation.command_line.GetProgram()); | 295 invocation.command_line.GetProgram()); |
296 EXPECT_EQ(2U, invocation.command_line.GetSwitches().size()); | 296 EXPECT_EQ(2U, invocation.command_line.GetSwitches().size()); |
297 EXPECT_EQ("experimental", | 297 EXPECT_EQ("experimental", |
298 invocation.command_line.GetSwitchValueASCII("engine")); | 298 invocation.command_line.GetSwitchValueASCII("engine")); |
299 EXPECT_EQ("TestSuffix", | 299 EXPECT_EQ("TestSuffix", |
300 invocation.command_line.GetSwitchValueASCII(kRegistrySuffixSwitch)); | 300 invocation.command_line.GetSwitchValueASCII(kRegistrySuffixSwitch)); |
301 ASSERT_EQ(1U, invocation.command_line.GetArgs().size()); | 301 ASSERT_EQ(1U, invocation.command_line.GetArgs().size()); |
302 EXPECT_EQ(L"random argument", invocation.command_line.GetArgs()[0]); | 302 EXPECT_EQ(L"random argument", invocation.command_line.GetArgs()[0]); |
303 EXPECT_EQ("TestSuffix", invocation.suffix); | 303 EXPECT_EQ("TestSuffix", invocation.suffix); |
304 EXPECT_EQ(0U, invocation.flags); | 304 EXPECT_EQ(0U, invocation.supported_behaviours); |
305 histograms_.ExpectTotalCount(kErrorHistogramName, 0); | 305 histograms_.ExpectTotalCount(kErrorHistogramName, 0); |
306 } | 306 } |
307 | 307 |
308 TEST_F(ExperimentalSwReporterInstallerTest, MultipleInvocations) { | 308 TEST_F(ExperimentalSwReporterInstallerTest, MultipleInvocations) { |
309 SwReporterInstallerTraits traits(launched_callback_, true); | 309 SwReporterInstallerTraits traits(launched_callback_, true); |
310 CreateFeatureWithTag(kExperimentTag); | 310 CreateFeatureWithTag(kExperimentTag); |
311 ExpectAttributesWithTag(traits, kExperimentTag); | 311 ExpectAttributesWithTag(traits, kExperimentTag); |
312 | 312 |
313 static constexpr char kTestManifest[] = | 313 static constexpr char kTestManifest[] = |
314 "{\"launch_params\": [" | 314 "{\"launch_params\": [" |
(...skipping 26 matching lines...) Expand all Loading... |
341 EXPECT_EQ(MakeTestFilePath(default_path_), | 341 EXPECT_EQ(MakeTestFilePath(default_path_), |
342 invocation.command_line.GetProgram()); | 342 invocation.command_line.GetProgram()); |
343 EXPECT_EQ(2U, invocation.command_line.GetSwitches().size()); | 343 EXPECT_EQ(2U, invocation.command_line.GetSwitches().size()); |
344 EXPECT_EQ("experimental", | 344 EXPECT_EQ("experimental", |
345 invocation.command_line.GetSwitchValueASCII("engine")); | 345 invocation.command_line.GetSwitchValueASCII("engine")); |
346 EXPECT_EQ("TestSuffix", invocation.command_line.GetSwitchValueASCII( | 346 EXPECT_EQ("TestSuffix", invocation.command_line.GetSwitchValueASCII( |
347 kRegistrySuffixSwitch)); | 347 kRegistrySuffixSwitch)); |
348 ASSERT_EQ(1U, invocation.command_line.GetArgs().size()); | 348 ASSERT_EQ(1U, invocation.command_line.GetArgs().size()); |
349 EXPECT_EQ(L"random argument", invocation.command_line.GetArgs()[0]); | 349 EXPECT_EQ(L"random argument", invocation.command_line.GetArgs()[0]); |
350 EXPECT_EQ("TestSuffix", invocation.suffix); | 350 EXPECT_EQ("TestSuffix", invocation.suffix); |
351 EXPECT_EQ(0U, invocation.flags); | 351 EXPECT_EQ(0U, invocation.supported_behaviours); |
352 } | 352 } |
353 | 353 |
354 { | 354 { |
355 SwReporterInvocation invocation = launched_invocations_.front(); | 355 SwReporterInvocation invocation = launched_invocations_.front(); |
356 launched_invocations_.pop(); | 356 launched_invocations_.pop(); |
357 EXPECT_EQ(MakeTestFilePath(default_path_), | 357 EXPECT_EQ(MakeTestFilePath(default_path_), |
358 invocation.command_line.GetProgram()); | 358 invocation.command_line.GetProgram()); |
359 EXPECT_EQ(2U, invocation.command_line.GetSwitches().size()); | 359 EXPECT_EQ(2U, invocation.command_line.GetSwitches().size()); |
360 EXPECT_EQ("second", invocation.command_line.GetSwitchValueASCII("engine")); | 360 EXPECT_EQ("second", invocation.command_line.GetSwitchValueASCII("engine")); |
361 EXPECT_EQ("SecondSuffix", invocation.command_line.GetSwitchValueASCII( | 361 EXPECT_EQ("SecondSuffix", invocation.command_line.GetSwitchValueASCII( |
362 kRegistrySuffixSwitch)); | 362 kRegistrySuffixSwitch)); |
363 ASSERT_TRUE(invocation.command_line.GetArgs().empty()); | 363 ASSERT_TRUE(invocation.command_line.GetArgs().empty()); |
364 EXPECT_EQ("SecondSuffix", invocation.suffix); | 364 EXPECT_EQ("SecondSuffix", invocation.suffix); |
365 EXPECT_EQ(SwReporterInvocation::FLAG_TRIGGER_PROMPT, invocation.flags); | 365 EXPECT_EQ(SwReporterInvocation::BEHAVIOUR_TRIGGER_PROMPT, |
| 366 invocation.supported_behaviours); |
366 } | 367 } |
367 | 368 |
368 { | 369 { |
369 SwReporterInvocation invocation = launched_invocations_.front(); | 370 SwReporterInvocation invocation = launched_invocations_.front(); |
370 launched_invocations_.pop(); | 371 launched_invocations_.pop(); |
371 EXPECT_EQ(MakeTestFilePath(default_path_), | 372 EXPECT_EQ(MakeTestFilePath(default_path_), |
372 invocation.command_line.GetProgram()); | 373 invocation.command_line.GetProgram()); |
373 EXPECT_EQ(2U, invocation.command_line.GetSwitches().size()); | 374 EXPECT_EQ(2U, invocation.command_line.GetSwitches().size()); |
374 EXPECT_EQ("third", invocation.command_line.GetSwitchValueASCII("engine")); | 375 EXPECT_EQ("third", invocation.command_line.GetSwitchValueASCII("engine")); |
375 EXPECT_EQ("ThirdSuffix", invocation.command_line.GetSwitchValueASCII( | 376 EXPECT_EQ("ThirdSuffix", invocation.command_line.GetSwitchValueASCII( |
376 kRegistrySuffixSwitch)); | 377 kRegistrySuffixSwitch)); |
377 ASSERT_TRUE(invocation.command_line.GetArgs().empty()); | 378 ASSERT_TRUE(invocation.command_line.GetArgs().empty()); |
378 EXPECT_EQ("ThirdSuffix", invocation.suffix); | 379 EXPECT_EQ("ThirdSuffix", invocation.suffix); |
379 // A missing "prompt" key means "false". | 380 // A missing "prompt" key means "false". |
380 EXPECT_EQ(0U, invocation.flags); | 381 EXPECT_EQ(0U, invocation.supported_behaviours); |
381 } | 382 } |
382 | 383 |
383 histograms_.ExpectTotalCount(kErrorHistogramName, 0); | 384 histograms_.ExpectTotalCount(kErrorHistogramName, 0); |
384 } | 385 } |
385 | 386 |
386 TEST_F(ExperimentalSwReporterInstallerTest, MissingSuffix) { | 387 TEST_F(ExperimentalSwReporterInstallerTest, MissingSuffix) { |
387 SwReporterInstallerTraits traits(launched_callback_, true); | 388 SwReporterInstallerTraits traits(launched_callback_, true); |
388 CreateFeatureWithTag(kExperimentTag); | 389 CreateFeatureWithTag(kExperimentTag); |
389 | 390 |
390 static constexpr char kTestManifest[] = | 391 static constexpr char kTestManifest[] = |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 traits.ComponentReady( | 698 traits.ComponentReady( |
698 default_version_, default_path_, | 699 default_version_, default_path_, |
699 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); | 700 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); |
700 | 701 |
701 // The SwReporter should not be launched, and an error should be logged. | 702 // The SwReporter should not be launched, and an error should be logged. |
702 EXPECT_TRUE(launched_invocations_.empty()); | 703 EXPECT_TRUE(launched_invocations_.empty()); |
703 histograms_.ExpectUniqueSample(kErrorHistogramName, | 704 histograms_.ExpectUniqueSample(kErrorHistogramName, |
704 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1); | 705 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1); |
705 } | 706 } |
706 } // namespace component_updater | 707 } // namespace component_updater |
OLD | NEW |