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