Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / remoting / host / ipc_desktop_environment_unittest.cc
blobd31d3d46acd51160f2aae5e3b6084cd03b66e202
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/bind.h"
6 #include "base/bind_helpers.h"
7 #include "base/callback.h"
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/process/process.h"
12 #include "base/process/process_handle.h"
13 #include "base/run_loop.h"
14 #include "ipc/ipc_channel.h"
15 #include "ipc/ipc_channel_proxy.h"
16 #include "ipc/ipc_listener.h"
17 #include "ipc/ipc_message.h"
18 #include "ipc/ipc_platform_file.h"
19 #include "remoting/base/auto_thread.h"
20 #include "remoting/base/auto_thread_task_runner.h"
21 #include "remoting/base/constants.h"
22 #include "remoting/host/chromoting_messages.h"
23 #include "remoting/host/desktop_process.h"
24 #include "remoting/host/desktop_session.h"
25 #include "remoting/host/desktop_session_connector.h"
26 #include "remoting/host/desktop_session_proxy.h"
27 #include "remoting/host/fake_desktop_capturer.h"
28 #include "remoting/host/fake_mouse_cursor_monitor.h"
29 #include "remoting/host/host_mock_objects.h"
30 #include "remoting/host/ipc_desktop_environment.h"
31 #include "remoting/protocol/protocol_mock_objects.h"
32 #include "remoting/protocol/test_event_matchers.h"
33 #include "testing/gmock/include/gmock/gmock.h"
34 #include "testing/gtest/include/gtest/gtest.h"
35 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
36 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h"
37 #include "third_party/webrtc/modules/desktop_capture/screen_capturer_mock_objects.h"
39 using testing::_;
40 using testing::AnyNumber;
41 using testing::AtLeast;
42 using testing::AtMost;
43 using testing::DeleteArg;
44 using testing::DoAll;
45 using testing::InSequence;
46 using testing::Return;
47 using testing::ReturnRef;
49 namespace remoting {
51 using protocol::test::EqualsTouchEvent;
52 using protocol::test::EqualsTouchEventTypeAndId;
54 namespace {
56 // Receives messages sent from the network process to the daemon.
57 class FakeDaemonSender : public IPC::Sender {
58 public:
59 FakeDaemonSender() {}
60 virtual ~FakeDaemonSender() {}
62 // IPC::Sender implementation.
63 virtual bool Send(IPC::Message* message) override;
65 MOCK_METHOD3(ConnectTerminal, void(int, const ScreenResolution&, bool));
66 MOCK_METHOD1(DisconnectTerminal, void(int));
67 MOCK_METHOD2(SetScreenResolution, void(int, const ScreenResolution&));
69 private:
70 void OnMessageReceived(const IPC::Message& message);
72 DISALLOW_COPY_AND_ASSIGN(FakeDaemonSender);
75 // Receives messages sent from the desktop process to the daemon.
76 class MockDaemonListener : public IPC::Listener {
77 public:
78 MockDaemonListener() {}
79 virtual ~MockDaemonListener() {}
81 virtual bool OnMessageReceived(const IPC::Message& message) override;
83 MOCK_METHOD1(OnDesktopAttached, void(IPC::PlatformFileForTransit));
84 MOCK_METHOD1(OnChannelConnected, void(int32));
85 MOCK_METHOD0(OnChannelError, void());
87 private:
88 DISALLOW_COPY_AND_ASSIGN(MockDaemonListener);
91 bool FakeDaemonSender::Send(IPC::Message* message) {
92 OnMessageReceived(*message);
93 delete message;
94 return true;
97 void FakeDaemonSender::OnMessageReceived(const IPC::Message& message) {
98 bool handled = true;
99 IPC_BEGIN_MESSAGE_MAP(FakeDaemonSender, message)
100 IPC_MESSAGE_HANDLER(ChromotingNetworkHostMsg_ConnectTerminal,
101 ConnectTerminal)
102 IPC_MESSAGE_HANDLER(ChromotingNetworkHostMsg_DisconnectTerminal,
103 DisconnectTerminal)
104 IPC_MESSAGE_HANDLER(ChromotingNetworkDaemonMsg_SetScreenResolution,
105 SetScreenResolution)
106 IPC_MESSAGE_UNHANDLED(handled = false)
107 IPC_END_MESSAGE_MAP()
109 EXPECT_TRUE(handled);
112 bool MockDaemonListener::OnMessageReceived(const IPC::Message& message) {
113 bool handled = true;
114 IPC_BEGIN_MESSAGE_MAP(MockDaemonListener, message)
115 IPC_MESSAGE_HANDLER(ChromotingDesktopDaemonMsg_DesktopAttached,
116 OnDesktopAttached)
117 IPC_MESSAGE_UNHANDLED(handled = false)
118 IPC_END_MESSAGE_MAP()
120 EXPECT_TRUE(handled);
121 return handled;
124 } // namespace
126 class IpcDesktopEnvironmentTest : public testing::Test {
127 public:
128 IpcDesktopEnvironmentTest();
129 ~IpcDesktopEnvironmentTest() override;
131 void SetUp() override;
133 void ConnectTerminal(int terminal_id,
134 const ScreenResolution& resolution,
135 bool virtual_terminal);
136 void DisconnectTerminal(int terminal_id);
138 // Creates a DesktopEnvironment with a fake webrtc::DesktopCapturer, to mock
139 // DesktopEnvironmentFactory::Create().
140 DesktopEnvironment* CreateDesktopEnvironment();
142 // Creates a dummy InputInjector, to mock
143 // DesktopEnvironment::CreateInputInjector().
144 InputInjector* CreateInputInjector();
146 // Creates a fake webrtc::DesktopCapturer, to mock
147 // DesktopEnvironment::CreateVideoCapturer().
148 webrtc::DesktopCapturer* CreateVideoCapturer();
150 // Creates a MockMouseCursorMonitor, to mock
151 // DesktopEnvironment::CreateMouseCursorMonitor
152 webrtc::MouseCursorMonitor* CreateMouseCursorMonitor();
154 void DeleteDesktopEnvironment();
156 // Forwards |event| to |clipboard_stub_|.
157 void ReflectClipboardEvent(const protocol::ClipboardEvent& event);
159 protected:
160 // Creates and starts an instance of desktop process object.
161 void CreateDesktopProcess();
163 // Destroys the desktop process object created by CreateDesktopProcess().
164 void DestoyDesktopProcess();
166 void OnDisconnectCallback();
168 // Invoked when ChromotingDesktopDaemonMsg_DesktopAttached message is
169 // received.
170 void OnDesktopAttached(IPC::PlatformFileForTransit desktop_pipe);
172 // The main message loop.
173 base::MessageLoopForUI message_loop_;
175 // Runs until |desktop_session_proxy_| is connected to the desktop.
176 scoped_ptr<base::RunLoop> setup_run_loop_;
178 // Runs until there are references to |task_runner_|.
179 base::RunLoop main_run_loop_;
181 scoped_refptr<AutoThreadTaskRunner> task_runner_;
182 scoped_refptr<AutoThreadTaskRunner> io_task_runner_;
184 std::string client_jid_;
186 // Clipboard stub that receives clipboard events from the desktop process.
187 protocol::ClipboardStub* clipboard_stub_;
189 // The daemons's end of the daemon-to-desktop channel.
190 scoped_ptr<IPC::ChannelProxy> desktop_channel_;
192 // Name of the daemon-to-desktop channel.
193 std::string desktop_channel_name_;
195 // Delegate that is passed to |desktop_channel_|.
196 MockDaemonListener desktop_listener_;
198 FakeDaemonSender daemon_channel_;
200 scoped_ptr<IpcDesktopEnvironmentFactory> desktop_environment_factory_;
201 scoped_ptr<DesktopEnvironment> desktop_environment_;
203 // The IPC input injector.
204 scoped_ptr<InputInjector> input_injector_;
206 // The IPC screen controls.
207 scoped_ptr<ScreenControls> screen_controls_;
209 // The IPC screen capturer.
210 scoped_ptr<webrtc::DesktopCapturer> video_capturer_;
212 // Represents the desktop process running in a user session.
213 scoped_ptr<DesktopProcess> desktop_process_;
215 // Input injector owned by |desktop_process_|.
216 MockInputInjector* remote_input_injector_;
218 // The last |terminal_id| passed to ConnectTermina();
219 int terminal_id_;
221 webrtc::MockScreenCapturerCallback desktop_capturer_callback_;
223 MockClientSessionControl client_session_control_;
224 base::WeakPtrFactory<ClientSessionControl> client_session_control_factory_;
227 IpcDesktopEnvironmentTest::IpcDesktopEnvironmentTest()
228 : client_jid_("user@domain/rest-of-jid"),
229 clipboard_stub_(nullptr),
230 remote_input_injector_(nullptr),
231 terminal_id_(-1),
232 client_session_control_factory_(&client_session_control_) {
235 IpcDesktopEnvironmentTest::~IpcDesktopEnvironmentTest() {
238 void IpcDesktopEnvironmentTest::SetUp() {
239 // Arrange to run |message_loop_| until no components depend on it.
240 task_runner_ = new AutoThreadTaskRunner(
241 message_loop_.message_loop_proxy(), main_run_loop_.QuitClosure());
243 io_task_runner_ = AutoThread::CreateWithType(
244 "IPC thread", task_runner_, base::MessageLoop::TYPE_IO);
246 setup_run_loop_.reset(new base::RunLoop());
248 // Set expectation that the DaemonProcess will send DesktopAttached message
249 // once it is ready.
250 EXPECT_CALL(desktop_listener_, OnChannelConnected(_))
251 .Times(AnyNumber());
252 EXPECT_CALL(desktop_listener_, OnDesktopAttached(_))
253 .Times(AnyNumber())
254 .WillRepeatedly(Invoke(this,
255 &IpcDesktopEnvironmentTest::OnDesktopAttached));
256 EXPECT_CALL(desktop_listener_, OnChannelError())
257 .Times(AnyNumber())
258 .WillOnce(Invoke(this,
259 &IpcDesktopEnvironmentTest::DestoyDesktopProcess));
261 // Intercept requests to connect and disconnect a terminal.
262 EXPECT_CALL(daemon_channel_, ConnectTerminal(_, _, _))
263 .Times(AnyNumber())
264 .WillRepeatedly(Invoke(this,
265 &IpcDesktopEnvironmentTest::ConnectTerminal));
266 EXPECT_CALL(daemon_channel_, DisconnectTerminal(_))
267 .Times(AnyNumber())
268 .WillRepeatedly(Invoke(this,
269 &IpcDesktopEnvironmentTest::DisconnectTerminal));
271 EXPECT_CALL(client_session_control_, client_jid())
272 .Times(AnyNumber())
273 .WillRepeatedly(ReturnRef(client_jid_));
274 EXPECT_CALL(client_session_control_, DisconnectSession())
275 .Times(AnyNumber())
276 .WillRepeatedly(Invoke(
277 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment));
278 EXPECT_CALL(client_session_control_, OnLocalMouseMoved(_))
279 .Times(0);
280 EXPECT_CALL(client_session_control_, SetDisableInputs(_))
281 .Times(0);
283 // Create a desktop environment instance.
284 desktop_environment_factory_.reset(new IpcDesktopEnvironmentFactory(
285 task_runner_,
286 task_runner_,
287 task_runner_,
288 io_task_runner_,
289 &daemon_channel_));
290 desktop_environment_ = desktop_environment_factory_->Create(
291 client_session_control_factory_.GetWeakPtr());
293 screen_controls_ = desktop_environment_->CreateScreenControls();
295 // Create the input injector.
296 input_injector_ = desktop_environment_->CreateInputInjector();
298 // Create the screen capturer.
299 video_capturer_ =
300 desktop_environment_->CreateVideoCapturer();
302 desktop_environment_->SetCapabilities(std::string());
305 void IpcDesktopEnvironmentTest::ConnectTerminal(
306 int terminal_id,
307 const ScreenResolution& resolution,
308 bool virtual_terminal) {
309 EXPECT_NE(terminal_id_, terminal_id);
311 terminal_id_ = terminal_id;
312 CreateDesktopProcess();
315 void IpcDesktopEnvironmentTest::DisconnectTerminal(int terminal_id) {
316 EXPECT_EQ(terminal_id_, terminal_id);
318 // The IPC desktop environment is fully destroyed now. Release the remaining
319 // task runners.
320 desktop_environment_factory_.reset();
323 DesktopEnvironment* IpcDesktopEnvironmentTest::CreateDesktopEnvironment() {
324 MockDesktopEnvironment* desktop_environment = new MockDesktopEnvironment();
325 EXPECT_CALL(*desktop_environment, CreateAudioCapturerPtr())
326 .Times(0);
327 EXPECT_CALL(*desktop_environment, CreateInputInjectorPtr())
328 .Times(AtMost(1))
329 .WillOnce(Invoke(
330 this, &IpcDesktopEnvironmentTest::CreateInputInjector));
331 EXPECT_CALL(*desktop_environment, CreateScreenControlsPtr())
332 .Times(AtMost(1));
333 EXPECT_CALL(*desktop_environment, CreateVideoCapturerPtr())
334 .Times(AtMost(1))
335 .WillOnce(Invoke(
336 this, &IpcDesktopEnvironmentTest::CreateVideoCapturer));
337 EXPECT_CALL(*desktop_environment, CreateMouseCursorMonitorPtr())
338 .Times(AtMost(1))
339 .WillOnce(Invoke(
340 this, &IpcDesktopEnvironmentTest::CreateMouseCursorMonitor));
341 EXPECT_CALL(*desktop_environment, GetCapabilities())
342 .Times(AtMost(1));
343 EXPECT_CALL(*desktop_environment, SetCapabilities(_))
344 .Times(AtMost(1));
346 // Let tests know that the remote desktop environment is created.
347 message_loop_.PostTask(FROM_HERE, setup_run_loop_->QuitClosure());
349 return desktop_environment;
352 InputInjector* IpcDesktopEnvironmentTest::CreateInputInjector() {
353 EXPECT_TRUE(remote_input_injector_ == nullptr);
354 remote_input_injector_ = new testing::StrictMock<MockInputInjector>();
356 EXPECT_CALL(*remote_input_injector_, StartPtr(_));
357 return remote_input_injector_;
360 webrtc::DesktopCapturer* IpcDesktopEnvironmentTest::CreateVideoCapturer() {
361 return new FakeDesktopCapturer();
364 webrtc::MouseCursorMonitor*
365 IpcDesktopEnvironmentTest::CreateMouseCursorMonitor() {
366 return new FakeMouseCursorMonitor();
369 void IpcDesktopEnvironmentTest::DeleteDesktopEnvironment() {
370 input_injector_.reset();
371 screen_controls_.reset();
372 video_capturer_.reset();
374 // Trigger DisconnectTerminal().
375 desktop_environment_.reset();
378 void IpcDesktopEnvironmentTest::ReflectClipboardEvent(
379 const protocol::ClipboardEvent& event) {
380 clipboard_stub_->InjectClipboardEvent(event);
383 void IpcDesktopEnvironmentTest::CreateDesktopProcess() {
384 EXPECT_TRUE(task_runner_.get());
385 EXPECT_TRUE(io_task_runner_.get());
387 // Create the daemon end of the daemon-to-desktop channel.
388 desktop_channel_name_ = IPC::Channel::GenerateUniqueRandomChannelID();
389 desktop_channel_ =
390 IPC::ChannelProxy::Create(IPC::ChannelHandle(desktop_channel_name_),
391 IPC::Channel::MODE_SERVER,
392 &desktop_listener_,
393 io_task_runner_.get());
395 // Create and start the desktop process.
396 desktop_process_.reset(new DesktopProcess(task_runner_,
397 io_task_runner_,
398 desktop_channel_name_));
400 scoped_ptr<MockDesktopEnvironmentFactory> desktop_environment_factory(
401 new MockDesktopEnvironmentFactory());
402 EXPECT_CALL(*desktop_environment_factory, CreatePtr())
403 .Times(AnyNumber())
404 .WillRepeatedly(Invoke(
405 this, &IpcDesktopEnvironmentTest::CreateDesktopEnvironment));
406 EXPECT_CALL(*desktop_environment_factory, SupportsAudioCapture())
407 .Times(AnyNumber())
408 .WillRepeatedly(Return(false));
410 EXPECT_TRUE(desktop_process_->Start(desktop_environment_factory.Pass()));
413 void IpcDesktopEnvironmentTest::DestoyDesktopProcess() {
414 desktop_channel_.reset();
415 if (desktop_process_) {
416 desktop_process_->OnChannelError();
417 desktop_process_.reset();
419 remote_input_injector_ = nullptr;
422 void IpcDesktopEnvironmentTest::OnDisconnectCallback() {
423 DeleteDesktopEnvironment();
426 void IpcDesktopEnvironmentTest::OnDesktopAttached(
427 IPC::PlatformFileForTransit desktop_pipe) {
429 base::ProcessHandle process_handle = base::GetCurrentProcessHandle();
430 #if defined(OS_WIN)
431 ASSERT_NE(FALSE, ::DuplicateHandle(GetCurrentProcess(), process_handle,
432 GetCurrentProcess(), &process_handle,
433 0, FALSE, DUPLICATE_SAME_ACCESS));
434 #endif
436 // Instruct DesktopSessionProxy to connect to the network-to-desktop pipe.
437 desktop_environment_factory_->OnDesktopSessionAgentAttached(
438 terminal_id_, process_handle, desktop_pipe);
441 // Runs until the desktop is attached and exits immediately after that.
442 TEST_F(IpcDesktopEnvironmentTest, Basic) {
443 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
444 new protocol::MockClipboardStub());
445 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
446 .Times(0);
448 // Start the input injector and screen capturer.
449 input_injector_->Start(clipboard_stub.Pass());
451 // Run the message loop until the desktop is attached.
452 setup_run_loop_->Run();
454 // Stop the test.
455 DeleteDesktopEnvironment();
457 task_runner_ = nullptr;
458 io_task_runner_ = nullptr;
459 main_run_loop_.Run();
462 // Tests that the video capturer receives a frame over IPC.
463 TEST_F(IpcDesktopEnvironmentTest, CaptureFrame) {
464 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
465 new protocol::MockClipboardStub());
466 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
467 .Times(0);
469 // Start the input injector and screen capturer.
470 input_injector_->Start(clipboard_stub.Pass());
471 video_capturer_->Start(&desktop_capturer_callback_);
473 // Run the message loop until the desktop is attached.
474 setup_run_loop_->Run();
476 // Stop the test when the first frame is captured.
477 EXPECT_CALL(desktop_capturer_callback_, OnCaptureCompleted(_))
478 .WillOnce(DoAll(
479 DeleteArg<0>(),
480 InvokeWithoutArgs(
481 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)));
483 // Capture a single frame.
484 video_capturer_->Capture(webrtc::DesktopRegion());
486 task_runner_ = nullptr;
487 io_task_runner_ = nullptr;
488 main_run_loop_.Run();
491 // Tests that attaching to a new desktop works.
492 TEST_F(IpcDesktopEnvironmentTest, Reattach) {
493 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
494 new protocol::MockClipboardStub());
495 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
496 .Times(0);
498 // Start the input injector and screen capturer.
499 input_injector_->Start(clipboard_stub.Pass());
500 video_capturer_->Start(&desktop_capturer_callback_);
502 // Run the message loop until the desktop is attached.
503 setup_run_loop_->Run();
505 // Create and start a new desktop process object.
506 setup_run_loop_.reset(new base::RunLoop());
507 DestoyDesktopProcess();
508 CreateDesktopProcess();
509 setup_run_loop_->Run();
511 // Stop the test.
512 DeleteDesktopEnvironment();
514 task_runner_ = nullptr;
515 io_task_runner_ = nullptr;
516 main_run_loop_.Run();
519 // Tests injection of clipboard events.
520 TEST_F(IpcDesktopEnvironmentTest, InjectClipboardEvent) {
521 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
522 new protocol::MockClipboardStub());
523 clipboard_stub_ = clipboard_stub.get();
525 // Stop the test when a clipboard event is received from the desktop process.
526 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
527 .Times(1)
528 .WillOnce(InvokeWithoutArgs(
529 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment));
531 // Start the input injector and screen capturer.
532 input_injector_->Start(clipboard_stub.Pass());
533 video_capturer_->Start(&desktop_capturer_callback_);
535 // Run the message loop until the desktop is attached.
536 setup_run_loop_->Run();
538 // Expect a single clipboard event.
539 EXPECT_CALL(*remote_input_injector_, InjectClipboardEvent(_))
540 .Times(1)
541 .WillOnce(Invoke(this,
542 &IpcDesktopEnvironmentTest::ReflectClipboardEvent));
544 // Send a clipboard event.
545 protocol::ClipboardEvent event;
546 event.set_mime_type(kMimeTypeTextUtf8);
547 event.set_data("a");
548 input_injector_->InjectClipboardEvent(event);
550 task_runner_ = nullptr;
551 io_task_runner_ = nullptr;
552 main_run_loop_.Run();
555 // Tests injection of key events.
556 TEST_F(IpcDesktopEnvironmentTest, InjectKeyEvent) {
557 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
558 new protocol::MockClipboardStub());
559 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
560 .Times(0);
562 // Start the input injector and screen capturer.
563 input_injector_->Start(clipboard_stub.Pass());
564 video_capturer_->Start(&desktop_capturer_callback_);
566 // Run the message loop until the desktop is attached.
567 setup_run_loop_->Run();
569 // Expect a single key event.
570 EXPECT_CALL(*remote_input_injector_, InjectKeyEvent(_))
571 .Times(AtLeast(1))
572 .WillRepeatedly(InvokeWithoutArgs(
573 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment));
575 // Send a key event.
576 protocol::KeyEvent event;
577 event.set_usb_keycode(0x070004);
578 event.set_pressed(true);
579 input_injector_->InjectKeyEvent(event);
581 task_runner_ = nullptr;
582 io_task_runner_ = nullptr;
583 main_run_loop_.Run();
586 // Tests injection of text events.
587 TEST_F(IpcDesktopEnvironmentTest, InjectTextEvent) {
588 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
589 new protocol::MockClipboardStub());
590 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
591 .Times(0);
593 // Start the input injector and screen capturer.
594 input_injector_->Start(clipboard_stub.Pass());
595 video_capturer_->Start(&desktop_capturer_callback_);
597 // Run the message loop until the desktop is attached.
598 setup_run_loop_->Run();
600 // Expect a single text event.
601 EXPECT_CALL(*remote_input_injector_, InjectTextEvent(_))
602 .Times(AtLeast(1))
603 .WillRepeatedly(InvokeWithoutArgs(
604 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment));
606 // Send a text event.
607 protocol::TextEvent event;
608 event.set_text("hello");
609 input_injector_->InjectTextEvent(event);
611 task_runner_ = nullptr;
612 io_task_runner_ = nullptr;
613 main_run_loop_.Run();
616 // Tests injection of mouse events.
617 TEST_F(IpcDesktopEnvironmentTest, InjectMouseEvent) {
618 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
619 new protocol::MockClipboardStub());
620 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
621 .Times(0);
623 // Start the input injector and screen capturer.
624 input_injector_->Start(clipboard_stub.Pass());
625 video_capturer_->Start(&desktop_capturer_callback_);
627 // Run the message loop until the desktop is attached.
628 setup_run_loop_->Run();
630 // Expect a single mouse event.
631 EXPECT_CALL(*remote_input_injector_, InjectMouseEvent(_))
632 .Times(1)
633 .WillOnce(InvokeWithoutArgs(
634 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment));
636 // Send a mouse event.
637 protocol::MouseEvent event;
638 event.set_x(0);
639 event.set_y(0);
640 input_injector_->InjectMouseEvent(event);
642 task_runner_ = nullptr;
643 io_task_runner_ = nullptr;
644 main_run_loop_.Run();
647 // Tests injection of touch events.
648 TEST_F(IpcDesktopEnvironmentTest, InjectTouchEvent) {
649 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
650 new protocol::MockClipboardStub());
651 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
652 .Times(0);
654 // Start the input injector and screen capturer.
655 input_injector_->Start(clipboard_stub.Pass());
656 video_capturer_->Start(&desktop_capturer_callback_);
658 // Run the message loop until the desktop is attached.
659 setup_run_loop_->Run();
661 protocol::TouchEvent event;
662 event.set_event_type(protocol::TouchEvent::TOUCH_POINT_START);
663 protocol::TouchEventPoint* point = event.add_touch_points();
664 point->set_id(0u);
665 point->set_x(0.0f);
666 point->set_y(0.0f);
667 point->set_radius_x(0.0f);
668 point->set_radius_y(0.0f);
669 point->set_angle(0.0f);
670 point->set_pressure(0.0f);
672 ON_CALL(*remote_input_injector_, InjectTouchEvent(_))
673 .WillByDefault(InvokeWithoutArgs(
674 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment));
676 InSequence s;
677 // Expect that the event gets propagated to remote_input_injector_.
678 // And one more call for ReleaseAll().
679 EXPECT_CALL(*remote_input_injector_,
680 InjectTouchEvent(EqualsTouchEvent(event)));
681 EXPECT_CALL(*remote_input_injector_,
682 InjectTouchEvent(EqualsTouchEventTypeAndId(
683 protocol::TouchEvent::TOUCH_POINT_CANCEL, 0u)));
685 // Send the touch event.
686 input_injector_->InjectTouchEvent(event);
688 task_runner_ = nullptr;
689 io_task_runner_ = nullptr;
690 main_run_loop_.Run();
693 // Tests that setting the desktop resolution works.
694 TEST_F(IpcDesktopEnvironmentTest, SetScreenResolution) {
695 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
696 new protocol::MockClipboardStub());
697 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
698 .Times(0);
700 // Start the input injector and screen capturer.
701 input_injector_->Start(clipboard_stub.Pass());
702 video_capturer_->Start(&desktop_capturer_callback_);
704 // Run the message loop until the desktop is attached.
705 setup_run_loop_->Run();
707 EXPECT_CALL(daemon_channel_, SetScreenResolution(_, _))
708 .Times(1)
709 .WillOnce(InvokeWithoutArgs(
710 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment));
712 // Change the desktop resolution.
713 screen_controls_->SetScreenResolution(ScreenResolution(
714 webrtc::DesktopSize(100, 100),
715 webrtc::DesktopVector(96, 96)));
717 task_runner_ = nullptr;
718 io_task_runner_ = nullptr;
719 main_run_loop_.Run();
722 } // namespace remoting