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