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

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

Issue 902613004: Fix ConnectionToClient to connect stubs only after authentication. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@audio_pump
Patch Set: Created 5 years, 10 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
« no previous file with comments | « remoting/host/client_session.cc ('k') | remoting/protocol/connection_to_client.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"
(...skipping 24 matching lines...) Expand all
35 using protocol::MockClientStub; 35 using protocol::MockClientStub;
36 using protocol::MockHostStub; 36 using protocol::MockHostStub;
37 using protocol::MockInputStub; 37 using protocol::MockInputStub;
38 using protocol::MockSession; 38 using protocol::MockSession;
39 using protocol::MockVideoStub; 39 using protocol::MockVideoStub;
40 using protocol::SessionConfig; 40 using protocol::SessionConfig;
41 41
42 using testing::_; 42 using testing::_;
43 using testing::AnyNumber; 43 using testing::AnyNumber;
44 using testing::AtMost; 44 using testing::AtMost;
45 using testing::AtLeast;
45 using testing::CreateFunctor; 46 using testing::CreateFunctor;
46 using testing::DeleteArg; 47 using testing::DeleteArg;
47 using testing::DoAll; 48 using testing::DoAll;
48 using testing::Expectation; 49 using testing::Expectation;
49 using testing::Invoke; 50 using testing::Invoke;
50 using testing::Return; 51 using testing::Return;
51 using testing::ReturnRef; 52 using testing::ReturnRef;
52 using testing::Sequence; 53 using testing::Sequence;
53 using testing::StrEq; 54 using testing::StrEq;
54 using testing::StrictMock; 55 using testing::StrictMock;
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 304
304 webrtc::DesktopCapturer* ClientSessionTest::CreateVideoCapturer() { 305 webrtc::DesktopCapturer* ClientSessionTest::CreateVideoCapturer() {
305 return new FakeDesktopCapturer(); 306 return new FakeDesktopCapturer();
306 } 307 }
307 308
308 webrtc::MouseCursorMonitor* ClientSessionTest::CreateMouseCursorMonitor() { 309 webrtc::MouseCursorMonitor* ClientSessionTest::CreateMouseCursorMonitor() {
309 return new FakeMouseCursorMonitor(); 310 return new FakeMouseCursorMonitor();
310 } 311 }
311 312
312 void ClientSessionTest::ConnectClientSession() { 313 void ClientSessionTest::ConnectClientSession() {
314 // Stubs should be set only after connection is authenticated.
315 EXPECT_FALSE(connection_->clipboard_stub());
316 EXPECT_FALSE(connection_->input_stub());
317
313 client_session_->OnConnectionAuthenticated(client_session_->connection()); 318 client_session_->OnConnectionAuthenticated(client_session_->connection());
319
320 EXPECT_TRUE(connection_->clipboard_stub());
321 EXPECT_TRUE(connection_->input_stub());
322
314 client_session_->OnConnectionChannelsConnected(client_session_->connection()); 323 client_session_->OnConnectionChannelsConnected(client_session_->connection());
315 } 324 }
316 325
317 void ClientSessionTest::SetMatchCapabilitiesExpectation() { 326 void ClientSessionTest::SetMatchCapabilitiesExpectation() {
318 // Set the client to report the same capabilities as the host. 327 // Set the client to report the same capabilities as the host.
319 EXPECT_CALL(client_stub_, SetCapabilities(_)) 328 EXPECT_CALL(client_stub_, SetCapabilities(_))
320 .Times(AtMost(1)) 329 .Times(AtMost(1))
321 .WillOnce(Invoke(client_session_.get(), &ClientSession::SetCapabilities)); 330 .WillOnce(Invoke(client_session_.get(), &ClientSession::SetCapabilities));
322 } 331 }
323 332
(...skipping 15 matching lines...) Expand all
339 } 348 }
340 349
341 MATCHER_P2(EqualsClipboardEvent, m, d, "") { 350 MATCHER_P2(EqualsClipboardEvent, m, d, "") {
342 return (strcmp(arg.mime_type().c_str(), m) == 0 && 351 return (strcmp(arg.mime_type().c_str(), m) == 0 &&
343 memcmp(arg.data().data(), d, arg.data().size()) == 0); 352 memcmp(arg.data().data(), d, arg.data().size()) == 0);
344 } 353 }
345 354
346 TEST_F(ClientSessionTest, ClipboardStubFilter) { 355 TEST_F(ClientSessionTest, ClipboardStubFilter) {
347 CreateClientSession(); 356 CreateClientSession();
348 357
349 protocol::ClipboardEvent clipboard_event1; 358 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_))
350 clipboard_event1.set_mime_type(kMimeTypeTextUtf8); 359 .WillOnce(Return(true));
351 clipboard_event1.set_data("a"); 360 EXPECT_CALL(*input_injector_, StartPtr(_));
352 361 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_));
353 protocol::ClipboardEvent clipboard_event2;
354 clipboard_event2.set_mime_type(kMimeTypeTextUtf8);
355 clipboard_event2.set_data("b");
356
357 protocol::ClipboardEvent clipboard_event3;
358 clipboard_event3.set_mime_type(kMimeTypeTextUtf8);
359 clipboard_event3.set_data("c");
360
361 Expectation authenticated =
362 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_))
363 .WillOnce(Return(true));
364 EXPECT_CALL(*input_injector_, StartPtr(_))
365 .After(authenticated);
366 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_))
367 .After(authenticated);
368 362
369 // Wait for the first video packet to be captured to make sure that 363 // Wait for the first video packet to be captured to make sure that
370 // the injected input will go though. Otherwise mouse events will be blocked 364 // the injected input will go though. Otherwise mouse events will be blocked
371 // by the mouse clamping filter. 365 // by the mouse clamping filter.
372 Sequence s; 366 base::RunLoop run_loop;
373 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) 367 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _))
374 .InSequence(s) 368 .Times(AtLeast(1))
375 .After(authenticated) 369 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
376 .WillOnce(DoAll(
377 // This event should get through to the clipboard stub.
378 InjectClipboardEvent(connection_, clipboard_event2),
379 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession),
380 // This event should not get through to the clipboard stub,
381 // because the client has disconnected.
382 InjectClipboardEvent(connection_, clipboard_event3),
383 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession)));
384 EXPECT_CALL(*input_injector_, InjectClipboardEvent(EqualsClipboardEvent(
385 kMimeTypeTextUtf8, "b")))
386 .InSequence(s);
387 EXPECT_CALL(session_event_handler_, OnSessionClosed(_))
388 .InSequence(s);
389 370
390 // This event should not get through to the clipboard stub, 371 {
391 // because the client isn't authenticated yet. 372 EXPECT_CALL(*input_injector_, InjectClipboardEvent(EqualsClipboardEvent(
392 connection_->clipboard_stub()->InjectClipboardEvent(clipboard_event1); 373 kMimeTypeTextUtf8, "a")));
374 EXPECT_CALL(*input_injector_, InjectKeyEvent(EqualsUsbEvent(1, true)));
375 EXPECT_CALL(*input_injector_, InjectKeyEvent(EqualsUsbEvent(1, false)));
376 EXPECT_CALL(*input_injector_, InjectMouseEvent(EqualsMouseEvent(100, 101)));
377
378 EXPECT_CALL(*input_injector_, InjectClipboardEvent(EqualsClipboardEvent(
379 kMimeTypeTextUtf8, "c")));
380 EXPECT_CALL(*input_injector_, InjectKeyEvent(EqualsUsbEvent(3, true)));
381 EXPECT_CALL(*input_injector_, InjectMouseEvent(EqualsMouseEvent(300, 301)));
382 EXPECT_CALL(*input_injector_, InjectKeyEvent(EqualsUsbEvent(3, false)));
383 }
393 384
394 ConnectClientSession(); 385 ConnectClientSession();
395 }
396 386
397 TEST_F(ClientSessionTest, InputStubFilter) { 387 // With for the first frame.
398 CreateClientSession(); 388 run_loop.Run();
399 389
400 protocol::KeyEvent key_event1; 390 // Inject test events that are expected to be injected.
401 key_event1.set_pressed(true); 391 protocol::ClipboardEvent clipboard_event;
402 key_event1.set_usb_keycode(1); 392 clipboard_event.set_mime_type(kMimeTypeTextUtf8);
393 clipboard_event.set_data("a");
394 connection_->clipboard_stub()->InjectClipboardEvent(clipboard_event);
403 395
404 protocol::KeyEvent key_event2_down; 396 protocol::KeyEvent key_event;
405 key_event2_down.set_pressed(true); 397 key_event.set_pressed(true);
406 key_event2_down.set_usb_keycode(2); 398 key_event.set_usb_keycode(1);
399 connection_->input_stub()->InjectKeyEvent(key_event);
407 400
408 protocol::KeyEvent key_event2_up; 401 protocol::MouseEvent mouse_event;
409 key_event2_up.set_pressed(false); 402 mouse_event.set_x(100);
410 key_event2_up.set_usb_keycode(2); 403 mouse_event.set_y(101);
404 connection_->input_stub()->InjectMouseEvent(mouse_event);
411 405
412 protocol::KeyEvent key_event3; 406 base::RunLoop().RunUntilIdle();
413 key_event3.set_pressed(true);
414 key_event3.set_usb_keycode(3);
415 407
416 protocol::MouseEvent mouse_event1; 408 // Disable input.
417 mouse_event1.set_x(100); 409 client_session_->SetDisableInputs(true);
418 mouse_event1.set_y(101);
419 410
420 protocol::MouseEvent mouse_event2; 411 // These event shouldn't get though to the input injector.
421 mouse_event2.set_x(200); 412 clipboard_event.set_data("b");
422 mouse_event2.set_y(201); 413 connection_->clipboard_stub()->InjectClipboardEvent(clipboard_event);
423 414
424 protocol::MouseEvent mouse_event3; 415 key_event.set_pressed(true);
425 mouse_event3.set_x(300); 416 key_event.set_usb_keycode(2);
426 mouse_event3.set_y(301); 417 connection_->input_stub()->InjectKeyEvent(key_event);
418 key_event.set_pressed(false);
419 key_event.set_usb_keycode(2);
420 connection_->input_stub()->InjectKeyEvent(key_event);
427 421
428 Expectation authenticated = 422 mouse_event.set_x(200);
429 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)) 423 mouse_event.set_y(201);
430 .WillOnce(Return(true)); 424 connection_->input_stub()->InjectMouseEvent(mouse_event);
431 EXPECT_CALL(*input_injector_, StartPtr(_))
432 .After(authenticated);
433 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_))
434 .After(authenticated);
435 425
436 // Wait for the first video packet to be captured to make sure that 426 base::RunLoop().RunUntilIdle();
437 // the injected input will go though. Otherwise mouse events will be blocked
438 // by the mouse clamping filter.
439 Sequence s;
440 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _))
441 .InSequence(s)
442 .After(authenticated)
443 .WillOnce(DoAll(
444 // These events should get through to the input stub.
445 InjectKeyEvent(connection_, key_event2_down),
446 InjectKeyEvent(connection_, key_event2_up),
447 InjectMouseEvent(connection_, mouse_event2),
448 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession),
449 // These events should not get through to the input stub,
450 // because the client has disconnected.
451 InjectKeyEvent(connection_, key_event3),
452 InjectMouseEvent(connection_, mouse_event3),
453 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession)));
454 EXPECT_CALL(*input_injector_, InjectKeyEvent(EqualsUsbEvent(2, true)))
455 .InSequence(s);
456 EXPECT_CALL(*input_injector_, InjectKeyEvent(EqualsUsbEvent(2, false)))
457 .InSequence(s);
458 EXPECT_CALL(*input_injector_, InjectMouseEvent(EqualsMouseEvent(200, 201)))
459 .InSequence(s);
460 EXPECT_CALL(session_event_handler_, OnSessionClosed(_))
461 .InSequence(s);
462 427
463 // These events should not get through to the input stub, 428 // Enable input again.
464 // because the client isn't authenticated yet. 429 client_session_->SetDisableInputs(false);
465 connection_->input_stub()->InjectKeyEvent(key_event1);
466 connection_->input_stub()->InjectMouseEvent(mouse_event1);
467 430
468 ConnectClientSession(); 431 clipboard_event.set_data("c");
432 connection_->clipboard_stub()->InjectClipboardEvent(clipboard_event);
433 base::RunLoop().RunUntilIdle();
434
435 key_event.set_pressed(true);
436 key_event.set_usb_keycode(3);
437 connection_->input_stub()->InjectKeyEvent(key_event);
438
439 mouse_event.set_x(300);
440 mouse_event.set_y(301);
441 connection_->input_stub()->InjectMouseEvent(mouse_event);
442
443 client_session_->DisconnectSession();
444 client_session_->OnConnectionClosed(connection_, protocol::OK);
445 client_session_.reset();
469 } 446 }
470 447
471 TEST_F(ClientSessionTest, LocalInputTest) { 448 TEST_F(ClientSessionTest, LocalInputTest) {
472 CreateClientSession(); 449 CreateClientSession();
473 450
474 protocol::MouseEvent mouse_event1; 451 protocol::MouseEvent mouse_event1;
475 mouse_event1.set_x(100); 452 mouse_event1.set_x(100);
476 mouse_event1.set_y(101); 453 mouse_event1.set_y(101);
477 protocol::MouseEvent mouse_event2; 454 protocol::MouseEvent mouse_event2;
478 mouse_event2.set_x(200); 455 mouse_event2.set_x(200);
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 785
809 DisconnectClientSession(); 786 DisconnectClientSession();
810 StopClientSession(); 787 StopClientSession();
811 788
812 // ext1 was instantiated and wrapped the video capturer. 789 // ext1 was instantiated and wrapped the video capturer.
813 EXPECT_TRUE(extension.was_instantiated()); 790 EXPECT_TRUE(extension.was_instantiated());
814 EXPECT_TRUE(extension.has_wrapped_video_capturer()); 791 EXPECT_TRUE(extension.has_wrapped_video_capturer());
815 } 792 }
816 793
817 } // namespace remoting 794 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/client_session.cc ('k') | remoting/protocol/connection_to_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698