OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/command_line.h" | 9 #include "base/command_line.h" |
9 #include "base/file_path.h" | 10 #include "base/file_path.h" |
10 #include "base/process_util.h" | 11 #include "base/process_util.h" |
11 | 12 |
12 #if !defined(OS_MACOSX) | 13 #if !defined(OS_MACOSX) |
13 #include "base/at_exit.h" | 14 #include "base/at_exit.h" |
14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
15 #include "base/string_util.h" | 16 #include "base/string_util.h" |
16 #include "base/test/multiprocess_test.h" | 17 #include "base/test/multiprocess_test.h" |
17 #include "base/test/test_timeouts.h" | 18 #include "base/test/test_timeouts.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 TEST_F(ServiceProcessStateTest, Singleton) { | 104 TEST_F(ServiceProcessStateTest, Singleton) { |
104 ServiceProcessState state; | 105 ServiceProcessState state; |
105 ASSERT_TRUE(state.Initialize()); | 106 ASSERT_TRUE(state.Initialize()); |
106 LaunchAndWait("ServiceProcessStateTestSingleton"); | 107 LaunchAndWait("ServiceProcessStateTestSingleton"); |
107 } | 108 } |
108 | 109 |
109 TEST_F(ServiceProcessStateTest, ReadyState) { | 110 TEST_F(ServiceProcessStateTest, ReadyState) { |
110 ASSERT_FALSE(CheckServiceProcessReady()); | 111 ASSERT_FALSE(CheckServiceProcessReady()); |
111 ServiceProcessState state; | 112 ServiceProcessState state; |
112 ASSERT_TRUE(state.Initialize()); | 113 ASSERT_TRUE(state.Initialize()); |
113 ASSERT_TRUE(state.SignalReady(IOMessageLoopProxy(), NULL)); | 114 ASSERT_TRUE(state.SignalReady(IOMessageLoopProxy(), base::Closure())); |
114 LaunchAndWait("ServiceProcessStateTestReadyTrue"); | 115 LaunchAndWait("ServiceProcessStateTestReadyTrue"); |
115 state.SignalStopped(); | 116 state.SignalStopped(); |
116 LaunchAndWait("ServiceProcessStateTestReadyFalse"); | 117 LaunchAndWait("ServiceProcessStateTestReadyFalse"); |
117 } | 118 } |
118 | 119 |
119 TEST_F(ServiceProcessStateTest, AutoRun) { | 120 TEST_F(ServiceProcessStateTest, AutoRun) { |
120 ServiceProcessState state; | 121 ServiceProcessState state; |
121 ASSERT_TRUE(state.AddToAutoRun()); | 122 ASSERT_TRUE(state.AddToAutoRun()); |
122 scoped_ptr<CommandLine> autorun_command_line; | 123 scoped_ptr<CommandLine> autorun_command_line; |
123 #if defined(OS_WIN) | 124 #if defined(OS_WIN) |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 | 217 |
217 MULTIPROCESS_TEST_MAIN(ServiceProcessStateTestShutdown) { | 218 MULTIPROCESS_TEST_MAIN(ServiceProcessStateTestShutdown) { |
218 MessageLoop message_loop; | 219 MessageLoop message_loop; |
219 message_loop.set_thread_name("ServiceProcessStateTestShutdownMainThread"); | 220 message_loop.set_thread_name("ServiceProcessStateTestShutdownMainThread"); |
220 base::Thread io_thread_("ServiceProcessStateTestShutdownIOThread"); | 221 base::Thread io_thread_("ServiceProcessStateTestShutdownIOThread"); |
221 base::Thread::Options options(MessageLoop::TYPE_IO, 0); | 222 base::Thread::Options options(MessageLoop::TYPE_IO, 0); |
222 EXPECT_TRUE(io_thread_.StartWithOptions(options)); | 223 EXPECT_TRUE(io_thread_.StartWithOptions(options)); |
223 ServiceProcessState state; | 224 ServiceProcessState state; |
224 EXPECT_TRUE(state.Initialize()); | 225 EXPECT_TRUE(state.Initialize()); |
225 EXPECT_TRUE(state.SignalReady(io_thread_.message_loop_proxy(), | 226 EXPECT_TRUE(state.SignalReady(io_thread_.message_loop_proxy(), |
226 NewRunnableFunction(&ShutdownTask, | 227 base::Bind(&ShutdownTask, |
227 MessageLoop::current()))); | 228 MessageLoop::current()))); |
228 message_loop.PostDelayedTask(FROM_HERE, | 229 message_loop.PostDelayedTask(FROM_HERE, |
229 new MessageLoop::QuitTask(), | 230 new MessageLoop::QuitTask(), |
230 TestTimeouts::action_max_timeout_ms()); | 231 TestTimeouts::action_max_timeout_ms()); |
231 EXPECT_FALSE(g_good_shutdown); | 232 EXPECT_FALSE(g_good_shutdown); |
232 message_loop.Run(); | 233 message_loop.Run(); |
233 EXPECT_TRUE(g_good_shutdown); | 234 EXPECT_TRUE(g_good_shutdown); |
234 return 0; | 235 return 0; |
235 } | 236 } |
236 | 237 |
237 #else // !OS_MACOSX | 238 #else // !OS_MACOSX |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 ASSERT_TRUE(MakeABundle(GetTempDirPath(), | 373 ASSERT_TRUE(MakeABundle(GetTempDirPath(), |
373 "Test", | 374 "Test", |
374 &bundle_path_, | 375 &bundle_path_, |
375 &executable_path_)); | 376 &executable_path_)); |
376 mock_launchd_.reset(new MockLaunchd(executable_path_, &loop_)); | 377 mock_launchd_.reset(new MockLaunchd(executable_path_, &loop_)); |
377 scoped_launchd_instance_.reset( | 378 scoped_launchd_instance_.reset( |
378 new Launchd::ScopedInstance(mock_launchd_.get())); | 379 new Launchd::ScopedInstance(mock_launchd_.get())); |
379 ASSERT_TRUE(service_process_state_.Initialize()); | 380 ASSERT_TRUE(service_process_state_.Initialize()); |
380 ASSERT_TRUE(service_process_state_.SignalReady( | 381 ASSERT_TRUE(service_process_state_.SignalReady( |
381 io_thread_.message_loop_proxy(), | 382 io_thread_.message_loop_proxy(), |
382 NULL)); | 383 base::Closure())); |
383 loop_.PostDelayedTask(FROM_HERE, | 384 loop_.PostDelayedTask(FROM_HERE, |
384 new MessageLoop::QuitTask, | 385 new MessageLoop::QuitTask, |
385 TestTimeouts::action_max_timeout_ms()); | 386 TestTimeouts::action_max_timeout_ms()); |
386 } | 387 } |
387 | 388 |
388 bool MakeABundle(const FilePath& dst, | 389 bool MakeABundle(const FilePath& dst, |
389 const std::string& name, | 390 const std::string& name, |
390 FilePath* bundle_root, | 391 FilePath* bundle_root, |
391 FilePath* executable) { | 392 FilePath* executable) { |
392 *bundle_root = dst.Append(name + std::string(".app")); | 393 *bundle_root = dst.Append(name + std::string(".app")); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 std::string output; | 515 std::string output; |
515 int exit_code = -1; | 516 int exit_code = -1; |
516 ASSERT_TRUE(base::GetAppOutputWithExitCode(cl, &output, &exit_code) | 517 ASSERT_TRUE(base::GetAppOutputWithExitCode(cl, &output, &exit_code) |
517 && exit_code == 0) | 518 && exit_code == 0) |
518 << " exit_code:" << exit_code << " " << output; | 519 << " exit_code:" << exit_code << " " << output; |
519 } | 520 } |
520 | 521 |
521 TEST_F(ServiceProcessStateFileManipulationTest, DeleteFile) { | 522 TEST_F(ServiceProcessStateFileManipulationTest, DeleteFile) { |
522 GetIOMessageLoopProxy()->PostTask( | 523 GetIOMessageLoopProxy()->PostTask( |
523 FROM_HERE, | 524 FROM_HERE, |
524 NewRunnableFunction(&DeleteFunc, executable_path())); | 525 base::Bind(&DeleteFunc, executable_path())); |
525 Run(); | 526 Run(); |
526 ASSERT_TRUE(mock_launchd()->remove_called()); | 527 ASSERT_TRUE(mock_launchd()->remove_called()); |
527 ASSERT_TRUE(mock_launchd()->delete_called()); | 528 ASSERT_TRUE(mock_launchd()->delete_called()); |
528 } | 529 } |
529 | 530 |
530 TEST_F(ServiceProcessStateFileManipulationTest, DeleteBundle) { | 531 TEST_F(ServiceProcessStateFileManipulationTest, DeleteBundle) { |
531 GetIOMessageLoopProxy()->PostTask( | 532 GetIOMessageLoopProxy()->PostTask( |
532 FROM_HERE, | 533 FROM_HERE, |
533 NewRunnableFunction(&DeleteFunc, bundle_path())); | 534 base::Bind(&DeleteFunc, bundle_path())); |
534 Run(); | 535 Run(); |
535 ASSERT_TRUE(mock_launchd()->remove_called()); | 536 ASSERT_TRUE(mock_launchd()->remove_called()); |
536 ASSERT_TRUE(mock_launchd()->delete_called()); | 537 ASSERT_TRUE(mock_launchd()->delete_called()); |
537 } | 538 } |
538 | 539 |
539 TEST_F(ServiceProcessStateFileManipulationTest, MoveBundle) { | 540 TEST_F(ServiceProcessStateFileManipulationTest, MoveBundle) { |
540 FilePath new_loc = GetTempDirPath().AppendASCII("MoveBundle"); | 541 FilePath new_loc = GetTempDirPath().AppendASCII("MoveBundle"); |
541 GetIOMessageLoopProxy()->PostTask( | 542 GetIOMessageLoopProxy()->PostTask( |
542 FROM_HERE, | 543 FROM_HERE, |
543 NewRunnableFunction(&MoveFunc, bundle_path(), new_loc)); | 544 base::Bind(&MoveFunc, bundle_path(), new_loc)); |
544 Run(); | 545 Run(); |
545 ASSERT_TRUE(mock_launchd()->restart_called()); | 546 ASSERT_TRUE(mock_launchd()->restart_called()); |
546 ASSERT_TRUE(mock_launchd()->write_called()); | 547 ASSERT_TRUE(mock_launchd()->write_called()); |
547 } | 548 } |
548 | 549 |
549 TEST_F(ServiceProcessStateFileManipulationTest, MoveFile) { | 550 TEST_F(ServiceProcessStateFileManipulationTest, MoveFile) { |
550 FilePath new_loc = GetTempDirPath().AppendASCII("MoveFile"); | 551 FilePath new_loc = GetTempDirPath().AppendASCII("MoveFile"); |
551 GetIOMessageLoopProxy()->PostTask( | 552 GetIOMessageLoopProxy()->PostTask( |
552 FROM_HERE, | 553 FROM_HERE, |
553 NewRunnableFunction(&MoveFunc, executable_path(), new_loc)); | 554 base::Bind(&MoveFunc, executable_path(), new_loc)); |
554 Run(); | 555 Run(); |
555 ASSERT_TRUE(mock_launchd()->remove_called()); | 556 ASSERT_TRUE(mock_launchd()->remove_called()); |
556 ASSERT_TRUE(mock_launchd()->delete_called()); | 557 ASSERT_TRUE(mock_launchd()->delete_called()); |
557 } | 558 } |
558 | 559 |
559 TEST_F(ServiceProcessStateFileManipulationTest, TrashBundle) { | 560 TEST_F(ServiceProcessStateFileManipulationTest, TrashBundle) { |
560 FSRef bundle_ref; | 561 FSRef bundle_ref; |
561 ASSERT_TRUE(base::mac::FSRefFromPath(bundle_path().value(), &bundle_ref)); | 562 ASSERT_TRUE(base::mac::FSRefFromPath(bundle_path().value(), &bundle_ref)); |
562 GetIOMessageLoopProxy()->PostTask( | 563 GetIOMessageLoopProxy()->PostTask( |
563 FROM_HERE, | 564 FROM_HERE, |
564 NewRunnableFunction(&TrashFunc, bundle_path())); | 565 base::Bind(&TrashFunc, bundle_path())); |
565 Run(); | 566 Run(); |
566 ASSERT_TRUE(mock_launchd()->remove_called()); | 567 ASSERT_TRUE(mock_launchd()->remove_called()); |
567 ASSERT_TRUE(mock_launchd()->delete_called()); | 568 ASSERT_TRUE(mock_launchd()->delete_called()); |
568 std::string path(base::mac::PathFromFSRef(bundle_ref)); | 569 std::string path(base::mac::PathFromFSRef(bundle_ref)); |
569 FilePath file_path(path); | 570 FilePath file_path(path); |
570 ASSERT_TRUE(file_util::Delete(file_path, true)); | 571 ASSERT_TRUE(file_util::Delete(file_path, true)); |
571 } | 572 } |
572 | 573 |
573 TEST_F(ServiceProcessStateFileManipulationTest, ChangeAttr) { | 574 TEST_F(ServiceProcessStateFileManipulationTest, ChangeAttr) { |
574 ScopedAttributesRestorer restorer(bundle_path(), 0777); | 575 ScopedAttributesRestorer restorer(bundle_path(), 0777); |
575 GetIOMessageLoopProxy()->PostTask( | 576 GetIOMessageLoopProxy()->PostTask( |
576 FROM_HERE, | 577 FROM_HERE, |
577 NewRunnableFunction(&ChangeAttr, bundle_path(), 0222)); | 578 base::Bind(&ChangeAttr, bundle_path(), 0222)); |
578 Run(); | 579 Run(); |
579 ASSERT_TRUE(mock_launchd()->remove_called()); | 580 ASSERT_TRUE(mock_launchd()->remove_called()); |
580 ASSERT_TRUE(mock_launchd()->delete_called()); | 581 ASSERT_TRUE(mock_launchd()->delete_called()); |
581 } | 582 } |
582 | 583 |
583 #endif // !OS_MACOSX | 584 #endif // !OS_MACOSX |
OLD | NEW |