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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 | 300 |
301 class CloudPrintProxyPolicyStartupTest : public base::MultiProcessTest, | 301 class CloudPrintProxyPolicyStartupTest : public base::MultiProcessTest, |
302 public IPC::Listener { | 302 public IPC::Listener { |
303 public: | 303 public: |
304 CloudPrintProxyPolicyStartupTest(); | 304 CloudPrintProxyPolicyStartupTest(); |
305 ~CloudPrintProxyPolicyStartupTest() override; | 305 ~CloudPrintProxyPolicyStartupTest() override; |
306 | 306 |
307 void SetUp() override; | 307 void SetUp() override; |
308 void TearDown() override; | 308 void TearDown() override; |
309 | 309 |
310 scoped_refptr<base::MessageLoopProxy> IOMessageLoopProxy() { | 310 scoped_refptr<base::SingleThreadTaskRunner> IOTaskRunner() { |
311 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | 311 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
312 } | 312 } |
313 base::Process Launch(const std::string& name); | 313 base::Process Launch(const std::string& name); |
314 void WaitForConnect(); | 314 void WaitForConnect(); |
315 bool Send(IPC::Message* message); | 315 bool Send(IPC::Message* message); |
316 void ShutdownAndWaitForExitWithTimeout(base::Process process); | 316 void ShutdownAndWaitForExitWithTimeout(base::Process process); |
317 | 317 |
318 // IPC::Listener implementation | 318 // IPC::Listener implementation |
319 bool OnMessageReceived(const IPC::Message& message) override { return false; } | 319 bool OnMessageReceived(const IPC::Message& message) override { return false; } |
320 void OnChannelConnected(int32 peer_pid) override; | 320 void OnChannelConnected(int32 peer_pid) override; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 const std::string& name) { | 435 const std::string& name) { |
436 EXPECT_FALSE(CheckServiceProcessReady()); | 436 EXPECT_FALSE(CheckServiceProcessReady()); |
437 | 437 |
438 startup_channel_id_ = | 438 startup_channel_id_ = |
439 base::StringPrintf("%d.%p.%d", | 439 base::StringPrintf("%d.%p.%d", |
440 base::GetCurrentProcId(), this, | 440 base::GetCurrentProcId(), this, |
441 base::RandInt(0, std::numeric_limits<int>::max())); | 441 base::RandInt(0, std::numeric_limits<int>::max())); |
442 startup_channel_ = IPC::ChannelProxy::Create(startup_channel_id_, | 442 startup_channel_ = IPC::ChannelProxy::Create(startup_channel_id_, |
443 IPC::Channel::MODE_SERVER, | 443 IPC::Channel::MODE_SERVER, |
444 this, | 444 this, |
445 IOMessageLoopProxy()); | 445 IOTaskRunner()); |
446 | 446 |
447 #if defined(OS_POSIX) | 447 #if defined(OS_POSIX) |
448 base::FileHandleMappingVector ipc_file_list; | 448 base::FileHandleMappingVector ipc_file_list; |
449 ipc_file_list.push_back(std::make_pair( | 449 ipc_file_list.push_back(std::make_pair( |
450 startup_channel_->TakeClientFileDescriptor().release(), | 450 startup_channel_->TakeClientFileDescriptor().release(), |
451 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor)); | 451 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor)); |
452 base::LaunchOptions options; | 452 base::LaunchOptions options; |
453 options.fds_to_remap = &ipc_file_list; | 453 options.fds_to_remap = &ipc_file_list; |
454 base::Process process = SpawnChildWithOptions(name, options); | 454 base::Process process = SpawnChildWithOptions(name, options); |
455 #else | 455 #else |
456 base::Process process = SpawnChild(name); | 456 base::Process process = SpawnChild(name); |
457 #endif | 457 #endif |
458 EXPECT_TRUE(process.IsValid()); | 458 EXPECT_TRUE(process.IsValid()); |
459 return process.Pass(); | 459 return process.Pass(); |
460 } | 460 } |
461 | 461 |
462 void CloudPrintProxyPolicyStartupTest::WaitForConnect() { | 462 void CloudPrintProxyPolicyStartupTest::WaitForConnect() { |
463 observer_.Wait(); | 463 observer_.Wait(); |
464 EXPECT_TRUE(CheckServiceProcessReady()); | 464 EXPECT_TRUE(CheckServiceProcessReady()); |
465 EXPECT_TRUE(base::MessageLoopProxy::current().get()); | 465 EXPECT_TRUE(base::MessageLoopProxy::current().get()); |
466 ServiceProcessControl::GetInstance()->SetChannel( | 466 ServiceProcessControl::GetInstance()->SetChannel( |
467 IPC::ChannelProxy::Create(GetServiceProcessChannel(), | 467 IPC::ChannelProxy::Create(GetServiceProcessChannel(), |
468 IPC::Channel::MODE_NAMED_CLIENT, | 468 IPC::Channel::MODE_NAMED_CLIENT, |
469 ServiceProcessControl::GetInstance(), | 469 ServiceProcessControl::GetInstance(), |
470 IOMessageLoopProxy())); | 470 IOTaskRunner())); |
471 } | 471 } |
472 | 472 |
473 bool CloudPrintProxyPolicyStartupTest::Send(IPC::Message* message) { | 473 bool CloudPrintProxyPolicyStartupTest::Send(IPC::Message* message) { |
474 return ServiceProcessControl::GetInstance()->Send(message); | 474 return ServiceProcessControl::GetInstance()->Send(message); |
475 } | 475 } |
476 | 476 |
477 void CloudPrintProxyPolicyStartupTest::ShutdownAndWaitForExitWithTimeout( | 477 void CloudPrintProxyPolicyStartupTest::ShutdownAndWaitForExitWithTimeout( |
478 base::Process process) { | 478 base::Process process) { |
479 ASSERT_TRUE(Send(new ServiceMsg_Shutdown())); | 479 ASSERT_TRUE(Send(new ServiceMsg_Shutdown())); |
480 | 480 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 } | 518 } |
519 | 519 |
520 KeyedService* CloudPrintProxyServiceFactoryForPolicyTest( | 520 KeyedService* CloudPrintProxyServiceFactoryForPolicyTest( |
521 content::BrowserContext* profile) { | 521 content::BrowserContext* profile) { |
522 CloudPrintProxyService* service = | 522 CloudPrintProxyService* service = |
523 new CloudPrintProxyService(static_cast<Profile*>(profile)); | 523 new CloudPrintProxyService(static_cast<Profile*>(profile)); |
524 service->Initialize(); | 524 service->Initialize(); |
525 return service; | 525 return service; |
526 } | 526 } |
527 | 527 |
OLD | NEW |