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

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

Issue 985863002: Move all protocol event matchers to test_event_matchers.h (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 5 years, 9 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
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_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/test/test_simple_task_runner.h" 12 #include "base/test/test_simple_task_runner.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/host/audio_capturer.h" 15 #include "remoting/host/audio_capturer.h"
16 #include "remoting/host/client_session.h" 16 #include "remoting/host/client_session.h"
17 #include "remoting/host/desktop_environment.h" 17 #include "remoting/host/desktop_environment.h"
18 #include "remoting/host/fake_desktop_capturer.h" 18 #include "remoting/host/fake_desktop_capturer.h"
19 #include "remoting/host/fake_host_extension.h" 19 #include "remoting/host/fake_host_extension.h"
20 #include "remoting/host/fake_mouse_cursor_monitor.h" 20 #include "remoting/host/fake_mouse_cursor_monitor.h"
21 #include "remoting/host/host_extension.h" 21 #include "remoting/host/host_extension.h"
22 #include "remoting/host/host_extension_session.h" 22 #include "remoting/host/host_extension_session.h"
23 #include "remoting/host/host_mock_objects.h" 23 #include "remoting/host/host_mock_objects.h"
24 #include "remoting/protocol/protocol_mock_objects.h" 24 #include "remoting/protocol/protocol_mock_objects.h"
25 #include "remoting/protocol/test_event_matchers.h"
25 #include "testing/gmock/include/gmock/gmock-matchers.h" 26 #include "testing/gmock/include/gmock/gmock-matchers.h"
26 #include "testing/gmock_mutant.h" 27 #include "testing/gmock_mutant.h"
27 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
28 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" 29 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
29 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h" 30 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h"
30 #include "third_party/webrtc/modules/desktop_capture/screen_capturer_mock_object s.h" 31 #include "third_party/webrtc/modules/desktop_capture/screen_capturer_mock_object s.h"
31 32
32 namespace remoting { 33 namespace remoting {
33 34
35 using protocol::MockClientStub;
34 using protocol::MockConnectionToClient; 36 using protocol::MockConnectionToClient;
35 using protocol::MockClientStub;
36 using protocol::MockHostStub; 37 using protocol::MockHostStub;
37 using protocol::MockInputStub; 38 using protocol::MockInputStub;
38 using protocol::MockSession; 39 using protocol::MockSession;
39 using protocol::MockVideoStub; 40 using protocol::MockVideoStub;
40 using protocol::SessionConfig; 41 using protocol::SessionConfig;
42 using protocol::test::EqualsClipboardEvent;
43 using protocol::test::EqualsMouseButtonEvent;
44 using protocol::test::EqualsMouseMoveEvent;
45 using protocol::test::EqualsKeyEvent;
41 46
42 using testing::_; 47 using testing::_;
43 using testing::AnyNumber; 48 using testing::AnyNumber;
44 using testing::AtMost; 49 using testing::AtMost;
45 using testing::AtLeast; 50 using testing::AtLeast;
46 using testing::CreateFunctor; 51 using testing::CreateFunctor;
47 using testing::DeleteArg; 52 using testing::DeleteArg;
48 using testing::DoAll; 53 using testing::DoAll;
49 using testing::Expectation; 54 using testing::Expectation;
50 using testing::Invoke; 55 using testing::Invoke;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 ACTION_P2(DeliverClientMessage, client_session, message) { 87 ACTION_P2(DeliverClientMessage, client_session, message) {
83 client_session->DeliverClientMessage(message); 88 client_session->DeliverClientMessage(message);
84 } 89 }
85 90
86 ACTION_P2(SetCapabilities, client_session, capabilities) { 91 ACTION_P2(SetCapabilities, client_session, capabilities) {
87 protocol::Capabilities capabilities_message; 92 protocol::Capabilities capabilities_message;
88 capabilities_message.set_capabilities(capabilities); 93 capabilities_message.set_capabilities(capabilities);
89 client_session->SetCapabilities(capabilities_message); 94 client_session->SetCapabilities(capabilities_message);
90 } 95 }
91 96
92 MATCHER_P2(EqualsUsbEvent, usb_keycode, pressed, "") {
93 return arg.usb_keycode() == (unsigned int)usb_keycode &&
94 arg.pressed() == pressed;
95 }
96
97 MATCHER_P2(EqualsMouseEvent, x, y, "") {
98 return arg.x() == x && arg.y() == y;
99 }
100
101 MATCHER_P2(EqualsMouseButtonEvent, button, down, "") {
102 return arg.button() == button && arg.button_down() == down;
103 }
104
105 // Matches a |protocol::Capabilities| argument against a list of capabilities 97 // Matches a |protocol::Capabilities| argument against a list of capabilities
106 // formatted as a space-separated string. 98 // formatted as a space-separated string.
107 MATCHER_P(EqCapabilities, expected_capabilities, "") { 99 MATCHER_P(EqCapabilities, expected_capabilities, "") {
108 if (!arg.has_capabilities()) 100 if (!arg.has_capabilities())
109 return false; 101 return false;
110 102
111 std::vector<std::string> words_args; 103 std::vector<std::string> words_args;
112 std::vector<std::string> words_expected; 104 std::vector<std::string> words_expected;
113 Tokenize(arg.capabilities(), " ", &words_args); 105 Tokenize(arg.capabilities(), " ", &words_args);
114 Tokenize(expected_capabilities, " ", &words_expected); 106 Tokenize(expected_capabilities, " ", &words_expected);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 new MockConnectionToClient(session, nullptr)); 234 new MockConnectionToClient(session, nullptr));
243 EXPECT_CALL(*connection, session()).WillRepeatedly(Return(session)); 235 EXPECT_CALL(*connection, session()).WillRepeatedly(Return(session));
244 EXPECT_CALL(*connection, client_stub()) 236 EXPECT_CALL(*connection, client_stub())
245 .WillRepeatedly(Return(&client_stub_)); 237 .WillRepeatedly(Return(&client_stub_));
246 EXPECT_CALL(*connection, video_stub()).WillRepeatedly(Return(&video_stub_)); 238 EXPECT_CALL(*connection, video_stub()).WillRepeatedly(Return(&video_stub_));
247 EXPECT_CALL(*connection, Disconnect()); 239 EXPECT_CALL(*connection, Disconnect());
248 connection_ = connection.get(); 240 connection_ = connection.get();
249 241
250 client_session_.reset(new ClientSession( 242 client_session_.reset(new ClientSession(
251 &session_event_handler_, 243 &session_event_handler_,
252 task_runner_, // Audio thread. 244 task_runner_, // Audio thread.
253 task_runner_, // Input thread. 245 task_runner_, // Input thread.
254 task_runner_, // Capture thread. 246 task_runner_, // Capture thread.
255 task_runner_, // Encode thread. 247 task_runner_, // Encode thread.
256 task_runner_, // Network thread. 248 task_runner_, // Network thread.
257 task_runner_, // UI thread. 249 task_runner_, // UI thread.
258 connection.Pass(), 250 connection.Pass(),
259 desktop_environment_factory_.get(), 251 desktop_environment_factory_.get(),
260 base::TimeDelta(), 252 base::TimeDelta(),
261 nullptr, 253 nullptr,
262 extensions_)); 254 extensions_));
263 } 255 }
264 256
265 void ClientSessionTest::DisconnectClientSession() { 257 void ClientSessionTest::DisconnectClientSession() {
266 client_session_->DisconnectSession(); 258 client_session_->DisconnectSession();
267 // MockSession won't trigger OnConnectionClosed, so fake it. 259 // MockSession won't trigger OnConnectionClosed, so fake it.
(...skipping 15 matching lines...) Expand all
283 .WillOnce(Invoke(this, &ClientSessionTest::CreateInputInjector)); 275 .WillOnce(Invoke(this, &ClientSessionTest::CreateInputInjector));
284 EXPECT_CALL(*desktop_environment, CreateScreenControlsPtr()) 276 EXPECT_CALL(*desktop_environment, CreateScreenControlsPtr())
285 .Times(AtMost(1)); 277 .Times(AtMost(1));
286 EXPECT_CALL(*desktop_environment, CreateVideoCapturerPtr()) 278 EXPECT_CALL(*desktop_environment, CreateVideoCapturerPtr())
287 .WillRepeatedly(Invoke(this, &ClientSessionTest::CreateVideoCapturer)); 279 .WillRepeatedly(Invoke(this, &ClientSessionTest::CreateVideoCapturer));
288 EXPECT_CALL(*desktop_environment, CreateMouseCursorMonitorPtr()) 280 EXPECT_CALL(*desktop_environment, CreateMouseCursorMonitorPtr())
289 .WillRepeatedly( 281 .WillRepeatedly(
290 Invoke(this, &ClientSessionTest::CreateMouseCursorMonitor)); 282 Invoke(this, &ClientSessionTest::CreateMouseCursorMonitor));
291 EXPECT_CALL(*desktop_environment, GetCapabilities()) 283 EXPECT_CALL(*desktop_environment, GetCapabilities())
292 .Times(AtMost(1)) 284 .Times(AtMost(1))
293 .WillOnce(Return(kDefaultTestCapability)); 285 .WillOnce(Return(kDefaultTestCapability));
294 EXPECT_CALL(*desktop_environment, SetCapabilities(_)) 286 EXPECT_CALL(*desktop_environment, SetCapabilities(_))
295 .Times(AtMost(1)); 287 .Times(AtMost(1));
296 288
297 return desktop_environment; 289 return desktop_environment;
298 } 290 }
299 291
300 InputInjector* ClientSessionTest::CreateInputInjector() { 292 InputInjector* ClientSessionTest::CreateInputInjector() {
301 EXPECT_TRUE(input_injector_); 293 EXPECT_TRUE(input_injector_);
302 return input_injector_.release(); 294 return input_injector_.release();
303 } 295 }
(...skipping 27 matching lines...) Expand all
331 } 323 }
332 324
333 void ClientSessionTest::SetSendMessageAndDisconnectExpectation( 325 void ClientSessionTest::SetSendMessageAndDisconnectExpectation(
334 const std::string& message_type) { 326 const std::string& message_type) {
335 protocol::ExtensionMessage message; 327 protocol::ExtensionMessage message;
336 message.set_type(message_type); 328 message.set_type(message_type);
337 message.set_data("data"); 329 message.set_data("data");
338 330
339 Expectation authenticated = 331 Expectation authenticated =
340 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)) 332 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_))
341 .WillOnce(Return(true)); 333 .WillOnce(Return(true));
342 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)) 334 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_))
343 .After(authenticated) 335 .After(authenticated)
344 .WillOnce(DoAll( 336 .WillOnce(DoAll(
345 DeliverClientMessage(client_session_.get(), message), 337 DeliverClientMessage(client_session_.get(), message),
346 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), 338 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession),
347 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); 339 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession)));
348 } 340 }
349 341
350 MATCHER_P2(EqualsClipboardEvent, m, d, "") {
351 return (strcmp(arg.mime_type().c_str(), m) == 0 &&
352 memcmp(arg.data().data(), d, arg.data().size()) == 0);
353 }
354
355 TEST_F(ClientSessionTest, ClipboardStubFilter) { 342 TEST_F(ClientSessionTest, ClipboardStubFilter) {
356 CreateClientSession(); 343 CreateClientSession();
357 344
358 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)) 345 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_))
359 .WillOnce(Return(true)); 346 .WillOnce(Return(true));
360 EXPECT_CALL(*input_injector_, StartPtr(_)); 347 EXPECT_CALL(*input_injector_, StartPtr(_));
361 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); 348 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_));
362 349
363 // Wait for the first video packet to be captured to make sure that 350 // Wait for the first video packet to be captured to make sure that
364 // the injected input will go though. Otherwise mouse events will be blocked 351 // the injected input will go though. Otherwise mouse events will be blocked
365 // by the mouse clamping filter. 352 // by the mouse clamping filter.
366 base::RunLoop run_loop; 353 base::RunLoop run_loop;
367 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) 354 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _))
368 .Times(AtLeast(1)) 355 .Times(AtLeast(1))
369 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 356 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
370 357
371 { 358 {
372 EXPECT_CALL(*input_injector_, InjectClipboardEvent(EqualsClipboardEvent( 359 EXPECT_CALL(*input_injector_, InjectClipboardEvent(EqualsClipboardEvent(
373 kMimeTypeTextUtf8, "a"))); 360 kMimeTypeTextUtf8, "a")));
374 EXPECT_CALL(*input_injector_, InjectKeyEvent(EqualsUsbEvent(1, true))); 361 EXPECT_CALL(*input_injector_, InjectKeyEvent(EqualsKeyEvent(1, true)));
375 EXPECT_CALL(*input_injector_, InjectKeyEvent(EqualsUsbEvent(1, false))); 362 EXPECT_CALL(*input_injector_, InjectKeyEvent(EqualsKeyEvent(1, false)));
376 EXPECT_CALL(*input_injector_, InjectMouseEvent(EqualsMouseEvent(100, 101))); 363 EXPECT_CALL(*input_injector_,
364 InjectMouseEvent(EqualsMouseMoveEvent(100, 101)));
377 365
378 EXPECT_CALL(*input_injector_, InjectClipboardEvent(EqualsClipboardEvent( 366 EXPECT_CALL(*input_injector_, InjectClipboardEvent(EqualsClipboardEvent(
379 kMimeTypeTextUtf8, "c"))); 367 kMimeTypeTextUtf8, "c")));
380 EXPECT_CALL(*input_injector_, InjectKeyEvent(EqualsUsbEvent(3, true))); 368 EXPECT_CALL(*input_injector_, InjectKeyEvent(EqualsKeyEvent(3, true)));
381 EXPECT_CALL(*input_injector_, InjectMouseEvent(EqualsMouseEvent(300, 301))); 369 EXPECT_CALL(*input_injector_,
382 EXPECT_CALL(*input_injector_, InjectKeyEvent(EqualsUsbEvent(3, false))); 370 InjectMouseEvent(EqualsMouseMoveEvent(300, 301)));
371 EXPECT_CALL(*input_injector_, InjectKeyEvent(EqualsKeyEvent(3, false)));
383 } 372 }
384 373
385 ConnectClientSession(); 374 ConnectClientSession();
386 375
387 // Wait for the first frame. 376 // Wait for the first frame.
388 run_loop.Run(); 377 run_loop.Run();
389 378
390 // Inject test events that are expected to be injected. 379 // Inject test events that are expected to be injected.
391 protocol::ClipboardEvent clipboard_event; 380 protocol::ClipboardEvent clipboard_event;
392 clipboard_event.set_mime_type(kMimeTypeTextUtf8); 381 clipboard_event.set_mime_type(kMimeTypeTextUtf8);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 InjectMouseEvent(connection_, mouse_event2), 473 InjectMouseEvent(connection_, mouse_event2),
485 // Now this is a genuine local event. 474 // Now this is a genuine local event.
486 LocalMouseMoved(client_session_.get(), mouse_event1), 475 LocalMouseMoved(client_session_.get(), mouse_event1),
487 // This one should be blocked because of the previous local input 476 // This one should be blocked because of the previous local input
488 // event. 477 // event.
489 InjectMouseEvent(connection_, mouse_event3), 478 InjectMouseEvent(connection_, mouse_event3),
490 // TODO(jamiewalch): Verify that remote inputs are re-enabled 479 // TODO(jamiewalch): Verify that remote inputs are re-enabled
491 // eventually (via dependency injection, not sleep!) 480 // eventually (via dependency injection, not sleep!)
492 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), 481 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession),
493 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); 482 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession)));
494 EXPECT_CALL(*input_injector_, InjectMouseEvent(EqualsMouseEvent(100, 101))) 483 EXPECT_CALL(*input_injector_,
495 .InSequence(s); 484 InjectMouseEvent(EqualsMouseMoveEvent(100, 101))).InSequence(s);
496 EXPECT_CALL(*input_injector_, InjectMouseEvent(EqualsMouseEvent(200, 201))) 485 EXPECT_CALL(*input_injector_,
497 .InSequence(s); 486 InjectMouseEvent(EqualsMouseMoveEvent(200, 201))).InSequence(s);
498 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)) 487 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)).InSequence(s);
499 .InSequence(s);
500 488
501 ConnectClientSession(); 489 ConnectClientSession();
502 } 490 }
503 491
504 TEST_F(ClientSessionTest, RestoreEventState) { 492 TEST_F(ClientSessionTest, RestoreEventState) {
505 CreateClientSession(); 493 CreateClientSession();
506 494
507 protocol::KeyEvent key1; 495 protocol::KeyEvent key1;
508 key1.set_pressed(true); 496 key1.set_pressed(true);
509 key1.set_usb_keycode(1); 497 key1.set_usb_keycode(1);
510 498
511 protocol::KeyEvent key2; 499 protocol::KeyEvent key2;
512 key2.set_pressed(true); 500 key2.set_pressed(true);
513 key2.set_usb_keycode(2); 501 key2.set_usb_keycode(2);
514 502
515 protocol::MouseEvent mousedown; 503 protocol::MouseEvent mousedown;
516 mousedown.set_button(protocol::MouseEvent::BUTTON_LEFT); 504 mousedown.set_button(protocol::MouseEvent::BUTTON_LEFT);
517 mousedown.set_button_down(true); 505 mousedown.set_button_down(true);
518 506
519 Expectation authenticated = 507 Expectation authenticated =
520 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)) 508 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_))
521 .WillOnce(Return(true)); 509 .WillOnce(Return(true));
522 EXPECT_CALL(*input_injector_, StartPtr(_)) 510 EXPECT_CALL(*input_injector_, StartPtr(_)).After(authenticated);
523 .After(authenticated);
524 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)) 511 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_))
525 .After(authenticated); 512 .After(authenticated);
526 513
527 // Wait for the first video packet to be captured to make sure that 514 // Wait for the first video packet to be captured to make sure that
528 // the injected input will go though. Otherwise mouse events will be blocked 515 // the injected input will go though. Otherwise mouse events will be blocked
529 // by the mouse clamping filter. 516 // by the mouse clamping filter.
530 Sequence s; 517 Sequence s;
531 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) 518 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _))
532 .InSequence(s) 519 .InSequence(s)
533 .After(authenticated) 520 .After(authenticated)
534 .WillOnce(DoAll( 521 .WillOnce(DoAll(
535 InjectKeyEvent(connection_, key1), 522 InjectKeyEvent(connection_, key1), InjectKeyEvent(connection_, key2),
536 InjectKeyEvent(connection_, key2),
537 InjectMouseEvent(connection_, mousedown), 523 InjectMouseEvent(connection_, mousedown),
538 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), 524 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession),
539 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); 525 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession)));
540 EXPECT_CALL(*input_injector_, InjectKeyEvent(EqualsUsbEvent(1, true))) 526 EXPECT_CALL(*input_injector_, InjectKeyEvent(EqualsKeyEvent(1, true)))
541 .InSequence(s); 527 .InSequence(s);
542 EXPECT_CALL(*input_injector_, InjectKeyEvent(EqualsUsbEvent(2, true))) 528 EXPECT_CALL(*input_injector_, InjectKeyEvent(EqualsKeyEvent(2, true)))
543 .InSequence(s); 529 .InSequence(s);
544 EXPECT_CALL(*input_injector_, InjectMouseEvent(EqualsMouseButtonEvent( 530 EXPECT_CALL(*input_injector_, InjectMouseEvent(EqualsMouseButtonEvent(
545 protocol::MouseEvent::BUTTON_LEFT, true))) 531 protocol::MouseEvent::BUTTON_LEFT, true)))
546 .InSequence(s); 532 .InSequence(s);
547 EXPECT_CALL(*input_injector_, InjectKeyEvent(EqualsUsbEvent(1, false))) 533 EXPECT_CALL(*input_injector_, InjectKeyEvent(EqualsKeyEvent(1, false)))
548 .InSequence(s); 534 .InSequence(s);
549 EXPECT_CALL(*input_injector_, InjectKeyEvent(EqualsUsbEvent(2, false))) 535 EXPECT_CALL(*input_injector_, InjectKeyEvent(EqualsKeyEvent(2, false)))
550 .InSequence(s); 536 .InSequence(s);
551 EXPECT_CALL(*input_injector_, InjectMouseEvent(EqualsMouseButtonEvent( 537 EXPECT_CALL(*input_injector_, InjectMouseEvent(EqualsMouseButtonEvent(
552 protocol::MouseEvent::BUTTON_LEFT, false))) 538 protocol::MouseEvent::BUTTON_LEFT, false)))
553 .InSequence(s); 539 .InSequence(s);
554 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)) 540 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)).InSequence(s);
555 .InSequence(s);
556 541
557 ConnectClientSession(); 542 ConnectClientSession();
558 } 543 }
559 544
560 TEST_F(ClientSessionTest, ClampMouseEvents) { 545 TEST_F(ClientSessionTest, ClampMouseEvents) {
561 CreateClientSession(); 546 CreateClientSession();
562 547
563 Expectation authenticated = 548 Expectation authenticated =
564 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)) 549 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_))
565 .WillOnce(Return(true)); 550 .WillOnce(Return(true));
566 EXPECT_CALL(*input_injector_, StartPtr(_)) 551 EXPECT_CALL(*input_injector_, StartPtr(_)).After(authenticated);
567 .After(authenticated);
568 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)) 552 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_))
569 .After(authenticated); 553 .After(authenticated);
570 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)) 554 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)).After(authenticated);
571 .After(authenticated);
572 555
573 Expectation connected = authenticated; 556 Expectation connected = authenticated;
574 557
575 int input_x[3] = { -999, 100, 999 }; 558 int input_x[3] = { -999, 100, 999 };
576 int expected_x[3] = { 0, 100, FakeDesktopCapturer::kWidth - 1 }; 559 int expected_x[3] = { 0, 100, FakeDesktopCapturer::kWidth - 1 };
577 int input_y[3] = { -999, 50, 999 }; 560 int input_y[3] = { -999, 50, 999 };
578 int expected_y[3] = { 0, 50, FakeDesktopCapturer::kHeight - 1 }; 561 int expected_y[3] = { 0, 50, FakeDesktopCapturer::kHeight - 1 };
579 562
580 protocol::MouseEvent expected_event; 563 protocol::MouseEvent expected_event;
581 for (int j = 0; j < 3; j++) { 564 for (int j = 0; j < 3; j++) {
582 for (int i = 0; i < 3; i++) { 565 for (int i = 0; i < 3; i++) {
583 protocol::MouseEvent injected_event; 566 protocol::MouseEvent injected_event;
584 injected_event.set_x(input_x[i]); 567 injected_event.set_x(input_x[i]);
585 injected_event.set_y(input_y[j]); 568 injected_event.set_y(input_y[j]);
586 569
587 if (i == 0 && j == 0) { 570 if (i == 0 && j == 0) {
588 // Inject the 1st event once a video packet has been received. 571 // Inject the 1st event once a video packet has been received.
589 connected = 572 connected =
590 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) 573 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _))
591 .After(connected) 574 .After(connected)
592 .WillOnce(InjectMouseEvent(connection_, injected_event)); 575 .WillOnce(InjectMouseEvent(connection_, injected_event));
593 } else { 576 } else {
594 // Every next event is injected once the previous event has been 577 // Every next event is injected once the previous event has been
595 // received. 578 // received.
596 connected = 579 connected =
597 EXPECT_CALL(*input_injector_, 580 EXPECT_CALL(*input_injector_,
598 InjectMouseEvent(EqualsMouseEvent(expected_event.x(), 581 InjectMouseEvent(EqualsMouseMoveEvent(
599 expected_event.y()))) 582 expected_event.x(), expected_event.y())))
600 .After(connected) 583 .After(connected)
601 .WillOnce(InjectMouseEvent(connection_, injected_event)); 584 .WillOnce(InjectMouseEvent(connection_, injected_event));
602 } 585 }
603 586
604 expected_event.set_x(expected_x[i]); 587 expected_event.set_x(expected_x[i]);
605 expected_event.set_y(expected_y[j]); 588 expected_event.set_y(expected_y[j]);
606 } 589 }
607 } 590 }
608 591
609 // Shutdown the connection once the last event has been received. 592 // Shutdown the connection once the last event has been received.
610 EXPECT_CALL(*input_injector_, 593 EXPECT_CALL(*input_injector_, InjectMouseEvent(EqualsMouseMoveEvent(
611 InjectMouseEvent(EqualsMouseEvent(expected_event.x(), 594 expected_event.x(), expected_event.y())))
612 expected_event.y())))
613 .After(connected) 595 .After(connected)
614 .WillOnce(DoAll( 596 .WillOnce(DoAll(
615 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), 597 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession),
616 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); 598 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession)));
617 599
618 ConnectClientSession(); 600 ConnectClientSession();
619 } 601 }
620 602
621 TEST_F(ClientSessionTest, NoGnubbyAuth) { 603 TEST_F(ClientSessionTest, NoGnubbyAuth) {
622 CreateClientSession(); 604 CreateClientSession();
623 605
624 protocol::ExtensionMessage message; 606 protocol::ExtensionMessage message;
625 message.set_type("gnubby-auth"); 607 message.set_type("gnubby-auth");
626 message.set_data("test"); 608 message.set_data("test");
627 609
628 Expectation authenticated = 610 Expectation authenticated =
629 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)) 611 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_))
630 .WillOnce(Return(true)); 612 .WillOnce(Return(true));
631 EXPECT_CALL(*input_injector_, StartPtr(_)).After(authenticated); 613 EXPECT_CALL(*input_injector_, StartPtr(_)).After(authenticated);
632 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)) 614 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_))
633 .After(authenticated) 615 .After(authenticated)
634 .WillOnce(DoAll( 616 .WillOnce(DoAll(
635 DeliverClientMessage(client_session_.get(), message), 617 DeliverClientMessage(client_session_.get(), message),
636 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), 618 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession),
637 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); 619 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession)));
638 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); 620 EXPECT_CALL(session_event_handler_, OnSessionClosed(_));
639 621
640 ConnectClientSession(); 622 ConnectClientSession();
641 } 623 }
642 624
643 TEST_F(ClientSessionTest, EnableGnubbyAuth) { 625 TEST_F(ClientSessionTest, EnableGnubbyAuth) {
644 CreateClientSession(); 626 CreateClientSession();
645 627
646 // Lifetime controlled by object under test. 628 // Lifetime controlled by object under test.
647 MockGnubbyAuthHandler* gnubby_auth_handler = new MockGnubbyAuthHandler(); 629 MockGnubbyAuthHandler* gnubby_auth_handler = new MockGnubbyAuthHandler();
648 630
649 protocol::ExtensionMessage message; 631 protocol::ExtensionMessage message;
650 message.set_type("gnubby-auth"); 632 message.set_type("gnubby-auth");
651 message.set_data("test"); 633 message.set_data("test");
652 634
653 Expectation authenticated = 635 Expectation authenticated =
654 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)) 636 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_))
655 .WillOnce(Return(true)); 637 .WillOnce(Return(true));
656 EXPECT_CALL(*input_injector_, StartPtr(_)).After(authenticated); 638 EXPECT_CALL(*input_injector_, StartPtr(_)).After(authenticated);
657 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)) 639 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_))
658 .After(authenticated) 640 .After(authenticated)
659 .WillOnce(DoAll( 641 .WillOnce(DoAll(
660 SetGnubbyAuthHandlerForTesting(client_session_.get(), 642 SetGnubbyAuthHandlerForTesting(client_session_.get(),
661 gnubby_auth_handler), 643 gnubby_auth_handler),
662 DeliverClientMessage(client_session_.get(), message), 644 DeliverClientMessage(client_session_.get(), message),
663 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), 645 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession),
664 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); 646 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession)));
665 EXPECT_CALL(*gnubby_auth_handler, DeliverClientMessage(_)); 647 EXPECT_CALL(*gnubby_auth_handler, DeliverClientMessage(_));
666 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); 648 EXPECT_CALL(session_event_handler_, OnSessionClosed(_));
667 649
668 ConnectClientSession(); 650 ConnectClientSession();
669 } 651 }
670 652
671 // Verifies that the client's video pipeline can be reset mid-session. 653 // Verifies that the client's video pipeline can be reset mid-session.
672 TEST_F(ClientSessionTest, ResetVideoPipeline) { 654 TEST_F(ClientSessionTest, ResetVideoPipeline) {
673 CreateClientSession(); 655 CreateClientSession();
674 656
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 767
786 DisconnectClientSession(); 768 DisconnectClientSession();
787 StopClientSession(); 769 StopClientSession();
788 770
789 // ext1 was instantiated and wrapped the video capturer. 771 // ext1 was instantiated and wrapped the video capturer.
790 EXPECT_TRUE(extension.was_instantiated()); 772 EXPECT_TRUE(extension.was_instantiated());
791 EXPECT_TRUE(extension.has_wrapped_video_capturer()); 773 EXPECT_TRUE(extension.has_wrapped_video_capturer());
792 } 774 }
793 775
794 } // namespace remoting 776 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/client/plugin/touch_input_scaler_unittest.cc ('k') | remoting/host/ipc_desktop_environment_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698