Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: remoting/host/desktop_process_unittest.cc

Issue 12087073: Pass a DesktopEnvironmentFactory when creating DesktopProcess. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased. fixed posix. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/host/desktop_process_main.cc ('k') | remoting/host/desktop_session_agent.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "remoting/host/desktop_process.h" 5 #include "remoting/host/desktop_process.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
14 #include "ipc/ipc_channel.h" 14 #include "ipc/ipc_channel.h"
15 #include "ipc/ipc_channel_proxy.h" 15 #include "ipc/ipc_channel_proxy.h"
16 #include "ipc/ipc_listener.h" 16 #include "ipc/ipc_listener.h"
17 #include "ipc/ipc_message.h" 17 #include "ipc/ipc_message.h"
18 #include "media/video/capture/screen/screen_capturer_fake.h"
18 #include "remoting/base/auto_thread.h" 19 #include "remoting/base/auto_thread.h"
19 #include "remoting/base/auto_thread_task_runner.h" 20 #include "remoting/base/auto_thread_task_runner.h"
20 #include "remoting/host/chromoting_messages.h" 21 #include "remoting/host/chromoting_messages.h"
21 #include "remoting/host/desktop_process.h" 22 #include "remoting/host/desktop_process.h"
22 #include "remoting/host/host_exit_codes.h" 23 #include "remoting/host/host_exit_codes.h"
24 #include "remoting/host/host_mock_objects.h"
25 #include "remoting/protocol/protocol_mock_objects.h"
23 #include "testing/gmock_mutant.h" 26 #include "testing/gmock_mutant.h"
24 #include "testing/gmock/include/gmock/gmock.h" 27 #include "testing/gmock/include/gmock/gmock.h"
25 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
26 29
27 using testing::_; 30 using testing::_;
28 using testing::AnyNumber; 31 using testing::AnyNumber;
29 using testing::InSequence; 32 using testing::InSequence;
33 using testing::Return;
30 34
31 namespace remoting { 35 namespace remoting {
32 36
33 namespace { 37 namespace {
34 38
35 class MockDaemonListener : public IPC::Listener { 39 class MockDaemonListener : public IPC::Listener {
36 public: 40 public:
37 MockDaemonListener() {} 41 MockDaemonListener() {}
38 virtual ~MockDaemonListener() {} 42 virtual ~MockDaemonListener() {}
39 43
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 virtual ~DesktopProcessTest(); 95 virtual ~DesktopProcessTest();
92 96
93 // testing::Test overrides 97 // testing::Test overrides
94 virtual void SetUp() OVERRIDE; 98 virtual void SetUp() OVERRIDE;
95 virtual void TearDown() OVERRIDE; 99 virtual void TearDown() OVERRIDE;
96 100
97 // MockDaemonListener mocks 101 // MockDaemonListener mocks
98 void ConnectNetworkChannel(IPC::PlatformFileForTransit desktop_process); 102 void ConnectNetworkChannel(IPC::PlatformFileForTransit desktop_process);
99 void OnDesktopAttached(IPC::PlatformFileForTransit desktop_process); 103 void OnDesktopAttached(IPC::PlatformFileForTransit desktop_process);
100 104
105 // Creates a DesktopEnvironment with a fake media::ScreenCapturer, to mock
106 // DesktopEnvironmentFactory::Create().
107 DesktopEnvironment* CreateDesktopEnvironment();
108
109 // Creates a dummy EventExecutor, to mock
110 // DesktopEnvironment::CreateEventExecutor().
111 EventExecutor* CreateEventExecutor();
112
113 // Creates a fake media::ScreenCapturer, to mock
114 // DesktopEnvironment::CreateVideoCapturer().
115 media::ScreenCapturer* CreateVideoCapturer();
116
101 // Disconnects the daemon-to-desktop channel causing the desktop process to 117 // Disconnects the daemon-to-desktop channel causing the desktop process to
102 // exit. 118 // exit.
103 void DisconnectChannels(); 119 void DisconnectChannels();
104 120
105 // Runs the desktop process code in a separate thread. 121 // Runs the desktop process code in a separate thread.
106 void RunDesktopProcess(); 122 void RunDesktopProcess();
107 123
108 // Creates the desktop process and sends a crash request to it. 124 // Creates the desktop process and sends a crash request to it.
109 void RunDeathTest(); 125 void RunDeathTest();
110 126
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 178
163 void DesktopProcessTest::OnDesktopAttached( 179 void DesktopProcessTest::OnDesktopAttached(
164 IPC::PlatformFileForTransit desktop_process) { 180 IPC::PlatformFileForTransit desktop_process) {
165 #if defined(OS_POSIX) 181 #if defined(OS_POSIX)
166 DCHECK(desktop_process.auto_close); 182 DCHECK(desktop_process.auto_close);
167 183
168 base::ClosePlatformFile(desktop_process.fd); 184 base::ClosePlatformFile(desktop_process.fd);
169 #endif // defined(OS_POSIX) 185 #endif // defined(OS_POSIX)
170 } 186 }
171 187
188 DesktopEnvironment* DesktopProcessTest::CreateDesktopEnvironment() {
189 MockDesktopEnvironment* desktop_environment = new MockDesktopEnvironment();
190 EXPECT_CALL(*desktop_environment, CreateAudioCapturerPtr(_))
191 .Times(0);
192 EXPECT_CALL(*desktop_environment, CreateEventExecutorPtr(_, _))
193 .Times(AnyNumber())
194 .WillRepeatedly(
195 InvokeWithoutArgs(this, &DesktopProcessTest::CreateEventExecutor));
196 EXPECT_CALL(*desktop_environment, CreateVideoCapturerPtr(_, _))
197 .Times(AnyNumber())
198 .WillRepeatedly(
199 InvokeWithoutArgs(this, &DesktopProcessTest::CreateVideoCapturer));
200 return desktop_environment;
201 }
202
203 EventExecutor* DesktopProcessTest::CreateEventExecutor() {
204 MockEventExecutor* event_executor = new MockEventExecutor();
205 EXPECT_CALL(*event_executor, StartPtr(_));
206 return event_executor;
207 }
208
209 media::ScreenCapturer* DesktopProcessTest::CreateVideoCapturer() {
210 return new media::ScreenCapturerFake();
211 }
212
172 void DesktopProcessTest::DisconnectChannels() { 213 void DesktopProcessTest::DisconnectChannels() {
173 daemon_channel_.reset(); 214 daemon_channel_.reset();
174 network_channel_.reset(); 215 network_channel_.reset();
175 io_task_runner_ = NULL; 216 io_task_runner_ = NULL;
176 } 217 }
177 218
178 void DesktopProcessTest::RunDesktopProcess() { 219 void DesktopProcessTest::RunDesktopProcess() {
179 base::RunLoop run_loop; 220 base::RunLoop run_loop;
180 base::Closure quit_ui_task_runner = base::Bind( 221 base::Closure quit_ui_task_runner = base::Bind(
181 base::IgnoreResult(&base::SingleThreadTaskRunner::PostTask), 222 base::IgnoreResult(&base::SingleThreadTaskRunner::PostTask),
182 message_loop_.message_loop_proxy(), 223 message_loop_.message_loop_proxy(),
183 FROM_HERE, run_loop.QuitClosure()); 224 FROM_HERE, run_loop.QuitClosure());
184 scoped_refptr<AutoThreadTaskRunner> ui_task_runner = new AutoThreadTaskRunner( 225 scoped_refptr<AutoThreadTaskRunner> ui_task_runner = new AutoThreadTaskRunner(
185 message_loop_.message_loop_proxy(), quit_ui_task_runner); 226 message_loop_.message_loop_proxy(), quit_ui_task_runner);
186 227
187 io_task_runner_ = AutoThread::CreateWithType("IPC thread", ui_task_runner, 228 io_task_runner_ = AutoThread::CreateWithType("IPC thread", ui_task_runner,
188 MessageLoop::TYPE_IO); 229 MessageLoop::TYPE_IO);
189 230
190 std::string channel_name = IPC::Channel::GenerateUniqueRandomChannelID(); 231 std::string channel_name = IPC::Channel::GenerateUniqueRandomChannelID();
191 daemon_channel_.reset(new IPC::ChannelProxy( 232 daemon_channel_.reset(new IPC::ChannelProxy(
192 IPC::ChannelHandle(channel_name), 233 IPC::ChannelHandle(channel_name),
193 IPC::Channel::MODE_SERVER, 234 IPC::Channel::MODE_SERVER,
194 &daemon_listener_, 235 &daemon_listener_,
195 io_task_runner_)); 236 io_task_runner_));
196 237
238 scoped_ptr<MockDesktopEnvironmentFactory> desktop_environment_factory(
239 new MockDesktopEnvironmentFactory());
240 EXPECT_CALL(*desktop_environment_factory, CreatePtr())
241 .Times(AnyNumber())
242 .WillRepeatedly(Invoke(this,
243 &DesktopProcessTest::CreateDesktopEnvironment));
244 EXPECT_CALL(*desktop_environment_factory, SupportsAudioCapture())
245 .Times(AnyNumber())
246 .WillRepeatedly(Return(false));
247
197 DesktopProcess desktop_process(ui_task_runner, channel_name); 248 DesktopProcess desktop_process(ui_task_runner, channel_name);
198 EXPECT_TRUE(desktop_process.Start()); 249 EXPECT_TRUE(desktop_process.Start(
250 desktop_environment_factory.PassAs<DesktopEnvironmentFactory>()));
199 251
200 ui_task_runner = NULL; 252 ui_task_runner = NULL;
201 run_loop.Run(); 253 run_loop.Run();
202 } 254 }
203 255
204 void DesktopProcessTest::RunDeathTest() { 256 void DesktopProcessTest::RunDeathTest() {
205 InSequence s; 257 InSequence s;
206 EXPECT_CALL(daemon_listener_, OnChannelConnected(_)); 258 EXPECT_CALL(daemon_listener_, OnChannelConnected(_));
207 EXPECT_CALL(daemon_listener_, OnDesktopAttached(_)) 259 EXPECT_CALL(daemon_listener_, OnDesktopAttached(_))
208 .WillOnce(DoAll( 260 .WillOnce(DoAll(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 } 296 }
245 297
246 // Run the desktop process and ask it to crash. 298 // Run the desktop process and ask it to crash.
247 TEST_F(DesktopProcessTest, DeathTest) { 299 TEST_F(DesktopProcessTest, DeathTest) {
248 testing::GTEST_FLAG(death_test_style) = "threadsafe"; 300 testing::GTEST_FLAG(death_test_style) = "threadsafe";
249 301
250 EXPECT_DEATH(RunDeathTest(), ""); 302 EXPECT_DEATH(RunDeathTest(), "");
251 } 303 }
252 304
253 } // namespace remoting 305 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/desktop_process_main.cc ('k') | remoting/host/desktop_session_agent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698