Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2862)

Unified Diff: chrome/installer/util/product_state_unittest.cc

Issue 2618583005: Remove support for non-browser products from InstallationState and ProductState. (Closed)
Patch Set: fix Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/installer/util/product_state_unittest.cc
diff --git a/chrome/installer/util/product_state_unittest.cc b/chrome/installer/util/product_state_unittest.cc
index 1b710e0f2d787e4c52542764d782bf522862e3c7..23cf0bbfd3f74c19fedef83fb1069ed760d5a555 100644
--- a/chrome/installer/util/product_state_unittest.cc
+++ b/chrome/installer/util/product_state_unittest.cc
@@ -4,7 +4,6 @@
#include <windows.h>
-#include "base/strings/utf_string_conversions.h"
#include "base/test/test_reg_util_win.h"
#include "base/version.h"
#include "base/win/registry.h"
@@ -14,76 +13,34 @@
#include "chrome/installer/util/util_constants.h"
#include "testing/gtest/include/gtest/gtest.h"
-using base::win::RegKey;
-using installer::ProductState;
-using registry_util::RegistryOverrideManager;
+namespace installer {
class ProductStateTest : public testing::Test {
protected:
- static void SetUpTestCase();
- static void TearDownTestCase();
-
- void SetUp() override;
- void TearDown() override;
+ ProductStateTest();
void ApplyUninstallCommand(const wchar_t* exe_path, const wchar_t* args);
void MinimallyInstallProduct(const wchar_t* version);
- static BrowserDistribution* dist_;
- bool system_install_;
- HKEY overridden_;
+ const bool system_install_;
+ const HKEY overridden_;
registry_util::RegistryOverrideManager registry_override_manager_;
- RegKey clients_;
- RegKey client_state_;
+ base::win::RegKey clients_;
+ base::win::RegKey client_state_;
};
-BrowserDistribution* ProductStateTest::dist_;
-
-// static
-void ProductStateTest::SetUpTestCase() {
- testing::Test::SetUpTestCase();
-
- // We'll use Chrome as our test subject.
- dist_ = BrowserDistribution::GetSpecificDistribution(
- BrowserDistribution::CHROME_BROWSER);
-}
-
-// static
-void ProductStateTest::TearDownTestCase() {
- dist_ = NULL;
-
- testing::Test::TearDownTestCase();
-}
-
-void ProductStateTest::SetUp() {
- testing::Test::SetUp();
-
- // Create/open the keys for the product we'll test.
- system_install_ = true;
- overridden_ = (system_install_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER);
-
- // Override for test purposes. We don't use ScopedRegistryKeyOverride
- // directly because it doesn't suit itself to our use here.
- RegKey temp_key;
-
+ProductStateTest::ProductStateTest()
+ : system_install_(true),
huangs 2017/01/09 09:09:10 Test looks broken: It skips user-level altogether.
grt (UTC plus 2) 2017/01/09 10:11:45 Added coverage for user-level.
+ overridden_(system_install_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER) {
registry_override_manager_.OverrideRegistry(overridden_);
+ BrowserDistribution* dist = BrowserDistribution::GetDistribution();
EXPECT_EQ(ERROR_SUCCESS,
- clients_.Create(overridden_, dist_->GetVersionKey().c_str(),
- KEY_ALL_ACCESS));
+ clients_.Create(overridden_, dist->GetVersionKey().c_str(),
+ KEY_ALL_ACCESS | KEY_WOW64_32KEY));
EXPECT_EQ(ERROR_SUCCESS,
- client_state_.Create(overridden_, dist_->GetStateKey().c_str(),
- KEY_ALL_ACCESS));
-}
-
-void ProductStateTest::TearDown() {
- // Done with the keys.
- client_state_.Close();
- clients_.Close();
- overridden_ = NULL;
- system_install_ = false;
-
- testing::Test::TearDown();
+ client_state_.Create(overridden_, dist->GetStateKey().c_str(),
+ KEY_ALL_ACCESS | KEY_WOW64_32KEY));
}
void ProductStateTest::MinimallyInstallProduct(const wchar_t* version) {
@@ -94,22 +51,19 @@ void ProductStateTest::MinimallyInstallProduct(const wchar_t* version) {
void ProductStateTest::ApplyUninstallCommand(const wchar_t* exe_path,
const wchar_t* args) {
if (exe_path == NULL) {
- LONG result = client_state_.DeleteValue(installer::kUninstallStringField);
+ LONG result = client_state_.DeleteValue(kUninstallStringField);
EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND);
} else {
EXPECT_EQ(ERROR_SUCCESS,
- client_state_.WriteValue(installer::kUninstallStringField,
- exe_path));
+ client_state_.WriteValue(kUninstallStringField, exe_path));
}
if (args == NULL) {
- LONG result =
- client_state_.DeleteValue(installer::kUninstallArgumentsField);
+ LONG result = client_state_.DeleteValue(kUninstallArgumentsField);
EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND);
} else {
EXPECT_EQ(ERROR_SUCCESS,
- client_state_.WriteValue(installer::kUninstallArgumentsField,
- args));
+ client_state_.WriteValue(kUninstallArgumentsField, args));
}
}
@@ -119,7 +73,7 @@ TEST_F(ProductStateTest, InitializeInstalled) {
ProductState state;
LONG result = clients_.DeleteValue(google_update::kRegVersionField);
EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND);
- EXPECT_FALSE(state.Initialize(system_install_, dist_));
+ EXPECT_FALSE(state.Initialize(system_install_));
}
// Empty version.
@@ -127,7 +81,7 @@ TEST_F(ProductStateTest, InitializeInstalled) {
ProductState state;
LONG result = clients_.WriteValue(google_update::kRegVersionField, L"");
EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND);
- EXPECT_FALSE(state.Initialize(system_install_, dist_));
+ EXPECT_FALSE(state.Initialize(system_install_));
}
// Bogus version.
@@ -136,7 +90,7 @@ TEST_F(ProductStateTest, InitializeInstalled) {
LONG result = clients_.WriteValue(google_update::kRegVersionField,
L"goofy");
EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND);
- EXPECT_FALSE(state.Initialize(system_install_, dist_));
+ EXPECT_FALSE(state.Initialize(system_install_));
}
// Valid "pv" value.
@@ -145,7 +99,7 @@ TEST_F(ProductStateTest, InitializeInstalled) {
LONG result = clients_.WriteValue(google_update::kRegVersionField,
L"10.0.47.0");
EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND);
- EXPECT_TRUE(state.Initialize(system_install_, dist_));
+ EXPECT_TRUE(state.Initialize(system_install_));
EXPECT_EQ("10.0.47.0", state.version().GetString());
}
}
@@ -159,7 +113,7 @@ TEST_F(ProductStateTest, InitializeOldVersion) {
ProductState state;
LONG result = clients_.DeleteValue(google_update::kRegOldVersionField);
EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND);
- EXPECT_TRUE(state.Initialize(system_install_, dist_));
+ EXPECT_TRUE(state.Initialize(system_install_));
EXPECT_TRUE(state.old_version() == NULL);
}
@@ -168,7 +122,7 @@ TEST_F(ProductStateTest, InitializeOldVersion) {
ProductState state;
LONG result = clients_.WriteValue(google_update::kRegOldVersionField, L"");
EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND);
- EXPECT_TRUE(state.Initialize(system_install_, dist_));
+ EXPECT_TRUE(state.Initialize(system_install_));
EXPECT_TRUE(state.old_version() == NULL);
}
@@ -178,7 +132,7 @@ TEST_F(ProductStateTest, InitializeOldVersion) {
LONG result = clients_.WriteValue(google_update::kRegOldVersionField,
L"coming home");
EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND);
- EXPECT_TRUE(state.Initialize(system_install_, dist_));
+ EXPECT_TRUE(state.Initialize(system_install_));
EXPECT_TRUE(state.old_version() == NULL);
}
@@ -188,7 +142,7 @@ TEST_F(ProductStateTest, InitializeOldVersion) {
LONG result = clients_.WriteValue(google_update::kRegOldVersionField,
L"10.0.47.0");
EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND);
- EXPECT_TRUE(state.Initialize(system_install_, dist_));
+ EXPECT_TRUE(state.Initialize(system_install_));
EXPECT_TRUE(state.old_version() != NULL);
EXPECT_EQ("10.0.47.0", state.old_version()->GetString());
}
@@ -203,7 +157,7 @@ TEST_F(ProductStateTest, InitializeRenameCmd) {
ProductState state;
LONG result = clients_.DeleteValue(google_update::kRegRenameCmdField);
EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND);
- EXPECT_TRUE(state.Initialize(system_install_, dist_));
+ EXPECT_TRUE(state.Initialize(system_install_));
EXPECT_TRUE(state.rename_cmd().empty());
}
@@ -212,7 +166,7 @@ TEST_F(ProductStateTest, InitializeRenameCmd) {
ProductState state;
LONG result = clients_.WriteValue(google_update::kRegRenameCmdField, L"");
EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND);
- EXPECT_TRUE(state.Initialize(system_install_, dist_));
+ EXPECT_TRUE(state.Initialize(system_install_));
EXPECT_TRUE(state.rename_cmd().empty());
}
@@ -222,7 +176,7 @@ TEST_F(ProductStateTest, InitializeRenameCmd) {
LONG result = clients_.WriteValue(google_update::kRegRenameCmdField,
L"spam.exe --spamalot");
EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND);
- EXPECT_TRUE(state.Initialize(system_install_, dist_));
+ EXPECT_TRUE(state.Initialize(system_install_));
EXPECT_EQ(L"spam.exe --spamalot", state.rename_cmd());
}
}
@@ -236,7 +190,7 @@ TEST_F(ProductStateTest, InitializeChannelInfo) {
ProductState state;
LONG result = client_state_.DeleteValue(google_update::kRegApField);
EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND);
- EXPECT_TRUE(state.Initialize(system_install_, dist_));
+ EXPECT_TRUE(state.Initialize(system_install_));
EXPECT_TRUE(state.channel().value().empty());
}
@@ -245,7 +199,7 @@ TEST_F(ProductStateTest, InitializeChannelInfo) {
ProductState state;
LONG result = client_state_.WriteValue(google_update::kRegApField, L"");
EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND);
- EXPECT_TRUE(state.Initialize(system_install_, dist_));
+ EXPECT_TRUE(state.Initialize(system_install_));
EXPECT_TRUE(state.channel().value().empty());
}
@@ -254,7 +208,7 @@ TEST_F(ProductStateTest, InitializeChannelInfo) {
ProductState state;
LONG result = client_state_.WriteValue(google_update::kRegApField, L"spam");
EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND);
- EXPECT_TRUE(state.Initialize(system_install_, dist_));
+ EXPECT_TRUE(state.Initialize(system_install_));
EXPECT_EQ(L"spam", state.channel().value());
}
}
@@ -268,7 +222,7 @@ TEST_F(ProductStateTest, InitializeUninstallCommand) {
{
ProductState state;
ApplyUninstallCommand(NULL, NULL);
- EXPECT_TRUE(state.Initialize(system_install_, dist_));
+ EXPECT_TRUE(state.Initialize(system_install_));
EXPECT_TRUE(state.GetSetupPath().empty());
EXPECT_TRUE(state.uninstall_command().GetCommandLineString().empty());
EXPECT_TRUE(state.uninstall_command().GetSwitches().empty());
@@ -278,7 +232,7 @@ TEST_F(ProductStateTest, InitializeUninstallCommand) {
{
ProductState state;
ApplyUninstallCommand(L"", L"");
- EXPECT_TRUE(state.Initialize(system_install_, dist_));
+ EXPECT_TRUE(state.Initialize(system_install_));
EXPECT_TRUE(state.GetSetupPath().empty());
EXPECT_TRUE(state.uninstall_command().GetCommandLineString().empty());
EXPECT_TRUE(state.uninstall_command().GetSwitches().empty());
@@ -288,7 +242,7 @@ TEST_F(ProductStateTest, InitializeUninstallCommand) {
{
ProductState state;
ApplyUninstallCommand(NULL, L"--uninstall");
- EXPECT_TRUE(state.Initialize(system_install_, dist_));
+ EXPECT_TRUE(state.Initialize(system_install_));
EXPECT_TRUE(state.GetSetupPath().empty());
EXPECT_EQ(L" --uninstall",
state.uninstall_command().GetCommandLineString());
@@ -299,7 +253,7 @@ TEST_F(ProductStateTest, InitializeUninstallCommand) {
{
ProductState state;
ApplyUninstallCommand(L"setup.exe", NULL);
- EXPECT_TRUE(state.Initialize(system_install_, dist_));
+ EXPECT_TRUE(state.Initialize(system_install_));
EXPECT_EQ(L"setup.exe", state.GetSetupPath().value());
EXPECT_EQ(L"setup.exe", state.uninstall_command().GetCommandLineString());
EXPECT_TRUE(state.uninstall_command().GetSwitches().empty());
@@ -309,7 +263,7 @@ TEST_F(ProductStateTest, InitializeUninstallCommand) {
{
ProductState state;
ApplyUninstallCommand(L"set up.exe", NULL);
- EXPECT_TRUE(state.Initialize(system_install_, dist_));
+ EXPECT_TRUE(state.Initialize(system_install_));
EXPECT_EQ(L"set up.exe", state.GetSetupPath().value());
EXPECT_EQ(L"\"set up.exe\"",
state.uninstall_command().GetCommandLineString());
@@ -320,7 +274,7 @@ TEST_F(ProductStateTest, InitializeUninstallCommand) {
{
ProductState state;
ApplyUninstallCommand(L"setup.exe", L"--uninstall");
- EXPECT_TRUE(state.Initialize(system_install_, dist_));
+ EXPECT_TRUE(state.Initialize(system_install_));
EXPECT_EQ(L"setup.exe", state.GetSetupPath().value());
EXPECT_EQ(L"setup.exe --uninstall",
state.uninstall_command().GetCommandLineString());
@@ -337,7 +291,7 @@ TEST_F(ProductStateTest, InitializeMsi) {
ProductState state;
LONG result = client_state_.DeleteValue(google_update::kRegMSIField);
EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND);
- EXPECT_TRUE(state.Initialize(system_install_, dist_));
+ EXPECT_TRUE(state.Initialize(system_install_));
EXPECT_FALSE(state.is_msi());
}
@@ -347,7 +301,7 @@ TEST_F(ProductStateTest, InitializeMsi) {
EXPECT_EQ(ERROR_SUCCESS,
client_state_.WriteValue(google_update::kRegMSIField,
static_cast<DWORD>(0)));
- EXPECT_TRUE(state.Initialize(system_install_, dist_));
+ EXPECT_TRUE(state.Initialize(system_install_));
EXPECT_FALSE(state.is_msi());
}
@@ -357,7 +311,7 @@ TEST_F(ProductStateTest, InitializeMsi) {
EXPECT_EQ(ERROR_SUCCESS,
client_state_.WriteValue(google_update::kRegMSIField,
static_cast<DWORD>(1)));
- EXPECT_TRUE(state.Initialize(system_install_, dist_));
+ EXPECT_TRUE(state.Initialize(system_install_));
EXPECT_TRUE(state.is_msi());
}
@@ -367,7 +321,7 @@ TEST_F(ProductStateTest, InitializeMsi) {
EXPECT_EQ(ERROR_SUCCESS,
client_state_.WriteValue(google_update::kRegMSIField,
static_cast<DWORD>(47)));
- EXPECT_TRUE(state.Initialize(system_install_, dist_));
+ EXPECT_TRUE(state.Initialize(system_install_));
EXPECT_TRUE(state.is_msi());
}
@@ -377,7 +331,7 @@ TEST_F(ProductStateTest, InitializeMsi) {
EXPECT_EQ(ERROR_SUCCESS,
client_state_.WriteValue(google_update::kRegMSIField,
L"bogus!"));
- EXPECT_TRUE(state.Initialize(system_install_, dist_));
+ EXPECT_TRUE(state.Initialize(system_install_));
EXPECT_FALSE(state.is_msi());
}
}
@@ -390,7 +344,7 @@ TEST_F(ProductStateTest, InitializeMultiInstall) {
{
ProductState state;
ApplyUninstallCommand(NULL, NULL);
- EXPECT_TRUE(state.Initialize(system_install_, dist_));
+ EXPECT_TRUE(state.Initialize(system_install_));
EXPECT_FALSE(state.is_multi_install());
}
@@ -398,7 +352,7 @@ TEST_F(ProductStateTest, InitializeMultiInstall) {
{
ProductState state;
ApplyUninstallCommand(L"setup.exe", L"--uninstall");
- EXPECT_TRUE(state.Initialize(system_install_, dist_));
+ EXPECT_TRUE(state.Initialize(system_install_));
EXPECT_FALSE(state.is_multi_install());
}
@@ -407,7 +361,9 @@ TEST_F(ProductStateTest, InitializeMultiInstall) {
ProductState state;
ApplyUninstallCommand(L"setup.exe",
L"--uninstall --chrome --multi-install");
- EXPECT_TRUE(state.Initialize(system_install_, dist_));
+ EXPECT_TRUE(state.Initialize(system_install_));
EXPECT_TRUE(state.is_multi_install());
}
}
+
+} // namespace installer

Powered by Google App Engine
This is Rietveld 408576698