OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <windows.h> | 5 #include <windows.h> |
6 | 6 |
7 #include "sandbox/src/handle_table.h" | 7 #include "sandbox/src/handle_table.h" |
8 #include "sandbox/tests/common/test_utils.h" | 8 #include "sandbox/tests/common/test_utils.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 29 matching lines...) Expand all Loading... |
40 | 40 |
41 // Create a temp file so we have a handle to find. | 41 // Create a temp file so we have a handle to find. |
42 wchar_t temp_directory[MAX_PATH]; | 42 wchar_t temp_directory[MAX_PATH]; |
43 wchar_t my_file[MAX_PATH]; | 43 wchar_t my_file[MAX_PATH]; |
44 ASSERT_NE(::GetTempPath(MAX_PATH, temp_directory), 0u); | 44 ASSERT_NE(::GetTempPath(MAX_PATH, temp_directory), 0u); |
45 ASSERT_NE(::GetTempFileName(temp_directory, L"test", 0, my_file), 0u); | 45 ASSERT_NE(::GetTempFileName(temp_directory, L"test", 0, my_file), 0u); |
46 HANDLE file = ::CreateFile(my_file, FILE_ALL_ACCESS, | 46 HANDLE file = ::CreateFile(my_file, FILE_ALL_ACCESS, |
47 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, | 47 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, |
48 OPEN_EXISTING, FILE_FLAG_DELETE_ON_CLOSE, NULL); | 48 OPEN_EXISTING, FILE_FLAG_DELETE_ON_CLOSE, NULL); |
49 EXPECT_NE(INVALID_HANDLE_VALUE, file); | 49 EXPECT_NE(INVALID_HANDLE_VALUE, file); |
| 50 string16 handle_name; |
| 51 ASSERT_NE(sandbox::GetHandleName(file, &handle_name), FALSE); |
50 | 52 |
51 // Look for the handle in our process | 53 // Look for the handle in our process |
52 bool handle_found = false; | 54 bool handle_found = false; |
53 HandleTable handles; | 55 HandleTable handles; |
54 for (HandleTable::Iterator it = | 56 for (HandleTable::Iterator it = |
55 handles.HandlesForProcess(::GetCurrentProcessId()); | 57 handles.HandlesForProcess(::GetCurrentProcessId()); |
56 it != handles.end(); ++it) { | 58 it != handles.end(); ++it) { |
57 if (it->IsType(HandleTable::kTypeFile) && it->Name().compare(my_file)) { | 59 if (it->IsType(HandleTable::kTypeFile) && it->Name() == handle_name) { |
58 handle_found = true; | 60 handle_found = true; |
59 break; | 61 break; |
60 } | 62 } |
61 } | 63 } |
62 EXPECT_TRUE(handle_found); | 64 EXPECT_TRUE(handle_found); |
63 | 65 |
64 // Clean up the file we made. | 66 // Clean up the file we made. |
65 EXPECT_TRUE(::CloseHandle(file)); | 67 EXPECT_TRUE(::CloseHandle(file)); |
66 } | 68 } |
OLD | NEW |