Roll src/third_party/WebKit b41a10f:afd8afd (svn 202201:202202)
[chromium-blink-merge.git] / remoting / host / ipc_desktop_environment_unittest.cc
blobb8c39105292a801350e86593ff75e5ae12c95c24
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 ~FakeDaemonSender() override {}
62 // IPC::Sender implementation.
63 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 ~MockDaemonListener() override {}
81 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;
132 void TearDown() override;
134 void ConnectTerminal(int terminal_id,
135 const ScreenResolution& resolution,
136 bool virtual_terminal);
137 void DisconnectTerminal(int terminal_id);
139 // Creates a DesktopEnvironment with a fake webrtc::DesktopCapturer, to mock
140 // DesktopEnvironmentFactory::Create().
141 DesktopEnvironment* CreateDesktopEnvironment();
143 // Creates a dummy InputInjector, to mock
144 // DesktopEnvironment::CreateInputInjector().
145 InputInjector* CreateInputInjector();
147 // Creates a fake webrtc::DesktopCapturer, to mock
148 // DesktopEnvironment::CreateVideoCapturer().
149 webrtc::DesktopCapturer* CreateVideoCapturer();
151 // Creates a MockMouseCursorMonitor, to mock
152 // DesktopEnvironment::CreateMouseCursorMonitor
153 webrtc::MouseCursorMonitor* CreateMouseCursorMonitor();
155 void DeleteDesktopEnvironment();
157 // Forwards |event| to |clipboard_stub_|.
158 void ReflectClipboardEvent(const protocol::ClipboardEvent& event);
160 protected:
161 // Creates and starts an instance of desktop process object.
162 void CreateDesktopProcess();
164 // Destroys the desktop process object created by CreateDesktopProcess().
165 void DestoyDesktopProcess();
167 void OnDisconnectCallback();
169 // Invoked when ChromotingDesktopDaemonMsg_DesktopAttached message is
170 // received.
171 void OnDesktopAttached(IPC::PlatformFileForTransit desktop_pipe);
173 void RunMainLoopUntilDone();
175 // The main message loop.
176 base::MessageLoopForUI message_loop_;
178 // Runs until |desktop_session_proxy_| is connected to the desktop.
179 scoped_ptr<base::RunLoop> setup_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_;
226 private:
227 // Runs until there are references to |task_runner_|.
228 base::RunLoop main_run_loop_;
231 IpcDesktopEnvironmentTest::IpcDesktopEnvironmentTest()
232 : client_jid_("user@domain/rest-of-jid"),
233 clipboard_stub_(nullptr),
234 remote_input_injector_(nullptr),
235 terminal_id_(-1),
236 client_session_control_factory_(&client_session_control_) {
239 IpcDesktopEnvironmentTest::~IpcDesktopEnvironmentTest() {
242 void IpcDesktopEnvironmentTest::SetUp() {
243 // Arrange to run |message_loop_| until no components depend on it.
244 task_runner_ = new AutoThreadTaskRunner(
245 message_loop_.task_runner(), main_run_loop_.QuitClosure());
247 io_task_runner_ = AutoThread::CreateWithType(
248 "IPC thread", task_runner_, base::MessageLoop::TYPE_IO);
250 setup_run_loop_.reset(new base::RunLoop());
252 // Set expectation that the DaemonProcess will send DesktopAttached message
253 // once it is ready.
254 EXPECT_CALL(desktop_listener_, OnChannelConnected(_))
255 .Times(AnyNumber());
256 EXPECT_CALL(desktop_listener_, OnDesktopAttached(_))
257 .Times(AnyNumber())
258 .WillRepeatedly(Invoke(this,
259 &IpcDesktopEnvironmentTest::OnDesktopAttached));
260 EXPECT_CALL(desktop_listener_, OnChannelError())
261 .Times(AnyNumber())
262 .WillOnce(Invoke(this,
263 &IpcDesktopEnvironmentTest::DestoyDesktopProcess));
265 // Intercept requests to connect and disconnect a terminal.
266 EXPECT_CALL(daemon_channel_, ConnectTerminal(_, _, _))
267 .Times(AnyNumber())
268 .WillRepeatedly(Invoke(this,
269 &IpcDesktopEnvironmentTest::ConnectTerminal));
270 EXPECT_CALL(daemon_channel_, DisconnectTerminal(_))
271 .Times(AnyNumber())
272 .WillRepeatedly(Invoke(this,
273 &IpcDesktopEnvironmentTest::DisconnectTerminal));
275 EXPECT_CALL(client_session_control_, client_jid())
276 .Times(AnyNumber())
277 .WillRepeatedly(ReturnRef(client_jid_));
278 EXPECT_CALL(client_session_control_, DisconnectSession())
279 .Times(AnyNumber())
280 .WillRepeatedly(Invoke(
281 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment));
282 EXPECT_CALL(client_session_control_, OnLocalMouseMoved(_))
283 .Times(0);
284 EXPECT_CALL(client_session_control_, SetDisableInputs(_))
285 .Times(0);
287 // Create a desktop environment instance.
288 desktop_environment_factory_.reset(new IpcDesktopEnvironmentFactory(
289 task_runner_,
290 task_runner_,
291 task_runner_,
292 io_task_runner_,
293 &daemon_channel_));
294 desktop_environment_ = desktop_environment_factory_->Create(
295 client_session_control_factory_.GetWeakPtr());
297 screen_controls_ = desktop_environment_->CreateScreenControls();
299 // Create the input injector.
300 input_injector_ = desktop_environment_->CreateInputInjector();
302 // Create the screen capturer.
303 video_capturer_ =
304 desktop_environment_->CreateVideoCapturer();
306 desktop_environment_->SetCapabilities(std::string());
309 void IpcDesktopEnvironmentTest::TearDown() {
310 RunMainLoopUntilDone();
313 void IpcDesktopEnvironmentTest::ConnectTerminal(
314 int terminal_id,
315 const ScreenResolution& resolution,
316 bool virtual_terminal) {
317 EXPECT_NE(terminal_id_, terminal_id);
319 terminal_id_ = terminal_id;
320 CreateDesktopProcess();
323 void IpcDesktopEnvironmentTest::DisconnectTerminal(int terminal_id) {
324 EXPECT_EQ(terminal_id_, terminal_id);
326 // The IPC desktop environment is fully destroyed now. Release the remaining
327 // task runners.
328 desktop_environment_factory_.reset();
331 DesktopEnvironment* IpcDesktopEnvironmentTest::CreateDesktopEnvironment() {
332 MockDesktopEnvironment* desktop_environment = new MockDesktopEnvironment();
333 EXPECT_CALL(*desktop_environment, CreateAudioCapturerPtr())
334 .Times(0);
335 EXPECT_CALL(*desktop_environment, CreateInputInjectorPtr())
336 .Times(AtMost(1))
337 .WillOnce(Invoke(
338 this, &IpcDesktopEnvironmentTest::CreateInputInjector));
339 EXPECT_CALL(*desktop_environment, CreateScreenControlsPtr())
340 .Times(AtMost(1));
341 EXPECT_CALL(*desktop_environment, CreateVideoCapturerPtr())
342 .Times(AtMost(1))
343 .WillOnce(Invoke(
344 this, &IpcDesktopEnvironmentTest::CreateVideoCapturer));
345 EXPECT_CALL(*desktop_environment, CreateMouseCursorMonitorPtr())
346 .Times(AtMost(1))
347 .WillOnce(Invoke(
348 this, &IpcDesktopEnvironmentTest::CreateMouseCursorMonitor));
349 EXPECT_CALL(*desktop_environment, GetCapabilities())
350 .Times(AtMost(1));
351 EXPECT_CALL(*desktop_environment, SetCapabilities(_))
352 .Times(AtMost(1));
354 // Let tests know that the remote desktop environment is created.
355 message_loop_.PostTask(FROM_HERE, setup_run_loop_->QuitClosure());
357 return desktop_environment;
360 InputInjector* IpcDesktopEnvironmentTest::CreateInputInjector() {
361 EXPECT_TRUE(remote_input_injector_ == nullptr);
362 remote_input_injector_ = new testing::StrictMock<MockInputInjector>();
364 EXPECT_CALL(*remote_input_injector_, StartPtr(_));
365 return remote_input_injector_;
368 webrtc::DesktopCapturer* IpcDesktopEnvironmentTest::CreateVideoCapturer() {
369 return new FakeDesktopCapturer();
372 webrtc::MouseCursorMonitor*
373 IpcDesktopEnvironmentTest::CreateMouseCursorMonitor() {
374 return new FakeMouseCursorMonitor();
377 void IpcDesktopEnvironmentTest::DeleteDesktopEnvironment() {
378 input_injector_.reset();
379 screen_controls_.reset();
380 video_capturer_.reset();
382 // Trigger DisconnectTerminal().
383 desktop_environment_.reset();
386 void IpcDesktopEnvironmentTest::ReflectClipboardEvent(
387 const protocol::ClipboardEvent& event) {
388 clipboard_stub_->InjectClipboardEvent(event);
391 void IpcDesktopEnvironmentTest::CreateDesktopProcess() {
392 EXPECT_TRUE(task_runner_.get());
393 EXPECT_TRUE(io_task_runner_.get());
395 // Create the daemon end of the daemon-to-desktop channel.
396 desktop_channel_name_ = IPC::Channel::GenerateUniqueRandomChannelID();
397 desktop_channel_ =
398 IPC::ChannelProxy::Create(IPC::ChannelHandle(desktop_channel_name_),
399 IPC::Channel::MODE_SERVER,
400 &desktop_listener_,
401 io_task_runner_.get(),
402 nullptr);
404 // Create and start the desktop process.
405 desktop_process_.reset(new DesktopProcess(task_runner_,
406 io_task_runner_,
407 desktop_channel_name_));
409 scoped_ptr<MockDesktopEnvironmentFactory> desktop_environment_factory(
410 new MockDesktopEnvironmentFactory());
411 EXPECT_CALL(*desktop_environment_factory, CreatePtr())
412 .Times(AnyNumber())
413 .WillRepeatedly(Invoke(
414 this, &IpcDesktopEnvironmentTest::CreateDesktopEnvironment));
415 EXPECT_CALL(*desktop_environment_factory, SupportsAudioCapture())
416 .Times(AnyNumber())
417 .WillRepeatedly(Return(false));
419 EXPECT_TRUE(desktop_process_->Start(desktop_environment_factory.Pass()));
422 void IpcDesktopEnvironmentTest::DestoyDesktopProcess() {
423 desktop_channel_.reset();
424 if (desktop_process_) {
425 desktop_process_->OnChannelError();
426 desktop_process_.reset();
428 remote_input_injector_ = nullptr;
431 void IpcDesktopEnvironmentTest::OnDisconnectCallback() {
432 DeleteDesktopEnvironment();
435 void IpcDesktopEnvironmentTest::OnDesktopAttached(
436 IPC::PlatformFileForTransit desktop_pipe) {
438 base::ProcessHandle process_handle = base::GetCurrentProcessHandle();
439 #if defined(OS_WIN)
440 ASSERT_NE(FALSE, ::DuplicateHandle(GetCurrentProcess(), process_handle,
441 GetCurrentProcess(), &process_handle,
442 0, FALSE, DUPLICATE_SAME_ACCESS));
443 #endif
445 // Instruct DesktopSessionProxy to connect to the network-to-desktop pipe.
446 desktop_environment_factory_->OnDesktopSessionAgentAttached(
447 terminal_id_, process_handle, desktop_pipe);
450 void IpcDesktopEnvironmentTest::RunMainLoopUntilDone() {
451 task_runner_ = nullptr;
452 io_task_runner_ = nullptr;
453 main_run_loop_.Run();
456 // Runs until the desktop is attached and exits immediately after that.
457 TEST_F(IpcDesktopEnvironmentTest, Basic) {
458 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
459 new protocol::MockClipboardStub());
460 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
461 .Times(0);
463 // Start the input injector and screen capturer.
464 input_injector_->Start(clipboard_stub.Pass());
466 // Run the message loop until the desktop is attached.
467 setup_run_loop_->Run();
469 // Stop the test.
470 DeleteDesktopEnvironment();
473 // Check Capabilities.
474 TEST_F(IpcDesktopEnvironmentTest, CapabilitiesNoTouch) {
475 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
476 new protocol::MockClipboardStub());
477 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
478 .Times(0);
480 EXPECT_EQ("rateLimitResizeRequests", desktop_environment_->GetCapabilities());
482 // Start the input injector and screen capturer.
483 input_injector_->Start(clipboard_stub.Pass());
485 // Run the message loop until the desktop is attached.
486 setup_run_loop_->Run();
488 // Stop the test.
489 DeleteDesktopEnvironment();
492 // Check touchEvents capability is set when the desktop environment can
493 // inject touch events.
494 TEST_F(IpcDesktopEnvironmentTest, TouchEventsCapabilities) {
495 // Create an environment with multi touch enabled.
496 desktop_environment_factory_->set_supports_touch_events(true);
497 desktop_environment_ = desktop_environment_factory_->Create(
498 client_session_control_factory_.GetWeakPtr());
500 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
501 new protocol::MockClipboardStub());
502 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
503 .Times(0);
505 EXPECT_EQ("rateLimitResizeRequests touchEvents",
506 desktop_environment_->GetCapabilities());
508 // Start the input injector and screen capturer.
509 input_injector_->Start(clipboard_stub.Pass());
511 // Run the message loop until the desktop is attached.
512 setup_run_loop_->Run();
514 // Stop the test.
515 DeleteDesktopEnvironment();
518 // Tests that the video capturer receives a frame over IPC.
519 TEST_F(IpcDesktopEnvironmentTest, CaptureFrame) {
520 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
521 new protocol::MockClipboardStub());
522 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
523 .Times(0);
525 // Start the input injector and screen capturer.
526 input_injector_->Start(clipboard_stub.Pass());
527 video_capturer_->Start(&desktop_capturer_callback_);
529 // Run the message loop until the desktop is attached.
530 setup_run_loop_->Run();
532 // Stop the test when the first frame is captured.
533 EXPECT_CALL(desktop_capturer_callback_, OnCaptureCompleted(_))
534 .WillOnce(DoAll(
535 DeleteArg<0>(),
536 InvokeWithoutArgs(
537 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)));
539 // Capture a single frame.
540 video_capturer_->Capture(webrtc::DesktopRegion());
543 // Tests that attaching to a new desktop works.
544 TEST_F(IpcDesktopEnvironmentTest, Reattach) {
545 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
546 new protocol::MockClipboardStub());
547 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
548 .Times(0);
550 // Start the input injector and screen capturer.
551 input_injector_->Start(clipboard_stub.Pass());
552 video_capturer_->Start(&desktop_capturer_callback_);
554 // Run the message loop until the desktop is attached.
555 setup_run_loop_->Run();
557 // Create and start a new desktop process object.
558 setup_run_loop_.reset(new base::RunLoop());
559 DestoyDesktopProcess();
560 CreateDesktopProcess();
561 setup_run_loop_->Run();
563 // Stop the test.
564 DeleteDesktopEnvironment();
567 // Tests injection of clipboard events.
568 TEST_F(IpcDesktopEnvironmentTest, InjectClipboardEvent) {
569 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
570 new protocol::MockClipboardStub());
571 clipboard_stub_ = clipboard_stub.get();
573 // Stop the test when a clipboard event is received from the desktop process.
574 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
575 .Times(1)
576 .WillOnce(InvokeWithoutArgs(
577 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment));
579 // Start the input injector and screen capturer.
580 input_injector_->Start(clipboard_stub.Pass());
581 video_capturer_->Start(&desktop_capturer_callback_);
583 // Run the message loop until the desktop is attached.
584 setup_run_loop_->Run();
586 // Expect a single clipboard event.
587 EXPECT_CALL(*remote_input_injector_, InjectClipboardEvent(_))
588 .Times(1)
589 .WillOnce(Invoke(this,
590 &IpcDesktopEnvironmentTest::ReflectClipboardEvent));
592 // Send a clipboard event.
593 protocol::ClipboardEvent event;
594 event.set_mime_type(kMimeTypeTextUtf8);
595 event.set_data("a");
596 input_injector_->InjectClipboardEvent(event);
599 // Tests injection of key events.
600 TEST_F(IpcDesktopEnvironmentTest, InjectKeyEvent) {
601 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
602 new protocol::MockClipboardStub());
603 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
604 .Times(0);
606 // Start the input injector and screen capturer.
607 input_injector_->Start(clipboard_stub.Pass());
608 video_capturer_->Start(&desktop_capturer_callback_);
610 // Run the message loop until the desktop is attached.
611 setup_run_loop_->Run();
613 // Expect a single key event.
614 EXPECT_CALL(*remote_input_injector_, InjectKeyEvent(_))
615 .Times(AtLeast(1))
616 .WillRepeatedly(InvokeWithoutArgs(
617 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment));
619 // Send a key event.
620 protocol::KeyEvent event;
621 event.set_usb_keycode(0x070004);
622 event.set_pressed(true);
623 input_injector_->InjectKeyEvent(event);
626 // Tests injection of text events.
627 TEST_F(IpcDesktopEnvironmentTest, InjectTextEvent) {
628 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
629 new protocol::MockClipboardStub());
630 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
631 .Times(0);
633 // Start the input injector and screen capturer.
634 input_injector_->Start(clipboard_stub.Pass());
635 video_capturer_->Start(&desktop_capturer_callback_);
637 // Run the message loop until the desktop is attached.
638 setup_run_loop_->Run();
640 // Expect a single text event.
641 EXPECT_CALL(*remote_input_injector_, InjectTextEvent(_))
642 .Times(AtLeast(1))
643 .WillRepeatedly(InvokeWithoutArgs(
644 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment));
646 // Send a text event.
647 protocol::TextEvent event;
648 event.set_text("hello");
649 input_injector_->InjectTextEvent(event);
652 // Tests injection of mouse events.
653 TEST_F(IpcDesktopEnvironmentTest, InjectMouseEvent) {
654 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
655 new protocol::MockClipboardStub());
656 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
657 .Times(0);
659 // Start the input injector and screen capturer.
660 input_injector_->Start(clipboard_stub.Pass());
661 video_capturer_->Start(&desktop_capturer_callback_);
663 // Run the message loop until the desktop is attached.
664 setup_run_loop_->Run();
666 // Expect a single mouse event.
667 EXPECT_CALL(*remote_input_injector_, InjectMouseEvent(_))
668 .Times(1)
669 .WillOnce(InvokeWithoutArgs(
670 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment));
672 // Send a mouse event.
673 protocol::MouseEvent event;
674 event.set_x(0);
675 event.set_y(0);
676 input_injector_->InjectMouseEvent(event);
679 // Tests injection of touch events.
680 TEST_F(IpcDesktopEnvironmentTest, InjectTouchEvent) {
681 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
682 new protocol::MockClipboardStub());
683 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
684 .Times(0);
686 // Start the input injector and screen capturer.
687 input_injector_->Start(clipboard_stub.Pass());
688 video_capturer_->Start(&desktop_capturer_callback_);
690 // Run the message loop until the desktop is attached.
691 setup_run_loop_->Run();
693 protocol::TouchEvent event;
694 event.set_event_type(protocol::TouchEvent::TOUCH_POINT_START);
695 protocol::TouchEventPoint* point = event.add_touch_points();
696 point->set_id(0u);
697 point->set_x(0.0f);
698 point->set_y(0.0f);
699 point->set_radius_x(0.0f);
700 point->set_radius_y(0.0f);
701 point->set_angle(0.0f);
702 point->set_pressure(0.0f);
704 ON_CALL(*remote_input_injector_, InjectTouchEvent(_))
705 .WillByDefault(InvokeWithoutArgs(
706 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment));
708 InSequence s;
709 // Expect that the event gets propagated to remote_input_injector_.
710 // And one more call for ReleaseAll().
711 EXPECT_CALL(*remote_input_injector_,
712 InjectTouchEvent(EqualsTouchEvent(event)));
713 EXPECT_CALL(*remote_input_injector_,
714 InjectTouchEvent(EqualsTouchEventTypeAndId(
715 protocol::TouchEvent::TOUCH_POINT_CANCEL, 0u)));
717 // Send the touch event.
718 input_injector_->InjectTouchEvent(event);
721 // Tests that setting the desktop resolution works.
722 TEST_F(IpcDesktopEnvironmentTest, SetScreenResolution) {
723 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
724 new protocol::MockClipboardStub());
725 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
726 .Times(0);
728 // Start the input injector and screen capturer.
729 input_injector_->Start(clipboard_stub.Pass());
730 video_capturer_->Start(&desktop_capturer_callback_);
732 // Run the message loop until the desktop is attached.
733 setup_run_loop_->Run();
735 EXPECT_CALL(daemon_channel_, SetScreenResolution(_, _))
736 .Times(1)
737 .WillOnce(InvokeWithoutArgs(
738 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment));
740 // Change the desktop resolution.
741 screen_controls_->SetScreenResolution(ScreenResolution(
742 webrtc::DesktopSize(100, 100),
743 webrtc::DesktopVector(96, 96)));
746 } // namespace remoting