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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 #endif | 47 #endif |
48 | 48 |
49 namespace { | 49 namespace { |
50 | 50 |
51 bool g_good_shutdown = false; | 51 bool g_good_shutdown = false; |
52 | 52 |
53 void ShutdownTask(base::MessageLoop* loop) { | 53 void ShutdownTask(base::MessageLoop* loop) { |
54 // Quit the main message loop. | 54 // Quit the main message loop. |
55 ASSERT_FALSE(g_good_shutdown); | 55 ASSERT_FALSE(g_good_shutdown); |
56 g_good_shutdown = true; | 56 g_good_shutdown = true; |
57 loop->task_runner()->PostTask(FROM_HERE, base::MessageLoop::QuitClosure()); | 57 loop->task_runner()->PostTask(FROM_HERE, |
| 58 base::MessageLoop::QuitWhenIdleClosure()); |
58 } | 59 } |
59 | 60 |
60 } // namespace | 61 } // namespace |
61 | 62 |
62 TEST(ServiceProcessUtilTest, ScopedVersionedName) { | 63 TEST(ServiceProcessUtilTest, ScopedVersionedName) { |
63 std::string test_str = "test"; | 64 std::string test_str = "test"; |
64 std::string scoped_name = GetServiceProcessScopedVersionedName(test_str); | 65 std::string scoped_name = GetServiceProcessScopedVersionedName(test_str); |
65 EXPECT_TRUE(base::EndsWith(scoped_name, test_str, | 66 EXPECT_TRUE(base::EndsWith(scoped_name, test_str, |
66 base::CompareCase::SENSITIVE)); | 67 base::CompareCase::SENSITIVE)); |
67 EXPECT_NE(std::string::npos, | 68 EXPECT_NE(std::string::npos, |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 message_loop.set_thread_name("ServiceProcessStateTestShutdownMainThread"); | 229 message_loop.set_thread_name("ServiceProcessStateTestShutdownMainThread"); |
229 base::Thread io_thread_("ServiceProcessStateTestShutdownIOThread"); | 230 base::Thread io_thread_("ServiceProcessStateTestShutdownIOThread"); |
230 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0); | 231 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0); |
231 EXPECT_TRUE(io_thread_.StartWithOptions(options)); | 232 EXPECT_TRUE(io_thread_.StartWithOptions(options)); |
232 ServiceProcessState state; | 233 ServiceProcessState state; |
233 EXPECT_TRUE(state.Initialize()); | 234 EXPECT_TRUE(state.Initialize()); |
234 EXPECT_TRUE(state.SignalReady( | 235 EXPECT_TRUE(state.SignalReady( |
235 io_thread_.task_runner().get(), | 236 io_thread_.task_runner().get(), |
236 base::Bind(&ShutdownTask, base::MessageLoop::current()))); | 237 base::Bind(&ShutdownTask, base::MessageLoop::current()))); |
237 message_loop.task_runner()->PostDelayedTask( | 238 message_loop.task_runner()->PostDelayedTask( |
238 FROM_HERE, base::MessageLoop::QuitClosure(), | 239 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
239 TestTimeouts::action_max_timeout()); | 240 TestTimeouts::action_max_timeout()); |
240 EXPECT_FALSE(g_good_shutdown); | 241 EXPECT_FALSE(g_good_shutdown); |
241 message_loop.Run(); | 242 message_loop.Run(); |
242 EXPECT_TRUE(g_good_shutdown); | 243 EXPECT_TRUE(g_good_shutdown); |
243 return 0; | 244 return 0; |
244 } | 245 } |
245 | 246 |
246 #else // !OS_MACOSX | 247 #else // !OS_MACOSX |
247 | 248 |
248 #include <CoreFoundation/CoreFoundation.h> | 249 #include <CoreFoundation/CoreFoundation.h> |
(...skipping 23 matching lines...) Expand all Loading... |
272 "Test", | 273 "Test", |
273 &bundle_path_, | 274 &bundle_path_, |
274 &executable_path_)); | 275 &executable_path_)); |
275 mock_launchd_.reset(new MockLaunchd(executable_path_, &loop_, | 276 mock_launchd_.reset(new MockLaunchd(executable_path_, &loop_, |
276 false, false)); | 277 false, false)); |
277 scoped_launchd_instance_.reset( | 278 scoped_launchd_instance_.reset( |
278 new Launchd::ScopedInstance(mock_launchd_.get())); | 279 new Launchd::ScopedInstance(mock_launchd_.get())); |
279 ASSERT_TRUE(service_process_state_.Initialize()); | 280 ASSERT_TRUE(service_process_state_.Initialize()); |
280 ASSERT_TRUE(service_process_state_.SignalReady( | 281 ASSERT_TRUE(service_process_state_.SignalReady( |
281 io_thread_.task_runner().get(), base::Closure())); | 282 io_thread_.task_runner().get(), base::Closure())); |
282 loop_.PostDelayedTask(FROM_HERE, | 283 loop_.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
283 base::MessageLoop::QuitClosure(), | |
284 TestTimeouts::action_max_timeout()); | 284 TestTimeouts::action_max_timeout()); |
285 } | 285 } |
286 | 286 |
287 const MockLaunchd* mock_launchd() const { return mock_launchd_.get(); } | 287 const MockLaunchd* mock_launchd() const { return mock_launchd_.get(); } |
288 const base::FilePath& executable_path() const { return executable_path_; } | 288 const base::FilePath& executable_path() const { return executable_path_; } |
289 const base::FilePath& bundle_path() const { return bundle_path_; } | 289 const base::FilePath& bundle_path() const { return bundle_path_; } |
290 const base::FilePath& GetTempDirPath() const { return temp_dir_.path(); } | 290 const base::FilePath& GetTempDirPath() const { return temp_dir_.path(); } |
291 | 291 |
292 base::SingleThreadTaskRunner* GetIOMessageLoopProxy() { | 292 base::SingleThreadTaskRunner* GetIOMessageLoopProxy() { |
293 return io_thread_.task_runner().get(); | 293 return io_thread_.task_runner().get(); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 ScopedAttributesRestorer restorer(bundle_path(), 0777); | 418 ScopedAttributesRestorer restorer(bundle_path(), 0777); |
419 GetIOMessageLoopProxy()->PostTask( | 419 GetIOMessageLoopProxy()->PostTask( |
420 FROM_HERE, | 420 FROM_HERE, |
421 base::Bind(&ChangeAttr, bundle_path(), 0222)); | 421 base::Bind(&ChangeAttr, bundle_path(), 0222)); |
422 Run(); | 422 Run(); |
423 ASSERT_TRUE(mock_launchd()->remove_called()); | 423 ASSERT_TRUE(mock_launchd()->remove_called()); |
424 ASSERT_TRUE(mock_launchd()->delete_called()); | 424 ASSERT_TRUE(mock_launchd()->delete_called()); |
425 } | 425 } |
426 | 426 |
427 #endif // !OS_MACOSX | 427 #endif // !OS_MACOSX |
OLD | NEW |