Compute can_use_lcd_text using property trees.
[chromium-blink-merge.git] / remoting / host / ipc_desktop_environment_unittest.cc
blobcce01240653ff61418fa435e0a130fd48c142862
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());
403 // Create and start the desktop process.
404 desktop_process_.reset(new DesktopProcess(task_runner_,
405 io_task_runner_,
406 desktop_channel_name_));
408 scoped_ptr<MockDesktopEnvironmentFactory> desktop_environment_factory(
409 new MockDesktopEnvironmentFactory());
410 EXPECT_CALL(*desktop_environment_factory, CreatePtr())
411 .Times(AnyNumber())
412 .WillRepeatedly(Invoke(
413 this, &IpcDesktopEnvironmentTest::CreateDesktopEnvironment));
414 EXPECT_CALL(*desktop_environment_factory, SupportsAudioCapture())
415 .Times(AnyNumber())
416 .WillRepeatedly(Return(false));
418 EXPECT_TRUE(desktop_process_->Start(desktop_environment_factory.Pass()));
421 void IpcDesktopEnvironmentTest::DestoyDesktopProcess() {
422 desktop_channel_.reset();
423 if (desktop_process_) {
424 desktop_process_->OnChannelError();
425 desktop_process_.reset();
427 remote_input_injector_ = nullptr;
430 void IpcDesktopEnvironmentTest::OnDisconnectCallback() {
431 DeleteDesktopEnvironment();
434 void IpcDesktopEnvironmentTest::OnDesktopAttached(
435 IPC::PlatformFileForTransit desktop_pipe) {
437 base::ProcessHandle process_handle = base::GetCurrentProcessHandle();
438 #if defined(OS_WIN)
439 ASSERT_NE(FALSE, ::DuplicateHandle(GetCurrentProcess(), process_handle,
440 GetCurrentProcess(), &process_handle,
441 0, FALSE, DUPLICATE_SAME_ACCESS));
442 #endif
444 // Instruct DesktopSessionProxy to connect to the network-to-desktop pipe.
445 desktop_environment_factory_->OnDesktopSessionAgentAttached(
446 terminal_id_, process_handle, desktop_pipe);
449 void IpcDesktopEnvironmentTest::RunMainLoopUntilDone() {
450 task_runner_ = nullptr;
451 io_task_runner_ = nullptr;
452 main_run_loop_.Run();
455 // Runs until the desktop is attached and exits immediately after that.
456 TEST_F(IpcDesktopEnvironmentTest, Basic) {
457 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
458 new protocol::MockClipboardStub());
459 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
460 .Times(0);
462 // Start the input injector and screen capturer.
463 input_injector_->Start(clipboard_stub.Pass());
465 // Run the message loop until the desktop is attached.
466 setup_run_loop_->Run();
468 // Stop the test.
469 DeleteDesktopEnvironment();
472 // Check Capabilities.
473 TEST_F(IpcDesktopEnvironmentTest, CapabilitiesNoTouch) {
474 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
475 new protocol::MockClipboardStub());
476 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
477 .Times(0);
479 EXPECT_EQ("rateLimitResizeRequests", desktop_environment_->GetCapabilities());
481 // Start the input injector and screen capturer.
482 input_injector_->Start(clipboard_stub.Pass());
484 // Run the message loop until the desktop is attached.
485 setup_run_loop_->Run();
487 // Stop the test.
488 DeleteDesktopEnvironment();
491 // Check touchEvents capability is set when the desktop environment can
492 // inject touch events.
493 TEST_F(IpcDesktopEnvironmentTest, TouchEventsCapabilities) {
494 // Create an environment with multi touch enabled.
495 desktop_environment_factory_->set_supports_touch_events(true);
496 desktop_environment_ = desktop_environment_factory_->Create(
497 client_session_control_factory_.GetWeakPtr());
499 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
500 new protocol::MockClipboardStub());
501 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
502 .Times(0);
504 EXPECT_EQ("rateLimitResizeRequests touchEvents",
505 desktop_environment_->GetCapabilities());
507 // Start the input injector and screen capturer.
508 input_injector_->Start(clipboard_stub.Pass());
510 // Run the message loop until the desktop is attached.
511 setup_run_loop_->Run();
513 // Stop the test.
514 DeleteDesktopEnvironment();
517 // Tests that the video capturer receives a frame over IPC.
518 TEST_F(IpcDesktopEnvironmentTest, CaptureFrame) {
519 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
520 new protocol::MockClipboardStub());
521 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
522 .Times(0);
524 // Start the input injector and screen capturer.
525 input_injector_->Start(clipboard_stub.Pass());
526 video_capturer_->Start(&desktop_capturer_callback_);
528 // Run the message loop until the desktop is attached.
529 setup_run_loop_->Run();
531 // Stop the test when the first frame is captured.
532 EXPECT_CALL(desktop_capturer_callback_, OnCaptureCompleted(_))
533 .WillOnce(DoAll(
534 DeleteArg<0>(),
535 InvokeWithoutArgs(
536 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)));
538 // Capture a single frame.
539 video_capturer_->Capture(webrtc::DesktopRegion());
542 // Tests that attaching to a new desktop works.
543 TEST_F(IpcDesktopEnvironmentTest, Reattach) {
544 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
545 new protocol::MockClipboardStub());
546 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
547 .Times(0);
549 // Start the input injector and screen capturer.
550 input_injector_->Start(clipboard_stub.Pass());
551 video_capturer_->Start(&desktop_capturer_callback_);
553 // Run the message loop until the desktop is attached.
554 setup_run_loop_->Run();
556 // Create and start a new desktop process object.
557 setup_run_loop_.reset(new base::RunLoop());
558 DestoyDesktopProcess();
559 CreateDesktopProcess();
560 setup_run_loop_->Run();
562 // Stop the test.
563 DeleteDesktopEnvironment();
566 // Tests injection of clipboard events.
567 TEST_F(IpcDesktopEnvironmentTest, InjectClipboardEvent) {
568 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
569 new protocol::MockClipboardStub());
570 clipboard_stub_ = clipboard_stub.get();
572 // Stop the test when a clipboard event is received from the desktop process.
573 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
574 .Times(1)
575 .WillOnce(InvokeWithoutArgs(
576 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment));
578 // Start the input injector and screen capturer.
579 input_injector_->Start(clipboard_stub.Pass());
580 video_capturer_->Start(&desktop_capturer_callback_);
582 // Run the message loop until the desktop is attached.
583 setup_run_loop_->Run();
585 // Expect a single clipboard event.
586 EXPECT_CALL(*remote_input_injector_, InjectClipboardEvent(_))
587 .Times(1)
588 .WillOnce(Invoke(this,
589 &IpcDesktopEnvironmentTest::ReflectClipboardEvent));
591 // Send a clipboard event.
592 protocol::ClipboardEvent event;
593 event.set_mime_type(kMimeTypeTextUtf8);
594 event.set_data("a");
595 input_injector_->InjectClipboardEvent(event);
598 // Tests injection of key events.
599 TEST_F(IpcDesktopEnvironmentTest, InjectKeyEvent) {
600 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
601 new protocol::MockClipboardStub());
602 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
603 .Times(0);
605 // Start the input injector and screen capturer.
606 input_injector_->Start(clipboard_stub.Pass());
607 video_capturer_->Start(&desktop_capturer_callback_);
609 // Run the message loop until the desktop is attached.
610 setup_run_loop_->Run();
612 // Expect a single key event.
613 EXPECT_CALL(*remote_input_injector_, InjectKeyEvent(_))
614 .Times(AtLeast(1))
615 .WillRepeatedly(InvokeWithoutArgs(
616 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment));
618 // Send a key event.
619 protocol::KeyEvent event;
620 event.set_usb_keycode(0x070004);
621 event.set_pressed(true);
622 input_injector_->InjectKeyEvent(event);
625 // Tests injection of text events.
626 TEST_F(IpcDesktopEnvironmentTest, InjectTextEvent) {
627 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
628 new protocol::MockClipboardStub());
629 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
630 .Times(0);
632 // Start the input injector and screen capturer.
633 input_injector_->Start(clipboard_stub.Pass());
634 video_capturer_->Start(&desktop_capturer_callback_);
636 // Run the message loop until the desktop is attached.
637 setup_run_loop_->Run();
639 // Expect a single text event.
640 EXPECT_CALL(*remote_input_injector_, InjectTextEvent(_))
641 .Times(AtLeast(1))
642 .WillRepeatedly(InvokeWithoutArgs(
643 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment));
645 // Send a text event.
646 protocol::TextEvent event;
647 event.set_text("hello");
648 input_injector_->InjectTextEvent(event);
651 // Tests injection of mouse events.
652 TEST_F(IpcDesktopEnvironmentTest, InjectMouseEvent) {
653 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
654 new protocol::MockClipboardStub());
655 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
656 .Times(0);
658 // Start the input injector and screen capturer.
659 input_injector_->Start(clipboard_stub.Pass());
660 video_capturer_->Start(&desktop_capturer_callback_);
662 // Run the message loop until the desktop is attached.
663 setup_run_loop_->Run();
665 // Expect a single mouse event.
666 EXPECT_CALL(*remote_input_injector_, InjectMouseEvent(_))
667 .Times(1)
668 .WillOnce(InvokeWithoutArgs(
669 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment));
671 // Send a mouse event.
672 protocol::MouseEvent event;
673 event.set_x(0);
674 event.set_y(0);
675 input_injector_->InjectMouseEvent(event);
678 // Tests injection of touch events.
679 TEST_F(IpcDesktopEnvironmentTest, InjectTouchEvent) {
680 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
681 new protocol::MockClipboardStub());
682 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
683 .Times(0);
685 // Start the input injector and screen capturer.
686 input_injector_->Start(clipboard_stub.Pass());
687 video_capturer_->Start(&desktop_capturer_callback_);
689 // Run the message loop until the desktop is attached.
690 setup_run_loop_->Run();
692 protocol::TouchEvent event;
693 event.set_event_type(protocol::TouchEvent::TOUCH_POINT_START);
694 protocol::TouchEventPoint* point = event.add_touch_points();
695 point->set_id(0u);
696 point->set_x(0.0f);
697 point->set_y(0.0f);
698 point->set_radius_x(0.0f);
699 point->set_radius_y(0.0f);
700 point->set_angle(0.0f);
701 point->set_pressure(0.0f);
703 ON_CALL(*remote_input_injector_, InjectTouchEvent(_))
704 .WillByDefault(InvokeWithoutArgs(
705 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment));
707 InSequence s;
708 // Expect that the event gets propagated to remote_input_injector_.
709 // And one more call for ReleaseAll().
710 EXPECT_CALL(*remote_input_injector_,
711 InjectTouchEvent(EqualsTouchEvent(event)));
712 EXPECT_CALL(*remote_input_injector_,
713 InjectTouchEvent(EqualsTouchEventTypeAndId(
714 protocol::TouchEvent::TOUCH_POINT_CANCEL, 0u)));
716 // Send the touch event.
717 input_injector_->InjectTouchEvent(event);
720 // Tests that setting the desktop resolution works.
721 TEST_F(IpcDesktopEnvironmentTest, SetScreenResolution) {
722 scoped_ptr<protocol::MockClipboardStub> clipboard_stub(
723 new protocol::MockClipboardStub());
724 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_))
725 .Times(0);
727 // Start the input injector and screen capturer.
728 input_injector_->Start(clipboard_stub.Pass());
729 video_capturer_->Start(&desktop_capturer_callback_);
731 // Run the message loop until the desktop is attached.
732 setup_run_loop_->Run();
734 EXPECT_CALL(daemon_channel_, SetScreenResolution(_, _))
735 .Times(1)
736 .WillOnce(InvokeWithoutArgs(
737 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment));
739 // Change the desktop resolution.
740 screen_controls_->SetScreenResolution(ScreenResolution(
741 webrtc::DesktopSize(100, 100),
742 webrtc::DesktopVector(96, 96)));
745 } // namespace remoting