OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/bind.h" |
| 6 #include "remoting/host/client_session.h" |
| 7 #include "remoting/host/host_mock_objects.h" |
| 8 #include "remoting/host/user_authenticator_fake.h" |
| 9 #include "remoting/protocol/protocol_mock_objects.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 namespace remoting { |
| 13 |
| 14 namespace { |
| 15 |
| 16 UserAuthenticator* MakeUserAuthenticator() { |
| 17 return new UserAuthenticatorFake(); |
| 18 } |
| 19 |
| 20 // A task that does nothing. |
| 21 class DummyTask : public Task { |
| 22 public: |
| 23 void Run() {} |
| 24 }; |
| 25 |
| 26 } // namespace |
| 27 |
| 28 using protocol::MockConnectionToClient; |
| 29 using protocol::MockConnectionToClientEventHandler; |
| 30 using protocol::MockHostStub; |
| 31 using protocol::MockInputStub; |
| 32 |
| 33 using testing::_; |
| 34 using testing::InSequence; |
| 35 |
| 36 class ClientSessionTest : public testing::Test { |
| 37 public: |
| 38 ClientSessionTest() { |
| 39 } |
| 40 |
| 41 virtual void SetUp() { |
| 42 connection_ = new MockConnectionToClient(&message_loop_, |
| 43 &connection_event_handler_, |
| 44 &host_stub_, |
| 45 &input_stub_); |
| 46 client_session_ = new ClientSession(&session_event_handler_, |
| 47 base::Bind(MakeUserAuthenticator), |
| 48 connection_, |
| 49 &input_stub_); |
| 50 credentials_.set_type(protocol::PASSWORD); |
| 51 credentials_.set_username("user"); |
| 52 credentials_.set_credential("password"); |
| 53 } |
| 54 |
| 55 virtual void TearDown() { |
| 56 } |
| 57 |
| 58 protected: |
| 59 MessageLoop message_loop_; |
| 60 MockConnectionToClientEventHandler connection_event_handler_; |
| 61 MockHostStub host_stub_; |
| 62 MockInputStub input_stub_; |
| 63 MockClientSessionEventHandler session_event_handler_; |
| 64 scoped_refptr<MockConnectionToClient> connection_; |
| 65 scoped_refptr<ClientSession> client_session_; |
| 66 protocol::LocalLoginCredentials credentials_; |
| 67 }; |
| 68 |
| 69 TEST_F(ClientSessionTest, InputStubFilter) { |
| 70 protocol::KeyEvent key_event1; |
| 71 key_event1.set_pressed(true); |
| 72 key_event1.set_keycode(1); |
| 73 |
| 74 protocol::KeyEvent key_event2; |
| 75 key_event2.set_pressed(true); |
| 76 key_event2.set_keycode(2); |
| 77 |
| 78 protocol::KeyEvent key_event3; |
| 79 key_event3.set_pressed(true); |
| 80 key_event3.set_keycode(3); |
| 81 |
| 82 protocol::MouseEvent mouse_event1; |
| 83 mouse_event1.set_x(100); |
| 84 mouse_event1.set_y(101); |
| 85 |
| 86 protocol::MouseEvent mouse_event2; |
| 87 mouse_event2.set_x(200); |
| 88 mouse_event2.set_y(201); |
| 89 |
| 90 protocol::MouseEvent mouse_event3; |
| 91 mouse_event3.set_x(300); |
| 92 mouse_event3.set_y(301); |
| 93 |
| 94 credentials_.set_type(protocol::PASSWORD); |
| 95 credentials_.set_username("user"); |
| 96 credentials_.set_credential("password"); |
| 97 |
| 98 InSequence s; |
| 99 EXPECT_CALL(session_event_handler_, LocalLoginSucceeded(_)); |
| 100 EXPECT_CALL(input_stub_, InjectKeyEvent(&key_event2, _)); |
| 101 EXPECT_CALL(input_stub_, InjectMouseEvent(&mouse_event2, _)); |
| 102 EXPECT_CALL(*connection_.get(), Disconnect()); |
| 103 |
| 104 // These events should not get through to the input stub, |
| 105 // because the client isn't authenticated yet. |
| 106 client_session_->InjectKeyEvent(&key_event1, new DummyTask()); |
| 107 client_session_->InjectMouseEvent(&mouse_event1, new DummyTask()); |
| 108 client_session_->BeginSessionRequest(&credentials_, new DummyTask()); |
| 109 // These events should get through to the input stub. |
| 110 client_session_->InjectKeyEvent(&key_event2, new DummyTask()); |
| 111 client_session_->InjectMouseEvent(&mouse_event2, new DummyTask()); |
| 112 client_session_->Disconnect(); |
| 113 // These events should not get through to the input stub, |
| 114 // because the client has disconnected. |
| 115 client_session_->InjectKeyEvent(&key_event3, new DummyTask()); |
| 116 client_session_->InjectMouseEvent(&mouse_event3, new DummyTask()); |
| 117 } |
| 118 |
| 119 } // namespace remoting |
OLD | NEW |