| OLD | NEW |
| 1 // Copyright (c) 2010 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 "webkit/support/webkit_support.h" | 5 #include "webkit/support/webkit_support.h" |
| 6 | 6 |
| 7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/debug_util.h" | 9 #include "base/debug_util.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 using WebKit::WebCString; | 44 using WebKit::WebCString; |
| 45 using WebKit::WebFrame; | 45 using WebKit::WebFrame; |
| 46 using WebKit::WebMediaPlayerClient; | 46 using WebKit::WebMediaPlayerClient; |
| 47 using WebKit::WebPlugin; | 47 using WebKit::WebPlugin; |
| 48 using WebKit::WebPluginParams; | 48 using WebKit::WebPluginParams; |
| 49 using WebKit::WebString; | 49 using WebKit::WebString; |
| 50 using WebKit::WebURL; | 50 using WebKit::WebURL; |
| 51 | 51 |
| 52 namespace { | 52 namespace { |
| 53 | 53 |
| 54 // All fatal log messages (e.g. DCHECK failures) imply unit test failures |
| 55 void UnitTestAssertHandler(const std::string& str) { |
| 56 FAIL() << str; |
| 57 } |
| 58 |
| 59 void InitLogging(bool enable_gp_fault_error_box) { |
| 60 logging::SetLogAssertHandler(UnitTestAssertHandler); |
| 61 |
| 62 #if defined(OS_WIN) |
| 63 if (!::IsDebuggerPresent()) { |
| 64 UINT new_flags = SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX; |
| 65 if (!enable_gp_fault_error_box) |
| 66 new_flags |= SEM_NOGPFAULTERRORBOX; |
| 67 |
| 68 // Preserve existing error mode, as discussed at |
| 69 // http://blogs.msdn.com/oldnewthing/archive/2004/07/27/198410.aspx |
| 70 UINT existing_flags = SetErrorMode(new_flags); |
| 71 SetErrorMode(existing_flags | new_flags); |
| 72 } |
| 73 #endif |
| 74 |
| 75 FilePath log_filename; |
| 76 PathService::Get(base::DIR_EXE, &log_filename); |
| 77 log_filename = log_filename.AppendASCII("DumpRenderTree.log"); |
| 78 logging::InitLogging( |
| 79 log_filename.value().c_str(), |
| 80 // Only log to a file. This prevents debugging output from disrupting |
| 81 // whether or not we pass. |
| 82 logging::LOG_ONLY_TO_FILE, |
| 83 // We might have multiple DumpRenderTree processes going at once. |
| 84 logging::LOCK_LOG_FILE, |
| 85 logging::DELETE_OLD_LOG_FILE); |
| 86 |
| 87 // We want process and thread IDs because we may have multiple processes. |
| 88 const bool kProcessId = true; |
| 89 const bool kThreadId = true; |
| 90 const bool kTimestamp = true; |
| 91 const bool kTickcount = true; |
| 92 logging::SetLogItems(kProcessId, kThreadId, !kTimestamp, kTickcount); |
| 93 } |
| 94 |
| 54 class TestEnvironment { | 95 class TestEnvironment { |
| 55 public: | 96 public: |
| 56 explicit TestEnvironment(bool unit_test_mode) { | 97 explicit TestEnvironment(bool unit_test_mode) { |
| 57 if (!unit_test_mode) | 98 if (!unit_test_mode) { |
| 58 at_exit_manager_.reset(new base::AtExitManager); | 99 at_exit_manager_.reset(new base::AtExitManager); |
| 100 InitLogging(false); |
| 101 } |
| 59 main_message_loop_.reset(new MessageLoopForUI); | 102 main_message_loop_.reset(new MessageLoopForUI); |
| 60 // TestWebKitClient must be instantiated after the MessageLoopForUI. | 103 // TestWebKitClient must be instantiated after the MessageLoopForUI. |
| 61 webkit_client_.reset(new TestWebKitClient(unit_test_mode)); | 104 webkit_client_.reset(new TestWebKitClient(unit_test_mode)); |
| 62 } | 105 } |
| 63 | 106 |
| 64 ~TestEnvironment() { | 107 ~TestEnvironment() { |
| 65 SimpleResourceLoaderBridge::Shutdown(); | 108 SimpleResourceLoaderBridge::Shutdown(); |
| 66 } | 109 } |
| 67 | 110 |
| 68 TestWebKitClient* webkit_client() { return webkit_client_.get(); } | 111 TestWebKitClient* webkit_client() { return webkit_client_.get(); } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 FilePath basePath; | 148 FilePath basePath; |
| 106 PathService::Get(base::DIR_SOURCE_ROOT, &basePath); | 149 PathService::Get(base::DIR_SOURCE_ROOT, &basePath); |
| 107 if (file_util::PathExists(basePath.Append(FILE_PATH_LITERAL("chrome")))) { | 150 if (file_util::PathExists(basePath.Append(FILE_PATH_LITERAL("chrome")))) { |
| 108 return basePath.Append(FILE_PATH_LITERAL("third_party/WebKit")); | 151 return basePath.Append(FILE_PATH_LITERAL("third_party/WebKit")); |
| 109 } else { | 152 } else { |
| 110 // WebKit/WebKit/chromium/ -> WebKit/ | 153 // WebKit/WebKit/chromium/ -> WebKit/ |
| 111 return basePath.Append(FILE_PATH_LITERAL("../..")); | 154 return basePath.Append(FILE_PATH_LITERAL("../..")); |
| 112 } | 155 } |
| 113 } | 156 } |
| 114 | 157 |
| 115 // All fatal log messages (e.g. DCHECK failures) imply unit test failures | |
| 116 void UnitTestAssertHandler(const std::string& str) { | |
| 117 FAIL() << str; | |
| 118 } | |
| 119 | |
| 120 void InitLogging(bool enable_gp_fault_error_box) { | |
| 121 logging::SetLogAssertHandler(UnitTestAssertHandler); | |
| 122 | |
| 123 #if defined(OS_WIN) | |
| 124 if (!::IsDebuggerPresent()) { | |
| 125 UINT new_flags = SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX; | |
| 126 if (!enable_gp_fault_error_box) | |
| 127 new_flags |= SEM_NOGPFAULTERRORBOX; | |
| 128 | |
| 129 // Preserve existing error mode, as discussed at | |
| 130 // http://blogs.msdn.com/oldnewthing/archive/2004/07/27/198410.aspx | |
| 131 UINT existing_flags = SetErrorMode(new_flags); | |
| 132 SetErrorMode(existing_flags | new_flags); | |
| 133 } | |
| 134 #endif | |
| 135 | |
| 136 FilePath log_filename; | |
| 137 PathService::Get(base::DIR_EXE, &log_filename); | |
| 138 log_filename = log_filename.AppendASCII("DumpRenderTree.log"); | |
| 139 logging::InitLogging( | |
| 140 log_filename.value().c_str(), | |
| 141 // Only log to a file. This prevents debugging output from disrupting | |
| 142 // whether or not we pass. | |
| 143 logging::LOG_ONLY_TO_FILE, | |
| 144 // We might have multiple DumpRenderTree processes going at once. | |
| 145 logging::LOCK_LOG_FILE, | |
| 146 logging::DELETE_OLD_LOG_FILE); | |
| 147 | |
| 148 // We want process and thread IDs because we may have multiple processes. | |
| 149 const bool kProcessId = true; | |
| 150 const bool kThreadId = true; | |
| 151 const bool kTimestamp = true; | |
| 152 const bool kTickcount = true; | |
| 153 logging::SetLogItems(kProcessId, kThreadId, !kTimestamp, kTickcount); | |
| 154 } | |
| 155 | |
| 156 } // namespace | 158 } // namespace |
| 157 | 159 |
| 158 namespace webkit_support { | 160 namespace webkit_support { |
| 159 | 161 |
| 160 static TestEnvironment* test_environment; | 162 static TestEnvironment* test_environment; |
| 161 | 163 |
| 162 static void SetUpTestEnvironmentImpl(bool unit_test_mode) { | 164 static void SetUpTestEnvironmentImpl(bool unit_test_mode) { |
| 163 base::EnableInProcessStackDumping(); | 165 base::EnableInProcessStackDumping(); |
| 164 base::EnableTerminationOnHeapCorruption(); | 166 base::EnableTerminationOnHeapCorruption(); |
| 165 | 167 |
| 166 // Initialize the singleton CommandLine with fixed values. Some code refer to | 168 // Initialize the singleton CommandLine with fixed values. Some code refer to |
| 167 // CommandLine::ForCurrentProcess(). We don't use the actual command-line | 169 // CommandLine::ForCurrentProcess(). We don't use the actual command-line |
| 168 // arguments of DRT to avoid unexpected behavior change. | 170 // arguments of DRT to avoid unexpected behavior change. |
| 169 // | 171 // |
| 170 // webkit/glue/webmediaplayer_impl.cc checks --enable-openmax. | 172 // webkit/glue/webmediaplayer_impl.cc checks --enable-openmax. |
| 171 // webkit/glue/plugin/plugin_list_posix.cc checks --debug-plugin-loading. | 173 // webkit/glue/plugin/plugin_list_posix.cc checks --debug-plugin-loading. |
| 172 // webkit/glue/plugin/plugin_list_win.cc checks --old-wmp. | 174 // webkit/glue/plugin/plugin_list_win.cc checks --old-wmp. |
| 173 // If DRT needs these flags, specify them in the following kFixedArguments. | 175 // If DRT needs these flags, specify them in the following kFixedArguments. |
| 174 const char* kFixedArguments[] = {"DumpRenderTree"}; | 176 const char* kFixedArguments[] = {"DumpRenderTree"}; |
| 175 CommandLine::Init(arraysize(kFixedArguments), kFixedArguments); | 177 CommandLine::Init(arraysize(kFixedArguments), kFixedArguments); |
| 176 | 178 |
| 177 InitLogging(false); | |
| 178 | |
| 179 webkit_support::BeforeInitialize(); | 179 webkit_support::BeforeInitialize(); |
| 180 webkit_support::test_environment = new TestEnvironment(unit_test_mode); | 180 webkit_support::test_environment = new TestEnvironment(unit_test_mode); |
| 181 webkit_support::AfterInitialize(); | 181 webkit_support::AfterInitialize(); |
| 182 if (!unit_test_mode) { | 182 if (!unit_test_mode) { |
| 183 // Load ICU data tables. This has to run after TestEnvironment is created | 183 // Load ICU data tables. This has to run after TestEnvironment is created |
| 184 // because on Linux, we need base::AtExitManager. | 184 // because on Linux, we need base::AtExitManager. |
| 185 icu_util::Initialize(); | 185 icu_util::Initialize(); |
| 186 } | 186 } |
| 187 } | 187 } |
| 188 | 188 |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 if (!webkit_glue::GetExeDirectory(&dirExe)) { | 444 if (!webkit_glue::GetExeDirectory(&dirExe)) { |
| 445 DCHECK(false); | 445 DCHECK(false); |
| 446 return WebURL(); | 446 return WebURL(); |
| 447 } | 447 } |
| 448 FilePath devToolsPath = dirExe.AppendASCII( | 448 FilePath devToolsPath = dirExe.AppendASCII( |
| 449 "resources/inspector/devtools.html"); | 449 "resources/inspector/devtools.html"); |
| 450 return net::FilePathToFileURL(devToolsPath); | 450 return net::FilePathToFileURL(devToolsPath); |
| 451 } | 451 } |
| 452 | 452 |
| 453 } // namespace webkit_support | 453 } // namespace webkit_support |
| OLD | NEW |