1 // Copyright 2014 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "base/debug/debugger.h" 6 #include "build/build_config.h" 7 8 #if BUILDFLAG(IS_WIN) 9 #include <windows.h> 10 #endif 11 12 #include "testing/gtest/include/gtest/gtest.h" 13 14 namespace { 15 16 #if defined(GTEST_HAS_DEATH_TEST) && !BUILDFLAG(IS_ANDROID) CrashWithBreakDebugger()17void CrashWithBreakDebugger() { 18 base::debug::SetSuppressDebugUI(false); 19 base::debug::BreakDebugger(); 20 21 #if BUILDFLAG(IS_WIN) 22 // This should not be executed. 23 _exit(125); 24 #endif 25 } 26 #endif // defined(GTEST_HAS_DEATH_TEST) 27 28 } // namespace 29 30 // Death tests misbehave on Android. 31 #if defined(GTEST_HAS_DEATH_TEST) && !BUILDFLAG(IS_ANDROID) 32 TEST(Debugger,CrashAtBreakpoint)33TEST(Debugger, CrashAtBreakpoint) { 34 EXPECT_DEATH(CrashWithBreakDebugger(), ""); 35 } 36 37 #if BUILDFLAG(IS_WIN) TEST(Debugger,DoesntExecuteBeyondBreakpoint)38TEST(Debugger, DoesntExecuteBeyondBreakpoint) { 39 EXPECT_EXIT(CrashWithBreakDebugger(), 40 ::testing::ExitedWithCode(STATUS_BREAKPOINT), ""); 41 } 42 #endif // BUILDFLAG(IS_WIN) 43 44 #else // defined(GTEST_HAS_DEATH_TEST) && !BUILDFLAG(IS_ANDROID) TEST(Debugger,NoTest)45TEST(Debugger, NoTest) { 46 } 47 #endif // defined(GTEST_HAS_DEATH_TEST) && !BUILDFLAG(IS_ANDROID) 48