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 <stdint.h> |
| 10 |
9 #include "base/bind.h" | 11 #include "base/bind.h" |
10 #include "base/command_line.h" | 12 #include "base/command_line.h" |
11 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
12 #include "base/process/kill.h" | 14 #include "base/process/kill.h" |
13 #include "base/process/process.h" | 15 #include "base/process/process.h" |
14 #include "base/rand_util.h" | 16 #include "base/rand_util.h" |
15 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
16 #include "base/synchronization/waitable_event.h" | 18 #include "base/synchronization/waitable_event.h" |
17 #include "base/test/multiprocess_test.h" | 19 #include "base/test/multiprocess_test.h" |
18 #include "base/test/test_timeouts.h" | 20 #include "base/test/test_timeouts.h" |
19 #include "base/thread_task_runner_handle.h" | 21 #include "base/thread_task_runner_handle.h" |
20 #include "base/time/default_tick_clock.h" | 22 #include "base/time/default_tick_clock.h" |
21 #include "base/time/time.h" | 23 #include "base/time/time.h" |
| 24 #include "build/build_config.h" |
22 #include "chrome/browser/chrome_content_browser_client.h" | 25 #include "chrome/browser/chrome_content_browser_client.h" |
23 #include "chrome/browser/prefs/browser_prefs.h" | 26 #include "chrome/browser/prefs/browser_prefs.h" |
24 #include "chrome/browser/service_process/service_process_control.h" | 27 #include "chrome/browser/service_process/service_process_control.h" |
25 #include "chrome/browser/ui/startup/startup_browser_creator.h" | 28 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
26 #include "chrome/common/chrome_content_client.h" | 29 #include "chrome/common/chrome_content_client.h" |
27 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
28 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
29 #include "chrome/common/service_messages.h" | 32 #include "chrome/common/service_messages.h" |
30 #include "chrome/common/service_process_util.h" | 33 #include "chrome/common/service_process_util.h" |
31 #include "chrome/service/service_ipc_server.h" | 34 #include "chrome/service/service_ipc_server.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 | 125 |
123 MockServiceIPCServer( | 126 MockServiceIPCServer( |
124 ServiceIPCServer::Client* client, | 127 ServiceIPCServer::Client* client, |
125 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, | 128 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, |
126 const IPC::ChannelHandle& handle, | 129 const IPC::ChannelHandle& handle, |
127 base::WaitableEvent* shutdown_event) | 130 base::WaitableEvent* shutdown_event) |
128 : ServiceIPCServer(client, io_task_runner, handle, shutdown_event), | 131 : ServiceIPCServer(client, io_task_runner, handle, shutdown_event), |
129 enabled_(true) { } | 132 enabled_(true) { } |
130 | 133 |
131 MOCK_METHOD1(OnMessageReceived, bool(const IPC::Message& message)); | 134 MOCK_METHOD1(OnMessageReceived, bool(const IPC::Message& message)); |
132 MOCK_METHOD1(OnChannelConnected, void(int32 peer_pid)); | 135 MOCK_METHOD1(OnChannelConnected, void(int32_t peer_pid)); |
133 MOCK_METHOD0(OnChannelError, void()); | 136 MOCK_METHOD0(OnChannelError, void()); |
134 | 137 |
135 void SetServiceEnabledExpectations(); | 138 void SetServiceEnabledExpectations(); |
136 void SetWillBeDisabledExpectations(); | 139 void SetWillBeDisabledExpectations(); |
137 | 140 |
138 void CallServiceOnChannelConnected(int32 peer_pid) { | 141 void CallServiceOnChannelConnected(int32_t peer_pid) { |
139 ServiceIPCServer::OnChannelConnected(peer_pid); | 142 ServiceIPCServer::OnChannelConnected(peer_pid); |
140 } | 143 } |
141 | 144 |
142 bool SendInfo(); | 145 bool SendInfo(); |
143 | 146 |
144 private: | 147 private: |
145 cloud_print::CloudPrintProxyInfo info_; | 148 cloud_print::CloudPrintProxyInfo info_; |
146 bool enabled_; | 149 bool enabled_; |
147 }; | 150 }; |
148 | 151 |
149 // static | 152 // static |
150 std::string MockServiceIPCServer::EnabledUserId() { | 153 std::string MockServiceIPCServer::EnabledUserId() { |
151 return std::string("kitteh@canhazcheezburger.cat"); | 154 return std::string("kitteh@canhazcheezburger.cat"); |
152 } | 155 } |
153 | 156 |
154 void MockServiceIPCServer::SetServiceEnabledExpectations() { | 157 void MockServiceIPCServer::SetServiceEnabledExpectations() { |
155 EXPECT_CALL(*this, OnChannelConnected(_)).Times(1) | 158 EXPECT_CALL(*this, OnChannelConnected(_)).Times(1) |
156 .WillRepeatedly( | 159 .WillRepeatedly( |
157 Invoke(this, &MockServiceIPCServer::CallServiceOnChannelConnected)); | 160 Invoke(this, &MockServiceIPCServer::CallServiceOnChannelConnected)); |
158 | 161 |
159 EXPECT_CALL(*this, OnChannelError()).Times(0); | 162 EXPECT_CALL(*this, OnChannelError()).Times(0); |
160 EXPECT_CALL(*this, OnMessageReceived(_)).Times(0); | 163 EXPECT_CALL(*this, OnMessageReceived(_)).Times(0); |
161 | 164 |
162 EXPECT_CALL(*this, | 165 EXPECT_CALL(*this, |
163 OnMessageReceived( | 166 OnMessageReceived(Property( |
164 Property(&IPC::Message::type, | 167 &IPC::Message::type, |
165 static_cast<int32>(ServiceMsg_GetCloudPrintProxyInfo::ID)))) | 168 static_cast<int32_t>(ServiceMsg_GetCloudPrintProxyInfo::ID)))) |
166 .Times(AnyNumber()).WillRepeatedly( | 169 .Times(AnyNumber()) |
| 170 .WillRepeatedly( |
167 WithoutArgs(Invoke(this, &MockServiceIPCServer::SendInfo))); | 171 WithoutArgs(Invoke(this, &MockServiceIPCServer::SendInfo))); |
168 | 172 |
169 EXPECT_CALL(*this, | 173 EXPECT_CALL(*this, OnMessageReceived(Property( |
170 OnMessageReceived( | 174 &IPC::Message::type, |
171 Property(&IPC::Message::type, | 175 static_cast<int32_t>(ServiceMsg_Shutdown::ID)))) |
172 static_cast<int32>(ServiceMsg_Shutdown::ID)))) | |
173 .Times(1) | 176 .Times(1) |
174 .WillOnce( | 177 .WillOnce(DoAll( |
175 DoAll(Assign(&g_good_shutdown, true), | 178 Assign(&g_good_shutdown, true), |
176 WithoutArgs( | 179 WithoutArgs(Invoke(g_service_process, &ServiceProcess::Shutdown)), |
177 Invoke(g_service_process, &ServiceProcess::Shutdown)), | 180 Return(true))); |
178 Return(true))); | |
179 } | 181 } |
180 | 182 |
181 void MockServiceIPCServer::SetWillBeDisabledExpectations() { | 183 void MockServiceIPCServer::SetWillBeDisabledExpectations() { |
182 SetServiceEnabledExpectations(); | 184 SetServiceEnabledExpectations(); |
183 | 185 |
184 EXPECT_CALL(*this, | 186 EXPECT_CALL(*this, |
185 OnMessageReceived( | 187 OnMessageReceived(Property( |
186 Property(&IPC::Message::type, | 188 &IPC::Message::type, |
187 static_cast<int32>( | 189 static_cast<int32_t>(ServiceMsg_DisableCloudPrintProxy::ID)))) |
188 ServiceMsg_DisableCloudPrintProxy::ID)))) | |
189 .Times(AtLeast(1)) | 190 .Times(AtLeast(1)) |
190 .WillRepeatedly(DoAll(Assign(&enabled_, false), Return(true))); | 191 .WillRepeatedly(DoAll(Assign(&enabled_, false), Return(true))); |
191 } | 192 } |
192 | 193 |
193 bool MockServiceIPCServer::SendInfo() { | 194 bool MockServiceIPCServer::SendInfo() { |
194 if (enabled_) { | 195 if (enabled_) { |
195 info_.enabled = true; | 196 info_.enabled = true; |
196 info_.email = EnabledUserId(); | 197 info_.email = EnabledUserId(); |
197 EXPECT_TRUE(Send(new ServiceHostMsg_CloudPrintProxy_Info(info_))); | 198 EXPECT_TRUE(Send(new ServiceHostMsg_CloudPrintProxy_Info(info_))); |
198 } else { | 199 } else { |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 scoped_refptr<base::SingleThreadTaskRunner> IOTaskRunner() { | 313 scoped_refptr<base::SingleThreadTaskRunner> IOTaskRunner() { |
313 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | 314 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
314 } | 315 } |
315 base::Process Launch(const std::string& name); | 316 base::Process Launch(const std::string& name); |
316 void WaitForConnect(); | 317 void WaitForConnect(); |
317 bool Send(IPC::Message* message); | 318 bool Send(IPC::Message* message); |
318 void ShutdownAndWaitForExitWithTimeout(base::Process process); | 319 void ShutdownAndWaitForExitWithTimeout(base::Process process); |
319 | 320 |
320 // IPC::Listener implementation | 321 // IPC::Listener implementation |
321 bool OnMessageReceived(const IPC::Message& message) override { return false; } | 322 bool OnMessageReceived(const IPC::Message& message) override { return false; } |
322 void OnChannelConnected(int32 peer_pid) override; | 323 void OnChannelConnected(int32_t peer_pid) override; |
323 | 324 |
324 // MultiProcessTest implementation. | 325 // MultiProcessTest implementation. |
325 base::CommandLine MakeCmdLine(const std::string& procname) override; | 326 base::CommandLine MakeCmdLine(const std::string& procname) override; |
326 | 327 |
327 bool LaunchBrowser(const base::CommandLine& command_line, Profile* profile) { | 328 bool LaunchBrowser(const base::CommandLine& command_line, Profile* profile) { |
328 StartupBrowserCreator browser_creator; | 329 StartupBrowserCreator browser_creator; |
329 return StartupBrowserCreator::ProcessCmdLineImpl( | 330 return StartupBrowserCreator::ProcessCmdLineImpl( |
330 command_line, base::FilePath(), false, profile, | 331 command_line, base::FilePath(), false, profile, |
331 StartupBrowserCreator::Profiles(), &browser_creator); | 332 StartupBrowserCreator::Profiles(), &browser_creator); |
332 } | 333 } |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 base::Process process) { | 481 base::Process process) { |
481 ASSERT_TRUE(Send(new ServiceMsg_Shutdown())); | 482 ASSERT_TRUE(Send(new ServiceMsg_Shutdown())); |
482 | 483 |
483 int exit_code = -100; | 484 int exit_code = -100; |
484 bool exited = process.WaitForExitWithTimeout(TestTimeouts::action_timeout(), | 485 bool exited = process.WaitForExitWithTimeout(TestTimeouts::action_timeout(), |
485 &exit_code); | 486 &exit_code); |
486 EXPECT_TRUE(exited); | 487 EXPECT_TRUE(exited); |
487 EXPECT_EQ(exit_code, 0); | 488 EXPECT_EQ(exit_code, 0); |
488 } | 489 } |
489 | 490 |
490 void CloudPrintProxyPolicyStartupTest::OnChannelConnected(int32 peer_pid) { | 491 void CloudPrintProxyPolicyStartupTest::OnChannelConnected(int32_t peer_pid) { |
491 observer_.Notify(); | 492 observer_.Notify(); |
492 } | 493 } |
493 | 494 |
494 base::CommandLine CloudPrintProxyPolicyStartupTest::MakeCmdLine( | 495 base::CommandLine CloudPrintProxyPolicyStartupTest::MakeCmdLine( |
495 const std::string& procname) { | 496 const std::string& procname) { |
496 base::CommandLine cl = MultiProcessTest::MakeCmdLine(procname); | 497 base::CommandLine cl = MultiProcessTest::MakeCmdLine(procname); |
497 cl.AppendSwitchASCII(switches::kProcessChannelID, startup_channel_id_); | 498 cl.AppendSwitchASCII(switches::kProcessChannelID, startup_channel_id_); |
498 #if defined(OS_MACOSX) | 499 #if defined(OS_MACOSX) |
499 cl.AppendSwitchASCII(kTestExecutablePath, executable_path_.value()); | 500 cl.AppendSwitchASCII(kTestExecutablePath, executable_path_.value()); |
500 #endif | 501 #endif |
(...skipping 10 matching lines...) Expand all Loading... |
511 // LocalState for the BrowserProcess. Must be created before profiles are | 512 // LocalState for the BrowserProcess. Must be created before profiles are |
512 // constructed. | 513 // constructed. |
513 chrome::TestingIOThreadState testing_io_thread_state; | 514 chrome::TestingIOThreadState testing_io_thread_state; |
514 | 515 |
515 base::Process process = | 516 base::Process process = |
516 Launch("CloudPrintMockService_StartEnabledWaitForQuit"); | 517 Launch("CloudPrintMockService_StartEnabledWaitForQuit"); |
517 WaitForConnect(); | 518 WaitForConnect(); |
518 ShutdownAndWaitForExitWithTimeout(process.Pass()); | 519 ShutdownAndWaitForExitWithTimeout(process.Pass()); |
519 content::RunAllPendingInMessageLoop(); | 520 content::RunAllPendingInMessageLoop(); |
520 } | 521 } |
OLD | NEW |