| OLD | NEW |
| 1 // Copyright (c) 2010 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 #include <unknwn.h> | 7 #include <unknwn.h> |
| 8 |
| 7 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 8 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
| 9 #include "base/scoped_handle.h" | 11 #include "base/win/scoped_handle.h" |
| 10 #include "gtest/gtest.h" | 12 #include "gtest/gtest.h" |
| 11 #include "gmock/gmock.h" | 13 #include "gmock/gmock.h" |
| 12 | 14 |
| 13 namespace { | 15 namespace { |
| 14 // GMock names we use. | 16 // GMock names we use. |
| 15 using testing::_; | 17 using testing::_; |
| 16 using testing::Return; | 18 using testing::Return; |
| 17 | 19 |
| 18 class MockClassFactory : public IClassFactory { | 20 class MockClassFactory : public IClassFactory { |
| 19 public: | 21 public: |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 | 204 |
| 203 } // namespace vtable_patch | 205 } // namespace vtable_patch |
| 204 | 206 |
| 205 TEST_F(VtablePatchManagerTest, ThreadSafePatching) { | 207 TEST_F(VtablePatchManagerTest, ThreadSafePatching) { |
| 206 // It's difficult to test for threadsafe patching, but as a close proxy, | 208 // It's difficult to test for threadsafe patching, but as a close proxy, |
| 207 // test for no patching happening from a background thread while the patch | 209 // test for no patching happening from a background thread while the patch |
| 208 // lock is held. | 210 // lock is held. |
| 209 base::Thread background("Background Test Thread"); | 211 base::Thread background("Background Test Thread"); |
| 210 | 212 |
| 211 EXPECT_TRUE(background.Start()); | 213 EXPECT_TRUE(background.Start()); |
| 212 ScopedHandle event(::CreateEvent(NULL, TRUE, FALSE, NULL)); | 214 base::win::ScopedHandle event(::CreateEvent(NULL, TRUE, FALSE, NULL)); |
| 213 | 215 |
| 214 // Grab the patch lock. | 216 // Grab the patch lock. |
| 215 vtable_patch::patch_lock_.Acquire(); | 217 vtable_patch::patch_lock_.Acquire(); |
| 216 | 218 |
| 217 // Instruct the background thread to patch factory_. | 219 // Instruct the background thread to patch factory_. |
| 218 background.message_loop()->PostTask(FROM_HERE, | 220 background.message_loop()->PostTask(FROM_HERE, |
| 219 NewRunnableFunction(&vtable_patch::PatchInterfaceMethods, | 221 NewRunnableFunction(&vtable_patch::PatchInterfaceMethods, |
| 220 &factory_, | 222 &factory_, |
| 221 &IClassFactory_PatchInfo[0])); | 223 &IClassFactory_PatchInfo[0])); |
| 222 | 224 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 | 281 |
| 280 // Release the patch lock and wait on the event. | 282 // Release the patch lock and wait on the event. |
| 281 vtable_patch::patch_lock_.Release(); | 283 vtable_patch::patch_lock_.Release(); |
| 282 EXPECT_EQ(WAIT_OBJECT_0, ::WaitForSingleObject(event.Get(), INFINITE)); | 284 EXPECT_EQ(WAIT_OBJECT_0, ::WaitForSingleObject(event.Get(), INFINITE)); |
| 283 | 285 |
| 284 // Verify that unpatching took place. | 286 // Verify that unpatching took place. |
| 285 EXPECT_CALL(factory_, LockServer(TRUE)) | 287 EXPECT_CALL(factory_, LockServer(TRUE)) |
| 286 .WillOnce(Return(S_FALSE)); | 288 .WillOnce(Return(S_FALSE)); |
| 287 EXPECT_EQ(S_FALSE, factory_.LockServer(TRUE)); | 289 EXPECT_EQ(S_FALSE, factory_.LockServer(TRUE)); |
| 288 } | 290 } |
| OLD | NEW |