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 "remoting/host/client_session.h" | 5 #include "remoting/host/client_session.h" |
6 #include "remoting/host/host_mock_objects.h" | 6 #include "remoting/host/host_mock_objects.h" |
7 #include "remoting/protocol/protocol_mock_objects.h" | 7 #include "remoting/protocol/protocol_mock_objects.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace remoting { | 10 namespace remoting { |
(...skipping 18 matching lines...) Expand all Loading... |
29 client_jid_ = "user@domain/rest-of-jid"; | 29 client_jid_ = "user@domain/rest-of-jid"; |
30 EXPECT_CALL(session_, jid()).WillRepeatedly(ReturnRef(client_jid_)); | 30 EXPECT_CALL(session_, jid()).WillRepeatedly(ReturnRef(client_jid_)); |
31 | 31 |
32 connection_ = new MockConnectionToClient( | 32 connection_ = new MockConnectionToClient( |
33 &connection_event_handler_, &host_stub_, &input_stub_); | 33 &connection_event_handler_, &host_stub_, &input_stub_); |
34 | 34 |
35 EXPECT_CALL(*connection_, session()).WillRepeatedly(Return(&session_)); | 35 EXPECT_CALL(*connection_, session()).WillRepeatedly(Return(&session_)); |
36 | 36 |
37 // Set up a large default screen size that won't affect most tests. | 37 // Set up a large default screen size that won't affect most tests. |
38 default_screen_size_.set(1000, 1000); | 38 default_screen_size_.set(1000, 1000); |
39 ON_CALL(capturer_, size_most_recent()).WillByDefault(ReturnRef( | 39 EXPECT_CALL(capturer_, size_most_recent()) |
40 default_screen_size_)); | 40 .WillRepeatedly(ReturnRef(default_screen_size_)); |
41 | 41 |
42 user_authenticator_ = new MockUserAuthenticator(); | 42 user_authenticator_ = new MockUserAuthenticator(); |
43 client_session_ = new ClientSession( | 43 client_session_ = new ClientSession( |
44 &session_event_handler_, | 44 &session_event_handler_, |
45 user_authenticator_, | |
46 connection_, | 45 connection_, |
47 &input_stub_, | 46 &input_stub_, |
48 &capturer_); | 47 &capturer_); |
49 } | 48 } |
50 | 49 |
51 protected: | 50 protected: |
52 SkISize default_screen_size_; | 51 SkISize default_screen_size_; |
53 MessageLoop message_loop_; | 52 MessageLoop message_loop_; |
54 std::string client_jid_; | 53 std::string client_jid_; |
55 MockSession session_; | 54 MockSession session_; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 mouse_event1.set_y(101); | 96 mouse_event1.set_y(101); |
98 | 97 |
99 protocol::MouseEvent mouse_event2; | 98 protocol::MouseEvent mouse_event2; |
100 mouse_event2.set_x(200); | 99 mouse_event2.set_x(200); |
101 mouse_event2.set_y(201); | 100 mouse_event2.set_y(201); |
102 | 101 |
103 protocol::MouseEvent mouse_event3; | 102 protocol::MouseEvent mouse_event3; |
104 mouse_event3.set_x(300); | 103 mouse_event3.set_x(300); |
105 mouse_event3.set_y(301); | 104 mouse_event3.set_y(301); |
106 | 105 |
107 protocol::LocalLoginCredentials credentials; | |
108 credentials.set_type(protocol::PASSWORD); | |
109 credentials.set_username("user"); | |
110 credentials.set_credential("password"); | |
111 | |
112 InSequence s; | 106 InSequence s; |
113 EXPECT_CALL(*user_authenticator_, Authenticate(_, _)) | 107 EXPECT_CALL(session_event_handler_, OnAuthenticationComplete(_)); |
114 .WillOnce(Return(true)); | |
115 EXPECT_CALL(session_event_handler_, LocalLoginSucceeded(_)); | |
116 EXPECT_CALL(input_stub_, InjectKeyEvent(EqualsKeyEvent(2, true))); | 108 EXPECT_CALL(input_stub_, InjectKeyEvent(EqualsKeyEvent(2, true))); |
117 EXPECT_CALL(input_stub_, InjectKeyEvent(EqualsKeyEvent(2, false))); | 109 EXPECT_CALL(input_stub_, InjectKeyEvent(EqualsKeyEvent(2, false))); |
118 EXPECT_CALL(input_stub_, InjectMouseEvent(EqualsMouseEvent(200, 201))); | 110 EXPECT_CALL(input_stub_, InjectMouseEvent(EqualsMouseEvent(200, 201))); |
119 | 111 |
120 // These events should not get through to the input stub, | 112 // These events should not get through to the input stub, |
121 // because the client isn't authenticated yet. | 113 // because the client isn't authenticated yet. |
122 client_session_->InjectKeyEvent(key_event1); | 114 client_session_->InjectKeyEvent(key_event1); |
123 client_session_->InjectMouseEvent(mouse_event1); | 115 client_session_->InjectMouseEvent(mouse_event1); |
124 client_session_->BeginSessionRequest(&credentials, base::Closure()); | 116 client_session_->OnAuthenticationComplete(); |
125 // These events should get through to the input stub. | 117 // These events should get through to the input stub. |
126 client_session_->InjectKeyEvent(key_event2_down); | 118 client_session_->InjectKeyEvent(key_event2_down); |
127 client_session_->InjectKeyEvent(key_event2_up); | 119 client_session_->InjectKeyEvent(key_event2_up); |
128 client_session_->InjectMouseEvent(mouse_event2); | 120 client_session_->InjectMouseEvent(mouse_event2); |
129 client_session_->OnDisconnected(); | 121 client_session_->OnDisconnected(); |
130 // These events should not get through to the input stub, | 122 // These events should not get through to the input stub, |
131 // because the client has disconnected. | 123 // because the client has disconnected. |
132 client_session_->InjectKeyEvent(key_event3); | 124 client_session_->InjectKeyEvent(key_event3); |
133 client_session_->InjectMouseEvent(mouse_event3); | 125 client_session_->InjectMouseEvent(mouse_event3); |
134 } | 126 } |
135 | 127 |
136 TEST_F(ClientSessionTest, LocalInputTest) { | 128 TEST_F(ClientSessionTest, LocalInputTest) { |
137 protocol::MouseEvent mouse_event1; | 129 protocol::MouseEvent mouse_event1; |
138 mouse_event1.set_x(100); | 130 mouse_event1.set_x(100); |
139 mouse_event1.set_y(101); | 131 mouse_event1.set_y(101); |
140 protocol::MouseEvent mouse_event2; | 132 protocol::MouseEvent mouse_event2; |
141 mouse_event2.set_x(200); | 133 mouse_event2.set_x(200); |
142 mouse_event2.set_y(201); | 134 mouse_event2.set_y(201); |
143 protocol::MouseEvent mouse_event3; | 135 protocol::MouseEvent mouse_event3; |
144 mouse_event3.set_x(300); | 136 mouse_event3.set_x(300); |
145 mouse_event3.set_y(301); | 137 mouse_event3.set_y(301); |
146 | 138 |
147 protocol::LocalLoginCredentials credentials; | |
148 credentials.set_type(protocol::PASSWORD); | |
149 credentials.set_username("user"); | |
150 credentials.set_credential("password"); | |
151 | |
152 InSequence s; | 139 InSequence s; |
153 EXPECT_CALL(*user_authenticator_, Authenticate(_, _)) | 140 EXPECT_CALL(session_event_handler_, OnAuthenticationComplete(_)); |
154 .WillOnce(Return(true)); | |
155 EXPECT_CALL(session_event_handler_, LocalLoginSucceeded(_)); | |
156 EXPECT_CALL(input_stub_, InjectMouseEvent(EqualsMouseEvent(100, 101))); | 141 EXPECT_CALL(input_stub_, InjectMouseEvent(EqualsMouseEvent(100, 101))); |
157 EXPECT_CALL(input_stub_, InjectMouseEvent(EqualsMouseEvent(200, 201))); | 142 EXPECT_CALL(input_stub_, InjectMouseEvent(EqualsMouseEvent(200, 201))); |
158 | 143 |
159 client_session_->BeginSessionRequest(&credentials, base::Closure()); | 144 client_session_->OnAuthenticationComplete(); |
160 // This event should get through to the input stub. | 145 // This event should get through to the input stub. |
161 client_session_->InjectMouseEvent(mouse_event1); | 146 client_session_->InjectMouseEvent(mouse_event1); |
162 // This one should too because the local event echoes the remote one. | 147 // This one should too because the local event echoes the remote one. |
163 client_session_->LocalMouseMoved(SkIPoint::Make(mouse_event1.x(), | 148 client_session_->LocalMouseMoved(SkIPoint::Make(mouse_event1.x(), |
164 mouse_event1.y())); | 149 mouse_event1.y())); |
165 client_session_->InjectMouseEvent(mouse_event2); | 150 client_session_->InjectMouseEvent(mouse_event2); |
166 // This one should not. | 151 // This one should not. |
167 client_session_->LocalMouseMoved(SkIPoint::Make(mouse_event1.x(), | 152 client_session_->LocalMouseMoved(SkIPoint::Make(mouse_event1.x(), |
168 mouse_event1.y())); | 153 mouse_event1.y())); |
169 client_session_->InjectMouseEvent(mouse_event3); | 154 client_session_->InjectMouseEvent(mouse_event3); |
(...skipping 25 matching lines...) Expand all Loading... |
195 protocol::MouseEvent::BUTTON_LEFT))); | 180 protocol::MouseEvent::BUTTON_LEFT))); |
196 | 181 |
197 client_session_->RestoreEventState(); | 182 client_session_->RestoreEventState(); |
198 } | 183 } |
199 | 184 |
200 TEST_F(ClientSessionTest, ClampMouseEvents) { | 185 TEST_F(ClientSessionTest, ClampMouseEvents) { |
201 SkISize screen(SkISize::Make(200, 100)); | 186 SkISize screen(SkISize::Make(200, 100)); |
202 EXPECT_CALL(capturer_, size_most_recent()) | 187 EXPECT_CALL(capturer_, size_most_recent()) |
203 .WillRepeatedly(ReturnRef(screen)); | 188 .WillRepeatedly(ReturnRef(screen)); |
204 | 189 |
205 protocol::LocalLoginCredentials credentials; | 190 EXPECT_CALL(session_event_handler_, OnAuthenticationComplete(_)); |
206 credentials.set_type(protocol::PASSWORD); | 191 client_session_->OnAuthenticationComplete(); |
207 credentials.set_username("user"); | |
208 credentials.set_credential("password"); | |
209 EXPECT_CALL(*user_authenticator_, Authenticate(_, _)) | |
210 .WillOnce(Return(true)); | |
211 EXPECT_CALL(session_event_handler_, LocalLoginSucceeded(_)); | |
212 client_session_->BeginSessionRequest(&credentials, base::Closure()); | |
213 | 192 |
214 int input_x[3] = { -999, 100, 999 }; | 193 int input_x[3] = { -999, 100, 999 }; |
215 int expected_x[3] = { 0, 100, 199 }; | 194 int expected_x[3] = { 0, 100, 199 }; |
216 int input_y[3] = { -999, 50, 999 }; | 195 int input_y[3] = { -999, 50, 999 }; |
217 int expected_y[3] = { 0, 50, 99 }; | 196 int expected_y[3] = { 0, 50, 99 }; |
218 | 197 |
219 protocol::MouseEvent event; | 198 protocol::MouseEvent event; |
220 for (int j = 0; j < 3; j++) { | 199 for (int j = 0; j < 3; j++) { |
221 for (int i = 0; i < 3; i++) { | 200 for (int i = 0; i < 3; i++) { |
222 event.set_x(input_x[i]); | 201 event.set_x(input_x[i]); |
223 event.set_y(input_y[j]); | 202 event.set_y(input_y[j]); |
224 EXPECT_CALL(input_stub_, InjectMouseEvent(EqualsMouseEvent( | 203 EXPECT_CALL(input_stub_, InjectMouseEvent(EqualsMouseEvent( |
225 expected_x[i], expected_y[j]))); | 204 expected_x[i], expected_y[j]))); |
226 client_session_->InjectMouseEvent(event); | 205 client_session_->InjectMouseEvent(event); |
227 } | 206 } |
228 } | 207 } |
229 } | 208 } |
230 | 209 |
231 } // namespace remoting | 210 } // namespace remoting |
OLD | NEW |