Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Side by Side Diff: content/test/content_test_suite.cc

Issue 1208603002: content: implement unittests backend for Ozone GBM Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/test/content_test_suite.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "content/test/content_test_suite.h" 5 #include "content/test/content_test_suite.h"
6 6
7 #include "base/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "content/public/common/content_client.h" 9 #include "content/public/common/content_client.h"
10 #include "content/public/common/content_paths.h" 10 #include "content/public/common/content_paths.h"
(...skipping 17 matching lines...) Expand all
28 #include "base/base_switches.h" 28 #include "base/base_switches.h"
29 #include "base/command_line.h" 29 #include "base/command_line.h"
30 #include "media/base/media.h" 30 #include "media/base/media.h"
31 #include "ui/gl/gl_surface.h" 31 #include "ui/gl/gl_surface.h"
32 #endif 32 #endif
33 33
34 #if defined(OS_ANDROID) 34 #if defined(OS_ANDROID)
35 #include "content/browser/android/in_process_surface_texture_manager.h" 35 #include "content/browser/android/in_process_surface_texture_manager.h"
36 #endif 36 #endif
37 37
38 #if defined(USE_OZONE)
39 #include "base/bind.h"
40 #include "base/synchronization/waitable_event.h"
41 #include "base/threading/thread.h"
42 #include "ui/ozone/public/ozone_gpu_test_helper.h"
43 #include "ui/ozone/public/ozone_platform.h"
44 #endif
45
38 namespace content { 46 namespace content {
39 namespace { 47 namespace {
40 48
41 class TestInitializationListener : public testing::EmptyTestEventListener { 49 class TestInitializationListener : public testing::EmptyTestEventListener {
42 public: 50 public:
43 TestInitializationListener() : test_content_client_initializer_(NULL) { 51 TestInitializationListener() : test_content_client_initializer_(NULL) {
44 } 52 }
45 53
46 void OnTestStart(const testing::TestInfo& test_info) override { 54 void OnTestStart(const testing::TestInfo& test_info) override {
47 test_content_client_initializer_ = 55 test_content_client_initializer_ =
48 new content::TestContentClientInitializer(); 56 new content::TestContentClientInitializer();
49 } 57 }
50 58
51 void OnTestEnd(const testing::TestInfo& test_info) override { 59 void OnTestEnd(const testing::TestInfo& test_info) override {
52 delete test_content_client_initializer_; 60 delete test_content_client_initializer_;
53 } 61 }
54 62
55 private: 63 private:
56 content::TestContentClientInitializer* test_content_client_initializer_; 64 content::TestContentClientInitializer* test_content_client_initializer_;
57 65
58 DISALLOW_COPY_AND_ASSIGN(TestInitializationListener); 66 DISALLOW_COPY_AND_ASSIGN(TestInitializationListener);
59 }; 67 };
60 68
61 } // namespace 69 } // namespace
62 70
71 #if defined(USE_OZONE)
72 struct ContentTestSuite::Impl {
73 Impl()
74 : ui_thread_("TestUIThread"),
75 gpu_ipc_thread_("TestGpuIpcThread"),
76 gpu_helper_(new ui::OzoneGpuTestHelper) {}
77 // On Ozone, the backend requires task runner.
78 base::MessageLoopForUI message_loop_;
79 base::Thread ui_thread_;
80 base::Thread gpu_ipc_thread_;
81 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
82 };
83 #endif
84
63 ContentTestSuite::ContentTestSuite(int argc, char** argv) 85 ContentTestSuite::ContentTestSuite(int argc, char** argv)
64 : ContentTestSuiteBase(argc, argv) { 86 : ContentTestSuiteBase(argc, argv) {
65 } 87 }
66 88
67 ContentTestSuite::~ContentTestSuite() { 89 ContentTestSuite::~ContentTestSuite() {
68 } 90 }
69 91
92 #if defined(USE_OZONE)
93 void InitializeUI(base::WaitableEvent* done) {
94 ui::OzonePlatform::InitializeForUI();
95 done->Signal();
96 }
97
98 void Noop(base::WaitableEvent* done) {
99 done->Signal();
100 }
101 #endif
102
70 void ContentTestSuite::Initialize() { 103 void ContentTestSuite::Initialize() {
71 #if defined(OS_MACOSX) 104 #if defined(OS_MACOSX)
72 base::mac::ScopedNSAutoreleasePool autorelease_pool; 105 base::mac::ScopedNSAutoreleasePool autorelease_pool;
73 #if !defined(OS_IOS) 106 #if !defined(OS_IOS)
74 mock_cr_app::RegisterMockCrApp(); 107 mock_cr_app::RegisterMockCrApp();
75 #endif 108 #endif
76 #endif 109 #endif
77 110
78 #if defined(OS_WIN) 111 #if defined(OS_WIN)
79 gfx::InitDeviceScaleFactor(1.0f); 112 gfx::InitDeviceScaleFactor(1.0f);
80 #endif 113 #endif
81 114
115 bool is_child_process = base::CommandLine::ForCurrentProcess()->HasSwitch(
116 switches::kTestChildProcess);
117 #if defined(USE_OZONE)
118 if (!is_child_process) {
119 ozone_impl_.reset(new Impl());
120 ozone_impl_->ui_thread_.Start();
121
122 {
123 base::WaitableEvent done(false, false);
124 ozone_impl_->ui_thread_.task_runner()->PostTask(
125 FROM_HERE, base::Bind(&InitializeUI, &done));
126 done.Wait();
127 }
128 }
129 #endif
130
82 ContentTestSuiteBase::Initialize(); 131 ContentTestSuiteBase::Initialize();
83 { 132 {
84 ContentClient client; 133 ContentClient client;
85 ContentTestSuiteBase::RegisterContentSchemes(&client); 134 ContentTestSuiteBase::RegisterContentSchemes(&client);
86 } 135 }
87 RegisterPathProvider(); 136 RegisterPathProvider();
88 #if !defined(OS_IOS) 137 #if !defined(OS_IOS)
89 media::InitializeMediaLibrary(); 138 media::InitializeMediaLibrary();
90 // When running in a child process for Mac sandbox tests, the sandbox exists 139 // When running in a child process for Mac sandbox tests, the sandbox exists
91 // to initialize GL, so don't do it here. 140 // to initialize GL, so don't do it here.
92 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 141 if (!is_child_process) {
93 switches::kTestChildProcess)) { 142 // This thread is kind of GPU main thread.
94 gfx::GLSurface::InitializeOneOffForTests(); 143 gfx::GLSurface::InitializeOneOffForTests();
95 gpu::ApplyGpuDriverBugWorkarounds(base::CommandLine::ForCurrentProcess()); 144 gpu::ApplyGpuDriverBugWorkarounds(base::CommandLine::ForCurrentProcess());
96 } 145 }
97 #endif 146 #endif
98 testing::TestEventListeners& listeners = 147 testing::TestEventListeners& listeners =
99 testing::UnitTest::GetInstance()->listeners(); 148 testing::UnitTest::GetInstance()->listeners();
100 listeners.Append(new TestInitializationListener); 149 listeners.Append(new TestInitializationListener);
101 #if defined(OS_ANDROID) 150 #if defined(OS_ANDROID)
102 SurfaceTextureManager::SetInstance( 151 SurfaceTextureManager::SetInstance(
103 InProcessSurfaceTextureManager::GetInstance()); 152 InProcessSurfaceTextureManager::GetInstance());
104 #endif 153 #endif
105 #if defined(OS_MACOSX) && !defined(OS_IOS) 154 #if defined(OS_MACOSX) && !defined(OS_IOS)
106 IOSurfaceManager::SetInstance(InProcessIOSurfaceManager::GetInstance()); 155 IOSurfaceManager::SetInstance(InProcessIOSurfaceManager::GetInstance());
107 #endif 156 #endif
157 #if defined(USE_OZONE)
158 if (!is_child_process) {
159 // Separate GPU main thread (i.e. this thread) and GPU IPC thread because we
160 // must wait for all IPC for initialization done. Note here and each
161 // unittest are on the same stack, so there is no way to handle IPC before
162 // running each unittest.
163 ozone_impl_->gpu_ipc_thread_.Start();
164 ozone_impl_->gpu_helper_->Initialize(
165 ozone_impl_->ui_thread_.task_runner(),
166 ozone_impl_->gpu_ipc_thread_.task_runner());
167 {
168 base::WaitableEvent done(false, false);
169 ozone_impl_->gpu_ipc_thread_.task_runner()->PostTask(
170 FROM_HERE, base::Bind(&Noop, &done));
171 // Wait for all IPC for initialization done
172 done.Wait();
173 }
174 }
175 #endif
108 } 176 }
109 177
110 } // namespace content 178 } // namespace content
OLDNEW
« no previous file with comments | « content/test/content_test_suite.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698