Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(451)

Side by Side Diff: remoting/host/desktop_process_unittest.cc

Issue 2451953002: Use ChannelMojo between the remoting network and desktop processes. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/host/desktop_process.cc ('k') | remoting/host/desktop_session_agent.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/desktop_process.h" 5 #include "remoting/host/desktop_process.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/message_loop/message_loop.h" 16 #include "base/message_loop/message_loop.h"
17 #include "base/run_loop.h" 17 #include "base/run_loop.h"
18 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
19 #include "build/build_config.h" 19 #include "build/build_config.h"
20 #include "ipc/attachment_broker_privileged.h"
21 #include "ipc/ipc_channel.h" 20 #include "ipc/ipc_channel.h"
22 #include "ipc/ipc_channel_proxy.h" 21 #include "ipc/ipc_channel_proxy.h"
23 #include "ipc/ipc_listener.h" 22 #include "ipc/ipc_listener.h"
24 #include "ipc/ipc_message.h" 23 #include "ipc/ipc_message.h"
25 #include "remoting/base/auto_thread.h" 24 #include "remoting/base/auto_thread.h"
26 #include "remoting/base/auto_thread_task_runner.h" 25 #include "remoting/base/auto_thread_task_runner.h"
27 #include "remoting/host/chromoting_messages.h" 26 #include "remoting/host/chromoting_messages.h"
28 #include "remoting/host/desktop_process.h" 27 #include "remoting/host/desktop_process.h"
29 #include "remoting/host/fake_mouse_cursor_monitor.h" 28 #include "remoting/host/fake_mouse_cursor_monitor.h"
30 #include "remoting/host/host_exit_codes.h" 29 #include "remoting/host/host_exit_codes.h"
(...skipping 15 matching lines...) Expand all
46 45
47 namespace { 46 namespace {
48 47
49 class MockDaemonListener : public IPC::Listener { 48 class MockDaemonListener : public IPC::Listener {
50 public: 49 public:
51 MockDaemonListener() {} 50 MockDaemonListener() {}
52 ~MockDaemonListener() override {} 51 ~MockDaemonListener() override {}
53 52
54 bool OnMessageReceived(const IPC::Message& message) override; 53 bool OnMessageReceived(const IPC::Message& message) override;
55 54
56 MOCK_METHOD1(OnDesktopAttached, void(IPC::PlatformFileForTransit)); 55 MOCK_METHOD1(OnDesktopAttached, void(const IPC::ChannelHandle&));
57 MOCK_METHOD1(OnChannelConnected, void(int32_t)); 56 MOCK_METHOD1(OnChannelConnected, void(int32_t));
58 MOCK_METHOD0(OnChannelError, void()); 57 MOCK_METHOD0(OnChannelError, void());
59 58
60 private: 59 private:
61 DISALLOW_COPY_AND_ASSIGN(MockDaemonListener); 60 DISALLOW_COPY_AND_ASSIGN(MockDaemonListener);
62 }; 61 };
63 62
64 class MockNetworkListener : public IPC::Listener { 63 class MockNetworkListener : public IPC::Listener {
65 public: 64 public:
66 MockNetworkListener() {} 65 MockNetworkListener() {}
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 return handled; 97 return handled;
99 } 98 }
100 99
101 } // namespace 100 } // namespace
102 101
103 class DesktopProcessTest : public testing::Test { 102 class DesktopProcessTest : public testing::Test {
104 public: 103 public:
105 DesktopProcessTest(); 104 DesktopProcessTest();
106 ~DesktopProcessTest() override; 105 ~DesktopProcessTest() override;
107 106
108 // testing::Test overrides
109 void SetUp() override;
110 void TearDown() override;
111
112 // MockDaemonListener mocks 107 // MockDaemonListener mocks
113 void ConnectNetworkChannel(IPC::PlatformFileForTransit desktop_process); 108 void ConnectNetworkChannel(const IPC::ChannelHandle& desktop_process);
114 void OnDesktopAttached(IPC::PlatformFileForTransit desktop_process); 109 void OnDesktopAttached(const IPC::ChannelHandle& desktop_process);
115 110
116 // Creates a DesktopEnvironment with a fake webrtc::DesktopCapturer, to mock 111 // Creates a DesktopEnvironment with a fake webrtc::DesktopCapturer, to mock
117 // DesktopEnvironmentFactory::Create(). 112 // DesktopEnvironmentFactory::Create().
118 DesktopEnvironment* CreateDesktopEnvironment(); 113 DesktopEnvironment* CreateDesktopEnvironment();
119 114
120 // Creates a dummy InputInjector, to mock 115 // Creates a dummy InputInjector, to mock
121 // DesktopEnvironment::CreateInputInjector(). 116 // DesktopEnvironment::CreateInputInjector().
122 InputInjector* CreateInputInjector(); 117 InputInjector* CreateInputInjector();
123 118
124 // Creates a fake webrtc::DesktopCapturer, to mock 119 // Creates a fake webrtc::DesktopCapturer, to mock
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 // Runs the daemon's end of the channel. 153 // Runs the daemon's end of the channel.
159 base::MessageLoopForUI message_loop_; 154 base::MessageLoopForUI message_loop_;
160 155
161 scoped_refptr<AutoThreadTaskRunner> io_task_runner_; 156 scoped_refptr<AutoThreadTaskRunner> io_task_runner_;
162 157
163 // The network's end of the network-to-desktop channel. 158 // The network's end of the network-to-desktop channel.
164 std::unique_ptr<IPC::ChannelProxy> network_channel_; 159 std::unique_ptr<IPC::ChannelProxy> network_channel_;
165 160
166 // Delegate that is passed to |network_channel_|. 161 // Delegate that is passed to |network_channel_|.
167 MockNetworkListener network_listener_; 162 MockNetworkListener network_listener_;
163
164 mojo::ScopedMessagePipeHandle desktop_process_channel_;
168 }; 165 };
169 166
170 DesktopProcessTest::DesktopProcessTest() {} 167 DesktopProcessTest::DesktopProcessTest() {}
171 168
172 DesktopProcessTest::~DesktopProcessTest() { 169 DesktopProcessTest::~DesktopProcessTest() {
173 } 170 }
174 171
175 void DesktopProcessTest::SetUp() {
176 IPC::AttachmentBrokerPrivileged::CreateBrokerForSingleProcessTests();
177 }
178
179 void DesktopProcessTest::TearDown() {
180 }
181
182 void DesktopProcessTest::ConnectNetworkChannel( 172 void DesktopProcessTest::ConnectNetworkChannel(
183 IPC::PlatformFileForTransit desktop_process) { 173 const IPC::ChannelHandle& channel_handle) {
184
185 #if defined(OS_POSIX)
186 IPC::ChannelHandle channel_handle(std::string(), desktop_process);
187 #elif defined(OS_WIN)
188 IPC::ChannelHandle channel_handle(desktop_process.GetHandle());
189 #endif // defined(OS_WIN)
190
191 network_channel_ = 174 network_channel_ =
192 IPC::ChannelProxy::Create(channel_handle, IPC::Channel::MODE_CLIENT, 175 IPC::ChannelProxy::Create(channel_handle, IPC::Channel::MODE_CLIENT,
193 &network_listener_, io_task_runner_.get()); 176 &network_listener_, io_task_runner_.get());
194 } 177 }
195 178
196 void DesktopProcessTest::OnDesktopAttached( 179 void DesktopProcessTest::OnDesktopAttached(
197 IPC::PlatformFileForTransit desktop_process) { 180 const IPC::ChannelHandle& desktop_process) {
198 #if defined(OS_POSIX) 181 desktop_process_channel_.reset(desktop_process.mojo_handle);
199 DCHECK(desktop_process.auto_close);
200
201 base::File closer(IPC::PlatformFileForTransitToFile(desktop_process));
202 #endif // defined(OS_POSIX)
203 } 182 }
204 183
205 DesktopEnvironment* DesktopProcessTest::CreateDesktopEnvironment() { 184 DesktopEnvironment* DesktopProcessTest::CreateDesktopEnvironment() {
206 MockDesktopEnvironment* desktop_environment = new MockDesktopEnvironment(); 185 MockDesktopEnvironment* desktop_environment = new MockDesktopEnvironment();
207 EXPECT_CALL(*desktop_environment, CreateAudioCapturerPtr()) 186 EXPECT_CALL(*desktop_environment, CreateAudioCapturerPtr())
208 .Times(0); 187 .Times(0);
209 EXPECT_CALL(*desktop_environment, CreateInputInjectorPtr()) 188 EXPECT_CALL(*desktop_environment, CreateInputInjectorPtr())
210 .Times(AtMost(1)) 189 .Times(AtMost(1))
211 .WillOnce(Invoke(this, &DesktopProcessTest::CreateInputInjector)); 190 .WillOnce(Invoke(this, &DesktopProcessTest::CreateInputInjector));
212 EXPECT_CALL(*desktop_environment, CreateScreenControlsPtr()) 191 EXPECT_CALL(*desktop_environment, CreateScreenControlsPtr())
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 } 335 }
357 336
358 // Run the desktop process and ask it to crash. 337 // Run the desktop process and ask it to crash.
359 TEST_F(DesktopProcessTest, DeathTest) { 338 TEST_F(DesktopProcessTest, DeathTest) {
360 testing::GTEST_FLAG(death_test_style) = "threadsafe"; 339 testing::GTEST_FLAG(death_test_style) = "threadsafe";
361 340
362 EXPECT_DEATH(RunDeathTest(), ""); 341 EXPECT_DEATH(RunDeathTest(), "");
363 } 342 }
364 343
365 } // namespace remoting 344 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/desktop_process.cc ('k') | remoting/host/desktop_session_agent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698