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

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

Issue 1231973002: Force restoration of Chrome's shortcuts when Active Setup kicks in in response to a major OS upgrad… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@a4_use_as_workitem
Patch Set: Created 5 years, 5 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/install_util_unittest.cc
diff --git a/chrome/installer/util/install_util_unittest.cc b/chrome/installer/util/install_util_unittest.cc
index a891f8de0c0cc5dfe550e91364f0ee54fb5f59c7..ddc4a70841a3b90c1ea3de8b2dd54017d1bca83c 100644
--- a/chrome/installer/util/install_util_unittest.cc
+++ b/chrome/installer/util/install_util_unittest.cc
@@ -2,25 +2,29 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "chrome/installer/util/install_util.h"
+
#include <string>
#include <utility>
#include "base/base_paths.h"
#include "base/command_line.h"
#include "base/files/file_util.h"
+#include "base/files/scoped_temp_dir.h"
+#include "base/macros.h"
#include "base/path_service.h"
#include "base/strings/string_util.h"
#include "base/test/scoped_path_override.h"
#include "base/test/test_reg_util_win.h"
#include "base/win/registry.h"
+#include "chrome/installer/util/browser_distribution.h"
#include "chrome/installer/util/google_update_constants.h"
-#include "chrome/installer/util/install_util.h"
-#include "chrome/installer/util/product_unittest.h"
+#include "chrome/installer/util/update_active_setup_version_work_item.h"
#include "chrome/installer/util/work_item.h"
#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
using base::win::RegKey;
-using registry_util::RegistryOverrideManager;
using ::testing::_;
using ::testing::Return;
using ::testing::StrEq;
@@ -30,10 +34,110 @@ class MockRegistryValuePredicate : public InstallUtil::RegistryValuePredicate {
MOCK_CONST_METHOD1(Evaluate, bool(const std::wstring&));
};
-class InstallUtilTest : public TestWithTempDirAndDeleteTempOverrideKeys {
+class InstallUtilTest : public testing::Test {
protected:
+ InstallUtilTest() {}
+
+ void SetUp() override {
+ ASSERT_TRUE(test_dir_.CreateUniqueTempDir());
+ ResetRegistryOverrides();
+ }
+
+ void ResetRegistryOverrides() {
+ registry_override_manager_.reset(
+ new registry_util::RegistryOverrideManager);
+ registry_override_manager_->OverrideRegistry(HKEY_CURRENT_USER);
+ registry_override_manager_->OverrideRegistry(HKEY_LOCAL_MACHINE);
+ }
+
+ base::ScopedTempDir test_dir_;
+
+ private:
+ scoped_ptr<registry_util::RegistryOverrideManager> registry_override_manager_;
+
+ DISALLOW_COPY_AND_ASSIGN(InstallUtilTest);
};
+TEST_F(InstallUtilTest, UpdateLastOSUpgradeHandledByActiveSetup) {
+ BrowserDistribution* chrome_dist =
+ BrowserDistribution::GetSpecificDistribution(
+ BrowserDistribution::CHROME_BROWSER);
+ const base::string16 active_setup_path(
+ InstallUtil::GetActiveSetupPath(chrome_dist));
+
+ RegKey test_key;
+ base::string16 unused_tmp;
+
+ EXPECT_EQ(ERROR_FILE_NOT_FOUND,
+ test_key.Open(HKEY_LOCAL_MACHINE, active_setup_path.c_str(),
+ KEY_QUERY_VALUE));
+ // The WorkItem assume the ActiveSetup key itself already exists and only
+ // handles the Version entry, create it now, but don't fill the "Version"
+ // entry just yet.
+ EXPECT_EQ(ERROR_SUCCESS,
+ test_key.Create(HKEY_LOCAL_MACHINE, active_setup_path.c_str(),
+ KEY_QUERY_VALUE));
+ EXPECT_EQ(ERROR_FILE_NOT_FOUND, test_key.ReadValue(L"Version", &unused_tmp));
+
+ // Test returns false when no Active Setup version present (and doesn't alter
+ // that state).
+ EXPECT_FALSE(
+ InstallUtil::UpdateLastOSUpgradeHandledByActiveSetup(chrome_dist));
+ EXPECT_EQ(ERROR_FILE_NOT_FOUND, test_key.ReadValue(L"Version", &unused_tmp));
+
+ {
+ UpdateActiveSetupVersionWorkItem active_setup_work_item(
+ active_setup_path, UpdateActiveSetupVersionWorkItem::UPDATE);
+ active_setup_work_item.Do();
+ EXPECT_EQ(ERROR_SUCCESS, test_key.ReadValue(L"Version", &unused_tmp));
+ }
+
+ // Test returns false with default Active Setup version.
+ EXPECT_FALSE(
+ InstallUtil::UpdateLastOSUpgradeHandledByActiveSetup(chrome_dist));
+ EXPECT_EQ(ERROR_SUCCESS, test_key.ReadValue(L"Version", &unused_tmp));
+
+ // Run through |kIterations| sequences of bumping the OS upgrade version |i|
+ // times and simulating a regular update |kIterations-i| times, confirming
+ // that handling any number of OS upgrades only results in a single hit and
+ // that no amount of regular updates after that result in any hit.
+ const size_t kIterations = 4U;
+ for (size_t i = 0U; i < kIterations; ++i) {
+ SCOPED_TRACE(i);
+ // Bump the OS_UPGRADES component |i| times.
+ for (size_t j = 0; j < i; ++j) {
+ UpdateActiveSetupVersionWorkItem active_setup_work_item(
+ active_setup_path, UpdateActiveSetupVersionWorkItem::
+ UPDATE_AND_BUMP_OS_UPGRADES_COMPONENT);
+ active_setup_work_item.Do();
+ }
+
+ // There should be a single OS upgrade to handle if the OS_UPGRADES
+ // component was bumped at least once.
+ EXPECT_EQ(i > 0, InstallUtil::UpdateLastOSUpgradeHandledByActiveSetup(
+ chrome_dist));
+
+ // We should only be told to handle the latest OS upgrade once above.
+ EXPECT_FALSE(
+ InstallUtil::UpdateLastOSUpgradeHandledByActiveSetup(chrome_dist));
+ EXPECT_FALSE(
+ InstallUtil::UpdateLastOSUpgradeHandledByActiveSetup(chrome_dist));
+
+ // Run |kIterations-i| regular updates.
+ for (size_t j = i; j < kIterations; ++j) {
+ UpdateActiveSetupVersionWorkItem active_setup_work_item(
+ active_setup_path, UpdateActiveSetupVersionWorkItem::UPDATE);
+ active_setup_work_item.Do();
+ }
+
+ // No amount of regular updates should trigger an OS upgrade to be handled.
+ EXPECT_FALSE(
+ InstallUtil::UpdateLastOSUpgradeHandledByActiveSetup(chrome_dist));
+ EXPECT_FALSE(
+ InstallUtil::UpdateLastOSUpgradeHandledByActiveSetup(chrome_dist));
+ }
+}
+
TEST_F(InstallUtilTest, ComposeCommandLine) {
base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
@@ -84,8 +188,7 @@ TEST_F(InstallUtilTest, UpdateInstallerStageAP) {
// Update the stage when there's no "ap" value.
{
- RegistryOverrideManager override_manager;
- override_manager.OverrideRegistry(root);
+ ResetRegistryOverrides();
RegKey(root, state_key_path.c_str(), KEY_SET_VALUE);
InstallUtil::UpdateInstallerStage(system_level, state_key_path,
installer::BUILDING);
@@ -98,8 +201,7 @@ TEST_F(InstallUtilTest, UpdateInstallerStageAP) {
// Update the stage when there is an "ap" value.
{
- RegistryOverrideManager override_manager;
- override_manager.OverrideRegistry(root);
+ ResetRegistryOverrides();
RegKey(root, state_key_path.c_str(), KEY_SET_VALUE)
.WriteValue(google_update::kRegApField, L"2.0-dev");
InstallUtil::UpdateInstallerStage(system_level, state_key_path,
@@ -113,8 +215,7 @@ TEST_F(InstallUtilTest, UpdateInstallerStageAP) {
// Clear the stage.
{
- RegistryOverrideManager override_manager;
- override_manager.OverrideRegistry(root);
+ ResetRegistryOverrides();
RegKey(root, state_key_path.c_str(), KEY_SET_VALUE)
.WriteValue(google_update::kRegApField, L"2.0-dev-stage:building");
InstallUtil::UpdateInstallerStage(system_level, state_key_path,
@@ -134,8 +235,7 @@ TEST_F(InstallUtilTest, UpdateInstallerStage) {
// Update the stage when there's no "InstallerExtraCode1" value.
{
- RegistryOverrideManager override_manager;
- override_manager.OverrideRegistry(root);
+ ResetRegistryOverrides();
RegKey(root, state_key_path.c_str(), KEY_SET_VALUE)
.DeleteValue(installer::kInstallerExtraCode1);
InstallUtil::UpdateInstallerStage(system_level, state_key_path,
@@ -149,8 +249,7 @@ TEST_F(InstallUtilTest, UpdateInstallerStage) {
// Update the stage when there is an "InstallerExtraCode1" value.
{
- RegistryOverrideManager override_manager;
- override_manager.OverrideRegistry(root);
+ ResetRegistryOverrides();
RegKey(root, state_key_path.c_str(), KEY_SET_VALUE)
.WriteValue(installer::kInstallerExtraCode1,
static_cast<DWORD>(installer::UNPACKING));
@@ -165,8 +264,7 @@ TEST_F(InstallUtilTest, UpdateInstallerStage) {
// Clear the stage.
{
- RegistryOverrideManager override_manager;
- override_manager.OverrideRegistry(root);
+ ResetRegistryOverrides();
RegKey(root, state_key_path.c_str(), KEY_SET_VALUE)
.WriteValue(installer::kInstallerExtraCode1, static_cast<DWORD>(5));
InstallUtil::UpdateInstallerStage(system_level, state_key_path,
@@ -186,105 +284,88 @@ TEST_F(InstallUtilTest, DeleteRegistryKeyIf) {
const wchar_t value_name[] = L"some_value_name";
const wchar_t value[] = L"hi mom";
+ // Nothing to delete if the keys aren't even there.
{
- RegistryOverrideManager override_manager;
- override_manager.OverrideRegistry(root);
- // Nothing to delete if the keys aren't even there.
- {
- MockRegistryValuePredicate pred;
-
- EXPECT_CALL(pred, Evaluate(_)).Times(0);
- ASSERT_FALSE(RegKey(root, parent_key_path.c_str(),
- KEY_QUERY_VALUE).Valid());
- EXPECT_EQ(InstallUtil::NOT_FOUND,
- InstallUtil::DeleteRegistryKeyIf(root, parent_key_path,
- child_key_path,
- WorkItem::kWow64Default,
- value_name, pred));
- EXPECT_FALSE(RegKey(root, parent_key_path.c_str(),
- KEY_QUERY_VALUE).Valid());
- }
-
- // Parent exists, but not child: no delete.
- {
- MockRegistryValuePredicate pred;
-
- EXPECT_CALL(pred, Evaluate(_)).Times(0);
- ASSERT_TRUE(RegKey(root, parent_key_path.c_str(), KEY_SET_VALUE).Valid());
- EXPECT_EQ(InstallUtil::NOT_FOUND,
- InstallUtil::DeleteRegistryKeyIf(root, parent_key_path,
- child_key_path,
- WorkItem::kWow64Default,
- value_name, pred));
- EXPECT_TRUE(RegKey(root, parent_key_path.c_str(),
- KEY_QUERY_VALUE).Valid());
- }
-
- // Child exists, but no value: no delete.
- {
- MockRegistryValuePredicate pred;
-
- EXPECT_CALL(pred, Evaluate(_)).Times(0);
- ASSERT_TRUE(RegKey(root, child_key_path.c_str(), KEY_SET_VALUE).Valid());
- EXPECT_EQ(InstallUtil::NOT_FOUND,
- InstallUtil::DeleteRegistryKeyIf(root, parent_key_path,
- child_key_path,
- WorkItem::kWow64Default,
- value_name, pred));
- EXPECT_TRUE(RegKey(root, parent_key_path.c_str(),
- KEY_QUERY_VALUE).Valid());
- }
-
- // Value exists, but doesn't match: no delete.
- {
- MockRegistryValuePredicate pred;
+ MockRegistryValuePredicate pred;
+
+ EXPECT_CALL(pred, Evaluate(_)).Times(0);
+ ASSERT_FALSE(
+ RegKey(root, parent_key_path.c_str(), KEY_QUERY_VALUE).Valid());
+ EXPECT_EQ(InstallUtil::NOT_FOUND,
+ InstallUtil::DeleteRegistryKeyIf(
+ root, parent_key_path, child_key_path,
+ WorkItem::kWow64Default, value_name, pred));
+ EXPECT_FALSE(
+ RegKey(root, parent_key_path.c_str(), KEY_QUERY_VALUE).Valid());
+ }
- EXPECT_CALL(pred, Evaluate(StrEq(L"foosball!"))).WillOnce(Return(false));
- ASSERT_EQ(ERROR_SUCCESS,
- RegKey(root, child_key_path.c_str(),
- KEY_SET_VALUE).WriteValue(value_name, L"foosball!"));
- EXPECT_EQ(InstallUtil::NOT_FOUND,
- InstallUtil::DeleteRegistryKeyIf(root, parent_key_path,
- child_key_path,
- WorkItem::kWow64Default,
- value_name, pred));
- EXPECT_TRUE(RegKey(root, parent_key_path.c_str(),
- KEY_QUERY_VALUE).Valid());
- }
+ // Parent exists, but not child: no delete.
+ {
+ MockRegistryValuePredicate pred;
+
+ EXPECT_CALL(pred, Evaluate(_)).Times(0);
+ ASSERT_TRUE(RegKey(root, parent_key_path.c_str(), KEY_SET_VALUE).Valid());
+ EXPECT_EQ(InstallUtil::NOT_FOUND,
+ InstallUtil::DeleteRegistryKeyIf(
+ root, parent_key_path, child_key_path,
+ WorkItem::kWow64Default, value_name, pred));
+ EXPECT_TRUE(RegKey(root, parent_key_path.c_str(), KEY_QUERY_VALUE).Valid());
+ }
- // Value exists, and matches: delete.
- {
- MockRegistryValuePredicate pred;
+ // Child exists, but no value: no delete.
+ {
+ MockRegistryValuePredicate pred;
+
+ EXPECT_CALL(pred, Evaluate(_)).Times(0);
+ ASSERT_TRUE(RegKey(root, child_key_path.c_str(), KEY_SET_VALUE).Valid());
+ EXPECT_EQ(InstallUtil::NOT_FOUND,
+ InstallUtil::DeleteRegistryKeyIf(
+ root, parent_key_path, child_key_path,
+ WorkItem::kWow64Default, value_name, pred));
+ EXPECT_TRUE(RegKey(root, parent_key_path.c_str(), KEY_QUERY_VALUE).Valid());
+ }
- EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true));
- ASSERT_EQ(ERROR_SUCCESS,
- RegKey(root, child_key_path.c_str(),
- KEY_SET_VALUE).WriteValue(value_name, value));
- EXPECT_EQ(InstallUtil::DELETED,
- InstallUtil::DeleteRegistryKeyIf(root, parent_key_path,
- child_key_path,
- WorkItem::kWow64Default,
- value_name, pred));
- EXPECT_FALSE(RegKey(root, parent_key_path.c_str(),
- KEY_QUERY_VALUE).Valid());
- }
+ // Value exists, but doesn't match: no delete.
+ {
+ MockRegistryValuePredicate pred;
+
+ EXPECT_CALL(pred, Evaluate(StrEq(L"foosball!"))).WillOnce(Return(false));
+ ASSERT_EQ(ERROR_SUCCESS, RegKey(root, child_key_path.c_str(), KEY_SET_VALUE)
+ .WriteValue(value_name, L"foosball!"));
+ EXPECT_EQ(InstallUtil::NOT_FOUND,
+ InstallUtil::DeleteRegistryKeyIf(
+ root, parent_key_path, child_key_path,
+ WorkItem::kWow64Default, value_name, pred));
+ EXPECT_TRUE(RegKey(root, parent_key_path.c_str(), KEY_QUERY_VALUE).Valid());
+ }
- // Default value exists and matches: delete.
- {
- MockRegistryValuePredicate pred;
+ // Value exists, and matches: delete.
+ {
+ MockRegistryValuePredicate pred;
+
+ EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true));
+ ASSERT_EQ(ERROR_SUCCESS, RegKey(root, child_key_path.c_str(), KEY_SET_VALUE)
+ .WriteValue(value_name, value));
+ EXPECT_EQ(InstallUtil::DELETED,
+ InstallUtil::DeleteRegistryKeyIf(
+ root, parent_key_path, child_key_path,
+ WorkItem::kWow64Default, value_name, pred));
+ EXPECT_FALSE(
+ RegKey(root, parent_key_path.c_str(), KEY_QUERY_VALUE).Valid());
+ }
- EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true));
- ASSERT_EQ(ERROR_SUCCESS,
- RegKey(root, child_key_path.c_str(),
- KEY_SET_VALUE).WriteValue(NULL, value));
- EXPECT_EQ(InstallUtil::DELETED,
- InstallUtil::DeleteRegistryKeyIf(root, parent_key_path,
- child_key_path,
- WorkItem::kWow64Default,
- NULL, pred));
- EXPECT_FALSE(RegKey(root, parent_key_path.c_str(),
- KEY_QUERY_VALUE).Valid());
- }
+ // Default value exists and matches: delete.
+ {
+ MockRegistryValuePredicate pred;
+
+ EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true));
+ ASSERT_EQ(ERROR_SUCCESS, RegKey(root, child_key_path.c_str(), KEY_SET_VALUE)
+ .WriteValue(NULL, value));
+ EXPECT_EQ(InstallUtil::DELETED, InstallUtil::DeleteRegistryKeyIf(
+ root, parent_key_path, child_key_path,
+ WorkItem::kWow64Default, NULL, pred));
+ EXPECT_FALSE(
+ RegKey(root, parent_key_path.c_str(), KEY_QUERY_VALUE).Valid());
}
}
@@ -295,8 +376,7 @@ TEST_F(InstallUtilTest, DeleteRegistryValueIf) {
const wchar_t value[] = L"hi mom";
{
- RegistryOverrideManager override_manager;
- override_manager.OverrideRegistry(root);
+ ResetRegistryOverrides();
// Nothing to delete if the key isn't even there.
{
MockRegistryValuePredicate pred;
@@ -359,8 +439,7 @@ TEST_F(InstallUtilTest, DeleteRegistryValueIf) {
}
{
- RegistryOverrideManager override_manager;
- override_manager.OverrideRegistry(root);
+ ResetRegistryOverrides();
// Default value matches: delete using empty string.
{
MockRegistryValuePredicate pred;
@@ -380,8 +459,7 @@ TEST_F(InstallUtilTest, DeleteRegistryValueIf) {
}
{
- RegistryOverrideManager override_manager;
- override_manager.OverrideRegistry(root);
+ ResetRegistryOverrides();
// Default value matches: delete using NULL.
{
MockRegistryValuePredicate pred;

Powered by Google App Engine
This is Rietveld 408576698