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

Side by Side Diff: chrome/browser/printing/cloud_print/test/cloud_print_proxy_process_browsertest.cc

Issue 843113003: MultiProcessTest: Update SpawnChild* to return a Process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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 | « base/test/multiprocess_test_android.cc ('k') | chrome/common/multi_process_lock_unittest.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 // Create a service process that uses a Mock to respond to the browser in order 5 // Create a service process that uses a Mock to respond to the browser in order
6 // to test launching the browser using the cloud print policy check command 6 // to test launching the browser using the cloud print policy check command
7 // line switch. 7 // line switch.
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/process/kill.h" 12 #include "base/process/kill.h"
13 #include "base/process/process.h"
13 #include "base/rand_util.h" 14 #include "base/rand_util.h"
14 #include "base/synchronization/waitable_event.h" 15 #include "base/synchronization/waitable_event.h"
15 #include "base/test/multiprocess_test.h" 16 #include "base/test/multiprocess_test.h"
16 #include "base/test/test_timeouts.h" 17 #include "base/test/test_timeouts.h"
17 #include "base/time/default_tick_clock.h" 18 #include "base/time/default_tick_clock.h"
18 #include "base/time/time.h" 19 #include "base/time/time.h"
19 #include "chrome/browser/chrome_content_browser_client.h" 20 #include "chrome/browser/chrome_content_browser_client.h"
20 #include "chrome/browser/prefs/browser_prefs.h" 21 #include "chrome/browser/prefs/browser_prefs.h"
21 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" 22 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
22 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory. h" 23 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory. h"
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 public: 302 public:
302 CloudPrintProxyPolicyStartupTest(); 303 CloudPrintProxyPolicyStartupTest();
303 ~CloudPrintProxyPolicyStartupTest() override; 304 ~CloudPrintProxyPolicyStartupTest() override;
304 305
305 void SetUp() override; 306 void SetUp() override;
306 void TearDown() override; 307 void TearDown() override;
307 308
308 scoped_refptr<base::MessageLoopProxy> IOMessageLoopProxy() { 309 scoped_refptr<base::MessageLoopProxy> IOMessageLoopProxy() {
309 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); 310 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
310 } 311 }
311 base::ProcessHandle Launch(const std::string& name); 312 base::Process Launch(const std::string& name);
312 void WaitForConnect(); 313 void WaitForConnect();
313 bool Send(IPC::Message* message); 314 bool Send(IPC::Message* message);
314 void ShutdownAndWaitForExitWithTimeout(base::ProcessHandle handle); 315 void ShutdownAndWaitForExitWithTimeout(base::Process process);
315 316
316 // IPC::Listener implementation 317 // IPC::Listener implementation
317 bool OnMessageReceived(const IPC::Message& message) override { return false; } 318 bool OnMessageReceived(const IPC::Message& message) override { return false; }
318 void OnChannelConnected(int32 peer_pid) override; 319 void OnChannelConnected(int32 peer_pid) override;
319 320
320 // MultiProcessTest implementation. 321 // MultiProcessTest implementation.
321 base::CommandLine MakeCmdLine(const std::string& procname) override; 322 base::CommandLine MakeCmdLine(const std::string& procname) override;
322 323
323 bool LaunchBrowser(const base::CommandLine& command_line, Profile* profile) { 324 bool LaunchBrowser(const base::CommandLine& command_line, Profile* profile) {
324 int return_code = 0; 325 int return_code = 0;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 } 424 }
424 425
425 void CloudPrintProxyPolicyStartupTest::TearDown() { 426 void CloudPrintProxyPolicyStartupTest::TearDown() {
426 browser_content_client_.reset(); 427 browser_content_client_.reset();
427 content_client_.reset(); 428 content_client_.reset();
428 content::SetContentClient(NULL); 429 content::SetContentClient(NULL);
429 430
430 TestingBrowserProcess::DeleteInstance(); 431 TestingBrowserProcess::DeleteInstance();
431 } 432 }
432 433
433 base::ProcessHandle CloudPrintProxyPolicyStartupTest::Launch( 434 base::Process CloudPrintProxyPolicyStartupTest::Launch(
434 const std::string& name) { 435 const std::string& name) {
435 EXPECT_FALSE(CheckServiceProcessReady()); 436 EXPECT_FALSE(CheckServiceProcessReady());
436 437
437 startup_channel_id_ = 438 startup_channel_id_ =
438 base::StringPrintf("%d.%p.%d", 439 base::StringPrintf("%d.%p.%d",
439 base::GetCurrentProcId(), this, 440 base::GetCurrentProcId(), this,
440 base::RandInt(0, std::numeric_limits<int>::max())); 441 base::RandInt(0, std::numeric_limits<int>::max()));
441 startup_channel_ = IPC::ChannelProxy::Create(startup_channel_id_, 442 startup_channel_ = IPC::ChannelProxy::Create(startup_channel_id_,
442 IPC::Channel::MODE_SERVER, 443 IPC::Channel::MODE_SERVER,
443 this, 444 this,
444 IOMessageLoopProxy()); 445 IOMessageLoopProxy());
445 446
446 #if defined(OS_POSIX) 447 #if defined(OS_POSIX)
447 base::FileHandleMappingVector ipc_file_list; 448 base::FileHandleMappingVector ipc_file_list;
448 ipc_file_list.push_back(std::make_pair( 449 ipc_file_list.push_back(std::make_pair(
449 startup_channel_->TakeClientFileDescriptor().release(), 450 startup_channel_->TakeClientFileDescriptor().release(),
450 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor)); 451 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor));
451 base::LaunchOptions options; 452 base::LaunchOptions options;
452 options.fds_to_remap = &ipc_file_list; 453 options.fds_to_remap = &ipc_file_list;
453 base::ProcessHandle handle = SpawnChildWithOptions(name, options); 454 base::Process process = SpawnChildWithOptions(name, options);
454 #else 455 #else
455 base::ProcessHandle handle = SpawnChild(name); 456 base::Process process = SpawnChild(name);
456 #endif 457 #endif
457 EXPECT_TRUE(handle); 458 EXPECT_TRUE(process.IsValid());
458 return handle; 459 return process.Pass();
459 } 460 }
460 461
461 void CloudPrintProxyPolicyStartupTest::WaitForConnect() { 462 void CloudPrintProxyPolicyStartupTest::WaitForConnect() {
462 observer_.Wait(); 463 observer_.Wait();
463 EXPECT_TRUE(CheckServiceProcessReady()); 464 EXPECT_TRUE(CheckServiceProcessReady());
464 EXPECT_TRUE(base::MessageLoopProxy::current().get()); 465 EXPECT_TRUE(base::MessageLoopProxy::current().get());
465 ServiceProcessControl::GetInstance()->SetChannel( 466 ServiceProcessControl::GetInstance()->SetChannel(
466 IPC::ChannelProxy::Create(GetServiceProcessChannel(), 467 IPC::ChannelProxy::Create(GetServiceProcessChannel(),
467 IPC::Channel::MODE_NAMED_CLIENT, 468 IPC::Channel::MODE_NAMED_CLIENT,
468 ServiceProcessControl::GetInstance(), 469 ServiceProcessControl::GetInstance(),
469 IOMessageLoopProxy())); 470 IOMessageLoopProxy()));
470 } 471 }
471 472
472 bool CloudPrintProxyPolicyStartupTest::Send(IPC::Message* message) { 473 bool CloudPrintProxyPolicyStartupTest::Send(IPC::Message* message) {
473 return ServiceProcessControl::GetInstance()->Send(message); 474 return ServiceProcessControl::GetInstance()->Send(message);
474 } 475 }
475 476
476 void CloudPrintProxyPolicyStartupTest::ShutdownAndWaitForExitWithTimeout( 477 void CloudPrintProxyPolicyStartupTest::ShutdownAndWaitForExitWithTimeout(
477 base::ProcessHandle handle) { 478 base::Process process) {
478 ASSERT_TRUE(Send(new ServiceMsg_Shutdown())); 479 ASSERT_TRUE(Send(new ServiceMsg_Shutdown()));
479 480
480 int exit_code = -100; 481 int exit_code = -100;
481 bool exited = 482 bool exited = process.WaitForExitWithTimeout(TestTimeouts::action_timeout(),
482 base::WaitForExitCodeWithTimeout(handle, &exit_code, 483 &exit_code);
483 TestTimeouts::action_timeout());
484 EXPECT_TRUE(exited); 484 EXPECT_TRUE(exited);
485 EXPECT_EQ(exit_code, 0); 485 EXPECT_EQ(exit_code, 0);
486 base::CloseProcessHandle(handle);
487 } 486 }
488 487
489 void CloudPrintProxyPolicyStartupTest::OnChannelConnected(int32 peer_pid) { 488 void CloudPrintProxyPolicyStartupTest::OnChannelConnected(int32 peer_pid) {
490 observer_.Notify(); 489 observer_.Notify();
491 } 490 }
492 491
493 base::CommandLine CloudPrintProxyPolicyStartupTest::MakeCmdLine( 492 base::CommandLine CloudPrintProxyPolicyStartupTest::MakeCmdLine(
494 const std::string& procname) { 493 const std::string& procname) {
495 base::CommandLine cl = MultiProcessTest::MakeCmdLine(procname); 494 base::CommandLine cl = MultiProcessTest::MakeCmdLine(procname);
496 cl.AppendSwitchASCII(switches::kProcessChannelID, startup_channel_id_); 495 cl.AppendSwitchASCII(switches::kProcessChannelID, startup_channel_id_);
497 #if defined(OS_MACOSX) 496 #if defined(OS_MACOSX)
498 cl.AppendSwitchASCII(kTestExecutablePath, executable_path_.value()); 497 cl.AppendSwitchASCII(kTestExecutablePath, executable_path_.value());
499 #endif 498 #endif
500 return cl; 499 return cl;
501 } 500 }
502 501
503 TEST_F(CloudPrintProxyPolicyStartupTest, StartAndShutdown) { 502 TEST_F(CloudPrintProxyPolicyStartupTest, StartAndShutdown) {
504 TestingBrowserProcess* browser_process = 503 TestingBrowserProcess* browser_process =
505 TestingBrowserProcess::GetGlobal(); 504 TestingBrowserProcess::GetGlobal();
506 TestingProfileManager profile_manager(browser_process); 505 TestingProfileManager profile_manager(browser_process);
507 ASSERT_TRUE(profile_manager.SetUp()); 506 ASSERT_TRUE(profile_manager.SetUp());
508 507
509 // Must be created after the TestingProfileManager since that creates the 508 // Must be created after the TestingProfileManager since that creates the
510 // LocalState for the BrowserProcess. Must be created before profiles are 509 // LocalState for the BrowserProcess. Must be created before profiles are
511 // constructed. 510 // constructed.
512 chrome::TestingIOThreadState testing_io_thread_state; 511 chrome::TestingIOThreadState testing_io_thread_state;
513 512
514 base::ProcessHandle handle = 513 base::Process process =
515 Launch("CloudPrintMockService_StartEnabledWaitForQuit"); 514 Launch("CloudPrintMockService_StartEnabledWaitForQuit");
516 WaitForConnect(); 515 WaitForConnect();
517 ShutdownAndWaitForExitWithTimeout(handle); 516 ShutdownAndWaitForExitWithTimeout(process.Pass());
518 content::RunAllPendingInMessageLoop(); 517 content::RunAllPendingInMessageLoop();
519 } 518 }
520 519
521 KeyedService* CloudPrintProxyServiceFactoryForPolicyTest( 520 KeyedService* CloudPrintProxyServiceFactoryForPolicyTest(
522 content::BrowserContext* profile) { 521 content::BrowserContext* profile) {
523 CloudPrintProxyService* service = 522 CloudPrintProxyService* service =
524 new CloudPrintProxyService(static_cast<Profile*>(profile)); 523 new CloudPrintProxyService(static_cast<Profile*>(profile));
525 service->Initialize(); 524 service->Initialize();
526 return service; 525 return service;
527 } 526 }
528 527
529 TEST_F(CloudPrintProxyPolicyStartupTest, StartBrowserWithoutPolicy) { 528 TEST_F(CloudPrintProxyPolicyStartupTest, StartBrowserWithoutPolicy) {
530 base::ProcessHandle handle = 529 base::Process process =
531 Launch("CloudPrintMockService_StartEnabledWaitForQuit"); 530 Launch("CloudPrintMockService_StartEnabledWaitForQuit");
532 531
533 // Setup the Browser Process with a full IOThread::Globals. 532 // Setup the Browser Process with a full IOThread::Globals.
534 TestingBrowserProcess* browser_process = 533 TestingBrowserProcess* browser_process =
535 TestingBrowserProcess::GetGlobal(); 534 TestingBrowserProcess::GetGlobal();
536 535
537 TestingProfileManager profile_manager(browser_process); 536 TestingProfileManager profile_manager(browser_process);
538 ASSERT_TRUE(profile_manager.SetUp()); 537 ASSERT_TRUE(profile_manager.SetUp());
539 538
540 // Must be created after the TestingProfileManager since that creates the 539 // Must be created after the TestingProfileManager since that creates the
(...skipping 23 matching lines...) Expand all
564 TestTimeouts::action_timeout()); 563 TestTimeouts::action_timeout());
565 564
566 bool should_run_loop = LaunchBrowser(command_line, profile); 565 bool should_run_loop = LaunchBrowser(command_line, profile);
567 EXPECT_FALSE(should_run_loop); 566 EXPECT_FALSE(should_run_loop);
568 if (should_run_loop) 567 if (should_run_loop)
569 run_loop.Run(); 568 run_loop.Run();
570 569
571 EXPECT_EQ(MockServiceIPCServer::EnabledUserId(), 570 EXPECT_EQ(MockServiceIPCServer::EnabledUserId(),
572 prefs->GetString(prefs::kCloudPrintEmail)); 571 prefs->GetString(prefs::kCloudPrintEmail));
573 572
574 ShutdownAndWaitForExitWithTimeout(handle); 573 ShutdownAndWaitForExitWithTimeout(process.Pass());
575 content::RunAllPendingInMessageLoop(); 574 content::RunAllPendingInMessageLoop();
576 profile_manager.DeleteTestingProfile("StartBrowserWithoutPolicy"); 575 profile_manager.DeleteTestingProfile("StartBrowserWithoutPolicy");
577 } 576 }
578 577
579 TEST_F(CloudPrintProxyPolicyStartupTest, StartBrowserWithPolicy) { 578 TEST_F(CloudPrintProxyPolicyStartupTest, StartBrowserWithPolicy) {
580 base::ProcessHandle handle = 579 base::Process process =
581 Launch("CloudPrintMockService_StartEnabledExpectDisabled"); 580 Launch("CloudPrintMockService_StartEnabledExpectDisabled");
582 581
583 TestingBrowserProcess* browser_process = 582 TestingBrowserProcess* browser_process =
584 TestingBrowserProcess::GetGlobal(); 583 TestingBrowserProcess::GetGlobal();
585 TestingProfileManager profile_manager(browser_process); 584 TestingProfileManager profile_manager(browser_process);
586 ASSERT_TRUE(profile_manager.SetUp()); 585 ASSERT_TRUE(profile_manager.SetUp());
587 586
588 // Must be created after the TestingProfileManager since that creates the 587 // Must be created after the TestingProfileManager since that creates the
589 // LocalState for the BrowserProcess. Must be created before profiles are 588 // LocalState for the BrowserProcess. Must be created before profiles are
590 // constructed. 589 // constructed.
(...skipping 24 matching lines...) Expand all
615 614
616 bool should_run_loop = LaunchBrowser(command_line, profile); 615 bool should_run_loop = LaunchBrowser(command_line, profile);
617 616
618 // No expectations on run_loop being true here; that would be a race 617 // No expectations on run_loop being true here; that would be a race
619 // condition. 618 // condition.
620 if (should_run_loop) 619 if (should_run_loop)
621 run_loop.Run(); 620 run_loop.Run();
622 621
623 EXPECT_EQ("", prefs->GetString(prefs::kCloudPrintEmail)); 622 EXPECT_EQ("", prefs->GetString(prefs::kCloudPrintEmail));
624 623
625 ShutdownAndWaitForExitWithTimeout(handle); 624 ShutdownAndWaitForExitWithTimeout(process.Pass());
626 content::RunAllPendingInMessageLoop(); 625 content::RunAllPendingInMessageLoop();
627 profile_manager.DeleteTestingProfile("StartBrowserWithPolicy"); 626 profile_manager.DeleteTestingProfile("StartBrowserWithPolicy");
628 } 627 }
OLDNEW
« no previous file with comments | « base/test/multiprocess_test_android.cc ('k') | chrome/common/multi_process_lock_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698