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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 } | 95 } |
96 | 96 |
97 } // namespace | 97 } // namespace |
98 | 98 |
99 // Test that we are parsing Chrome version correctly. | 99 // Test that we are parsing Chrome version correctly. |
100 TEST_F(SetupUtilTestWithDir, GetMaxVersionFromArchiveDirTest) { | 100 TEST_F(SetupUtilTestWithDir, GetMaxVersionFromArchiveDirTest) { |
101 // Create a version dir | 101 // Create a version dir |
102 base::FilePath chrome_dir = test_dir_.path().AppendASCII("1.0.0.0"); | 102 base::FilePath chrome_dir = test_dir_.path().AppendASCII("1.0.0.0"); |
103 base::CreateDirectory(chrome_dir); | 103 base::CreateDirectory(chrome_dir); |
104 ASSERT_TRUE(base::PathExists(chrome_dir)); | 104 ASSERT_TRUE(base::PathExists(chrome_dir)); |
105 scoped_ptr<base::Version> version( | 105 scoped_ptr<Version> version( |
106 installer::GetMaxVersionFromArchiveDir(test_dir_.path())); | 106 installer::GetMaxVersionFromArchiveDir(test_dir_.path())); |
107 ASSERT_EQ(version->GetString(), "1.0.0.0"); | 107 ASSERT_EQ(version->GetString(), "1.0.0.0"); |
108 | 108 |
109 base::DeleteFile(chrome_dir, true); | 109 base::DeleteFile(chrome_dir, true); |
110 ASSERT_FALSE(base::PathExists(chrome_dir)); | 110 ASSERT_FALSE(base::PathExists(chrome_dir)); |
111 ASSERT_TRUE(installer::GetMaxVersionFromArchiveDir(test_dir_.path()) == NULL); | 111 ASSERT_TRUE(installer::GetMaxVersionFromArchiveDir(test_dir_.path()) == NULL); |
112 | 112 |
113 chrome_dir = test_dir_.path().AppendASCII("ABC"); | 113 chrome_dir = test_dir_.path().AppendASCII("ABC"); |
114 base::CreateDirectory(chrome_dir); | 114 base::CreateDirectory(chrome_dir); |
115 ASSERT_TRUE(base::PathExists(chrome_dir)); | 115 ASSERT_TRUE(base::PathExists(chrome_dir)); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 protected: | 268 protected: |
269 class FakeInstallationState : public installer::InstallationState { | 269 class FakeInstallationState : public installer::InstallationState { |
270 }; | 270 }; |
271 | 271 |
272 class FakeProductState : public installer::ProductState { | 272 class FakeProductState : public installer::ProductState { |
273 public: | 273 public: |
274 static FakeProductState* FromProductState(const ProductState* product) { | 274 static FakeProductState* FromProductState(const ProductState* product) { |
275 return static_cast<FakeProductState*>(const_cast<ProductState*>(product)); | 275 return static_cast<FakeProductState*>(const_cast<ProductState*>(product)); |
276 } | 276 } |
277 | 277 |
278 void set_version(const base::Version& version) { | 278 void set_version(const Version& version) { |
279 if (version.IsValid()) | 279 if (version.IsValid()) |
280 version_.reset(new base::Version(version)); | 280 version_.reset(new Version(version)); |
281 else | 281 else |
282 version_.reset(); | 282 version_.reset(); |
283 } | 283 } |
284 | 284 |
285 void set_uninstall_command(const CommandLine& uninstall_command) { | 285 void set_uninstall_command(const CommandLine& uninstall_command) { |
286 uninstall_command_ = uninstall_command; | 286 uninstall_command_ = uninstall_command; |
287 } | 287 } |
288 }; | 288 }; |
289 | 289 |
290 virtual void SetUp() OVERRIDE { | 290 virtual void SetUp() OVERRIDE { |
291 SetupUtilTestWithDir::SetUp(); | 291 SetupUtilTestWithDir::SetUp(); |
292 product_version_ = base::Version("30.0.1559.0"); | 292 product_version_ = Version("30.0.1559.0"); |
293 max_version_ = base::Version("47.0.1559.0"); | 293 max_version_ = Version("47.0.1559.0"); |
294 | 294 |
295 // Install the product according to the version. | 295 // Install the product according to the version. |
296 original_state_.reset(new FakeInstallationState()); | 296 original_state_.reset(new FakeInstallationState()); |
297 InstallProduct(); | 297 InstallProduct(); |
298 | 298 |
299 // Prepare to update the product in the temp dir. | 299 // Prepare to update the product in the temp dir. |
300 installer_state_.reset(new installer::InstallerState( | 300 installer_state_.reset(new installer::InstallerState( |
301 kSystemInstall_ ? installer::InstallerState::SYSTEM_LEVEL : | 301 kSystemInstall_ ? installer::InstallerState::SYSTEM_LEVEL : |
302 installer::InstallerState::USER_LEVEL)); | 302 installer::InstallerState::USER_LEVEL)); |
303 installer_state_->AddProductFromState( | 303 installer_state_->AddProductFromState( |
304 kProductType_, | 304 kProductType_, |
305 *original_state_->GetProductState(kSystemInstall_, kProductType_)); | 305 *original_state_->GetProductState(kSystemInstall_, kProductType_)); |
306 | 306 |
307 // Create archives in the two version dirs. | 307 // Create archives in the two version dirs. |
308 ASSERT_TRUE( | 308 ASSERT_TRUE( |
309 base::CreateDirectory(GetProductVersionArchivePath().DirName())); | 309 base::CreateDirectory(GetProductVersionArchivePath().DirName())); |
310 ASSERT_EQ(1, file_util::WriteFile(GetProductVersionArchivePath(), "a", 1)); | 310 ASSERT_EQ(1, file_util::WriteFile(GetProductVersionArchivePath(), "a", 1)); |
311 ASSERT_TRUE( | 311 ASSERT_TRUE( |
312 base::CreateDirectory(GetMaxVersionArchivePath().DirName())); | 312 base::CreateDirectory(GetMaxVersionArchivePath().DirName())); |
313 ASSERT_EQ(1, file_util::WriteFile(GetMaxVersionArchivePath(), "b", 1)); | 313 ASSERT_EQ(1, file_util::WriteFile(GetMaxVersionArchivePath(), "b", 1)); |
314 } | 314 } |
315 | 315 |
316 virtual void TearDown() OVERRIDE { | 316 virtual void TearDown() OVERRIDE { |
317 original_state_.reset(); | 317 original_state_.reset(); |
318 SetupUtilTestWithDir::TearDown(); | 318 SetupUtilTestWithDir::TearDown(); |
319 } | 319 } |
320 | 320 |
321 base::FilePath GetArchivePath(const base::Version& version) const { | 321 base::FilePath GetArchivePath(const Version& version) const { |
322 return test_dir_.path() | 322 return test_dir_.path() |
323 .AppendASCII(version.GetString()) | 323 .AppendASCII(version.GetString()) |
324 .Append(installer::kInstallerDir) | 324 .Append(installer::kInstallerDir) |
325 .Append(installer::kChromeArchive); | 325 .Append(installer::kChromeArchive); |
326 } | 326 } |
327 | 327 |
328 base::FilePath GetMaxVersionArchivePath() const { | 328 base::FilePath GetMaxVersionArchivePath() const { |
329 return GetArchivePath(max_version_); | 329 return GetArchivePath(max_version_); |
330 } | 330 } |
331 | 331 |
(...skipping 12 matching lines...) Expand all Loading... |
344 .Append(installer::kInstallerDir) | 344 .Append(installer::kInstallerDir) |
345 .Append(installer::kSetupExe)); | 345 .Append(installer::kSetupExe)); |
346 uninstall_command.AppendSwitch(installer::switches::kUninstall); | 346 uninstall_command.AppendSwitch(installer::switches::kUninstall); |
347 product->set_uninstall_command(uninstall_command); | 347 product->set_uninstall_command(uninstall_command); |
348 } | 348 } |
349 | 349 |
350 void UninstallProduct() { | 350 void UninstallProduct() { |
351 FakeProductState::FromProductState( | 351 FakeProductState::FromProductState( |
352 original_state_->GetNonVersionedProductState(kSystemInstall_, | 352 original_state_->GetNonVersionedProductState(kSystemInstall_, |
353 kProductType_)) | 353 kProductType_)) |
354 ->set_version(base::Version()); | 354 ->set_version(Version()); |
355 } | 355 } |
356 | 356 |
357 static const bool kSystemInstall_; | 357 static const bool kSystemInstall_; |
358 static const BrowserDistribution::Type kProductType_; | 358 static const BrowserDistribution::Type kProductType_; |
359 base::Version product_version_; | 359 Version product_version_; |
360 base::Version max_version_; | 360 Version max_version_; |
361 scoped_ptr<FakeInstallationState> original_state_; | 361 scoped_ptr<FakeInstallationState> original_state_; |
362 scoped_ptr<installer::InstallerState> installer_state_; | 362 scoped_ptr<installer::InstallerState> installer_state_; |
363 }; | 363 }; |
364 | 364 |
365 const bool FindArchiveToPatchTest::kSystemInstall_ = false; | 365 const bool FindArchiveToPatchTest::kSystemInstall_ = false; |
366 const BrowserDistribution::Type FindArchiveToPatchTest::kProductType_ = | 366 const BrowserDistribution::Type FindArchiveToPatchTest::kProductType_ = |
367 BrowserDistribution::CHROME_BROWSER; | 367 BrowserDistribution::CHROME_BROWSER; |
368 | 368 |
369 } // namespace | 369 } // namespace |
370 | 370 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 } | 487 } |
488 | 488 |
489 TEST(SetupUtilTest, ContainsUnsupportedSwitch) { | 489 TEST(SetupUtilTest, ContainsUnsupportedSwitch) { |
490 EXPECT_FALSE(installer::ContainsUnsupportedSwitch( | 490 EXPECT_FALSE(installer::ContainsUnsupportedSwitch( |
491 CommandLine::FromString(L"foo.exe"))); | 491 CommandLine::FromString(L"foo.exe"))); |
492 EXPECT_FALSE(installer::ContainsUnsupportedSwitch( | 492 EXPECT_FALSE(installer::ContainsUnsupportedSwitch( |
493 CommandLine::FromString(L"foo.exe --multi-install --chrome"))); | 493 CommandLine::FromString(L"foo.exe --multi-install --chrome"))); |
494 EXPECT_TRUE(installer::ContainsUnsupportedSwitch( | 494 EXPECT_TRUE(installer::ContainsUnsupportedSwitch( |
495 CommandLine::FromString(L"foo.exe --chrome-frame"))); | 495 CommandLine::FromString(L"foo.exe --chrome-frame"))); |
496 } | 496 } |
OLD | NEW |