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 "chrome_frame/vtable_patch_manager.h" | 5 #include "chrome_frame/vtable_patch_manager.h" |
6 | 6 |
7 #include <unknwn.h> | 7 #include <unknwn.h> |
8 | 8 |
| 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" |
9 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
10 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
11 #include "base/win/scoped_handle.h" | 13 #include "base/win/scoped_handle.h" |
12 #include "gtest/gtest.h" | 14 #include "gtest/gtest.h" |
13 #include "gmock/gmock.h" | 15 #include "gmock/gmock.h" |
14 | 16 |
15 namespace { | 17 namespace { |
16 // GMock names we use. | 18 // GMock names we use. |
17 using testing::_; | 19 using testing::_; |
18 using testing::Return; | 20 using testing::Return; |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 // lock is held. | 212 // lock is held. |
211 base::Thread background("Background Test Thread"); | 213 base::Thread background("Background Test Thread"); |
212 | 214 |
213 EXPECT_TRUE(background.Start()); | 215 EXPECT_TRUE(background.Start()); |
214 base::win::ScopedHandle event(::CreateEvent(NULL, TRUE, FALSE, NULL)); | 216 base::win::ScopedHandle event(::CreateEvent(NULL, TRUE, FALSE, NULL)); |
215 | 217 |
216 // Grab the patch lock. | 218 // Grab the patch lock. |
217 vtable_patch::patch_lock_.Acquire(); | 219 vtable_patch::patch_lock_.Acquire(); |
218 | 220 |
219 // Instruct the background thread to patch factory_. | 221 // Instruct the background thread to patch factory_. |
220 background.message_loop()->PostTask(FROM_HERE, | 222 background.message_loop()->PostTask( |
221 NewRunnableFunction(&vtable_patch::PatchInterfaceMethods, | 223 FROM_HERE, |
222 &factory_, | 224 base::IgnoreReturn<HRESULT>( |
223 &IClassFactory_PatchInfo[0])); | 225 base::Bind(&vtable_patch::PatchInterfaceMethods, &factory_, |
| 226 &IClassFactory_PatchInfo[0]))); |
224 | 227 |
225 // And subsequently to signal the event. Neither of these actions should | 228 // And subsequently to signal the event. Neither of these actions should |
226 // occur until we've released the patch lock. | 229 // occur until we've released the patch lock. |
227 background.message_loop()->PostTask(FROM_HERE, | 230 background.message_loop()->PostTask( |
228 NewRunnableFunction(::SetEvent, event.Get())); | 231 FROM_HERE, base::IgnoreReturn<BOOL>(base::Bind(::SetEvent, event.Get()))); |
229 | 232 |
230 // Wait for a little while, to give the background thread time to process. | 233 // Wait for a little while, to give the background thread time to process. |
231 // We expect this wait to time out, as the background thread should end up | 234 // We expect this wait to time out, as the background thread should end up |
232 // blocking on the patch lock. | 235 // blocking on the patch lock. |
233 EXPECT_EQ(WAIT_TIMEOUT, ::WaitForSingleObject(event.Get(), 50)); | 236 EXPECT_EQ(WAIT_TIMEOUT, ::WaitForSingleObject(event.Get(), 50)); |
234 | 237 |
235 // Verify that patching did not take place yet. | 238 // Verify that patching did not take place yet. |
236 EXPECT_CALL(factory_, LockServer(TRUE)) | 239 EXPECT_CALL(factory_, LockServer(TRUE)) |
237 .WillOnce(Return(S_FALSE)); | 240 .WillOnce(Return(S_FALSE)); |
238 EXPECT_EQ(S_FALSE, factory_.LockServer(TRUE)); | 241 EXPECT_EQ(S_FALSE, factory_.LockServer(TRUE)); |
(...skipping 12 matching lines...) Expand all Loading... |
251 .WillOnce(Return(S_FALSE)); | 254 .WillOnce(Return(S_FALSE)); |
252 EXPECT_EQ(S_FALSE, factory_.LockServer(TRUE)); | 255 EXPECT_EQ(S_FALSE, factory_.LockServer(TRUE)); |
253 | 256 |
254 // Same deal for unpatching. | 257 // Same deal for unpatching. |
255 ::ResetEvent(event.Get()); | 258 ::ResetEvent(event.Get()); |
256 | 259 |
257 // Grab the patch lock. | 260 // Grab the patch lock. |
258 vtable_patch::patch_lock_.Acquire(); | 261 vtable_patch::patch_lock_.Acquire(); |
259 | 262 |
260 // Instruct the background thread to unpatch. | 263 // Instruct the background thread to unpatch. |
261 background.message_loop()->PostTask(FROM_HERE, | 264 background.message_loop()->PostTask( |
262 NewRunnableFunction(&vtable_patch::UnpatchInterfaceMethods, | 265 FROM_HERE, |
263 &IClassFactory_PatchInfo[0])); | 266 base::IgnoreReturn<HRESULT>( |
| 267 base::Bind(&vtable_patch::UnpatchInterfaceMethods, |
| 268 &IClassFactory_PatchInfo[0]))); |
264 | 269 |
265 // And subsequently to signal the event. Neither of these actions should | 270 // And subsequently to signal the event. Neither of these actions should |
266 // occur until we've released the patch lock. | 271 // occur until we've released the patch lock. |
267 background.message_loop()->PostTask(FROM_HERE, | 272 background.message_loop()->PostTask( |
268 NewRunnableFunction(::SetEvent, event.Get())); | 273 FROM_HERE, base::IgnoreReturn<BOOL>(base::Bind(::SetEvent, event.Get()))); |
269 | 274 |
270 // Wait for a little while, to give the background thread time to process. | 275 // Wait for a little while, to give the background thread time to process. |
271 // We expect this wait to time out, as the background thread should end up | 276 // We expect this wait to time out, as the background thread should end up |
272 // blocking on the patch lock. | 277 // blocking on the patch lock. |
273 EXPECT_EQ(WAIT_TIMEOUT, ::WaitForSingleObject(event.Get(), 50)); | 278 EXPECT_EQ(WAIT_TIMEOUT, ::WaitForSingleObject(event.Get(), 50)); |
274 | 279 |
275 // We should still be patched. | 280 // We should still be patched. |
276 EXPECT_CALL(factory_, LockServer(TRUE)) | 281 EXPECT_CALL(factory_, LockServer(TRUE)) |
277 .Times(0); | 282 .Times(0); |
278 EXPECT_CALL(*this, LockServerPatch(_, &factory_, TRUE)) | 283 EXPECT_CALL(*this, LockServerPatch(_, &factory_, TRUE)) |
279 .WillOnce(Return(S_FALSE)); | 284 .WillOnce(Return(S_FALSE)); |
280 EXPECT_EQ(S_FALSE, factory_.LockServer(TRUE)); | 285 EXPECT_EQ(S_FALSE, factory_.LockServer(TRUE)); |
281 | 286 |
282 // Release the patch lock and wait on the event. | 287 // Release the patch lock and wait on the event. |
283 vtable_patch::patch_lock_.Release(); | 288 vtable_patch::patch_lock_.Release(); |
284 EXPECT_EQ(WAIT_OBJECT_0, ::WaitForSingleObject(event.Get(), INFINITE)); | 289 EXPECT_EQ(WAIT_OBJECT_0, ::WaitForSingleObject(event.Get(), INFINITE)); |
285 | 290 |
286 // Verify that unpatching took place. | 291 // Verify that unpatching took place. |
287 EXPECT_CALL(factory_, LockServer(TRUE)) | 292 EXPECT_CALL(factory_, LockServer(TRUE)) |
288 .WillOnce(Return(S_FALSE)); | 293 .WillOnce(Return(S_FALSE)); |
289 EXPECT_EQ(S_FALSE, factory_.LockServer(TRUE)); | 294 EXPECT_EQ(S_FALSE, factory_.LockServer(TRUE)); |
290 } | 295 } |
OLD | NEW |