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 "remoting/base/constants.h" | 5 #include "remoting/base/constants.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/protocol/protocol_mock_objects.h" | 8 #include "remoting/protocol/protocol_mock_objects.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
11 namespace remoting { | 11 namespace remoting { |
12 | 12 |
| 13 using protocol::MockClipboardStub; |
13 using protocol::MockConnectionToClient; | 14 using protocol::MockConnectionToClient; |
14 using protocol::MockConnectionToClientEventHandler; | 15 using protocol::MockConnectionToClientEventHandler; |
15 using protocol::MockHostStub; | 16 using protocol::MockHostStub; |
16 using protocol::MockHostEventStub; | 17 using protocol::MockInputStub; |
17 using protocol::MockSession; | 18 using protocol::MockSession; |
18 | 19 |
19 using testing::_; | 20 using testing::_; |
20 using testing::DeleteArg; | 21 using testing::DeleteArg; |
21 using testing::InSequence; | 22 using testing::InSequence; |
22 using testing::Return; | 23 using testing::Return; |
23 using testing::ReturnRef; | 24 using testing::ReturnRef; |
24 | 25 |
25 class ClientSessionTest : public testing::Test { | 26 class ClientSessionTest : public testing::Test { |
26 public: | 27 public: |
27 ClientSessionTest() {} | 28 ClientSessionTest() {} |
28 | 29 |
29 virtual void SetUp() OVERRIDE { | 30 virtual void SetUp() OVERRIDE { |
30 client_jid_ = "user@domain/rest-of-jid"; | 31 client_jid_ = "user@domain/rest-of-jid"; |
31 | 32 |
32 // Set up a large default screen size that won't affect most tests. | 33 // Set up a large default screen size that won't affect most tests. |
33 default_screen_size_.set(1000, 1000); | 34 default_screen_size_.set(1000, 1000); |
34 EXPECT_CALL(capturer_, size_most_recent()) | 35 EXPECT_CALL(capturer_, size_most_recent()) |
35 .WillRepeatedly(ReturnRef(default_screen_size_)); | 36 .WillRepeatedly(ReturnRef(default_screen_size_)); |
36 | 37 |
37 protocol::MockSession* session = new MockSession(); | 38 protocol::MockSession* session = new MockSession(); |
38 EXPECT_CALL(*session, jid()).WillRepeatedly(ReturnRef(client_jid_)); | 39 EXPECT_CALL(*session, jid()).WillRepeatedly(ReturnRef(client_jid_)); |
39 EXPECT_CALL(*session, SetEventHandler(_)); | 40 EXPECT_CALL(*session, SetEventHandler(_)); |
40 EXPECT_CALL(*session, Close()); | 41 EXPECT_CALL(*session, Close()); |
41 scoped_ptr<protocol::ConnectionToClient> connection( | 42 scoped_ptr<protocol::ConnectionToClient> connection( |
42 new protocol::ConnectionToClient(session)); | 43 new protocol::ConnectionToClient(session)); |
43 client_session_.reset(new ClientSession( | 44 client_session_.reset(new ClientSession( |
44 &session_event_handler_, connection.Pass(), | 45 &session_event_handler_, connection.Pass(), |
45 &host_event_stub_, &capturer_, base::TimeDelta())); | 46 &host_clipboard_stub_, &host_input_stub_, &capturer_, |
| 47 base::TimeDelta())); |
46 } | 48 } |
47 | 49 |
48 virtual void TearDown() OVERRIDE { | 50 virtual void TearDown() OVERRIDE { |
49 client_session_.reset(); | 51 client_session_.reset(); |
50 // Run message loop before destroying because protocol::Session is | 52 // Run message loop before destroying because protocol::Session is |
51 // destroyed asynchronously. | 53 // destroyed asynchronously. |
52 message_loop_.RunAllPending(); | 54 message_loop_.RunAllPending(); |
53 } | 55 } |
54 | 56 |
55 protected: | 57 protected: |
56 void DisconnectClientSession() { | 58 void DisconnectClientSession() { |
57 client_session_->Disconnect(); | 59 client_session_->Disconnect(); |
58 // MockSession won't trigger OnConnectionClosed, so fake it. | 60 // MockSession won't trigger OnConnectionClosed, so fake it. |
59 client_session_->OnConnectionClosed(client_session_->connection(), | 61 client_session_->OnConnectionClosed(client_session_->connection(), |
60 protocol::OK); | 62 protocol::OK); |
61 } | 63 } |
62 | 64 |
63 SkISize default_screen_size_; | 65 SkISize default_screen_size_; |
64 MessageLoop message_loop_; | 66 MessageLoop message_loop_; |
65 std::string client_jid_; | 67 std::string client_jid_; |
66 MockHostStub host_stub_; | 68 MockHostStub host_stub_; |
67 MockHostEventStub host_event_stub_; | 69 MockClipboardStub host_clipboard_stub_; |
| 70 MockInputStub host_input_stub_; |
68 MockVideoFrameCapturer capturer_; | 71 MockVideoFrameCapturer capturer_; |
69 MockClientSessionEventHandler session_event_handler_; | 72 MockClientSessionEventHandler session_event_handler_; |
70 scoped_ptr<ClientSession> client_session_; | 73 scoped_ptr<ClientSession> client_session_; |
71 }; | 74 }; |
72 | 75 |
73 MATCHER_P2(EqualsClipboardEvent, m, d, "") { | 76 MATCHER_P2(EqualsClipboardEvent, m, d, "") { |
74 return (strcmp(arg.mime_type().c_str(), m) == 0 && | 77 return (strcmp(arg.mime_type().c_str(), m) == 0 && |
75 memcmp(arg.data().data(), d, arg.data().size()) == 0); | 78 memcmp(arg.data().data(), d, arg.data().size()) == 0); |
76 } | 79 } |
77 | 80 |
78 TEST_F(ClientSessionTest, ClipboardStubFilter) { | 81 TEST_F(ClientSessionTest, ClipboardStubFilter) { |
79 protocol::ClipboardEvent clipboard_event1; | 82 protocol::ClipboardEvent clipboard_event1; |
80 clipboard_event1.set_mime_type(kMimeTypeTextUtf8); | 83 clipboard_event1.set_mime_type(kMimeTypeTextUtf8); |
81 clipboard_event1.set_data("a"); | 84 clipboard_event1.set_data("a"); |
82 | 85 |
83 protocol::ClipboardEvent clipboard_event2; | 86 protocol::ClipboardEvent clipboard_event2; |
84 clipboard_event2.set_mime_type(kMimeTypeTextUtf8); | 87 clipboard_event2.set_mime_type(kMimeTypeTextUtf8); |
85 clipboard_event2.set_data("b"); | 88 clipboard_event2.set_data("b"); |
86 | 89 |
87 protocol::ClipboardEvent clipboard_event3; | 90 protocol::ClipboardEvent clipboard_event3; |
88 clipboard_event3.set_mime_type(kMimeTypeTextUtf8); | 91 clipboard_event3.set_mime_type(kMimeTypeTextUtf8); |
89 clipboard_event3.set_data("c"); | 92 clipboard_event3.set_data("c"); |
90 | 93 |
91 InSequence s; | 94 InSequence s; |
92 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); | 95 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); |
93 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); | 96 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); |
94 EXPECT_CALL(host_event_stub_, InjectClipboardEvent(EqualsClipboardEvent( | 97 EXPECT_CALL(host_clipboard_stub_, InjectClipboardEvent(EqualsClipboardEvent( |
95 kMimeTypeTextUtf8, "b"))); | 98 kMimeTypeTextUtf8, "b"))); |
96 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); | 99 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); |
97 | 100 |
98 // This event should not get through to the clipboard stub, | 101 // This event should not get through to the clipboard stub, |
99 // because the client isn't authenticated yet. | 102 // because the client isn't authenticated yet. |
100 client_session_->InjectClipboardEvent(clipboard_event1); | 103 client_session_->InjectClipboardEvent(clipboard_event1); |
101 client_session_->OnConnectionAuthenticated(client_session_->connection()); | 104 client_session_->OnConnectionAuthenticated(client_session_->connection()); |
102 client_session_->OnConnectionChannelsConnected(client_session_->connection()); | 105 client_session_->OnConnectionChannelsConnected(client_session_->connection()); |
103 // This event should get through to the clipboard stub. | 106 // This event should get through to the clipboard stub. |
104 client_session_->InjectClipboardEvent(clipboard_event2); | 107 client_session_->InjectClipboardEvent(clipboard_event2); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 mouse_event2.set_x(200); | 148 mouse_event2.set_x(200); |
146 mouse_event2.set_y(201); | 149 mouse_event2.set_y(201); |
147 | 150 |
148 protocol::MouseEvent mouse_event3; | 151 protocol::MouseEvent mouse_event3; |
149 mouse_event3.set_x(300); | 152 mouse_event3.set_x(300); |
150 mouse_event3.set_y(301); | 153 mouse_event3.set_y(301); |
151 | 154 |
152 InSequence s; | 155 InSequence s; |
153 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); | 156 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); |
154 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); | 157 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); |
155 EXPECT_CALL(host_event_stub_, InjectKeyEvent(EqualsKeyEvent(2, true))); | 158 EXPECT_CALL(host_input_stub_, InjectKeyEvent(EqualsKeyEvent(2, true))); |
156 EXPECT_CALL(host_event_stub_, InjectKeyEvent(EqualsKeyEvent(2, false))); | 159 EXPECT_CALL(host_input_stub_, InjectKeyEvent(EqualsKeyEvent(2, false))); |
157 EXPECT_CALL(host_event_stub_, InjectMouseEvent(EqualsMouseEvent(200, 201))); | 160 EXPECT_CALL(host_input_stub_, InjectMouseEvent(EqualsMouseEvent(200, 201))); |
158 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); | 161 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); |
159 | 162 |
160 // These events should not get through to the input stub, | 163 // These events should not get through to the input stub, |
161 // because the client isn't authenticated yet. | 164 // because the client isn't authenticated yet. |
162 client_session_->InjectKeyEvent(key_event1); | 165 client_session_->InjectKeyEvent(key_event1); |
163 client_session_->InjectMouseEvent(mouse_event1); | 166 client_session_->InjectMouseEvent(mouse_event1); |
164 client_session_->OnConnectionAuthenticated(client_session_->connection()); | 167 client_session_->OnConnectionAuthenticated(client_session_->connection()); |
165 client_session_->OnConnectionChannelsConnected(client_session_->connection()); | 168 client_session_->OnConnectionChannelsConnected(client_session_->connection()); |
166 // These events should get through to the input stub. | 169 // These events should get through to the input stub. |
167 client_session_->InjectKeyEvent(key_event2_down); | 170 client_session_->InjectKeyEvent(key_event2_down); |
(...skipping 13 matching lines...) Expand all Loading... |
181 protocol::MouseEvent mouse_event2; | 184 protocol::MouseEvent mouse_event2; |
182 mouse_event2.set_x(200); | 185 mouse_event2.set_x(200); |
183 mouse_event2.set_y(201); | 186 mouse_event2.set_y(201); |
184 protocol::MouseEvent mouse_event3; | 187 protocol::MouseEvent mouse_event3; |
185 mouse_event3.set_x(300); | 188 mouse_event3.set_x(300); |
186 mouse_event3.set_y(301); | 189 mouse_event3.set_y(301); |
187 | 190 |
188 InSequence s; | 191 InSequence s; |
189 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); | 192 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); |
190 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); | 193 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); |
191 EXPECT_CALL(host_event_stub_, InjectMouseEvent(EqualsMouseEvent(100, 101))); | 194 EXPECT_CALL(host_input_stub_, InjectMouseEvent(EqualsMouseEvent(100, 101))); |
192 EXPECT_CALL(host_event_stub_, InjectMouseEvent(EqualsMouseEvent(200, 201))); | 195 EXPECT_CALL(host_input_stub_, InjectMouseEvent(EqualsMouseEvent(200, 201))); |
193 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); | 196 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); |
194 | 197 |
195 client_session_->OnConnectionAuthenticated(client_session_->connection()); | 198 client_session_->OnConnectionAuthenticated(client_session_->connection()); |
196 client_session_->OnConnectionChannelsConnected(client_session_->connection()); | 199 client_session_->OnConnectionChannelsConnected(client_session_->connection()); |
197 // This event should get through to the input stub. | 200 // This event should get through to the input stub. |
198 client_session_->InjectMouseEvent(mouse_event1); | 201 client_session_->InjectMouseEvent(mouse_event1); |
199 // This one should too because the local event echoes the remote one. | 202 // This one should too because the local event echoes the remote one. |
200 client_session_->LocalMouseMoved(SkIPoint::Make(mouse_event1.x(), | 203 client_session_->LocalMouseMoved(SkIPoint::Make(mouse_event1.x(), |
201 mouse_event1.y())); | 204 mouse_event1.y())); |
202 client_session_->InjectMouseEvent(mouse_event2); | 205 client_session_->InjectMouseEvent(mouse_event2); |
(...skipping 15 matching lines...) Expand all Loading... |
218 key2.set_pressed(true); | 221 key2.set_pressed(true); |
219 key2.set_keycode(2); | 222 key2.set_keycode(2); |
220 | 223 |
221 protocol::MouseEvent mousedown; | 224 protocol::MouseEvent mousedown; |
222 mousedown.set_button(protocol::MouseEvent::BUTTON_LEFT); | 225 mousedown.set_button(protocol::MouseEvent::BUTTON_LEFT); |
223 mousedown.set_button_down(true); | 226 mousedown.set_button_down(true); |
224 | 227 |
225 InSequence s; | 228 InSequence s; |
226 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); | 229 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); |
227 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); | 230 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); |
228 EXPECT_CALL(host_event_stub_, InjectKeyEvent(EqualsKeyEvent(1, true))); | 231 EXPECT_CALL(host_input_stub_, InjectKeyEvent(EqualsKeyEvent(1, true))); |
229 EXPECT_CALL(host_event_stub_, InjectKeyEvent(EqualsKeyEvent(2, true))); | 232 EXPECT_CALL(host_input_stub_, InjectKeyEvent(EqualsKeyEvent(2, true))); |
230 EXPECT_CALL(host_event_stub_, InjectMouseEvent(EqualsMouseButtonEvent( | 233 EXPECT_CALL(host_input_stub_, InjectMouseEvent(EqualsMouseButtonEvent( |
231 protocol::MouseEvent::BUTTON_LEFT, true))); | 234 protocol::MouseEvent::BUTTON_LEFT, true))); |
232 EXPECT_CALL(host_event_stub_, InjectKeyEvent(EqualsKeyEvent(1, false))); | 235 EXPECT_CALL(host_input_stub_, InjectKeyEvent(EqualsKeyEvent(1, false))); |
233 EXPECT_CALL(host_event_stub_, InjectKeyEvent(EqualsKeyEvent(2, false))); | 236 EXPECT_CALL(host_input_stub_, InjectKeyEvent(EqualsKeyEvent(2, false))); |
234 EXPECT_CALL(host_event_stub_, InjectMouseEvent(EqualsMouseButtonEvent( | 237 EXPECT_CALL(host_input_stub_, InjectMouseEvent(EqualsMouseButtonEvent( |
235 protocol::MouseEvent::BUTTON_LEFT, false))); | 238 protocol::MouseEvent::BUTTON_LEFT, false))); |
236 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); | 239 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); |
237 | 240 |
238 client_session_->OnConnectionAuthenticated(client_session_->connection()); | 241 client_session_->OnConnectionAuthenticated(client_session_->connection()); |
239 client_session_->OnConnectionChannelsConnected(client_session_->connection()); | 242 client_session_->OnConnectionChannelsConnected(client_session_->connection()); |
240 | 243 |
241 client_session_->InjectKeyEvent(key1); | 244 client_session_->InjectKeyEvent(key1); |
242 client_session_->InjectKeyEvent(key2); | 245 client_session_->InjectKeyEvent(key2); |
243 client_session_->InjectMouseEvent(mousedown); | 246 client_session_->InjectMouseEvent(mousedown); |
244 | 247 |
(...skipping 15 matching lines...) Expand all Loading... |
260 int input_x[3] = { -999, 100, 999 }; | 263 int input_x[3] = { -999, 100, 999 }; |
261 int expected_x[3] = { 0, 100, 199 }; | 264 int expected_x[3] = { 0, 100, 199 }; |
262 int input_y[3] = { -999, 50, 999 }; | 265 int input_y[3] = { -999, 50, 999 }; |
263 int expected_y[3] = { 0, 50, 99 }; | 266 int expected_y[3] = { 0, 50, 99 }; |
264 | 267 |
265 protocol::MouseEvent event; | 268 protocol::MouseEvent event; |
266 for (int j = 0; j < 3; j++) { | 269 for (int j = 0; j < 3; j++) { |
267 for (int i = 0; i < 3; i++) { | 270 for (int i = 0; i < 3; i++) { |
268 event.set_x(input_x[i]); | 271 event.set_x(input_x[i]); |
269 event.set_y(input_y[j]); | 272 event.set_y(input_y[j]); |
270 EXPECT_CALL(host_event_stub_, InjectMouseEvent(EqualsMouseEvent( | 273 EXPECT_CALL(host_input_stub_, InjectMouseEvent(EqualsMouseEvent( |
271 expected_x[i], expected_y[j]))); | 274 expected_x[i], expected_y[j]))); |
272 client_session_->InjectMouseEvent(event); | 275 client_session_->InjectMouseEvent(event); |
273 } | 276 } |
274 } | 277 } |
275 | 278 |
276 DisconnectClientSession(); | 279 DisconnectClientSession(); |
277 } | 280 } |
278 | 281 |
279 } // namespace remoting | 282 } // namespace remoting |
OLD | NEW |