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 <memory> | 8 #include <memory> |
| 9 #include <string> |
| 10 #include <utility> |
8 #include <vector> | 11 #include <vector> |
9 | 12 |
10 #include "base/bind.h" | 13 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
12 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 16 #include "base/feature_list.h" |
13 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
| 18 #include "base/json/json_reader.h" |
14 #include "base/macros.h" | 19 #include "base/macros.h" |
| 20 #include "base/metrics/field_trial.h" |
| 21 #include "base/strings/stringprintf.h" |
| 22 #include "base/test/histogram_tester.h" |
| 23 #include "base/test/scoped_feature_list.h" |
15 #include "base/values.h" | 24 #include "base/values.h" |
16 #include "base/version.h" | 25 #include "base/version.h" |
17 #include "chrome/browser/safe_browsing/srt_fetcher_win.h" | 26 #include "chrome/browser/safe_browsing/srt_fetcher_win.h" |
| 27 #include "components/variations/variations_associated_data.h" |
18 #include "content/public/test/test_browser_thread_bundle.h" | 28 #include "content/public/test/test_browser_thread_bundle.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
20 | 30 |
21 namespace component_updater { | 31 namespace component_updater { |
22 | 32 |
| 33 namespace { |
| 34 |
| 35 constexpr char kRegistrySuffixSwitch[] = "registry-suffix"; |
| 36 constexpr char kErrorHistogramName[] = "SoftwareReporter.ExperimentErrors"; |
| 37 constexpr char kExperimentTag[] = "experiment_tag"; |
| 38 constexpr char kMissingTag[] = "missing_tag"; |
| 39 |
| 40 } // namespace |
| 41 |
23 class SwReporterInstallerTest : public ::testing::Test { | 42 class SwReporterInstallerTest : public ::testing::Test { |
24 public: | 43 public: |
25 SwReporterInstallerTest() | 44 SwReporterInstallerTest() |
26 : traits_(base::Bind(&SwReporterInstallerTest::SwReporterLaunched, | 45 : launched_callback_( |
27 base::Unretained(this))), | 46 base::Bind(&SwReporterInstallerTest::SwReporterLaunched, |
| 47 base::Unretained(this))), |
28 default_version_("1.2.3"), | 48 default_version_("1.2.3"), |
29 default_path_(L"C:\\full\\path\\to\\download") {} | 49 default_path_(L"C:\\full\\path\\to\\download") {} |
30 | 50 |
| 51 ~SwReporterInstallerTest() override {} |
| 52 |
31 protected: | 53 protected: |
32 // Each test fixture inherits from |SwReporterInstallerTest|, and friendship | |
33 // is not transitive so they will not have access to |ComponentReady|. Use | |
34 // this helper function to call it. | |
35 void TestComponentReady(const base::Version& version, | |
36 const base::FilePath& path) { | |
37 traits_.ComponentReady(version, path, | |
38 std::make_unique<base::DictionaryValue>()); | |
39 } | |
40 | |
41 void SwReporterLaunched(const safe_browsing::SwReporterInvocation& invocation, | 54 void SwReporterLaunched(const safe_browsing::SwReporterInvocation& invocation, |
42 const base::Version& version) { | 55 const base::Version& version) { |
43 ASSERT_TRUE(launched_invocations_.empty()); | 56 ASSERT_TRUE(launched_invocations_.empty()); |
44 launched_invocations_.push_back(invocation); | 57 launched_invocations_.push_back(invocation); |
45 launched_version_ = version; | 58 launched_version_ = version; |
46 } | 59 } |
47 | 60 |
48 base::FilePath MakeTestFilePath(const base::FilePath& path) const { | 61 base::FilePath MakeTestFilePath(const base::FilePath& path) const { |
49 return path.Append(L"software_reporter_tool.exe"); | 62 return path.Append(L"software_reporter_tool.exe"); |
50 } | 63 } |
51 | 64 |
| 65 void ExpectEmptyAttributes(const SwReporterInstallerTraits& traits) const { |
| 66 update_client::InstallerAttributes attributes = |
| 67 traits.GetInstallerAttributes(); |
| 68 EXPECT_TRUE(attributes.empty()); |
| 69 } |
| 70 |
| 71 // Expects that the SwReporter was launched exactly once, with no arguments. |
| 72 void ExpectDefaultInvocation() const { |
| 73 EXPECT_EQ(default_version_, launched_version_); |
| 74 ASSERT_EQ(1U, launched_invocations_.size()); |
| 75 |
| 76 const safe_browsing::SwReporterInvocation& invocation = |
| 77 launched_invocations_[0]; |
| 78 EXPECT_EQ(MakeTestFilePath(default_path_), |
| 79 invocation.command_line.GetProgram()); |
| 80 EXPECT_TRUE(invocation.command_line.GetSwitches().empty()); |
| 81 EXPECT_TRUE(invocation.command_line.GetArgs().empty()); |
| 82 EXPECT_TRUE(invocation.suffix.empty()); |
| 83 EXPECT_FALSE(invocation.is_experimental); |
| 84 } |
| 85 |
52 // |ComponentReady| asserts that it is run on the UI thread, so we must | 86 // |ComponentReady| asserts that it is run on the UI thread, so we must |
53 // create test threads before calling it. | 87 // create test threads before calling it. |
54 content::TestBrowserThreadBundle threads_; | 88 content::TestBrowserThreadBundle threads_; |
55 | 89 |
56 // The traits object to test. | 90 // Bound callback to the |SwReporterLaunched| method. |
57 SwReporterInstallerTraits traits_; | 91 SwReporterRunner launched_callback_; |
58 | 92 |
59 // Default parameters for |ComponentReady|. | 93 // Default parameters for |ComponentReady|. |
60 base::Version default_version_; | 94 base::Version default_version_; |
61 base::FilePath default_path_; | 95 base::FilePath default_path_; |
62 | 96 |
63 // Results of running |ComponentReady|. | 97 // Results of running |ComponentReady|. |
64 std::vector<safe_browsing::SwReporterInvocation> launched_invocations_; | 98 std::vector<safe_browsing::SwReporterInvocation> launched_invocations_; |
65 base::Version launched_version_; | 99 base::Version launched_version_; |
66 | 100 |
67 private: | 101 private: |
68 DISALLOW_COPY_AND_ASSIGN(SwReporterInstallerTest); | 102 DISALLOW_COPY_AND_ASSIGN(SwReporterInstallerTest); |
69 }; | 103 }; |
70 | 104 |
| 105 // This class contains extended setup that is only used for tests of the |
| 106 // experimental reporter. |
| 107 class ExperimentalSwReporterInstallerTest : public SwReporterInstallerTest { |
| 108 public: |
| 109 ExperimentalSwReporterInstallerTest() {} |
| 110 ~ExperimentalSwReporterInstallerTest() override {} |
| 111 |
| 112 protected: |
| 113 void CreateFeatureWithoutTag() { |
| 114 std::map<std::string, std::string> params; |
| 115 CreateFeatureWithParams(params); |
| 116 } |
| 117 |
| 118 void CreateFeatureWithTag(const std::string& tag) { |
| 119 std::map<std::string, std::string> params; |
| 120 params["tag"] = tag; |
| 121 CreateFeatureWithParams(params); |
| 122 } |
| 123 |
| 124 void CreateFeatureWithParams( |
| 125 const std::map<std::string, std::string>& params) { |
| 126 constexpr char kExperimentGroupName[] = "ExperimentalSwReporterEngine"; |
| 127 |
| 128 // Assign the given variation params to the experiment group until |
| 129 // |variations_| goes out of scope when the test exits. This will also |
| 130 // create a FieldTrial for this group. |
| 131 variations_ = std::make_unique<variations::testing::VariationParamsManager>( |
| 132 kExperimentGroupName, params); |
| 133 |
| 134 // Create a feature list containing only the field trial for this group, |
| 135 // and enable it for the length of the test. |
| 136 base::FieldTrial* trial = base::FieldTrialList::Find(kExperimentGroupName); |
| 137 ASSERT_TRUE(trial); |
| 138 auto feature_list = std::make_unique<base::FeatureList>(); |
| 139 feature_list->RegisterFieldTrialOverride( |
| 140 kExperimentGroupName, base::FeatureList::OVERRIDE_ENABLE_FEATURE, |
| 141 trial); |
| 142 scoped_feature_list_.InitWithFeatureList(std::move(feature_list)); |
| 143 } |
| 144 |
| 145 void ExpectAttributesWithTag(const SwReporterInstallerTraits& traits, |
| 146 const std::string& tag) { |
| 147 update_client::InstallerAttributes attributes = |
| 148 traits.GetInstallerAttributes(); |
| 149 EXPECT_EQ(1U, attributes.size()); |
| 150 EXPECT_EQ(tag, attributes["tag"]); |
| 151 } |
| 152 |
| 153 // Expects that the SwReporter was launched exactly once, with the given |
| 154 // |expected_suffix| and one |expected_additional_argument| on the |
| 155 // command-line. (|expected_additional_argument| mainly exists to test that |
| 156 // arguments are included at all, so there is no need to test for |
| 157 // combinations of multiple arguments and switches in this function.) |
| 158 void ExpectExperimentalInvocation( |
| 159 const std::string& expected_suffix, |
| 160 const base::string16& expected_additional_argument) { |
| 161 EXPECT_EQ(default_version_, launched_version_); |
| 162 ASSERT_EQ(1U, launched_invocations_.size()); |
| 163 |
| 164 const safe_browsing::SwReporterInvocation& invocation = |
| 165 launched_invocations_[0]; |
| 166 EXPECT_EQ(MakeTestFilePath(default_path_), |
| 167 invocation.command_line.GetProgram()); |
| 168 |
| 169 if (expected_suffix.empty()) { |
| 170 EXPECT_TRUE(invocation.command_line.GetSwitches().empty()); |
| 171 EXPECT_TRUE(invocation.suffix.empty()); |
| 172 } else { |
| 173 EXPECT_EQ(1U, invocation.command_line.GetSwitches().size()); |
| 174 EXPECT_EQ(expected_suffix, invocation.command_line.GetSwitchValueASCII( |
| 175 kRegistrySuffixSwitch)); |
| 176 EXPECT_EQ(expected_suffix, invocation.suffix); |
| 177 } |
| 178 |
| 179 if (expected_additional_argument.empty()) { |
| 180 EXPECT_TRUE(invocation.command_line.GetArgs().empty()); |
| 181 } else { |
| 182 EXPECT_EQ(1U, invocation.command_line.GetArgs().size()); |
| 183 EXPECT_EQ(expected_additional_argument, |
| 184 invocation.command_line.GetArgs()[0]); |
| 185 } |
| 186 |
| 187 EXPECT_TRUE(invocation.is_experimental); |
| 188 histograms_.ExpectTotalCount(kErrorHistogramName, 0); |
| 189 } |
| 190 |
| 191 void ExpectLaunchError() { |
| 192 // The SwReporter should not be launched, and an error should be logged. |
| 193 EXPECT_TRUE(launched_invocations_.empty()); |
| 194 histograms_.ExpectUniqueSample(kErrorHistogramName, |
| 195 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1); |
| 196 } |
| 197 |
| 198 std::unique_ptr<variations::testing::VariationParamsManager> variations_; |
| 199 base::test::ScopedFeatureList scoped_feature_list_; |
| 200 base::HistogramTester histograms_; |
| 201 |
| 202 private: |
| 203 DISALLOW_COPY_AND_ASSIGN(ExperimentalSwReporterInstallerTest); |
| 204 }; |
| 205 |
71 TEST_F(SwReporterInstallerTest, Default) { | 206 TEST_F(SwReporterInstallerTest, Default) { |
72 TestComponentReady(default_version_, default_path_); | 207 SwReporterInstallerTraits traits(launched_callback_, false); |
| 208 ExpectEmptyAttributes(traits); |
| 209 traits.ComponentReady(default_version_, default_path_, |
| 210 std::make_unique<base::DictionaryValue>()); |
| 211 ExpectDefaultInvocation(); |
| 212 } |
73 | 213 |
74 // The SwReporter should be launched exactly once, with no arguments. | 214 TEST_F(ExperimentalSwReporterInstallerTest, NoExperimentConfig) { |
| 215 // Even if the experiment is supported on this hardware, the user shouldn't |
| 216 // be enrolled unless enabled through variations. |
| 217 SwReporterInstallerTraits traits(launched_callback_, true); |
| 218 ExpectEmptyAttributes(traits); |
| 219 traits.ComponentReady(default_version_, default_path_, |
| 220 std::make_unique<base::DictionaryValue>()); |
| 221 ExpectDefaultInvocation(); |
| 222 } |
| 223 |
| 224 TEST_F(ExperimentalSwReporterInstallerTest, ExperimentUnsupported) { |
| 225 // Even if the experiment config is enabled in variations, the user shouldn't |
| 226 // be enrolled if the hardware doesn't support it. |
| 227 SwReporterInstallerTraits traits(launched_callback_, false); |
| 228 CreateFeatureWithTag(kExperimentTag); |
| 229 ExpectEmptyAttributes(traits); |
| 230 traits.ComponentReady(default_version_, default_path_, |
| 231 std::make_unique<base::DictionaryValue>()); |
| 232 ExpectDefaultInvocation(); |
| 233 } |
| 234 |
| 235 TEST_F(ExperimentalSwReporterInstallerTest, ExperimentMissingTag) { |
| 236 SwReporterInstallerTraits traits(launched_callback_, true); |
| 237 CreateFeatureWithoutTag(); |
| 238 ExpectAttributesWithTag(traits, kMissingTag); |
| 239 histograms_.ExpectUniqueSample(kErrorHistogramName, |
| 240 SW_REPORTER_EXPERIMENT_ERROR_BAD_TAG, 1); |
| 241 } |
| 242 |
| 243 TEST_F(ExperimentalSwReporterInstallerTest, ExperimentInvalidTag) { |
| 244 SwReporterInstallerTraits traits(launched_callback_, true); |
| 245 CreateFeatureWithTag("tag with invalid whitespace chars"); |
| 246 ExpectAttributesWithTag(traits, kMissingTag); |
| 247 histograms_.ExpectUniqueSample(kErrorHistogramName, |
| 248 SW_REPORTER_EXPERIMENT_ERROR_BAD_TAG, 1); |
| 249 } |
| 250 |
| 251 TEST_F(ExperimentalSwReporterInstallerTest, ExperimentTagTooLong) { |
| 252 SwReporterInstallerTraits traits(launched_callback_, true); |
| 253 std::string tag_too_long(500, 'x'); |
| 254 CreateFeatureWithTag(tag_too_long); |
| 255 ExpectAttributesWithTag(traits, kMissingTag); |
| 256 histograms_.ExpectUniqueSample(kErrorHistogramName, |
| 257 SW_REPORTER_EXPERIMENT_ERROR_BAD_TAG, 1); |
| 258 } |
| 259 |
| 260 TEST_F(ExperimentalSwReporterInstallerTest, ExperimentEmptyTag) { |
| 261 SwReporterInstallerTraits traits(launched_callback_, true); |
| 262 CreateFeatureWithTag(""); |
| 263 ExpectAttributesWithTag(traits, kMissingTag); |
| 264 histograms_.ExpectUniqueSample(kErrorHistogramName, |
| 265 SW_REPORTER_EXPERIMENT_ERROR_BAD_TAG, 1); |
| 266 } |
| 267 |
| 268 TEST_F(ExperimentalSwReporterInstallerTest, SingleInvocation) { |
| 269 SwReporterInstallerTraits traits(launched_callback_, true); |
| 270 CreateFeatureWithTag(kExperimentTag); |
| 271 ExpectAttributesWithTag(traits, kExperimentTag); |
| 272 |
| 273 static constexpr char kTestManifest[] = |
| 274 "{\"launch_params\": [" |
| 275 " {" |
| 276 " \"arguments\": [\"--engine=experimental\", \"random argument\"]," |
| 277 " \"suffix\": \"TestSuffix\"" |
| 278 " }" |
| 279 "]}"; |
| 280 traits.ComponentReady( |
| 281 default_version_, default_path_, |
| 282 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); |
| 283 |
| 284 // The SwReporter should be launched once with the given arguments. |
75 EXPECT_EQ(default_version_, launched_version_); | 285 EXPECT_EQ(default_version_, launched_version_); |
76 ASSERT_EQ(1U, launched_invocations_.size()); | 286 ASSERT_EQ(1U, launched_invocations_.size()); |
77 | 287 |
78 const safe_browsing::SwReporterInvocation& invocation = | 288 const safe_browsing::SwReporterInvocation& invocation = |
79 launched_invocations_[0]; | 289 launched_invocations_[0]; |
80 EXPECT_EQ(MakeTestFilePath(default_path_), | 290 EXPECT_EQ(MakeTestFilePath(default_path_), |
81 invocation.command_line.GetProgram()); | 291 invocation.command_line.GetProgram()); |
82 EXPECT_TRUE(invocation.command_line.GetSwitches().empty()); | 292 EXPECT_EQ(2U, invocation.command_line.GetSwitches().size()); |
83 EXPECT_TRUE(invocation.command_line.GetArgs().empty()); | 293 EXPECT_EQ("experimental", |
| 294 invocation.command_line.GetSwitchValueASCII("engine")); |
| 295 EXPECT_EQ("TestSuffix", |
| 296 invocation.command_line.GetSwitchValueASCII(kRegistrySuffixSwitch)); |
| 297 ASSERT_EQ(1U, invocation.command_line.GetArgs().size()); |
| 298 EXPECT_EQ(L"random argument", invocation.command_line.GetArgs()[0]); |
| 299 EXPECT_EQ("TestSuffix", invocation.suffix); |
| 300 EXPECT_TRUE(invocation.is_experimental); |
| 301 histograms_.ExpectTotalCount(kErrorHistogramName, 0); |
| 302 } |
| 303 |
| 304 TEST_F(ExperimentalSwReporterInstallerTest, MultipleInvocations) { |
| 305 SwReporterInstallerTraits traits(launched_callback_, true); |
| 306 CreateFeatureWithTag(kExperimentTag); |
| 307 ExpectAttributesWithTag(traits, kExperimentTag); |
| 308 |
| 309 static constexpr char kTestManifest[] = |
| 310 "{\"launch_params\": [" |
| 311 " {" |
| 312 " \"arguments\": [\"--engine=experimental\", \"random argument\"]," |
| 313 " \"suffix\": \"TestSuffix\"" |
| 314 " }," |
| 315 " {" |
| 316 " \"arguments\": [\"--engine=second\"]," |
| 317 " \"suffix\": \"SecondSuffix\"" |
| 318 " }" |
| 319 "]}"; |
| 320 traits.ComponentReady( |
| 321 default_version_, default_path_, |
| 322 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); |
| 323 |
| 324 // Not supported yet. |
| 325 ExpectLaunchError(); |
| 326 } |
| 327 |
| 328 TEST_F(ExperimentalSwReporterInstallerTest, MissingSuffix) { |
| 329 SwReporterInstallerTraits traits(launched_callback_, true); |
| 330 CreateFeatureWithTag(kExperimentTag); |
| 331 |
| 332 static constexpr char kTestManifest[] = |
| 333 "{\"launch_params\": [" |
| 334 " {" |
| 335 " \"arguments\": [\"random argument\"]" |
| 336 " }" |
| 337 "]}"; |
| 338 traits.ComponentReady( |
| 339 default_version_, default_path_, |
| 340 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); |
| 341 |
| 342 ExpectLaunchError(); |
| 343 } |
| 344 |
| 345 TEST_F(ExperimentalSwReporterInstallerTest, EmptySuffix) { |
| 346 SwReporterInstallerTraits traits(launched_callback_, true); |
| 347 CreateFeatureWithTag(kExperimentTag); |
| 348 |
| 349 static constexpr char kTestManifest[] = |
| 350 "{\"launch_params\": [" |
| 351 " {" |
| 352 " \"suffix\": \"\"," |
| 353 " \"arguments\": [\"random argument\"]" |
| 354 " }" |
| 355 "]}"; |
| 356 traits.ComponentReady( |
| 357 default_version_, default_path_, |
| 358 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); |
| 359 |
| 360 ExpectExperimentalInvocation("", L"random argument"); |
| 361 } |
| 362 |
| 363 TEST_F(ExperimentalSwReporterInstallerTest, MissingSuffixAndArgs) { |
| 364 SwReporterInstallerTraits traits(launched_callback_, true); |
| 365 CreateFeatureWithTag(kExperimentTag); |
| 366 |
| 367 static constexpr char kTestManifest[] = |
| 368 "{\"launch_params\": [" |
| 369 " {" |
| 370 " }" |
| 371 "]}"; |
| 372 traits.ComponentReady( |
| 373 default_version_, default_path_, |
| 374 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); |
| 375 |
| 376 ExpectLaunchError(); |
| 377 } |
| 378 |
| 379 TEST_F(ExperimentalSwReporterInstallerTest, EmptySuffixAndArgs) { |
| 380 SwReporterInstallerTraits traits(launched_callback_, true); |
| 381 CreateFeatureWithTag(kExperimentTag); |
| 382 |
| 383 static constexpr char kTestManifest[] = |
| 384 "{\"launch_params\": [" |
| 385 " {" |
| 386 " \"suffix\": \"\"," |
| 387 " \"arguments\": []" |
| 388 " }" |
| 389 "]}"; |
| 390 traits.ComponentReady( |
| 391 default_version_, default_path_, |
| 392 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); |
| 393 |
| 394 ExpectExperimentalInvocation("", L""); |
| 395 } |
| 396 |
| 397 TEST_F(ExperimentalSwReporterInstallerTest, EmptySuffixAndArgs2) { |
| 398 SwReporterInstallerTraits traits(launched_callback_, true); |
| 399 CreateFeatureWithTag(kExperimentTag); |
| 400 |
| 401 static constexpr char kTestManifest[] = |
| 402 "{\"launch_params\": [" |
| 403 " {" |
| 404 " \"suffix\": \"\"," |
| 405 " \"arguments\": [\"\"]" |
| 406 " }" |
| 407 "]}"; |
| 408 traits.ComponentReady( |
| 409 default_version_, default_path_, |
| 410 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); |
| 411 |
| 412 ExpectExperimentalInvocation("", L""); |
| 413 } |
| 414 |
| 415 TEST_F(ExperimentalSwReporterInstallerTest, MissingArguments) { |
| 416 SwReporterInstallerTraits traits(launched_callback_, true); |
| 417 CreateFeatureWithTag(kExperimentTag); |
| 418 |
| 419 static constexpr char kTestManifest[] = |
| 420 "{\"launch_params\": [" |
| 421 " {" |
| 422 " \"suffix\": \"TestSuffix\"" |
| 423 " }" |
| 424 "]}"; |
| 425 traits.ComponentReady( |
| 426 default_version_, default_path_, |
| 427 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); |
| 428 |
| 429 ExpectLaunchError(); |
| 430 } |
| 431 |
| 432 TEST_F(ExperimentalSwReporterInstallerTest, EmptyArguments) { |
| 433 SwReporterInstallerTraits traits(launched_callback_, true); |
| 434 CreateFeatureWithTag(kExperimentTag); |
| 435 |
| 436 static constexpr char kTestManifest[] = |
| 437 "{\"launch_params\": [" |
| 438 " {" |
| 439 " \"suffix\": \"TestSuffix\"," |
| 440 " \"arguments\": []" |
| 441 " }" |
| 442 "]}"; |
| 443 traits.ComponentReady( |
| 444 default_version_, default_path_, |
| 445 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); |
| 446 |
| 447 ExpectExperimentalInvocation("TestSuffix", L""); |
| 448 } |
| 449 |
| 450 TEST_F(ExperimentalSwReporterInstallerTest, EmptyArguments2) { |
| 451 SwReporterInstallerTraits traits(launched_callback_, true); |
| 452 CreateFeatureWithTag(kExperimentTag); |
| 453 |
| 454 static constexpr char kTestManifest[] = |
| 455 "{\"launch_params\": [" |
| 456 " {" |
| 457 " \"suffix\": \"TestSuffix\"," |
| 458 " \"arguments\": [\"\"]" |
| 459 " }" |
| 460 "]}"; |
| 461 traits.ComponentReady( |
| 462 default_version_, default_path_, |
| 463 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); |
| 464 |
| 465 ExpectExperimentalInvocation("TestSuffix", L""); |
| 466 } |
| 467 |
| 468 TEST_F(ExperimentalSwReporterInstallerTest, EmptyManifest) { |
| 469 SwReporterInstallerTraits traits(launched_callback_, true); |
| 470 CreateFeatureWithTag(kExperimentTag); |
| 471 |
| 472 static constexpr char kTestManifest[] = "{}"; |
| 473 traits.ComponentReady( |
| 474 default_version_, default_path_, |
| 475 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); |
| 476 |
| 477 // 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, |
| 479 // which does not have "launch_params" in its manifest, is already present.) |
| 480 EXPECT_TRUE(launched_invocations_.empty()); |
| 481 histograms_.ExpectTotalCount(kErrorHistogramName, 0); |
| 482 } |
| 483 |
| 484 TEST_F(ExperimentalSwReporterInstallerTest, EmptyLaunchParams) { |
| 485 SwReporterInstallerTraits traits(launched_callback_, true); |
| 486 CreateFeatureWithTag(kExperimentTag); |
| 487 |
| 488 static constexpr char kTestManifest[] = "{\"launch_params\": []}"; |
| 489 traits.ComponentReady( |
| 490 default_version_, default_path_, |
| 491 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); |
| 492 |
| 493 // The SwReporter should not be launched, and an error should be logged. |
| 494 EXPECT_TRUE(launched_invocations_.empty()); |
| 495 histograms_.ExpectUniqueSample(kErrorHistogramName, |
| 496 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1); |
| 497 } |
| 498 |
| 499 TEST_F(ExperimentalSwReporterInstallerTest, EmptyLaunchParams2) { |
| 500 SwReporterInstallerTraits traits(launched_callback_, true); |
| 501 CreateFeatureWithTag(kExperimentTag); |
| 502 |
| 503 static constexpr char kTestManifest[] = "{\"launch_params\": {}}"; |
| 504 traits.ComponentReady( |
| 505 default_version_, default_path_, |
| 506 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); |
| 507 |
| 508 // The SwReporter should not be launched, and an error should be logged. |
| 509 EXPECT_TRUE(launched_invocations_.empty()); |
| 510 histograms_.ExpectUniqueSample(kErrorHistogramName, |
| 511 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1); |
| 512 } |
| 513 |
| 514 TEST_F(ExperimentalSwReporterInstallerTest, BadSuffix) { |
| 515 SwReporterInstallerTraits traits(launched_callback_, true); |
| 516 CreateFeatureWithTag(kExperimentTag); |
| 517 |
| 518 static constexpr char kTestManifest[] = |
| 519 "{\"launch_params\": [" |
| 520 " {" |
| 521 " \"arguments\": [\"--engine=experimental\"]," |
| 522 " \"suffix\": \"invalid whitespace characters\"" |
| 523 " }" |
| 524 "]}"; |
| 525 traits.ComponentReady( |
| 526 default_version_, default_path_, |
| 527 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); |
| 528 |
| 529 // The SwReporter should not be launched, and an error should be logged. |
| 530 EXPECT_TRUE(launched_invocations_.empty()); |
| 531 histograms_.ExpectUniqueSample(kErrorHistogramName, |
| 532 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1); |
| 533 } |
| 534 |
| 535 TEST_F(ExperimentalSwReporterInstallerTest, SuffixTooLong) { |
| 536 SwReporterInstallerTraits traits(launched_callback_, true); |
| 537 CreateFeatureWithTag(kExperimentTag); |
| 538 |
| 539 static constexpr char kTestManifest[] = |
| 540 "{\"launch_params\": [" |
| 541 " {" |
| 542 " \"arguments\": [\"--engine=experimental\"]," |
| 543 " \"suffix\": \"%s\"" |
| 544 " }" |
| 545 "]}"; |
| 546 std::string suffix_too_long(500, 'x'); |
| 547 std::string manifest = |
| 548 base::StringPrintf(kTestManifest, suffix_too_long.c_str()); |
| 549 traits.ComponentReady( |
| 550 default_version_, default_path_, |
| 551 base::DictionaryValue::From(base::JSONReader::Read(manifest))); |
| 552 |
| 553 // The SwReporter should not be launched, and an error should be logged. |
| 554 EXPECT_TRUE(launched_invocations_.empty()); |
| 555 histograms_.ExpectUniqueSample(kErrorHistogramName, |
| 556 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1); |
| 557 } |
| 558 |
| 559 TEST_F(ExperimentalSwReporterInstallerTest, BadTypesInManifest) { |
| 560 SwReporterInstallerTraits traits(launched_callback_, true); |
| 561 CreateFeatureWithTag(kExperimentTag); |
| 562 |
| 563 // This has a string instead of a list for "arguments". |
| 564 static constexpr char kTestManifest[] = |
| 565 "{\"launch_params\": [" |
| 566 " {" |
| 567 " \"arguments\": \"--engine=experimental\"," |
| 568 " \"suffix\": \"TestSuffix\"" |
| 569 " }" |
| 570 "]}"; |
| 571 traits.ComponentReady( |
| 572 default_version_, default_path_, |
| 573 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); |
| 574 |
| 575 // The SwReporter should not be launched, and an error should be logged. |
| 576 EXPECT_TRUE(launched_invocations_.empty()); |
| 577 histograms_.ExpectUniqueSample(kErrorHistogramName, |
| 578 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1); |
| 579 } |
| 580 |
| 581 TEST_F(ExperimentalSwReporterInstallerTest, BadTypesInManifest2) { |
| 582 SwReporterInstallerTraits traits(launched_callback_, true); |
| 583 CreateFeatureWithTag(kExperimentTag); |
| 584 |
| 585 // This has the invocation parameters as direct children of "launch_params", |
| 586 // instead of using a list. |
| 587 static constexpr char kTestManifest[] = |
| 588 "{\"launch_params\": " |
| 589 " {" |
| 590 " \"arguments\": [\"--engine=experimental\"]," |
| 591 " \"suffix\": \"TestSuffix\"" |
| 592 " }" |
| 593 "}"; |
| 594 traits.ComponentReady( |
| 595 default_version_, default_path_, |
| 596 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); |
| 597 |
| 598 // The SwReporter should not be launched, and an error should be logged. |
| 599 EXPECT_TRUE(launched_invocations_.empty()); |
| 600 histograms_.ExpectUniqueSample(kErrorHistogramName, |
| 601 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1); |
| 602 } |
| 603 |
| 604 TEST_F(ExperimentalSwReporterInstallerTest, BadTypesInManifest3) { |
| 605 SwReporterInstallerTraits traits(launched_callback_, true); |
| 606 CreateFeatureWithTag(kExperimentTag); |
| 607 |
| 608 // This has a list for suffix as well as for arguments. |
| 609 static constexpr char kTestManifest[] = |
| 610 "{\"launch_params\": [" |
| 611 " {" |
| 612 " \"arguments\": [\"--engine=experimental\"]," |
| 613 " \"suffix\": [\"TestSuffix\"]" |
| 614 " }" |
| 615 "]}"; |
| 616 traits.ComponentReady( |
| 617 default_version_, default_path_, |
| 618 base::DictionaryValue::From(base::JSONReader::Read(kTestManifest))); |
| 619 |
| 620 // The SwReporter should not be launched, and an error should be logged. |
| 621 EXPECT_TRUE(launched_invocations_.empty()); |
| 622 histograms_.ExpectUniqueSample(kErrorHistogramName, |
| 623 SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1); |
84 } | 624 } |
85 | 625 |
86 } // namespace component_updater | 626 } // namespace component_updater |
OLD | NEW |