| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 | 89 |
| 90 class TestServiceProcess : public ServiceProcess { | 90 class TestServiceProcess : public ServiceProcess { |
| 91 public: | 91 public: |
| 92 TestServiceProcess() { } | 92 TestServiceProcess() { } |
| 93 virtual ~TestServiceProcess() { } | 93 virtual ~TestServiceProcess() { } |
| 94 | 94 |
| 95 bool Initialize(base::MessageLoopForUI* message_loop, | 95 bool Initialize(base::MessageLoopForUI* message_loop, |
| 96 ServiceProcessState* state); | 96 ServiceProcessState* state); |
| 97 | 97 |
| 98 base::MessageLoopProxy* IOMessageLoopProxy() { | 98 base::MessageLoopProxy* IOMessageLoopProxy() { |
| 99 return io_thread_->message_loop_proxy(); | 99 return io_thread_->message_loop_proxy().get(); |
| 100 } | 100 } |
| 101 }; | 101 }; |
| 102 | 102 |
| 103 bool TestServiceProcess::Initialize(base::MessageLoopForUI* message_loop, | 103 bool TestServiceProcess::Initialize(base::MessageLoopForUI* message_loop, |
| 104 ServiceProcessState* state) { | 104 ServiceProcessState* state) { |
| 105 main_message_loop_ = message_loop; | 105 main_message_loop_ = message_loop; |
| 106 | 106 |
| 107 service_process_state_.reset(state); | 107 service_process_state_.reset(state); |
| 108 | 108 |
| 109 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0); | 109 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 } | 283 } |
| 284 | 284 |
| 285 class CloudPrintProxyPolicyStartupTest : public base::MultiProcessTest, | 285 class CloudPrintProxyPolicyStartupTest : public base::MultiProcessTest, |
| 286 public IPC::Listener { | 286 public IPC::Listener { |
| 287 public: | 287 public: |
| 288 CloudPrintProxyPolicyStartupTest(); | 288 CloudPrintProxyPolicyStartupTest(); |
| 289 virtual ~CloudPrintProxyPolicyStartupTest(); | 289 virtual ~CloudPrintProxyPolicyStartupTest(); |
| 290 | 290 |
| 291 virtual void SetUp(); | 291 virtual void SetUp(); |
| 292 base::MessageLoopProxy* IOMessageLoopProxy() { | 292 base::MessageLoopProxy* IOMessageLoopProxy() { |
| 293 return io_thread_.message_loop_proxy(); | 293 return io_thread_.message_loop_proxy().get(); |
| 294 } | 294 } |
| 295 base::ProcessHandle Launch(const std::string& name); | 295 base::ProcessHandle Launch(const std::string& name); |
| 296 void WaitForConnect(); | 296 void WaitForConnect(); |
| 297 bool Send(IPC::Message* message); | 297 bool Send(IPC::Message* message); |
| 298 void ShutdownAndWaitForExitWithTimeout(base::ProcessHandle handle); | 298 void ShutdownAndWaitForExitWithTimeout(base::ProcessHandle handle); |
| 299 | 299 |
| 300 // IPC::Listener implementation | 300 // IPC::Listener implementation |
| 301 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { | 301 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { |
| 302 return false; | 302 return false; |
| 303 } | 303 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 #else | 404 #else |
| 405 base::ProcessHandle handle = SpawnChild(name, false); | 405 base::ProcessHandle handle = SpawnChild(name, false); |
| 406 #endif | 406 #endif |
| 407 EXPECT_TRUE(handle); | 407 EXPECT_TRUE(handle); |
| 408 return handle; | 408 return handle; |
| 409 } | 409 } |
| 410 | 410 |
| 411 void CloudPrintProxyPolicyStartupTest::WaitForConnect() { | 411 void CloudPrintProxyPolicyStartupTest::WaitForConnect() { |
| 412 observer_.Wait(); | 412 observer_.Wait(); |
| 413 EXPECT_TRUE(CheckServiceProcessReady()); | 413 EXPECT_TRUE(CheckServiceProcessReady()); |
| 414 EXPECT_TRUE(base::MessageLoopProxy::current()); | 414 EXPECT_TRUE(base::MessageLoopProxy::current().get()); |
| 415 ServiceProcessControl::GetInstance()->SetChannel(new IPC::ChannelProxy( | 415 ServiceProcessControl::GetInstance()->SetChannel( |
| 416 GetServiceProcessChannel(), IPC::Channel::MODE_NAMED_CLIENT, | 416 new IPC::ChannelProxy(GetServiceProcessChannel(), |
| 417 ServiceProcessControl::GetInstance(), IOMessageLoopProxy())); | 417 IPC::Channel::MODE_NAMED_CLIENT, |
| 418 ServiceProcessControl::GetInstance(), |
| 419 IOMessageLoopProxy())); |
| 418 } | 420 } |
| 419 | 421 |
| 420 bool CloudPrintProxyPolicyStartupTest::Send(IPC::Message* message) { | 422 bool CloudPrintProxyPolicyStartupTest::Send(IPC::Message* message) { |
| 421 return ServiceProcessControl::GetInstance()->Send(message); | 423 return ServiceProcessControl::GetInstance()->Send(message); |
| 422 } | 424 } |
| 423 | 425 |
| 424 void CloudPrintProxyPolicyStartupTest::ShutdownAndWaitForExitWithTimeout( | 426 void CloudPrintProxyPolicyStartupTest::ShutdownAndWaitForExitWithTimeout( |
| 425 base::ProcessHandle handle) { | 427 base::ProcessHandle handle) { |
| 426 ASSERT_TRUE(Send(new ServiceMsg_Shutdown())); | 428 ASSERT_TRUE(Send(new ServiceMsg_Shutdown())); |
| 427 | 429 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 // No expectations on run_loop being true here; that would be a race | 543 // No expectations on run_loop being true here; that would be a race |
| 542 // condition. | 544 // condition. |
| 543 if (run_loop) | 545 if (run_loop) |
| 544 base::MessageLoop::current()->Run(); | 546 base::MessageLoop::current()->Run(); |
| 545 | 547 |
| 546 EXPECT_EQ("", prefs->GetString(prefs::kCloudPrintEmail)); | 548 EXPECT_EQ("", prefs->GetString(prefs::kCloudPrintEmail)); |
| 547 | 549 |
| 548 ShutdownAndWaitForExitWithTimeout(handle); | 550 ShutdownAndWaitForExitWithTimeout(handle); |
| 549 profile_manager.DeleteTestingProfile("StartBrowserWithPolicy"); | 551 profile_manager.DeleteTestingProfile("StartBrowserWithPolicy"); |
| 550 } | 552 } |
| OLD | NEW |