Chromium Code Reviews| Index: chrome/installer/mini_installer/configuration_test.cc |
| diff --git a/chrome/installer/mini_installer/configuration_test.cc b/chrome/installer/mini_installer/configuration_test.cc |
| index 3d9766e97cdd788eade6e874169b7542b2deb3d3..02cf2fc3b360a2106e170e07e5fbdafb1a0d1742 100644 |
| --- a/chrome/installer/mini_installer/configuration_test.cc |
| +++ b/chrome/installer/mini_installer/configuration_test.cc |
| @@ -8,13 +8,13 @@ |
| #include <stdlib.h> |
| #include <memory> |
| +#include <vector> |
| #include "base/environment.h" |
| #include "chrome/installer/mini_installer/appid.h" |
| +#include "chrome/installer/mini_installer/mini_installer_constants.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| -using mini_installer::Configuration; |
| - |
| namespace { |
| // A helper class to set the "GoogleUpdateIsMachine" environment variable. |
| @@ -35,40 +35,62 @@ class ScopedGoogleUpdateIsMachine { |
| } // namespace |
| +namespace mini_installer { |
| + |
| class TestConfiguration : public Configuration { |
| public: |
| - explicit TestConfiguration(const wchar_t* command_line) |
| - : Configuration(), |
| - open_registry_key_result_(false), |
| - read_registry_value_result_(0), |
| - read_registry_value_(L"") { |
| - Initialize(command_line); |
| - } |
| - explicit TestConfiguration(const wchar_t* command_line, |
| - LONG ret, const wchar_t* value) |
| - : Configuration(), |
| - open_registry_key_result_(true), |
| - read_registry_value_result_(ret), |
| - read_registry_value_(value) { |
| + using RegistryLocation = Configuration::RegistryLocation; |
|
gab
2016/12/12 21:38:16
Shouldn't this also be inherited?
grt (UTC plus 2)
2016/12/13 09:20:37
This was making the type public for consumers of t
|
| + TestConfiguration() {} |
|
gab
2016/12/12 21:38:16
= default;
grt (UTC plus 2)
2016/12/13 09:20:37
Removed
|
| + explicit TestConfiguration(const wchar_t* command_line) : Configuration() { |
|
gab
2016/12/12 21:38:16
Isn't ": Configuration()" implicit anyways?
grt (UTC plus 2)
2016/12/13 09:20:37
Yes. The original author must have liked being exp
|
| Initialize(command_line); |
| } |
| - void SetRegistryResults(bool openkey, LONG ret, const wchar_t* value) { |
| + void AddRegistryValueResult(RegistryLocation location, |
| + const wchar_t* app_guid, |
| + const wchar_t* value_name, |
| + LONG result, |
| + const wchar_t* value) { |
| + registry_results_.emplace_back(location, app_guid, value_name, result, |
| + value); |
| } |
| - private: |
| - bool open_registry_key_result_; |
| - LONG read_registry_value_result_; |
| - const wchar_t* read_registry_value_ = L""; |
| - |
| void Initialize(const wchar_t* command_line) { |
| Clear(); |
| ASSERT_TRUE(ParseCommandLine(command_line)); |
| } |
| - bool ReadClientStateRegistryValue( |
| - const HKEY root_key, const wchar_t* app_guid, |
| - LONG* retval, ValueString& value) override { |
| - *retval = read_registry_value_result_; |
| - value.assign(read_registry_value_); |
| - return open_registry_key_result_; |
| + |
| + private: |
| + struct RegistryResult { |
| + RegistryLocation registry_location; |
| + const wchar_t* app_guid; |
| + const wchar_t* value_name; |
| + LONG result; |
| + const wchar_t* value; |
| + RegistryResult(RegistryLocation location, |
| + const wchar_t* app_guid, |
| + const wchar_t* value_name, |
| + LONG result, |
| + const wchar_t* value) |
| + : registry_location(location), |
| + app_guid(app_guid), |
| + value_name(value_name), |
| + result(result), |
| + value(value) {} |
| + }; |
| + std::vector<RegistryResult> registry_results_; |
| + |
| + LONG ReadRegistryValue(RegistryLocation location, |
| + const wchar_t* app_guid, |
| + const wchar_t* value_name, |
| + ValueString* value) const override { |
| + for (const auto& result : registry_results_) { |
| + if (result.registry_location == location && |
| + !::wcscmp(result.app_guid, app_guid) && |
| + !::wcscmp(result.value_name, value_name)) { |
| + if (result.value) |
| + value->assign(result.value); |
| + return result.result; |
| + } |
| + } |
| + return ERROR_FILE_NOT_FOUND; |
| } |
| }; |
| @@ -115,49 +137,63 @@ TEST(MiniInstallerConfigurationTest, CommandLine) { |
| } |
| } |
| -TEST(MiniInstallerConfigurationTest, ChromeAppGuid) { |
| - EXPECT_TRUE(std::wstring(google_update::kAppGuid) == |
| - TestConfiguration(L"spam.exe").chrome_app_guid()); |
| - EXPECT_TRUE(std::wstring(google_update::kAppGuid) == |
| - TestConfiguration(L"spam.exe --chrome").chrome_app_guid()); |
| - EXPECT_TRUE(std::wstring(google_update::kSxSAppGuid) == |
| - TestConfiguration(L"spam.exe --chrome-sxs").chrome_app_guid()); |
| - EXPECT_TRUE(std::wstring(google_update::kMultiInstallAppGuid) == |
| - TestConfiguration(L"spam.exe --multi-install --chrome") |
| - .chrome_app_guid()); |
| - EXPECT_TRUE(std::wstring(google_update::kMultiInstallAppGuid) == |
| - TestConfiguration(L"spam.exe --multi-install --chrome", |
| - ERROR_INVALID_FUNCTION, L"") |
| - .chrome_app_guid()); |
| - EXPECT_TRUE(std::wstring(google_update::kAppGuid) == |
| - TestConfiguration(L"spam.exe --multi-install --chrome", |
| - ERROR_FILE_NOT_FOUND, L"") |
| - .chrome_app_guid()); |
| - EXPECT_TRUE(std::wstring(google_update::kAppGuid) == |
| - TestConfiguration(L"spam.exe --multi-install --chrome", |
| - ERROR_SUCCESS, L"foo-bar") |
| - .chrome_app_guid()); |
| - EXPECT_TRUE(std::wstring(google_update::kMultiInstallAppGuid) == |
| - TestConfiguration(L"spam.exe --multi-install --chrome", |
| - ERROR_SUCCESS, L"foo-multi") |
| - .chrome_app_guid()); |
| -} |
| +TEST(MiniInstallerConfigurationTest, IsUpdatingMultiChrome) { |
| +#if defined(GOOGLE_CHROME_BUILD) |
| + EXPECT_FALSE(TestConfiguration(L"spam.exe").is_updating_multi_chrome()); |
| + EXPECT_FALSE( |
| + TestConfiguration(L"spam.exe --chrome-sxs").is_updating_multi_chrome()); |
| + EXPECT_FALSE(TestConfiguration(L"spam.exe --multi-install --chrome") |
| + .is_updating_multi_chrome()); |
| + EXPECT_FALSE(TestConfiguration(L"spam.exe --multi-install") |
| + .is_updating_multi_chrome()); |
| -TEST(MiniInstallerConfigurationTest, HasChrome) { |
| - EXPECT_TRUE(TestConfiguration(L"spam.exe").has_chrome()); |
| - EXPECT_TRUE(TestConfiguration(L"spam.exe --chrome").has_chrome()); |
| - EXPECT_TRUE(TestConfiguration(L"spam.exe --multi-install --chrome") |
| - .has_chrome()); |
| - EXPECT_FALSE(TestConfiguration(L"spam.exe --multi-install").has_chrome()); |
| + { |
| + TestConfiguration configuration; |
| + configuration.AddRegistryValueResult( |
| + TestConfiguration::RegistryLocation::CLIENTS_KEY, |
| + google_update::kAppGuid, kPvRegistryValue, ERROR_SUCCESS, L"4.3.2.1"); |
| + configuration.AddRegistryValueResult( |
| + TestConfiguration::RegistryLocation::CLIENT_STATE_KEY, |
| + google_update::kAppGuid, kUninstallArgumentsRegistryValue, |
| + ERROR_SUCCESS, L"--uninstall --multi-install"); |
| + configuration.Initialize(L"spam.exe"); |
| + EXPECT_TRUE(configuration.is_updating_multi_chrome()); |
| + } |
| + |
| + { |
| + TestConfiguration configuration; |
| + configuration.AddRegistryValueResult( |
| + TestConfiguration::RegistryLocation::CLIENTS_KEY, |
| + google_update::kAppGuid, kPvRegistryValue, ERROR_SUCCESS, L"4.3.2.1"); |
| + configuration.AddRegistryValueResult( |
| + TestConfiguration::RegistryLocation::CLIENT_STATE_KEY, |
| + google_update::kAppGuid, kUninstallArgumentsRegistryValue, |
| + ERROR_SUCCESS, L"--uninstall"); |
| + configuration.Initialize(L"spam.exe"); |
| + EXPECT_FALSE(configuration.is_updating_multi_chrome()); |
| + } |
| + |
| + { |
| + TestConfiguration configuration; |
| + configuration.AddRegistryValueResult( |
| + TestConfiguration::RegistryLocation::CLIENTS_KEY, |
| + google_update::kAppGuid, kPvRegistryValue, ERROR_FILE_NOT_FOUND, |
| + nullptr); |
| + configuration.Initialize(L"spam.exe"); |
| + EXPECT_FALSE(configuration.is_updating_multi_chrome()); |
| + } |
| +#else |
| + EXPECT_FALSE(TestConfiguration(L"spam.exe").is_updating_multi_chrome()); |
| +#endif |
| } |
| -TEST(MiniInstallerConfigurationTest, IsMultiInstall) { |
| - EXPECT_FALSE(TestConfiguration(L"spam.exe").is_multi_install()); |
| - EXPECT_FALSE(TestConfiguration(L"spam.exe --chrome").is_multi_install()); |
| - EXPECT_TRUE(TestConfiguration(L"spam.exe --multi-install --chrome") |
| - .is_multi_install()); |
| - EXPECT_TRUE(TestConfiguration(L"spam.exe --multi-install") |
| - .is_multi_install()); |
| +TEST(MiniInstallerConfigurationTest, ChromeAppGuid) { |
| +#if defined(GOOGLE_CHROME_BUILD) |
| + EXPECT_STREQ(google_update::kAppGuid, |
| + TestConfiguration(L"spam.exe").chrome_app_guid()); |
| + EXPECT_STREQ(google_update::kSxSAppGuid, |
| + TestConfiguration(L"spam.exe --chrome-sxs").chrome_app_guid()); |
| +#endif |
| } |
| TEST(MiniInstallerConfigurationTest, IsSystemLevel) { |
| @@ -176,8 +212,19 @@ TEST(MiniInstallerConfigurationTest, IsSystemLevel) { |
| } |
| } |
| +TEST(MiniInstallerConfigurationTest, IsSideBySide) { |
| + EXPECT_FALSE(TestConfiguration(L"spam.exe").is_side_by_side()); |
| +#if defined(GOOGLE_CHROME_BUILD) |
| + EXPECT_TRUE(TestConfiguration(L"spam.exe --chrome-sxs").is_side_by_side()); |
| +#else |
| + EXPECT_FALSE(TestConfiguration(L"spam.exe --chrome-sxs").is_side_by_side()); |
| +#endif |
| +} |
| + |
| TEST(MiniInstallerConfigurationTest, HasInvalidSwitch) { |
| EXPECT_FALSE(TestConfiguration(L"spam.exe").has_invalid_switch()); |
| EXPECT_TRUE(TestConfiguration(L"spam.exe --chrome-frame") |
| .has_invalid_switch()); |
| } |
| + |
| +} // namespace mini_installer |