Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: chrome/common/service_process_util_unittest.cc

Issue 1167163002: chrome: Remove use of MessageLoopProxy and deprecated MessageLoop APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added some missing message_loop.h includes. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/common/service_process_util_posix.cc ('k') | chrome/common/service_process_util_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/location.h"
11 #include "base/process/kill.h" 12 #include "base/process/kill.h"
12 #include "base/process/launch.h" 13 #include "base/process/launch.h"
14 #include "base/single_thread_task_runner.h"
13 #include "base/strings/string_split.h" 15 #include "base/strings/string_split.h"
14 16
15 #if !defined(OS_MACOSX) 17 #if !defined(OS_MACOSX)
16 #include "base/at_exit.h" 18 #include "base/at_exit.h"
17 #include "base/memory/scoped_ptr.h" 19 #include "base/memory/scoped_ptr.h"
18 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
19 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
20 #include "base/test/multiprocess_test.h" 22 #include "base/test/multiprocess_test.h"
21 #include "base/test/test_timeouts.h" 23 #include "base/test/test_timeouts.h"
22 #include "base/threading/thread.h" 24 #include "base/threading/thread.h"
(...skipping 22 matching lines...) Expand all
45 #endif 47 #endif
46 48
47 namespace { 49 namespace {
48 50
49 bool g_good_shutdown = false; 51 bool g_good_shutdown = false;
50 52
51 void ShutdownTask(base::MessageLoop* loop) { 53 void ShutdownTask(base::MessageLoop* loop) {
52 // Quit the main message loop. 54 // Quit the main message loop.
53 ASSERT_FALSE(g_good_shutdown); 55 ASSERT_FALSE(g_good_shutdown);
54 g_good_shutdown = true; 56 g_good_shutdown = true;
55 loop->PostTask(FROM_HERE, base::MessageLoop::QuitClosure()); 57 loop->task_runner()->PostTask(FROM_HERE, base::MessageLoop::QuitClosure());
56 } 58 }
57 59
58 } // namespace 60 } // namespace
59 61
60 TEST(ServiceProcessUtilTest, ScopedVersionedName) { 62 TEST(ServiceProcessUtilTest, ScopedVersionedName) {
61 std::string test_str = "test"; 63 std::string test_str = "test";
62 std::string scoped_name = GetServiceProcessScopedVersionedName(test_str); 64 std::string scoped_name = GetServiceProcessScopedVersionedName(test_str);
63 chrome::VersionInfo version_info; 65 chrome::VersionInfo version_info;
64 EXPECT_TRUE(EndsWith(scoped_name, test_str, true)); 66 EXPECT_TRUE(EndsWith(scoped_name, test_str, true));
65 EXPECT_NE(std::string::npos, scoped_name.find(version_info.Version())); 67 EXPECT_NE(std::string::npos, scoped_name.find(version_info.Version()));
66 } 68 }
67 69
68 class ServiceProcessStateTest : public base::MultiProcessTest { 70 class ServiceProcessStateTest : public base::MultiProcessTest {
69 public: 71 public:
70 ServiceProcessStateTest(); 72 ServiceProcessStateTest();
71 ~ServiceProcessStateTest() override; 73 ~ServiceProcessStateTest() override;
72 void SetUp() override; 74 void SetUp() override;
73 base::MessageLoopProxy* IOMessageLoopProxy() { 75 base::SingleThreadTaskRunner* IOMessageLoopProxy() {
74 return io_thread_.message_loop_proxy().get(); 76 return io_thread_.task_runner().get();
75 } 77 }
76 void LaunchAndWait(const std::string& name); 78 void LaunchAndWait(const std::string& name);
77 79
78 private: 80 private:
79 // This is used to release the ServiceProcessState singleton after each test. 81 // This is used to release the ServiceProcessState singleton after each test.
80 base::ShadowingAtExitManager at_exit_manager_; 82 base::ShadowingAtExitManager at_exit_manager_;
81 base::Thread io_thread_; 83 base::Thread io_thread_;
82 }; 84 };
83 85
84 ServiceProcessStateTest::ServiceProcessStateTest() 86 ServiceProcessStateTest::ServiceProcessStateTest()
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 223
222 MULTIPROCESS_TEST_MAIN(ServiceProcessStateTestShutdown) { 224 MULTIPROCESS_TEST_MAIN(ServiceProcessStateTestShutdown) {
223 base::MessageLoop message_loop; 225 base::MessageLoop message_loop;
224 message_loop.set_thread_name("ServiceProcessStateTestShutdownMainThread"); 226 message_loop.set_thread_name("ServiceProcessStateTestShutdownMainThread");
225 base::Thread io_thread_("ServiceProcessStateTestShutdownIOThread"); 227 base::Thread io_thread_("ServiceProcessStateTestShutdownIOThread");
226 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0); 228 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0);
227 EXPECT_TRUE(io_thread_.StartWithOptions(options)); 229 EXPECT_TRUE(io_thread_.StartWithOptions(options));
228 ServiceProcessState state; 230 ServiceProcessState state;
229 EXPECT_TRUE(state.Initialize()); 231 EXPECT_TRUE(state.Initialize());
230 EXPECT_TRUE(state.SignalReady( 232 EXPECT_TRUE(state.SignalReady(
231 io_thread_.message_loop_proxy().get(), 233 io_thread_.task_runner().get(),
232 base::Bind(&ShutdownTask, base::MessageLoop::current()))); 234 base::Bind(&ShutdownTask, base::MessageLoop::current())));
233 message_loop.PostDelayedTask(FROM_HERE, 235 message_loop.task_runner()->PostDelayedTask(
234 base::MessageLoop::QuitClosure(), 236 FROM_HERE, base::MessageLoop::QuitClosure(),
235 TestTimeouts::action_max_timeout()); 237 TestTimeouts::action_max_timeout());
236 EXPECT_FALSE(g_good_shutdown); 238 EXPECT_FALSE(g_good_shutdown);
237 message_loop.Run(); 239 message_loop.Run();
238 EXPECT_TRUE(g_good_shutdown); 240 EXPECT_TRUE(g_good_shutdown);
239 return 0; 241 return 0;
240 } 242 }
241 243
242 #else // !OS_MACOSX 244 #else // !OS_MACOSX
243 245
244 #include <CoreFoundation/CoreFoundation.h> 246 #include <CoreFoundation/CoreFoundation.h>
245 247
(...skipping 21 matching lines...) Expand all
267 ASSERT_TRUE(MockLaunchd::MakeABundle(GetTempDirPath(), 269 ASSERT_TRUE(MockLaunchd::MakeABundle(GetTempDirPath(),
268 "Test", 270 "Test",
269 &bundle_path_, 271 &bundle_path_,
270 &executable_path_)); 272 &executable_path_));
271 mock_launchd_.reset(new MockLaunchd(executable_path_, &loop_, 273 mock_launchd_.reset(new MockLaunchd(executable_path_, &loop_,
272 false, false)); 274 false, false));
273 scoped_launchd_instance_.reset( 275 scoped_launchd_instance_.reset(
274 new Launchd::ScopedInstance(mock_launchd_.get())); 276 new Launchd::ScopedInstance(mock_launchd_.get()));
275 ASSERT_TRUE(service_process_state_.Initialize()); 277 ASSERT_TRUE(service_process_state_.Initialize());
276 ASSERT_TRUE(service_process_state_.SignalReady( 278 ASSERT_TRUE(service_process_state_.SignalReady(
277 io_thread_.message_loop_proxy().get(), base::Closure())); 279 io_thread_.task_runner().get(), base::Closure()));
278 loop_.PostDelayedTask(FROM_HERE, 280 loop_.PostDelayedTask(FROM_HERE,
279 base::MessageLoop::QuitClosure(), 281 base::MessageLoop::QuitClosure(),
280 TestTimeouts::action_max_timeout()); 282 TestTimeouts::action_max_timeout());
281 } 283 }
282 284
283 const MockLaunchd* mock_launchd() const { return mock_launchd_.get(); } 285 const MockLaunchd* mock_launchd() const { return mock_launchd_.get(); }
284 const base::FilePath& executable_path() const { return executable_path_; } 286 const base::FilePath& executable_path() const { return executable_path_; }
285 const base::FilePath& bundle_path() const { return bundle_path_; } 287 const base::FilePath& bundle_path() const { return bundle_path_; }
286 const base::FilePath& GetTempDirPath() const { return temp_dir_.path(); } 288 const base::FilePath& GetTempDirPath() const { return temp_dir_.path(); }
287 289
288 base::MessageLoopProxy* GetIOMessageLoopProxy() { 290 base::SingleThreadTaskRunner* GetIOMessageLoopProxy() {
289 return io_thread_.message_loop_proxy().get(); 291 return io_thread_.task_runner().get();
290 } 292 }
291 void Run() { loop_.Run(); } 293 void Run() { loop_.Run(); }
292 294
293 private: 295 private:
294 base::ScopedTempDir temp_dir_; 296 base::ScopedTempDir temp_dir_;
295 base::MessageLoopForUI loop_; 297 base::MessageLoopForUI loop_;
296 base::Thread io_thread_; 298 base::Thread io_thread_;
297 base::FilePath executable_path_, bundle_path_; 299 base::FilePath executable_path_, bundle_path_;
298 scoped_ptr<MockLaunchd> mock_launchd_; 300 scoped_ptr<MockLaunchd> mock_launchd_;
299 scoped_ptr<Launchd::ScopedInstance> scoped_launchd_instance_; 301 scoped_ptr<Launchd::ScopedInstance> scoped_launchd_instance_;
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 ScopedAttributesRestorer restorer(bundle_path(), 0777); 416 ScopedAttributesRestorer restorer(bundle_path(), 0777);
415 GetIOMessageLoopProxy()->PostTask( 417 GetIOMessageLoopProxy()->PostTask(
416 FROM_HERE, 418 FROM_HERE,
417 base::Bind(&ChangeAttr, bundle_path(), 0222)); 419 base::Bind(&ChangeAttr, bundle_path(), 0222));
418 Run(); 420 Run();
419 ASSERT_TRUE(mock_launchd()->remove_called()); 421 ASSERT_TRUE(mock_launchd()->remove_called());
420 ASSERT_TRUE(mock_launchd()->delete_called()); 422 ASSERT_TRUE(mock_launchd()->delete_called());
421 } 423 }
422 424
423 #endif // !OS_MACOSX 425 #endif // !OS_MACOSX
OLDNEW
« no previous file with comments | « chrome/common/service_process_util_posix.cc ('k') | chrome/common/service_process_util_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698