OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/base64.h" | 8 #include "base/base64.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 class TestEnvironment { | 142 class TestEnvironment { |
143 public: | 143 public: |
144 #if defined(OS_ANDROID) | 144 #if defined(OS_ANDROID) |
145 // Android UI message loop goes through Java, so don't use it in tests. | 145 // Android UI message loop goes through Java, so don't use it in tests. |
146 typedef MessageLoop MessageLoopType; | 146 typedef MessageLoop MessageLoopType; |
147 #else | 147 #else |
148 typedef MessageLoopForUI MessageLoopType; | 148 typedef MessageLoopForUI MessageLoopType; |
149 #endif | 149 #endif |
150 | 150 |
151 TestEnvironment(bool unit_test_mode, | 151 TestEnvironment(bool unit_test_mode, |
152 base::AtExitManager* existing_at_exit_manager) { | 152 base::AtExitManager* existing_at_exit_manager, |
| 153 WebKit::Platform* shadow_platform_delegate) { |
153 if (unit_test_mode) { | 154 if (unit_test_mode) { |
154 logging::SetLogAssertHandler(UnitTestAssertHandler); | 155 logging::SetLogAssertHandler(UnitTestAssertHandler); |
155 } else { | 156 } else { |
156 // The existing_at_exit_manager must be not NULL. | 157 // The existing_at_exit_manager must be not NULL. |
157 at_exit_manager_.reset(existing_at_exit_manager); | 158 at_exit_manager_.reset(existing_at_exit_manager); |
158 InitLogging(); | 159 InitLogging(); |
159 } | 160 } |
160 main_message_loop_.reset(new MessageLoopType); | 161 main_message_loop_.reset(new MessageLoopType); |
| 162 |
161 // TestWebKitPlatformSupport must be instantiated after MessageLoopType. | 163 // TestWebKitPlatformSupport must be instantiated after MessageLoopType. |
162 webkit_platform_support_.reset( | 164 webkit_platform_support_.reset( |
163 new TestWebKitPlatformSupport(unit_test_mode)); | 165 new TestWebKitPlatformSupport(unit_test_mode, |
| 166 shadow_platform_delegate)); |
164 | 167 |
165 #if defined(OS_ANDROID) | 168 #if defined(OS_ANDROID) |
166 media_player_manager_.reset( | 169 media_player_manager_.reset( |
167 new webkit_media::WebMediaPlayerManagerAndroid()); | 170 new webkit_media::WebMediaPlayerManagerAndroid()); |
168 #endif | 171 #endif |
169 } | 172 } |
170 | 173 |
171 ~TestEnvironment() { | 174 ~TestEnvironment() { |
172 SimpleResourceLoaderBridge::Shutdown(); | 175 SimpleResourceLoaderBridge::Shutdown(); |
173 } | 176 } |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 private: | 274 private: |
272 MessageLoop* message_loop_; | 275 MessageLoop* message_loop_; |
273 }; | 276 }; |
274 | 277 |
275 webkit_support::GraphicsContext3DImplementation | 278 webkit_support::GraphicsContext3DImplementation |
276 g_graphics_context_3d_implementation = | 279 g_graphics_context_3d_implementation = |
277 webkit_support::IN_PROCESS_COMMAND_BUFFER; | 280 webkit_support::IN_PROCESS_COMMAND_BUFFER; |
278 | 281 |
279 TestEnvironment* test_environment; | 282 TestEnvironment* test_environment; |
280 | 283 |
281 void SetUpTestEnvironmentImpl(bool unit_test_mode) { | 284 void SetUpTestEnvironmentImpl(bool unit_test_mode, |
| 285 WebKit::Platform* shadow_platform_delegate) { |
282 base::EnableInProcessStackDumping(); | 286 base::EnableInProcessStackDumping(); |
283 base::EnableTerminationOnHeapCorruption(); | 287 base::EnableTerminationOnHeapCorruption(); |
284 | 288 |
285 // Initialize the singleton CommandLine with fixed values. Some code refer to | 289 // Initialize the singleton CommandLine with fixed values. Some code refer to |
286 // CommandLine::ForCurrentProcess(). We don't use the actual command-line | 290 // CommandLine::ForCurrentProcess(). We don't use the actual command-line |
287 // arguments of DRT to avoid unexpected behavior change. | 291 // arguments of DRT to avoid unexpected behavior change. |
288 // | 292 // |
289 // webkit/glue/plugin/plugin_list_posix.cc checks --debug-plugin-loading. | 293 // webkit/glue/plugin/plugin_list_posix.cc checks --debug-plugin-loading. |
290 // webkit/glue/plugin/plugin_list_win.cc checks --old-wmp. | 294 // webkit/glue/plugin/plugin_list_win.cc checks --old-wmp. |
291 // If DRT needs these flags, specify them in the following kFixedArguments. | 295 // If DRT needs these flags, specify them in the following kFixedArguments. |
292 const char* kFixedArguments[] = {"DumpRenderTree"}; | 296 const char* kFixedArguments[] = {"DumpRenderTree"}; |
293 CommandLine::Init(arraysize(kFixedArguments), kFixedArguments); | 297 CommandLine::Init(arraysize(kFixedArguments), kFixedArguments); |
294 | 298 |
295 // Explicitly initialize the GURL library before spawning any threads. | 299 // Explicitly initialize the GURL library before spawning any threads. |
296 // Otherwise crash may happend when different threads try to create a GURL | 300 // Otherwise crash may happend when different threads try to create a GURL |
297 // at same time. | 301 // at same time. |
298 url_util::Initialize(); | 302 url_util::Initialize(); |
299 base::AtExitManager* at_exit_manager = NULL; | 303 base::AtExitManager* at_exit_manager = NULL; |
300 // In Android DumpRenderTree, AtExitManager is created in | 304 // In Android DumpRenderTree, AtExitManager is created in |
301 // testing/android/native_test_wrapper.cc before main() is called. | 305 // testing/android/native_test_wrapper.cc before main() is called. |
302 #if !defined(OS_ANDROID) | 306 #if !defined(OS_ANDROID) |
303 // Some initialization code may use a AtExitManager before initializing | 307 // Some initialization code may use a AtExitManager before initializing |
304 // TestEnvironment, so we create a AtExitManager early and pass its ownership | 308 // TestEnvironment, so we create a AtExitManager early and pass its ownership |
305 // to TestEnvironment. | 309 // to TestEnvironment. |
306 if (!unit_test_mode) | 310 if (!unit_test_mode) |
307 at_exit_manager = new base::AtExitManager; | 311 at_exit_manager = new base::AtExitManager; |
308 #endif | 312 #endif |
309 webkit_support::BeforeInitialize(unit_test_mode); | 313 webkit_support::BeforeInitialize(unit_test_mode); |
310 test_environment = new TestEnvironment(unit_test_mode, at_exit_manager); | 314 test_environment = new TestEnvironment(unit_test_mode, at_exit_manager, |
| 315 shadow_platform_delegate); |
311 webkit_support::AfterInitialize(unit_test_mode); | 316 webkit_support::AfterInitialize(unit_test_mode); |
312 if (!unit_test_mode) { | 317 if (!unit_test_mode) { |
313 // Load ICU data tables. This has to run after TestEnvironment is created | 318 // Load ICU data tables. This has to run after TestEnvironment is created |
314 // because on Linux, we need base::AtExitManager. | 319 // because on Linux, we need base::AtExitManager. |
315 icu_util::Initialize(); | 320 icu_util::Initialize(); |
316 } | 321 } |
317 webkit_glue::SetUserAgent(webkit_glue::BuildUserAgentFromProduct( | 322 webkit_glue::SetUserAgent(webkit_glue::BuildUserAgentFromProduct( |
318 "DumpRenderTree/0.0.0.0"), false); | 323 "DumpRenderTree/0.0.0.0"), false); |
319 } | 324 } |
320 | 325 |
321 } // namespace | 326 } // namespace |
322 | 327 |
323 namespace webkit_support { | 328 namespace webkit_support { |
324 | 329 |
325 void SetUpTestEnvironment() { | 330 void SetUpTestEnvironment() { |
326 SetUpTestEnvironmentImpl(false); | 331 SetUpTestEnvironment(NULL); |
327 } | 332 } |
328 | 333 |
329 void SetUpTestEnvironmentForUnitTests() { | 334 void SetUpTestEnvironmentForUnitTests() { |
330 SetUpTestEnvironmentImpl(true); | 335 SetUpTestEnvironmentForUnitTests(NULL); |
| 336 } |
| 337 |
| 338 void SetUpTestEnvironment(WebKit::Platform* shadow_platform_delegate) { |
| 339 SetUpTestEnvironmentImpl(false, shadow_platform_delegate); |
| 340 } |
| 341 |
| 342 void SetUpTestEnvironmentForUnitTests( |
| 343 WebKit::Platform* shadow_platform_delegate) { |
| 344 SetUpTestEnvironmentImpl(true, shadow_platform_delegate); |
331 } | 345 } |
332 | 346 |
333 void TearDownTestEnvironment() { | 347 void TearDownTestEnvironment() { |
334 // Flush any remaining messages before we kill ourselves. | 348 // Flush any remaining messages before we kill ourselves. |
335 // http://code.google.com/p/chromium/issues/detail?id=9500 | 349 // http://code.google.com/p/chromium/issues/detail?id=9500 |
336 MessageLoop::current()->RunAllPending(); | 350 MessageLoop::current()->RunAllPending(); |
337 | 351 |
338 BeforeShutdown(); | 352 BeforeShutdown(); |
339 if (RunningOnValgrind()) | 353 if (RunningOnValgrind()) |
340 WebKit::WebCache::clear(); | 354 WebKit::WebCache::clear(); |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 // Logging | 823 // Logging |
810 void EnableWebCoreLogChannels(const std::string& channels) { | 824 void EnableWebCoreLogChannels(const std::string& channels) { |
811 webkit_glue::EnableWebCoreLogChannels(channels); | 825 webkit_glue::EnableWebCoreLogChannels(channels); |
812 } | 826 } |
813 | 827 |
814 void SetGamepadData(const WebKit::WebGamepads& pads) { | 828 void SetGamepadData(const WebKit::WebGamepads& pads) { |
815 test_environment->webkit_platform_support()->setGamepadData(pads); | 829 test_environment->webkit_platform_support()->setGamepadData(pads); |
816 } | 830 } |
817 | 831 |
818 } // namespace webkit_support | 832 } // namespace webkit_support |
OLD | NEW |