Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 | 303 |
| 304 webrtc::DesktopCapturer* ClientSessionTest::CreateVideoCapturer() { | 304 webrtc::DesktopCapturer* ClientSessionTest::CreateVideoCapturer() { |
| 305 return new FakeDesktopCapturer(); | 305 return new FakeDesktopCapturer(); |
| 306 } | 306 } |
| 307 | 307 |
| 308 webrtc::MouseCursorMonitor* ClientSessionTest::CreateMouseCursorMonitor() { | 308 webrtc::MouseCursorMonitor* ClientSessionTest::CreateMouseCursorMonitor() { |
| 309 return new FakeMouseCursorMonitor(); | 309 return new FakeMouseCursorMonitor(); |
| 310 } | 310 } |
| 311 | 311 |
| 312 void ClientSessionTest::ConnectClientSession() { | 312 void ClientSessionTest::ConnectClientSession() { |
| 313 // Stubs should be set only after connection is authenticated. | |
| 314 EXPECT_FALSE(connection_->clipboard_stub()); | |
| 315 EXPECT_FALSE(connection_->input_stub()); | |
| 316 | |
| 313 client_session_->OnConnectionAuthenticated(client_session_->connection()); | 317 client_session_->OnConnectionAuthenticated(client_session_->connection()); |
| 318 | |
| 319 EXPECT_TRUE(connection_->clipboard_stub()); | |
| 320 EXPECT_TRUE(connection_->input_stub()); | |
| 321 | |
| 314 client_session_->OnConnectionChannelsConnected(client_session_->connection()); | 322 client_session_->OnConnectionChannelsConnected(client_session_->connection()); |
| 315 } | 323 } |
| 316 | 324 |
| 317 void ClientSessionTest::SetMatchCapabilitiesExpectation() { | 325 void ClientSessionTest::SetMatchCapabilitiesExpectation() { |
| 318 // Set the client to report the same capabilities as the host. | 326 // Set the client to report the same capabilities as the host. |
| 319 EXPECT_CALL(client_stub_, SetCapabilities(_)) | 327 EXPECT_CALL(client_stub_, SetCapabilities(_)) |
| 320 .Times(AtMost(1)) | 328 .Times(AtMost(1)) |
| 321 .WillOnce(Invoke(client_session_.get(), &ClientSession::SetCapabilities)); | 329 .WillOnce(Invoke(client_session_.get(), &ClientSession::SetCapabilities)); |
| 322 } | 330 } |
| 323 | 331 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 336 DeliverClientMessage(client_session_.get(), message), | 344 DeliverClientMessage(client_session_.get(), message), |
| 337 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), | 345 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), |
| 338 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); | 346 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); |
| 339 } | 347 } |
| 340 | 348 |
| 341 MATCHER_P2(EqualsClipboardEvent, m, d, "") { | 349 MATCHER_P2(EqualsClipboardEvent, m, d, "") { |
| 342 return (strcmp(arg.mime_type().c_str(), m) == 0 && | 350 return (strcmp(arg.mime_type().c_str(), m) == 0 && |
| 343 memcmp(arg.data().data(), d, arg.data().size()) == 0); | 351 memcmp(arg.data().data(), d, arg.data().size()) == 0); |
| 344 } | 352 } |
| 345 | 353 |
| 346 TEST_F(ClientSessionTest, ClipboardStubFilter) { | |
|
Wez
2015/02/07 00:40:43
We should have some disable-inputs tests - perhaps
Sergey Ulanov
2015/02/13 19:40:21
Done.
| |
| 347 CreateClientSession(); | |
| 348 | |
| 349 protocol::ClipboardEvent clipboard_event1; | |
| 350 clipboard_event1.set_mime_type(kMimeTypeTextUtf8); | |
| 351 clipboard_event1.set_data("a"); | |
| 352 | |
| 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 | |
| 369 // 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 | |
| 371 // by the mouse clamping filter. | |
| 372 Sequence s; | |
| 373 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) | |
| 374 .InSequence(s) | |
| 375 .After(authenticated) | |
| 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 | |
| 390 // This event should not get through to the clipboard stub, | |
| 391 // because the client isn't authenticated yet. | |
| 392 connection_->clipboard_stub()->InjectClipboardEvent(clipboard_event1); | |
| 393 | |
| 394 ConnectClientSession(); | |
| 395 } | |
| 396 | |
| 397 TEST_F(ClientSessionTest, InputStubFilter) { | |
| 398 CreateClientSession(); | |
| 399 | |
| 400 protocol::KeyEvent key_event1; | |
| 401 key_event1.set_pressed(true); | |
| 402 key_event1.set_usb_keycode(1); | |
| 403 | |
| 404 protocol::KeyEvent key_event2_down; | |
| 405 key_event2_down.set_pressed(true); | |
| 406 key_event2_down.set_usb_keycode(2); | |
| 407 | |
| 408 protocol::KeyEvent key_event2_up; | |
| 409 key_event2_up.set_pressed(false); | |
| 410 key_event2_up.set_usb_keycode(2); | |
| 411 | |
| 412 protocol::KeyEvent key_event3; | |
| 413 key_event3.set_pressed(true); | |
| 414 key_event3.set_usb_keycode(3); | |
| 415 | |
| 416 protocol::MouseEvent mouse_event1; | |
| 417 mouse_event1.set_x(100); | |
| 418 mouse_event1.set_y(101); | |
| 419 | |
| 420 protocol::MouseEvent mouse_event2; | |
| 421 mouse_event2.set_x(200); | |
| 422 mouse_event2.set_y(201); | |
| 423 | |
| 424 protocol::MouseEvent mouse_event3; | |
| 425 mouse_event3.set_x(300); | |
| 426 mouse_event3.set_y(301); | |
| 427 | |
| 428 Expectation authenticated = | |
| 429 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)) | |
| 430 .WillOnce(Return(true)); | |
| 431 EXPECT_CALL(*input_injector_, StartPtr(_)) | |
| 432 .After(authenticated); | |
| 433 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)) | |
| 434 .After(authenticated); | |
| 435 | |
| 436 // Wait for the first video packet to be captured to make sure that | |
| 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 | |
| 463 // These events should not get through to the input stub, | |
| 464 // because the client isn't authenticated yet. | |
| 465 connection_->input_stub()->InjectKeyEvent(key_event1); | |
| 466 connection_->input_stub()->InjectMouseEvent(mouse_event1); | |
| 467 | |
| 468 ConnectClientSession(); | |
| 469 } | |
| 470 | |
| 471 TEST_F(ClientSessionTest, LocalInputTest) { | 354 TEST_F(ClientSessionTest, LocalInputTest) { |
| 472 CreateClientSession(); | 355 CreateClientSession(); |
| 473 | 356 |
| 474 protocol::MouseEvent mouse_event1; | 357 protocol::MouseEvent mouse_event1; |
| 475 mouse_event1.set_x(100); | 358 mouse_event1.set_x(100); |
| 476 mouse_event1.set_y(101); | 359 mouse_event1.set_y(101); |
| 477 protocol::MouseEvent mouse_event2; | 360 protocol::MouseEvent mouse_event2; |
| 478 mouse_event2.set_x(200); | 361 mouse_event2.set_x(200); |
| 479 mouse_event2.set_y(201); | 362 mouse_event2.set_y(201); |
| 480 protocol::MouseEvent mouse_event3; | 363 protocol::MouseEvent mouse_event3; |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 808 | 691 |
| 809 DisconnectClientSession(); | 692 DisconnectClientSession(); |
| 810 StopClientSession(); | 693 StopClientSession(); |
| 811 | 694 |
| 812 // ext1 was instantiated and wrapped the video capturer. | 695 // ext1 was instantiated and wrapped the video capturer. |
| 813 EXPECT_TRUE(extension.was_instantiated()); | 696 EXPECT_TRUE(extension.was_instantiated()); |
| 814 EXPECT_TRUE(extension.has_wrapped_video_capturer()); | 697 EXPECT_TRUE(extension.has_wrapped_video_capturer()); |
| 815 } | 698 } |
| 816 | 699 |
| 817 } // namespace remoting | 700 } // namespace remoting |
| OLD | NEW |