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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 } // namespace | 86 } // namespace |
87 | 87 |
88 class TestServiceProcess : public ServiceProcess { | 88 class TestServiceProcess : public ServiceProcess { |
89 public: | 89 public: |
90 TestServiceProcess() { } | 90 TestServiceProcess() { } |
91 virtual ~TestServiceProcess() { } | 91 virtual ~TestServiceProcess() { } |
92 | 92 |
93 bool Initialize(MessageLoopForUI* message_loop, ServiceProcessState* state); | 93 bool Initialize(MessageLoopForUI* message_loop, ServiceProcessState* state); |
94 | 94 |
95 base::MessageLoopProxy* IOMessageLoopProxy() { | 95 base::MessageLoopProxy* IOMessageLoopProxy() { |
96 return io_thread_->message_loop_proxy(); | 96 return io_thread_->message_loop_proxy().get(); |
97 } | 97 } |
98 }; | 98 }; |
99 | 99 |
100 bool TestServiceProcess::Initialize(MessageLoopForUI* message_loop, | 100 bool TestServiceProcess::Initialize(MessageLoopForUI* message_loop, |
101 ServiceProcessState* state) { | 101 ServiceProcessState* state) { |
102 main_message_loop_ = message_loop; | 102 main_message_loop_ = message_loop; |
103 | 103 |
104 service_process_state_.reset(state); | 104 service_process_state_.reset(state); |
105 | 105 |
106 base::Thread::Options options(MessageLoop::TYPE_IO, 0); | 106 base::Thread::Options options(MessageLoop::TYPE_IO, 0); |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 } | 280 } |
281 | 281 |
282 class CloudPrintProxyPolicyStartupTest : public base::MultiProcessTest, | 282 class CloudPrintProxyPolicyStartupTest : public base::MultiProcessTest, |
283 public IPC::Listener { | 283 public IPC::Listener { |
284 public: | 284 public: |
285 CloudPrintProxyPolicyStartupTest(); | 285 CloudPrintProxyPolicyStartupTest(); |
286 ~CloudPrintProxyPolicyStartupTest(); | 286 ~CloudPrintProxyPolicyStartupTest(); |
287 | 287 |
288 virtual void SetUp(); | 288 virtual void SetUp(); |
289 base::MessageLoopProxy* IOMessageLoopProxy() { | 289 base::MessageLoopProxy* IOMessageLoopProxy() { |
290 return io_thread_.message_loop_proxy(); | 290 return io_thread_.message_loop_proxy().get(); |
291 } | 291 } |
292 base::ProcessHandle Launch(const std::string& name); | 292 base::ProcessHandle Launch(const std::string& name); |
293 void WaitForConnect(); | 293 void WaitForConnect(); |
294 bool Send(IPC::Message* message); | 294 bool Send(IPC::Message* message); |
295 void ShutdownAndWaitForExitWithTimeout(base::ProcessHandle handle); | 295 void ShutdownAndWaitForExitWithTimeout(base::ProcessHandle handle); |
296 | 296 |
297 // IPC::Listener implementation | 297 // IPC::Listener implementation |
298 virtual bool OnMessageReceived(const IPC::Message& message) { return false; } | 298 virtual bool OnMessageReceived(const IPC::Message& message) { return false; } |
299 virtual void OnChannelConnected(int32 peer_pid); | 299 virtual void OnChannelConnected(int32 peer_pid); |
300 | 300 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 #else | 399 #else |
400 base::ProcessHandle handle = SpawnChild(name, false); | 400 base::ProcessHandle handle = SpawnChild(name, false); |
401 #endif | 401 #endif |
402 EXPECT_TRUE(handle); | 402 EXPECT_TRUE(handle); |
403 return handle; | 403 return handle; |
404 } | 404 } |
405 | 405 |
406 void CloudPrintProxyPolicyStartupTest::WaitForConnect() { | 406 void CloudPrintProxyPolicyStartupTest::WaitForConnect() { |
407 observer_.Wait(); | 407 observer_.Wait(); |
408 EXPECT_TRUE(CheckServiceProcessReady()); | 408 EXPECT_TRUE(CheckServiceProcessReady()); |
409 EXPECT_TRUE(base::MessageLoopProxy::current()); | 409 EXPECT_TRUE(base::MessageLoopProxy::current().get()); |
410 ServiceProcessControl::GetInstance()->SetChannel(new IPC::ChannelProxy( | 410 ServiceProcessControl::GetInstance()->SetChannel(new IPC::ChannelProxy( |
411 GetServiceProcessChannel(), IPC::Channel::MODE_NAMED_CLIENT, | 411 GetServiceProcessChannel(), IPC::Channel::MODE_NAMED_CLIENT, |
412 ServiceProcessControl::GetInstance(), IOMessageLoopProxy())); | 412 ServiceProcessControl::GetInstance(), IOMessageLoopProxy())); |
413 } | 413 } |
414 | 414 |
415 bool CloudPrintProxyPolicyStartupTest::Send(IPC::Message* message) { | 415 bool CloudPrintProxyPolicyStartupTest::Send(IPC::Message* message) { |
416 return ServiceProcessControl::GetInstance()->Send(message); | 416 return ServiceProcessControl::GetInstance()->Send(message); |
417 } | 417 } |
418 | 418 |
419 void CloudPrintProxyPolicyStartupTest::ShutdownAndWaitForExitWithTimeout( | 419 void CloudPrintProxyPolicyStartupTest::ShutdownAndWaitForExitWithTimeout( |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 // No expectations on run_loop being true here; that would be a race | 533 // No expectations on run_loop being true here; that would be a race |
534 // condition. | 534 // condition. |
535 if (run_loop) | 535 if (run_loop) |
536 MessageLoop::current()->Run(); | 536 MessageLoop::current()->Run(); |
537 | 537 |
538 EXPECT_EQ("", prefs->GetString(prefs::kCloudPrintEmail)); | 538 EXPECT_EQ("", prefs->GetString(prefs::kCloudPrintEmail)); |
539 | 539 |
540 ShutdownAndWaitForExitWithTimeout(handle); | 540 ShutdownAndWaitForExitWithTimeout(handle); |
541 profile_manager.DeleteTestingProfile("StartBrowserWithPolicy"); | 541 profile_manager.DeleteTestingProfile("StartBrowserWithPolicy"); |
542 } | 542 } |
OLD | NEW |