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

Side by Side Diff: sandbox/src/interception_unittest.cc

Issue 10493002: Revert 130716 - Use ScopedProcessInformation and other RAII types in sandbox. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sandbox/src/broker_services.cc ('k') | sandbox/src/job_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 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 // This file contains unit tests for InterceptionManager. 5 // This file contains unit tests for InterceptionManager.
6 // The tests require private information so the whole interception.cc file is 6 // The tests require private information so the whole interception.cc file is
7 // included from this file. 7 // included from this file.
8 8
9 #include <windows.h> 9 #include <windows.h>
10 10
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 (*num_dlls)++; 72 (*num_dlls)++;
73 dll = reinterpret_cast<DllPatchInfo*>(reinterpret_cast<char*>(dll) + 73 dll = reinterpret_cast<DllPatchInfo*>(reinterpret_cast<char*>(dll) +
74 dll->record_bytes); 74 dll->record_bytes);
75 } 75 }
76 } 76 }
77 77
78 TEST(InterceptionManagerTest, BufferLayout1) { 78 TEST(InterceptionManagerTest, BufferLayout1) {
79 wchar_t exe_name[MAX_PATH]; 79 wchar_t exe_name[MAX_PATH];
80 ASSERT_NE(0u, GetModuleFileName(NULL, exe_name, MAX_PATH - 1)); 80 ASSERT_NE(0u, GetModuleFileName(NULL, exe_name, MAX_PATH - 1));
81 81
82 base::win::ScopedHandle current_process; 82 TargetProcess *target = MakeTestTargetProcess(::GetCurrentProcess(),
83 ASSERT_TRUE(
84 ::DuplicateHandle(::GetCurrentProcess(), ::GetCurrentProcess(),
85 ::GetCurrentProcess(), current_process.Receive(),
86 0, FALSE, DUPLICATE_SAME_ACCESS));
87
88 TargetProcess *target = MakeTestTargetProcess(current_process.Take(),
89 ::GetModuleHandle(exe_name)); 83 ::GetModuleHandle(exe_name));
90 84
91 InterceptionManager interceptions(target, true); 85 InterceptionManager interceptions(target, true);
92 86
93 // Any pointer will do for a function pointer. 87 // Any pointer will do for a function pointer.
94 void* function = &interceptions; 88 void* function = &interceptions;
95 89
96 // We don't care about the interceptor id. 90 // We don't care about the interceptor id.
97 interceptions.AddToPatchedFunctions(L"ntdll.dll", "NtCreateFile", 91 interceptions.AddToPatchedFunctions(L"ntdll.dll", "NtCreateFile",
98 INTERCEPTION_SERVICE_CALL, function, 92 INTERCEPTION_SERVICE_CALL, function,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 // interceptor function. 159 // interceptor function.
166 EXPECT_EQ(6, num_dlls); 160 EXPECT_EQ(6, num_dlls);
167 EXPECT_EQ(15, num_functions); 161 EXPECT_EQ(15, num_functions);
168 EXPECT_EQ(4, num_names); 162 EXPECT_EQ(4, num_names);
169 } 163 }
170 164
171 TEST(InterceptionManagerTest, BufferLayout2) { 165 TEST(InterceptionManagerTest, BufferLayout2) {
172 wchar_t exe_name[MAX_PATH]; 166 wchar_t exe_name[MAX_PATH];
173 ASSERT_NE(0u, GetModuleFileName(NULL, exe_name, MAX_PATH - 1)); 167 ASSERT_NE(0u, GetModuleFileName(NULL, exe_name, MAX_PATH - 1));
174 168
175 base::win::ScopedHandle current_process; 169 TargetProcess *target = MakeTestTargetProcess(::GetCurrentProcess(),
176 ASSERT_TRUE(
177 ::DuplicateHandle(::GetCurrentProcess(), ::GetCurrentProcess(),
178 ::GetCurrentProcess(), current_process.Receive(),
179 0, FALSE, DUPLICATE_SAME_ACCESS));
180
181 TargetProcess *target = MakeTestTargetProcess(current_process.Take(),
182 ::GetModuleHandle(exe_name)); 170 ::GetModuleHandle(exe_name));
183 171
184 InterceptionManager interceptions(target, true); 172 InterceptionManager interceptions(target, true);
185 173
186 // Any pointer will do for a function pointer. 174 // Any pointer will do for a function pointer.
187 void* function = &interceptions; 175 void* function = &interceptions;
188 interceptions.AddToUnloadModules(L"some01.dll"); 176 interceptions.AddToUnloadModules(L"some01.dll");
189 // We don't care about the interceptor id. 177 // We don't care about the interceptor id.
190 interceptions.AddToPatchedFunctions(L"ntdll.dll", "NtCreateFile", 178 interceptions.AddToPatchedFunctions(L"ntdll.dll", "NtCreateFile",
191 INTERCEPTION_SERVICE_CALL, function, 179 INTERCEPTION_SERVICE_CALL, function,
(...skipping 23 matching lines...) Expand all
215 int num_dlls, num_functions, num_names; 203 int num_dlls, num_functions, num_names;
216 WalkBuffer(local_buffer.get(), buffer_size, &num_dlls, &num_functions, 204 WalkBuffer(local_buffer.get(), buffer_size, &num_dlls, &num_functions,
217 &num_names); 205 &num_names);
218 206
219 EXPECT_EQ(3, num_dlls); 207 EXPECT_EQ(3, num_dlls);
220 EXPECT_EQ(4, num_functions); 208 EXPECT_EQ(4, num_functions);
221 EXPECT_EQ(0, num_names); 209 EXPECT_EQ(0, num_names);
222 } 210 }
223 211
224 } // namespace sandbox 212 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/src/broker_services.cc ('k') | sandbox/src/job_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698