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

Side by Side 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 unified diff | Download patch
OLDNEW
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"
6
5 #include <string> 7 #include <string>
6 #include <utility> 8 #include <utility>
7 9
8 #include "base/base_paths.h" 10 #include "base/base_paths.h"
9 #include "base/command_line.h" 11 #include "base/command_line.h"
10 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/files/scoped_temp_dir.h"
14 #include "base/macros.h"
11 #include "base/path_service.h" 15 #include "base/path_service.h"
12 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
13 #include "base/test/scoped_path_override.h" 17 #include "base/test/scoped_path_override.h"
14 #include "base/test/test_reg_util_win.h" 18 #include "base/test/test_reg_util_win.h"
15 #include "base/win/registry.h" 19 #include "base/win/registry.h"
20 #include "chrome/installer/util/browser_distribution.h"
16 #include "chrome/installer/util/google_update_constants.h" 21 #include "chrome/installer/util/google_update_constants.h"
17 #include "chrome/installer/util/install_util.h" 22 #include "chrome/installer/util/update_active_setup_version_work_item.h"
18 #include "chrome/installer/util/product_unittest.h"
19 #include "chrome/installer/util/work_item.h" 23 #include "chrome/installer/util/work_item.h"
20 #include "testing/gmock/include/gmock/gmock.h" 24 #include "testing/gmock/include/gmock/gmock.h"
25 #include "testing/gtest/include/gtest/gtest.h"
21 26
22 using base::win::RegKey; 27 using base::win::RegKey;
23 using registry_util::RegistryOverrideManager;
24 using ::testing::_; 28 using ::testing::_;
25 using ::testing::Return; 29 using ::testing::Return;
26 using ::testing::StrEq; 30 using ::testing::StrEq;
27 31
28 class MockRegistryValuePredicate : public InstallUtil::RegistryValuePredicate { 32 class MockRegistryValuePredicate : public InstallUtil::RegistryValuePredicate {
29 public: 33 public:
30 MOCK_CONST_METHOD1(Evaluate, bool(const std::wstring&)); 34 MOCK_CONST_METHOD1(Evaluate, bool(const std::wstring&));
31 }; 35 };
32 36
33 class InstallUtilTest : public TestWithTempDirAndDeleteTempOverrideKeys { 37 class InstallUtilTest : public testing::Test {
34 protected: 38 protected:
39 InstallUtilTest() {}
40
41 void SetUp() override {
42 ASSERT_TRUE(test_dir_.CreateUniqueTempDir());
43 ResetRegistryOverrides();
44 }
45
46 void ResetRegistryOverrides() {
47 registry_override_manager_.reset(
48 new registry_util::RegistryOverrideManager);
49 registry_override_manager_->OverrideRegistry(HKEY_CURRENT_USER);
50 registry_override_manager_->OverrideRegistry(HKEY_LOCAL_MACHINE);
51 }
52
53 base::ScopedTempDir test_dir_;
54
55 private:
56 scoped_ptr<registry_util::RegistryOverrideManager> registry_override_manager_;
57
58 DISALLOW_COPY_AND_ASSIGN(InstallUtilTest);
35 }; 59 };
36 60
61 TEST_F(InstallUtilTest, UpdateLastOSUpgradeHandledByActiveSetup) {
62 BrowserDistribution* chrome_dist =
63 BrowserDistribution::GetSpecificDistribution(
64 BrowserDistribution::CHROME_BROWSER);
65 const base::string16 active_setup_path(
66 InstallUtil::GetActiveSetupPath(chrome_dist));
67
68 RegKey test_key;
69 base::string16 unused_tmp;
70
71 EXPECT_EQ(ERROR_FILE_NOT_FOUND,
72 test_key.Open(HKEY_LOCAL_MACHINE, active_setup_path.c_str(),
73 KEY_QUERY_VALUE));
74 // The WorkItem assume the ActiveSetup key itself already exists and only
75 // handles the Version entry, create it now, but don't fill the "Version"
76 // entry just yet.
77 EXPECT_EQ(ERROR_SUCCESS,
78 test_key.Create(HKEY_LOCAL_MACHINE, active_setup_path.c_str(),
79 KEY_QUERY_VALUE));
80 EXPECT_EQ(ERROR_FILE_NOT_FOUND, test_key.ReadValue(L"Version", &unused_tmp));
81
82 // Test returns false when no Active Setup version present (and doesn't alter
83 // that state).
84 EXPECT_FALSE(
85 InstallUtil::UpdateLastOSUpgradeHandledByActiveSetup(chrome_dist));
86 EXPECT_EQ(ERROR_FILE_NOT_FOUND, test_key.ReadValue(L"Version", &unused_tmp));
87
88 {
89 UpdateActiveSetupVersionWorkItem active_setup_work_item(
90 active_setup_path, UpdateActiveSetupVersionWorkItem::UPDATE);
91 active_setup_work_item.Do();
92 EXPECT_EQ(ERROR_SUCCESS, test_key.ReadValue(L"Version", &unused_tmp));
93 }
94
95 // Test returns false with default Active Setup version.
96 EXPECT_FALSE(
97 InstallUtil::UpdateLastOSUpgradeHandledByActiveSetup(chrome_dist));
98 EXPECT_EQ(ERROR_SUCCESS, test_key.ReadValue(L"Version", &unused_tmp));
99
100 // Run through |kIterations| sequences of bumping the OS upgrade version |i|
101 // times and simulating a regular update |kIterations-i| times, confirming
102 // that handling any number of OS upgrades only results in a single hit and
103 // that no amount of regular updates after that result in any hit.
104 const size_t kIterations = 4U;
105 for (size_t i = 0U; i < kIterations; ++i) {
106 SCOPED_TRACE(i);
107 // Bump the OS_UPGRADES component |i| times.
108 for (size_t j = 0; j < i; ++j) {
109 UpdateActiveSetupVersionWorkItem active_setup_work_item(
110 active_setup_path, UpdateActiveSetupVersionWorkItem::
111 UPDATE_AND_BUMP_OS_UPGRADES_COMPONENT);
112 active_setup_work_item.Do();
113 }
114
115 // There should be a single OS upgrade to handle if the OS_UPGRADES
116 // component was bumped at least once.
117 EXPECT_EQ(i > 0, InstallUtil::UpdateLastOSUpgradeHandledByActiveSetup(
118 chrome_dist));
119
120 // We should only be told to handle the latest OS upgrade once above.
121 EXPECT_FALSE(
122 InstallUtil::UpdateLastOSUpgradeHandledByActiveSetup(chrome_dist));
123 EXPECT_FALSE(
124 InstallUtil::UpdateLastOSUpgradeHandledByActiveSetup(chrome_dist));
125
126 // Run |kIterations-i| regular updates.
127 for (size_t j = i; j < kIterations; ++j) {
128 UpdateActiveSetupVersionWorkItem active_setup_work_item(
129 active_setup_path, UpdateActiveSetupVersionWorkItem::UPDATE);
130 active_setup_work_item.Do();
131 }
132
133 // No amount of regular updates should trigger an OS upgrade to be handled.
134 EXPECT_FALSE(
135 InstallUtil::UpdateLastOSUpgradeHandledByActiveSetup(chrome_dist));
136 EXPECT_FALSE(
137 InstallUtil::UpdateLastOSUpgradeHandledByActiveSetup(chrome_dist));
138 }
139 }
140
37 TEST_F(InstallUtilTest, ComposeCommandLine) { 141 TEST_F(InstallUtilTest, ComposeCommandLine) {
38 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); 142 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
39 143
40 std::pair<std::wstring, std::wstring> params[] = { 144 std::pair<std::wstring, std::wstring> params[] = {
41 std::make_pair(std::wstring(L""), std::wstring(L"")), 145 std::make_pair(std::wstring(L""), std::wstring(L"")),
42 std::make_pair(std::wstring(L""), std::wstring(L"--do-something --silly")), 146 std::make_pair(std::wstring(L""), std::wstring(L"--do-something --silly")),
43 std::make_pair(std::wstring(L"spam.exe"), std::wstring(L"")), 147 std::make_pair(std::wstring(L"spam.exe"), std::wstring(L"")),
44 std::make_pair(std::wstring(L"spam.exe"), 148 std::make_pair(std::wstring(L"spam.exe"),
45 std::wstring(L"--do-something --silly")), 149 std::wstring(L"--do-something --silly")),
46 }; 150 };
(...skipping 30 matching lines...) Expand all
77 } 181 }
78 } 182 }
79 183
80 TEST_F(InstallUtilTest, UpdateInstallerStageAP) { 184 TEST_F(InstallUtilTest, UpdateInstallerStageAP) {
81 const bool system_level = false; 185 const bool system_level = false;
82 const HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; 186 const HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
83 std::wstring state_key_path(L"PhonyClientState"); 187 std::wstring state_key_path(L"PhonyClientState");
84 188
85 // Update the stage when there's no "ap" value. 189 // Update the stage when there's no "ap" value.
86 { 190 {
87 RegistryOverrideManager override_manager; 191 ResetRegistryOverrides();
88 override_manager.OverrideRegistry(root);
89 RegKey(root, state_key_path.c_str(), KEY_SET_VALUE); 192 RegKey(root, state_key_path.c_str(), KEY_SET_VALUE);
90 InstallUtil::UpdateInstallerStage(system_level, state_key_path, 193 InstallUtil::UpdateInstallerStage(system_level, state_key_path,
91 installer::BUILDING); 194 installer::BUILDING);
92 std::wstring value; 195 std::wstring value;
93 EXPECT_EQ(ERROR_SUCCESS, 196 EXPECT_EQ(ERROR_SUCCESS,
94 RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE) 197 RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE)
95 .ReadValue(google_update::kRegApField, &value)); 198 .ReadValue(google_update::kRegApField, &value));
96 EXPECT_EQ(L"-stage:building", value); 199 EXPECT_EQ(L"-stage:building", value);
97 } 200 }
98 201
99 // Update the stage when there is an "ap" value. 202 // Update the stage when there is an "ap" value.
100 { 203 {
101 RegistryOverrideManager override_manager; 204 ResetRegistryOverrides();
102 override_manager.OverrideRegistry(root);
103 RegKey(root, state_key_path.c_str(), KEY_SET_VALUE) 205 RegKey(root, state_key_path.c_str(), KEY_SET_VALUE)
104 .WriteValue(google_update::kRegApField, L"2.0-dev"); 206 .WriteValue(google_update::kRegApField, L"2.0-dev");
105 InstallUtil::UpdateInstallerStage(system_level, state_key_path, 207 InstallUtil::UpdateInstallerStage(system_level, state_key_path,
106 installer::BUILDING); 208 installer::BUILDING);
107 std::wstring value; 209 std::wstring value;
108 EXPECT_EQ(ERROR_SUCCESS, 210 EXPECT_EQ(ERROR_SUCCESS,
109 RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE) 211 RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE)
110 .ReadValue(google_update::kRegApField, &value)); 212 .ReadValue(google_update::kRegApField, &value));
111 EXPECT_EQ(L"2.0-dev-stage:building", value); 213 EXPECT_EQ(L"2.0-dev-stage:building", value);
112 } 214 }
113 215
114 // Clear the stage. 216 // Clear the stage.
115 { 217 {
116 RegistryOverrideManager override_manager; 218 ResetRegistryOverrides();
117 override_manager.OverrideRegistry(root);
118 RegKey(root, state_key_path.c_str(), KEY_SET_VALUE) 219 RegKey(root, state_key_path.c_str(), KEY_SET_VALUE)
119 .WriteValue(google_update::kRegApField, L"2.0-dev-stage:building"); 220 .WriteValue(google_update::kRegApField, L"2.0-dev-stage:building");
120 InstallUtil::UpdateInstallerStage(system_level, state_key_path, 221 InstallUtil::UpdateInstallerStage(system_level, state_key_path,
121 installer::NO_STAGE); 222 installer::NO_STAGE);
122 std::wstring value; 223 std::wstring value;
123 EXPECT_EQ(ERROR_SUCCESS, 224 EXPECT_EQ(ERROR_SUCCESS,
124 RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE) 225 RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE)
125 .ReadValue(google_update::kRegApField, &value)); 226 .ReadValue(google_update::kRegApField, &value));
126 EXPECT_EQ(L"2.0-dev", value); 227 EXPECT_EQ(L"2.0-dev", value);
127 } 228 }
128 } 229 }
129 230
130 TEST_F(InstallUtilTest, UpdateInstallerStage) { 231 TEST_F(InstallUtilTest, UpdateInstallerStage) {
131 const bool system_level = false; 232 const bool system_level = false;
132 const HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; 233 const HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
133 std::wstring state_key_path(L"PhonyClientState"); 234 std::wstring state_key_path(L"PhonyClientState");
134 235
135 // Update the stage when there's no "InstallerExtraCode1" value. 236 // Update the stage when there's no "InstallerExtraCode1" value.
136 { 237 {
137 RegistryOverrideManager override_manager; 238 ResetRegistryOverrides();
138 override_manager.OverrideRegistry(root);
139 RegKey(root, state_key_path.c_str(), KEY_SET_VALUE) 239 RegKey(root, state_key_path.c_str(), KEY_SET_VALUE)
140 .DeleteValue(installer::kInstallerExtraCode1); 240 .DeleteValue(installer::kInstallerExtraCode1);
141 InstallUtil::UpdateInstallerStage(system_level, state_key_path, 241 InstallUtil::UpdateInstallerStage(system_level, state_key_path,
142 installer::BUILDING); 242 installer::BUILDING);
143 DWORD value; 243 DWORD value;
144 EXPECT_EQ(ERROR_SUCCESS, 244 EXPECT_EQ(ERROR_SUCCESS,
145 RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE) 245 RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE)
146 .ReadValueDW(installer::kInstallerExtraCode1, &value)); 246 .ReadValueDW(installer::kInstallerExtraCode1, &value));
147 EXPECT_EQ(static_cast<DWORD>(installer::BUILDING), value); 247 EXPECT_EQ(static_cast<DWORD>(installer::BUILDING), value);
148 } 248 }
149 249
150 // Update the stage when there is an "InstallerExtraCode1" value. 250 // Update the stage when there is an "InstallerExtraCode1" value.
151 { 251 {
152 RegistryOverrideManager override_manager; 252 ResetRegistryOverrides();
153 override_manager.OverrideRegistry(root);
154 RegKey(root, state_key_path.c_str(), KEY_SET_VALUE) 253 RegKey(root, state_key_path.c_str(), KEY_SET_VALUE)
155 .WriteValue(installer::kInstallerExtraCode1, 254 .WriteValue(installer::kInstallerExtraCode1,
156 static_cast<DWORD>(installer::UNPACKING)); 255 static_cast<DWORD>(installer::UNPACKING));
157 InstallUtil::UpdateInstallerStage(system_level, state_key_path, 256 InstallUtil::UpdateInstallerStage(system_level, state_key_path,
158 installer::BUILDING); 257 installer::BUILDING);
159 DWORD value; 258 DWORD value;
160 EXPECT_EQ(ERROR_SUCCESS, 259 EXPECT_EQ(ERROR_SUCCESS,
161 RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE) 260 RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE)
162 .ReadValueDW(installer::kInstallerExtraCode1, &value)); 261 .ReadValueDW(installer::kInstallerExtraCode1, &value));
163 EXPECT_EQ(static_cast<DWORD>(installer::BUILDING), value); 262 EXPECT_EQ(static_cast<DWORD>(installer::BUILDING), value);
164 } 263 }
165 264
166 // Clear the stage. 265 // Clear the stage.
167 { 266 {
168 RegistryOverrideManager override_manager; 267 ResetRegistryOverrides();
169 override_manager.OverrideRegistry(root);
170 RegKey(root, state_key_path.c_str(), KEY_SET_VALUE) 268 RegKey(root, state_key_path.c_str(), KEY_SET_VALUE)
171 .WriteValue(installer::kInstallerExtraCode1, static_cast<DWORD>(5)); 269 .WriteValue(installer::kInstallerExtraCode1, static_cast<DWORD>(5));
172 InstallUtil::UpdateInstallerStage(system_level, state_key_path, 270 InstallUtil::UpdateInstallerStage(system_level, state_key_path,
173 installer::NO_STAGE); 271 installer::NO_STAGE);
174 DWORD value; 272 DWORD value;
175 EXPECT_EQ(ERROR_FILE_NOT_FOUND, 273 EXPECT_EQ(ERROR_FILE_NOT_FOUND,
176 RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE) 274 RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE)
177 .ReadValueDW(installer::kInstallerExtraCode1, &value)); 275 .ReadValueDW(installer::kInstallerExtraCode1, &value));
178 } 276 }
179 } 277 }
180 278
181 TEST_F(InstallUtilTest, DeleteRegistryKeyIf) { 279 TEST_F(InstallUtilTest, DeleteRegistryKeyIf) {
182 const HKEY root = HKEY_CURRENT_USER; 280 const HKEY root = HKEY_CURRENT_USER;
183 std::wstring parent_key_path(L"SomeKey\\ToDelete"); 281 std::wstring parent_key_path(L"SomeKey\\ToDelete");
184 std::wstring child_key_path(parent_key_path); 282 std::wstring child_key_path(parent_key_path);
185 child_key_path.append(L"\\ChildKey\\WithAValue"); 283 child_key_path.append(L"\\ChildKey\\WithAValue");
186 const wchar_t value_name[] = L"some_value_name"; 284 const wchar_t value_name[] = L"some_value_name";
187 const wchar_t value[] = L"hi mom"; 285 const wchar_t value[] = L"hi mom";
188 286
287 // Nothing to delete if the keys aren't even there.
189 { 288 {
190 RegistryOverrideManager override_manager; 289 MockRegistryValuePredicate pred;
191 override_manager.OverrideRegistry(root);
192 // Nothing to delete if the keys aren't even there.
193 {
194 MockRegistryValuePredicate pred;
195 290
196 EXPECT_CALL(pred, Evaluate(_)).Times(0); 291 EXPECT_CALL(pred, Evaluate(_)).Times(0);
197 ASSERT_FALSE(RegKey(root, parent_key_path.c_str(), 292 ASSERT_FALSE(
198 KEY_QUERY_VALUE).Valid()); 293 RegKey(root, parent_key_path.c_str(), KEY_QUERY_VALUE).Valid());
199 EXPECT_EQ(InstallUtil::NOT_FOUND, 294 EXPECT_EQ(InstallUtil::NOT_FOUND,
200 InstallUtil::DeleteRegistryKeyIf(root, parent_key_path, 295 InstallUtil::DeleteRegistryKeyIf(
201 child_key_path, 296 root, parent_key_path, child_key_path,
202 WorkItem::kWow64Default, 297 WorkItem::kWow64Default, value_name, pred));
203 value_name, pred)); 298 EXPECT_FALSE(
204 EXPECT_FALSE(RegKey(root, parent_key_path.c_str(), 299 RegKey(root, parent_key_path.c_str(), KEY_QUERY_VALUE).Valid());
205 KEY_QUERY_VALUE).Valid()); 300 }
206 }
207 301
208 // Parent exists, but not child: no delete. 302 // Parent exists, but not child: no delete.
209 { 303 {
210 MockRegistryValuePredicate pred; 304 MockRegistryValuePredicate pred;
211 305
212 EXPECT_CALL(pred, Evaluate(_)).Times(0); 306 EXPECT_CALL(pred, Evaluate(_)).Times(0);
213 ASSERT_TRUE(RegKey(root, parent_key_path.c_str(), KEY_SET_VALUE).Valid()); 307 ASSERT_TRUE(RegKey(root, parent_key_path.c_str(), KEY_SET_VALUE).Valid());
214 EXPECT_EQ(InstallUtil::NOT_FOUND, 308 EXPECT_EQ(InstallUtil::NOT_FOUND,
215 InstallUtil::DeleteRegistryKeyIf(root, parent_key_path, 309 InstallUtil::DeleteRegistryKeyIf(
216 child_key_path, 310 root, parent_key_path, child_key_path,
217 WorkItem::kWow64Default, 311 WorkItem::kWow64Default, value_name, pred));
218 value_name, pred)); 312 EXPECT_TRUE(RegKey(root, parent_key_path.c_str(), KEY_QUERY_VALUE).Valid());
219 EXPECT_TRUE(RegKey(root, parent_key_path.c_str(), 313 }
220 KEY_QUERY_VALUE).Valid());
221 }
222 314
223 // Child exists, but no value: no delete. 315 // Child exists, but no value: no delete.
224 { 316 {
225 MockRegistryValuePredicate pred; 317 MockRegistryValuePredicate pred;
226 318
227 EXPECT_CALL(pred, Evaluate(_)).Times(0); 319 EXPECT_CALL(pred, Evaluate(_)).Times(0);
228 ASSERT_TRUE(RegKey(root, child_key_path.c_str(), KEY_SET_VALUE).Valid()); 320 ASSERT_TRUE(RegKey(root, child_key_path.c_str(), KEY_SET_VALUE).Valid());
229 EXPECT_EQ(InstallUtil::NOT_FOUND, 321 EXPECT_EQ(InstallUtil::NOT_FOUND,
230 InstallUtil::DeleteRegistryKeyIf(root, parent_key_path, 322 InstallUtil::DeleteRegistryKeyIf(
231 child_key_path, 323 root, parent_key_path, child_key_path,
232 WorkItem::kWow64Default, 324 WorkItem::kWow64Default, value_name, pred));
233 value_name, pred)); 325 EXPECT_TRUE(RegKey(root, parent_key_path.c_str(), KEY_QUERY_VALUE).Valid());
234 EXPECT_TRUE(RegKey(root, parent_key_path.c_str(), 326 }
235 KEY_QUERY_VALUE).Valid());
236 }
237 327
238 // Value exists, but doesn't match: no delete. 328 // Value exists, but doesn't match: no delete.
239 { 329 {
240 MockRegistryValuePredicate pred; 330 MockRegistryValuePredicate pred;
241 331
242 EXPECT_CALL(pred, Evaluate(StrEq(L"foosball!"))).WillOnce(Return(false)); 332 EXPECT_CALL(pred, Evaluate(StrEq(L"foosball!"))).WillOnce(Return(false));
243 ASSERT_EQ(ERROR_SUCCESS, 333 ASSERT_EQ(ERROR_SUCCESS, RegKey(root, child_key_path.c_str(), KEY_SET_VALUE)
244 RegKey(root, child_key_path.c_str(), 334 .WriteValue(value_name, L"foosball!"));
245 KEY_SET_VALUE).WriteValue(value_name, L"foosball!")); 335 EXPECT_EQ(InstallUtil::NOT_FOUND,
246 EXPECT_EQ(InstallUtil::NOT_FOUND, 336 InstallUtil::DeleteRegistryKeyIf(
247 InstallUtil::DeleteRegistryKeyIf(root, parent_key_path, 337 root, parent_key_path, child_key_path,
248 child_key_path, 338 WorkItem::kWow64Default, value_name, pred));
249 WorkItem::kWow64Default, 339 EXPECT_TRUE(RegKey(root, parent_key_path.c_str(), KEY_QUERY_VALUE).Valid());
250 value_name, pred)); 340 }
251 EXPECT_TRUE(RegKey(root, parent_key_path.c_str(),
252 KEY_QUERY_VALUE).Valid());
253 }
254 341
255 // Value exists, and matches: delete. 342 // Value exists, and matches: delete.
256 { 343 {
257 MockRegistryValuePredicate pred; 344 MockRegistryValuePredicate pred;
258 345
259 EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true)); 346 EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true));
260 ASSERT_EQ(ERROR_SUCCESS, 347 ASSERT_EQ(ERROR_SUCCESS, RegKey(root, child_key_path.c_str(), KEY_SET_VALUE)
261 RegKey(root, child_key_path.c_str(), 348 .WriteValue(value_name, value));
262 KEY_SET_VALUE).WriteValue(value_name, value)); 349 EXPECT_EQ(InstallUtil::DELETED,
263 EXPECT_EQ(InstallUtil::DELETED, 350 InstallUtil::DeleteRegistryKeyIf(
264 InstallUtil::DeleteRegistryKeyIf(root, parent_key_path, 351 root, parent_key_path, child_key_path,
265 child_key_path, 352 WorkItem::kWow64Default, value_name, pred));
266 WorkItem::kWow64Default, 353 EXPECT_FALSE(
267 value_name, pred)); 354 RegKey(root, parent_key_path.c_str(), KEY_QUERY_VALUE).Valid());
268 EXPECT_FALSE(RegKey(root, parent_key_path.c_str(), 355 }
269 KEY_QUERY_VALUE).Valid());
270 }
271 356
272 // Default value exists and matches: delete. 357 // Default value exists and matches: delete.
273 { 358 {
274 MockRegistryValuePredicate pred; 359 MockRegistryValuePredicate pred;
275 360
276 EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true)); 361 EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true));
277 ASSERT_EQ(ERROR_SUCCESS, 362 ASSERT_EQ(ERROR_SUCCESS, RegKey(root, child_key_path.c_str(), KEY_SET_VALUE)
278 RegKey(root, child_key_path.c_str(), 363 .WriteValue(NULL, value));
279 KEY_SET_VALUE).WriteValue(NULL, value)); 364 EXPECT_EQ(InstallUtil::DELETED, InstallUtil::DeleteRegistryKeyIf(
280 EXPECT_EQ(InstallUtil::DELETED, 365 root, parent_key_path, child_key_path,
281 InstallUtil::DeleteRegistryKeyIf(root, parent_key_path, 366 WorkItem::kWow64Default, NULL, pred));
282 child_key_path, 367 EXPECT_FALSE(
283 WorkItem::kWow64Default, 368 RegKey(root, parent_key_path.c_str(), KEY_QUERY_VALUE).Valid());
284 NULL, pred));
285 EXPECT_FALSE(RegKey(root, parent_key_path.c_str(),
286 KEY_QUERY_VALUE).Valid());
287 }
288 } 369 }
289 } 370 }
290 371
291 TEST_F(InstallUtilTest, DeleteRegistryValueIf) { 372 TEST_F(InstallUtilTest, DeleteRegistryValueIf) {
292 const HKEY root = HKEY_CURRENT_USER; 373 const HKEY root = HKEY_CURRENT_USER;
293 std::wstring key_path(L"SomeKey\\ToDelete"); 374 std::wstring key_path(L"SomeKey\\ToDelete");
294 const wchar_t value_name[] = L"some_value_name"; 375 const wchar_t value_name[] = L"some_value_name";
295 const wchar_t value[] = L"hi mom"; 376 const wchar_t value[] = L"hi mom";
296 377
297 { 378 {
298 RegistryOverrideManager override_manager; 379 ResetRegistryOverrides();
299 override_manager.OverrideRegistry(root);
300 // Nothing to delete if the key isn't even there. 380 // Nothing to delete if the key isn't even there.
301 { 381 {
302 MockRegistryValuePredicate pred; 382 MockRegistryValuePredicate pred;
303 383
304 EXPECT_CALL(pred, Evaluate(_)).Times(0); 384 EXPECT_CALL(pred, Evaluate(_)).Times(0);
305 ASSERT_FALSE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); 385 ASSERT_FALSE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid());
306 EXPECT_EQ(InstallUtil::NOT_FOUND, 386 EXPECT_EQ(InstallUtil::NOT_FOUND,
307 InstallUtil::DeleteRegistryValueIf(root, key_path.c_str(), 387 InstallUtil::DeleteRegistryValueIf(root, key_path.c_str(),
308 WorkItem::kWow64Default, 388 WorkItem::kWow64Default,
309 value_name, pred)); 389 value_name, pred));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 InstallUtil::DeleteRegistryValueIf(root, key_path.c_str(), 432 InstallUtil::DeleteRegistryValueIf(root, key_path.c_str(),
353 WorkItem::kWow64Default, 433 WorkItem::kWow64Default,
354 value_name, pred)); 434 value_name, pred));
355 EXPECT_TRUE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); 435 EXPECT_TRUE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid());
356 EXPECT_FALSE(RegKey(root, key_path.c_str(), 436 EXPECT_FALSE(RegKey(root, key_path.c_str(),
357 KEY_QUERY_VALUE).HasValue(value_name)); 437 KEY_QUERY_VALUE).HasValue(value_name));
358 } 438 }
359 } 439 }
360 440
361 { 441 {
362 RegistryOverrideManager override_manager; 442 ResetRegistryOverrides();
363 override_manager.OverrideRegistry(root);
364 // Default value matches: delete using empty string. 443 // Default value matches: delete using empty string.
365 { 444 {
366 MockRegistryValuePredicate pred; 445 MockRegistryValuePredicate pred;
367 446
368 EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true)); 447 EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true));
369 ASSERT_EQ(ERROR_SUCCESS, 448 ASSERT_EQ(ERROR_SUCCESS,
370 RegKey(root, key_path.c_str(), 449 RegKey(root, key_path.c_str(),
371 KEY_SET_VALUE).WriteValue(L"", value)); 450 KEY_SET_VALUE).WriteValue(L"", value));
372 EXPECT_EQ(InstallUtil::DELETED, 451 EXPECT_EQ(InstallUtil::DELETED,
373 InstallUtil::DeleteRegistryValueIf(root, key_path.c_str(), 452 InstallUtil::DeleteRegistryValueIf(root, key_path.c_str(),
374 WorkItem::kWow64Default, L"", 453 WorkItem::kWow64Default, L"",
375 pred)); 454 pred));
376 EXPECT_TRUE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); 455 EXPECT_TRUE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid());
377 EXPECT_FALSE(RegKey(root, key_path.c_str(), 456 EXPECT_FALSE(RegKey(root, key_path.c_str(),
378 KEY_QUERY_VALUE).HasValue(L"")); 457 KEY_QUERY_VALUE).HasValue(L""));
379 } 458 }
380 } 459 }
381 460
382 { 461 {
383 RegistryOverrideManager override_manager; 462 ResetRegistryOverrides();
384 override_manager.OverrideRegistry(root);
385 // Default value matches: delete using NULL. 463 // Default value matches: delete using NULL.
386 { 464 {
387 MockRegistryValuePredicate pred; 465 MockRegistryValuePredicate pred;
388 466
389 EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true)); 467 EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true));
390 ASSERT_EQ(ERROR_SUCCESS, 468 ASSERT_EQ(ERROR_SUCCESS,
391 RegKey(root, key_path.c_str(), 469 RegKey(root, key_path.c_str(),
392 KEY_SET_VALUE).WriteValue(L"", value)); 470 KEY_SET_VALUE).WriteValue(L"", value));
393 EXPECT_EQ(InstallUtil::DELETED, 471 EXPECT_EQ(InstallUtil::DELETED,
394 InstallUtil::DeleteRegistryValueIf(root, key_path.c_str(), 472 InstallUtil::DeleteRegistryValueIf(root, key_path.c_str(),
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 #if defined(_WIN64) 557 #if defined(_WIN64)
480 const int kOtherProgramFilesKey = base::DIR_PROGRAM_FILES; 558 const int kOtherProgramFilesKey = base::DIR_PROGRAM_FILES;
481 base::ScopedPathOverride other_program_files_override(kOtherProgramFilesKey); 559 base::ScopedPathOverride other_program_files_override(kOtherProgramFilesKey);
482 ASSERT_TRUE(PathService::Get(kOtherProgramFilesKey, &some_exe)); 560 ASSERT_TRUE(PathService::Get(kOtherProgramFilesKey, &some_exe));
483 some_exe = some_exe.AppendASCII("Company") 561 some_exe = some_exe.AppendASCII("Company")
484 .AppendASCII("Product") 562 .AppendASCII("Product")
485 .AppendASCII("product.exe"); 563 .AppendASCII("product.exe");
486 EXPECT_TRUE(InstallUtil::IsPerUserInstall(some_exe)); 564 EXPECT_TRUE(InstallUtil::IsPerUserInstall(some_exe));
487 #endif // defined(_WIN64) 565 #endif // defined(_WIN64)
488 } 566 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698