| 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_child = SpawnChild(name); |
| 105 ASSERT_TRUE(process.IsValid()); | 105 ASSERT_TRUE(spawn_child.process.IsValid()); |
| 106 int exit_code = 0; | 106 int exit_code = 0; |
| 107 ASSERT_TRUE(process.WaitForExit(&exit_code)); | 107 ASSERT_TRUE(spawn_child.process.WaitForExit(&exit_code)); |
| 108 ASSERT_EQ(exit_code, 0); | 108 ASSERT_EQ(exit_code, 0); |
| 109 } | 109 } |
| 110 | 110 |
| 111 TEST_F(ServiceProcessStateTest, Singleton) { | 111 TEST_F(ServiceProcessStateTest, Singleton) { |
| 112 ServiceProcessState state; | 112 ServiceProcessState state; |
| 113 ASSERT_TRUE(state.Initialize()); | 113 ASSERT_TRUE(state.Initialize()); |
| 114 LaunchAndWait("ServiceProcessStateTestSingleton"); | 114 LaunchAndWait("ServiceProcessStateTestSingleton"); |
| 115 } | 115 } |
| 116 | 116 |
| 117 // http://crbug.com/396390 | 117 // http://crbug.com/396390 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 // implementation on Posix, this check will only execute on Windows. | 188 // implementation on Posix, this check will only execute on Windows. |
| 189 ASSERT_FALSE(GetServiceProcessData(&version, &pid)); | 189 ASSERT_FALSE(GetServiceProcessData(&version, &pid)); |
| 190 #endif // defined(OS_WIN) | 190 #endif // defined(OS_WIN) |
| 191 ServiceProcessState state; | 191 ServiceProcessState state; |
| 192 ASSERT_TRUE(state.Initialize()); | 192 ASSERT_TRUE(state.Initialize()); |
| 193 ASSERT_TRUE(GetServiceProcessData(&version, &pid)); | 193 ASSERT_TRUE(GetServiceProcessData(&version, &pid)); |
| 194 ASSERT_EQ(base::GetCurrentProcId(), pid); | 194 ASSERT_EQ(base::GetCurrentProcId(), pid); |
| 195 } | 195 } |
| 196 | 196 |
| 197 TEST_F(ServiceProcessStateTest, MAYBE_ForceShutdown) { | 197 TEST_F(ServiceProcessStateTest, MAYBE_ForceShutdown) { |
| 198 base::Process process = SpawnChild("ServiceProcessStateTestShutdown"); | 198 base::SpawnChildResult spawn_child = |
| 199 ASSERT_TRUE(process.IsValid()); | 199 SpawnChild("ServiceProcessStateTestShutdown"); |
| 200 ASSERT_TRUE(spawn_child.process.IsValid()); |
| 200 for (int i = 0; !CheckServiceProcessReady() && i < 10; ++i) { | 201 for (int i = 0; !CheckServiceProcessReady() && i < 10; ++i) { |
| 201 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); | 202 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); |
| 202 } | 203 } |
| 203 ASSERT_TRUE(CheckServiceProcessReady()); | 204 ASSERT_TRUE(CheckServiceProcessReady()); |
| 204 std::string version; | 205 std::string version; |
| 205 base::ProcessId pid; | 206 base::ProcessId pid; |
| 206 ASSERT_TRUE(GetServiceProcessData(&version, &pid)); | 207 ASSERT_TRUE(GetServiceProcessData(&version, &pid)); |
| 207 ASSERT_TRUE(ForceServiceProcessShutdown(version, pid)); | 208 ASSERT_TRUE(ForceServiceProcessShutdown(version, pid)); |
| 208 int exit_code = 0; | 209 int exit_code = 0; |
| 209 ASSERT_TRUE(process.WaitForExitWithTimeout(TestTimeouts::action_max_timeout(), | 210 ASSERT_TRUE(spawn_child.process.WaitForExitWithTimeout( |
| 210 &exit_code)); | 211 TestTimeouts::action_max_timeout(), &exit_code)); |
| 211 ASSERT_EQ(exit_code, 0); | 212 ASSERT_EQ(exit_code, 0); |
| 212 } | 213 } |
| 213 | 214 |
| 214 MULTIPROCESS_TEST_MAIN(ServiceProcessStateTestSingleton) { | 215 MULTIPROCESS_TEST_MAIN(ServiceProcessStateTestSingleton) { |
| 215 ServiceProcessState state; | 216 ServiceProcessState state; |
| 216 EXPECT_FALSE(state.Initialize()); | 217 EXPECT_FALSE(state.Initialize()); |
| 217 return 0; | 218 return 0; |
| 218 } | 219 } |
| 219 | 220 |
| 220 MULTIPROCESS_TEST_MAIN(ServiceProcessStateTestReadyTrue) { | 221 MULTIPROCESS_TEST_MAIN(ServiceProcessStateTestReadyTrue) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 241 message_loop.task_runner()->PostDelayedTask( | 242 message_loop.task_runner()->PostDelayedTask( |
| 242 FROM_HERE, run_loop.QuitWhenIdleClosure(), | 243 FROM_HERE, run_loop.QuitWhenIdleClosure(), |
| 243 TestTimeouts::action_max_timeout()); | 244 TestTimeouts::action_max_timeout()); |
| 244 EXPECT_FALSE(g_good_shutdown); | 245 EXPECT_FALSE(g_good_shutdown); |
| 245 run_loop.Run(); | 246 run_loop.Run(); |
| 246 EXPECT_TRUE(g_good_shutdown); | 247 EXPECT_TRUE(g_good_shutdown); |
| 247 return 0; | 248 return 0; |
| 248 } | 249 } |
| 249 | 250 |
| 250 #endif // !OS_MACOSX | 251 #endif // !OS_MACOSX |
| OLD | NEW |