| 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/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 87 |
| 88 ServiceProcessStateTest::~ServiceProcessStateTest() { | 88 ServiceProcessStateTest::~ServiceProcessStateTest() { |
| 89 } | 89 } |
| 90 | 90 |
| 91 void ServiceProcessStateTest::SetUp() { | 91 void ServiceProcessStateTest::SetUp() { |
| 92 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0); | 92 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0); |
| 93 ASSERT_TRUE(io_thread_.StartWithOptions(options)); | 93 ASSERT_TRUE(io_thread_.StartWithOptions(options)); |
| 94 } | 94 } |
| 95 | 95 |
| 96 void ServiceProcessStateTest::LaunchAndWait(const std::string& name) { | 96 void ServiceProcessStateTest::LaunchAndWait(const std::string& name) { |
| 97 base::ProcessHandle handle = SpawnChild(name); | 97 base::Process process = SpawnChild(name); |
| 98 ASSERT_TRUE(handle); | 98 ASSERT_TRUE(process.IsValid()); |
| 99 int exit_code = 0; | 99 int exit_code = 0; |
| 100 ASSERT_TRUE(base::WaitForExitCode(handle, &exit_code)); | 100 ASSERT_TRUE(process.WaitForExit(&exit_code)); |
| 101 ASSERT_EQ(exit_code, 0); | 101 ASSERT_EQ(exit_code, 0); |
| 102 } | 102 } |
| 103 | 103 |
| 104 TEST_F(ServiceProcessStateTest, Singleton) { | 104 TEST_F(ServiceProcessStateTest, Singleton) { |
| 105 ServiceProcessState state; | 105 ServiceProcessState state; |
| 106 ASSERT_TRUE(state.Initialize()); | 106 ASSERT_TRUE(state.Initialize()); |
| 107 LaunchAndWait("ServiceProcessStateTestSingleton"); | 107 LaunchAndWait("ServiceProcessStateTestSingleton"); |
| 108 } | 108 } |
| 109 | 109 |
| 110 // http://crbug.com/396390 | 110 // http://crbug.com/396390 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 // implementation on Posix, this check will only execute on Windows. | 180 // implementation on Posix, this check will only execute on Windows. |
| 181 ASSERT_FALSE(GetServiceProcessData(&version, &pid)); | 181 ASSERT_FALSE(GetServiceProcessData(&version, &pid)); |
| 182 #endif // defined(OS_WIN) | 182 #endif // defined(OS_WIN) |
| 183 ServiceProcessState state; | 183 ServiceProcessState state; |
| 184 ASSERT_TRUE(state.Initialize()); | 184 ASSERT_TRUE(state.Initialize()); |
| 185 ASSERT_TRUE(GetServiceProcessData(&version, &pid)); | 185 ASSERT_TRUE(GetServiceProcessData(&version, &pid)); |
| 186 ASSERT_EQ(base::GetCurrentProcId(), pid); | 186 ASSERT_EQ(base::GetCurrentProcId(), pid); |
| 187 } | 187 } |
| 188 | 188 |
| 189 TEST_F(ServiceProcessStateTest, MAYBE_ForceShutdown) { | 189 TEST_F(ServiceProcessStateTest, MAYBE_ForceShutdown) { |
| 190 base::ProcessHandle handle = SpawnChild("ServiceProcessStateTestShutdown"); | 190 base::Process process = SpawnChild("ServiceProcessStateTestShutdown"); |
| 191 ASSERT_TRUE(handle); | 191 ASSERT_TRUE(process.IsValid()); |
| 192 for (int i = 0; !CheckServiceProcessReady() && i < 10; ++i) { | 192 for (int i = 0; !CheckServiceProcessReady() && i < 10; ++i) { |
| 193 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); | 193 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); |
| 194 } | 194 } |
| 195 ASSERT_TRUE(CheckServiceProcessReady()); | 195 ASSERT_TRUE(CheckServiceProcessReady()); |
| 196 std::string version; | 196 std::string version; |
| 197 base::ProcessId pid; | 197 base::ProcessId pid; |
| 198 ASSERT_TRUE(GetServiceProcessData(&version, &pid)); | 198 ASSERT_TRUE(GetServiceProcessData(&version, &pid)); |
| 199 ASSERT_TRUE(ForceServiceProcessShutdown(version, pid)); | 199 ASSERT_TRUE(ForceServiceProcessShutdown(version, pid)); |
| 200 int exit_code = 0; | 200 int exit_code = 0; |
| 201 ASSERT_TRUE(base::WaitForExitCodeWithTimeout(handle, | 201 ASSERT_TRUE(process.WaitForExitWithTimeout(TestTimeouts::action_max_timeout(), |
| 202 &exit_code, TestTimeouts::action_max_timeout())); | 202 &exit_code)); |
| 203 base::CloseProcessHandle(handle); | |
| 204 ASSERT_EQ(exit_code, 0); | 203 ASSERT_EQ(exit_code, 0); |
| 205 } | 204 } |
| 206 | 205 |
| 207 MULTIPROCESS_TEST_MAIN(ServiceProcessStateTestSingleton) { | 206 MULTIPROCESS_TEST_MAIN(ServiceProcessStateTestSingleton) { |
| 208 ServiceProcessState state; | 207 ServiceProcessState state; |
| 209 EXPECT_FALSE(state.Initialize()); | 208 EXPECT_FALSE(state.Initialize()); |
| 210 return 0; | 209 return 0; |
| 211 } | 210 } |
| 212 | 211 |
| 213 MULTIPROCESS_TEST_MAIN(ServiceProcessStateTestReadyTrue) { | 212 MULTIPROCESS_TEST_MAIN(ServiceProcessStateTestReadyTrue) { |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 ScopedAttributesRestorer restorer(bundle_path(), 0777); | 415 ScopedAttributesRestorer restorer(bundle_path(), 0777); |
| 417 GetIOMessageLoopProxy()->PostTask( | 416 GetIOMessageLoopProxy()->PostTask( |
| 418 FROM_HERE, | 417 FROM_HERE, |
| 419 base::Bind(&ChangeAttr, bundle_path(), 0222)); | 418 base::Bind(&ChangeAttr, bundle_path(), 0222)); |
| 420 Run(); | 419 Run(); |
| 421 ASSERT_TRUE(mock_launchd()->remove_called()); | 420 ASSERT_TRUE(mock_launchd()->remove_called()); |
| 422 ASSERT_TRUE(mock_launchd()->delete_called()); | 421 ASSERT_TRUE(mock_launchd()->delete_called()); |
| 423 } | 422 } |
| 424 | 423 |
| 425 #endif // !OS_MACOSX | 424 #endif // !OS_MACOSX |
| OLD | NEW |