| 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 26 matching lines...) Expand all Loading... |
| 268 mock_launchd_.reset(new MockLaunchd(executable_path_, &loop_, | 268 mock_launchd_.reset(new MockLaunchd(executable_path_, &loop_, |
| 269 false, false)); | 269 false, false)); |
| 270 scoped_launchd_instance_.reset( | 270 scoped_launchd_instance_.reset( |
| 271 new Launchd::ScopedInstance(mock_launchd_.get())); | 271 new Launchd::ScopedInstance(mock_launchd_.get())); |
| 272 ASSERT_TRUE(service_process_state_.Initialize()); | 272 ASSERT_TRUE(service_process_state_.Initialize()); |
| 273 ASSERT_TRUE(service_process_state_.SignalReady( | 273 ASSERT_TRUE(service_process_state_.SignalReady( |
| 274 io_thread_.message_loop_proxy(), | 274 io_thread_.message_loop_proxy(), |
| 275 base::Closure())); | 275 base::Closure())); |
| 276 loop_.PostDelayedTask(FROM_HERE, | 276 loop_.PostDelayedTask(FROM_HERE, |
| 277 MessageLoop::QuitClosure(), | 277 MessageLoop::QuitClosure(), |
| 278 TestTimeouts::action_max_timeout_ms()); | 278 TestTimeouts::action_max_timeout()); |
| 279 } | 279 } |
| 280 | 280 |
| 281 const MockLaunchd* mock_launchd() const { return mock_launchd_.get(); } | 281 const MockLaunchd* mock_launchd() const { return mock_launchd_.get(); } |
| 282 const FilePath& executable_path() const { return executable_path_; } | 282 const FilePath& executable_path() const { return executable_path_; } |
| 283 const FilePath& bundle_path() const { return bundle_path_; } | 283 const FilePath& bundle_path() const { return bundle_path_; } |
| 284 const FilePath& GetTempDirPath() const { return temp_dir_.path(); } | 284 const FilePath& GetTempDirPath() const { return temp_dir_.path(); } |
| 285 | 285 |
| 286 base::MessageLoopProxy* GetIOMessageLoopProxy() { | 286 base::MessageLoopProxy* GetIOMessageLoopProxy() { |
| 287 return io_thread_.message_loop_proxy().get(); | 287 return io_thread_.message_loop_proxy().get(); |
| 288 } | 288 } |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 ScopedAttributesRestorer restorer(bundle_path(), 0777); | 409 ScopedAttributesRestorer restorer(bundle_path(), 0777); |
| 410 GetIOMessageLoopProxy()->PostTask( | 410 GetIOMessageLoopProxy()->PostTask( |
| 411 FROM_HERE, | 411 FROM_HERE, |
| 412 base::Bind(&ChangeAttr, bundle_path(), 0222)); | 412 base::Bind(&ChangeAttr, bundle_path(), 0222)); |
| 413 Run(); | 413 Run(); |
| 414 ASSERT_TRUE(mock_launchd()->remove_called()); | 414 ASSERT_TRUE(mock_launchd()->remove_called()); |
| 415 ASSERT_TRUE(mock_launchd()->delete_called()); | 415 ASSERT_TRUE(mock_launchd()->delete_called()); |
| 416 } | 416 } |
| 417 | 417 |
| 418 #endif // !OS_MACOSX | 418 #endif // !OS_MACOSX |
| OLD | NEW |