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 "chrome/common/service_process_util.h" | 5 #include "chrome/common/service_process_util.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 ASSERT_TRUE(state.Initialize()); | 178 ASSERT_TRUE(state.Initialize()); |
179 ASSERT_TRUE(GetServiceProcessData(&version, &pid)); | 179 ASSERT_TRUE(GetServiceProcessData(&version, &pid)); |
180 ASSERT_EQ(base::GetCurrentProcId(), pid); | 180 ASSERT_EQ(base::GetCurrentProcId(), pid); |
181 } | 181 } |
182 | 182 |
183 TEST_F(ServiceProcessStateTest, MAYBE_ForceShutdown) { | 183 TEST_F(ServiceProcessStateTest, MAYBE_ForceShutdown) { |
184 base::ProcessHandle handle = SpawnChild("ServiceProcessStateTestShutdown", | 184 base::ProcessHandle handle = SpawnChild("ServiceProcessStateTestShutdown", |
185 true); | 185 true); |
186 ASSERT_TRUE(handle); | 186 ASSERT_TRUE(handle); |
187 for (int i = 0; !CheckServiceProcessReady() && i < 10; ++i) { | 187 for (int i = 0; !CheckServiceProcessReady() && i < 10; ++i) { |
188 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout_ms()); | 188 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); |
189 } | 189 } |
190 ASSERT_TRUE(CheckServiceProcessReady()); | 190 ASSERT_TRUE(CheckServiceProcessReady()); |
191 std::string version; | 191 std::string version; |
192 base::ProcessId pid; | 192 base::ProcessId pid; |
193 ASSERT_TRUE(GetServiceProcessData(&version, &pid)); | 193 ASSERT_TRUE(GetServiceProcessData(&version, &pid)); |
194 ASSERT_TRUE(ForceServiceProcessShutdown(version, pid)); | 194 ASSERT_TRUE(ForceServiceProcessShutdown(version, pid)); |
195 int exit_code = 0; | 195 int exit_code = 0; |
196 ASSERT_TRUE(base::WaitForExitCodeWithTimeout(handle, | 196 ASSERT_TRUE(base::WaitForExitCodeWithTimeout(handle, |
197 &exit_code, TestTimeouts::action_max_timeout_ms())); | 197 &exit_code, TestTimeouts::action_max_timeout_ms())); |
198 base::CloseProcessHandle(handle); | 198 base::CloseProcessHandle(handle); |
(...skipping 22 matching lines...) Expand all Loading... |
221 base::Thread io_thread_("ServiceProcessStateTestShutdownIOThread"); | 221 base::Thread io_thread_("ServiceProcessStateTestShutdownIOThread"); |
222 base::Thread::Options options(MessageLoop::TYPE_IO, 0); | 222 base::Thread::Options options(MessageLoop::TYPE_IO, 0); |
223 EXPECT_TRUE(io_thread_.StartWithOptions(options)); | 223 EXPECT_TRUE(io_thread_.StartWithOptions(options)); |
224 ServiceProcessState state; | 224 ServiceProcessState state; |
225 EXPECT_TRUE(state.Initialize()); | 225 EXPECT_TRUE(state.Initialize()); |
226 EXPECT_TRUE(state.SignalReady(io_thread_.message_loop_proxy(), | 226 EXPECT_TRUE(state.SignalReady(io_thread_.message_loop_proxy(), |
227 base::Bind(&ShutdownTask, | 227 base::Bind(&ShutdownTask, |
228 MessageLoop::current()))); | 228 MessageLoop::current()))); |
229 message_loop.PostDelayedTask(FROM_HERE, | 229 message_loop.PostDelayedTask(FROM_HERE, |
230 MessageLoop::QuitClosure(), | 230 MessageLoop::QuitClosure(), |
231 TestTimeouts::action_max_timeout_ms()); | 231 TestTimeouts::action_max_timeout()); |
232 EXPECT_FALSE(g_good_shutdown); | 232 EXPECT_FALSE(g_good_shutdown); |
233 message_loop.Run(); | 233 message_loop.Run(); |
234 EXPECT_TRUE(g_good_shutdown); | 234 EXPECT_TRUE(g_good_shutdown); |
235 return 0; | 235 return 0; |
236 } | 236 } |
237 | 237 |
238 #else // !OS_MACOSX | 238 #else // !OS_MACOSX |
239 | 239 |
240 #include <CoreFoundation/CoreFoundation.h> | 240 #include <CoreFoundation/CoreFoundation.h> |
241 | 241 |
(...skipping 25 matching lines...) Expand all Loading... |
267 &executable_path_)); | 267 &executable_path_)); |
268 mock_launchd_.reset(new MockLaunchd(executable_path_, &loop_)); | 268 mock_launchd_.reset(new MockLaunchd(executable_path_, &loop_)); |
269 scoped_launchd_instance_.reset( | 269 scoped_launchd_instance_.reset( |
270 new Launchd::ScopedInstance(mock_launchd_.get())); | 270 new Launchd::ScopedInstance(mock_launchd_.get())); |
271 ASSERT_TRUE(service_process_state_.Initialize()); | 271 ASSERT_TRUE(service_process_state_.Initialize()); |
272 ASSERT_TRUE(service_process_state_.SignalReady( | 272 ASSERT_TRUE(service_process_state_.SignalReady( |
273 io_thread_.message_loop_proxy(), | 273 io_thread_.message_loop_proxy(), |
274 base::Closure())); | 274 base::Closure())); |
275 loop_.PostDelayedTask(FROM_HERE, | 275 loop_.PostDelayedTask(FROM_HERE, |
276 MessageLoop::QuitClosure(), | 276 MessageLoop::QuitClosure(), |
277 TestTimeouts::action_max_timeout_ms()); | 277 TestTimeouts::action_max_timeout()); |
278 } | 278 } |
279 | 279 |
280 const MockLaunchd* mock_launchd() const { return mock_launchd_.get(); } | 280 const MockLaunchd* mock_launchd() const { return mock_launchd_.get(); } |
281 const FilePath& executable_path() const { return executable_path_; } | 281 const FilePath& executable_path() const { return executable_path_; } |
282 const FilePath& bundle_path() const { return bundle_path_; } | 282 const FilePath& bundle_path() const { return bundle_path_; } |
283 const FilePath& GetTempDirPath() const { return temp_dir_.path(); } | 283 const FilePath& GetTempDirPath() const { return temp_dir_.path(); } |
284 | 284 |
285 base::MessageLoopProxy* GetIOMessageLoopProxy() { | 285 base::MessageLoopProxy* GetIOMessageLoopProxy() { |
286 return io_thread_.message_loop_proxy().get(); | 286 return io_thread_.message_loop_proxy().get(); |
287 } | 287 } |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 ScopedAttributesRestorer restorer(bundle_path(), 0777); | 408 ScopedAttributesRestorer restorer(bundle_path(), 0777); |
409 GetIOMessageLoopProxy()->PostTask( | 409 GetIOMessageLoopProxy()->PostTask( |
410 FROM_HERE, | 410 FROM_HERE, |
411 base::Bind(&ChangeAttr, bundle_path(), 0222)); | 411 base::Bind(&ChangeAttr, bundle_path(), 0222)); |
412 Run(); | 412 Run(); |
413 ASSERT_TRUE(mock_launchd()->remove_called()); | 413 ASSERT_TRUE(mock_launchd()->remove_called()); |
414 ASSERT_TRUE(mock_launchd()->delete_called()); | 414 ASSERT_TRUE(mock_launchd()->delete_called()); |
415 } | 415 } |
416 | 416 |
417 #endif // !OS_MACOSX | 417 #endif // !OS_MACOSX |
OLD | NEW |