| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/environment.h" |
| 7 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/scoped_ptr.h" |
| 10 #include "base/utf_string_conversions.h" |
| 8 #include "chrome_frame/crash_reporting/crash_dll.h" | 11 #include "chrome_frame/crash_reporting/crash_dll.h" |
| 9 #include "chrome_frame/crash_reporting/nt_loader.h" | 12 #include "chrome_frame/crash_reporting/nt_loader.h" |
| 10 #include "chrome_frame/crash_reporting/vectored_handler-impl.h" | 13 #include "chrome_frame/crash_reporting/vectored_handler-impl.h" |
| 11 #include "chrome_frame/crash_reporting/veh_test.h" | 14 #include "chrome_frame/crash_reporting/veh_test.h" |
| 12 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 17 |
| 15 using testing::_; | 18 using testing::_; |
| 16 | 19 |
| 17 ACTION_P(StackTraceDump, s) { | 20 ACTION_P(StackTraceDump, s) { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 134 |
| 132 // Exception in a loading module, we are on the stack. | 135 // Exception in a loading module, we are on the stack. |
| 133 // Make sure we don't report it. | 136 // Make sure we don't report it. |
| 134 api.SetSEH(no_seh); | 137 api.SetSEH(no_seh); |
| 135 api.SetStack(on_stack); | 138 api.SetStack(on_stack); |
| 136 EXPECT_CALL(api, WriteDump(_)).Times(0); | 139 EXPECT_CALL(api, WriteDump(_)).Times(0); |
| 137 | 140 |
| 138 g_mock_veh = &veh; | 141 g_mock_veh = &veh; |
| 139 void* id = ::AddVectoredExceptionHandler(FALSE, VEH); | 142 void* id = ::AddVectoredExceptionHandler(FALSE, VEH); |
| 140 | 143 |
| 141 EXPECT_TRUE(::SetEnvironmentVariable(kCrashOnLoadMode, L"1")); | 144 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 145 EXPECT_TRUE(env->SetVar(WideToUTF8(kCrashOnLoadMode).c_str(), "1")); |
| 142 long exceptions_seen = veh.get_exceptions_seen(); | 146 long exceptions_seen = veh.get_exceptions_seen(); |
| 143 HMODULE module = ::LoadLibrary(kCrashDllName); | 147 HMODULE module = ::LoadLibrary(kCrashDllName); |
| 144 EXPECT_EQ(NULL, module); | 148 EXPECT_EQ(NULL, module); |
| 145 | 149 |
| 146 testing::Mock::VerifyAndClearExpectations(&api); | 150 testing::Mock::VerifyAndClearExpectations(&api); |
| 147 EXPECT_EQ(exceptions_seen + 1, veh.get_exceptions_seen()); | 151 EXPECT_EQ(exceptions_seen + 1, veh.get_exceptions_seen()); |
| 148 EXPECT_TRUE(::SetEnvironmentVariable(kCrashOnLoadMode, NULL)); | 152 EXPECT_TRUE(env->UnSetVar(WideToUTF8(kCrashOnLoadMode).c_str())); |
| 149 | 153 |
| 150 // Exception in an unloading module, we are on the stack/ | 154 // Exception in an unloading module, we are on the stack/ |
| 151 // Make sure we report it. | 155 // Make sure we report it. |
| 152 EXPECT_TRUE(::SetEnvironmentVariable(kCrashOnUnloadMode, L"1")); | 156 EXPECT_TRUE(env->SetVar(WideToUTF8(kCrashOnUnloadMode).c_str(), "1")); |
| 153 | 157 |
| 154 module = ::LoadLibrary(kCrashDllName); | 158 module = ::LoadLibrary(kCrashDllName); |
| 155 | 159 |
| 156 api.SetSEH(no_seh); | 160 api.SetSEH(no_seh); |
| 157 api.SetStack(on_stack); | 161 api.SetStack(on_stack); |
| 158 EXPECT_CALL(api, WriteDump(_)).Times(1); | 162 EXPECT_CALL(api, WriteDump(_)).Times(1); |
| 159 EXPECT_TRUE(module != NULL); | 163 EXPECT_TRUE(module != NULL); |
| 160 exceptions_seen = veh.get_exceptions_seen(); | 164 exceptions_seen = veh.get_exceptions_seen(); |
| 161 | 165 |
| 162 // Crash on unloading. | 166 // Crash on unloading. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 | 220 |
| 217 DWORD tid; | 221 DWORD tid; |
| 218 HANDLE h = ::CreateThread(0, 0, CrashingThread, 0, 0, &tid); | 222 HANDLE h = ::CreateThread(0, 0, CrashingThread, 0, 0, &tid); |
| 219 ::WaitForSingleObject(h, INFINITE); | 223 ::WaitForSingleObject(h, INFINITE); |
| 220 ::CloseHandle(h); | 224 ::CloseHandle(h); |
| 221 | 225 |
| 222 EXPECT_EQ(2, veh.get_exceptions_seen()); | 226 EXPECT_EQ(2, veh.get_exceptions_seen()); |
| 223 ::RemoveVectoredExceptionHandler(id); | 227 ::RemoveVectoredExceptionHandler(id); |
| 224 g_mock_veh = NULL; | 228 g_mock_veh = NULL; |
| 225 } | 229 } |
| OLD | NEW |