Index: content/test/content_test_suite.cc |
diff --git a/content/test/content_test_suite.cc b/content/test/content_test_suite.cc |
index 116bd0ce472064bf8445bc610e3bafd172f4f860..b7fab5bc77f15a7a55a01fa675ddf83a0971c683 100644 |
--- a/content/test/content_test_suite.cc |
+++ b/content/test/content_test_suite.cc |
@@ -35,6 +35,14 @@ |
#include "content/browser/android/in_process_surface_texture_manager.h" |
#endif |
+#if defined(USE_OZONE) |
+#include "base/bind.h" |
+#include "base/synchronization/waitable_event.h" |
+#include "base/threading/thread.h" |
+#include "ui/ozone/public/ozone_gpu_test_helper.h" |
+#include "ui/ozone/public/ozone_platform.h" |
+#endif |
+ |
namespace content { |
namespace { |
@@ -60,6 +68,20 @@ class TestInitializationListener : public testing::EmptyTestEventListener { |
} // namespace |
+#if defined(USE_OZONE) |
+struct ContentTestSuite::Impl { |
+ Impl() |
+ : ui_thread_("TestUIThread"), |
+ gpu_ipc_thread_("TestGpuIpcThread"), |
+ gpu_helper_(new ui::OzoneGpuTestHelper) {} |
+ // On Ozone, the backend requires task runner. |
+ base::MessageLoopForUI message_loop_; |
+ base::Thread ui_thread_; |
+ base::Thread gpu_ipc_thread_; |
+ scoped_ptr<ui::OzoneGpuTestHelper> gpu_helper_; |
vignatti (out of this project)
2015/06/24 22:16:17
would be better if we had the full GPU service in
dshwang
2015/06/25 05:38:40
reveman, what do you think about vignatti's opinio
|
+}; |
+#endif |
+ |
ContentTestSuite::ContentTestSuite(int argc, char** argv) |
: ContentTestSuiteBase(argc, argv) { |
} |
@@ -67,6 +89,17 @@ ContentTestSuite::ContentTestSuite(int argc, char** argv) |
ContentTestSuite::~ContentTestSuite() { |
} |
+#if defined(USE_OZONE) |
+void InitializeUI(base::WaitableEvent* done) { |
+ ui::OzonePlatform::InitializeForUI(); |
+ done->Signal(); |
+} |
+ |
+void Noop(base::WaitableEvent* done) { |
+ done->Signal(); |
+} |
+#endif |
+ |
void ContentTestSuite::Initialize() { |
#if defined(OS_MACOSX) |
base::mac::ScopedNSAutoreleasePool autorelease_pool; |
@@ -79,6 +112,22 @@ void ContentTestSuite::Initialize() { |
gfx::InitDeviceScaleFactor(1.0f); |
#endif |
+ bool is_child_process = base::CommandLine::ForCurrentProcess()->HasSwitch( |
+ switches::kTestChildProcess); |
+#if defined(USE_OZONE) |
+ if (!is_child_process) { |
+ ozone_impl_.reset(new Impl()); |
+ ozone_impl_->ui_thread_.Start(); |
+ |
+ { |
+ base::WaitableEvent done(false, false); |
+ ozone_impl_->ui_thread_.task_runner()->PostTask( |
+ FROM_HERE, base::Bind(&InitializeUI, &done)); |
+ done.Wait(); |
+ } |
+ } |
+#endif |
+ |
ContentTestSuiteBase::Initialize(); |
{ |
ContentClient client; |
@@ -89,8 +138,8 @@ void ContentTestSuite::Initialize() { |
media::InitializeMediaLibrary(); |
// When running in a child process for Mac sandbox tests, the sandbox exists |
// to initialize GL, so don't do it here. |
- if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
- switches::kTestChildProcess)) { |
+ if (!is_child_process) { |
+ // This thread is kind of GPU main thread. |
gfx::GLSurface::InitializeOneOffForTests(); |
gpu::ApplyGpuDriverBugWorkarounds(base::CommandLine::ForCurrentProcess()); |
} |
@@ -105,6 +154,25 @@ void ContentTestSuite::Initialize() { |
#if defined(OS_MACOSX) && !defined(OS_IOS) |
IOSurfaceManager::SetInstance(InProcessIOSurfaceManager::GetInstance()); |
#endif |
+#if defined(USE_OZONE) |
+ if (!is_child_process) { |
+ // Separate GPU main thread (i.e. this thread) and GPU IPC thread because we |
+ // must wait for all IPC for initialization done. Note here and each |
+ // unittest are on the same stack, so there is no way to handle IPC before |
+ // running each unittest. |
+ ozone_impl_->gpu_ipc_thread_.Start(); |
+ ozone_impl_->gpu_helper_->Initialize( |
+ ozone_impl_->ui_thread_.task_runner(), |
+ ozone_impl_->gpu_ipc_thread_.task_runner()); |
+ { |
+ base::WaitableEvent done(false, false); |
+ ozone_impl_->gpu_ipc_thread_.task_runner()->PostTask( |
+ FROM_HERE, base::Bind(&Noop, &done)); |
+ // Wait for all IPC for initialization done |
+ done.Wait(); |
+ } |
+ } |
+#endif |
} |
} // namespace content |