| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 class FakeDaemonSender : public IPC::Sender { | 52 class FakeDaemonSender : public IPC::Sender { |
| 53 public: | 53 public: |
| 54 FakeDaemonSender() {} | 54 FakeDaemonSender() {} |
| 55 virtual ~FakeDaemonSender() {} | 55 virtual ~FakeDaemonSender() {} |
| 56 | 56 |
| 57 // IPC::Sender implementation. | 57 // IPC::Sender implementation. |
| 58 virtual bool Send(IPC::Message* message) OVERRIDE; | 58 virtual bool Send(IPC::Message* message) OVERRIDE; |
| 59 | 59 |
| 60 MOCK_METHOD3(ConnectTerminal, void(int, const ScreenResolution&, bool)); | 60 MOCK_METHOD3(ConnectTerminal, void(int, const ScreenResolution&, bool)); |
| 61 MOCK_METHOD1(DisconnectTerminal, void(int)); | 61 MOCK_METHOD1(DisconnectTerminal, void(int)); |
| 62 MOCK_METHOD2(SetScreenResolution, void(int, const ScreenResolution&)); |
| 62 | 63 |
| 63 private: | 64 private: |
| 64 void OnMessageReceived(const IPC::Message& message); | 65 void OnMessageReceived(const IPC::Message& message); |
| 65 | 66 |
| 66 DISALLOW_COPY_AND_ASSIGN(FakeDaemonSender); | 67 DISALLOW_COPY_AND_ASSIGN(FakeDaemonSender); |
| 67 }; | 68 }; |
| 68 | 69 |
| 69 // Receives messages sent from the desktop process to the daemon. | 70 // Receives messages sent from the desktop process to the daemon. |
| 70 class MockDaemonListener : public IPC::Listener { | 71 class MockDaemonListener : public IPC::Listener { |
| 71 public: | 72 public: |
| (...skipping 16 matching lines...) Expand all Loading... |
| 88 return true; | 89 return true; |
| 89 } | 90 } |
| 90 | 91 |
| 91 void FakeDaemonSender::OnMessageReceived(const IPC::Message& message) { | 92 void FakeDaemonSender::OnMessageReceived(const IPC::Message& message) { |
| 92 bool handled = true; | 93 bool handled = true; |
| 93 IPC_BEGIN_MESSAGE_MAP(FakeDaemonSender, message) | 94 IPC_BEGIN_MESSAGE_MAP(FakeDaemonSender, message) |
| 94 IPC_MESSAGE_HANDLER(ChromotingNetworkHostMsg_ConnectTerminal, | 95 IPC_MESSAGE_HANDLER(ChromotingNetworkHostMsg_ConnectTerminal, |
| 95 ConnectTerminal) | 96 ConnectTerminal) |
| 96 IPC_MESSAGE_HANDLER(ChromotingNetworkHostMsg_DisconnectTerminal, | 97 IPC_MESSAGE_HANDLER(ChromotingNetworkHostMsg_DisconnectTerminal, |
| 97 DisconnectTerminal) | 98 DisconnectTerminal) |
| 99 IPC_MESSAGE_HANDLER(ChromotingNetworkDaemonMsg_SetScreenResolution, |
| 100 SetScreenResolution) |
| 98 IPC_MESSAGE_UNHANDLED(handled = false) | 101 IPC_MESSAGE_UNHANDLED(handled = false) |
| 99 IPC_END_MESSAGE_MAP() | 102 IPC_END_MESSAGE_MAP() |
| 100 | 103 |
| 101 EXPECT_TRUE(handled); | 104 EXPECT_TRUE(handled); |
| 102 } | 105 } |
| 103 | 106 |
| 104 bool MockDaemonListener::OnMessageReceived(const IPC::Message& message) { | 107 bool MockDaemonListener::OnMessageReceived(const IPC::Message& message) { |
| 105 bool handled = true; | 108 bool handled = true; |
| 106 IPC_BEGIN_MESSAGE_MAP(MockDaemonListener, message) | 109 IPC_BEGIN_MESSAGE_MAP(MockDaemonListener, message) |
| 107 IPC_MESSAGE_HANDLER(ChromotingDesktopDaemonMsg_DesktopAttached, | 110 IPC_MESSAGE_HANDLER(ChromotingDesktopDaemonMsg_DesktopAttached, |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 MockDaemonListener desktop_listener_; | 187 MockDaemonListener desktop_listener_; |
| 185 | 188 |
| 186 FakeDaemonSender daemon_channel_; | 189 FakeDaemonSender daemon_channel_; |
| 187 | 190 |
| 188 scoped_ptr<IpcDesktopEnvironmentFactory> desktop_environment_factory_; | 191 scoped_ptr<IpcDesktopEnvironmentFactory> desktop_environment_factory_; |
| 189 scoped_ptr<DesktopEnvironment> desktop_environment_; | 192 scoped_ptr<DesktopEnvironment> desktop_environment_; |
| 190 | 193 |
| 191 // The IPC input injector. | 194 // The IPC input injector. |
| 192 scoped_ptr<InputInjector> input_injector_; | 195 scoped_ptr<InputInjector> input_injector_; |
| 193 | 196 |
| 197 // The IPC screen controls. |
| 198 scoped_ptr<ScreenControls> screen_controls_; |
| 199 |
| 194 // The IPC screen capturer. | 200 // The IPC screen capturer. |
| 195 scoped_ptr<media::ScreenCapturer> video_capturer_; | 201 scoped_ptr<media::ScreenCapturer> video_capturer_; |
| 196 | 202 |
| 197 // Represents the desktop process running in a user session. | 203 // Represents the desktop process running in a user session. |
| 198 scoped_ptr<DesktopProcess> desktop_process_; | 204 scoped_ptr<DesktopProcess> desktop_process_; |
| 199 | 205 |
| 200 // Input injector owned by |desktop_process_|. | 206 // Input injector owned by |desktop_process_|. |
| 201 MockInputInjector* remote_input_injector_; | 207 MockInputInjector* remote_input_injector_; |
| 202 | 208 |
| 203 // The last |terminal_id| passed to ConnectTermina(); | 209 // The last |terminal_id| passed to ConnectTermina(); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 // Create a desktop environment instance. | 275 // Create a desktop environment instance. |
| 270 desktop_environment_factory_.reset(new IpcDesktopEnvironmentFactory( | 276 desktop_environment_factory_.reset(new IpcDesktopEnvironmentFactory( |
| 271 task_runner_, | 277 task_runner_, |
| 272 task_runner_, | 278 task_runner_, |
| 273 task_runner_, | 279 task_runner_, |
| 274 io_task_runner_, | 280 io_task_runner_, |
| 275 &daemon_channel_)); | 281 &daemon_channel_)); |
| 276 desktop_environment_ = desktop_environment_factory_->Create( | 282 desktop_environment_ = desktop_environment_factory_->Create( |
| 277 client_session_control_factory_.GetWeakPtr()); | 283 client_session_control_factory_.GetWeakPtr()); |
| 278 | 284 |
| 285 screen_controls_ = desktop_environment_->CreateScreenControls(); |
| 286 |
| 279 // Create the input injector. | 287 // Create the input injector. |
| 280 input_injector_ = desktop_environment_->CreateInputInjector(); | 288 input_injector_ = desktop_environment_->CreateInputInjector(); |
| 281 | 289 |
| 282 // Create the screen capturer. | 290 // Create the screen capturer. |
| 283 video_capturer_ = | 291 video_capturer_ = |
| 284 desktop_environment_->CreateVideoCapturer(); | 292 desktop_environment_->CreateVideoCapturer(); |
| 285 | 293 |
| 286 desktop_environment_->SetCapabilities(std::string()); | 294 desktop_environment_->SetCapabilities(std::string()); |
| 287 } | 295 } |
| 288 | 296 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 EXPECT_CALL(*remote_input_injector_, StartPtr(_)); | 344 EXPECT_CALL(*remote_input_injector_, StartPtr(_)); |
| 337 return remote_input_injector_; | 345 return remote_input_injector_; |
| 338 } | 346 } |
| 339 | 347 |
| 340 media::ScreenCapturer* IpcDesktopEnvironmentTest::CreateVideoCapturer() { | 348 media::ScreenCapturer* IpcDesktopEnvironmentTest::CreateVideoCapturer() { |
| 341 return new media::ScreenCapturerFake(); | 349 return new media::ScreenCapturerFake(); |
| 342 } | 350 } |
| 343 | 351 |
| 344 void IpcDesktopEnvironmentTest::DeleteDesktopEnvironment() { | 352 void IpcDesktopEnvironmentTest::DeleteDesktopEnvironment() { |
| 345 input_injector_.reset(); | 353 input_injector_.reset(); |
| 354 screen_controls_.reset(); |
| 346 video_capturer_.reset(); | 355 video_capturer_.reset(); |
| 347 | 356 |
| 348 // Trigger DisconnectTerminal(). | 357 // Trigger DisconnectTerminal(). |
| 349 desktop_environment_.reset(); | 358 desktop_environment_.reset(); |
| 350 } | 359 } |
| 351 | 360 |
| 352 void IpcDesktopEnvironmentTest::ReflectClipboardEvent( | 361 void IpcDesktopEnvironmentTest::ReflectClipboardEvent( |
| 353 const protocol::ClipboardEvent& event) { | 362 const protocol::ClipboardEvent& event) { |
| 354 clipboard_stub_->InjectClipboardEvent(event); | 363 clipboard_stub_->InjectClipboardEvent(event); |
| 355 } | 364 } |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 protocol::MouseEvent event; | 620 protocol::MouseEvent event; |
| 612 event.set_x(0); | 621 event.set_x(0); |
| 613 event.set_y(0); | 622 event.set_y(0); |
| 614 input_injector_->InjectMouseEvent(event); | 623 input_injector_->InjectMouseEvent(event); |
| 615 | 624 |
| 616 task_runner_ = NULL; | 625 task_runner_ = NULL; |
| 617 io_task_runner_ = NULL; | 626 io_task_runner_ = NULL; |
| 618 main_run_loop_.Run(); | 627 main_run_loop_.Run(); |
| 619 } | 628 } |
| 620 | 629 |
| 630 // Tests that setting the desktop resolution works. |
| 631 TEST_F(IpcDesktopEnvironmentTest, SetScreenResolution) { |
| 632 scoped_ptr<protocol::MockClipboardStub> clipboard_stub( |
| 633 new protocol::MockClipboardStub()); |
| 634 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) |
| 635 .Times(0); |
| 636 |
| 637 // Start the input injector and screen capturer. |
| 638 input_injector_->Start(clipboard_stub.PassAs<protocol::ClipboardStub>()); |
| 639 video_capturer_->Start(&screen_capturer_callback_); |
| 640 |
| 641 // Run the message loop until the desktop is attached. |
| 642 setup_run_loop_->Run(); |
| 643 |
| 644 EXPECT_CALL(daemon_channel_, SetScreenResolution(_, _)) |
| 645 .Times(1) |
| 646 .WillOnce(InvokeWithoutArgs( |
| 647 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); |
| 648 |
| 649 // Change the desktop resolution. |
| 650 screen_controls_->SetScreenResolution(ScreenResolution( |
| 651 webrtc::DesktopSize(100, 100), |
| 652 webrtc::DesktopVector(96, 96))); |
| 653 |
| 654 task_runner_ = NULL; |
| 655 io_task_runner_ = NULL; |
| 656 main_run_loop_.Run(); |
| 657 } |
| 658 |
| 621 } // namespace remoting | 659 } // namespace remoting |
| OLD | NEW |