| 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 <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 | 94 |
| 95 ServiceProcessStateTest::~ServiceProcessStateTest() { | 95 ServiceProcessStateTest::~ServiceProcessStateTest() { |
| 96 } | 96 } |
| 97 | 97 |
| 98 void ServiceProcessStateTest::SetUp() { | 98 void ServiceProcessStateTest::SetUp() { |
| 99 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0); | 99 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0); |
| 100 ASSERT_TRUE(io_thread_.StartWithOptions(options)); | 100 ASSERT_TRUE(io_thread_.StartWithOptions(options)); |
| 101 } | 101 } |
| 102 | 102 |
| 103 void ServiceProcessStateTest::LaunchAndWait(const std::string& name) { | 103 void ServiceProcessStateTest::LaunchAndWait(const std::string& name) { |
| 104 base::Process process = SpawnChild(name); | 104 base::SpawnChildResult spawn_result = SpawnChild(name); |
| 105 base::Process process(std::move(spawn_result.process)); |
| 105 ASSERT_TRUE(process.IsValid()); | 106 ASSERT_TRUE(process.IsValid()); |
| 106 int exit_code = 0; | 107 int exit_code = 0; |
| 107 ASSERT_TRUE(process.WaitForExit(&exit_code)); | 108 ASSERT_TRUE(process.WaitForExit(&exit_code)); |
| 108 ASSERT_EQ(exit_code, 0); | 109 ASSERT_EQ(exit_code, 0); |
| 109 } | 110 } |
| 110 | 111 |
| 111 TEST_F(ServiceProcessStateTest, Singleton) { | 112 TEST_F(ServiceProcessStateTest, Singleton) { |
| 112 ServiceProcessState state; | 113 ServiceProcessState state; |
| 113 ASSERT_TRUE(state.Initialize()); | 114 ASSERT_TRUE(state.Initialize()); |
| 114 LaunchAndWait("ServiceProcessStateTestSingleton"); | 115 LaunchAndWait("ServiceProcessStateTestSingleton"); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 // implementation on Posix, this check will only execute on Windows. | 189 // implementation on Posix, this check will only execute on Windows. |
| 189 ASSERT_FALSE(GetServiceProcessData(&version, &pid)); | 190 ASSERT_FALSE(GetServiceProcessData(&version, &pid)); |
| 190 #endif // defined(OS_WIN) | 191 #endif // defined(OS_WIN) |
| 191 ServiceProcessState state; | 192 ServiceProcessState state; |
| 192 ASSERT_TRUE(state.Initialize()); | 193 ASSERT_TRUE(state.Initialize()); |
| 193 ASSERT_TRUE(GetServiceProcessData(&version, &pid)); | 194 ASSERT_TRUE(GetServiceProcessData(&version, &pid)); |
| 194 ASSERT_EQ(base::GetCurrentProcId(), pid); | 195 ASSERT_EQ(base::GetCurrentProcId(), pid); |
| 195 } | 196 } |
| 196 | 197 |
| 197 TEST_F(ServiceProcessStateTest, MAYBE_ForceShutdown) { | 198 TEST_F(ServiceProcessStateTest, MAYBE_ForceShutdown) { |
| 198 base::Process process = SpawnChild("ServiceProcessStateTestShutdown"); | 199 base::SpawnChildResult spawn_result = |
| 200 SpawnChild("ServiceProcessStateTestShutdown"); |
| 201 base::Process process(std::move(spawn_result.process)); |
| 199 ASSERT_TRUE(process.IsValid()); | 202 ASSERT_TRUE(process.IsValid()); |
| 200 for (int i = 0; !CheckServiceProcessReady() && i < 10; ++i) { | 203 for (int i = 0; !CheckServiceProcessReady() && i < 10; ++i) { |
| 201 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); | 204 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); |
| 202 } | 205 } |
| 203 ASSERT_TRUE(CheckServiceProcessReady()); | 206 ASSERT_TRUE(CheckServiceProcessReady()); |
| 204 std::string version; | 207 std::string version; |
| 205 base::ProcessId pid; | 208 base::ProcessId pid; |
| 206 ASSERT_TRUE(GetServiceProcessData(&version, &pid)); | 209 ASSERT_TRUE(GetServiceProcessData(&version, &pid)); |
| 207 ASSERT_TRUE(ForceServiceProcessShutdown(version, pid)); | 210 ASSERT_TRUE(ForceServiceProcessShutdown(version, pid)); |
| 208 int exit_code = 0; | 211 int exit_code = 0; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 message_loop.task_runner()->PostDelayedTask( | 244 message_loop.task_runner()->PostDelayedTask( |
| 242 FROM_HERE, run_loop.QuitWhenIdleClosure(), | 245 FROM_HERE, run_loop.QuitWhenIdleClosure(), |
| 243 TestTimeouts::action_max_timeout()); | 246 TestTimeouts::action_max_timeout()); |
| 244 EXPECT_FALSE(g_good_shutdown); | 247 EXPECT_FALSE(g_good_shutdown); |
| 245 run_loop.Run(); | 248 run_loop.Run(); |
| 246 EXPECT_TRUE(g_good_shutdown); | 249 EXPECT_TRUE(g_good_shutdown); |
| 247 return 0; | 250 return 0; |
| 248 } | 251 } |
| 249 | 252 |
| 250 #endif // !OS_MACOSX | 253 #endif // !OS_MACOSX |
| OLD | NEW |