| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/installer/util/install_util.h" | 5 #include "chrome/installer/util/install_util.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 class TestBrowserDistribution : public BrowserDistribution { | 40 class TestBrowserDistribution : public BrowserDistribution { |
| 41 public: | 41 public: |
| 42 TestBrowserDistribution() | 42 TestBrowserDistribution() |
| 43 : BrowserDistribution(base::MakeUnique<TestAppRegistrationData>()) {} | 43 : BrowserDistribution(base::MakeUnique<TestAppRegistrationData>()) {} |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 class InstallUtilTest : public testing::Test { | 46 class InstallUtilTest : public testing::Test { |
| 47 protected: | 47 protected: |
| 48 InstallUtilTest() {} | 48 InstallUtilTest() {} |
| 49 | 49 |
| 50 void SetUp() override { | 50 void SetUp() override { ASSERT_NO_FATAL_FAILURE(ResetRegistryOverrides()); } |
| 51 ResetRegistryOverrides(); | |
| 52 } | |
| 53 | 51 |
| 54 void ResetRegistryOverrides() { | 52 void ResetRegistryOverrides() { |
| 55 registry_override_manager_.reset( | 53 registry_override_manager_.reset( |
| 56 new registry_util::RegistryOverrideManager); | 54 new registry_util::RegistryOverrideManager); |
| 57 registry_override_manager_->OverrideRegistry(HKEY_CURRENT_USER); | 55 ASSERT_NO_FATAL_FAILURE( |
| 58 registry_override_manager_->OverrideRegistry(HKEY_LOCAL_MACHINE); | 56 registry_override_manager_->OverrideRegistry(HKEY_CURRENT_USER)); |
| 57 ASSERT_NO_FATAL_FAILURE( |
| 58 registry_override_manager_->OverrideRegistry(HKEY_LOCAL_MACHINE)); |
| 59 } | 59 } |
| 60 | 60 |
| 61 private: | 61 private: |
| 62 std::unique_ptr<registry_util::RegistryOverrideManager> | 62 std::unique_ptr<registry_util::RegistryOverrideManager> |
| 63 registry_override_manager_; | 63 registry_override_manager_; |
| 64 | 64 |
| 65 DISALLOW_COPY_AND_ASSIGN(InstallUtilTest); | 65 DISALLOW_COPY_AND_ASSIGN(InstallUtilTest); |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 TEST_F(InstallUtilTest, ComposeCommandLine) { | 68 TEST_F(InstallUtilTest, ComposeCommandLine) { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 } | 200 } |
| 201 } | 201 } |
| 202 | 202 |
| 203 TEST_F(InstallUtilTest, DeleteRegistryValueIf) { | 203 TEST_F(InstallUtilTest, DeleteRegistryValueIf) { |
| 204 const HKEY root = HKEY_CURRENT_USER; | 204 const HKEY root = HKEY_CURRENT_USER; |
| 205 std::wstring key_path(L"SomeKey\\ToDelete"); | 205 std::wstring key_path(L"SomeKey\\ToDelete"); |
| 206 const wchar_t value_name[] = L"some_value_name"; | 206 const wchar_t value_name[] = L"some_value_name"; |
| 207 const wchar_t value[] = L"hi mom"; | 207 const wchar_t value[] = L"hi mom"; |
| 208 | 208 |
| 209 { | 209 { |
| 210 ResetRegistryOverrides(); | 210 ASSERT_NO_FATAL_FAILURE(ResetRegistryOverrides()); |
| 211 // Nothing to delete if the key isn't even there. | 211 // Nothing to delete if the key isn't even there. |
| 212 { | 212 { |
| 213 MockRegistryValuePredicate pred; | 213 MockRegistryValuePredicate pred; |
| 214 | 214 |
| 215 EXPECT_CALL(pred, Evaluate(_)).Times(0); | 215 EXPECT_CALL(pred, Evaluate(_)).Times(0); |
| 216 ASSERT_FALSE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); | 216 ASSERT_FALSE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); |
| 217 EXPECT_EQ(InstallUtil::NOT_FOUND, | 217 EXPECT_EQ(InstallUtil::NOT_FOUND, |
| 218 InstallUtil::DeleteRegistryValueIf(root, key_path.c_str(), | 218 InstallUtil::DeleteRegistryValueIf(root, key_path.c_str(), |
| 219 WorkItem::kWow64Default, | 219 WorkItem::kWow64Default, |
| 220 value_name, pred)); | 220 value_name, pred)); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 InstallUtil::DeleteRegistryValueIf(root, key_path.c_str(), | 263 InstallUtil::DeleteRegistryValueIf(root, key_path.c_str(), |
| 264 WorkItem::kWow64Default, | 264 WorkItem::kWow64Default, |
| 265 value_name, pred)); | 265 value_name, pred)); |
| 266 EXPECT_TRUE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); | 266 EXPECT_TRUE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); |
| 267 EXPECT_FALSE(RegKey(root, key_path.c_str(), | 267 EXPECT_FALSE(RegKey(root, key_path.c_str(), |
| 268 KEY_QUERY_VALUE).HasValue(value_name)); | 268 KEY_QUERY_VALUE).HasValue(value_name)); |
| 269 } | 269 } |
| 270 } | 270 } |
| 271 | 271 |
| 272 { | 272 { |
| 273 ResetRegistryOverrides(); | 273 ASSERT_NO_FATAL_FAILURE(ResetRegistryOverrides()); |
| 274 // Default value matches: delete using empty string. | 274 // Default value matches: delete using empty string. |
| 275 { | 275 { |
| 276 MockRegistryValuePredicate pred; | 276 MockRegistryValuePredicate pred; |
| 277 | 277 |
| 278 EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true)); | 278 EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true)); |
| 279 ASSERT_EQ(ERROR_SUCCESS, | 279 ASSERT_EQ(ERROR_SUCCESS, |
| 280 RegKey(root, key_path.c_str(), | 280 RegKey(root, key_path.c_str(), |
| 281 KEY_SET_VALUE).WriteValue(L"", value)); | 281 KEY_SET_VALUE).WriteValue(L"", value)); |
| 282 EXPECT_EQ(InstallUtil::DELETED, | 282 EXPECT_EQ(InstallUtil::DELETED, |
| 283 InstallUtil::DeleteRegistryValueIf(root, key_path.c_str(), | 283 InstallUtil::DeleteRegistryValueIf(root, key_path.c_str(), |
| 284 WorkItem::kWow64Default, L"", | 284 WorkItem::kWow64Default, L"", |
| 285 pred)); | 285 pred)); |
| 286 EXPECT_TRUE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); | 286 EXPECT_TRUE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); |
| 287 EXPECT_FALSE(RegKey(root, key_path.c_str(), | 287 EXPECT_FALSE(RegKey(root, key_path.c_str(), |
| 288 KEY_QUERY_VALUE).HasValue(L"")); | 288 KEY_QUERY_VALUE).HasValue(L"")); |
| 289 } | 289 } |
| 290 } | 290 } |
| 291 | 291 |
| 292 { | 292 { |
| 293 ResetRegistryOverrides(); | 293 ASSERT_NO_FATAL_FAILURE(ResetRegistryOverrides()); |
| 294 // Default value matches: delete using NULL. | 294 // Default value matches: delete using NULL. |
| 295 { | 295 { |
| 296 MockRegistryValuePredicate pred; | 296 MockRegistryValuePredicate pred; |
| 297 | 297 |
| 298 EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true)); | 298 EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true)); |
| 299 ASSERT_EQ(ERROR_SUCCESS, | 299 ASSERT_EQ(ERROR_SUCCESS, |
| 300 RegKey(root, key_path.c_str(), | 300 RegKey(root, key_path.c_str(), |
| 301 KEY_SET_VALUE).WriteValue(L"", value)); | 301 KEY_SET_VALUE).WriteValue(L"", value)); |
| 302 EXPECT_EQ(InstallUtil::DELETED, | 302 EXPECT_EQ(InstallUtil::DELETED, |
| 303 InstallUtil::DeleteRegistryValueIf(root, key_path.c_str(), | 303 InstallUtil::DeleteRegistryValueIf(root, key_path.c_str(), |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 ASSERT_TRUE(list->Do()); | 497 ASSERT_TRUE(list->Do()); |
| 498 EXPECT_EQ(current_version, | 498 EXPECT_EQ(current_version, |
| 499 InstallUtil::GetDowngradeVersion(system_install, &dist)); | 499 InstallUtil::GetDowngradeVersion(system_install, &dist)); |
| 500 list.reset(WorkItem::CreateWorkItemList()); | 500 list.reset(WorkItem::CreateWorkItemList()); |
| 501 InstallUtil::AddUpdateDowngradeVersionItem( | 501 InstallUtil::AddUpdateDowngradeVersionItem( |
| 502 system_install, nullptr, lower_new_version_1, &dist, list.get()); | 502 system_install, nullptr, lower_new_version_1, &dist, list.get()); |
| 503 ASSERT_TRUE(list->Do()); | 503 ASSERT_TRUE(list->Do()); |
| 504 ASSERT_FALSE( | 504 ASSERT_FALSE( |
| 505 InstallUtil::GetDowngradeVersion(system_install, &dist).IsValid()); | 505 InstallUtil::GetDowngradeVersion(system_install, &dist).IsValid()); |
| 506 } | 506 } |
| OLD | NEW |