Chromium Code Reviews| 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 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 446 MAX_PATH); | 446 MAX_PATH); |
| 447 ASSERT_NE(static_cast<DWORD>(0), short_len); | 447 ASSERT_NE(static_cast<DWORD>(0), short_len); |
| 448 ASSERT_GT(static_cast<DWORD>(MAX_PATH), short_len); | 448 ASSERT_GT(static_cast<DWORD>(MAX_PATH), short_len); |
| 449 short_expect.resize(short_len); | 449 short_expect.resize(short_len); |
| 450 ASSERT_FALSE(base::FilePath::CompareEqualIgnoreCase(expect.value(), | 450 ASSERT_FALSE(base::FilePath::CompareEqualIgnoreCase(expect.value(), |
| 451 short_expect)); | 451 short_expect)); |
| 452 EXPECT_TRUE(InstallUtil::ProgramCompare(expect).Evaluate( | 452 EXPECT_TRUE(InstallUtil::ProgramCompare(expect).Evaluate( |
| 453 L"\"" + short_expect + L"\"")); | 453 L"\"" + short_expect + L"\"")); |
| 454 } | 454 } |
| 455 | 455 |
| 456 TEST_F(InstallUtilTest, ProgramCompareWithDirectories) { | |
|
gab
2016/03/21 19:28:13
Should also verify that all other file tests pass
| |
| 457 base::ScopedTempDir test_dir; | |
| 458 ASSERT_TRUE(test_dir.CreateUniqueTempDir()); | |
| 459 const base::FilePath some_long_dir( | |
| 460 test_dir.path().Append(L"Some Long Directory Name")); | |
| 461 const base::FilePath expect(some_long_dir.Append(L"directory")); | |
| 462 const base::FilePath expect_upcase(some_long_dir.Append(L"DIRECTORY")); | |
| 463 const base::FilePath other(some_long_dir.Append(L"other_directory")); | |
| 464 | |
| 465 ASSERT_TRUE(base::CreateDirectory(some_long_dir)); | |
| 466 ASSERT_TRUE(base::CreateDirectory(expect)); | |
| 467 ASSERT_TRUE(base::CreateDirectory(other)); | |
| 468 | |
| 469 InstallUtil::ProgramCompare program_compare( | |
| 470 expect, InstallUtil::ProgramCompare::ComparisonType::FILE_OR_DIRECTORY); | |
| 471 | |
| 472 // Paths match exactly. | |
| 473 EXPECT_TRUE(program_compare.EvaluatePath(expect)); | |
| 474 // Paths differ by case. | |
| 475 EXPECT_TRUE(program_compare.EvaluatePath(expect_upcase)); | |
| 476 // Paths don't match. | |
| 477 EXPECT_FALSE(program_compare.EvaluatePath(other)); | |
| 478 | |
| 479 // Test where strings don't match, but the same directory is indicated. | |
| 480 std::wstring short_expect; | |
|
gab
2016/03/21 19:28:13
base::string16
| |
| 481 DWORD short_len = | |
| 482 GetShortPathName(expect.value().c_str(), | |
| 483 base::WriteInto(&short_expect, MAX_PATH), MAX_PATH); | |
| 484 ASSERT_NE(static_cast<DWORD>(0), short_len); | |
| 485 ASSERT_GT(static_cast<DWORD>(MAX_PATH), short_len); | |
| 486 short_expect.resize(short_len); | |
| 487 ASSERT_FALSE( | |
| 488 base::FilePath::CompareEqualIgnoreCase(expect.value(), short_expect)); | |
| 489 EXPECT_TRUE(program_compare.EvaluatePath(expect)); | |
| 490 EXPECT_TRUE(program_compare.EvaluatePath(expect_upcase)); | |
| 491 EXPECT_FALSE(program_compare.EvaluatePath(other)); | |
| 492 } | |
| 493 | |
| 456 // Win64 Chrome is always installed in the 32-bit Program Files directory. Test | 494 // Win64 Chrome is always installed in the 32-bit Program Files directory. Test |
| 457 // that IsPerUserInstall returns false for an arbitrary path with | 495 // that IsPerUserInstall returns false for an arbitrary path with |
| 458 // DIR_PROGRAM_FILESX86 as a suffix but not DIR_PROGRAM_FILES when the two are | 496 // DIR_PROGRAM_FILESX86 as a suffix but not DIR_PROGRAM_FILES when the two are |
| 459 // unrelated. | 497 // unrelated. |
| 460 TEST_F(InstallUtilTest, IsPerUserInstall) { | 498 TEST_F(InstallUtilTest, IsPerUserInstall) { |
| 461 #if defined(_WIN64) | 499 #if defined(_WIN64) |
| 462 const int kChromeProgramFilesKey = base::DIR_PROGRAM_FILESX86; | 500 const int kChromeProgramFilesKey = base::DIR_PROGRAM_FILESX86; |
| 463 #else | 501 #else |
| 464 const int kChromeProgramFilesKey = base::DIR_PROGRAM_FILES; | 502 const int kChromeProgramFilesKey = base::DIR_PROGRAM_FILES; |
| 465 #endif | 503 #endif |
| 466 base::ScopedPathOverride program_files_override(kChromeProgramFilesKey); | 504 base::ScopedPathOverride program_files_override(kChromeProgramFilesKey); |
| 467 base::FilePath some_exe; | 505 base::FilePath some_exe; |
| 468 ASSERT_TRUE(PathService::Get(kChromeProgramFilesKey, &some_exe)); | 506 ASSERT_TRUE(PathService::Get(kChromeProgramFilesKey, &some_exe)); |
| 469 some_exe = some_exe.AppendASCII("Company") | 507 some_exe = some_exe.AppendASCII("Company") |
| 470 .AppendASCII("Product") | 508 .AppendASCII("Product") |
| 471 .AppendASCII("product.exe"); | 509 .AppendASCII("product.exe"); |
| 472 EXPECT_FALSE(InstallUtil::IsPerUserInstall(some_exe)); | 510 EXPECT_FALSE(InstallUtil::IsPerUserInstall(some_exe)); |
| 473 | 511 |
| 474 #if defined(_WIN64) | 512 #if defined(_WIN64) |
| 475 const int kOtherProgramFilesKey = base::DIR_PROGRAM_FILES; | 513 const int kOtherProgramFilesKey = base::DIR_PROGRAM_FILES; |
| 476 base::ScopedPathOverride other_program_files_override(kOtherProgramFilesKey); | 514 base::ScopedPathOverride other_program_files_override(kOtherProgramFilesKey); |
| 477 ASSERT_TRUE(PathService::Get(kOtherProgramFilesKey, &some_exe)); | 515 ASSERT_TRUE(PathService::Get(kOtherProgramFilesKey, &some_exe)); |
| 478 some_exe = some_exe.AppendASCII("Company") | 516 some_exe = some_exe.AppendASCII("Company") |
| 479 .AppendASCII("Product") | 517 .AppendASCII("Product") |
| 480 .AppendASCII("product.exe"); | 518 .AppendASCII("product.exe"); |
| 481 EXPECT_TRUE(InstallUtil::IsPerUserInstall(some_exe)); | 519 EXPECT_TRUE(InstallUtil::IsPerUserInstall(some_exe)); |
| 482 #endif // defined(_WIN64) | 520 #endif // defined(_WIN64) |
| 483 } | 521 } |
| OLD | NEW |