| 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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 | 261 |
| 262 // Connect up the parent/child IPC channel to signal that the test can | 262 // Connect up the parent/child IPC channel to signal that the test can |
| 263 // continue. | 263 // continue. |
| 264 TestStartupClientChannelListener listener; | 264 TestStartupClientChannelListener listener; |
| 265 EXPECT_TRUE(base::CommandLine::ForCurrentProcess()->HasSwitch( | 265 EXPECT_TRUE(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 266 switches::kProcessChannelID)); | 266 switches::kProcessChannelID)); |
| 267 std::string startup_channel_name = | 267 std::string startup_channel_name = |
| 268 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 268 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 269 switches::kProcessChannelID); | 269 switches::kProcessChannelID); |
| 270 scoped_ptr<IPC::ChannelProxy> startup_channel; | 270 scoped_ptr<IPC::ChannelProxy> startup_channel; |
| 271 startup_channel = | 271 startup_channel = IPC::ChannelProxy::Create( |
| 272 IPC::ChannelProxy::Create(startup_channel_name, | 272 startup_channel_name, IPC::Channel::MODE_CLIENT, &listener, |
| 273 IPC::Channel::MODE_CLIENT, | 273 service_process.IOMessageLoopProxy(), nullptr); |
| 274 &listener, | |
| 275 service_process.IOMessageLoopProxy()); | |
| 276 | 274 |
| 277 main_message_loop.Run(); | 275 main_message_loop.Run(); |
| 278 if (!Mock::VerifyAndClearExpectations(&server)) | 276 if (!Mock::VerifyAndClearExpectations(&server)) |
| 279 return kExpectationsNotMet; | 277 return kExpectationsNotMet; |
| 280 if (!g_good_shutdown) | 278 if (!g_good_shutdown) |
| 281 return kShutdownNotGood; | 279 return kShutdownNotGood; |
| 282 return 0; | 280 return 0; |
| 283 } | 281 } |
| 284 | 282 |
| 285 void SetServiceEnabledExpectations(MockServiceIPCServer* server) { | 283 void SetServiceEnabledExpectations(MockServiceIPCServer* server) { |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 } | 432 } |
| 435 | 433 |
| 436 base::Process CloudPrintProxyPolicyStartupTest::Launch( | 434 base::Process CloudPrintProxyPolicyStartupTest::Launch( |
| 437 const std::string& name) { | 435 const std::string& name) { |
| 438 EXPECT_FALSE(CheckServiceProcessReady()); | 436 EXPECT_FALSE(CheckServiceProcessReady()); |
| 439 | 437 |
| 440 startup_channel_id_ = | 438 startup_channel_id_ = |
| 441 base::StringPrintf("%d.%p.%d", | 439 base::StringPrintf("%d.%p.%d", |
| 442 base::GetCurrentProcId(), this, | 440 base::GetCurrentProcId(), this, |
| 443 base::RandInt(0, std::numeric_limits<int>::max())); | 441 base::RandInt(0, std::numeric_limits<int>::max())); |
| 444 startup_channel_ = IPC::ChannelProxy::Create(startup_channel_id_, | 442 startup_channel_ = |
| 445 IPC::Channel::MODE_SERVER, | 443 IPC::ChannelProxy::Create(startup_channel_id_, IPC::Channel::MODE_SERVER, |
| 446 this, | 444 this, IOTaskRunner(), nullptr); |
| 447 IOTaskRunner()); | |
| 448 | 445 |
| 449 #if defined(OS_POSIX) | 446 #if defined(OS_POSIX) |
| 450 base::FileHandleMappingVector ipc_file_list; | 447 base::FileHandleMappingVector ipc_file_list; |
| 451 ipc_file_list.push_back(std::make_pair( | 448 ipc_file_list.push_back(std::make_pair( |
| 452 startup_channel_->TakeClientFileDescriptor().release(), | 449 startup_channel_->TakeClientFileDescriptor().release(), |
| 453 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor)); | 450 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor)); |
| 454 base::LaunchOptions options; | 451 base::LaunchOptions options; |
| 455 options.fds_to_remap = &ipc_file_list; | 452 options.fds_to_remap = &ipc_file_list; |
| 456 base::Process process = SpawnChildWithOptions(name, options); | 453 base::Process process = SpawnChildWithOptions(name, options); |
| 457 #else | 454 #else |
| 458 base::Process process = SpawnChild(name); | 455 base::Process process = SpawnChild(name); |
| 459 #endif | 456 #endif |
| 460 EXPECT_TRUE(process.IsValid()); | 457 EXPECT_TRUE(process.IsValid()); |
| 461 return process.Pass(); | 458 return process.Pass(); |
| 462 } | 459 } |
| 463 | 460 |
| 464 void CloudPrintProxyPolicyStartupTest::WaitForConnect() { | 461 void CloudPrintProxyPolicyStartupTest::WaitForConnect() { |
| 465 observer_.Wait(); | 462 observer_.Wait(); |
| 466 EXPECT_TRUE(CheckServiceProcessReady()); | 463 EXPECT_TRUE(CheckServiceProcessReady()); |
| 467 EXPECT_TRUE(base::ThreadTaskRunnerHandle::Get().get()); | 464 EXPECT_TRUE(base::ThreadTaskRunnerHandle::Get().get()); |
| 468 ServiceProcessControl::GetInstance()->SetChannel( | 465 ServiceProcessControl::GetInstance()->SetChannel(IPC::ChannelProxy::Create( |
| 469 IPC::ChannelProxy::Create(GetServiceProcessChannel(), | 466 GetServiceProcessChannel(), IPC::Channel::MODE_NAMED_CLIENT, |
| 470 IPC::Channel::MODE_NAMED_CLIENT, | 467 ServiceProcessControl::GetInstance(), IOTaskRunner(), nullptr)); |
| 471 ServiceProcessControl::GetInstance(), | |
| 472 IOTaskRunner())); | |
| 473 } | 468 } |
| 474 | 469 |
| 475 bool CloudPrintProxyPolicyStartupTest::Send(IPC::Message* message) { | 470 bool CloudPrintProxyPolicyStartupTest::Send(IPC::Message* message) { |
| 476 return ServiceProcessControl::GetInstance()->Send(message); | 471 return ServiceProcessControl::GetInstance()->Send(message); |
| 477 } | 472 } |
| 478 | 473 |
| 479 void CloudPrintProxyPolicyStartupTest::ShutdownAndWaitForExitWithTimeout( | 474 void CloudPrintProxyPolicyStartupTest::ShutdownAndWaitForExitWithTimeout( |
| 480 base::Process process) { | 475 base::Process process) { |
| 481 ASSERT_TRUE(Send(new ServiceMsg_Shutdown())); | 476 ASSERT_TRUE(Send(new ServiceMsg_Shutdown())); |
| 482 | 477 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 } | 515 } |
| 521 | 516 |
| 522 KeyedService* CloudPrintProxyServiceFactoryForPolicyTest( | 517 KeyedService* CloudPrintProxyServiceFactoryForPolicyTest( |
| 523 content::BrowserContext* profile) { | 518 content::BrowserContext* profile) { |
| 524 CloudPrintProxyService* service = | 519 CloudPrintProxyService* service = |
| 525 new CloudPrintProxyService(static_cast<Profile*>(profile)); | 520 new CloudPrintProxyService(static_cast<Profile*>(profile)); |
| 526 service->Initialize(); | 521 service->Initialize(); |
| 527 return service; | 522 return service; |
| 528 } | 523 } |
| 529 | 524 |
| OLD | NEW |