| Index: chrome/browser/component_updater/sw_reporter_installer_win_unittest.cc
|
| diff --git a/chrome/browser/component_updater/sw_reporter_installer_win_unittest.cc b/chrome/browser/component_updater/sw_reporter_installer_win_unittest.cc
|
| index 0c8cb199a4c40882c2e7fc1d2137c3a0aa18af6b..ef1a66c0b778b99e0c76113cd9fb49f98e6f8cfa 100644
|
| --- a/chrome/browser/component_updater/sw_reporter_installer_win_unittest.cc
|
| +++ b/chrome/browser/component_updater/sw_reporter_installer_win_unittest.cc
|
| @@ -8,7 +8,6 @@
|
| #include <memory>
|
| #include <string>
|
| #include <utility>
|
| -#include <vector>
|
|
|
| #include "base/bind.h"
|
| #include "base/bind_helpers.h"
|
| @@ -37,6 +36,8 @@ constexpr char kErrorHistogramName[] = "SoftwareReporter.ExperimentErrors";
|
| constexpr char kExperimentTag[] = "experiment_tag";
|
| constexpr char kMissingTag[] = "missing_tag";
|
|
|
| +using safe_browsing::SwReporterInvocation;
|
| +
|
| } // namespace
|
|
|
| class SwReporterInstallerTest : public ::testing::Test {
|
| @@ -46,15 +47,17 @@ class SwReporterInstallerTest : public ::testing::Test {
|
| base::Bind(&SwReporterInstallerTest::SwReporterLaunched,
|
| base::Unretained(this))),
|
| default_version_("1.2.3"),
|
| - default_path_(L"C:\\full\\path\\to\\download") {}
|
| + default_path_(L"C:\\full\\path\\to\\download"),
|
| + launched_version_("0.0.0") {}
|
|
|
| ~SwReporterInstallerTest() override {}
|
|
|
| protected:
|
| - void SwReporterLaunched(const safe_browsing::SwReporterInvocation& invocation,
|
| - const base::Version& version) {
|
| - ASSERT_TRUE(launched_invocations_.empty());
|
| - launched_invocations_.push_back(invocation);
|
| + void SwReporterLaunched(
|
| + std::unique_ptr<safe_browsing::SwReporterQueue> invocations,
|
| + const base::Version& version) {
|
| + ASSERT_FALSE(launched_invocations_);
|
| + launched_invocations_ = std::move(invocations);
|
| launched_version_ = version;
|
| }
|
|
|
| @@ -71,16 +74,19 @@ class SwReporterInstallerTest : public ::testing::Test {
|
| // Expects that the SwReporter was launched exactly once, with no arguments.
|
| void ExpectDefaultInvocation() const {
|
| EXPECT_EQ(default_version_, launched_version_);
|
| - ASSERT_EQ(1U, launched_invocations_.size());
|
| + ASSERT_TRUE(launched_invocations_);
|
| + ASSERT_EQ(1U, launched_invocations_->size());
|
|
|
| - const safe_browsing::SwReporterInvocation& invocation =
|
| - launched_invocations_[0];
|
| + const SwReporterInvocation& invocation = launched_invocations_->front();
|
| EXPECT_EQ(MakeTestFilePath(default_path_),
|
| invocation.command_line.GetProgram());
|
| EXPECT_TRUE(invocation.command_line.GetSwitches().empty());
|
| EXPECT_TRUE(invocation.command_line.GetArgs().empty());
|
| EXPECT_TRUE(invocation.suffix.empty());
|
| - EXPECT_FALSE(invocation.is_experimental);
|
| + EXPECT_EQ(SwReporterInvocation::FLAG_LOG_TO_RAPPOR |
|
| + SwReporterInvocation::FLAG_LOG_TO_PREFS |
|
| + SwReporterInvocation::FLAG_TRIGGER_PROMPT,
|
| + invocation.flags);
|
| }
|
|
|
| // |ComponentReady| asserts that it is run on the UI thread, so we must
|
| @@ -95,7 +101,7 @@ class SwReporterInstallerTest : public ::testing::Test {
|
| base::FilePath default_path_;
|
|
|
| // Results of running |ComponentReady|.
|
| - std::vector<safe_browsing::SwReporterInvocation> launched_invocations_;
|
| + std::unique_ptr<safe_browsing::SwReporterQueue> launched_invocations_;
|
| base::Version launched_version_;
|
|
|
| private:
|
| @@ -159,10 +165,10 @@ class ExperimentalSwReporterInstallerTest : public SwReporterInstallerTest {
|
| const std::string& expected_suffix,
|
| const base::string16& expected_additional_argument) {
|
| EXPECT_EQ(default_version_, launched_version_);
|
| - ASSERT_EQ(1U, launched_invocations_.size());
|
| + ASSERT_TRUE(launched_invocations_);
|
| + ASSERT_EQ(1U, launched_invocations_->size());
|
|
|
| - const safe_browsing::SwReporterInvocation& invocation =
|
| - launched_invocations_[0];
|
| + const SwReporterInvocation& invocation = launched_invocations_->front();
|
| EXPECT_EQ(MakeTestFilePath(default_path_),
|
| invocation.command_line.GetProgram());
|
|
|
| @@ -184,13 +190,13 @@ class ExperimentalSwReporterInstallerTest : public SwReporterInstallerTest {
|
| invocation.command_line.GetArgs()[0]);
|
| }
|
|
|
| - EXPECT_TRUE(invocation.is_experimental);
|
| + EXPECT_EQ(0, invocation.flags);
|
| histograms_.ExpectTotalCount(kErrorHistogramName, 0);
|
| }
|
|
|
| void ExpectLaunchError() {
|
| // The SwReporter should not be launched, and an error should be logged.
|
| - EXPECT_TRUE(launched_invocations_.empty());
|
| + EXPECT_FALSE(launched_invocations_);
|
| histograms_.ExpectUniqueSample(kErrorHistogramName,
|
| SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1);
|
| }
|
| @@ -274,7 +280,8 @@ TEST_F(ExperimentalSwReporterInstallerTest, SingleInvocation) {
|
| "{\"launch_params\": ["
|
| " {"
|
| " \"arguments\": [\"--engine=experimental\", \"random argument\"],"
|
| - " \"suffix\": \"TestSuffix\""
|
| + " \"suffix\": \"TestSuffix\","
|
| + " \"prompt\": false"
|
| " }"
|
| "]}";
|
| traits.ComponentReady(
|
| @@ -283,10 +290,10 @@ TEST_F(ExperimentalSwReporterInstallerTest, SingleInvocation) {
|
|
|
| // The SwReporter should be launched once with the given arguments.
|
| EXPECT_EQ(default_version_, launched_version_);
|
| - ASSERT_EQ(1U, launched_invocations_.size());
|
| + ASSERT_TRUE(launched_invocations_);
|
| + ASSERT_EQ(1U, launched_invocations_->size());
|
|
|
| - const safe_browsing::SwReporterInvocation& invocation =
|
| - launched_invocations_[0];
|
| + const SwReporterInvocation& invocation = launched_invocations_->front();
|
| EXPECT_EQ(MakeTestFilePath(default_path_),
|
| invocation.command_line.GetProgram());
|
| EXPECT_EQ(2U, invocation.command_line.GetSwitches().size());
|
| @@ -297,7 +304,7 @@ TEST_F(ExperimentalSwReporterInstallerTest, SingleInvocation) {
|
| ASSERT_EQ(1U, invocation.command_line.GetArgs().size());
|
| EXPECT_EQ(L"random argument", invocation.command_line.GetArgs()[0]);
|
| EXPECT_EQ("TestSuffix", invocation.suffix);
|
| - EXPECT_TRUE(invocation.is_experimental);
|
| + EXPECT_EQ(0, invocation.flags);
|
| histograms_.ExpectTotalCount(kErrorHistogramName, 0);
|
| }
|
|
|
| @@ -310,19 +317,74 @@ TEST_F(ExperimentalSwReporterInstallerTest, MultipleInvocations) {
|
| "{\"launch_params\": ["
|
| " {"
|
| " \"arguments\": [\"--engine=experimental\", \"random argument\"],"
|
| - " \"suffix\": \"TestSuffix\""
|
| + " \"suffix\": \"TestSuffix\","
|
| + " \"prompt\": false"
|
| " },"
|
| " {"
|
| " \"arguments\": [\"--engine=second\"],"
|
| - " \"suffix\": \"SecondSuffix\""
|
| + " \"suffix\": \"SecondSuffix\","
|
| + " \"prompt\": true"
|
| + " },"
|
| + " {"
|
| + " \"arguments\": [\"--engine=third\"],"
|
| + " \"suffix\": \"ThirdSuffix\""
|
| " }"
|
| "]}";
|
| traits.ComponentReady(
|
| default_version_, default_path_,
|
| base::DictionaryValue::From(base::JSONReader::Read(kTestManifest)));
|
|
|
| - // Not supported yet.
|
| - ExpectLaunchError();
|
| + // The SwReporter should be launched three times with the given arguments.
|
| + EXPECT_EQ(default_version_, launched_version_);
|
| + ASSERT_TRUE(launched_invocations_);
|
| + ASSERT_EQ(3U, launched_invocations_->size());
|
| +
|
| + {
|
| + SwReporterInvocation invocation = launched_invocations_->front();
|
| + launched_invocations_->pop();
|
| + EXPECT_EQ(MakeTestFilePath(default_path_),
|
| + invocation.command_line.GetProgram());
|
| + EXPECT_EQ(2U, invocation.command_line.GetSwitches().size());
|
| + EXPECT_EQ("experimental",
|
| + invocation.command_line.GetSwitchValueASCII("engine"));
|
| + EXPECT_EQ("TestSuffix", invocation.command_line.GetSwitchValueASCII(
|
| + kRegistrySuffixSwitch));
|
| + ASSERT_EQ(1U, invocation.command_line.GetArgs().size());
|
| + EXPECT_EQ(L"random argument", invocation.command_line.GetArgs()[0]);
|
| + EXPECT_EQ("TestSuffix", invocation.suffix);
|
| + EXPECT_EQ(0, invocation.flags);
|
| + }
|
| +
|
| + {
|
| + SwReporterInvocation invocation = launched_invocations_->front();
|
| + launched_invocations_->pop();
|
| + EXPECT_EQ(MakeTestFilePath(default_path_),
|
| + invocation.command_line.GetProgram());
|
| + EXPECT_EQ(2U, invocation.command_line.GetSwitches().size());
|
| + EXPECT_EQ("second", invocation.command_line.GetSwitchValueASCII("engine"));
|
| + EXPECT_EQ("SecondSuffix", invocation.command_line.GetSwitchValueASCII(
|
| + kRegistrySuffixSwitch));
|
| + ASSERT_TRUE(invocation.command_line.GetArgs().empty());
|
| + EXPECT_EQ("SecondSuffix", invocation.suffix);
|
| + EXPECT_EQ(SwReporterInvocation::FLAG_TRIGGER_PROMPT, invocation.flags);
|
| + }
|
| +
|
| + {
|
| + SwReporterInvocation invocation = launched_invocations_->front();
|
| + launched_invocations_->pop();
|
| + EXPECT_EQ(MakeTestFilePath(default_path_),
|
| + invocation.command_line.GetProgram());
|
| + EXPECT_EQ(2U, invocation.command_line.GetSwitches().size());
|
| + EXPECT_EQ("third", invocation.command_line.GetSwitchValueASCII("engine"));
|
| + EXPECT_EQ("ThirdSuffix", invocation.command_line.GetSwitchValueASCII(
|
| + kRegistrySuffixSwitch));
|
| + ASSERT_TRUE(invocation.command_line.GetArgs().empty());
|
| + EXPECT_EQ("ThirdSuffix", invocation.suffix);
|
| + // A missing "prompt" key means "false".
|
| + EXPECT_EQ(0, invocation.flags);
|
| + }
|
| +
|
| + histograms_.ExpectTotalCount(kErrorHistogramName, 0);
|
| }
|
|
|
| TEST_F(ExperimentalSwReporterInstallerTest, MissingSuffix) {
|
| @@ -477,7 +539,7 @@ TEST_F(ExperimentalSwReporterInstallerTest, EmptyManifest) {
|
| // The SwReporter should not be launched, but no error should be logged.
|
| // (This tests the case where a non-experimental version of the reporter,
|
| // which does not have "launch_params" in its manifest, is already present.)
|
| - EXPECT_TRUE(launched_invocations_.empty());
|
| + EXPECT_FALSE(launched_invocations_);
|
| histograms_.ExpectTotalCount(kErrorHistogramName, 0);
|
| }
|
|
|
| @@ -491,7 +553,7 @@ TEST_F(ExperimentalSwReporterInstallerTest, EmptyLaunchParams) {
|
| base::DictionaryValue::From(base::JSONReader::Read(kTestManifest)));
|
|
|
| // The SwReporter should not be launched, and an error should be logged.
|
| - EXPECT_TRUE(launched_invocations_.empty());
|
| + EXPECT_FALSE(launched_invocations_);
|
| histograms_.ExpectUniqueSample(kErrorHistogramName,
|
| SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1);
|
| }
|
| @@ -506,7 +568,7 @@ TEST_F(ExperimentalSwReporterInstallerTest, EmptyLaunchParams2) {
|
| base::DictionaryValue::From(base::JSONReader::Read(kTestManifest)));
|
|
|
| // The SwReporter should not be launched, and an error should be logged.
|
| - EXPECT_TRUE(launched_invocations_.empty());
|
| + EXPECT_FALSE(launched_invocations_);
|
| histograms_.ExpectUniqueSample(kErrorHistogramName,
|
| SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1);
|
| }
|
| @@ -527,7 +589,7 @@ TEST_F(ExperimentalSwReporterInstallerTest, BadSuffix) {
|
| base::DictionaryValue::From(base::JSONReader::Read(kTestManifest)));
|
|
|
| // The SwReporter should not be launched, and an error should be logged.
|
| - EXPECT_TRUE(launched_invocations_.empty());
|
| + EXPECT_FALSE(launched_invocations_);
|
| histograms_.ExpectUniqueSample(kErrorHistogramName,
|
| SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1);
|
| }
|
| @@ -551,7 +613,7 @@ TEST_F(ExperimentalSwReporterInstallerTest, SuffixTooLong) {
|
| base::DictionaryValue::From(base::JSONReader::Read(manifest)));
|
|
|
| // The SwReporter should not be launched, and an error should be logged.
|
| - EXPECT_TRUE(launched_invocations_.empty());
|
| + EXPECT_FALSE(launched_invocations_);
|
| histograms_.ExpectUniqueSample(kErrorHistogramName,
|
| SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1);
|
| }
|
| @@ -573,7 +635,7 @@ TEST_F(ExperimentalSwReporterInstallerTest, BadTypesInManifest) {
|
| base::DictionaryValue::From(base::JSONReader::Read(kTestManifest)));
|
|
|
| // The SwReporter should not be launched, and an error should be logged.
|
| - EXPECT_TRUE(launched_invocations_.empty());
|
| + EXPECT_FALSE(launched_invocations_);
|
| histograms_.ExpectUniqueSample(kErrorHistogramName,
|
| SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1);
|
| }
|
| @@ -596,7 +658,7 @@ TEST_F(ExperimentalSwReporterInstallerTest, BadTypesInManifest2) {
|
| base::DictionaryValue::From(base::JSONReader::Read(kTestManifest)));
|
|
|
| // The SwReporter should not be launched, and an error should be logged.
|
| - EXPECT_TRUE(launched_invocations_.empty());
|
| + EXPECT_FALSE(launched_invocations_);
|
| histograms_.ExpectUniqueSample(kErrorHistogramName,
|
| SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1);
|
| }
|
| @@ -618,9 +680,31 @@ TEST_F(ExperimentalSwReporterInstallerTest, BadTypesInManifest3) {
|
| base::DictionaryValue::From(base::JSONReader::Read(kTestManifest)));
|
|
|
| // The SwReporter should not be launched, and an error should be logged.
|
| - EXPECT_TRUE(launched_invocations_.empty());
|
| + EXPECT_FALSE(launched_invocations_);
|
| histograms_.ExpectUniqueSample(kErrorHistogramName,
|
| SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1);
|
| }
|
|
|
| +TEST_F(ExperimentalSwReporterInstallerTest, BadTypesInManifest4) {
|
| + SwReporterInstallerTraits traits(launched_callback_, true);
|
| + CreateFeatureWithTag(kExperimentTag);
|
| +
|
| + // This has an int instead of a bool for prompt.
|
| + static constexpr char kTestManifest[] =
|
| + "{\"launch_params\": ["
|
| + " {"
|
| + " \"arguments\": [\"--engine=experimental\"],"
|
| + " \"suffix\": \"TestSuffix\","
|
| + " \"prompt\": 1"
|
| + " }"
|
| + "]}";
|
| + traits.ComponentReady(
|
| + default_version_, default_path_,
|
| + base::DictionaryValue::From(base::JSONReader::Read(kTestManifest)));
|
| +
|
| + // The SwReporter should not be launched, and an error should be logged.
|
| + EXPECT_FALSE(launched_invocations_);
|
| + histograms_.ExpectUniqueSample(kErrorHistogramName,
|
| + SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS, 1);
|
| +}
|
| } // namespace component_updater
|
|
|