| OLD | NEW |
| 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/daemon_process.h" |
| 6 |
| 5 #include <stdint.h> | 7 #include <stdint.h> |
| 6 | 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 9 #include "base/location.h" | 11 #include "base/location.h" |
| 10 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ptr_util.h" |
| 11 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 12 #include "base/process/process.h" | 15 #include "base/process/process.h" |
| 13 #include "ipc/ipc_message.h" | 16 #include "ipc/ipc_message.h" |
| 14 #include "ipc/ipc_message_macros.h" | 17 #include "ipc/ipc_message_macros.h" |
| 15 #include "ipc/ipc_platform_file.h" | 18 #include "ipc/ipc_platform_file.h" |
| 16 #include "remoting/base/auto_thread_task_runner.h" | 19 #include "remoting/base/auto_thread_task_runner.h" |
| 17 #include "remoting/host/chromoting_messages.h" | 20 #include "remoting/host/chromoting_messages.h" |
| 18 #include "remoting/host/daemon_process.h" | |
| 19 #include "remoting/host/desktop_session.h" | 21 #include "remoting/host/desktop_session.h" |
| 20 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
| 21 #include "testing/gmock_mutant.h" | 23 #include "testing/gmock_mutant.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 25 |
| 24 using testing::_; | 26 using testing::_; |
| 25 using testing::AnyNumber; | 27 using testing::AnyNumber; |
| 26 using testing::InSequence; | 28 using testing::InSequence; |
| 27 | 29 |
| 28 namespace remoting { | 30 namespace remoting { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 52 }; | 54 }; |
| 53 | 55 |
| 54 class MockDaemonProcess : public DaemonProcess { | 56 class MockDaemonProcess : public DaemonProcess { |
| 55 public: | 57 public: |
| 56 MockDaemonProcess( | 58 MockDaemonProcess( |
| 57 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, | 59 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, |
| 58 scoped_refptr<AutoThreadTaskRunner> io_task_runner, | 60 scoped_refptr<AutoThreadTaskRunner> io_task_runner, |
| 59 const base::Closure& stopped_callback); | 61 const base::Closure& stopped_callback); |
| 60 ~MockDaemonProcess() override; | 62 ~MockDaemonProcess() override; |
| 61 | 63 |
| 62 scoped_ptr<DesktopSession> DoCreateDesktopSession( | 64 std::unique_ptr<DesktopSession> DoCreateDesktopSession( |
| 63 int terminal_id, | 65 int terminal_id, |
| 64 const ScreenResolution& resolution, | 66 const ScreenResolution& resolution, |
| 65 bool virtual_terminal) override; | 67 bool virtual_terminal) override; |
| 66 | 68 |
| 67 bool OnMessageReceived(const IPC::Message& message) override; | 69 bool OnMessageReceived(const IPC::Message& message) override; |
| 68 void SendToNetwork(IPC::Message* message) override; | 70 void SendToNetwork(IPC::Message* message) override; |
| 69 | 71 |
| 70 MOCK_METHOD1(Received, void(const IPC::Message&)); | 72 MOCK_METHOD1(Received, void(const IPC::Message&)); |
| 71 MOCK_METHOD1(Sent, void(const IPC::Message&)); | 73 MOCK_METHOD1(Sent, void(const IPC::Message&)); |
| 72 | 74 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 91 MockDaemonProcess::MockDaemonProcess( | 93 MockDaemonProcess::MockDaemonProcess( |
| 92 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, | 94 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, |
| 93 scoped_refptr<AutoThreadTaskRunner> io_task_runner, | 95 scoped_refptr<AutoThreadTaskRunner> io_task_runner, |
| 94 const base::Closure& stopped_callback) | 96 const base::Closure& stopped_callback) |
| 95 : DaemonProcess(caller_task_runner, io_task_runner, stopped_callback) { | 97 : DaemonProcess(caller_task_runner, io_task_runner, stopped_callback) { |
| 96 } | 98 } |
| 97 | 99 |
| 98 MockDaemonProcess::~MockDaemonProcess() { | 100 MockDaemonProcess::~MockDaemonProcess() { |
| 99 } | 101 } |
| 100 | 102 |
| 101 scoped_ptr<DesktopSession> MockDaemonProcess::DoCreateDesktopSession( | 103 std::unique_ptr<DesktopSession> MockDaemonProcess::DoCreateDesktopSession( |
| 102 int terminal_id, | 104 int terminal_id, |
| 103 const ScreenResolution& resolution, | 105 const ScreenResolution& resolution, |
| 104 bool virtual_terminal) { | 106 bool virtual_terminal) { |
| 105 return make_scoped_ptr(DoCreateDesktopSessionPtr(terminal_id)); | 107 return base::WrapUnique(DoCreateDesktopSessionPtr(terminal_id)); |
| 106 } | 108 } |
| 107 | 109 |
| 108 bool MockDaemonProcess::OnMessageReceived(const IPC::Message& message) { | 110 bool MockDaemonProcess::OnMessageReceived(const IPC::Message& message) { |
| 109 // Notify the mock method. | 111 // Notify the mock method. |
| 110 Received(message); | 112 Received(message); |
| 111 | 113 |
| 112 // Call the actual handler. | 114 // Call the actual handler. |
| 113 return DaemonProcess::OnMessageReceived(message); | 115 return DaemonProcess::OnMessageReceived(message); |
| 114 } | 116 } |
| 115 | 117 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 142 | 144 |
| 143 void StartDaemonProcess(); | 145 void StartDaemonProcess(); |
| 144 | 146 |
| 145 const DaemonProcess::DesktopSessionList& desktop_sessions() const { | 147 const DaemonProcess::DesktopSessionList& desktop_sessions() const { |
| 146 return daemon_process_->desktop_sessions(); | 148 return daemon_process_->desktop_sessions(); |
| 147 } | 149 } |
| 148 | 150 |
| 149 protected: | 151 protected: |
| 150 base::MessageLoopForIO message_loop_; | 152 base::MessageLoopForIO message_loop_; |
| 151 | 153 |
| 152 scoped_ptr<MockDaemonProcess> daemon_process_; | 154 std::unique_ptr<MockDaemonProcess> daemon_process_; |
| 153 int terminal_id_; | 155 int terminal_id_; |
| 154 }; | 156 }; |
| 155 | 157 |
| 156 DaemonProcessTest::DaemonProcessTest() : terminal_id_(0) { | 158 DaemonProcessTest::DaemonProcessTest() : terminal_id_(0) { |
| 157 } | 159 } |
| 158 | 160 |
| 159 DaemonProcessTest::~DaemonProcessTest() { | 161 DaemonProcessTest::~DaemonProcessTest() { |
| 160 } | 162 } |
| 161 | 163 |
| 162 void DaemonProcessTest::SetUp() { | 164 void DaemonProcessTest::SetUp() { |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 EXPECT_EQ(1u, desktop_sessions().size()); | 337 EXPECT_EQ(1u, desktop_sessions().size()); |
| 336 EXPECT_EQ(id, desktop_sessions().front()->id()); | 338 EXPECT_EQ(id, desktop_sessions().front()->id()); |
| 337 | 339 |
| 338 EXPECT_TRUE(daemon_process_->OnMessageReceived( | 340 EXPECT_TRUE(daemon_process_->OnMessageReceived( |
| 339 ChromotingNetworkHostMsg_ConnectTerminal(id, resolution, false))); | 341 ChromotingNetworkHostMsg_ConnectTerminal(id, resolution, false))); |
| 340 EXPECT_TRUE(desktop_sessions().empty()); | 342 EXPECT_TRUE(desktop_sessions().empty()); |
| 341 EXPECT_EQ(0, terminal_id_); | 343 EXPECT_EQ(0, terminal_id_); |
| 342 } | 344 } |
| 343 | 345 |
| 344 } // namespace remoting | 346 } // namespace remoting |
| OLD | NEW |