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

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

Issue 1472873005: Add VideoStream interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move_video_pump
Patch Set: Created 5 years 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/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 <algorithm> 5 #include <algorithm>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "base/strings/string_split.h" 11 #include "base/strings/string_split.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "remoting/base/auto_thread_task_runner.h" 13 #include "remoting/base/auto_thread_task_runner.h"
14 #include "remoting/base/constants.h" 14 #include "remoting/base/constants.h"
15 #include "remoting/codec/video_encoder_verbatim.h"
15 #include "remoting/host/client_session.h" 16 #include "remoting/host/client_session.h"
16 #include "remoting/host/desktop_environment.h" 17 #include "remoting/host/desktop_environment.h"
17 #include "remoting/host/fake_desktop_environment.h" 18 #include "remoting/host/fake_desktop_environment.h"
18 #include "remoting/host/fake_host_extension.h" 19 #include "remoting/host/fake_host_extension.h"
19 #include "remoting/host/fake_mouse_cursor_monitor.h" 20 #include "remoting/host/fake_mouse_cursor_monitor.h"
20 #include "remoting/host/host_extension.h" 21 #include "remoting/host/host_extension.h"
21 #include "remoting/host/host_extension_session.h" 22 #include "remoting/host/host_extension_session.h"
22 #include "remoting/host/host_mock_objects.h" 23 #include "remoting/host/host_mock_objects.h"
23 #include "remoting/protocol/fake_connection_to_client.h" 24 #include "remoting/protocol/fake_connection_to_client.h"
24 #include "remoting/protocol/fake_desktop_capturer.h" 25 #include "remoting/protocol/fake_desktop_capturer.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 98
98 // Creates the client session. 99 // Creates the client session.
99 void CreateClientSession(); 100 void CreateClientSession();
100 101
101 protected: 102 protected:
102 // Notifies the client session that the client connection has been 103 // Notifies the client session that the client connection has been
103 // authenticated and channels have been connected. This effectively enables 104 // authenticated and channels have been connected. This effectively enables
104 // the input pipe line and starts video capturing. 105 // the input pipe line and starts video capturing.
105 void ConnectClientSession(); 106 void ConnectClientSession();
106 107
107 // Waits for the first frame to be processed. 108 // Fakes video size notification from the VideoStream.
108 void WaitFirstFrame(); 109 void NotifyVideoSize();
109 110
110 // Creates expectations to send an extension message and to disconnect 111 // Creates expectations to send an extension message and to disconnect
111 // afterwards. 112 // afterwards.
112 void SetSendMessageAndDisconnectExpectation(const std::string& message_type); 113 void SetSendMessageAndDisconnectExpectation(const std::string& message_type);
113 114
114 // Message loop that will process all ClientSession tasks. 115 // Message loop that will process all ClientSession tasks.
115 base::MessageLoop message_loop_; 116 base::MessageLoop message_loop_;
116 117
117 // AutoThreadTaskRunner on which |client_session_| will be run. 118 // AutoThreadTaskRunner on which |client_session_| will be run.
118 scoped_refptr<AutoThreadTaskRunner> task_runner_; 119 scoped_refptr<AutoThreadTaskRunner> task_runner_;
(...skipping 11 matching lines...) Expand all
130 131
131 // ClientSession::EventHandler mock for use in tests. 132 // ClientSession::EventHandler mock for use in tests.
132 MockClientSessionEventHandler session_event_handler_; 133 MockClientSessionEventHandler session_event_handler_;
133 134
134 // Storage for values to be returned by the protocol::Session mock. 135 // Storage for values to be returned by the protocol::Session mock.
135 scoped_ptr<SessionConfig> session_config_; 136 scoped_ptr<SessionConfig> session_config_;
136 const std::string client_jid_; 137 const std::string client_jid_;
137 138
138 // Stubs returned to |client_session_| components by |connection_|. 139 // Stubs returned to |client_session_| components by |connection_|.
139 MockClientStub client_stub_; 140 MockClientStub client_stub_;
140 MockVideoStub video_stub_;
141 141
142 // ClientSession owns |connection_| but tests need it to inject fake events. 142 // ClientSession owns |connection_| but tests need it to inject fake events.
143 protocol::FakeConnectionToClient* connection_; 143 protocol::FakeConnectionToClient* connection_;
144 144
145 scoped_ptr<FakeDesktopEnvironmentFactory> desktop_environment_factory_; 145 scoped_ptr<FakeDesktopEnvironmentFactory> desktop_environment_factory_;
146 }; 146 };
147 147
148 void ClientSessionTest::SetUp() { 148 void ClientSessionTest::SetUp() {
149 // Arrange to run |message_loop_| until no components depend on it. 149 // Arrange to run |message_loop_| until no components depend on it.
150 task_runner_ = new AutoThreadTaskRunner( 150 task_runner_ = new AutoThreadTaskRunner(
(...skipping 20 matching lines...) Expand all
171 // Mock protocol::Session APIs called directly by ClientSession. 171 // Mock protocol::Session APIs called directly by ClientSession.
172 scoped_ptr<protocol::MockSession> session(new MockSession()); 172 scoped_ptr<protocol::MockSession> session(new MockSession());
173 EXPECT_CALL(*session, config()).WillRepeatedly(ReturnRef(*session_config_)); 173 EXPECT_CALL(*session, config()).WillRepeatedly(ReturnRef(*session_config_));
174 EXPECT_CALL(*session, jid()).WillRepeatedly(ReturnRef(client_jid_)); 174 EXPECT_CALL(*session, jid()).WillRepeatedly(ReturnRef(client_jid_));
175 175
176 // Mock protocol::ConnectionToClient APIs called directly by ClientSession. 176 // Mock protocol::ConnectionToClient APIs called directly by ClientSession.
177 // HostStub is not touched by ClientSession, so we can safely pass nullptr. 177 // HostStub is not touched by ClientSession, so we can safely pass nullptr.
178 scoped_ptr<protocol::FakeConnectionToClient> connection( 178 scoped_ptr<protocol::FakeConnectionToClient> connection(
179 new protocol::FakeConnectionToClient(session.Pass())); 179 new protocol::FakeConnectionToClient(session.Pass()));
180 connection->set_client_stub(&client_stub_); 180 connection->set_client_stub(&client_stub_);
181 connection->set_video_stub(&video_stub_);
182 connection_ = connection.get(); 181 connection_ = connection.get();
183 182
184 client_session_.reset(new ClientSession( 183 client_session_.reset(new ClientSession(
185 &session_event_handler_, 184 &session_event_handler_,
186 task_runner_, // Audio thread. 185 task_runner_, // Audio thread.
187 task_runner_, // Input thread. 186 task_runner_, // Input thread.
188 task_runner_, // Capture thread. 187 task_runner_, // Capture thread.
189 task_runner_, // Encode thread. 188 task_runner_, // Encode thread.
190 task_runner_, // Network thread. 189 task_runner_, // Network thread.
191 task_runner_, // UI thread. 190 task_runner_, // UI thread.
(...skipping 13 matching lines...) Expand all
205 EXPECT_FALSE(connection_->input_stub()); 204 EXPECT_FALSE(connection_->input_stub());
206 205
207 client_session_->OnConnectionAuthenticated(client_session_->connection()); 206 client_session_->OnConnectionAuthenticated(client_session_->connection());
208 207
209 EXPECT_TRUE(connection_->clipboard_stub()); 208 EXPECT_TRUE(connection_->clipboard_stub());
210 EXPECT_TRUE(connection_->input_stub()); 209 EXPECT_TRUE(connection_->input_stub());
211 210
212 client_session_->OnConnectionChannelsConnected(client_session_->connection()); 211 client_session_->OnConnectionChannelsConnected(client_session_->connection());
213 } 212 }
214 213
215 void ClientSessionTest::WaitFirstFrame() { 214 void ClientSessionTest::NotifyVideoSize() {
216 // Wait for the first video packet to be captured to make sure that 215 connection_->last_video_stream()->size_callback().Run(
217 // the injected input will go though. Otherwise mouse events will be blocked 216 webrtc::DesktopSize(protocol::FakeDesktopCapturer::kWidth,
218 // by the mouse clamping filter. 217 protocol::FakeDesktopCapturer::kHeight));
219 base::RunLoop run_loop;
220 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _))
221 .Times(AtLeast(1))
222 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
223 run_loop.Run();
224 } 218 }
225 219
226 TEST_F(ClientSessionTest, DisableInputs) { 220 TEST_F(ClientSessionTest, DisableInputs) {
227 CreateClientSession(); 221 CreateClientSession();
228 ConnectClientSession(); 222 ConnectClientSession();
229 WaitFirstFrame(); 223 NotifyVideoSize();
230 224
231 FakeInputInjector* input_injector = 225 FakeInputInjector* input_injector =
232 desktop_environment_factory_->last_desktop_environment() 226 desktop_environment_factory_->last_desktop_environment()
233 ->last_input_injector() 227 ->last_input_injector()
234 .get(); 228 .get();
235 std::vector<protocol::KeyEvent> key_events; 229 std::vector<protocol::KeyEvent> key_events;
236 input_injector->set_key_events(&key_events); 230 input_injector->set_key_events(&key_events);
237 std::vector<protocol::MouseEvent> mouse_events; 231 std::vector<protocol::MouseEvent> mouse_events;
238 input_injector->set_mouse_events(&mouse_events); 232 input_injector->set_mouse_events(&mouse_events);
239 std::vector<protocol::ClipboardEvent> clipboard_events; 233 std::vector<protocol::ClipboardEvent> clipboard_events;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 EXPECT_EQ(2U, clipboard_events.size()); 269 EXPECT_EQ(2U, clipboard_events.size());
276 EXPECT_THAT(clipboard_events[0], 270 EXPECT_THAT(clipboard_events[0],
277 EqualsClipboardEvent(kMimeTypeTextUtf8, "a")); 271 EqualsClipboardEvent(kMimeTypeTextUtf8, "a"));
278 EXPECT_THAT(clipboard_events[1], 272 EXPECT_THAT(clipboard_events[1],
279 EqualsClipboardEvent(kMimeTypeTextUtf8, "c")); 273 EqualsClipboardEvent(kMimeTypeTextUtf8, "c"));
280 } 274 }
281 275
282 TEST_F(ClientSessionTest, LocalInputTest) { 276 TEST_F(ClientSessionTest, LocalInputTest) {
283 CreateClientSession(); 277 CreateClientSession();
284 ConnectClientSession(); 278 ConnectClientSession();
285 WaitFirstFrame(); 279 NotifyVideoSize();
280
286 281
287 std::vector<protocol::MouseEvent> mouse_events; 282 std::vector<protocol::MouseEvent> mouse_events;
288 desktop_environment_factory_->last_desktop_environment() 283 desktop_environment_factory_->last_desktop_environment()
289 ->last_input_injector() 284 ->last_input_injector()
290 ->set_mouse_events(&mouse_events); 285 ->set_mouse_events(&mouse_events);
291 286
292 connection_->input_stub()->InjectMouseEvent(MakeMouseMoveEvent(100, 101)); 287 connection_->input_stub()->InjectMouseEvent(MakeMouseMoveEvent(100, 101));
293 288
294 #if !defined(OS_WIN) 289 #if !defined(OS_WIN)
295 // The OS echoes the injected event back. 290 // The OS echoes the injected event back.
(...skipping 14 matching lines...) Expand all
310 EXPECT_THAT(mouse_events[0], EqualsMouseMoveEvent(100, 101)); 305 EXPECT_THAT(mouse_events[0], EqualsMouseMoveEvent(100, 101));
311 EXPECT_THAT(mouse_events[1], EqualsMouseMoveEvent(200, 201)); 306 EXPECT_THAT(mouse_events[1], EqualsMouseMoveEvent(200, 201));
312 307
313 // TODO(jamiewalch): Verify that remote inputs are re-enabled 308 // TODO(jamiewalch): Verify that remote inputs are re-enabled
314 // eventually (via dependency injection, not sleep!) 309 // eventually (via dependency injection, not sleep!)
315 } 310 }
316 311
317 TEST_F(ClientSessionTest, RestoreEventState) { 312 TEST_F(ClientSessionTest, RestoreEventState) {
318 CreateClientSession(); 313 CreateClientSession();
319 ConnectClientSession(); 314 ConnectClientSession();
320 WaitFirstFrame(); 315 NotifyVideoSize();
321 316
322 FakeInputInjector* input_injector = 317 FakeInputInjector* input_injector =
323 desktop_environment_factory_->last_desktop_environment() 318 desktop_environment_factory_->last_desktop_environment()
324 ->last_input_injector() 319 ->last_input_injector()
325 .get(); 320 .get();
326 std::vector<protocol::KeyEvent> key_events; 321 std::vector<protocol::KeyEvent> key_events;
327 input_injector->set_key_events(&key_events); 322 input_injector->set_key_events(&key_events);
328 std::vector<protocol::MouseEvent> mouse_events; 323 std::vector<protocol::MouseEvent> mouse_events;
329 input_injector->set_mouse_events(&mouse_events); 324 input_injector->set_mouse_events(&mouse_events);
330 325
(...skipping 17 matching lines...) Expand all
348 EXPECT_EQ(4U, key_events.size()); 343 EXPECT_EQ(4U, key_events.size());
349 EXPECT_THAT(key_events[0], EqualsKeyEvent(1, true)); 344 EXPECT_THAT(key_events[0], EqualsKeyEvent(1, true));
350 EXPECT_THAT(key_events[1], EqualsKeyEvent(2, true)); 345 EXPECT_THAT(key_events[1], EqualsKeyEvent(2, true));
351 EXPECT_THAT(key_events[2], EqualsKeyEvent(1, false)); 346 EXPECT_THAT(key_events[2], EqualsKeyEvent(1, false));
352 EXPECT_THAT(key_events[3], EqualsKeyEvent(2, false)); 347 EXPECT_THAT(key_events[3], EqualsKeyEvent(2, false));
353 } 348 }
354 349
355 TEST_F(ClientSessionTest, ClampMouseEvents) { 350 TEST_F(ClientSessionTest, ClampMouseEvents) {
356 CreateClientSession(); 351 CreateClientSession();
357 ConnectClientSession(); 352 ConnectClientSession();
358 WaitFirstFrame(); 353 NotifyVideoSize();
359 354
360 std::vector<protocol::MouseEvent> mouse_events; 355 std::vector<protocol::MouseEvent> mouse_events;
361 desktop_environment_factory_->last_desktop_environment() 356 desktop_environment_factory_->last_desktop_environment()
362 ->last_input_injector() 357 ->last_input_injector()
363 ->set_mouse_events(&mouse_events); 358 ->set_mouse_events(&mouse_events);
364 359
365 int input_x[3] = {-999, 100, 999}; 360 int input_x[3] = {-999, 100, 999};
366 int expected_x[3] = {0, 100, protocol::FakeDesktopCapturer::kWidth - 1}; 361 int expected_x[3] = {0, 100, protocol::FakeDesktopCapturer::kWidth - 1};
367 int input_y[3] = {-999, 50, 999}; 362 int input_y[3] = {-999, 50, 999};
368 int expected_y[3] = {0, 50, protocol::FakeDesktopCapturer::kHeight - 1}; 363 int expected_y[3] = {0, 50, protocol::FakeDesktopCapturer::kHeight - 1};
369 364
370 protocol::MouseEvent expected_event; 365 protocol::MouseEvent expected_event;
371 for (int j = 0; j < 3; j++) { 366 for (int j = 0; j < 3; j++) {
372 for (int i = 0; i < 3; i++) { 367 for (int i = 0; i < 3; i++) {
373 mouse_events.clear(); 368 mouse_events.clear();
374 connection_->input_stub()->InjectMouseEvent( 369 connection_->input_stub()->InjectMouseEvent(
375 MakeMouseMoveEvent(input_x[i], input_y[j])); 370 MakeMouseMoveEvent(input_x[i], input_y[j]));
376 371
377 EXPECT_EQ(1U, mouse_events.size()); 372 EXPECT_EQ(1U, mouse_events.size());
378 EXPECT_THAT(mouse_events[0], 373 EXPECT_THAT(mouse_events[0],
379 EqualsMouseMoveEvent(expected_x[i], expected_y[j])); 374 EqualsMouseMoveEvent(expected_x[i], expected_y[j]));
380 } 375 }
381 } 376 }
382 } 377 }
383 378
384 TEST_F(ClientSessionTest, NoGnubbyAuth) { 379 TEST_F(ClientSessionTest, NoGnubbyAuth) {
385 CreateClientSession(); 380 CreateClientSession();
386 ConnectClientSession(); 381 ConnectClientSession();
387 WaitFirstFrame(); 382 NotifyVideoSize();
388 383
389 protocol::ExtensionMessage message; 384 protocol::ExtensionMessage message;
390 message.set_type("gnubby-auth"); 385 message.set_type("gnubby-auth");
391 message.set_data("test"); 386 message.set_data("test");
392 387
393 // Host should ignore gnubby messages when gnubby is disabled. 388 // Host should ignore gnubby messages when gnubby is disabled.
394 client_session_->DeliverClientMessage(message); 389 client_session_->DeliverClientMessage(message);
395 } 390 }
396 391
397 TEST_F(ClientSessionTest, EnableGnubbyAuth) { 392 TEST_F(ClientSessionTest, EnableGnubbyAuth) {
398 CreateClientSession(); 393 CreateClientSession();
399 ConnectClientSession(); 394 ConnectClientSession();
400 WaitFirstFrame(); 395 NotifyVideoSize();
401 396
402 // Lifetime controlled by object under test. 397 // Lifetime controlled by object under test.
403 MockGnubbyAuthHandler* gnubby_auth_handler = new MockGnubbyAuthHandler(); 398 MockGnubbyAuthHandler* gnubby_auth_handler = new MockGnubbyAuthHandler();
404 client_session_->SetGnubbyAuthHandlerForTesting(gnubby_auth_handler); 399 client_session_->SetGnubbyAuthHandlerForTesting(gnubby_auth_handler);
405 400
406 // Host should ignore gnubby messages when gnubby is disabled. 401 // Host should ignore gnubby messages when gnubby is disabled.
407 protocol::ExtensionMessage message; 402 protocol::ExtensionMessage message;
408 message.set_type("gnubby-auth"); 403 message.set_type("gnubby-auth");
409 message.set_data("test"); 404 message.set_data("test");
410 405
411 EXPECT_CALL(*gnubby_auth_handler, DeliverClientMessage(_)).Times(1); 406 EXPECT_CALL(*gnubby_auth_handler, DeliverClientMessage(_)).Times(1);
412 client_session_->DeliverClientMessage(message); 407 client_session_->DeliverClientMessage(message);
413 } 408 }
414 409
415 // Verifies that the client's video pipeline can be reset mid-session. 410 // Verifies that the client's video pipeline can be reset mid-session.
416 TEST_F(ClientSessionTest, ResetVideoPipeline) { 411 TEST_F(ClientSessionTest, ResetVideoPipeline) {
417 CreateClientSession(); 412 CreateClientSession();
418 ConnectClientSession(); 413 ConnectClientSession();
419 WaitFirstFrame(); 414 NotifyVideoSize();
420 415
421 client_session_->ResetVideoPipeline(); 416 client_session_->ResetVideoPipeline();
422 } 417 }
423 418
424 // Verifies that clients can have extensions registered, resulting in the 419 // Verifies that clients can have extensions registered, resulting in the
425 // correct capabilities being reported, and messages delivered correctly. 420 // correct capabilities being reported, and messages delivered correctly.
426 // The extension system is tested more extensively in the 421 // The extension system is tested more extensively in the
427 // HostExtensionSessionManager unit-tests. 422 // HostExtensionSessionManager unit-tests.
428 TEST_F(ClientSessionTest, Extensions) { 423 TEST_F(ClientSessionTest, Extensions) {
429 // Configure fake extensions for testing. 424 // Configure fake extensions for testing.
(...skipping 13 matching lines...) Expand all
443 CreateClientSession(); 438 CreateClientSession();
444 ConnectClientSession(); 439 ConnectClientSession();
445 440
446 testing::Mock::VerifyAndClearExpectations(&client_stub_); 441 testing::Mock::VerifyAndClearExpectations(&client_stub_);
447 442
448 // Mimic the client reporting an overlapping set of capabilities. 443 // Mimic the client reporting an overlapping set of capabilities.
449 protocol::Capabilities capabilities_message; 444 protocol::Capabilities capabilities_message;
450 capabilities_message.set_capabilities("cap1 cap4 default"); 445 capabilities_message.set_capabilities("cap1 cap4 default");
451 client_session_->SetCapabilities(capabilities_message); 446 client_session_->SetCapabilities(capabilities_message);
452 447
448 // Simulate OnCreateVideoEncoder() which is normally called by the
449 // ConnectionToClient when creating the video stream.
450 scoped_ptr<VideoEncoder> encoder(new VideoEncoderVerbatim());
451 connection_->event_handler()->OnCreateVideoEncoder(&encoder);
452
453 // Verify that the correct extension messages are delivered, and dropped. 453 // Verify that the correct extension messages are delivered, and dropped.
454 protocol::ExtensionMessage message1; 454 protocol::ExtensionMessage message1;
455 message1.set_type("ext1"); 455 message1.set_type("ext1");
456 message1.set_data("data"); 456 message1.set_data("data");
457 client_session_->DeliverClientMessage(message1); 457 client_session_->DeliverClientMessage(message1);
458 protocol::ExtensionMessage message3; 458 protocol::ExtensionMessage message3;
459 message3.set_type("ext3"); 459 message3.set_type("ext3");
460 message3.set_data("data"); 460 message3.set_data("data");
461 client_session_->DeliverClientMessage(message3); 461 client_session_->DeliverClientMessage(message3);
462 protocol::ExtensionMessage message4; 462 protocol::ExtensionMessage message4;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 515
516 client_session_->DisconnectSession(protocol::OK); 516 client_session_->DisconnectSession(protocol::OK);
517 client_session_.reset(); 517 client_session_.reset();
518 518
519 // ext1 was instantiated and wrapped the video capturer. 519 // ext1 was instantiated and wrapped the video capturer.
520 EXPECT_TRUE(extension.was_instantiated()); 520 EXPECT_TRUE(extension.was_instantiated());
521 EXPECT_TRUE(extension.has_wrapped_video_capturer()); 521 EXPECT_TRUE(extension.has_wrapped_video_capturer());
522 } 522 }
523 523
524 } // namespace remoting 524 } // 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