| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 88 |
| 89 ServiceProcessStateTest::~ServiceProcessStateTest() { | 89 ServiceProcessStateTest::~ServiceProcessStateTest() { |
| 90 } | 90 } |
| 91 | 91 |
| 92 void ServiceProcessStateTest::SetUp() { | 92 void ServiceProcessStateTest::SetUp() { |
| 93 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0); | 93 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0); |
| 94 ASSERT_TRUE(io_thread_.StartWithOptions(options)); | 94 ASSERT_TRUE(io_thread_.StartWithOptions(options)); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void ServiceProcessStateTest::LaunchAndWait(const std::string& name) { | 97 void ServiceProcessStateTest::LaunchAndWait(const std::string& name) { |
| 98 base::ProcessHandle handle = SpawnChild(name, false); | 98 base::ProcessHandle handle = SpawnChild(name); |
| 99 ASSERT_TRUE(handle); | 99 ASSERT_TRUE(handle); |
| 100 int exit_code = 0; | 100 int exit_code = 0; |
| 101 ASSERT_TRUE(base::WaitForExitCode(handle, &exit_code)); | 101 ASSERT_TRUE(base::WaitForExitCode(handle, &exit_code)); |
| 102 ASSERT_EQ(exit_code, 0); | 102 ASSERT_EQ(exit_code, 0); |
| 103 } | 103 } |
| 104 | 104 |
| 105 TEST_F(ServiceProcessStateTest, Singleton) { | 105 TEST_F(ServiceProcessStateTest, Singleton) { |
| 106 ServiceProcessState state; | 106 ServiceProcessState state; |
| 107 ASSERT_TRUE(state.Initialize()); | 107 ASSERT_TRUE(state.Initialize()); |
| 108 LaunchAndWait("ServiceProcessStateTestSingleton"); | 108 LaunchAndWait("ServiceProcessStateTestSingleton"); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 // implementation on Posix, this check will only execute on Windows. | 178 // implementation on Posix, this check will only execute on Windows. |
| 179 ASSERT_FALSE(GetServiceProcessData(&version, &pid)); | 179 ASSERT_FALSE(GetServiceProcessData(&version, &pid)); |
| 180 #endif // defined(OS_WIN) | 180 #endif // defined(OS_WIN) |
| 181 ServiceProcessState state; | 181 ServiceProcessState state; |
| 182 ASSERT_TRUE(state.Initialize()); | 182 ASSERT_TRUE(state.Initialize()); |
| 183 ASSERT_TRUE(GetServiceProcessData(&version, &pid)); | 183 ASSERT_TRUE(GetServiceProcessData(&version, &pid)); |
| 184 ASSERT_EQ(base::GetCurrentProcId(), pid); | 184 ASSERT_EQ(base::GetCurrentProcId(), pid); |
| 185 } | 185 } |
| 186 | 186 |
| 187 TEST_F(ServiceProcessStateTest, MAYBE_ForceShutdown) { | 187 TEST_F(ServiceProcessStateTest, MAYBE_ForceShutdown) { |
| 188 base::ProcessHandle handle = SpawnChild("ServiceProcessStateTestShutdown", | 188 base::ProcessHandle handle = SpawnChild("ServiceProcessStateTestShutdown"); |
| 189 true); | |
| 190 ASSERT_TRUE(handle); | 189 ASSERT_TRUE(handle); |
| 191 for (int i = 0; !CheckServiceProcessReady() && i < 10; ++i) { | 190 for (int i = 0; !CheckServiceProcessReady() && i < 10; ++i) { |
| 192 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); | 191 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); |
| 193 } | 192 } |
| 194 ASSERT_TRUE(CheckServiceProcessReady()); | 193 ASSERT_TRUE(CheckServiceProcessReady()); |
| 195 std::string version; | 194 std::string version; |
| 196 base::ProcessId pid; | 195 base::ProcessId pid; |
| 197 ASSERT_TRUE(GetServiceProcessData(&version, &pid)); | 196 ASSERT_TRUE(GetServiceProcessData(&version, &pid)); |
| 198 ASSERT_TRUE(ForceServiceProcessShutdown(version, pid)); | 197 ASSERT_TRUE(ForceServiceProcessShutdown(version, pid)); |
| 199 int exit_code = 0; | 198 int exit_code = 0; |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 ScopedAttributesRestorer restorer(bundle_path(), 0777); | 411 ScopedAttributesRestorer restorer(bundle_path(), 0777); |
| 413 GetIOMessageLoopProxy()->PostTask( | 412 GetIOMessageLoopProxy()->PostTask( |
| 414 FROM_HERE, | 413 FROM_HERE, |
| 415 base::Bind(&ChangeAttr, bundle_path(), 0222)); | 414 base::Bind(&ChangeAttr, bundle_path(), 0222)); |
| 416 Run(); | 415 Run(); |
| 417 ASSERT_TRUE(mock_launchd()->remove_called()); | 416 ASSERT_TRUE(mock_launchd()->remove_called()); |
| 418 ASSERT_TRUE(mock_launchd()->delete_called()); | 417 ASSERT_TRUE(mock_launchd()->delete_called()); |
| 419 } | 418 } |
| 420 | 419 |
| 421 #endif // !OS_MACOSX | 420 #endif // !OS_MACOSX |
| OLD | NEW |