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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <shellapi.h> | 9 #include <shellapi.h> |
10 #include <shlobj.h> | 10 #include <shlobj.h> |
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
662 FILE_FLAG_BACKUP_SEMANTICS, // Needed to open a directory. | 662 FILE_FLAG_BACKUP_SEMANTICS, // Needed to open a directory. |
663 NULL)); | 663 NULL)); |
664 ASSERT_TRUE(dir.IsValid()); | 664 ASSERT_TRUE(dir.IsValid()); |
665 base::PlatformFileInfo info; | 665 base::PlatformFileInfo info; |
666 EXPECT_TRUE(base::GetPlatformFileInfo(dir.Get(), &info)); | 666 EXPECT_TRUE(base::GetPlatformFileInfo(dir.Get(), &info)); |
667 EXPECT_TRUE(info.is_directory); | 667 EXPECT_TRUE(info.is_directory); |
668 EXPECT_FALSE(info.is_symbolic_link); | 668 EXPECT_FALSE(info.is_symbolic_link); |
669 EXPECT_EQ(0, info.size); | 669 EXPECT_EQ(0, info.size); |
670 } | 670 } |
671 | 671 |
672 // TODO(rogerm): Flesh out the *PreReadImage* tests to validate an observed | |
673 // change in paging behaviour between raw loading and pre-reading. | |
674 | |
675 // TODO(rogerm): Add checks to the *PreReadImage* tests to validate the | |
676 // handling of invalid pe files and paths as input. | |
677 | |
678 TEST_F(FileUtilTest, PreReadImage) { | |
679 using file_util::PreReadImage; | |
680 | |
681 FilePath current_exe; | |
682 ASSERT_TRUE(PathService::Get(base::FILE_EXE, ¤t_exe)); | |
683 | |
684 int64 file_size_64 = 0; | |
685 ASSERT_TRUE(file_util::GetFileSize(current_exe, &file_size_64)); | |
686 ASSERT_TRUE(file_size_64 < std::numeric_limits<std::size_t>::max()); | |
687 size_t file_size = static_cast<size_t>(file_size_64); | |
688 | |
689 // The module_path is valid while current_exe is unchanged and in scope. | |
690 const wchar_t* module_path = current_exe.value().c_str(); | |
691 const size_t kStepSize = 2 * 1024 * 1024; | |
692 | |
693 ASSERT_TRUE(PreReadImage(module_path, 0, kStepSize)); | |
694 ASSERT_TRUE(PreReadImage(module_path, file_size / 4, kStepSize)); | |
695 ASSERT_TRUE(PreReadImage(module_path, file_size / 2, kStepSize)); | |
696 ASSERT_TRUE(PreReadImage(module_path, file_size, kStepSize)); | |
697 ASSERT_TRUE(PreReadImage(module_path, file_size * 2, kStepSize)); | |
698 } | |
699 | |
700 TEST_F(FileUtilTest, PartialPreReadImage) { | |
701 using file_util::PartialPreReadImage; | |
702 | |
703 FilePath current_exe; | |
704 ASSERT_TRUE(PathService::Get(base::FILE_EXE, ¤t_exe)); | |
705 | |
706 // The module_path is valid while current_exe is unchanged and in scope. | |
Evan Martin
2012/01/27 20:13:58
Is this comment just pointing out that the wchar_t
Roger McFarlane (Google)
2012/01/27 21:25:54
Done.
| |
707 const wchar_t* module_path = current_exe.value().c_str(); | |
708 const size_t kStepSize = 2 * 1024 * 1024; | |
709 | |
710 ASSERT_TRUE(PartialPreReadImage(module_path, 0, kStepSize)); | |
711 ASSERT_TRUE(PartialPreReadImage(module_path, 25, kStepSize)); | |
712 ASSERT_TRUE(PartialPreReadImage(module_path, 50, kStepSize)); | |
713 ASSERT_TRUE(PartialPreReadImage(module_path, 100, kStepSize)); | |
714 ASSERT_TRUE(PartialPreReadImage(module_path, 150, kStepSize)); | |
715 } | |
716 | |
717 TEST_F(FileUtilTest, PartialPreReadImageOnDisk) { | |
718 using file_util::internal::PartialPreReadImageOnDisk; | |
719 | |
720 FilePath current_exe; | |
721 ASSERT_TRUE(PathService::Get(base::FILE_EXE, ¤t_exe)); | |
722 | |
723 // The module_path is valid while current_exe is unchanged and in scope. | |
724 const wchar_t* module_path = current_exe.value().c_str(); | |
725 const size_t kChunkSize = 2 * 1024 * 1024; | |
726 | |
727 ASSERT_TRUE(PartialPreReadImageOnDisk(module_path, 0, kChunkSize)); | |
728 ASSERT_TRUE(PartialPreReadImageOnDisk(module_path, 25, kChunkSize)); | |
729 ASSERT_TRUE(PartialPreReadImageOnDisk(module_path, 50, kChunkSize)); | |
730 ASSERT_TRUE(PartialPreReadImageOnDisk(module_path, 100, kChunkSize)); | |
731 ASSERT_TRUE(PartialPreReadImageOnDisk(module_path, 150, kChunkSize)); | |
732 } | |
733 | |
734 TEST_F(FileUtilTest, PartialPreReadImageInMemory) { | |
735 using file_util::internal::PartialPreReadImageInMemory; | |
736 | |
737 // The module_path is valid while current_exe is unchanged and in scope. | |
738 FilePath current_exe; | |
739 ASSERT_TRUE(PathService::Get(base::FILE_EXE, ¤t_exe)); | |
740 const wchar_t* module_path = current_exe.value().c_str(); | |
741 | |
742 ASSERT_TRUE(PartialPreReadImageInMemory(module_path, 0)); | |
743 ASSERT_TRUE(PartialPreReadImageInMemory(module_path, 25)); | |
744 ASSERT_TRUE(PartialPreReadImageInMemory(module_path, 50)); | |
745 ASSERT_TRUE(PartialPreReadImageInMemory(module_path, 100)); | |
746 ASSERT_TRUE(PartialPreReadImageInMemory(module_path, 150)); | |
747 } | |
748 | |
672 #endif // defined(OS_WIN) | 749 #endif // defined(OS_WIN) |
673 | 750 |
674 #if defined(OS_POSIX) | 751 #if defined(OS_POSIX) |
675 | 752 |
676 TEST_F(FileUtilTest, CreateAndReadSymlinks) { | 753 TEST_F(FileUtilTest, CreateAndReadSymlinks) { |
677 FilePath link_from = temp_dir_.path().Append(FPL("from_file")); | 754 FilePath link_from = temp_dir_.path().Append(FPL("from_file")); |
678 FilePath link_to = temp_dir_.path().Append(FPL("to_file")); | 755 FilePath link_to = temp_dir_.path().Append(FPL("to_file")); |
679 CreateTextFile(link_to, bogus_content); | 756 CreateTextFile(link_to, bogus_content); |
680 | 757 |
681 ASSERT_TRUE(file_util::CreateSymbolicLink(link_to, link_from)) | 758 ASSERT_TRUE(file_util::CreateSymbolicLink(link_to, link_from)) |
(...skipping 1604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2286 file_util::VerifyPathControlledByUser( | 2363 file_util::VerifyPathControlledByUser( |
2287 base_dir_, text_file_, uid_, ok_gids_)); | 2364 base_dir_, text_file_, uid_, ok_gids_)); |
2288 EXPECT_TRUE( | 2365 EXPECT_TRUE( |
2289 file_util::VerifyPathControlledByUser( | 2366 file_util::VerifyPathControlledByUser( |
2290 sub_dir_, text_file_, uid_, ok_gids_)); | 2367 sub_dir_, text_file_, uid_, ok_gids_)); |
2291 } | 2368 } |
2292 | 2369 |
2293 #endif // defined(OS_POSIX) | 2370 #endif // defined(OS_POSIX) |
2294 | 2371 |
2295 } // namespace | 2372 } // namespace |
OLD | NEW |