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 PlatformSupportCreatorCallback callback) { | |
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(callback(unit_test_mode)); |
163 new TestWebKitPlatformSupport(unit_test_mode)); | |
164 | 165 |
165 #if defined(OS_ANDROID) | 166 #if defined(OS_ANDROID) |
166 media_player_manager_.reset( | 167 media_player_manager_.reset( |
167 new webkit_media::WebMediaPlayerManagerAndroid()); | 168 new webkit_media::WebMediaPlayerManagerAndroid()); |
168 #endif | 169 #endif |
169 } | 170 } |
170 | 171 |
171 ~TestEnvironment() { | 172 ~TestEnvironment() { |
172 SimpleResourceLoaderBridge::Shutdown(); | 173 SimpleResourceLoaderBridge::Shutdown(); |
173 } | 174 } |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
271 private: | 272 private: |
272 MessageLoop* message_loop_; | 273 MessageLoop* message_loop_; |
273 }; | 274 }; |
274 | 275 |
275 webkit_support::GraphicsContext3DImplementation | 276 webkit_support::GraphicsContext3DImplementation |
276 g_graphics_context_3d_implementation = | 277 g_graphics_context_3d_implementation = |
277 webkit_support::IN_PROCESS_COMMAND_BUFFER; | 278 webkit_support::IN_PROCESS_COMMAND_BUFFER; |
278 | 279 |
279 TestEnvironment* test_environment; | 280 TestEnvironment* test_environment; |
280 | 281 |
281 void SetUpTestEnvironmentImpl(bool unit_test_mode) { | 282 void SetUpTestEnvironmentImpl(PlatformSupportCreatorCallback callback, |
283 bool unit_test_mode) { | |
282 base::EnableInProcessStackDumping(); | 284 base::EnableInProcessStackDumping(); |
283 base::EnableTerminationOnHeapCorruption(); | 285 base::EnableTerminationOnHeapCorruption(); |
284 | 286 |
285 // Initialize the singleton CommandLine with fixed values. Some code refer to | 287 // Initialize the singleton CommandLine with fixed values. Some code refer to |
286 // CommandLine::ForCurrentProcess(). We don't use the actual command-line | 288 // CommandLine::ForCurrentProcess(). We don't use the actual command-line |
287 // arguments of DRT to avoid unexpected behavior change. | 289 // arguments of DRT to avoid unexpected behavior change. |
288 // | 290 // |
289 // webkit/glue/plugin/plugin_list_posix.cc checks --debug-plugin-loading. | 291 // webkit/glue/plugin/plugin_list_posix.cc checks --debug-plugin-loading. |
290 // webkit/glue/plugin/plugin_list_win.cc checks --old-wmp. | 292 // webkit/glue/plugin/plugin_list_win.cc checks --old-wmp. |
291 // If DRT needs these flags, specify them in the following kFixedArguments. | 293 // If DRT needs these flags, specify them in the following kFixedArguments. |
292 const char* kFixedArguments[] = {"DumpRenderTree"}; | 294 const char* kFixedArguments[] = {"DumpRenderTree"}; |
293 CommandLine::Init(arraysize(kFixedArguments), kFixedArguments); | 295 CommandLine::Init(arraysize(kFixedArguments), kFixedArguments); |
294 | 296 |
295 // Explicitly initialize the GURL library before spawning any threads. | 297 // Explicitly initialize the GURL library before spawning any threads. |
296 // Otherwise crash may happend when different threads try to create a GURL | 298 // Otherwise crash may happend when different threads try to create a GURL |
297 // at same time. | 299 // at same time. |
298 url_util::Initialize(); | 300 url_util::Initialize(); |
299 base::AtExitManager* at_exit_manager = NULL; | 301 base::AtExitManager* at_exit_manager = NULL; |
300 // In Android DumpRenderTree, AtExitManager is created in | 302 // In Android DumpRenderTree, AtExitManager is created in |
301 // testing/android/native_test_wrapper.cc before main() is called. | 303 // testing/android/native_test_wrapper.cc before main() is called. |
302 #if !defined(OS_ANDROID) | 304 #if !defined(OS_ANDROID) |
303 // Some initialization code may use a AtExitManager before initializing | 305 // Some initialization code may use a AtExitManager before initializing |
304 // TestEnvironment, so we create a AtExitManager early and pass its ownership | 306 // TestEnvironment, so we create a AtExitManager early and pass its ownership |
305 // to TestEnvironment. | 307 // to TestEnvironment. |
306 if (!unit_test_mode) | 308 if (!unit_test_mode) |
307 at_exit_manager = new base::AtExitManager; | 309 at_exit_manager = new base::AtExitManager; |
308 #endif | 310 #endif |
309 webkit_support::BeforeInitialize(unit_test_mode); | 311 webkit_support::BeforeInitialize(unit_test_mode); |
310 test_environment = new TestEnvironment(unit_test_mode, at_exit_manager); | 312 test_environment = |
313 new TestEnvironment(unit_test_mode, at_exit_manager, callback); | |
311 webkit_support::AfterInitialize(unit_test_mode); | 314 webkit_support::AfterInitialize(unit_test_mode); |
312 if (!unit_test_mode) { | 315 if (!unit_test_mode) { |
313 // Load ICU data tables. This has to run after TestEnvironment is created | 316 // Load ICU data tables. This has to run after TestEnvironment is created |
314 // because on Linux, we need base::AtExitManager. | 317 // because on Linux, we need base::AtExitManager. |
315 icu_util::Initialize(); | 318 icu_util::Initialize(); |
316 } | 319 } |
317 webkit_glue::SetUserAgent(webkit_glue::BuildUserAgentFromProduct( | 320 webkit_glue::SetUserAgent(webkit_glue::BuildUserAgentFromProduct( |
318 "DumpRenderTree/0.0.0.0"), false); | 321 "DumpRenderTree/0.0.0.0"), false); |
319 } | 322 } |
320 | 323 |
321 } // namespace | 324 } // namespace |
322 | 325 |
323 namespace webkit_support { | 326 namespace webkit_support { |
324 | 327 |
328 TestWebKitPlatformSupport* | |
329 CreateDefaultTestWebKitPlatformSupport(bool unit_test_mode) { | |
330 return new TestWebKitPlatformSupport(unit_test_mode); | |
331 } | |
332 | |
325 void SetUpTestEnvironment() { | 333 void SetUpTestEnvironment() { |
326 SetUpTestEnvironmentImpl(false); | 334 SetUpTestEnvironment(CreateDefaultTestWebKitPlatformSupport); |
tommi (sloooow) - chröme
2012/07/10 09:48:37
SetUpTestEnvironment(&CreateDefaultTestWebKitPlatf
Tommy Widenflycht
2012/07/10 09:58:10
Done.
| |
327 } | 335 } |
328 | 336 |
329 void SetUpTestEnvironmentForUnitTests() { | 337 void SetUpTestEnvironmentForUnitTests() { |
330 SetUpTestEnvironmentImpl(true); | 338 SetUpTestEnvironmentForUnitTests(CreateDefaultTestWebKitPlatformSupport); |
tommi (sloooow) - chröme
2012/07/10 09:48:37
missing &
Tommy Widenflycht
2012/07/10 09:58:10
Done.
| |
339 } | |
340 | |
341 void SetUpTestEnvironment(PlatformSupportCreatorCallback callback) { | |
342 CHECK(callback); | |
343 SetUpTestEnvironmentImpl(callback, false); | |
344 } | |
345 | |
346 void SetUpTestEnvironmentForUnitTests(PlatformSupportCreatorCallback callback) { | |
347 CHECK(callback); | |
348 SetUpTestEnvironmentImpl(callback, true); | |
331 } | 349 } |
332 | 350 |
333 void TearDownTestEnvironment() { | 351 void TearDownTestEnvironment() { |
334 // Flush any remaining messages before we kill ourselves. | 352 // Flush any remaining messages before we kill ourselves. |
335 // http://code.google.com/p/chromium/issues/detail?id=9500 | 353 // http://code.google.com/p/chromium/issues/detail?id=9500 |
336 MessageLoop::current()->RunAllPending(); | 354 MessageLoop::current()->RunAllPending(); |
337 | 355 |
338 BeforeShutdown(); | 356 BeforeShutdown(); |
339 if (RunningOnValgrind()) | 357 if (RunningOnValgrind()) |
340 WebKit::WebCache::clear(); | 358 WebKit::WebCache::clear(); |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
803 // Logging | 821 // Logging |
804 void EnableWebCoreLogChannels(const std::string& channels) { | 822 void EnableWebCoreLogChannels(const std::string& channels) { |
805 webkit_glue::EnableWebCoreLogChannels(channels); | 823 webkit_glue::EnableWebCoreLogChannels(channels); |
806 } | 824 } |
807 | 825 |
808 void SetGamepadData(const WebKit::WebGamepads& pads) { | 826 void SetGamepadData(const WebKit::WebGamepads& pads) { |
809 test_environment->webkit_platform_support()->setGamepadData(pads); | 827 test_environment->webkit_platform_support()->setGamepadData(pads); |
810 } | 828 } |
811 | 829 |
812 } // namespace webkit_support | 830 } // namespace webkit_support |
OLD | NEW |