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

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

Issue 11781003: Connect to DesktopEnvironment's stubs only when audio/video schedulers are about to be created. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: CR feedback #2 Created 7 years, 11 months 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 | Annotate | Revision Log
« no previous file with comments | « remoting/host/client_session.cc ('k') | remoting/host/mouse_clamping_filter.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 "base/message_loop.h" 5 #include "base/message_loop.h"
6 #include "remoting/base/auto_thread_task_runner.h" 6 #include "remoting/base/auto_thread_task_runner.h"
7 #include "remoting/base/constants.h" 7 #include "remoting/base/constants.h"
8 #include "remoting/capturer/video_capturer_mock_objects.h" 8 #include "remoting/capturer/video_capturer_mock_objects.h"
9 #include "remoting/capturer/video_frame_capturer_fake.h"
9 #include "remoting/host/audio_capturer.h" 10 #include "remoting/host/audio_capturer.h"
10 #include "remoting/host/client_session.h" 11 #include "remoting/host/client_session.h"
11 #include "remoting/host/desktop_environment.h" 12 #include "remoting/host/desktop_environment.h"
12 #include "remoting/host/host_mock_objects.h" 13 #include "remoting/host/host_mock_objects.h"
13 #include "remoting/protocol/protocol_mock_objects.h" 14 #include "remoting/protocol/protocol_mock_objects.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 16
16 namespace remoting { 17 namespace remoting {
17 18
18 using protocol::MockConnectionToClient; 19 using protocol::MockConnectionToClient;
19 using protocol::MockClientStub; 20 using protocol::MockClientStub;
20 using protocol::MockHostStub; 21 using protocol::MockHostStub;
21 using protocol::MockInputStub; 22 using protocol::MockInputStub;
22 using protocol::MockSession; 23 using protocol::MockSession;
23 using protocol::MockVideoStub; 24 using protocol::MockVideoStub;
24 using protocol::SessionConfig; 25 using protocol::SessionConfig;
25 26
26 using testing::_; 27 using testing::_;
27 using testing::AnyNumber; 28 using testing::AnyNumber;
28 using testing::DeleteArg; 29 using testing::DeleteArg;
30 using testing::DoAll;
29 using testing::Expectation; 31 using testing::Expectation;
30 using testing::InSequence; 32 using testing::InSequence;
31 using testing::Return; 33 using testing::Return;
32 using testing::ReturnRef; 34 using testing::ReturnRef;
33 35
36 namespace {
37
38 ACTION_P2(InjectClipboardEvent, connection, event) {
39 connection->clipboard_stub()->InjectClipboardEvent(event);
40 }
41
42 ACTION_P2(InjectKeyEvent, connection, event) {
43 connection->input_stub()->InjectKeyEvent(event);
44 }
45
46 ACTION_P2(InjectMouseEvent, connection, event) {
47 connection->input_stub()->InjectMouseEvent(event);
48 }
49
50 ACTION_P2(LocalMouseMoved, client_session, event) {
51 client_session->LocalMouseMoved(SkIPoint::Make(event.x(), event.y()));
52 }
53
54 } // namespace
55
34 class ClientSessionTest : public testing::Test { 56 class ClientSessionTest : public testing::Test {
35 public: 57 public:
36 ClientSessionTest() : event_executor_(NULL) {} 58 ClientSessionTest()
59 : client_jid_("user@domain/rest-of-jid"),
60 event_executor_(NULL) {}
37 61
38 virtual void SetUp() OVERRIDE { 62 virtual void SetUp() OVERRIDE;
39 ui_task_runner_ = new AutoThreadTaskRunner( 63 virtual void TearDown() OVERRIDE;
40 message_loop_.message_loop_proxy(),
41 base::Bind(&ClientSessionTest::QuitMainMessageLoop,
42 base::Unretained(this)));
43 64
44 client_jid_ = "user@domain/rest-of-jid"; 65 // Disconnects the client session.
66 void DisconnectClientSession();
45 67
46 desktop_environment_factory_.reset(new MockDesktopEnvironmentFactory()); 68 // Asynchronously stops the client session. OnClientStopped() will be called
47 EXPECT_CALL(*desktop_environment_factory_, CreatePtr()) 69 // once the client session is fully stopped.
48 .Times(AnyNumber()) 70 void StopClientSession();
49 .WillRepeatedly(Invoke(this,
50 &ClientSessionTest::CreateDesktopEnvironment));
51
52 // Set up a large default screen size that won't affect most tests.
53 screen_size_.set(1000, 1000);
54
55 session_config_ = SessionConfig::ForTest();
56
57 // Mock protocol::Session APIs called directly by ClientSession.
58 protocol::MockSession* session = new MockSession();
59 EXPECT_CALL(*session, config()).WillRepeatedly(ReturnRef(session_config_));
60 EXPECT_CALL(*session, jid()).WillRepeatedly(ReturnRef(client_jid_));
61 EXPECT_CALL(*session, SetEventHandler(_));
62
63 // Mock protocol::ConnectionToClient APIs called directly by ClientSession.
64 // HostStub is not touched by ClientSession, so we can safely pass NULL.
65 scoped_ptr<MockConnectionToClient> connection(
66 new MockConnectionToClient(session, NULL));
67 EXPECT_CALL(*connection, session()).WillRepeatedly(Return(session));
68 EXPECT_CALL(*connection, client_stub())
69 .WillRepeatedly(Return(&client_stub_));
70 EXPECT_CALL(*connection, video_stub()).WillRepeatedly(Return(&video_stub_));
71 EXPECT_CALL(*connection, Disconnect());
72 connection_ = connection.get();
73
74 client_session_ = new ClientSession(
75 &session_event_handler_,
76 ui_task_runner_, // Audio thread.
77 ui_task_runner_, // Capture thread.
78 ui_task_runner_, // Encode thread.
79 ui_task_runner_, // Network thread.
80 connection.PassAs<protocol::ConnectionToClient>(),
81 desktop_environment_factory_.get(),
82 base::TimeDelta());
83 }
84
85 virtual void TearDown() OVERRIDE {
86 // MockClientSessionEventHandler won't trigger Stop, so fake it.
87 client_session_->Stop(base::Bind(
88 &ClientSessionTest::OnClientStopped, base::Unretained(this)));
89
90 // Run message loop before destroying because the session is destroyed
91 // asynchronously.
92 ui_task_runner_ = NULL;
93 message_loop_.Run();
94
95 // Verify that the client session has been stopped.
96 EXPECT_TRUE(client_session_.get() == NULL);
97 }
98 71
99 protected: 72 protected:
100 DesktopEnvironment* CreateDesktopEnvironment() { 73 // Creates a DesktopEnvironment with a fake VideoFrameCapturer, to mock
101 MockVideoFrameCapturer* capturer = new MockVideoFrameCapturer(); 74 // DesktopEnvironmentFactory::Create().
102 EXPECT_CALL(*capturer, Start(_)); 75 DesktopEnvironment* CreateDesktopEnvironment();
103 EXPECT_CALL(*capturer, Stop());
104 EXPECT_CALL(*capturer, InvalidateRegion(_)).Times(AnyNumber());
105 EXPECT_CALL(*capturer, CaptureFrame()).Times(AnyNumber());
106 EXPECT_CALL(*capturer, size_most_recent())
107 .WillRepeatedly(ReturnRef(screen_size_));
108 76
109 EXPECT_TRUE(!event_executor_); 77 // Notifies the client session that the client connection has been
110 event_executor_ = new MockEventExecutor(); 78 // authenticated and channels have been connected. This effectively enables
111 return new DesktopEnvironment(scoped_ptr<AudioCapturer>(NULL), 79 // the input pipe line and starts video capturing.
112 scoped_ptr<EventExecutor>(event_executor_), 80 void ConnectClientSession();
113 scoped_ptr<VideoFrameCapturer>(capturer));
114 }
115 81
116 void DisconnectClientSession() { 82 // Invoked when the last reference to the AutoThreadTaskRunner has been
117 client_session_->Disconnect(); 83 // released and quits the message loop to finish the test.
118 // MockSession won't trigger OnConnectionClosed, so fake it. 84 void QuitMainMessageLoop();
119 client_session_->OnConnectionClosed(client_session_->connection(),
120 protocol::OK);
121 }
122 85
123 void QuitMainMessageLoop() { 86 // Releases the ClientSession when it has been fully stopped, allowing
124 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure()); 87 // the MessageLoop to quit.
125 } 88 void OnClientStopped();
126
127 void OnClientStopped() {
128 client_session_ = NULL;
129 }
130 89
131 // Message loop passed to |client_session_| to perform all functions on. 90 // Message loop passed to |client_session_| to perform all functions on.
132 MessageLoop message_loop_; 91 MessageLoop message_loop_;
133 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_;
134 92
135 // ClientSession instance under test. 93 // ClientSession instance under test.
136 scoped_refptr<ClientSession> client_session_; 94 scoped_refptr<ClientSession> client_session_;
137 95
138 // ClientSession::EventHandler mock for use in tests. 96 // ClientSession::EventHandler mock for use in tests.
139 MockClientSessionEventHandler session_event_handler_; 97 MockClientSessionEventHandler session_event_handler_;
140 98
141 // Screen size that the fake VideoFrameCapturer should report.
142 SkISize screen_size_;
143
144 // Storage for values to be returned by the protocol::Session mock. 99 // Storage for values to be returned by the protocol::Session mock.
145 SessionConfig session_config_; 100 SessionConfig session_config_;
146 std::string client_jid_; 101 const std::string client_jid_;
147 102
148 // Stubs returned to |client_session_| components by |connection_|. 103 // Stubs returned to |client_session_| components by |connection_|.
149 MockClientStub client_stub_; 104 MockClientStub client_stub_;
150 MockVideoStub video_stub_; 105 MockVideoStub video_stub_;
151 106
152 // DesktopEnvironment owns |event_executor_|, but input injection tests need 107 // DesktopEnvironment owns |event_executor_|, but input injection tests need
153 // to express expectations on it. 108 // to express expectations on it.
154 MockEventExecutor* event_executor_; 109 MockEventExecutor* event_executor_;
155 110
156 // ClientSession owns |connection_| but tests need it to inject fake events. 111 // ClientSession owns |connection_| but tests need it to inject fake events.
157 MockConnectionToClient* connection_; 112 MockConnectionToClient* connection_;
158 113
159 scoped_ptr<MockDesktopEnvironmentFactory> desktop_environment_factory_; 114 scoped_ptr<MockDesktopEnvironmentFactory> desktop_environment_factory_;
160 }; 115 };
161 116
117 void ClientSessionTest::SetUp() {
118 // Arrange to run |message_loop_| until no components depend on it.
119 scoped_refptr<AutoThreadTaskRunner> ui_task_runner = new AutoThreadTaskRunner(
120 message_loop_.message_loop_proxy(),
121 base::Bind(&ClientSessionTest::QuitMainMessageLoop,
122 base::Unretained(this)));
123
124 desktop_environment_factory_.reset(new MockDesktopEnvironmentFactory());
125 EXPECT_CALL(*desktop_environment_factory_, CreatePtr())
126 .Times(AnyNumber())
127 .WillRepeatedly(Invoke(this,
128 &ClientSessionTest::CreateDesktopEnvironment));
129
130 session_config_ = SessionConfig::ForTest();
131
132 // Mock protocol::Session APIs called directly by ClientSession.
133 protocol::MockSession* session = new MockSession();
134 EXPECT_CALL(*session, config()).WillRepeatedly(ReturnRef(session_config_));
135 EXPECT_CALL(*session, jid()).WillRepeatedly(ReturnRef(client_jid_));
136 EXPECT_CALL(*session, SetEventHandler(_));
137
138 // Mock protocol::ConnectionToClient APIs called directly by ClientSession.
139 // HostStub is not touched by ClientSession, so we can safely pass NULL.
140 scoped_ptr<MockConnectionToClient> connection(
141 new MockConnectionToClient(session, NULL));
142 EXPECT_CALL(*connection, session()).WillRepeatedly(Return(session));
143 EXPECT_CALL(*connection, client_stub())
144 .WillRepeatedly(Return(&client_stub_));
145 EXPECT_CALL(*connection, video_stub()).WillRepeatedly(Return(&video_stub_));
146 EXPECT_CALL(*connection, Disconnect());
147 connection_ = connection.get();
148
149 client_session_ = new ClientSession(
150 &session_event_handler_,
151 ui_task_runner, // Audio thread.
152 ui_task_runner, // Capture thread.
153 ui_task_runner, // Encode thread.
154 ui_task_runner, // Network thread.
155 connection.PassAs<protocol::ConnectionToClient>(),
156 desktop_environment_factory_.get(),
157 base::TimeDelta());
158 }
159
160 void ClientSessionTest::TearDown() {
161 // Verify that the client session has been stopped.
162 EXPECT_TRUE(client_session_.get() == NULL);
163 }
164
165 void ClientSessionTest::DisconnectClientSession() {
166 client_session_->Disconnect();
167 // MockSession won't trigger OnConnectionClosed, so fake it.
168 client_session_->OnConnectionClosed(client_session_->connection(),
169 protocol::OK);
170 }
171
172 void ClientSessionTest::StopClientSession() {
173 // MockClientSessionEventHandler won't trigger Stop, so fake it.
174 client_session_->Stop(base::Bind(
175 &ClientSessionTest::OnClientStopped, base::Unretained(this)));
176 }
177
178 DesktopEnvironment* ClientSessionTest::CreateDesktopEnvironment() {
179 scoped_ptr<VideoFrameCapturer> video_capturer(new VideoFrameCapturerFake());
180
181 EXPECT_TRUE(!event_executor_);
182 event_executor_ = new MockEventExecutor();
183 return new DesktopEnvironment(scoped_ptr<AudioCapturer>(NULL),
184 scoped_ptr<EventExecutor>(event_executor_),
185 video_capturer.Pass());
186 }
187
188 void ClientSessionTest::ConnectClientSession() {
189 client_session_->OnConnectionAuthenticated(client_session_->connection());
190 client_session_->OnConnectionChannelsConnected(client_session_->connection());
191 }
192
193 void ClientSessionTest::QuitMainMessageLoop() {
194 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure());
195 }
196
197 void ClientSessionTest::OnClientStopped() {
198 client_session_ = NULL;
199 }
200
162 MATCHER_P2(EqualsClipboardEvent, m, d, "") { 201 MATCHER_P2(EqualsClipboardEvent, m, d, "") {
163 return (strcmp(arg.mime_type().c_str(), m) == 0 && 202 return (strcmp(arg.mime_type().c_str(), m) == 0 &&
164 memcmp(arg.data().data(), d, arg.data().size()) == 0); 203 memcmp(arg.data().data(), d, arg.data().size()) == 0);
165 } 204 }
166 205
167 TEST_F(ClientSessionTest, ClipboardStubFilter) { 206 TEST_F(ClientSessionTest, ClipboardStubFilter) {
168 protocol::ClipboardEvent clipboard_event1; 207 protocol::ClipboardEvent clipboard_event1;
169 clipboard_event1.set_mime_type(kMimeTypeTextUtf8); 208 clipboard_event1.set_mime_type(kMimeTypeTextUtf8);
170 clipboard_event1.set_data("a"); 209 clipboard_event1.set_data("a");
171 210
172 protocol::ClipboardEvent clipboard_event2; 211 protocol::ClipboardEvent clipboard_event2;
173 clipboard_event2.set_mime_type(kMimeTypeTextUtf8); 212 clipboard_event2.set_mime_type(kMimeTypeTextUtf8);
174 clipboard_event2.set_data("b"); 213 clipboard_event2.set_data("b");
175 214
176 protocol::ClipboardEvent clipboard_event3; 215 protocol::ClipboardEvent clipboard_event3;
177 clipboard_event3.set_mime_type(kMimeTypeTextUtf8); 216 clipboard_event3.set_mime_type(kMimeTypeTextUtf8);
178 clipboard_event3.set_data("c"); 217 clipboard_event3.set_data("c");
179 218
180 InSequence s; 219 InSequence s;
181 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); 220 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_));
182 EXPECT_CALL(*event_executor_, StartPtr(_)); 221 EXPECT_CALL(*event_executor_, StartPtr(_));
183 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); 222 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_));
223
224 // Wait for the first video packet to be captured to make sure that
225 // the injected input will go though. Otherwise mouse events will be blocked
226 // by the mouse clamping filter.
227 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _))
228 .WillOnce(DoAll(
229 // This event should get through to the clipboard stub.
230 InjectClipboardEvent(connection_, clipboard_event2),
231 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession),
232 // This event should not get through to the clipboard stub,
233 // because the client has disconnected.
234 InjectClipboardEvent(connection_, clipboard_event3),
235 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession)));
184 EXPECT_CALL(*event_executor_, InjectClipboardEvent(EqualsClipboardEvent( 236 EXPECT_CALL(*event_executor_, InjectClipboardEvent(EqualsClipboardEvent(
185 kMimeTypeTextUtf8, "b"))); 237 kMimeTypeTextUtf8, "b")));
186 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); 238 EXPECT_CALL(session_event_handler_, OnSessionClosed(_));
187 239
188 // This event should not get through to the clipboard stub, 240 // This event should not get through to the clipboard stub,
189 // because the client isn't authenticated yet. 241 // because the client isn't authenticated yet.
190 connection_->clipboard_stub()->InjectClipboardEvent(clipboard_event1); 242 connection_->clipboard_stub()->InjectClipboardEvent(clipboard_event1);
191 client_session_->OnConnectionAuthenticated(client_session_->connection()); 243
192 client_session_->OnConnectionChannelsConnected(client_session_->connection()); 244 ConnectClientSession();
193 // This event should get through to the clipboard stub. 245 message_loop_.Run();
194 connection_->clipboard_stub()->InjectClipboardEvent(clipboard_event2);
195 DisconnectClientSession();
196 // This event should not get through to the clipboard stub,
197 // because the client has disconnected.
198 connection_->clipboard_stub()->InjectClipboardEvent(clipboard_event3);
199 } 246 }
200 247
201 MATCHER_P2(EqualsUsbEvent, usb_keycode, pressed, "") { 248 MATCHER_P2(EqualsUsbEvent, usb_keycode, pressed, "") {
202 return arg.usb_keycode() == (unsigned int)usb_keycode && 249 return arg.usb_keycode() == (unsigned int)usb_keycode &&
203 arg.pressed() == pressed; 250 arg.pressed() == pressed;
204 } 251 }
205 252
206 MATCHER_P2(EqualsMouseEvent, x, y, "") { 253 MATCHER_P2(EqualsMouseEvent, x, y, "") {
207 return arg.x() == x && arg.y() == y; 254 return arg.x() == x && arg.y() == y;
208 } 255 }
(...skipping 28 matching lines...) Expand all
237 mouse_event2.set_y(201); 284 mouse_event2.set_y(201);
238 285
239 protocol::MouseEvent mouse_event3; 286 protocol::MouseEvent mouse_event3;
240 mouse_event3.set_x(300); 287 mouse_event3.set_x(300);
241 mouse_event3.set_y(301); 288 mouse_event3.set_y(301);
242 289
243 InSequence s; 290 InSequence s;
244 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); 291 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_));
245 EXPECT_CALL(*event_executor_, StartPtr(_)); 292 EXPECT_CALL(*event_executor_, StartPtr(_));
246 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); 293 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_));
294
295 // Wait for the first video packet to be captured to make sure that
296 // the injected input will go though. Otherwise mouse events will be blocked
297 // by the mouse clamping filter.
298 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _))
299 .WillOnce(DoAll(
300 // These events should get through to the input stub.
301 InjectKeyEvent(connection_, key_event2_down),
302 InjectKeyEvent(connection_, key_event2_up),
303 InjectMouseEvent(connection_, mouse_event2),
304 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession),
305 // These events should not get through to the input stub,
306 // because the client has disconnected.
307 InjectKeyEvent(connection_, key_event3),
308 InjectMouseEvent(connection_, mouse_event3),
309 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession)));
247 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, true))); 310 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, true)));
248 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, false))); 311 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, false)));
249 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseEvent(200, 201))); 312 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseEvent(200, 201)));
250 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); 313 EXPECT_CALL(session_event_handler_, OnSessionClosed(_));
251 314
252 // These events should not get through to the input stub, 315 // These events should not get through to the input stub,
253 // because the client isn't authenticated yet. 316 // because the client isn't authenticated yet.
254 connection_->input_stub()->InjectKeyEvent(key_event1); 317 connection_->input_stub()->InjectKeyEvent(key_event1);
255 connection_->input_stub()->InjectMouseEvent(mouse_event1); 318 connection_->input_stub()->InjectMouseEvent(mouse_event1);
256 client_session_->OnConnectionAuthenticated(client_session_->connection()); 319
257 client_session_->OnConnectionChannelsConnected(client_session_->connection()); 320 ConnectClientSession();
258 // These events should get through to the input stub. 321 message_loop_.Run();
259 connection_->input_stub()->InjectKeyEvent(key_event2_down);
260 connection_->input_stub()->InjectKeyEvent(key_event2_up);
261 connection_->input_stub()->InjectMouseEvent(mouse_event2);
262 DisconnectClientSession();
263 // These events should not get through to the input stub,
264 // because the client has disconnected.
265 connection_->input_stub()->InjectKeyEvent(key_event3);
266 connection_->input_stub()->InjectMouseEvent(mouse_event3);
267 } 322 }
268 323
269 TEST_F(ClientSessionTest, LocalInputTest) { 324 TEST_F(ClientSessionTest, LocalInputTest) {
270 protocol::MouseEvent mouse_event1; 325 protocol::MouseEvent mouse_event1;
271 mouse_event1.set_x(100); 326 mouse_event1.set_x(100);
272 mouse_event1.set_y(101); 327 mouse_event1.set_y(101);
273 protocol::MouseEvent mouse_event2; 328 protocol::MouseEvent mouse_event2;
274 mouse_event2.set_x(200); 329 mouse_event2.set_x(200);
275 mouse_event2.set_y(201); 330 mouse_event2.set_y(201);
276 protocol::MouseEvent mouse_event3; 331 protocol::MouseEvent mouse_event3;
277 mouse_event3.set_x(300); 332 mouse_event3.set_x(300);
278 mouse_event3.set_y(301); 333 mouse_event3.set_y(301);
279 334
280 InSequence s; 335 InSequence s;
281 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); 336 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_));
282 EXPECT_CALL(*event_executor_, StartPtr(_)); 337 EXPECT_CALL(*event_executor_, StartPtr(_));
283 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); 338 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_));
339
340 // Wait for the first video packet to be captured to make sure that
341 // the injected input will go though. Otherwise mouse events will be blocked
342 // by the mouse clamping filter.
343 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _))
344 .WillOnce(DoAll(
345 // This event should get through to the input stub.
346 InjectMouseEvent(connection_, mouse_event1),
347 // This one should too because the local event echoes the remote one.
348 LocalMouseMoved(client_session_.get(), mouse_event1),
349 InjectMouseEvent(connection_, mouse_event2),
350 // This one should not.
351 LocalMouseMoved(client_session_.get(), mouse_event1),
352 InjectMouseEvent(connection_, mouse_event3),
353 // TODO(jamiewalch): Verify that remote inputs are re-enabled
354 // eventually (via dependency injection, not sleep!)
355 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession),
356 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession)));
284 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseEvent(100, 101))); 357 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseEvent(100, 101)));
285 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseEvent(200, 201))); 358 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseEvent(200, 201)));
286 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); 359 EXPECT_CALL(session_event_handler_, OnSessionClosed(_));
287 360
288 client_session_->OnConnectionAuthenticated(client_session_->connection()); 361 ConnectClientSession();
289 client_session_->OnConnectionChannelsConnected(client_session_->connection()); 362 message_loop_.Run();
290 // This event should get through to the input stub.
291 connection_->input_stub()->InjectMouseEvent(mouse_event1);
292 // This one should too because the local event echoes the remote one.
293 client_session_->LocalMouseMoved(SkIPoint::Make(mouse_event1.x(),
294 mouse_event1.y()));
295 connection_->input_stub()->InjectMouseEvent(mouse_event2);
296 // This one should not.
297 client_session_->LocalMouseMoved(SkIPoint::Make(mouse_event1.x(),
298 mouse_event1.y()));
299 connection_->input_stub()->InjectMouseEvent(mouse_event3);
300 // TODO(jamiewalch): Verify that remote inputs are re-enabled eventually
301 // (via dependency injection, not sleep!)
302 DisconnectClientSession();
303 } 363 }
304 364
305 TEST_F(ClientSessionTest, RestoreEventState) { 365 TEST_F(ClientSessionTest, RestoreEventState) {
306 protocol::KeyEvent key1; 366 protocol::KeyEvent key1;
307 key1.set_pressed(true); 367 key1.set_pressed(true);
308 key1.set_usb_keycode(1); 368 key1.set_usb_keycode(1);
309 369
310 protocol::KeyEvent key2; 370 protocol::KeyEvent key2;
311 key2.set_pressed(true); 371 key2.set_pressed(true);
312 key2.set_usb_keycode(2); 372 key2.set_usb_keycode(2);
313 373
314 protocol::MouseEvent mousedown; 374 protocol::MouseEvent mousedown;
315 mousedown.set_button(protocol::MouseEvent::BUTTON_LEFT); 375 mousedown.set_button(protocol::MouseEvent::BUTTON_LEFT);
316 mousedown.set_button_down(true); 376 mousedown.set_button_down(true);
317 377
318 InSequence s; 378 InSequence s;
319 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); 379 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_));
320 EXPECT_CALL(*event_executor_, StartPtr(_)); 380 EXPECT_CALL(*event_executor_, StartPtr(_));
321 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); 381 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_));
382
383 // Wait for the first video packet to be captured to make sure that
384 // the injected input will go though. Otherwise mouse events will be blocked
385 // by the mouse clamping filter.
386 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _))
387 .WillOnce(DoAll(
388 InjectKeyEvent(connection_, key1),
389 InjectKeyEvent(connection_, key2),
390 InjectMouseEvent(connection_, mousedown),
391 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession),
392 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession)));
322 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(1, true))); 393 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(1, true)));
323 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, true))); 394 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, true)));
324 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseButtonEvent( 395 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseButtonEvent(
325 protocol::MouseEvent::BUTTON_LEFT, true))); 396 protocol::MouseEvent::BUTTON_LEFT, true)));
326 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(1, false))); 397 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(1, false)));
327 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, false))); 398 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, false)));
328 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseButtonEvent( 399 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseButtonEvent(
329 protocol::MouseEvent::BUTTON_LEFT, false))); 400 protocol::MouseEvent::BUTTON_LEFT, false)));
330 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); 401 EXPECT_CALL(session_event_handler_, OnSessionClosed(_));
331 402
332 client_session_->OnConnectionAuthenticated(client_session_->connection()); 403 ConnectClientSession();
333 client_session_->OnConnectionChannelsConnected(client_session_->connection()); 404 message_loop_.Run();
334
335 connection_->input_stub()->InjectKeyEvent(key1);
336 connection_->input_stub()->InjectKeyEvent(key2);
337 connection_->input_stub()->InjectMouseEvent(mousedown);
338
339 DisconnectClientSession();
340 } 405 }
341 406
342 TEST_F(ClientSessionTest, ClampMouseEvents) { 407 TEST_F(ClientSessionTest, ClampMouseEvents) {
343 screen_size_.set(200, 100);
344
345 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); 408 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_));
346 EXPECT_CALL(*event_executor_, StartPtr(_)); 409 EXPECT_CALL(*event_executor_, StartPtr(_));
347 Expectation connected = 410 Expectation connected =
348 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); 411 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_));
349 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); 412 EXPECT_CALL(session_event_handler_, OnSessionClosed(_));
350 413
351 client_session_->OnConnectionAuthenticated(client_session_->connection()); 414 int input_x[3] = { -999, 100, 999 };
352 client_session_->OnConnectionChannelsConnected(client_session_->connection()); 415 int expected_x[3] = { 0, 100, VideoFrameCapturerFake::kWidth - 1 };
416 int input_y[3] = { -999, 50, 999 };
417 int expected_y[3] = { 0, 50, VideoFrameCapturerFake::kHeight - 1 };
353 418
354 int input_x[3] = { -999, 100, 999 }; 419 // Inject the 1st event once a video packet has been received.
355 int expected_x[3] = { 0, 100, 199 }; 420 protocol::MouseEvent injected_event;
356 int input_y[3] = { -999, 50, 999 }; 421 injected_event.set_x(input_x[0]);
357 int expected_y[3] = { 0, 50, 99 }; 422 injected_event.set_y(input_y[0]);
423 connected =
424 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _))
425 .After(connected)
426 .WillOnce(InjectMouseEvent(connection_, injected_event));
358 427
359 protocol::MouseEvent event; 428 protocol::MouseEvent expected_event;
360 for (int j = 0; j < 3; j++) { 429 for (int j = 0; j < 3; j++) {
361 for (int i = 0; i < 3; i++) { 430 for (int i = 0; i < 3; i++) {
362 event.set_x(input_x[i]); 431 // Skip the first iteration since the 1st event has been injected already.
363 event.set_y(input_y[j]); 432 if (i > 0 || j > 0) {
364 connected = 433 injected_event.set_x(input_x[i]);
365 EXPECT_CALL(*event_executor_, 434 injected_event.set_y(input_y[j]);
366 InjectMouseEvent(EqualsMouseEvent(expected_x[i], 435 connected =
367 expected_y[j]))) 436 EXPECT_CALL(*event_executor_,
368 .After(connected); 437 InjectMouseEvent(EqualsMouseEvent(expected_event.x(),
369 connection_->input_stub()->InjectMouseEvent(event); 438 expected_event.y())))
439 .After(connected)
440 .WillOnce(InjectMouseEvent(connection_, injected_event));
441 }
442
443 expected_event.set_x(expected_x[i]);
444 expected_event.set_y(expected_y[j]);
370 } 445 }
371 } 446 }
372 447
373 DisconnectClientSession(); 448 // Shutdown the connection once the last event has been received.
449 EXPECT_CALL(*event_executor_,
450 InjectMouseEvent(EqualsMouseEvent(expected_event.x(),
451 expected_event.y())))
452 .After(connected)
453 .WillOnce(DoAll(
454 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession),
455 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession)));
456
457 ConnectClientSession();
458 message_loop_.Run();
374 } 459 }
375 460
376 } // namespace remoting 461 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/client_session.cc ('k') | remoting/host/mouse_clamping_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698