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 // 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" |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 bool Send(IPC::Message* message); | 310 bool Send(IPC::Message* message); |
311 void ShutdownAndWaitForExitWithTimeout(base::ProcessHandle handle); | 311 void ShutdownAndWaitForExitWithTimeout(base::ProcessHandle handle); |
312 | 312 |
313 // IPC::Listener implementation | 313 // IPC::Listener implementation |
314 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { | 314 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { |
315 return false; | 315 return false; |
316 } | 316 } |
317 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | 317 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; |
318 | 318 |
319 // MultiProcessTest implementation. | 319 // MultiProcessTest implementation. |
320 virtual CommandLine MakeCmdLine(const std::string& procname, | 320 virtual CommandLine MakeCmdLine(const std::string& procname) OVERRIDE; |
321 bool debug_on_start) OVERRIDE; | |
322 | 321 |
323 bool LaunchBrowser(const CommandLine& command_line, Profile* profile) { | 322 bool LaunchBrowser(const CommandLine& command_line, Profile* profile) { |
324 int return_code = 0; | 323 int return_code = 0; |
325 StartupBrowserCreator browser_creator; | 324 StartupBrowserCreator browser_creator; |
326 return StartupBrowserCreator::ProcessCmdLineImpl( | 325 return StartupBrowserCreator::ProcessCmdLineImpl( |
327 command_line, base::FilePath(), false, profile, | 326 command_line, base::FilePath(), false, profile, |
328 StartupBrowserCreator::Profiles(), &return_code, &browser_creator); | 327 StartupBrowserCreator::Profiles(), &return_code, &browser_creator); |
329 } | 328 } |
330 | 329 |
331 protected: | 330 protected: |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 startup_channel_id_, IPC::Channel::MODE_SERVER, | 426 startup_channel_id_, IPC::Channel::MODE_SERVER, |
428 this, IOMessageLoopProxy())); | 427 this, IOMessageLoopProxy())); |
429 | 428 |
430 #if defined(OS_POSIX) | 429 #if defined(OS_POSIX) |
431 base::FileHandleMappingVector ipc_file_list; | 430 base::FileHandleMappingVector ipc_file_list; |
432 ipc_file_list.push_back(std::make_pair( | 431 ipc_file_list.push_back(std::make_pair( |
433 startup_channel_->TakeClientFileDescriptor(), | 432 startup_channel_->TakeClientFileDescriptor(), |
434 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor)); | 433 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor)); |
435 base::LaunchOptions options; | 434 base::LaunchOptions options; |
436 options.fds_to_remap = &ipc_file_list; | 435 options.fds_to_remap = &ipc_file_list; |
437 base::ProcessHandle handle = SpawnChildWithOptions(name, options, false); | 436 base::ProcessHandle handle = SpawnChildWithOptions(name, options); |
438 #else | 437 #else |
439 base::ProcessHandle handle = SpawnChild(name, false); | 438 base::ProcessHandle handle = SpawnChild(name); |
440 #endif | 439 #endif |
441 EXPECT_TRUE(handle); | 440 EXPECT_TRUE(handle); |
442 return handle; | 441 return handle; |
443 } | 442 } |
444 | 443 |
445 void CloudPrintProxyPolicyStartupTest::WaitForConnect() { | 444 void CloudPrintProxyPolicyStartupTest::WaitForConnect() { |
446 observer_.Wait(); | 445 observer_.Wait(); |
447 EXPECT_TRUE(CheckServiceProcessReady()); | 446 EXPECT_TRUE(CheckServiceProcessReady()); |
448 EXPECT_TRUE(base::MessageLoopProxy::current().get()); | 447 EXPECT_TRUE(base::MessageLoopProxy::current().get()); |
449 ServiceProcessControl::GetInstance()->SetChannel( | 448 ServiceProcessControl::GetInstance()->SetChannel( |
(...skipping 18 matching lines...) Expand all Loading... |
468 EXPECT_TRUE(exited); | 467 EXPECT_TRUE(exited); |
469 EXPECT_EQ(exit_code, 0); | 468 EXPECT_EQ(exit_code, 0); |
470 base::CloseProcessHandle(handle); | 469 base::CloseProcessHandle(handle); |
471 } | 470 } |
472 | 471 |
473 void CloudPrintProxyPolicyStartupTest::OnChannelConnected(int32 peer_pid) { | 472 void CloudPrintProxyPolicyStartupTest::OnChannelConnected(int32 peer_pid) { |
474 observer_.Notify(); | 473 observer_.Notify(); |
475 } | 474 } |
476 | 475 |
477 CommandLine CloudPrintProxyPolicyStartupTest::MakeCmdLine( | 476 CommandLine CloudPrintProxyPolicyStartupTest::MakeCmdLine( |
478 const std::string& procname, | 477 const std::string& procname) { |
479 bool debug_on_start) { | 478 CommandLine cl = MultiProcessTest::MakeCmdLine(procname); |
480 CommandLine cl = MultiProcessTest::MakeCmdLine(procname, debug_on_start); | |
481 cl.AppendSwitchASCII(switches::kProcessChannelID, startup_channel_id_); | 479 cl.AppendSwitchASCII(switches::kProcessChannelID, startup_channel_id_); |
482 #if defined(OS_MACOSX) | 480 #if defined(OS_MACOSX) |
483 cl.AppendSwitchASCII(kTestExecutablePath, executable_path_.value()); | 481 cl.AppendSwitchASCII(kTestExecutablePath, executable_path_.value()); |
484 #endif | 482 #endif |
485 return cl; | 483 return cl; |
486 } | 484 } |
487 | 485 |
488 TEST_F(CloudPrintProxyPolicyStartupTest, StartAndShutdown) { | 486 TEST_F(CloudPrintProxyPolicyStartupTest, StartAndShutdown) { |
489 TestingBrowserProcess* browser_process = | 487 TestingBrowserProcess* browser_process = |
490 TestingBrowserProcess::GetGlobal(); | 488 TestingBrowserProcess::GetGlobal(); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 // condition. | 602 // condition. |
605 if (should_run_loop) | 603 if (should_run_loop) |
606 run_loop.Run(); | 604 run_loop.Run(); |
607 | 605 |
608 EXPECT_EQ("", prefs->GetString(prefs::kCloudPrintEmail)); | 606 EXPECT_EQ("", prefs->GetString(prefs::kCloudPrintEmail)); |
609 | 607 |
610 ShutdownAndWaitForExitWithTimeout(handle); | 608 ShutdownAndWaitForExitWithTimeout(handle); |
611 content::RunAllPendingInMessageLoop(); | 609 content::RunAllPendingInMessageLoop(); |
612 profile_manager.DeleteTestingProfile("StartBrowserWithPolicy"); | 610 profile_manager.DeleteTestingProfile("StartBrowserWithPolicy"); |
613 } | 611 } |
OLD | NEW |