OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/test/base/mojo_test_connector.h" | 5 #include "chrome/test/base/mojo_test_connector.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 // BackgroundState needs to be destroyed on the background thread. We're | 158 // BackgroundState needs to be destroyed on the background thread. We're |
159 // guaranteed |background_shell_| has been created by the time we reach | 159 // guaranteed |background_shell_| has been created by the time we reach |
160 // here as Init() blocks until |background_shell_| has been created. | 160 // here as Init() blocks until |background_shell_| has been created. |
161 background_shell_->ExecuteOnShellThread( | 161 background_shell_->ExecuteOnShellThread( |
162 base::Bind(&DestroyBackgroundStateOnBackgroundThread, | 162 base::Bind(&DestroyBackgroundStateOnBackgroundThread, |
163 base::Passed(&background_state_))); | 163 base::Passed(&background_state_))); |
164 } | 164 } |
165 | 165 |
166 void Init(base::CommandLine* command_line, | 166 void Init(base::CommandLine* command_line, |
167 base::TestLauncher::LaunchOptions* test_launch_options) { | 167 base::TestLauncher::LaunchOptions* test_launch_options) { |
168 base::WaitableEvent signal(true, false); | 168 base::WaitableEvent signal(base::WaitableEvent::ResetPolicy::MANUAL, |
| 169 base::WaitableEvent::InitialState::NOT_SIGNALED); |
169 background_shell_->ExecuteOnShellThread(base::Bind( | 170 background_shell_->ExecuteOnShellThread(base::Bind( |
170 &MojoTestState::BindOnBackgroundThread, base::Unretained(this), &signal, | 171 &MojoTestState::BindOnBackgroundThread, base::Unretained(this), &signal, |
171 command_line, test_launch_options)); | 172 command_line, test_launch_options)); |
172 signal.Wait(); | 173 signal.Wait(); |
173 } | 174 } |
174 | 175 |
175 private: | 176 private: |
176 // content::TestState: | 177 // content::TestState: |
177 void ChildProcessLaunched(base::ProcessHandle handle, | 178 void ChildProcessLaunched(base::ProcessHandle handle, |
178 base::ProcessId pid) override { | 179 base::ProcessId pid) override { |
179 // This is called on a random thread. We need to ensure BackgroundTestState | 180 // This is called on a random thread. We need to ensure BackgroundTestState |
180 // is only called on the background thread, and we wait for | 181 // is only called on the background thread, and we wait for |
181 // ChildProcessLaunchedOnBackgroundThread() to be run before continuing so | 182 // ChildProcessLaunchedOnBackgroundThread() to be run before continuing so |
182 // that |handle| is still valid. | 183 // that |handle| is still valid. |
183 base::WaitableEvent signal(true, false); | 184 base::WaitableEvent signal(base::WaitableEvent::ResetPolicy::MANUAL, |
| 185 base::WaitableEvent::InitialState::NOT_SIGNALED); |
184 background_shell_->ExecuteOnShellThread( | 186 background_shell_->ExecuteOnShellThread( |
185 base::Bind(&MojoTestState::ChildProcessLaunchedOnBackgroundThread, | 187 base::Bind(&MojoTestState::ChildProcessLaunchedOnBackgroundThread, |
186 base::Unretained(this), handle, pid, &signal)); | 188 base::Unretained(this), handle, pid, &signal)); |
187 signal.Wait(); | 189 signal.Wait(); |
188 } | 190 } |
189 | 191 |
190 void ChildProcessLaunchedOnBackgroundThread(base::ProcessHandle handle, | 192 void ChildProcessLaunchedOnBackgroundThread(base::ProcessHandle handle, |
191 base::ProcessId pid, | 193 base::ProcessId pid, |
192 base::WaitableEvent* signal, | 194 base::WaitableEvent* signal, |
193 shell::Shell* shell) { | 195 shell::Shell* shell) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 MojoTestConnector::~MojoTestConnector() {} | 238 MojoTestConnector::~MojoTestConnector() {} |
237 | 239 |
238 std::unique_ptr<content::TestState> MojoTestConnector::PrepareForTest( | 240 std::unique_ptr<content::TestState> MojoTestConnector::PrepareForTest( |
239 base::CommandLine* command_line, | 241 base::CommandLine* command_line, |
240 base::TestLauncher::LaunchOptions* test_launch_options) { | 242 base::TestLauncher::LaunchOptions* test_launch_options) { |
241 std::unique_ptr<MojoTestState> test_state( | 243 std::unique_ptr<MojoTestState> test_state( |
242 new MojoTestState(&background_shell_)); | 244 new MojoTestState(&background_shell_)); |
243 test_state->Init(command_line, test_launch_options); | 245 test_state->Init(command_line, test_launch_options); |
244 return std::move(test_state); | 246 return std::move(test_state); |
245 } | 247 } |
OLD | NEW |