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 "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 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 default_screen_size_.set(1000, 1000); | 34 default_screen_size_.set(1000, 1000); |
| 35 EXPECT_CALL(capturer_, size_most_recent()) | 35 EXPECT_CALL(capturer_, size_most_recent()) |
| 36 .WillRepeatedly(ReturnRef(default_screen_size_)); | 36 .WillRepeatedly(ReturnRef(default_screen_size_)); |
| 37 | 37 |
| 38 protocol::MockSession* session = new MockSession(); | 38 protocol::MockSession* session = new MockSession(); |
| 39 EXPECT_CALL(*session, jid()).WillRepeatedly(ReturnRef(client_jid_)); | 39 EXPECT_CALL(*session, jid()).WillRepeatedly(ReturnRef(client_jid_)); |
| 40 EXPECT_CALL(*session, SetEventHandler(_)); | 40 EXPECT_CALL(*session, SetEventHandler(_)); |
| 41 EXPECT_CALL(*session, Close()); | 41 EXPECT_CALL(*session, Close()); |
| 42 scoped_ptr<protocol::ConnectionToClient> connection( | 42 scoped_ptr<protocol::ConnectionToClient> connection( |
| 43 new protocol::ConnectionToClient(session)); | 43 new protocol::ConnectionToClient(session)); |
| 44 connection_ = connection.get(); | |
| 44 client_session_.reset(new ClientSession( | 45 client_session_.reset(new ClientSession( |
| 45 &session_event_handler_, connection.Pass(), | 46 &session_event_handler_, connection.Pass(), |
| 46 &host_clipboard_stub_, &host_input_stub_, &capturer_, | 47 &host_clipboard_stub_, &host_input_stub_, &capturer_, |
| 47 base::TimeDelta())); | 48 base::TimeDelta())); |
| 48 } | 49 } |
| 49 | 50 |
| 50 virtual void TearDown() OVERRIDE { | 51 virtual void TearDown() OVERRIDE { |
| 51 client_session_.reset(); | 52 client_session_.reset(); |
| 52 // Run message loop before destroying because protocol::Session is | 53 // Run message loop before destroying because protocol::Session is |
| 53 // destroyed asynchronously. | 54 // destroyed asynchronously. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 64 | 65 |
| 65 SkISize default_screen_size_; | 66 SkISize default_screen_size_; |
| 66 MessageLoop message_loop_; | 67 MessageLoop message_loop_; |
| 67 std::string client_jid_; | 68 std::string client_jid_; |
| 68 MockHostStub host_stub_; | 69 MockHostStub host_stub_; |
| 69 MockClipboardStub host_clipboard_stub_; | 70 MockClipboardStub host_clipboard_stub_; |
| 70 MockInputStub host_input_stub_; | 71 MockInputStub host_input_stub_; |
| 71 MockVideoFrameCapturer capturer_; | 72 MockVideoFrameCapturer capturer_; |
| 72 MockClientSessionEventHandler session_event_handler_; | 73 MockClientSessionEventHandler session_event_handler_; |
| 73 scoped_ptr<ClientSession> client_session_; | 74 scoped_ptr<ClientSession> client_session_; |
| 75 | |
| 76 // ClientSession owns |connection_| but tests it to inject events. | |
|
simonmorris
2012/08/16 01:02:42
"uses it to inject test events"? Or something else
Wez
2012/08/18 00:26:58
Done.
| |
| 77 protocol::ConnectionToClient* connection_; | |
| 74 }; | 78 }; |
| 75 | 79 |
| 76 MATCHER_P2(EqualsClipboardEvent, m, d, "") { | 80 MATCHER_P2(EqualsClipboardEvent, m, d, "") { |
| 77 return (strcmp(arg.mime_type().c_str(), m) == 0 && | 81 return (strcmp(arg.mime_type().c_str(), m) == 0 && |
| 78 memcmp(arg.data().data(), d, arg.data().size()) == 0); | 82 memcmp(arg.data().data(), d, arg.data().size()) == 0); |
| 79 } | 83 } |
| 80 | 84 |
| 81 TEST_F(ClientSessionTest, ClipboardStubFilter) { | 85 TEST_F(ClientSessionTest, ClipboardStubFilter) { |
| 82 protocol::ClipboardEvent clipboard_event1; | 86 protocol::ClipboardEvent clipboard_event1; |
| 83 clipboard_event1.set_mime_type(kMimeTypeTextUtf8); | 87 clipboard_event1.set_mime_type(kMimeTypeTextUtf8); |
| 84 clipboard_event1.set_data("a"); | 88 clipboard_event1.set_data("a"); |
| 85 | 89 |
| 86 protocol::ClipboardEvent clipboard_event2; | 90 protocol::ClipboardEvent clipboard_event2; |
| 87 clipboard_event2.set_mime_type(kMimeTypeTextUtf8); | 91 clipboard_event2.set_mime_type(kMimeTypeTextUtf8); |
| 88 clipboard_event2.set_data("b"); | 92 clipboard_event2.set_data("b"); |
| 89 | 93 |
| 90 protocol::ClipboardEvent clipboard_event3; | 94 protocol::ClipboardEvent clipboard_event3; |
| 91 clipboard_event3.set_mime_type(kMimeTypeTextUtf8); | 95 clipboard_event3.set_mime_type(kMimeTypeTextUtf8); |
| 92 clipboard_event3.set_data("c"); | 96 clipboard_event3.set_data("c"); |
| 93 | 97 |
| 94 InSequence s; | 98 InSequence s; |
| 95 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); | 99 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); |
| 96 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); | 100 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); |
| 97 EXPECT_CALL(host_clipboard_stub_, InjectClipboardEvent(EqualsClipboardEvent( | 101 EXPECT_CALL(host_clipboard_stub_, InjectClipboardEvent(EqualsClipboardEvent( |
| 98 kMimeTypeTextUtf8, "b"))); | 102 kMimeTypeTextUtf8, "b"))); |
| 99 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); | 103 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); |
| 100 | 104 |
| 101 // This event should not get through to the clipboard stub, | 105 // This event should not get through to the clipboard stub, |
| 102 // because the client isn't authenticated yet. | 106 // because the client isn't authenticated yet. |
| 103 client_session_->InjectClipboardEvent(clipboard_event1); | 107 connection_->clipboard_stub()->InjectClipboardEvent(clipboard_event1); |
| 104 client_session_->OnConnectionAuthenticated(client_session_->connection()); | 108 client_session_->OnConnectionAuthenticated(client_session_->connection()); |
| 105 client_session_->OnConnectionChannelsConnected(client_session_->connection()); | 109 client_session_->OnConnectionChannelsConnected(client_session_->connection()); |
| 106 // This event should get through to the clipboard stub. | 110 // This event should get through to the clipboard stub. |
| 107 client_session_->InjectClipboardEvent(clipboard_event2); | 111 connection_->clipboard_stub()->InjectClipboardEvent(clipboard_event2); |
| 108 DisconnectClientSession(); | 112 DisconnectClientSession(); |
| 109 // This event should not get through to the clipboard stub, | 113 // This event should not get through to the clipboard stub, |
| 110 // because the client has disconnected. | 114 // because the client has disconnected. |
| 111 client_session_->InjectClipboardEvent(clipboard_event3); | 115 connection_->clipboard_stub()->InjectClipboardEvent(clipboard_event3); |
| 112 } | 116 } |
| 113 | 117 |
| 114 MATCHER_P2(EqualsKeyEvent, keycode, pressed, "") { | 118 MATCHER_P2(EqualsKeyEvent, keycode, pressed, "") { |
| 115 return arg.keycode() == keycode && arg.pressed() == pressed; | 119 return arg.keycode() == keycode && arg.pressed() == pressed; |
| 116 } | 120 } |
| 117 | 121 |
| 118 MATCHER_P2(EqualsMouseEvent, x, y, "") { | 122 MATCHER_P2(EqualsMouseEvent, x, y, "") { |
| 119 return arg.x() == x && arg.y() == y; | 123 return arg.x() == x && arg.y() == y; |
| 120 } | 124 } |
| 121 | 125 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 InSequence s; | 159 InSequence s; |
| 156 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); | 160 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); |
| 157 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); | 161 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); |
| 158 EXPECT_CALL(host_input_stub_, InjectKeyEvent(EqualsKeyEvent(2, true))); | 162 EXPECT_CALL(host_input_stub_, InjectKeyEvent(EqualsKeyEvent(2, true))); |
| 159 EXPECT_CALL(host_input_stub_, InjectKeyEvent(EqualsKeyEvent(2, false))); | 163 EXPECT_CALL(host_input_stub_, InjectKeyEvent(EqualsKeyEvent(2, false))); |
| 160 EXPECT_CALL(host_input_stub_, InjectMouseEvent(EqualsMouseEvent(200, 201))); | 164 EXPECT_CALL(host_input_stub_, InjectMouseEvent(EqualsMouseEvent(200, 201))); |
| 161 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); | 165 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); |
| 162 | 166 |
| 163 // These events should not get through to the input stub, | 167 // These events should not get through to the input stub, |
| 164 // because the client isn't authenticated yet. | 168 // because the client isn't authenticated yet. |
| 165 client_session_->InjectKeyEvent(key_event1); | 169 connection_->input_stub()->InjectKeyEvent(key_event1); |
| 166 client_session_->InjectMouseEvent(mouse_event1); | 170 connection_->input_stub()->InjectMouseEvent(mouse_event1); |
| 167 client_session_->OnConnectionAuthenticated(client_session_->connection()); | 171 client_session_->OnConnectionAuthenticated(client_session_->connection()); |
| 168 client_session_->OnConnectionChannelsConnected(client_session_->connection()); | 172 client_session_->OnConnectionChannelsConnected(client_session_->connection()); |
| 169 // These events should get through to the input stub. | 173 // These events should get through to the input stub. |
| 170 client_session_->InjectKeyEvent(key_event2_down); | 174 connection_->input_stub()->InjectKeyEvent(key_event2_down); |
| 171 client_session_->InjectKeyEvent(key_event2_up); | 175 connection_->input_stub()->InjectKeyEvent(key_event2_up); |
| 172 client_session_->InjectMouseEvent(mouse_event2); | 176 connection_->input_stub()->InjectMouseEvent(mouse_event2); |
| 173 DisconnectClientSession(); | 177 DisconnectClientSession(); |
| 174 // These events should not get through to the input stub, | 178 // These events should not get through to the input stub, |
| 175 // because the client has disconnected. | 179 // because the client has disconnected. |
| 176 client_session_->InjectKeyEvent(key_event3); | 180 connection_->input_stub()->InjectKeyEvent(key_event3); |
| 177 client_session_->InjectMouseEvent(mouse_event3); | 181 connection_->input_stub()->InjectMouseEvent(mouse_event3); |
| 178 } | 182 } |
| 179 | 183 |
| 180 TEST_F(ClientSessionTest, LocalInputTest) { | 184 TEST_F(ClientSessionTest, LocalInputTest) { |
| 181 protocol::MouseEvent mouse_event1; | 185 protocol::MouseEvent mouse_event1; |
| 182 mouse_event1.set_x(100); | 186 mouse_event1.set_x(100); |
| 183 mouse_event1.set_y(101); | 187 mouse_event1.set_y(101); |
| 184 protocol::MouseEvent mouse_event2; | 188 protocol::MouseEvent mouse_event2; |
| 185 mouse_event2.set_x(200); | 189 mouse_event2.set_x(200); |
| 186 mouse_event2.set_y(201); | 190 mouse_event2.set_y(201); |
| 187 protocol::MouseEvent mouse_event3; | 191 protocol::MouseEvent mouse_event3; |
| 188 mouse_event3.set_x(300); | 192 mouse_event3.set_x(300); |
| 189 mouse_event3.set_y(301); | 193 mouse_event3.set_y(301); |
| 190 | 194 |
| 191 InSequence s; | 195 InSequence s; |
| 192 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); | 196 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); |
| 193 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); | 197 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); |
| 194 EXPECT_CALL(host_input_stub_, InjectMouseEvent(EqualsMouseEvent(100, 101))); | 198 EXPECT_CALL(host_input_stub_, InjectMouseEvent(EqualsMouseEvent(100, 101))); |
| 195 EXPECT_CALL(host_input_stub_, InjectMouseEvent(EqualsMouseEvent(200, 201))); | 199 EXPECT_CALL(host_input_stub_, InjectMouseEvent(EqualsMouseEvent(200, 201))); |
| 196 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); | 200 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); |
| 197 | 201 |
| 198 client_session_->OnConnectionAuthenticated(client_session_->connection()); | 202 client_session_->OnConnectionAuthenticated(client_session_->connection()); |
| 199 client_session_->OnConnectionChannelsConnected(client_session_->connection()); | 203 client_session_->OnConnectionChannelsConnected(client_session_->connection()); |
| 200 // This event should get through to the input stub. | 204 // This event should get through to the input stub. |
| 201 client_session_->InjectMouseEvent(mouse_event1); | 205 connection_->input_stub()->InjectMouseEvent(mouse_event1); |
| 202 // This one should too because the local event echoes the remote one. | 206 // This one should too because the local event echoes the remote one. |
| 203 client_session_->LocalMouseMoved(SkIPoint::Make(mouse_event1.x(), | 207 client_session_->LocalMouseMoved(SkIPoint::Make(mouse_event1.x(), |
| 204 mouse_event1.y())); | 208 mouse_event1.y())); |
| 205 client_session_->InjectMouseEvent(mouse_event2); | 209 connection_->input_stub()->InjectMouseEvent(mouse_event2); |
| 206 // This one should not. | 210 // This one should not. |
| 207 client_session_->LocalMouseMoved(SkIPoint::Make(mouse_event1.x(), | 211 client_session_->LocalMouseMoved(SkIPoint::Make(mouse_event1.x(), |
| 208 mouse_event1.y())); | 212 mouse_event1.y())); |
| 209 client_session_->InjectMouseEvent(mouse_event3); | 213 connection_->input_stub()->InjectMouseEvent(mouse_event3); |
| 210 // TODO(jamiewalch): Verify that remote inputs are re-enabled eventually | 214 // TODO(jamiewalch): Verify that remote inputs are re-enabled eventually |
| 211 // (via dependency injection, not sleep!) | 215 // (via dependency injection, not sleep!) |
| 212 DisconnectClientSession(); | 216 DisconnectClientSession(); |
| 213 } | 217 } |
| 214 | 218 |
| 215 TEST_F(ClientSessionTest, RestoreEventState) { | 219 TEST_F(ClientSessionTest, RestoreEventState) { |
| 216 protocol::KeyEvent key1; | 220 protocol::KeyEvent key1; |
| 217 key1.set_pressed(true); | 221 key1.set_pressed(true); |
| 218 key1.set_keycode(1); | 222 key1.set_keycode(1); |
| 219 | 223 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 234 protocol::MouseEvent::BUTTON_LEFT, true))); | 238 protocol::MouseEvent::BUTTON_LEFT, true))); |
| 235 EXPECT_CALL(host_input_stub_, InjectKeyEvent(EqualsKeyEvent(1, false))); | 239 EXPECT_CALL(host_input_stub_, InjectKeyEvent(EqualsKeyEvent(1, false))); |
| 236 EXPECT_CALL(host_input_stub_, InjectKeyEvent(EqualsKeyEvent(2, false))); | 240 EXPECT_CALL(host_input_stub_, InjectKeyEvent(EqualsKeyEvent(2, false))); |
| 237 EXPECT_CALL(host_input_stub_, InjectMouseEvent(EqualsMouseButtonEvent( | 241 EXPECT_CALL(host_input_stub_, InjectMouseEvent(EqualsMouseButtonEvent( |
| 238 protocol::MouseEvent::BUTTON_LEFT, false))); | 242 protocol::MouseEvent::BUTTON_LEFT, false))); |
| 239 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); | 243 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); |
| 240 | 244 |
| 241 client_session_->OnConnectionAuthenticated(client_session_->connection()); | 245 client_session_->OnConnectionAuthenticated(client_session_->connection()); |
| 242 client_session_->OnConnectionChannelsConnected(client_session_->connection()); | 246 client_session_->OnConnectionChannelsConnected(client_session_->connection()); |
| 243 | 247 |
| 244 client_session_->InjectKeyEvent(key1); | 248 connection_->input_stub()->InjectKeyEvent(key1); |
| 245 client_session_->InjectKeyEvent(key2); | 249 connection_->input_stub()->InjectKeyEvent(key2); |
| 246 client_session_->InjectMouseEvent(mousedown); | 250 connection_->input_stub()->InjectMouseEvent(mousedown); |
| 247 | 251 |
| 248 DisconnectClientSession(); | 252 DisconnectClientSession(); |
| 249 } | 253 } |
| 250 | 254 |
| 251 TEST_F(ClientSessionTest, ClampMouseEvents) { | 255 TEST_F(ClientSessionTest, ClampMouseEvents) { |
| 252 SkISize screen(SkISize::Make(200, 100)); | 256 SkISize screen(SkISize::Make(200, 100)); |
| 253 EXPECT_CALL(capturer_, size_most_recent()) | 257 EXPECT_CALL(capturer_, size_most_recent()) |
| 254 .WillRepeatedly(ReturnRef(screen)); | 258 .WillRepeatedly(ReturnRef(screen)); |
| 255 | 259 |
| 256 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); | 260 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); |
| 257 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); | 261 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); |
| 258 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); | 262 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); |
| 259 | 263 |
| 260 client_session_->OnConnectionAuthenticated(client_session_->connection()); | 264 client_session_->OnConnectionAuthenticated(client_session_->connection()); |
| 261 client_session_->OnConnectionChannelsConnected(client_session_->connection()); | 265 client_session_->OnConnectionChannelsConnected(client_session_->connection()); |
| 262 | 266 |
| 263 int input_x[3] = { -999, 100, 999 }; | 267 int input_x[3] = { -999, 100, 999 }; |
| 264 int expected_x[3] = { 0, 100, 199 }; | 268 int expected_x[3] = { 0, 100, 199 }; |
| 265 int input_y[3] = { -999, 50, 999 }; | 269 int input_y[3] = { -999, 50, 999 }; |
| 266 int expected_y[3] = { 0, 50, 99 }; | 270 int expected_y[3] = { 0, 50, 99 }; |
| 267 | 271 |
| 268 protocol::MouseEvent event; | 272 protocol::MouseEvent event; |
| 269 for (int j = 0; j < 3; j++) { | 273 for (int j = 0; j < 3; j++) { |
| 270 for (int i = 0; i < 3; i++) { | 274 for (int i = 0; i < 3; i++) { |
| 271 event.set_x(input_x[i]); | 275 event.set_x(input_x[i]); |
| 272 event.set_y(input_y[j]); | 276 event.set_y(input_y[j]); |
| 273 EXPECT_CALL(host_input_stub_, InjectMouseEvent(EqualsMouseEvent( | 277 EXPECT_CALL(host_input_stub_, InjectMouseEvent(EqualsMouseEvent( |
| 274 expected_x[i], expected_y[j]))); | 278 expected_x[i], expected_y[j]))); |
| 275 client_session_->InjectMouseEvent(event); | 279 connection_->input_stub()->InjectMouseEvent(event); |
| 276 } | 280 } |
| 277 } | 281 } |
| 278 | 282 |
| 279 DisconnectClientSession(); | 283 DisconnectClientSession(); |
| 280 } | 284 } |
| 281 | 285 |
| 282 } // namespace remoting | 286 } // namespace remoting |
| OLD | NEW |