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) { | |
| 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 static const char data[] = "data"; | |
|
Nico
2016/03/21 16:22:22
../../chrome/installer/util/install_util_unittest.
fdoray
2016/03/21 16:39:02
Done.
| |
| 466 ASSERT_TRUE(base::CreateDirectory(some_long_dir)); | |
| 467 ASSERT_TRUE(base::CreateDirectory(expect)); | |
| 468 ASSERT_TRUE(base::CreateDirectory(other)); | |
| 469 | |
| 470 InstallUtil::ProgramCompare program_compare( | |
| 471 expect, InstallUtil::ProgramCompare::ComparisonType::FILE_OR_DIRECTORY); | |
| 472 | |
| 473 // Paths match exactly. | |
| 474 EXPECT_TRUE(program_compare.EvaluatePath(expect)); | |
| 475 // Paths differ by case. | |
| 476 EXPECT_TRUE(program_compare.EvaluatePath(expect_upcase)); | |
| 477 // Paths don't match. | |
| 478 EXPECT_FALSE(program_compare.EvaluatePath(other)); | |
| 479 | |
| 480 // Test where strings don't match, but the same directory is indicated. | |
| 481 std::wstring short_expect; | |
| 482 DWORD short_len = | |
| 483 GetShortPathName(expect.value().c_str(), | |
| 484 base::WriteInto(&short_expect, MAX_PATH), MAX_PATH); | |
| 485 ASSERT_NE(static_cast<DWORD>(0), short_len); | |
| 486 ASSERT_GT(static_cast<DWORD>(MAX_PATH), short_len); | |
| 487 short_expect.resize(short_len); | |
| 488 ASSERT_FALSE( | |
| 489 base::FilePath::CompareEqualIgnoreCase(expect.value(), short_expect)); | |
| 490 EXPECT_TRUE(program_compare.EvaluatePath(expect)); | |
| 491 EXPECT_TRUE(program_compare.EvaluatePath(expect_upcase)); | |
| 492 EXPECT_FALSE(program_compare.EvaluatePath(other)); | |
| 493 } | |
| 494 | |
| 456 // Win64 Chrome is always installed in the 32-bit Program Files directory. Test | 495 // Win64 Chrome is always installed in the 32-bit Program Files directory. Test |
| 457 // that IsPerUserInstall returns false for an arbitrary path with | 496 // 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 | 497 // DIR_PROGRAM_FILESX86 as a suffix but not DIR_PROGRAM_FILES when the two are |
| 459 // unrelated. | 498 // unrelated. |
| 460 TEST_F(InstallUtilTest, IsPerUserInstall) { | 499 TEST_F(InstallUtilTest, IsPerUserInstall) { |
| 461 #if defined(_WIN64) | 500 #if defined(_WIN64) |
| 462 const int kChromeProgramFilesKey = base::DIR_PROGRAM_FILESX86; | 501 const int kChromeProgramFilesKey = base::DIR_PROGRAM_FILESX86; |
| 463 #else | 502 #else |
| 464 const int kChromeProgramFilesKey = base::DIR_PROGRAM_FILES; | 503 const int kChromeProgramFilesKey = base::DIR_PROGRAM_FILES; |
| 465 #endif | 504 #endif |
| 466 base::ScopedPathOverride program_files_override(kChromeProgramFilesKey); | 505 base::ScopedPathOverride program_files_override(kChromeProgramFilesKey); |
| 467 base::FilePath some_exe; | 506 base::FilePath some_exe; |
| 468 ASSERT_TRUE(PathService::Get(kChromeProgramFilesKey, &some_exe)); | 507 ASSERT_TRUE(PathService::Get(kChromeProgramFilesKey, &some_exe)); |
| 469 some_exe = some_exe.AppendASCII("Company") | 508 some_exe = some_exe.AppendASCII("Company") |
| 470 .AppendASCII("Product") | 509 .AppendASCII("Product") |
| 471 .AppendASCII("product.exe"); | 510 .AppendASCII("product.exe"); |
| 472 EXPECT_FALSE(InstallUtil::IsPerUserInstall(some_exe)); | 511 EXPECT_FALSE(InstallUtil::IsPerUserInstall(some_exe)); |
| 473 | 512 |
| 474 #if defined(_WIN64) | 513 #if defined(_WIN64) |
| 475 const int kOtherProgramFilesKey = base::DIR_PROGRAM_FILES; | 514 const int kOtherProgramFilesKey = base::DIR_PROGRAM_FILES; |
| 476 base::ScopedPathOverride other_program_files_override(kOtherProgramFilesKey); | 515 base::ScopedPathOverride other_program_files_override(kOtherProgramFilesKey); |
| 477 ASSERT_TRUE(PathService::Get(kOtherProgramFilesKey, &some_exe)); | 516 ASSERT_TRUE(PathService::Get(kOtherProgramFilesKey, &some_exe)); |
| 478 some_exe = some_exe.AppendASCII("Company") | 517 some_exe = some_exe.AppendASCII("Company") |
| 479 .AppendASCII("Product") | 518 .AppendASCII("Product") |
| 480 .AppendASCII("product.exe"); | 519 .AppendASCII("product.exe"); |
| 481 EXPECT_TRUE(InstallUtil::IsPerUserInstall(some_exe)); | 520 EXPECT_TRUE(InstallUtil::IsPerUserInstall(some_exe)); |
| 482 #endif // defined(_WIN64) | 521 #endif // defined(_WIN64) |
| 483 } | 522 } |
| OLD | NEW |