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

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: Do not create the audio capturer if audio is not supported 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
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));
Wez 2013/02/01 01:02:11 This will end up adding expectations after the tes
alexeypa (please no reviews) 2013/02/01 17:28:43 We use this pattern (create a new object and set a
Wez 2013/02/01 17:30:24 Yes, I think that the newly-created-object aspect
200
Wez 2013/02/01 01:02:11 nit: Don't really need a blank line here.
alexeypa (please no reviews) 2013/02/01 17:28:43 Done.
201 return desktop_environment;
202 }
203
204 EventExecutor* DesktopProcessTest::CreateEventExecutor() {
205 MockEventExecutor* event_executor = new MockEventExecutor();
206 EXPECT_CALL(*event_executor, StartPtr(_));
207 return event_executor;
208 }
209
210 media::ScreenCapturer* DesktopProcessTest::CreateVideoCapturer() {
211 return new media::ScreenCapturerFake();
212 }
213
172 void DesktopProcessTest::DisconnectChannels() { 214 void DesktopProcessTest::DisconnectChannels() {
173 daemon_channel_.reset(); 215 daemon_channel_.reset();
174 network_channel_.reset(); 216 network_channel_.reset();
175 io_task_runner_ = NULL; 217 io_task_runner_ = NULL;
176 } 218 }
177 219
178 void DesktopProcessTest::RunDesktopProcess() { 220 void DesktopProcessTest::RunDesktopProcess() {
179 base::RunLoop run_loop; 221 base::RunLoop run_loop;
180 base::Closure quit_ui_task_runner = base::Bind( 222 base::Closure quit_ui_task_runner = base::Bind(
181 base::IgnoreResult(&base::SingleThreadTaskRunner::PostTask), 223 base::IgnoreResult(&base::SingleThreadTaskRunner::PostTask),
182 message_loop_.message_loop_proxy(), 224 message_loop_.message_loop_proxy(),
183 FROM_HERE, run_loop.QuitClosure()); 225 FROM_HERE, run_loop.QuitClosure());
184 scoped_refptr<AutoThreadTaskRunner> ui_task_runner = new AutoThreadTaskRunner( 226 scoped_refptr<AutoThreadTaskRunner> ui_task_runner = new AutoThreadTaskRunner(
185 message_loop_.message_loop_proxy(), quit_ui_task_runner); 227 message_loop_.message_loop_proxy(), quit_ui_task_runner);
186 228
187 io_task_runner_ = AutoThread::CreateWithType("IPC thread", ui_task_runner, 229 io_task_runner_ = AutoThread::CreateWithType("IPC thread", ui_task_runner,
188 MessageLoop::TYPE_IO); 230 MessageLoop::TYPE_IO);
189 231
190 std::string channel_name = IPC::Channel::GenerateUniqueRandomChannelID(); 232 std::string channel_name = IPC::Channel::GenerateUniqueRandomChannelID();
191 daemon_channel_.reset(new IPC::ChannelProxy( 233 daemon_channel_.reset(new IPC::ChannelProxy(
192 IPC::ChannelHandle(channel_name), 234 IPC::ChannelHandle(channel_name),
193 IPC::Channel::MODE_SERVER, 235 IPC::Channel::MODE_SERVER,
194 &daemon_listener_, 236 &daemon_listener_,
195 io_task_runner_)); 237 io_task_runner_));
196 238
239 scoped_ptr<MockDesktopEnvironmentFactory> desktop_environment_factory(
240 new MockDesktopEnvironmentFactory());
241 EXPECT_CALL(*desktop_environment_factory, CreatePtr())
242 .Times(AnyNumber())
243 .WillRepeatedly(Invoke(this,
244 &DesktopProcessTest::CreateDesktopEnvironment));
245 EXPECT_CALL(*desktop_environment_factory, SupportsAudioCapture())
246 .Times(AnyNumber())
247 .WillRepeatedly(Return(false));
248
197 DesktopProcess desktop_process(ui_task_runner, channel_name); 249 DesktopProcess desktop_process(ui_task_runner, channel_name);
198 EXPECT_TRUE(desktop_process.Start()); 250 EXPECT_TRUE(desktop_process.Start(
251 desktop_environment_factory.PassAs<DesktopEnvironmentFactory>()));
199 252
200 ui_task_runner = NULL; 253 ui_task_runner = NULL;
201 run_loop.Run(); 254 run_loop.Run();
202 } 255 }
203 256
204 void DesktopProcessTest::RunDeathTest() { 257 void DesktopProcessTest::RunDeathTest() {
205 InSequence s; 258 InSequence s;
206 EXPECT_CALL(daemon_listener_, OnChannelConnected(_)); 259 EXPECT_CALL(daemon_listener_, OnChannelConnected(_));
207 EXPECT_CALL(daemon_listener_, OnDesktopAttached(_)) 260 EXPECT_CALL(daemon_listener_, OnDesktopAttached(_))
208 .WillOnce(DoAll( 261 .WillOnce(DoAll(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 } 297 }
245 298
246 // Run the desktop process and ask it to crash. 299 // Run the desktop process and ask it to crash.
247 TEST_F(DesktopProcessTest, DeathTest) { 300 TEST_F(DesktopProcessTest, DeathTest) {
248 testing::GTEST_FLAG(death_test_style) = "threadsafe"; 301 testing::GTEST_FLAG(death_test_style) = "threadsafe";
249 302
250 EXPECT_DEATH(RunDeathTest(), ""); 303 EXPECT_DEATH(RunDeathTest(), "");
251 } 304 }
252 305
253 } // namespace remoting 306 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698