| 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 #include <vector> | |
| 12 | 11 |
| 13 #include "base/bind.h" | 12 #include "base/bind.h" |
| 14 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 15 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 16 #include "base/feature_list.h" | 15 #include "base/feature_list.h" |
| 17 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
| 18 #include "base/json/json_reader.h" | 17 #include "base/json/json_reader.h" |
| 19 #include "base/macros.h" | 18 #include "base/macros.h" |
| 20 #include "base/metrics/field_trial.h" | 19 #include "base/metrics/field_trial.h" |
| 21 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
| 22 #include "base/test/histogram_tester.h" | 21 #include "base/test/histogram_tester.h" |
| 23 #include "base/test/scoped_feature_list.h" | 22 #include "base/test/scoped_feature_list.h" |
| 24 #include "base/values.h" | 23 #include "base/values.h" |
| 25 #include "base/version.h" | 24 #include "base/version.h" |
| 26 #include "chrome/browser/safe_browsing/srt_fetcher_win.h" | 25 #include "chrome/browser/safe_browsing/srt_fetcher_win.h" |
| 27 #include "components/variations/variations_associated_data.h" | 26 #include "components/variations/variations_associated_data.h" |
| 28 #include "content/public/test/test_browser_thread_bundle.h" | 27 #include "content/public/test/test_browser_thread_bundle.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 30 | 29 |
| 31 namespace component_updater { | 30 namespace component_updater { |
| 32 | 31 |
| 33 namespace { | 32 namespace { |
| 34 | 33 |
| 35 constexpr char kRegistrySuffixSwitch[] = "registry-suffix"; | 34 constexpr char kRegistrySuffixSwitch[] = "registry-suffix"; |
| 36 constexpr char kErrorHistogramName[] = "SoftwareReporter.ExperimentErrors"; | 35 constexpr char kErrorHistogramName[] = "SoftwareReporter.ExperimentErrors"; |
| 37 constexpr char kExperimentTag[] = "experiment_tag"; | 36 constexpr char kExperimentTag[] = "experiment_tag"; |
| 38 constexpr char kMissingTag[] = "missing_tag"; | 37 constexpr char kMissingTag[] = "missing_tag"; |
| 39 | 38 |
| 39 using safe_browsing::SwReporterInvocation; |
| 40 |
| 40 } // namespace | 41 } // namespace |
| 41 | 42 |
| 42 class SwReporterInstallerTest : public ::testing::Test { | 43 class SwReporterInstallerTest : public ::testing::Test { |
| 43 public: | 44 public: |
| 44 SwReporterInstallerTest() | 45 SwReporterInstallerTest() |
| 45 : launched_callback_( | 46 : launched_callback_( |
| 46 base::Bind(&SwReporterInstallerTest::SwReporterLaunched, | 47 base::Bind(&SwReporterInstallerTest::SwReporterLaunched, |
| 47 base::Unretained(this))), | 48 base::Unretained(this))), |
| 48 default_version_("1.2.3"), | 49 default_version_("1.2.3"), |
| 49 default_path_(L"C:\\full\\path\\to\\download") {} | 50 default_path_(L"C:\\full\\path\\to\\download"), |
| 51 launched_version_("0.0.0") {} |
| 50 | 52 |
| 51 ~SwReporterInstallerTest() override {} | 53 ~SwReporterInstallerTest() override {} |
| 52 | 54 |
| 53 protected: | 55 protected: |
| 54 void SwReporterLaunched(const safe_browsing::SwReporterInvocation& invocation, | 56 void SwReporterLaunched( |
| 55 const base::Version& version) { | 57 std::unique_ptr<safe_browsing::SwReporterQueue> invocations, |
| 56 ASSERT_TRUE(launched_invocations_.empty()); | 58 const base::Version& version) { |
| 57 launched_invocations_.push_back(invocation); | 59 ASSERT_FALSE(launched_invocations_); |
| 60 launched_invocations_ = std::move(invocations); |
| 58 launched_version_ = version; | 61 launched_version_ = version; |
| 59 } | 62 } |
| 60 | 63 |
| 61 base::FilePath MakeTestFilePath(const base::FilePath& path) const { | 64 base::FilePath MakeTestFilePath(const base::FilePath& path) const { |
| 62 return path.Append(L"software_reporter_tool.exe"); | 65 return path.Append(L"software_reporter_tool.exe"); |
| 63 } | 66 } |
| 64 | 67 |
| 65 void ExpectEmptyAttributes(const SwReporterInstallerTraits& traits) const { | 68 void ExpectEmptyAttributes(const SwReporterInstallerTraits& traits) const { |
| 66 update_client::InstallerAttributes attributes = | 69 update_client::InstallerAttributes attributes = |
| 67 traits.GetInstallerAttributes(); | 70 traits.GetInstallerAttributes(); |
| 68 EXPECT_TRUE(attributes.empty()); | 71 EXPECT_TRUE(attributes.empty()); |
| 69 } | 72 } |
| 70 | 73 |
| 71 // Expects that the SwReporter was launched exactly once, with no arguments. | 74 // Expects that the SwReporter was launched exactly once, with no arguments. |
| 72 void ExpectDefaultInvocation() const { | 75 void ExpectDefaultInvocation() const { |
| 73 EXPECT_EQ(default_version_, launched_version_); | 76 EXPECT_EQ(default_version_, launched_version_); |
| 74 ASSERT_EQ(1U, launched_invocations_.size()); | 77 ASSERT_TRUE(launched_invocations_); |
| 78 ASSERT_EQ(1U, launched_invocations_->size()); |
| 75 | 79 |
| 76 const safe_browsing::SwReporterInvocation& invocation = | 80 const SwReporterInvocation& invocation = launched_invocations_->front(); |
| 77 launched_invocations_[0]; | |
| 78 EXPECT_EQ(MakeTestFilePath(default_path_), | 81 EXPECT_EQ(MakeTestFilePath(default_path_), |
| 79 invocation.command_line.GetProgram()); | 82 invocation.command_line.GetProgram()); |
| 80 EXPECT_TRUE(invocation.command_line.GetSwitches().empty()); | 83 EXPECT_TRUE(invocation.command_line.GetSwitches().empty()); |
| 81 EXPECT_TRUE(invocation.command_line.GetArgs().empty()); | 84 EXPECT_TRUE(invocation.command_line.GetArgs().empty()); |
| 82 EXPECT_TRUE(invocation.suffix.empty()); | 85 EXPECT_TRUE(invocation.suffix.empty()); |
| 83 EXPECT_FALSE(invocation.is_experimental); | 86 EXPECT_EQ(SwReporterInvocation::FLAG_LOG_TO_RAPPOR | |
| 87 SwReporterInvocation::FLAG_LOG_TO_PREFS | |
| 88 SwReporterInvocation::FLAG_TRIGGER_PROMPT, |
| 89 invocation.flags); |
| 84 } | 90 } |
| 85 | 91 |
| 86 // |ComponentReady| asserts that it is run on the UI thread, so we must | 92 // |ComponentReady| asserts that it is run on the UI thread, so we must |
| 87 // create test threads before calling it. | 93 // create test threads before calling it. |
| 88 content::TestBrowserThreadBundle threads_; | 94 content::TestBrowserThreadBundle threads_; |
| 89 | 95 |
| 90 // Bound callback to the |SwReporterLaunched| method. | 96 // Bound callback to the |SwReporterLaunched| method. |
| 91 SwReporterRunner launched_callback_; | 97 SwReporterRunner launched_callback_; |
| 92 | 98 |
| 93 // Default parameters for |ComponentReady|. | 99 // Default parameters for |ComponentReady|. |
| 94 base::Version default_version_; | 100 base::Version default_version_; |
| 95 base::FilePath default_path_; | 101 base::FilePath default_path_; |
| 96 | 102 |
| 97 // Results of running |ComponentReady|. | 103 // Results of running |ComponentReady|. |
| 98 std::vector<safe_browsing::SwReporterInvocation> launched_invocations_; | 104 std::unique_ptr<safe_browsing::SwReporterQueue> launched_invocations_; |
| 99 base::Version launched_version_; | 105 base::Version launched_version_; |
| 100 | 106 |
| 101 private: | 107 private: |
| 102 DISALLOW_COPY_AND_ASSIGN(SwReporterInstallerTest); | 108 DISALLOW_COPY_AND_ASSIGN(SwReporterInstallerTest); |
| 103 }; | 109 }; |
| 104 | 110 |
| 105 // This class contains extended setup that is only used for tests of the | 111 // This class contains extended setup that is only used for tests of the |
| 106 // experimental reporter. | 112 // experimental reporter. |
| 107 class ExperimentalSwReporterInstallerTest : public SwReporterInstallerTest { | 113 class ExperimentalSwReporterInstallerTest : public SwReporterInstallerTest { |
| 108 public: | 114 public: |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 | 158 |
| 153 // Expects that the SwReporter was launched exactly once, with the given | 159 // Expects that the SwReporter was launched exactly once, with the given |
| 154 // |expected_suffix| and one |expected_additional_argument| on the | 160 // |expected_suffix| and one |expected_additional_argument| on the |
| 155 // command-line. (|expected_additional_argument| mainly exists to test that | 161 // command-line. (|expected_additional_argument| mainly exists to test that |
| 156 // arguments are included at all, so there is no need to test for | 162 // arguments are included at all, so there is no need to test for |
| 157 // combinations of multiple arguments and switches in this function.) | 163 // combinations of multiple arguments and switches in this function.) |
| 158 void ExpectExperimentalInvocation( | 164 void ExpectExperimentalInvocation( |
| 159 const std::string& expected_suffix, | 165 const std::string& expected_suffix, |
| 160 const base::string16& expected_additional_argument) { | 166 const base::string16& expected_additional_argument) { |
| 161 EXPECT_EQ(default_version_, launched_version_); | 167 EXPECT_EQ(default_version_, launched_version_); |
| 162 ASSERT_EQ(1U, launched_invocations_.size()); | 168 ASSERT_TRUE(launched_invocations_); |
| 169 ASSERT_EQ(1U, launched_invocations_->size()); |
| 163 | 170 |
| 164 const safe_browsing::SwReporterInvocation& invocation = | 171 const SwReporterInvocation& invocation = launched_invocations_->front(); |
| 165 launched_invocations_[0]; | |
| 166 EXPECT_EQ(MakeTestFilePath(default_path_), | 172 EXPECT_EQ(MakeTestFilePath(default_path_), |
| 167 invocation.command_line.GetProgram()); | 173 invocation.command_line.GetProgram()); |
| 168 | 174 |
| 169 if (expected_suffix.empty()) { | 175 if (expected_suffix.empty()) { |
| 170 EXPECT_TRUE(invocation.command_line.GetSwitches().empty()); | 176 EXPECT_TRUE(invocation.command_line.GetSwitches().empty()); |
| 171 EXPECT_TRUE(invocation.suffix.empty()); | 177 EXPECT_TRUE(invocation.suffix.empty()); |
| 172 } else { | 178 } else { |
| 173 EXPECT_EQ(1U, invocation.command_line.GetSwitches().size()); | 179 EXPECT_EQ(1U, invocation.command_line.GetSwitches().size()); |
| 174 EXPECT_EQ(expected_suffix, invocation.command_line.GetSwitchValueASCII( | 180 EXPECT_EQ(expected_suffix, invocation.command_line.GetSwitchValueASCII( |
| 175 kRegistrySuffixSwitch)); | 181 kRegistrySuffixSwitch)); |
| 176 EXPECT_EQ(expected_suffix, invocation.suffix); | 182 EXPECT_EQ(expected_suffix, invocation.suffix); |
| 177 } | 183 } |
| 178 | 184 |
| 179 if (expected_additional_argument.empty()) { | 185 if (expected_additional_argument.empty()) { |
| 180 EXPECT_TRUE(invocation.command_line.GetArgs().empty()); | 186 EXPECT_TRUE(invocation.command_line.GetArgs().empty()); |
| 181 } else { | 187 } else { |
| 182 EXPECT_EQ(1U, invocation.command_line.GetArgs().size()); | 188 EXPECT_EQ(1U, invocation.command_line.GetArgs().size()); |
| 183 EXPECT_EQ(expected_additional_argument, | 189 EXPECT_EQ(expected_additional_argument, |
| 184 invocation.command_line.GetArgs()[0]); | 190 invocation.command_line.GetArgs()[0]); |
| 185 } | 191 } |
| 186 | 192 |
| 187 EXPECT_TRUE(invocation.is_experimental); | 193 EXPECT_EQ(0, invocation.flags); |
| 188 histograms_.ExpectTotalCount(kErrorHistogramName, 0); | 194 histograms_.ExpectTotalCount(kErrorHistogramName, 0); |
| 189 } | 195 } |
| 190 | 196 |
| 191 void ExpectLaunchError() { | 197 void ExpectLaunchError() { |
| 192 // The SwReporter should not be launched, and an error should be logged. | 198 // The SwReporter should not be launched, and an error should be logged. |
| 193 EXPECT_TRUE(launched_invocations_.empty()); | 199 EXPECT_FALSE(launched_invocations_); |
| 194 histograms_.ExpectUniqueSample(kErrorHistogramName, | 200 histograms_.ExpectUniqueSample(kErrorHistogramName, |
| 195 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1); | 201 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1); |
| 196 } | 202 } |
| 197 | 203 |
| 198 std::unique_ptr<variations::testing::VariationParamsManager> variations_; | 204 std::unique_ptr<variations::testing::VariationParamsManager> variations_; |
| 199 base::test::ScopedFeatureList scoped_feature_list_; | 205 base::test::ScopedFeatureList scoped_feature_list_; |
| 200 base::HistogramTester histograms_; | 206 base::HistogramTester histograms_; |
| 201 | 207 |
| 202 private: | 208 private: |
| 203 DISALLOW_COPY_AND_ASSIGN(ExperimentalSwReporterInstallerTest); | 209 DISALLOW_COPY_AND_ASSIGN(ExperimentalSwReporterInstallerTest); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 | 273 |
| 268 TEST_F(ExperimentalSwReporterInstallerTest, SingleInvocation) { | 274 TEST_F(ExperimentalSwReporterInstallerTest, SingleInvocation) { |
| 269 SwReporterInstallerTraits traits(launched_callback_, true); | 275 SwReporterInstallerTraits traits(launched_callback_, true); |
| 270 CreateFeatureWithTag(kExperimentTag); | 276 CreateFeatureWithTag(kExperimentTag); |
| 271 ExpectAttributesWithTag(traits, kExperimentTag); | 277 ExpectAttributesWithTag(traits, kExperimentTag); |
| 272 | 278 |
| 273 static constexpr char kTestManifest[] = | 279 static constexpr char kTestManifest[] = |
| 274 "{\"launch_params\": [" | 280 "{\"launch_params\": [" |
| 275 " {" | 281 " {" |
| 276 " \"arguments\": [\"--engine=experimental\", \"random argument\"]," | 282 " \"arguments\": [\"--engine=experimental\", \"random argument\"]," |
| 277 " \"suffix\": \"TestSuffix\"" | 283 " \"suffix\": \"TestSuffix\"," |
| 284 " \"prompt\": false" |
| 278 " }" | 285 " }" |
| 279 "]}"; | 286 "]}"; |
| 280 traits.ComponentReady( | 287 traits.ComponentReady( |
| 281 default_version_, default_path_, | 288 default_version_, default_path_, |
| 282 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); | 289 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); |
| 283 | 290 |
| 284 // The SwReporter should be launched once with the given arguments. | 291 // The SwReporter should be launched once with the given arguments. |
| 285 EXPECT_EQ(default_version_, launched_version_); | 292 EXPECT_EQ(default_version_, launched_version_); |
| 286 ASSERT_EQ(1U, launched_invocations_.size()); | 293 ASSERT_TRUE(launched_invocations_); |
| 294 ASSERT_EQ(1U, launched_invocations_->size()); |
| 287 | 295 |
| 288 const safe_browsing::SwReporterInvocation& invocation = | 296 const SwReporterInvocation& invocation = launched_invocations_->front(); |
| 289 launched_invocations_[0]; | |
| 290 EXPECT_EQ(MakeTestFilePath(default_path_), | 297 EXPECT_EQ(MakeTestFilePath(default_path_), |
| 291 invocation.command_line.GetProgram()); | 298 invocation.command_line.GetProgram()); |
| 292 EXPECT_EQ(2U, invocation.command_line.GetSwitches().size()); | 299 EXPECT_EQ(2U, invocation.command_line.GetSwitches().size()); |
| 293 EXPECT_EQ("experimental", | 300 EXPECT_EQ("experimental", |
| 294 invocation.command_line.GetSwitchValueASCII("engine")); | 301 invocation.command_line.GetSwitchValueASCII("engine")); |
| 295 EXPECT_EQ("TestSuffix", | 302 EXPECT_EQ("TestSuffix", |
| 296 invocation.command_line.GetSwitchValueASCII(kRegistrySuffixSwitch)); | 303 invocation.command_line.GetSwitchValueASCII(kRegistrySuffixSwitch)); |
| 297 ASSERT_EQ(1U, invocation.command_line.GetArgs().size()); | 304 ASSERT_EQ(1U, invocation.command_line.GetArgs().size()); |
| 298 EXPECT_EQ(L"random argument", invocation.command_line.GetArgs()[0]); | 305 EXPECT_EQ(L"random argument", invocation.command_line.GetArgs()[0]); |
| 299 EXPECT_EQ("TestSuffix", invocation.suffix); | 306 EXPECT_EQ("TestSuffix", invocation.suffix); |
| 300 EXPECT_TRUE(invocation.is_experimental); | 307 EXPECT_EQ(0, invocation.flags); |
| 301 histograms_.ExpectTotalCount(kErrorHistogramName, 0); | 308 histograms_.ExpectTotalCount(kErrorHistogramName, 0); |
| 302 } | 309 } |
| 303 | 310 |
| 304 TEST_F(ExperimentalSwReporterInstallerTest, MultipleInvocations) { | 311 TEST_F(ExperimentalSwReporterInstallerTest, MultipleInvocations) { |
| 305 SwReporterInstallerTraits traits(launched_callback_, true); | 312 SwReporterInstallerTraits traits(launched_callback_, true); |
| 306 CreateFeatureWithTag(kExperimentTag); | 313 CreateFeatureWithTag(kExperimentTag); |
| 307 ExpectAttributesWithTag(traits, kExperimentTag); | 314 ExpectAttributesWithTag(traits, kExperimentTag); |
| 308 | 315 |
| 309 static constexpr char kTestManifest[] = | 316 static constexpr char kTestManifest[] = |
| 310 "{\"launch_params\": [" | 317 "{\"launch_params\": [" |
| 311 " {" | 318 " {" |
| 312 " \"arguments\": [\"--engine=experimental\", \"random argument\"]," | 319 " \"arguments\": [\"--engine=experimental\", \"random argument\"]," |
| 313 " \"suffix\": \"TestSuffix\"" | 320 " \"suffix\": \"TestSuffix\"," |
| 321 " \"prompt\": false" |
| 314 " }," | 322 " }," |
| 315 " {" | 323 " {" |
| 316 " \"arguments\": [\"--engine=second\"]," | 324 " \"arguments\": [\"--engine=second\"]," |
| 317 " \"suffix\": \"SecondSuffix\"" | 325 " \"suffix\": \"SecondSuffix\"," |
| 326 " \"prompt\": true" |
| 327 " }," |
| 328 " {" |
| 329 " \"arguments\": [\"--engine=third\"]," |
| 330 " \"suffix\": \"ThirdSuffix\"" |
| 318 " }" | 331 " }" |
| 319 "]}"; | 332 "]}"; |
| 320 traits.ComponentReady( | 333 traits.ComponentReady( |
| 321 default_version_, default_path_, | 334 default_version_, default_path_, |
| 322 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); | 335 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); |
| 323 | 336 |
| 324 // Not supported yet. | 337 // The SwReporter should be launched three times with the given arguments. |
| 325 ExpectLaunchError(); | 338 EXPECT_EQ(default_version_, launched_version_); |
| 339 ASSERT_TRUE(launched_invocations_); |
| 340 ASSERT_EQ(3U, launched_invocations_->size()); |
| 341 |
| 342 { |
| 343 SwReporterInvocation invocation = launched_invocations_->front(); |
| 344 launched_invocations_->pop(); |
| 345 EXPECT_EQ(MakeTestFilePath(default_path_), |
| 346 invocation.command_line.GetProgram()); |
| 347 EXPECT_EQ(2U, invocation.command_line.GetSwitches().size()); |
| 348 EXPECT_EQ("experimental", |
| 349 invocation.command_line.GetSwitchValueASCII("engine")); |
| 350 EXPECT_EQ("TestSuffix", invocation.command_line.GetSwitchValueASCII( |
| 351 kRegistrySuffixSwitch)); |
| 352 ASSERT_EQ(1U, invocation.command_line.GetArgs().size()); |
| 353 EXPECT_EQ(L"random argument", invocation.command_line.GetArgs()[0]); |
| 354 EXPECT_EQ("TestSuffix", invocation.suffix); |
| 355 EXPECT_EQ(0, invocation.flags); |
| 356 } |
| 357 |
| 358 { |
| 359 SwReporterInvocation invocation = launched_invocations_->front(); |
| 360 launched_invocations_->pop(); |
| 361 EXPECT_EQ(MakeTestFilePath(default_path_), |
| 362 invocation.command_line.GetProgram()); |
| 363 EXPECT_EQ(2U, invocation.command_line.GetSwitches().size()); |
| 364 EXPECT_EQ("second", invocation.command_line.GetSwitchValueASCII("engine")); |
| 365 EXPECT_EQ("SecondSuffix", invocation.command_line.GetSwitchValueASCII( |
| 366 kRegistrySuffixSwitch)); |
| 367 ASSERT_TRUE(invocation.command_line.GetArgs().empty()); |
| 368 EXPECT_EQ("SecondSuffix", invocation.suffix); |
| 369 EXPECT_EQ(SwReporterInvocation::FLAG_TRIGGER_PROMPT, invocation.flags); |
| 370 } |
| 371 |
| 372 { |
| 373 SwReporterInvocation invocation = launched_invocations_->front(); |
| 374 launched_invocations_->pop(); |
| 375 EXPECT_EQ(MakeTestFilePath(default_path_), |
| 376 invocation.command_line.GetProgram()); |
| 377 EXPECT_EQ(2U, invocation.command_line.GetSwitches().size()); |
| 378 EXPECT_EQ("third", invocation.command_line.GetSwitchValueASCII("engine")); |
| 379 EXPECT_EQ("ThirdSuffix", invocation.command_line.GetSwitchValueASCII( |
| 380 kRegistrySuffixSwitch)); |
| 381 ASSERT_TRUE(invocation.command_line.GetArgs().empty()); |
| 382 EXPECT_EQ("ThirdSuffix", invocation.suffix); |
| 383 // A missing "prompt" key means "false". |
| 384 EXPECT_EQ(0, invocation.flags); |
| 385 } |
| 386 |
| 387 histograms_.ExpectTotalCount(kErrorHistogramName, 0); |
| 326 } | 388 } |
| 327 | 389 |
| 328 TEST_F(ExperimentalSwReporterInstallerTest, MissingSuffix) { | 390 TEST_F(ExperimentalSwReporterInstallerTest, MissingSuffix) { |
| 329 SwReporterInstallerTraits traits(launched_callback_, true); | 391 SwReporterInstallerTraits traits(launched_callback_, true); |
| 330 CreateFeatureWithTag(kExperimentTag); | 392 CreateFeatureWithTag(kExperimentTag); |
| 331 | 393 |
| 332 static constexpr char kTestManifest[] = | 394 static constexpr char kTestManifest[] = |
| 333 "{\"launch_params\": [" | 395 "{\"launch_params\": [" |
| 334 " {" | 396 " {" |
| 335 " \"arguments\": [\"random argument\"]" | 397 " \"arguments\": [\"random argument\"]" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 CreateFeatureWithTag(kExperimentTag); | 532 CreateFeatureWithTag(kExperimentTag); |
| 471 | 533 |
| 472 static constexpr char kTestManifest[] = "{}"; | 534 static constexpr char kTestManifest[] = "{}"; |
| 473 traits.ComponentReady( | 535 traits.ComponentReady( |
| 474 default_version_, default_path_, | 536 default_version_, default_path_, |
| 475 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); | 537 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); |
| 476 | 538 |
| 477 // The SwReporter should not be launched, but no error should be logged. | 539 // The SwReporter should not be launched, but no error should be logged. |
| 478 // (This tests the case where a non-experimental version of the reporter, | 540 // (This tests the case where a non-experimental version of the reporter, |
| 479 // which does not have "launch_params" in its manifest, is already present.) | 541 // which does not have "launch_params" in its manifest, is already present.) |
| 480 EXPECT_TRUE(launched_invocations_.empty()); | 542 EXPECT_FALSE(launched_invocations_); |
| 481 histograms_.ExpectTotalCount(kErrorHistogramName, 0); | 543 histograms_.ExpectTotalCount(kErrorHistogramName, 0); |
| 482 } | 544 } |
| 483 | 545 |
| 484 TEST_F(ExperimentalSwReporterInstallerTest, EmptyLaunchParams) { | 546 TEST_F(ExperimentalSwReporterInstallerTest, EmptyLaunchParams) { |
| 485 SwReporterInstallerTraits traits(launched_callback_, true); | 547 SwReporterInstallerTraits traits(launched_callback_, true); |
| 486 CreateFeatureWithTag(kExperimentTag); | 548 CreateFeatureWithTag(kExperimentTag); |
| 487 | 549 |
| 488 static constexpr char kTestManifest[] = "{\"launch_params\": []}"; | 550 static constexpr char kTestManifest[] = "{\"launch_params\": []}"; |
| 489 traits.ComponentReady( | 551 traits.ComponentReady( |
| 490 default_version_, default_path_, | 552 default_version_, default_path_, |
| 491 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); | 553 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); |
| 492 | 554 |
| 493 // The SwReporter should not be launched, and an error should be logged. | 555 // The SwReporter should not be launched, and an error should be logged. |
| 494 EXPECT_TRUE(launched_invocations_.empty()); | 556 EXPECT_FALSE(launched_invocations_); |
| 495 histograms_.ExpectUniqueSample(kErrorHistogramName, | 557 histograms_.ExpectUniqueSample(kErrorHistogramName, |
| 496 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1); | 558 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1); |
| 497 } | 559 } |
| 498 | 560 |
| 499 TEST_F(ExperimentalSwReporterInstallerTest, EmptyLaunchParams2) { | 561 TEST_F(ExperimentalSwReporterInstallerTest, EmptyLaunchParams2) { |
| 500 SwReporterInstallerTraits traits(launched_callback_, true); | 562 SwReporterInstallerTraits traits(launched_callback_, true); |
| 501 CreateFeatureWithTag(kExperimentTag); | 563 CreateFeatureWithTag(kExperimentTag); |
| 502 | 564 |
| 503 static constexpr char kTestManifest[] = "{\"launch_params\": {}}"; | 565 static constexpr char kTestManifest[] = "{\"launch_params\": {}}"; |
| 504 traits.ComponentReady( | 566 traits.ComponentReady( |
| 505 default_version_, default_path_, | 567 default_version_, default_path_, |
| 506 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); | 568 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); |
| 507 | 569 |
| 508 // The SwReporter should not be launched, and an error should be logged. | 570 // The SwReporter should not be launched, and an error should be logged. |
| 509 EXPECT_TRUE(launched_invocations_.empty()); | 571 EXPECT_FALSE(launched_invocations_); |
| 510 histograms_.ExpectUniqueSample(kErrorHistogramName, | 572 histograms_.ExpectUniqueSample(kErrorHistogramName, |
| 511 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1); | 573 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1); |
| 512 } | 574 } |
| 513 | 575 |
| 514 TEST_F(ExperimentalSwReporterInstallerTest, BadSuffix) { | 576 TEST_F(ExperimentalSwReporterInstallerTest, BadSuffix) { |
| 515 SwReporterInstallerTraits traits(launched_callback_, true); | 577 SwReporterInstallerTraits traits(launched_callback_, true); |
| 516 CreateFeatureWithTag(kExperimentTag); | 578 CreateFeatureWithTag(kExperimentTag); |
| 517 | 579 |
| 518 static constexpr char kTestManifest[] = | 580 static constexpr char kTestManifest[] = |
| 519 "{\"launch_params\": [" | 581 "{\"launch_params\": [" |
| 520 " {" | 582 " {" |
| 521 " \"arguments\": [\"--engine=experimental\"]," | 583 " \"arguments\": [\"--engine=experimental\"]," |
| 522 " \"suffix\": \"invalid whitespace characters\"" | 584 " \"suffix\": \"invalid whitespace characters\"" |
| 523 " }" | 585 " }" |
| 524 "]}"; | 586 "]}"; |
| 525 traits.ComponentReady( | 587 traits.ComponentReady( |
| 526 default_version_, default_path_, | 588 default_version_, default_path_, |
| 527 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); | 589 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); |
| 528 | 590 |
| 529 // The SwReporter should not be launched, and an error should be logged. | 591 // The SwReporter should not be launched, and an error should be logged. |
| 530 EXPECT_TRUE(launched_invocations_.empty()); | 592 EXPECT_FALSE(launched_invocations_); |
| 531 histograms_.ExpectUniqueSample(kErrorHistogramName, | 593 histograms_.ExpectUniqueSample(kErrorHistogramName, |
| 532 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1); | 594 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1); |
| 533 } | 595 } |
| 534 | 596 |
| 535 TEST_F(ExperimentalSwReporterInstallerTest, SuffixTooLong) { | 597 TEST_F(ExperimentalSwReporterInstallerTest, SuffixTooLong) { |
| 536 SwReporterInstallerTraits traits(launched_callback_, true); | 598 SwReporterInstallerTraits traits(launched_callback_, true); |
| 537 CreateFeatureWithTag(kExperimentTag); | 599 CreateFeatureWithTag(kExperimentTag); |
| 538 | 600 |
| 539 static constexpr char kTestManifest[] = | 601 static constexpr char kTestManifest[] = |
| 540 "{\"launch_params\": [" | 602 "{\"launch_params\": [" |
| 541 " {" | 603 " {" |
| 542 " \"arguments\": [\"--engine=experimental\"]," | 604 " \"arguments\": [\"--engine=experimental\"]," |
| 543 " \"suffix\": \"%s\"" | 605 " \"suffix\": \"%s\"" |
| 544 " }" | 606 " }" |
| 545 "]}"; | 607 "]}"; |
| 546 std::string suffix_too_long(500, 'x'); | 608 std::string suffix_too_long(500, 'x'); |
| 547 std::string manifest = | 609 std::string manifest = |
| 548 base::StringPrintf(kTestManifest, suffix_too_long.c_str()); | 610 base::StringPrintf(kTestManifest, suffix_too_long.c_str()); |
| 549 traits.ComponentReady( | 611 traits.ComponentReady( |
| 550 default_version_, default_path_, | 612 default_version_, default_path_, |
| 551 base::DictionaryValue::From(base::JSONReader::Read(manifest))); | 613 base::DictionaryValue::From(base::JSONReader::Read(manifest))); |
| 552 | 614 |
| 553 // The SwReporter should not be launched, and an error should be logged. | 615 // The SwReporter should not be launched, and an error should be logged. |
| 554 EXPECT_TRUE(launched_invocations_.empty()); | 616 EXPECT_FALSE(launched_invocations_); |
| 555 histograms_.ExpectUniqueSample(kErrorHistogramName, | 617 histograms_.ExpectUniqueSample(kErrorHistogramName, |
| 556 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1); | 618 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1); |
| 557 } | 619 } |
| 558 | 620 |
| 559 TEST_F(ExperimentalSwReporterInstallerTest, BadTypesInManifest) { | 621 TEST_F(ExperimentalSwReporterInstallerTest, BadTypesInManifest) { |
| 560 SwReporterInstallerTraits traits(launched_callback_, true); | 622 SwReporterInstallerTraits traits(launched_callback_, true); |
| 561 CreateFeatureWithTag(kExperimentTag); | 623 CreateFeatureWithTag(kExperimentTag); |
| 562 | 624 |
| 563 // This has a string instead of a list for "arguments". | 625 // This has a string instead of a list for "arguments". |
| 564 static constexpr char kTestManifest[] = | 626 static constexpr char kTestManifest[] = |
| 565 "{\"launch_params\": [" | 627 "{\"launch_params\": [" |
| 566 " {" | 628 " {" |
| 567 " \"arguments\": \"--engine=experimental\"," | 629 " \"arguments\": \"--engine=experimental\"," |
| 568 " \"suffix\": \"TestSuffix\"" | 630 " \"suffix\": \"TestSuffix\"" |
| 569 " }" | 631 " }" |
| 570 "]}"; | 632 "]}"; |
| 571 traits.ComponentReady( | 633 traits.ComponentReady( |
| 572 default_version_, default_path_, | 634 default_version_, default_path_, |
| 573 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); | 635 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); |
| 574 | 636 |
| 575 // The SwReporter should not be launched, and an error should be logged. | 637 // The SwReporter should not be launched, and an error should be logged. |
| 576 EXPECT_TRUE(launched_invocations_.empty()); | 638 EXPECT_FALSE(launched_invocations_); |
| 577 histograms_.ExpectUniqueSample(kErrorHistogramName, | 639 histograms_.ExpectUniqueSample(kErrorHistogramName, |
| 578 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1); | 640 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1); |
| 579 } | 641 } |
| 580 | 642 |
| 581 TEST_F(ExperimentalSwReporterInstallerTest, BadTypesInManifest2) { | 643 TEST_F(ExperimentalSwReporterInstallerTest, BadTypesInManifest2) { |
| 582 SwReporterInstallerTraits traits(launched_callback_, true); | 644 SwReporterInstallerTraits traits(launched_callback_, true); |
| 583 CreateFeatureWithTag(kExperimentTag); | 645 CreateFeatureWithTag(kExperimentTag); |
| 584 | 646 |
| 585 // This has the invocation parameters as direct children of "launch_params", | 647 // This has the invocation parameters as direct children of "launch_params", |
| 586 // instead of using a list. | 648 // instead of using a list. |
| 587 static constexpr char kTestManifest[] = | 649 static constexpr char kTestManifest[] = |
| 588 "{\"launch_params\": " | 650 "{\"launch_params\": " |
| 589 " {" | 651 " {" |
| 590 " \"arguments\": [\"--engine=experimental\"]," | 652 " \"arguments\": [\"--engine=experimental\"]," |
| 591 " \"suffix\": \"TestSuffix\"" | 653 " \"suffix\": \"TestSuffix\"" |
| 592 " }" | 654 " }" |
| 593 "}"; | 655 "}"; |
| 594 traits.ComponentReady( | 656 traits.ComponentReady( |
| 595 default_version_, default_path_, | 657 default_version_, default_path_, |
| 596 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); | 658 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); |
| 597 | 659 |
| 598 // The SwReporter should not be launched, and an error should be logged. | 660 // The SwReporter should not be launched, and an error should be logged. |
| 599 EXPECT_TRUE(launched_invocations_.empty()); | 661 EXPECT_FALSE(launched_invocations_); |
| 600 histograms_.ExpectUniqueSample(kErrorHistogramName, | 662 histograms_.ExpectUniqueSample(kErrorHistogramName, |
| 601 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1); | 663 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1); |
| 602 } | 664 } |
| 603 | 665 |
| 604 TEST_F(ExperimentalSwReporterInstallerTest, BadTypesInManifest3) { | 666 TEST_F(ExperimentalSwReporterInstallerTest, BadTypesInManifest3) { |
| 605 SwReporterInstallerTraits traits(launched_callback_, true); | 667 SwReporterInstallerTraits traits(launched_callback_, true); |
| 606 CreateFeatureWithTag(kExperimentTag); | 668 CreateFeatureWithTag(kExperimentTag); |
| 607 | 669 |
| 608 // This has a list for suffix as well as for arguments. | 670 // This has a list for suffix as well as for arguments. |
| 609 static constexpr char kTestManifest[] = | 671 static constexpr char kTestManifest[] = |
| 610 "{\"launch_params\": [" | 672 "{\"launch_params\": [" |
| 611 " {" | 673 " {" |
| 612 " \"arguments\": [\"--engine=experimental\"]," | 674 " \"arguments\": [\"--engine=experimental\"]," |
| 613 " \"suffix\": [\"TestSuffix\"]" | 675 " \"suffix\": [\"TestSuffix\"]" |
| 614 " }" | 676 " }" |
| 615 "]}"; | 677 "]}"; |
| 616 traits.ComponentReady( | 678 traits.ComponentReady( |
| 617 default_version_, default_path_, | 679 default_version_, default_path_, |
| 618 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); | 680 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); |
| 619 | 681 |
| 620 // The SwReporter should not be launched, and an error should be logged. | 682 // The SwReporter should not be launched, and an error should be logged. |
| 621 EXPECT_TRUE(launched_invocations_.empty()); | 683 EXPECT_FALSE(launched_invocations_); |
| 622 histograms_.ExpectUniqueSample(kErrorHistogramName, | 684 histograms_.ExpectUniqueSample(kErrorHistogramName, |
| 623 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1); | 685 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1); |
| 624 } | 686 } |
| 625 | 687 |
| 688 TEST_F(ExperimentalSwReporterInstallerTest, BadTypesInManifest4) { |
| 689 SwReporterInstallerTraits traits(launched_callback_, true); |
| 690 CreateFeatureWithTag(kExperimentTag); |
| 691 |
| 692 // This has an int instead of a bool for prompt. |
| 693 static constexpr char kTestManifest[] = |
| 694 "{\"launch_params\": [" |
| 695 " {" |
| 696 " \"arguments\": [\"--engine=experimental\"]," |
| 697 " \"suffix\": \"TestSuffix\"," |
| 698 " \"prompt\": 1" |
| 699 " }" |
| 700 "]}"; |
| 701 traits.ComponentReady( |
| 702 default_version_, default_path_, |
| 703 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); |
| 704 |
| 705 // The SwReporter should not be launched, and an error should be logged. |
| 706 EXPECT_FALSE(launched_invocations_); |
| 707 histograms_.ExpectUniqueSample(kErrorHistogramName, |
| 708 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1); |
| 709 } |
| 626 } // namespace component_updater | 710 } // namespace component_updater |
| OLD | NEW |