Chromium Code Reviews| Index: util/win/process_info_test.cc |
| diff --git a/util/win/process_info_test.cc b/util/win/process_info_test.cc |
| index ce9e8ac7a53a5b248427b770060f750d2f86431c..34f473729127d432375ebf7a37161c39862f8868 100644 |
| --- a/util/win/process_info_test.cc |
| +++ b/util/win/process_info_test.cc |
| @@ -20,8 +20,12 @@ |
| #include "base/files/file_path.h" |
| #include "base/memory/scoped_ptr.h" |
| +#include "base/rand_util.h" |
| +#include "base/strings/stringprintf.h" |
| +#include "base/strings/utf_string_conversions.h" |
| #include "build/build_config.h" |
| #include "gtest/gtest.h" |
| +#include "test/scoped_temp_dir.h" |
| #include "test/paths.h" |
| #include "test/win/child_launcher.h" |
| #include "util/file/file_io.h" |
| @@ -510,6 +514,74 @@ TEST(ProcessInfo, ReadableRanges) { |
| &bytes_read)); |
| } |
| +struct ScopedRegistryKeyCloseTraits { |
| + static HKEY InvalidValue() { |
| + return nullptr; |
| + } |
| + static void Free(HKEY key) { |
| + RegCloseKey(key); |
| + } |
| +}; |
| +using ScopedRegistryKey = |
| + base::ScopedGeneric<HKEY, ScopedRegistryKeyCloseTraits>; |
| + |
| +TEST(ProcessInfo, Handles) { |
| + ScopedTempDir temp_dir; |
| + ScopedFileHandle file(LoggingOpenFileForWrite( |
| + temp_dir.path().Append(FILE_PATH_LITERAL("test_file")), |
| + FileWriteMode::kTruncateOrCreate, |
| + FilePermissions::kWorldReadable)); |
| + ASSERT_TRUE(file.is_valid()); |
| + |
| + HKEY key; |
| + ASSERT_EQ(ERROR_SUCCESS, |
| + RegOpenKeyEx( |
| + HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft", 0, KEY_READ, &key)); |
| + ScopedRegistryKey scoped_key(key); |
| + ASSERT_TRUE(scoped_key.is_valid()); |
| + |
| + std::wstring mapping_name = |
| + base::UTF8ToUTF16(base::StringPrintf("Global\\test_mapping_%d_%I64x", |
| + GetCurrentProcessId(), |
| + base::RandUint64())); |
| + ScopedKernelHANDLE mapping(CreateFileMapping(INVALID_HANDLE_VALUE, |
| + nullptr, |
| + PAGE_READWRITE, |
| + 0, |
| + 1024, |
| + mapping_name.c_str())); |
| + ASSERT_TRUE(mapping.is_valid()); |
| + |
| + ProcessInfo info; |
| + info.Initialize(GetCurrentProcess()); |
| + bool found_file_handle = false; |
| + bool found_key_handle = false; |
| + bool found_mapping_handle = false; |
| + for (auto handle : info.Handles()) { |
| + if (reinterpret_cast<uint32_t>(file.get()) == handle.handle) { |
| + EXPECT_FALSE(found_file_handle); |
| + found_file_handle = true; |
| + EXPECT_EQ(L"File", handle.type_name); |
| + EXPECT_EQ(1, handle.handle_count); |
|
Mark Mentovai
2015/10/14 22:49:55
Any way to reason about attributes and access here
scottmg
2015/10/15 00:17:42
attributes is almost always 0, but added some chec
|
| + } |
| + if (reinterpret_cast<uint32_t>(scoped_key.get()) == handle.handle) { |
| + EXPECT_FALSE(found_key_handle); |
| + found_key_handle = true; |
| + EXPECT_EQ(L"Key", handle.type_name); |
| + EXPECT_EQ(1, handle.handle_count); |
| + } |
| + if (reinterpret_cast<uint32_t>(mapping.get()) == handle.handle) { |
| + EXPECT_FALSE(found_mapping_handle); |
| + found_mapping_handle = true; |
| + EXPECT_EQ(L"Section", handle.type_name); |
| + EXPECT_EQ(1, handle.handle_count); |
| + } |
| + } |
| + EXPECT_TRUE(found_file_handle); |
| + EXPECT_TRUE(found_key_handle); |
| + EXPECT_TRUE(found_mapping_handle); |
| +} |
| + |
| } // namespace |
| } // namespace test |
| } // namespace crashpad |