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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 | 259 |
260 // Connect up the parent/child IPC channel to signal that the test can | 260 // Connect up the parent/child IPC channel to signal that the test can |
261 // continue. | 261 // continue. |
262 TestStartupClientChannelListener listener; | 262 TestStartupClientChannelListener listener; |
263 EXPECT_TRUE(CommandLine::ForCurrentProcess()->HasSwitch( | 263 EXPECT_TRUE(CommandLine::ForCurrentProcess()->HasSwitch( |
264 switches::kProcessChannelID)); | 264 switches::kProcessChannelID)); |
265 std::string startup_channel_name = | 265 std::string startup_channel_name = |
266 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 266 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
267 switches::kProcessChannelID); | 267 switches::kProcessChannelID); |
268 scoped_ptr<IPC::ChannelProxy> startup_channel; | 268 scoped_ptr<IPC::ChannelProxy> startup_channel; |
269 startup_channel.reset( | 269 startup_channel = IPC::ChannelProxy::CreateClient( |
270 new IPC::ChannelProxy(startup_channel_name, | 270 startup_channel_name, |
271 IPC::Channel::MODE_CLIENT, | 271 &listener, |
272 &listener, | 272 service_process.IOMessageLoopProxy()); |
273 service_process.IOMessageLoopProxy())); | |
274 | 273 |
275 main_message_loop.Run(); | 274 main_message_loop.Run(); |
276 if (!Mock::VerifyAndClearExpectations(&server)) | 275 if (!Mock::VerifyAndClearExpectations(&server)) |
277 return kExpectationsNotMet; | 276 return kExpectationsNotMet; |
278 if (!g_good_shutdown) | 277 if (!g_good_shutdown) |
279 return kShutdownNotGood; | 278 return kShutdownNotGood; |
280 return 0; | 279 return 0; |
281 } | 280 } |
282 | 281 |
283 void SetServiceEnabledExpectations(MockServiceIPCServer* server) { | 282 void SetServiceEnabledExpectations(MockServiceIPCServer* server) { |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 } | 434 } |
436 | 435 |
437 base::ProcessHandle CloudPrintProxyPolicyStartupTest::Launch( | 436 base::ProcessHandle CloudPrintProxyPolicyStartupTest::Launch( |
438 const std::string& name) { | 437 const std::string& name) { |
439 EXPECT_FALSE(CheckServiceProcessReady()); | 438 EXPECT_FALSE(CheckServiceProcessReady()); |
440 | 439 |
441 startup_channel_id_ = | 440 startup_channel_id_ = |
442 base::StringPrintf("%d.%p.%d", | 441 base::StringPrintf("%d.%p.%d", |
443 base::GetCurrentProcId(), this, | 442 base::GetCurrentProcId(), this, |
444 base::RandInt(0, std::numeric_limits<int>::max())); | 443 base::RandInt(0, std::numeric_limits<int>::max())); |
445 startup_channel_.reset(new IPC::ChannelProxy( | 444 startup_channel_ = IPC::ChannelProxy::CreateServer( |
446 startup_channel_id_, IPC::Channel::MODE_SERVER, | 445 startup_channel_id_, this, IOMessageLoopProxy()); |
447 this, IOMessageLoopProxy())); | |
448 | 446 |
449 #if defined(OS_POSIX) | 447 #if defined(OS_POSIX) |
450 base::FileHandleMappingVector ipc_file_list; | 448 base::FileHandleMappingVector ipc_file_list; |
451 ipc_file_list.push_back(std::make_pair( | 449 ipc_file_list.push_back(std::make_pair( |
452 startup_channel_->TakeClientFileDescriptor(), | 450 startup_channel_->TakeClientFileDescriptor(), |
453 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor)); | 451 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor)); |
454 base::LaunchOptions options; | 452 base::LaunchOptions options; |
455 options.fds_to_remap = &ipc_file_list; | 453 options.fds_to_remap = &ipc_file_list; |
456 base::ProcessHandle handle = SpawnChildWithOptions(name, options); | 454 base::ProcessHandle handle = SpawnChildWithOptions(name, options); |
457 #else | 455 #else |
458 base::ProcessHandle handle = SpawnChild(name); | 456 base::ProcessHandle handle = SpawnChild(name); |
459 #endif | 457 #endif |
460 EXPECT_TRUE(handle); | 458 EXPECT_TRUE(handle); |
461 return handle; | 459 return handle; |
462 } | 460 } |
463 | 461 |
464 void CloudPrintProxyPolicyStartupTest::WaitForConnect() { | 462 void CloudPrintProxyPolicyStartupTest::WaitForConnect() { |
465 observer_.Wait(); | 463 observer_.Wait(); |
466 EXPECT_TRUE(CheckServiceProcessReady()); | 464 EXPECT_TRUE(CheckServiceProcessReady()); |
467 EXPECT_TRUE(base::MessageLoopProxy::current().get()); | 465 EXPECT_TRUE(base::MessageLoopProxy::current().get()); |
468 ServiceProcessControl::GetInstance()->SetChannel( | 466 ServiceProcessControl::GetInstance()->SetChannel( |
469 new IPC::ChannelProxy(GetServiceProcessChannel(), | 467 IPC::ChannelProxy::CreateNamedClient( |
470 IPC::Channel::MODE_NAMED_CLIENT, | 468 GetServiceProcessChannel(), |
471 ServiceProcessControl::GetInstance(), | 469 ServiceProcessControl::GetInstance(), |
472 IOMessageLoopProxy())); | 470 IOMessageLoopProxy())); |
473 } | 471 } |
474 | 472 |
475 bool CloudPrintProxyPolicyStartupTest::Send(IPC::Message* message) { | 473 bool CloudPrintProxyPolicyStartupTest::Send(IPC::Message* message) { |
476 return ServiceProcessControl::GetInstance()->Send(message); | 474 return ServiceProcessControl::GetInstance()->Send(message); |
477 } | 475 } |
478 | 476 |
479 void CloudPrintProxyPolicyStartupTest::ShutdownAndWaitForExitWithTimeout( | 477 void CloudPrintProxyPolicyStartupTest::ShutdownAndWaitForExitWithTimeout( |
480 base::ProcessHandle handle) { | 478 base::ProcessHandle handle) { |
481 ASSERT_TRUE(Send(new ServiceMsg_Shutdown())); | 479 ASSERT_TRUE(Send(new ServiceMsg_Shutdown())); |
482 | 480 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 // condition. | 620 // condition. |
623 if (should_run_loop) | 621 if (should_run_loop) |
624 run_loop.Run(); | 622 run_loop.Run(); |
625 | 623 |
626 EXPECT_EQ("", prefs->GetString(prefs::kCloudPrintEmail)); | 624 EXPECT_EQ("", prefs->GetString(prefs::kCloudPrintEmail)); |
627 | 625 |
628 ShutdownAndWaitForExitWithTimeout(handle); | 626 ShutdownAndWaitForExitWithTimeout(handle); |
629 content::RunAllPendingInMessageLoop(); | 627 content::RunAllPendingInMessageLoop(); |
630 profile_manager.DeleteTestingProfile("StartBrowserWithPolicy"); | 628 profile_manager.DeleteTestingProfile("StartBrowserWithPolicy"); |
631 } | 629 } |
OLD | NEW |