Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(508)

Unified Diff: util/win/process_info_test.cc

Issue 1400413002: win: Add Handles() to ProcessInfo (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: . Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..03382fbb97d59fd5b8393f00b569322a45b214ee 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,84 @@ 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);
+ EXPECT_EQ(STANDARD_RIGHTS_READ | STANDARD_RIGHTS_WRITE | SYNCHRONIZE,
+ handle.granted_access & STANDARD_RIGHTS_ALL);
+ EXPECT_EQ(0, handle.attributes);
Mark Mentovai 2015/10/15 05:25:17 Can we reason about pointer_count for any of these
Mark Mentovai 2015/10/15 05:25:17 Not critical, but can we at least conjure up one H
scottmg 2015/10/15 21:38:45 So conjured!
scottmg 2015/10/15 21:38:45 They seem reasonable-ish on XP (1s and 2s), but on
Mark Mentovai 2015/10/16 04:03:04 scottmg wrote:
+ }
+ 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);
+ EXPECT_EQ(STANDARD_RIGHTS_READ,
+ handle.granted_access & STANDARD_RIGHTS_ALL);
+ EXPECT_EQ(0, handle.attributes);
+ }
+ 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_EQ(DELETE | READ_CONTROL | WRITE_DAC | WRITE_OWNER |
+ STANDARD_RIGHTS_READ | STANDARD_RIGHTS_WRITE,
+ handle.granted_access & STANDARD_RIGHTS_ALL);
+ EXPECT_EQ(0, handle.attributes);
+ }
+ }
+ EXPECT_TRUE(found_file_handle);
+ EXPECT_TRUE(found_key_handle);
+ EXPECT_TRUE(found_mapping_handle);
+}
+
} // namespace
} // namespace test
} // namespace crashpad

Powered by Google App Engine
This is Rietveld 408576698