| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <windows.h> | 5 #include <windows.h> |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "base/test/test_reg_util_win.h" | 8 #include "base/test/test_reg_util_win.h" |
| 9 #include "base/version.h" | 9 #include "base/version.h" |
| 10 #include "base/win/registry.h" | 10 #include "base/win/registry.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 static void SetUpTestCase(); | 24 static void SetUpTestCase(); |
| 25 static void TearDownTestCase(); | 25 static void TearDownTestCase(); |
| 26 | 26 |
| 27 virtual void SetUp(); | 27 virtual void SetUp(); |
| 28 virtual void TearDown(); | 28 virtual void TearDown(); |
| 29 | 29 |
| 30 void ApplyUninstallCommand(const wchar_t* exe_path, const wchar_t* args); | 30 void ApplyUninstallCommand(const wchar_t* exe_path, const wchar_t* args); |
| 31 void MinimallyInstallProduct(const wchar_t* version); | 31 void MinimallyInstallProduct(const wchar_t* version); |
| 32 | 32 |
| 33 static BrowserDistribution* dist_; | 33 static BrowserDistribution* dist_; |
| 34 static std::wstring temp_key_path_; |
| 34 bool system_install_; | 35 bool system_install_; |
| 35 HKEY overridden_; | 36 HKEY overridden_; |
| 36 registry_util::RegistryOverrideManager registry_override_manager_; | |
| 37 RegKey clients_; | 37 RegKey clients_; |
| 38 RegKey client_state_; | 38 RegKey client_state_; |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 BrowserDistribution* ProductStateTest::dist_; | 41 BrowserDistribution* ProductStateTest::dist_; |
| 42 std::wstring ProductStateTest::temp_key_path_; |
| 42 | 43 |
| 43 // static | 44 // static |
| 44 void ProductStateTest::SetUpTestCase() { | 45 void ProductStateTest::SetUpTestCase() { |
| 45 testing::Test::SetUpTestCase(); | 46 testing::Test::SetUpTestCase(); |
| 46 | 47 |
| 47 // We'll use Chrome as our test subject. | 48 // We'll use Chrome as our test subject. |
| 48 dist_ = BrowserDistribution::GetSpecificDistribution( | 49 dist_ = BrowserDistribution::GetSpecificDistribution( |
| 49 BrowserDistribution::CHROME_BROWSER); | 50 BrowserDistribution::CHROME_BROWSER); |
| 51 |
| 52 // And we'll play in HKCU here: |
| 53 temp_key_path_.assign(RegistryOverrideManager::kTempTestKeyPath) |
| 54 .append(1, L'\\') |
| 55 .append(L"ProductStateTest"); |
| 50 } | 56 } |
| 51 | 57 |
| 52 // static | 58 // static |
| 53 void ProductStateTest::TearDownTestCase() { | 59 void ProductStateTest::TearDownTestCase() { |
| 60 temp_key_path_.clear(); |
| 54 dist_ = NULL; | 61 dist_ = NULL; |
| 55 | 62 |
| 56 testing::Test::TearDownTestCase(); | 63 testing::Test::TearDownTestCase(); |
| 57 } | 64 } |
| 58 | 65 |
| 59 void ProductStateTest::SetUp() { | 66 void ProductStateTest::SetUp() { |
| 60 testing::Test::SetUp(); | 67 testing::Test::SetUp(); |
| 61 | 68 |
| 62 // Create/open the keys for the product we'll test. | 69 // Create/open the keys for the product we'll test. |
| 63 system_install_ = true; | 70 system_install_ = true; |
| 64 overridden_ = (system_install_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER); | 71 overridden_ = (system_install_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER); |
| 65 | 72 |
| 66 // Override for test purposes. We don't use ScopedRegistryKeyOverride | 73 // Override for test purposes. We don't use ScopedRegistryKeyOverride |
| 67 // directly because it doesn't suit itself to our use here. | 74 // directly because it doesn't suit itself to our use here. |
| 68 RegKey temp_key; | 75 RegKey temp_key; |
| 69 | 76 EXPECT_EQ(ERROR_SUCCESS, |
| 70 registry_override_manager_.OverrideRegistry(overridden_, L"ProductStateTest"); | 77 temp_key.Create(HKEY_CURRENT_USER, temp_key_path_.c_str(), |
| 78 KEY_ALL_ACCESS)); |
| 79 EXPECT_EQ(ERROR_SUCCESS, |
| 80 ::RegOverridePredefKey(overridden_, temp_key.Handle())); |
| 71 | 81 |
| 72 EXPECT_EQ(ERROR_SUCCESS, | 82 EXPECT_EQ(ERROR_SUCCESS, |
| 73 clients_.Create(overridden_, dist_->GetVersionKey().c_str(), | 83 clients_.Create(overridden_, dist_->GetVersionKey().c_str(), |
| 74 KEY_ALL_ACCESS)); | 84 KEY_ALL_ACCESS)); |
| 75 EXPECT_EQ(ERROR_SUCCESS, | 85 EXPECT_EQ(ERROR_SUCCESS, |
| 76 client_state_.Create(overridden_, dist_->GetStateKey().c_str(), | 86 client_state_.Create(overridden_, dist_->GetStateKey().c_str(), |
| 77 KEY_ALL_ACCESS)); | 87 KEY_ALL_ACCESS)); |
| 78 } | 88 } |
| 79 | 89 |
| 80 void ProductStateTest::TearDown() { | 90 void ProductStateTest::TearDown() { |
| 81 // Done with the keys. | 91 // Done with the keys. |
| 82 client_state_.Close(); | 92 client_state_.Close(); |
| 83 clients_.Close(); | 93 clients_.Close(); |
| 94 EXPECT_EQ(ERROR_SUCCESS, ::RegOverridePredefKey(overridden_, NULL)); |
| 84 overridden_ = NULL; | 95 overridden_ = NULL; |
| 85 system_install_ = false; | 96 system_install_ = false; |
| 86 | 97 |
| 98 // Shotgun approach to clearing out data we may have written. |
| 99 RegistryOverrideManager::DeleteAllTempKeys(); |
| 100 |
| 87 testing::Test::TearDown(); | 101 testing::Test::TearDown(); |
| 88 } | 102 } |
| 89 | 103 |
| 90 void ProductStateTest::MinimallyInstallProduct(const wchar_t* version) { | 104 void ProductStateTest::MinimallyInstallProduct(const wchar_t* version) { |
| 91 EXPECT_EQ(ERROR_SUCCESS, | 105 EXPECT_EQ(ERROR_SUCCESS, |
| 92 clients_.WriteValue(google_update::kRegVersionField, version)); | 106 clients_.WriteValue(google_update::kRegVersionField, version)); |
| 93 } | 107 } |
| 94 | 108 |
| 95 void ProductStateTest::ApplyUninstallCommand(const wchar_t* exe_path, | 109 void ProductStateTest::ApplyUninstallCommand(const wchar_t* exe_path, |
| 96 const wchar_t* args) { | 110 const wchar_t* args) { |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 | 419 |
| 406 // Uninstall command with --multi-install is multi install. | 420 // Uninstall command with --multi-install is multi install. |
| 407 { | 421 { |
| 408 ProductState state; | 422 ProductState state; |
| 409 ApplyUninstallCommand(L"setup.exe", | 423 ApplyUninstallCommand(L"setup.exe", |
| 410 L"--uninstall --chrome --multi-install"); | 424 L"--uninstall --chrome --multi-install"); |
| 411 EXPECT_TRUE(state.Initialize(system_install_, dist_)); | 425 EXPECT_TRUE(state.Initialize(system_install_, dist_)); |
| 412 EXPECT_TRUE(state.is_multi_install()); | 426 EXPECT_TRUE(state.is_multi_install()); |
| 413 } | 427 } |
| 414 } | 428 } |
| OLD | NEW |