| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <atlbase.h> | 5 #include <atlbase.h> |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome_frame/crash_reporting/vectored_handler-impl.h" | 8 #include "chrome_frame/crash_reporting/vectored_handler-impl.h" |
| 9 #include "chrome_frame/crash_reporting/crash_report.h" |
| 9 #include "gmock/gmock.h" | 10 #include "gmock/gmock.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 12 |
| 12 // Class that mocks external call from VectoredHandlerT for testing purposes. | 13 // Class that mocks external call from VectoredHandlerT for testing purposes. |
| 13 class EMock : public VEHTraitsBase { | 14 class EMock : public Win32VEHTraits { |
| 14 public: | 15 public: |
| 15 static inline bool WriteDump(EXCEPTION_POINTERS* p) { | 16 static inline bool WriteDump(EXCEPTION_POINTERS* p) { |
| 16 g_dump_made = true; | 17 g_dump_made = true; |
| 17 return true; | 18 return true; |
| 18 } | 19 } |
| 19 | 20 |
| 20 static inline void* Register(PVECTORED_EXCEPTION_HANDLER func, | 21 static inline void* Register(PVECTORED_EXCEPTION_HANDLER func, |
| 21 const void* module_start, | 22 const void* module_start, |
| 22 const void* module_end) { | 23 const void* module_end) { |
| 24 InitializeIgnoredBlocks(); |
| 23 VEHTraitsBase::SetModule(module_start, module_end); | 25 VEHTraitsBase::SetModule(module_start, module_end); |
| 24 // Return some arbitrary number, expecting to get the same on Unregister() | 26 // Return some arbitrary number, expecting to get the same on Unregister() |
| 25 return reinterpret_cast<void*>(4); | 27 return reinterpret_cast<void*>(4); |
| 26 } | 28 } |
| 27 | 29 |
| 28 static inline ULONG Unregister(void* handle) { | 30 static inline ULONG Unregister(void* handle) { |
| 29 EXPECT_EQ(handle, reinterpret_cast<void*>(4)); | 31 EXPECT_EQ(handle, reinterpret_cast<void*>(4)); |
| 30 return 1; | 32 return 1; |
| 31 } | 33 } |
| 32 | 34 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 | 183 |
| 182 // Exception, in our code, no SEH, not on stack (assume FPO screwed us) | 184 // Exception, in our code, no SEH, not on stack (assume FPO screwed us) |
| 183 ex.Set(STATUS_INTEGER_DIVIDE_BY_ZERO, our_code, 0); | 185 ex.Set(STATUS_INTEGER_DIVIDE_BY_ZERO, our_code, 0); |
| 184 EMock::SetNoSEHFilter(); | 186 EMock::SetNoSEHFilter(); |
| 185 EMock::SetNotOnStack(); | 187 EMock::SetNotOnStack(); |
| 186 EXPECT_EQ(ExceptionContinueSearch, VectoredHandlerMock::VectoredHandler(&ex)); | 188 EXPECT_EQ(ExceptionContinueSearch, VectoredHandlerMock::VectoredHandler(&ex)); |
| 187 EXPECT_EQ(4, VectoredHandlerMock::g_exceptions_seen); | 189 EXPECT_EQ(4, VectoredHandlerMock::g_exceptions_seen); |
| 188 EXPECT_TRUE(EMock::g_dump_made); | 190 EXPECT_TRUE(EMock::g_dump_made); |
| 189 EMock::g_dump_made = false; | 191 EMock::g_dump_made = false; |
| 190 | 192 |
| 193 // Exception, in IsBadStringPtrA, we are on the stack. |
| 194 char* ignore_address = reinterpret_cast<char*>(GetProcAddress( |
| 195 GetModuleHandleA("kernel32.dll"), "IsBadStringPtrA")) + 10; |
| 196 ex.Set(STATUS_ACCESS_VIOLATION, ignore_address + 10, 0); |
| 197 EMock::SetNoSEHFilter(); |
| 198 EMock::SetOnStack(); |
| 199 EXPECT_EQ(ExceptionContinueSearch, VectoredHandlerMock::VectoredHandler(&ex)); |
| 200 EXPECT_EQ(5, VectoredHandlerMock::g_exceptions_seen); |
| 201 EXPECT_FALSE(EMock::g_dump_made); |
| 202 EMock::g_dump_made = false; |
| 203 |
| 204 // Exception, in IsBadStringPtrA, we are not in stack. |
| 205 ex.Set(STATUS_ACCESS_VIOLATION, ignore_address + 10, 0); |
| 206 EMock::SetNoSEHFilter(); |
| 207 EMock::SetNotOnStack(); |
| 208 EXPECT_EQ(ExceptionContinueSearch, VectoredHandlerMock::VectoredHandler(&ex)); |
| 209 EXPECT_EQ(6, VectoredHandlerMock::g_exceptions_seen); |
| 210 EXPECT_FALSE(EMock::g_dump_made); |
| 211 EMock::g_dump_made = false; |
| 212 |
| 191 VectoredHandlerMock::Unregister(); | 213 VectoredHandlerMock::Unregister(); |
| 192 } | 214 } |
| OLD | NEW |