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/setup/setup_util_unittest.h" | 5 #include "chrome/installer/setup/setup_util_unittest.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 } // namespace | 88 } // namespace |
89 | 89 |
90 // Test that we are parsing Chrome version correctly. | 90 // Test that we are parsing Chrome version correctly. |
91 TEST(SetupUtilTest, GetMaxVersionFromArchiveDirTest) { | 91 TEST(SetupUtilTest, GetMaxVersionFromArchiveDirTest) { |
92 // Create a version dir | 92 // Create a version dir |
93 base::ScopedTempDir test_dir; | 93 base::ScopedTempDir test_dir; |
94 ASSERT_TRUE(test_dir.CreateUniqueTempDir()); | 94 ASSERT_TRUE(test_dir.CreateUniqueTempDir()); |
95 base::FilePath chrome_dir = test_dir.path().AppendASCII("1.0.0.0"); | 95 base::FilePath chrome_dir = test_dir.path().AppendASCII("1.0.0.0"); |
96 base::CreateDirectory(chrome_dir); | 96 base::CreateDirectory(chrome_dir); |
97 ASSERT_TRUE(base::PathExists(chrome_dir)); | 97 ASSERT_TRUE(base::PathExists(chrome_dir)); |
98 scoped_ptr<base::Version> version( | 98 scoped_ptr<Version> version( |
99 installer::GetMaxVersionFromArchiveDir(test_dir.path())); | 99 installer::GetMaxVersionFromArchiveDir(test_dir.path())); |
100 ASSERT_EQ(version->GetString(), "1.0.0.0"); | 100 ASSERT_EQ(version->GetString(), "1.0.0.0"); |
101 | 101 |
102 base::DeleteFile(chrome_dir, true); | 102 base::DeleteFile(chrome_dir, true); |
103 ASSERT_FALSE(base::PathExists(chrome_dir)) << chrome_dir.value(); | 103 ASSERT_FALSE(base::PathExists(chrome_dir)) << chrome_dir.value(); |
104 ASSERT_TRUE(installer::GetMaxVersionFromArchiveDir(test_dir.path()) == NULL); | 104 ASSERT_TRUE(installer::GetMaxVersionFromArchiveDir(test_dir.path()) == NULL); |
105 | 105 |
106 chrome_dir = test_dir.path().AppendASCII("ABC"); | 106 chrome_dir = test_dir.path().AppendASCII("ABC"); |
107 base::CreateDirectory(chrome_dir); | 107 base::CreateDirectory(chrome_dir); |
108 ASSERT_TRUE(base::PathExists(chrome_dir)); | 108 ASSERT_TRUE(base::PathExists(chrome_dir)); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 protected: | 262 protected: |
263 class FakeInstallationState : public installer::InstallationState { | 263 class FakeInstallationState : public installer::InstallationState { |
264 }; | 264 }; |
265 | 265 |
266 class FakeProductState : public installer::ProductState { | 266 class FakeProductState : public installer::ProductState { |
267 public: | 267 public: |
268 static FakeProductState* FromProductState(const ProductState* product) { | 268 static FakeProductState* FromProductState(const ProductState* product) { |
269 return static_cast<FakeProductState*>(const_cast<ProductState*>(product)); | 269 return static_cast<FakeProductState*>(const_cast<ProductState*>(product)); |
270 } | 270 } |
271 | 271 |
272 void set_version(const base::Version& version) { | 272 void set_version(const Version& version) { |
273 if (version.IsValid()) | 273 if (version.IsValid()) |
274 version_.reset(new base::Version(version)); | 274 version_.reset(new Version(version)); |
275 else | 275 else |
276 version_.reset(); | 276 version_.reset(); |
277 } | 277 } |
278 | 278 |
279 void set_uninstall_command(const base::CommandLine& uninstall_command) { | 279 void set_uninstall_command(const base::CommandLine& uninstall_command) { |
280 uninstall_command_ = uninstall_command; | 280 uninstall_command_ = uninstall_command; |
281 } | 281 } |
282 }; | 282 }; |
283 | 283 |
284 FindArchiveToPatchTest() {} | 284 FindArchiveToPatchTest() {} |
285 | 285 |
286 void SetUp() override { | 286 void SetUp() override { |
287 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); | 287 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); |
288 registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER); | 288 registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER); |
289 registry_override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE); | 289 registry_override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE); |
290 product_version_ = base::Version("30.0.1559.0"); | 290 product_version_ = Version("30.0.1559.0"); |
291 max_version_ = base::Version("47.0.1559.0"); | 291 max_version_ = Version("47.0.1559.0"); |
292 | 292 |
293 // Install the product according to the version. | 293 // Install the product according to the version. |
294 original_state_.reset(new FakeInstallationState()); | 294 original_state_.reset(new FakeInstallationState()); |
295 InstallProduct(); | 295 InstallProduct(); |
296 | 296 |
297 // Prepare to update the product in the temp dir. | 297 // Prepare to update the product in the temp dir. |
298 installer_state_.reset(new installer::InstallerState( | 298 installer_state_.reset(new installer::InstallerState( |
299 kSystemInstall_ ? installer::InstallerState::SYSTEM_LEVEL : | 299 kSystemInstall_ ? installer::InstallerState::SYSTEM_LEVEL : |
300 installer::InstallerState::USER_LEVEL)); | 300 installer::InstallerState::USER_LEVEL)); |
301 installer_state_->AddProductFromState( | 301 installer_state_->AddProductFromState( |
302 kProductType_, | 302 kProductType_, |
303 *original_state_->GetProductState(kSystemInstall_, kProductType_)); | 303 *original_state_->GetProductState(kSystemInstall_, kProductType_)); |
304 | 304 |
305 // Create archives in the two version dirs. | 305 // Create archives in the two version dirs. |
306 ASSERT_TRUE( | 306 ASSERT_TRUE( |
307 base::CreateDirectory(GetProductVersionArchivePath().DirName())); | 307 base::CreateDirectory(GetProductVersionArchivePath().DirName())); |
308 ASSERT_EQ(1, base::WriteFile(GetProductVersionArchivePath(), "a", 1)); | 308 ASSERT_EQ(1, base::WriteFile(GetProductVersionArchivePath(), "a", 1)); |
309 ASSERT_TRUE( | 309 ASSERT_TRUE( |
310 base::CreateDirectory(GetMaxVersionArchivePath().DirName())); | 310 base::CreateDirectory(GetMaxVersionArchivePath().DirName())); |
311 ASSERT_EQ(1, base::WriteFile(GetMaxVersionArchivePath(), "b", 1)); | 311 ASSERT_EQ(1, base::WriteFile(GetMaxVersionArchivePath(), "b", 1)); |
312 } | 312 } |
313 | 313 |
314 void TearDown() override { | 314 void TearDown() override { |
315 original_state_.reset(); | 315 original_state_.reset(); |
316 } | 316 } |
317 | 317 |
318 base::FilePath GetArchivePath(const base::Version& version) const { | 318 base::FilePath GetArchivePath(const Version& version) const { |
319 return test_dir_.path() | 319 return test_dir_.path() |
320 .AppendASCII(version.GetString()) | 320 .AppendASCII(version.GetString()) |
321 .Append(installer::kInstallerDir) | 321 .Append(installer::kInstallerDir) |
322 .Append(installer::kChromeArchive); | 322 .Append(installer::kChromeArchive); |
323 } | 323 } |
324 | 324 |
325 base::FilePath GetMaxVersionArchivePath() const { | 325 base::FilePath GetMaxVersionArchivePath() const { |
326 return GetArchivePath(max_version_); | 326 return GetArchivePath(max_version_); |
327 } | 327 } |
328 | 328 |
(...skipping 13 matching lines...) Expand all Loading... |
342 .Append(installer::kInstallerDir) | 342 .Append(installer::kInstallerDir) |
343 .Append(installer::kSetupExe)); | 343 .Append(installer::kSetupExe)); |
344 uninstall_command.AppendSwitch(installer::switches::kUninstall); | 344 uninstall_command.AppendSwitch(installer::switches::kUninstall); |
345 product->set_uninstall_command(uninstall_command); | 345 product->set_uninstall_command(uninstall_command); |
346 } | 346 } |
347 | 347 |
348 void UninstallProduct() { | 348 void UninstallProduct() { |
349 FakeProductState::FromProductState( | 349 FakeProductState::FromProductState( |
350 original_state_->GetNonVersionedProductState(kSystemInstall_, | 350 original_state_->GetNonVersionedProductState(kSystemInstall_, |
351 kProductType_)) | 351 kProductType_)) |
352 ->set_version(base::Version()); | 352 ->set_version(Version()); |
353 } | 353 } |
354 | 354 |
355 static const bool kSystemInstall_; | 355 static const bool kSystemInstall_; |
356 static const BrowserDistribution::Type kProductType_; | 356 static const BrowserDistribution::Type kProductType_; |
357 base::ScopedTempDir test_dir_; | 357 base::ScopedTempDir test_dir_; |
358 base::Version product_version_; | 358 Version product_version_; |
359 base::Version max_version_; | 359 Version max_version_; |
360 scoped_ptr<FakeInstallationState> original_state_; | 360 scoped_ptr<FakeInstallationState> original_state_; |
361 scoped_ptr<installer::InstallerState> installer_state_; | 361 scoped_ptr<installer::InstallerState> installer_state_; |
362 | 362 |
363 private: | 363 private: |
364 registry_util::RegistryOverrideManager registry_override_manager_; | 364 registry_util::RegistryOverrideManager registry_override_manager_; |
365 | 365 |
366 DISALLOW_COPY_AND_ASSIGN(FindArchiveToPatchTest); | 366 DISALLOW_COPY_AND_ASSIGN(FindArchiveToPatchTest); |
367 }; | 367 }; |
368 | 368 |
369 const bool FindArchiveToPatchTest::kSystemInstall_ = false; | 369 const bool FindArchiveToPatchTest::kSystemInstall_ = false; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 } | 509 } |
510 | 510 |
511 TEST(SetupUtilTest, GetRegistrationDataCommandKey) { | 511 TEST(SetupUtilTest, GetRegistrationDataCommandKey) { |
512 base::string16 app_guid = L"{AAAAAAAA-BBBB-1111-0123-456789ABCDEF}"; | 512 base::string16 app_guid = L"{AAAAAAAA-BBBB-1111-0123-456789ABCDEF}"; |
513 UpdatingAppRegistrationData reg_data(app_guid); | 513 UpdatingAppRegistrationData reg_data(app_guid); |
514 base::string16 key = | 514 base::string16 key = |
515 installer::GetRegistrationDataCommandKey(reg_data, L"test_name"); | 515 installer::GetRegistrationDataCommandKey(reg_data, L"test_name"); |
516 EXPECT_TRUE(base::EndsWith(key, app_guid + L"\\Commands\\test_name", | 516 EXPECT_TRUE(base::EndsWith(key, app_guid + L"\\Commands\\test_name", |
517 base::CompareCase::SENSITIVE)); | 517 base::CompareCase::SENSITIVE)); |
518 } | 518 } |
OLD | NEW |