summaryrefslogtreecommitdiff
path: root/chromium/webkit/support/webkit_support.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/webkit/support/webkit_support.cc')
-rw-r--r--chromium/webkit/support/webkit_support.cc89
1 files changed, 75 insertions, 14 deletions
diff --git a/chromium/webkit/support/webkit_support.cc b/chromium/webkit/support/webkit_support.cc
index 6f9d41ac3d7..c5846385a70 100644
--- a/chromium/webkit/support/webkit_support.cc
+++ b/chromium/webkit/support/webkit_support.cc
@@ -4,26 +4,77 @@
#include "webkit/support/webkit_support.h"
+#include "base/command_line.h"
+#include "base/debug/debugger.h"
+#include "base/debug/stack_trace.h"
+#include "base/logging.h"
#include "base/message_loop/message_loop.h"
+#include "base/path_service.h"
+#include "base/process/memory.h"
#include "base/run_loop.h"
+#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/public/web/WebCache.h"
#include "third_party/WebKit/public/web/WebKit.h"
#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
#include "url/url_util.h"
+#include "webkit/child/webkitplatformsupport_impl.h"
#include "webkit/common/user_agent/user_agent.h"
#include "webkit/common/user_agent/user_agent_util.h"
+#include "webkit/glue/webkit_glue.h"
+#include "webkit/support/platform_support.h"
#include "webkit/support/test_webkit_platform_support.h"
#if defined(OS_ANDROID)
-#include "base/android/jni_android.h"
-#include "net/android/network_library.h"
+#include "base/test/test_support_android.h"
#endif
-#if defined(OS_MACOSX)
-#include "base/test/mock_chrome_application_mac.h"
+namespace {
+
+// All fatal log messages (e.g. DCHECK failures) imply unit test failures
+void UnitTestAssertHandler(const std::string& str) {
+ FAIL() << str;
+}
+
+void InitLogging() {
+#if defined(OS_WIN)
+ if (!::IsDebuggerPresent()) {
+ UINT new_flags = SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX
+ | SEM_NOGPFAULTERRORBOX;
+
+ // Preserve existing error mode, as discussed at
+ // http://blogs.msdn.com/oldnewthing/archive/2004/07/27/198410.aspx
+ UINT existing_flags = SetErrorMode(new_flags);
+ SetErrorMode(existing_flags | new_flags);
+
+ // Don't pop up dialog on assertion failure, log to stdout instead.
+ _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
+ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDOUT);
+ }
#endif
-namespace {
+#if defined(OS_ANDROID)
+ // On Android we expect the log to appear in logcat.
+ base::InitAndroidTestLogging();
+#else
+ base::FilePath log_filename;
+ PathService::Get(base::DIR_EXE, &log_filename);
+ log_filename = log_filename.AppendASCII("DumpRenderTree.log");
+ logging::LoggingSettings settings;
+ // Only log to a file. This prevents debugging output from disrupting
+ // whether or not we pass.
+ settings.logging_dest = logging::LOG_TO_FILE;
+ settings.log_file = log_filename.value().c_str();
+ settings.delete_old = logging::DELETE_OLD_LOG_FILE;
+ logging::InitLogging(settings);
+
+ // We want process and thread IDs because we may have multiple processes.
+ const bool kProcessId = true;
+ const bool kThreadId = true;
+ const bool kTimestamp = true;
+ const bool kTickcount = true;
+ logging::SetLogItems(kProcessId, kThreadId, !kTimestamp, kTickcount);
+#endif // else defined(OS_ANDROID)
+}
class TestEnvironment {
public:
@@ -35,6 +86,7 @@ class TestEnvironment {
#endif
TestEnvironment() {
+ logging::SetLogAssertHandler(UnitTestAssertHandler);
main_message_loop_.reset(new MessageLoopType);
// TestWebKitPlatformSupport must be instantiated after MessageLoopType.
@@ -57,24 +109,30 @@ TestEnvironment* test_environment;
namespace webkit_support {
void SetUpTestEnvironmentForUnitTests() {
+ base::debug::EnableInProcessStackDumping();
+ base::EnableTerminationOnHeapCorruption();
+
+ // Initialize the singleton CommandLine with fixed values. Some code refer to
+ // CommandLine::ForCurrentProcess(). We don't use the actual command-line
+ // arguments of DRT to avoid unexpected behavior change.
+ //
+ // webkit/glue/plugin/plugin_list_posix.cc checks --debug-plugin-loading.
+ // webkit/glue/plugin/plugin_list_win.cc checks --old-wmp.
+ // If DRT needs these flags, specify them in the following kFixedArguments.
+ const char* kFixedArguments[] = {"DumpRenderTree"};
+ CommandLine::Init(arraysize(kFixedArguments), kFixedArguments);
+
WebKit::WebRuntimeFeatures::enableStableFeatures(true);
WebKit::WebRuntimeFeatures::enableExperimentalFeatures(true);
WebKit::WebRuntimeFeatures::enableTestOnlyFeatures(true);
-#if defined(OS_ANDROID)
- JNIEnv* env = base::android::AttachCurrentThread();
- net::android::RegisterNetworkLibrary(env);
-#endif
-
-#if defined(OS_MACOSX)
- mock_cr_app::RegisterMockCrApp();
-#endif
-
// Explicitly initialize the GURL library before spawning any threads.
// Otherwise crash may happend when different threads try to create a GURL
// at same time.
url_util::Initialize();
+ webkit_support::BeforeInitialize();
test_environment = new TestEnvironment;
+ webkit_support::AfterInitialize();
webkit_glue::SetUserAgent(webkit_glue::BuildUserAgentFromProduct(
"DumpRenderTree/0.0.0.0"), false);
}
@@ -84,11 +142,14 @@ void TearDownTestEnvironment() {
// http://code.google.com/p/chromium/issues/detail?id=9500
base::RunLoop().RunUntilIdle();
+ BeforeShutdown();
if (RunningOnValgrind())
WebKit::WebCache::clear();
WebKit::shutdown();
delete test_environment;
test_environment = NULL;
+ AfterShutdown();
+ logging::CloseLogFile();
}
} // namespace webkit_support