| 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/util/install_util.h" | 5 #include "chrome/installer/util/install_util.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 MAX_PATH); | 362 MAX_PATH); |
| 363 ASSERT_NE(static_cast<DWORD>(0), short_len); | 363 ASSERT_NE(static_cast<DWORD>(0), short_len); |
| 364 ASSERT_GT(static_cast<DWORD>(MAX_PATH), short_len); | 364 ASSERT_GT(static_cast<DWORD>(MAX_PATH), short_len); |
| 365 short_expect.resize(short_len); | 365 short_expect.resize(short_len); |
| 366 ASSERT_FALSE(base::FilePath::CompareEqualIgnoreCase(expect.value(), | 366 ASSERT_FALSE(base::FilePath::CompareEqualIgnoreCase(expect.value(), |
| 367 short_expect)); | 367 short_expect)); |
| 368 EXPECT_TRUE(InstallUtil::ProgramCompare(expect).Evaluate( | 368 EXPECT_TRUE(InstallUtil::ProgramCompare(expect).Evaluate( |
| 369 L"\"" + short_expect + L"\"")); | 369 L"\"" + short_expect + L"\"")); |
| 370 } | 370 } |
| 371 | 371 |
| 372 TEST_F(InstallUtilTest, ProgramCompareWithDirectories) { | |
| 373 base::ScopedTempDir test_dir; | |
| 374 ASSERT_TRUE(test_dir.CreateUniqueTempDir()); | |
| 375 const base::FilePath some_long_dir( | |
| 376 test_dir.GetPath().Append(L"Some Long Directory Name")); | |
| 377 const base::FilePath expect(some_long_dir.Append(L"directory")); | |
| 378 const base::FilePath expect_upcase(some_long_dir.Append(L"DIRECTORY")); | |
| 379 const base::FilePath other(some_long_dir.Append(L"other_directory")); | |
| 380 | |
| 381 ASSERT_TRUE(base::CreateDirectory(some_long_dir)); | |
| 382 ASSERT_TRUE(base::CreateDirectory(expect)); | |
| 383 ASSERT_TRUE(base::CreateDirectory(other)); | |
| 384 | |
| 385 InstallUtil::ProgramCompare program_compare( | |
| 386 expect, InstallUtil::ProgramCompare::ComparisonType::FILE_OR_DIRECTORY); | |
| 387 | |
| 388 // Paths match exactly. | |
| 389 EXPECT_TRUE(program_compare.EvaluatePath(expect)); | |
| 390 // Paths differ by case. | |
| 391 EXPECT_TRUE(program_compare.EvaluatePath(expect_upcase)); | |
| 392 // Paths don't match. | |
| 393 EXPECT_FALSE(program_compare.EvaluatePath(other)); | |
| 394 | |
| 395 // Test where strings don't match, but the same directory is indicated. | |
| 396 std::wstring short_expect; | |
| 397 DWORD short_len = | |
| 398 GetShortPathName(expect.value().c_str(), | |
| 399 base::WriteInto(&short_expect, MAX_PATH), MAX_PATH); | |
| 400 ASSERT_NE(static_cast<DWORD>(0), short_len); | |
| 401 ASSERT_GT(static_cast<DWORD>(MAX_PATH), short_len); | |
| 402 short_expect.resize(short_len); | |
| 403 ASSERT_FALSE( | |
| 404 base::FilePath::CompareEqualIgnoreCase(expect.value(), short_expect)); | |
| 405 EXPECT_TRUE(program_compare.EvaluatePath(expect)); | |
| 406 EXPECT_TRUE(program_compare.EvaluatePath(expect_upcase)); | |
| 407 EXPECT_FALSE(program_compare.EvaluatePath(other)); | |
| 408 } | |
| 409 | |
| 410 // Win64 Chrome is always installed in the 32-bit Program Files directory. Test | 372 // Win64 Chrome is always installed in the 32-bit Program Files directory. Test |
| 411 // that IsPerUserInstall returns false for an arbitrary path with | 373 // that IsPerUserInstall returns false for an arbitrary path with |
| 412 // DIR_PROGRAM_FILESX86 as a suffix but not DIR_PROGRAM_FILES when the two are | 374 // DIR_PROGRAM_FILESX86 as a suffix but not DIR_PROGRAM_FILES when the two are |
| 413 // unrelated. | 375 // unrelated. |
| 414 TEST_F(InstallUtilTest, IsPerUserInstall) { | 376 TEST_F(InstallUtilTest, IsPerUserInstall) { |
| 415 InstallUtil::ResetIsPerUserInstallForTest(); | 377 InstallUtil::ResetIsPerUserInstallForTest(); |
| 416 | 378 |
| 417 #if defined(_WIN64) | 379 #if defined(_WIN64) |
| 418 const int kChromeProgramFilesKey = base::DIR_PROGRAM_FILESX86; | 380 const int kChromeProgramFilesKey = base::DIR_PROGRAM_FILESX86; |
| 419 #else | 381 #else |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 ASSERT_TRUE(list->Do()); | 497 ASSERT_TRUE(list->Do()); |
| 536 EXPECT_EQ(current_version, | 498 EXPECT_EQ(current_version, |
| 537 InstallUtil::GetDowngradeVersion(system_install, &dist)); | 499 InstallUtil::GetDowngradeVersion(system_install, &dist)); |
| 538 list.reset(WorkItem::CreateWorkItemList()); | 500 list.reset(WorkItem::CreateWorkItemList()); |
| 539 InstallUtil::AddUpdateDowngradeVersionItem( | 501 InstallUtil::AddUpdateDowngradeVersionItem( |
| 540 system_install, nullptr, lower_new_version_1, &dist, list.get()); | 502 system_install, nullptr, lower_new_version_1, &dist, list.get()); |
| 541 ASSERT_TRUE(list->Do()); | 503 ASSERT_TRUE(list->Do()); |
| 542 ASSERT_FALSE( | 504 ASSERT_FALSE( |
| 543 InstallUtil::GetDowngradeVersion(system_install, &dist).IsValid()); | 505 InstallUtil::GetDowngradeVersion(system_install, &dist).IsValid()); |
| 544 } | 506 } |
| OLD | NEW |