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