diff options
-rw-r--r-- | base/logging.cc | 37 | ||||
-rw-r--r-- | base/test/test_suite.h | 17 | ||||
-rw-r--r-- | chrome/test/ui/ui_test_suite.cc | 2 |
3 files changed, 31 insertions, 25 deletions
diff --git a/base/logging.cc b/base/logging.cc index 72630fc..1212fd2 100644 --- a/base/logging.cc +++ b/base/logging.cc @@ -47,6 +47,7 @@ typedef pthread_mutex_t* MutexHandle; #if defined(OS_POSIX) #include "base/safe_strerror_posix.h" #endif +#include "base/process_util.h" #include "base/string_piece.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" @@ -328,19 +329,19 @@ void SetLogMessageHandler(LogMessageHandlerFunction handler) { } -// Displays a message box to the user with the error message in it. For -// Windows programs, it's possible that the message loop is messed up on -// a fatal error, and creating a MessageBox will cause that message loop -// to be run. Instead, we try to spawn another process that displays its -// command line. We look for "Debug Message.exe" in the same directory as -// the application. If it exists, we use it, otherwise, we use a regular -// message box. -void DisplayDebugMessage(const std::string& str) { +// Displays a message box to the user with the error message in it. +// Used for fatal messages, where we close the app simultaneously. +void DisplayDebugMessageInDialog(const std::string& str) { if (str.empty()) return; #if defined(OS_WIN) - // look for the debug dialog program next to our application + // For Windows programs, it's possible that the message loop is + // messed up on a fatal error, and creating a MessageBox will cause + // that message loop to be run. Instead, we try to spawn another + // process that displays its command line. We look for "Debug + // Message.exe" in the same directory as the application. If it + // exists, we use it, otherwise, we use a regular message box. wchar_t prog_name[MAX_PATH]; GetModuleFileNameW(NULL, prog_name, MAX_PATH); wchar_t* backslash = wcsrchr(prog_name, '\\'); @@ -367,9 +368,19 @@ void DisplayDebugMessage(const std::string& str) { MessageBoxW(NULL, &cmdline[0], L"Fatal error", MB_OK | MB_ICONHAND | MB_TOPMOST); } +#elif defined(USE_X11) + // Shell out to xmessage, which behaves like debug_message.exe, but is + // way more retro. We could use zenity/kdialog but then we're starting + // to get into needing to check the desktop env and this dialog should + // only be coming up in Very Bad situations. + std::vector<std::string> argv; + argv.push_back("xmessage"); + argv.push_back(str); + base::LaunchApp(argv, base::file_handle_mapping_vector(), true /* wait */, + NULL); #else - fprintf(stderr, "%s\n", str.c_str()); - fflush(stderr); + // http://code.google.com/p/chromium/issues/detail?id=37026 + NOTIMPLEMENTED(); #endif } @@ -581,7 +592,7 @@ LogMessage::~LogMessage() { // information, and displaying message boxes when the application is // hosed can cause additional problems. #ifndef NDEBUG - DisplayDebugMessage(stream_.str()); + DisplayDebugMessageInDialog(stream_.str()); #endif // Crash the process to generate a dump. DebugUtil::BreakDebugger(); @@ -592,7 +603,7 @@ LogMessage::~LogMessage() { if (log_report_handler) { log_report_handler(std::string(stream_.str())); } else { - DisplayDebugMessage(stream_.str()); + DisplayDebugMessageInDialog(stream_.str()); } } } diff --git a/base/test/test_suite.h b/base/test/test_suite.h index 94e7b1a..a8dfdeb 100644 --- a/base/test/test_suite.h +++ b/base/test/test_suite.h @@ -12,6 +12,7 @@ #include "base/at_exit.h" #include "base/base_paths.h" #include "base/debug_on_start.h" +#include "base/debug_util.h" #include "base/i18n/icu_util.h" #include "base/multiprocess_test.h" #include "base/nss_util.h" @@ -146,12 +147,11 @@ class TestSuite { } protected: -#if defined(OS_WIN) - // TODO(phajdan.jr): Clean up the windows-specific hacks. + // TODO(phajdan.jr): Clean this up. // See http://crbug.com/29997 // By default, base::LogMessage::~LogMessage calls DebugUtil::BreakDebugger() - // when severity is LOG_FATAL. On Windows, this results in error dialogs + // when severity is LOG_FATAL. This results in error dialogs // which are not friendly to buildbots. // To avoid these problems, we override the LogMessage behaviour by // replacing the assert handler with UnitTestAssertHandler. @@ -164,6 +164,7 @@ class TestSuite { // Disable crash dialogs so that it doesn't gum up the buildbot virtual void SuppressErrorDialogs() { +#if defined(OS_WIN) UINT new_flags = SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX; @@ -172,8 +173,8 @@ class TestSuite { // http://blogs.msdn.com/oldnewthing/archive/2004/07/27/198410.aspx UINT existing_flags = SetErrorMode(new_flags); SetErrorMode(existing_flags | new_flags); - } #endif // defined(OS_WIN) + } // Override these for custom initialization and shutdown handling. Use these // instead of putting complex code in your constructor/destructor. @@ -197,18 +198,14 @@ class TestSuite { // between production code and test code. bool result = base::Time::UseHighResolutionTimer(true); CHECK(result); +#endif // defined(OS_WIN) // In some cases, we do not want to see standard error dialogs. - if (!IsDebuggerPresent() && + if (!DebugUtil::BeingDebugged() && !CommandLine::ForCurrentProcess()->HasSwitch("show-error-dialogs")) { SuppressErrorDialogs(); -#if !defined(PURIFY) - // When the code in this file moved around, bug 6436 resurfaced. - // As a hack workaround, just #ifdef out this code for Purify builds. logging::SetLogAssertHandler(UnitTestAssertHandler); -#endif // !defined(PURIFY) } -#endif // defined(OS_WIN) icu_util::Initialize(); diff --git a/chrome/test/ui/ui_test_suite.cc b/chrome/test/ui/ui_test_suite.cc index a26000f..bbdf428b 100644 --- a/chrome/test/ui/ui_test_suite.cc +++ b/chrome/test/ui/ui_test_suite.cc @@ -110,9 +110,7 @@ void UITestSuite::Shutdown() { } void UITestSuite::SuppressErrorDialogs() { -#if defined(OS_WIN) TestSuite::SuppressErrorDialogs(); -#endif UITest::set_show_error_dialogs(false); } |