| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/test/blink_test_environment.h" | 5 #include "content/test/blink_test_environment.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/strings/string_tokenizer.h" | 12 #include "base/strings/string_tokenizer.h" |
| 13 #include "base/test/scoped_async_task_scheduler.h" | |
| 14 #include "base/test/test_discardable_memory_allocator.h" | 13 #include "base/test/test_discardable_memory_allocator.h" |
| 15 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 14 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
| 16 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 17 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
| 18 #include "content/public/common/user_agent.h" | 17 #include "content/public/common/user_agent.h" |
| 19 #include "content/public/test/test_content_client_initializer.h" | 18 #include "content/public/test/test_content_client_initializer.h" |
| 20 #include "content/test/test_blink_web_unit_test_support.h" | 19 #include "content/test/test_blink_web_unit_test_support.h" |
| 21 #include "third_party/WebKit/public/platform/WebCache.h" | 20 #include "third_party/WebKit/public/platform/WebCache.h" |
| 22 #include "third_party/WebKit/public/web/WebKit.h" | 21 #include "third_party/WebKit/public/web/WebKit.h" |
| 23 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 22 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
| 24 #include "url/url_util.h" | 23 #include "url/url_util.h" |
| 25 | 24 |
| 26 #if defined(OS_WIN) | 25 #if defined(OS_WIN) |
| 27 #include "ui/display/win/dpi.h" | 26 #include "ui/display/win/dpi.h" |
| 28 #endif | 27 #endif |
| 29 | 28 |
| 30 #if defined(OS_MACOSX) | 29 #if defined(OS_MACOSX) |
| 31 #include "base/test/mock_chrome_application_mac.h" | 30 #include "base/test/mock_chrome_application_mac.h" |
| 32 #endif | 31 #endif |
| 33 | 32 |
| 34 namespace content { | 33 namespace content { |
| 35 | 34 |
| 36 namespace { | 35 namespace { |
| 37 | 36 |
| 38 class TestEnvironment { | 37 class TestEnvironment { |
| 39 public: | 38 public: |
| 39 #if defined(OS_ANDROID) |
| 40 // Android UI message loop goes through Java, so don't use it in tests. |
| 41 typedef base::MessageLoop MessageLoopType; |
| 42 #else |
| 43 typedef base::MessageLoopForUI MessageLoopType; |
| 44 #endif |
| 45 |
| 40 TestEnvironment() { | 46 TestEnvironment() { |
| 41 // TestBlinkWebUnitTestSupport must be instantiated after the main | 47 main_message_loop_.reset(new MessageLoopType); |
| 42 // MessageLoop. | 48 |
| 49 // TestBlinkWebUnitTestSupport must be instantiated after MessageLoopType. |
| 43 blink_test_support_.reset(new TestBlinkWebUnitTestSupport); | 50 blink_test_support_.reset(new TestBlinkWebUnitTestSupport); |
| 44 content_initializer_.reset(new content::TestContentClientInitializer()); | 51 content_initializer_.reset(new content::TestContentClientInitializer()); |
| 45 | 52 |
| 46 base::DiscardableMemoryAllocator::SetInstance( | 53 base::DiscardableMemoryAllocator::SetInstance( |
| 47 &discardable_memory_allocator_); | 54 &discardable_memory_allocator_); |
| 48 } | 55 } |
| 49 | 56 |
| 50 ~TestEnvironment() { | 57 ~TestEnvironment() { |
| 51 } | 58 } |
| 52 | 59 |
| 53 TestBlinkWebUnitTestSupport* blink_platform_impl() const { | 60 TestBlinkWebUnitTestSupport* blink_platform_impl() const { |
| 54 return blink_test_support_.get(); | 61 return blink_test_support_.get(); |
| 55 } | 62 } |
| 56 | 63 |
| 57 private: | 64 private: |
| 58 #if defined(OS_ANDROID) | 65 std::unique_ptr<MessageLoopType> main_message_loop_; |
| 59 // Android UI message loop goes through Java, so don't use it in tests. | |
| 60 base::MessageLoop main_message_loop_; | |
| 61 #else | |
| 62 base::MessageLoopForUI main_message_loop_; | |
| 63 #endif | |
| 64 | |
| 65 // Required by gin::V8Platform::CallOnBackgroundThread(). Can't be a | |
| 66 // ScopedTaskScheduler because v8 synchronously waits for tasks to run. | |
| 67 base::test::ScopedAsyncTaskScheduler scoped_async_task_scheduler; | |
| 68 | |
| 69 std::unique_ptr<TestBlinkWebUnitTestSupport> blink_test_support_; | 66 std::unique_ptr<TestBlinkWebUnitTestSupport> blink_test_support_; |
| 70 std::unique_ptr<TestContentClientInitializer> content_initializer_; | 67 std::unique_ptr<TestContentClientInitializer> content_initializer_; |
| 71 base::TestDiscardableMemoryAllocator discardable_memory_allocator_; | 68 base::TestDiscardableMemoryAllocator discardable_memory_allocator_; |
| 72 }; | 69 }; |
| 73 | 70 |
| 74 TestEnvironment* test_environment; | 71 TestEnvironment* test_environment; |
| 75 | 72 |
| 76 } // namespace | 73 } // namespace |
| 77 | 74 |
| 78 void SetUpBlinkTestEnvironment() { | 75 void SetUpBlinkTestEnvironment() { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 99 // http://code.google.com/p/chromium/issues/detail?id=9500 | 96 // http://code.google.com/p/chromium/issues/detail?id=9500 |
| 100 base::RunLoop().RunUntilIdle(); | 97 base::RunLoop().RunUntilIdle(); |
| 101 | 98 |
| 102 if (RunningOnValgrind()) | 99 if (RunningOnValgrind()) |
| 103 blink::WebCache::clear(); | 100 blink::WebCache::clear(); |
| 104 delete test_environment; | 101 delete test_environment; |
| 105 test_environment = NULL; | 102 test_environment = NULL; |
| 106 } | 103 } |
| 107 | 104 |
| 108 } // namespace content | 105 } // namespace content |
| OLD | NEW |