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

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

Issue 2133083002: Remove all remaining traces of MessageLoopProxy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
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 <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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 base::CompareCase::SENSITIVE)); 70 base::CompareCase::SENSITIVE));
71 EXPECT_NE(std::string::npos, 71 EXPECT_NE(std::string::npos,
72 scoped_name.find(version_info::GetVersionNumber())); 72 scoped_name.find(version_info::GetVersionNumber()));
73 } 73 }
74 74
75 class ServiceProcessStateTest : public base::MultiProcessTest { 75 class ServiceProcessStateTest : public base::MultiProcessTest {
76 public: 76 public:
77 ServiceProcessStateTest(); 77 ServiceProcessStateTest();
78 ~ServiceProcessStateTest() override; 78 ~ServiceProcessStateTest() override;
79 void SetUp() override; 79 void SetUp() override;
80 base::SingleThreadTaskRunner* IOMessageLoopProxy() { 80 base::SingleThreadTaskRunner* IOTaskRunner() {
81 return io_thread_.task_runner().get(); 81 return io_thread_.task_runner().get();
82 } 82 }
83 void LaunchAndWait(const std::string& name); 83 void LaunchAndWait(const std::string& name);
84 84
85 private: 85 private:
86 // This is used to release the ServiceProcessState singleton after each test. 86 // This is used to release the ServiceProcessState singleton after each test.
87 base::ShadowingAtExitManager at_exit_manager_; 87 base::ShadowingAtExitManager at_exit_manager_;
88 base::Thread io_thread_; 88 base::Thread io_thread_;
89 }; 89 };
90 90
(...skipping 21 matching lines...) Expand all
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
118 TEST_F(ServiceProcessStateTest, DISABLED_ReadyState) { 118 TEST_F(ServiceProcessStateTest, DISABLED_ReadyState) {
119 ASSERT_FALSE(CheckServiceProcessReady()); 119 ASSERT_FALSE(CheckServiceProcessReady());
120 ServiceProcessState state; 120 ServiceProcessState state;
121 ASSERT_TRUE(state.Initialize()); 121 ASSERT_TRUE(state.Initialize());
122 ASSERT_TRUE(state.SignalReady(IOMessageLoopProxy(), base::Closure())); 122 ASSERT_TRUE(state.SignalReady(IOTaskRunner(), base::Closure()));
123 LaunchAndWait("ServiceProcessStateTestReadyTrue"); 123 LaunchAndWait("ServiceProcessStateTestReadyTrue");
124 state.SignalStopped(); 124 state.SignalStopped();
125 LaunchAndWait("ServiceProcessStateTestReadyFalse"); 125 LaunchAndWait("ServiceProcessStateTestReadyFalse");
126 } 126 }
127 127
128 TEST_F(ServiceProcessStateTest, AutoRun) { 128 TEST_F(ServiceProcessStateTest, AutoRun) {
129 ServiceProcessState state; 129 ServiceProcessState state;
130 ASSERT_TRUE(state.AddToAutoRun()); 130 ASSERT_TRUE(state.AddToAutoRun());
131 std::unique_ptr<base::CommandLine> autorun_command_line; 131 std::unique_ptr<base::CommandLine> autorun_command_line;
132 #if defined(OS_WIN) 132 #if defined(OS_WIN)
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 loop_.task_runner()->PostDelayedTask( 286 loop_.task_runner()->PostDelayedTask(
287 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), 287 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(),
288 TestTimeouts::action_max_timeout()); 288 TestTimeouts::action_max_timeout());
289 } 289 }
290 290
291 const MockLaunchd* mock_launchd() const { return mock_launchd_.get(); } 291 const MockLaunchd* mock_launchd() const { return mock_launchd_.get(); }
292 const base::FilePath& executable_path() const { return executable_path_; } 292 const base::FilePath& executable_path() const { return executable_path_; }
293 const base::FilePath& bundle_path() const { return bundle_path_; } 293 const base::FilePath& bundle_path() const { return bundle_path_; }
294 const base::FilePath& GetTempDirPath() const { return temp_dir_.path(); } 294 const base::FilePath& GetTempDirPath() const { return temp_dir_.path(); }
295 295
296 base::SingleThreadTaskRunner* GetIOMessageLoopProxy() { 296 base::SingleThreadTaskRunner* GetIOTaskRunner() {
297 return io_thread_.task_runner().get(); 297 return io_thread_.task_runner().get();
298 } 298 }
299 void Run() { loop_.Run(); } 299 void Run() { loop_.Run(); }
300 300
301 private: 301 private:
302 base::ScopedTempDir temp_dir_; 302 base::ScopedTempDir temp_dir_;
303 base::MessageLoopForUI loop_; 303 base::MessageLoopForUI loop_;
304 base::Thread io_thread_; 304 base::Thread io_thread_;
305 base::FilePath executable_path_, bundle_path_; 305 base::FilePath executable_path_, bundle_path_;
306 std::unique_ptr<MockLaunchd> mock_launchd_; 306 std::unique_ptr<MockLaunchd> mock_launchd_;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 cl.AppendArg("limit"); 360 cl.AppendArg("limit");
361 361
362 std::string output; 362 std::string output;
363 int exit_code = -1; 363 int exit_code = -1;
364 ASSERT_TRUE(base::GetAppOutputWithExitCode(cl, &output, &exit_code) 364 ASSERT_TRUE(base::GetAppOutputWithExitCode(cl, &output, &exit_code)
365 && exit_code == 0) 365 && exit_code == 0)
366 << " exit_code:" << exit_code << " " << output; 366 << " exit_code:" << exit_code << " " << output;
367 } 367 }
368 368
369 TEST_F(ServiceProcessStateFileManipulationTest, DeleteFile) { 369 TEST_F(ServiceProcessStateFileManipulationTest, DeleteFile) {
370 GetIOMessageLoopProxy()->PostTask( 370 GetIOTaskRunner()->PostTask(FROM_HERE,
371 FROM_HERE, 371 base::Bind(&DeleteFunc, executable_path()));
372 base::Bind(&DeleteFunc, executable_path()));
373 Run(); 372 Run();
374 ASSERT_TRUE(mock_launchd()->remove_called()); 373 ASSERT_TRUE(mock_launchd()->remove_called());
375 ASSERT_TRUE(mock_launchd()->delete_called()); 374 ASSERT_TRUE(mock_launchd()->delete_called());
376 } 375 }
377 376
378 TEST_F(ServiceProcessStateFileManipulationTest, DeleteBundle) { 377 TEST_F(ServiceProcessStateFileManipulationTest, DeleteBundle) {
379 GetIOMessageLoopProxy()->PostTask( 378 GetIOTaskRunner()->PostTask(FROM_HERE,
380 FROM_HERE, 379 base::Bind(&DeleteFunc, bundle_path()));
381 base::Bind(&DeleteFunc, bundle_path()));
382 Run(); 380 Run();
383 ASSERT_TRUE(mock_launchd()->remove_called()); 381 ASSERT_TRUE(mock_launchd()->remove_called());
384 ASSERT_TRUE(mock_launchd()->delete_called()); 382 ASSERT_TRUE(mock_launchd()->delete_called());
385 } 383 }
386 384
387 TEST_F(ServiceProcessStateFileManipulationTest, MoveBundle) { 385 TEST_F(ServiceProcessStateFileManipulationTest, MoveBundle) {
388 base::FilePath new_loc = GetTempDirPath().AppendASCII("MoveBundle"); 386 base::FilePath new_loc = GetTempDirPath().AppendASCII("MoveBundle");
389 GetIOMessageLoopProxy()->PostTask( 387 GetIOTaskRunner()->PostTask(FROM_HERE,
390 FROM_HERE, 388 base::Bind(&MoveFunc, bundle_path(), new_loc));
391 base::Bind(&MoveFunc, bundle_path(), new_loc));
392 Run(); 389 Run();
393 ASSERT_TRUE(mock_launchd()->restart_called()); 390 ASSERT_TRUE(mock_launchd()->restart_called());
394 ASSERT_TRUE(mock_launchd()->write_called()); 391 ASSERT_TRUE(mock_launchd()->write_called());
395 } 392 }
396 393
397 TEST_F(ServiceProcessStateFileManipulationTest, MoveFile) { 394 TEST_F(ServiceProcessStateFileManipulationTest, MoveFile) {
398 base::FilePath new_loc = GetTempDirPath().AppendASCII("MoveFile"); 395 base::FilePath new_loc = GetTempDirPath().AppendASCII("MoveFile");
399 GetIOMessageLoopProxy()->PostTask( 396 GetIOTaskRunner()->PostTask(
400 FROM_HERE, 397 FROM_HERE, base::Bind(&MoveFunc, executable_path(), new_loc));
401 base::Bind(&MoveFunc, executable_path(), new_loc));
402 Run(); 398 Run();
403 ASSERT_TRUE(mock_launchd()->remove_called()); 399 ASSERT_TRUE(mock_launchd()->remove_called());
404 ASSERT_TRUE(mock_launchd()->delete_called()); 400 ASSERT_TRUE(mock_launchd()->delete_called());
405 } 401 }
406 402
407 TEST_F(ServiceProcessStateFileManipulationTest, TrashBundle) { 403 TEST_F(ServiceProcessStateFileManipulationTest, TrashBundle) {
408 FSRef bundle_ref; 404 FSRef bundle_ref;
409 ASSERT_TRUE(base::mac::FSRefFromPath(bundle_path().value(), &bundle_ref)); 405 ASSERT_TRUE(base::mac::FSRefFromPath(bundle_path().value(), &bundle_ref));
410 GetIOMessageLoopProxy()->PostTask( 406 GetIOTaskRunner()->PostTask(FROM_HERE, base::Bind(&TrashFunc, bundle_path()));
411 FROM_HERE,
412 base::Bind(&TrashFunc, bundle_path()));
413 Run(); 407 Run();
414 ASSERT_TRUE(mock_launchd()->remove_called()); 408 ASSERT_TRUE(mock_launchd()->remove_called());
415 ASSERT_TRUE(mock_launchd()->delete_called()); 409 ASSERT_TRUE(mock_launchd()->delete_called());
416 std::string path(base::mac::PathFromFSRef(bundle_ref)); 410 std::string path(base::mac::PathFromFSRef(bundle_ref));
417 base::FilePath file_path(path); 411 base::FilePath file_path(path);
418 ASSERT_TRUE(base::DeleteFile(file_path, true)); 412 ASSERT_TRUE(base::DeleteFile(file_path, true));
419 } 413 }
420 414
421 TEST_F(ServiceProcessStateFileManipulationTest, ChangeAttr) { 415 TEST_F(ServiceProcessStateFileManipulationTest, ChangeAttr) {
422 ScopedAttributesRestorer restorer(bundle_path(), 0777); 416 ScopedAttributesRestorer restorer(bundle_path(), 0777);
423 GetIOMessageLoopProxy()->PostTask( 417 GetIOTaskRunner()->PostTask(FROM_HERE,
424 FROM_HERE, 418 base::Bind(&ChangeAttr, bundle_path(), 0222));
425 base::Bind(&ChangeAttr, bundle_path(), 0222));
426 Run(); 419 Run();
427 ASSERT_TRUE(mock_launchd()->remove_called()); 420 ASSERT_TRUE(mock_launchd()->remove_called());
428 ASSERT_TRUE(mock_launchd()->delete_called()); 421 ASSERT_TRUE(mock_launchd()->delete_called());
429 } 422 }
430 423
431 #endif // !OS_MACOSX 424 #endif // !OS_MACOSX
OLDNEW
« no previous file with comments | « chrome/browser/web_data_service_factory.cc ('k') | chrome/renderer/chrome_content_renderer_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698