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_EQ(sandbox::GetHandleName(file, &handle_name), true); | |
52 | 50 |
53 // Look for the handle in our process | 51 // Look for the handle in our process |
54 bool handle_found = false; | 52 bool handle_found = false; |
55 HandleTable handles; | 53 HandleTable handles; |
56 for (HandleTable::Iterator it = | 54 for (HandleTable::Iterator it = |
57 handles.HandlesForProcess(::GetCurrentProcessId()); | 55 handles.HandlesForProcess(::GetCurrentProcessId()); |
58 it != handles.end(); ++it) { | 56 it != handles.end(); ++it) { |
59 if (it->IsType(HandleTable::kTypeFile) && it->Name() == handle_name) { | 57 if (it->IsType(HandleTable::kTypeFile) && it->Name().compare(my_file)) { |
60 handle_found = true; | 58 handle_found = true; |
61 break; | 59 break; |
62 } | 60 } |
63 } | 61 } |
64 EXPECT_TRUE(handle_found); | 62 EXPECT_TRUE(handle_found); |
65 | 63 |
66 // Clean up the file we made. | 64 // Clean up the file we made. |
67 EXPECT_TRUE(::CloseHandle(file)); | 65 EXPECT_TRUE(::CloseHandle(file)); |
68 } | 66 } |
OLD | NEW |