| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 } | 46 } |
| 47 | 47 |
| 48 virtual void TearDown() OVERRIDE { | 48 virtual void TearDown() OVERRIDE { |
| 49 client_session_.reset(); | 49 client_session_.reset(); |
| 50 // Run message loop before destroying because protocol::Session is | 50 // Run message loop before destroying because protocol::Session is |
| 51 // destroyed asynchronously. | 51 // destroyed asynchronously. |
| 52 message_loop_.RunAllPending(); | 52 message_loop_.RunAllPending(); |
| 53 } | 53 } |
| 54 | 54 |
| 55 protected: | 55 protected: |
| 56 void DisconnectClientSession() { |
| 57 client_session_->Disconnect(); |
| 58 // MockSession won't trigger OnConnectionClosed, so fake it. |
| 59 client_session_->OnConnectionClosed(client_session_->connection(), |
| 60 protocol::OK); |
| 61 } |
| 62 |
| 56 SkISize default_screen_size_; | 63 SkISize default_screen_size_; |
| 57 MessageLoop message_loop_; | 64 MessageLoop message_loop_; |
| 58 std::string client_jid_; | 65 std::string client_jid_; |
| 59 MockHostStub host_stub_; | 66 MockHostStub host_stub_; |
| 60 MockHostEventStub host_event_stub_; | 67 MockHostEventStub host_event_stub_; |
| 61 MockCapturer capturer_; | 68 MockCapturer capturer_; |
| 62 MockClientSessionEventHandler session_event_handler_; | 69 MockClientSessionEventHandler session_event_handler_; |
| 63 scoped_ptr<ClientSession> client_session_; | 70 scoped_ptr<ClientSession> client_session_; |
| 64 }; | 71 }; |
| 65 | 72 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 76 protocol::ClipboardEvent clipboard_event2; | 83 protocol::ClipboardEvent clipboard_event2; |
| 77 clipboard_event2.set_mime_type(kMimeTypeTextUtf8); | 84 clipboard_event2.set_mime_type(kMimeTypeTextUtf8); |
| 78 clipboard_event2.set_data("b"); | 85 clipboard_event2.set_data("b"); |
| 79 | 86 |
| 80 protocol::ClipboardEvent clipboard_event3; | 87 protocol::ClipboardEvent clipboard_event3; |
| 81 clipboard_event3.set_mime_type(kMimeTypeTextUtf8); | 88 clipboard_event3.set_mime_type(kMimeTypeTextUtf8); |
| 82 clipboard_event3.set_data("c"); | 89 clipboard_event3.set_data("c"); |
| 83 | 90 |
| 84 InSequence s; | 91 InSequence s; |
| 85 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); | 92 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); |
| 93 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); |
| 86 EXPECT_CALL(host_event_stub_, InjectClipboardEvent(EqualsClipboardEvent( | 94 EXPECT_CALL(host_event_stub_, InjectClipboardEvent(EqualsClipboardEvent( |
| 87 kMimeTypeTextUtf8, "b"))); | 95 kMimeTypeTextUtf8, "b"))); |
| 96 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); |
| 88 | 97 |
| 89 // This event should not get through to the clipboard stub, | 98 // This event should not get through to the clipboard stub, |
| 90 // because the client isn't authenticated yet. | 99 // because the client isn't authenticated yet. |
| 91 client_session_->InjectClipboardEvent(clipboard_event1); | 100 client_session_->InjectClipboardEvent(clipboard_event1); |
| 92 client_session_->OnConnectionAuthenticated(client_session_->connection()); | 101 client_session_->OnConnectionAuthenticated(client_session_->connection()); |
| 93 client_session_->OnConnectionChannelsConnected(client_session_->connection()); | 102 client_session_->OnConnectionChannelsConnected(client_session_->connection()); |
| 94 // This event should get through to the clipboard stub. | 103 // This event should get through to the clipboard stub. |
| 95 client_session_->InjectClipboardEvent(clipboard_event2); | 104 client_session_->InjectClipboardEvent(clipboard_event2); |
| 96 client_session_->Disconnect(); | 105 DisconnectClientSession(); |
| 97 // This event should not get through to the clipboard stub, | 106 // This event should not get through to the clipboard stub, |
| 98 // because the client has disconnected. | 107 // because the client has disconnected. |
| 99 client_session_->InjectClipboardEvent(clipboard_event3); | 108 client_session_->InjectClipboardEvent(clipboard_event3); |
| 100 } | 109 } |
| 101 | 110 |
| 102 MATCHER_P2(EqualsKeyEvent, keycode, pressed, "") { | 111 MATCHER_P2(EqualsKeyEvent, keycode, pressed, "") { |
| 103 return arg.keycode() == keycode && arg.pressed() == pressed; | 112 return arg.keycode() == keycode && arg.pressed() == pressed; |
| 104 } | 113 } |
| 105 | 114 |
| 106 MATCHER_P2(EqualsMouseEvent, x, y, "") { | 115 MATCHER_P2(EqualsMouseEvent, x, y, "") { |
| 107 return arg.x() == x && arg.y() == y; | 116 return arg.x() == x && arg.y() == y; |
| 108 } | 117 } |
| 109 | 118 |
| 110 MATCHER_P(EqualsMouseUpEvent, button, "") { | 119 MATCHER_P2(EqualsMouseButtonEvent, button, down, "") { |
| 111 return arg.button() == button && !arg.button_down(); | 120 return arg.button() == button && arg.button_down() == down; |
| 112 } | 121 } |
| 113 | 122 |
| 114 TEST_F(ClientSessionTest, InputStubFilter) { | 123 TEST_F(ClientSessionTest, InputStubFilter) { |
| 115 protocol::KeyEvent key_event1; | 124 protocol::KeyEvent key_event1; |
| 116 key_event1.set_pressed(true); | 125 key_event1.set_pressed(true); |
| 117 key_event1.set_keycode(1); | 126 key_event1.set_keycode(1); |
| 118 | 127 |
| 119 protocol::KeyEvent key_event2_down; | 128 protocol::KeyEvent key_event2_down; |
| 120 key_event2_down.set_pressed(true); | 129 key_event2_down.set_pressed(true); |
| 121 key_event2_down.set_keycode(2); | 130 key_event2_down.set_keycode(2); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 139 protocol::MouseEvent mouse_event3; | 148 protocol::MouseEvent mouse_event3; |
| 140 mouse_event3.set_x(300); | 149 mouse_event3.set_x(300); |
| 141 mouse_event3.set_y(301); | 150 mouse_event3.set_y(301); |
| 142 | 151 |
| 143 InSequence s; | 152 InSequence s; |
| 144 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); | 153 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); |
| 145 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); | 154 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); |
| 146 EXPECT_CALL(host_event_stub_, InjectKeyEvent(EqualsKeyEvent(2, true))); | 155 EXPECT_CALL(host_event_stub_, InjectKeyEvent(EqualsKeyEvent(2, true))); |
| 147 EXPECT_CALL(host_event_stub_, InjectKeyEvent(EqualsKeyEvent(2, false))); | 156 EXPECT_CALL(host_event_stub_, InjectKeyEvent(EqualsKeyEvent(2, false))); |
| 148 EXPECT_CALL(host_event_stub_, InjectMouseEvent(EqualsMouseEvent(200, 201))); | 157 EXPECT_CALL(host_event_stub_, InjectMouseEvent(EqualsMouseEvent(200, 201))); |
| 158 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); |
| 149 | 159 |
| 150 // These events should not get through to the input stub, | 160 // These events should not get through to the input stub, |
| 151 // because the client isn't authenticated yet. | 161 // because the client isn't authenticated yet. |
| 152 client_session_->InjectKeyEvent(key_event1); | 162 client_session_->InjectKeyEvent(key_event1); |
| 153 client_session_->InjectMouseEvent(mouse_event1); | 163 client_session_->InjectMouseEvent(mouse_event1); |
| 154 client_session_->OnConnectionAuthenticated(client_session_->connection()); | 164 client_session_->OnConnectionAuthenticated(client_session_->connection()); |
| 155 client_session_->OnConnectionChannelsConnected(client_session_->connection()); | 165 client_session_->OnConnectionChannelsConnected(client_session_->connection()); |
| 156 // These events should get through to the input stub. | 166 // These events should get through to the input stub. |
| 157 client_session_->InjectKeyEvent(key_event2_down); | 167 client_session_->InjectKeyEvent(key_event2_down); |
| 158 client_session_->InjectKeyEvent(key_event2_up); | 168 client_session_->InjectKeyEvent(key_event2_up); |
| 159 client_session_->InjectMouseEvent(mouse_event2); | 169 client_session_->InjectMouseEvent(mouse_event2); |
| 160 client_session_->Disconnect(); | 170 DisconnectClientSession(); |
| 161 // These events should not get through to the input stub, | 171 // These events should not get through to the input stub, |
| 162 // because the client has disconnected. | 172 // because the client has disconnected. |
| 163 client_session_->InjectKeyEvent(key_event3); | 173 client_session_->InjectKeyEvent(key_event3); |
| 164 client_session_->InjectMouseEvent(mouse_event3); | 174 client_session_->InjectMouseEvent(mouse_event3); |
| 165 } | 175 } |
| 166 | 176 |
| 167 TEST_F(ClientSessionTest, LocalInputTest) { | 177 TEST_F(ClientSessionTest, LocalInputTest) { |
| 168 protocol::MouseEvent mouse_event1; | 178 protocol::MouseEvent mouse_event1; |
| 169 mouse_event1.set_x(100); | 179 mouse_event1.set_x(100); |
| 170 mouse_event1.set_y(101); | 180 mouse_event1.set_y(101); |
| 171 protocol::MouseEvent mouse_event2; | 181 protocol::MouseEvent mouse_event2; |
| 172 mouse_event2.set_x(200); | 182 mouse_event2.set_x(200); |
| 173 mouse_event2.set_y(201); | 183 mouse_event2.set_y(201); |
| 174 protocol::MouseEvent mouse_event3; | 184 protocol::MouseEvent mouse_event3; |
| 175 mouse_event3.set_x(300); | 185 mouse_event3.set_x(300); |
| 176 mouse_event3.set_y(301); | 186 mouse_event3.set_y(301); |
| 177 | 187 |
| 178 InSequence s; | 188 InSequence s; |
| 179 EXPECT_CALL(session_event_handler_, | 189 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); |
| 180 OnSessionAuthenticated(client_session_.get())); | 190 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); |
| 181 EXPECT_CALL(session_event_handler_, | |
| 182 OnSessionChannelsConnected(client_session_.get())); | |
| 183 EXPECT_CALL(host_event_stub_, InjectMouseEvent(EqualsMouseEvent(100, 101))); | 191 EXPECT_CALL(host_event_stub_, InjectMouseEvent(EqualsMouseEvent(100, 101))); |
| 184 EXPECT_CALL(host_event_stub_, InjectMouseEvent(EqualsMouseEvent(200, 201))); | 192 EXPECT_CALL(host_event_stub_, InjectMouseEvent(EqualsMouseEvent(200, 201))); |
| 193 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); |
| 185 | 194 |
| 186 client_session_->OnConnectionAuthenticated(client_session_->connection()); | 195 client_session_->OnConnectionAuthenticated(client_session_->connection()); |
| 187 client_session_->OnConnectionChannelsConnected(client_session_->connection()); | 196 client_session_->OnConnectionChannelsConnected(client_session_->connection()); |
| 188 // This event should get through to the input stub. | 197 // This event should get through to the input stub. |
| 189 client_session_->InjectMouseEvent(mouse_event1); | 198 client_session_->InjectMouseEvent(mouse_event1); |
| 190 // This one should too because the local event echoes the remote one. | 199 // This one should too because the local event echoes the remote one. |
| 191 client_session_->LocalMouseMoved(SkIPoint::Make(mouse_event1.x(), | 200 client_session_->LocalMouseMoved(SkIPoint::Make(mouse_event1.x(), |
| 192 mouse_event1.y())); | 201 mouse_event1.y())); |
| 193 client_session_->InjectMouseEvent(mouse_event2); | 202 client_session_->InjectMouseEvent(mouse_event2); |
| 194 // This one should not. | 203 // This one should not. |
| 195 client_session_->LocalMouseMoved(SkIPoint::Make(mouse_event1.x(), | 204 client_session_->LocalMouseMoved(SkIPoint::Make(mouse_event1.x(), |
| 196 mouse_event1.y())); | 205 mouse_event1.y())); |
| 197 client_session_->InjectMouseEvent(mouse_event3); | 206 client_session_->InjectMouseEvent(mouse_event3); |
| 198 // TODO(jamiewalch): Verify that remote inputs are re-enabled eventually | 207 // TODO(jamiewalch): Verify that remote inputs are re-enabled eventually |
| 199 // (via dependency injection, not sleep!) | 208 // (via dependency injection, not sleep!) |
| 200 client_session_->Disconnect(); | 209 DisconnectClientSession(); |
| 201 } | 210 } |
| 202 | 211 |
| 203 TEST_F(ClientSessionTest, RestoreEventState) { | 212 TEST_F(ClientSessionTest, RestoreEventState) { |
| 204 protocol::KeyEvent key1; | 213 protocol::KeyEvent key1; |
| 205 key1.set_pressed(true); | 214 key1.set_pressed(true); |
| 206 key1.set_keycode(1); | 215 key1.set_keycode(1); |
| 207 | 216 |
| 208 protocol::KeyEvent key2; | 217 protocol::KeyEvent key2; |
| 209 key2.set_pressed(true); | 218 key2.set_pressed(true); |
| 210 key2.set_keycode(2); | 219 key2.set_keycode(2); |
| 211 | 220 |
| 212 protocol::MouseEvent mousedown; | 221 protocol::MouseEvent mousedown; |
| 213 mousedown.set_button(protocol::MouseEvent::BUTTON_LEFT); | 222 mousedown.set_button(protocol::MouseEvent::BUTTON_LEFT); |
| 214 mousedown.set_button_down(true); | 223 mousedown.set_button_down(true); |
| 215 | 224 |
| 216 client_session_->RecordKeyEvent(key1); | 225 InSequence s; |
| 217 client_session_->RecordKeyEvent(key2); | 226 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); |
| 218 client_session_->RecordMouseButtonState(mousedown); | 227 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); |
| 219 | 228 EXPECT_CALL(host_event_stub_, InjectKeyEvent(EqualsKeyEvent(1, true))); |
| 229 EXPECT_CALL(host_event_stub_, InjectKeyEvent(EqualsKeyEvent(2, true))); |
| 230 EXPECT_CALL(host_event_stub_, InjectMouseEvent(EqualsMouseButtonEvent( |
| 231 protocol::MouseEvent::BUTTON_LEFT, true))); |
| 220 EXPECT_CALL(host_event_stub_, InjectKeyEvent(EqualsKeyEvent(1, false))); | 232 EXPECT_CALL(host_event_stub_, InjectKeyEvent(EqualsKeyEvent(1, false))); |
| 221 EXPECT_CALL(host_event_stub_, InjectKeyEvent(EqualsKeyEvent(2, false))); | 233 EXPECT_CALL(host_event_stub_, InjectKeyEvent(EqualsKeyEvent(2, false))); |
| 222 EXPECT_CALL(host_event_stub_, InjectMouseEvent(EqualsMouseUpEvent( | 234 EXPECT_CALL(host_event_stub_, InjectMouseEvent(EqualsMouseButtonEvent( |
| 223 protocol::MouseEvent::BUTTON_LEFT))); | 235 protocol::MouseEvent::BUTTON_LEFT, false))); |
| 236 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); |
| 224 | 237 |
| 225 client_session_->RestoreEventState(); | 238 client_session_->OnConnectionAuthenticated(client_session_->connection()); |
| 239 client_session_->OnConnectionChannelsConnected(client_session_->connection()); |
| 240 |
| 241 client_session_->InjectKeyEvent(key1); |
| 242 client_session_->InjectKeyEvent(key2); |
| 243 client_session_->InjectMouseEvent(mousedown); |
| 244 |
| 245 DisconnectClientSession(); |
| 226 } | 246 } |
| 227 | 247 |
| 228 TEST_F(ClientSessionTest, ClampMouseEvents) { | 248 TEST_F(ClientSessionTest, ClampMouseEvents) { |
| 229 SkISize screen(SkISize::Make(200, 100)); | 249 SkISize screen(SkISize::Make(200, 100)); |
| 230 EXPECT_CALL(capturer_, size_most_recent()) | 250 EXPECT_CALL(capturer_, size_most_recent()) |
| 231 .WillRepeatedly(ReturnRef(screen)); | 251 .WillRepeatedly(ReturnRef(screen)); |
| 232 | 252 |
| 233 EXPECT_CALL(session_event_handler_, | 253 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); |
| 234 OnSessionAuthenticated(client_session_.get())); | 254 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); |
| 235 EXPECT_CALL(session_event_handler_, | 255 |
| 236 OnSessionChannelsConnected(client_session_.get())); | |
| 237 client_session_->OnConnectionAuthenticated(client_session_->connection()); | 256 client_session_->OnConnectionAuthenticated(client_session_->connection()); |
| 238 client_session_->OnConnectionChannelsConnected(client_session_->connection()); | 257 client_session_->OnConnectionChannelsConnected(client_session_->connection()); |
| 239 | 258 |
| 240 int input_x[3] = { -999, 100, 999 }; | 259 int input_x[3] = { -999, 100, 999 }; |
| 241 int expected_x[3] = { 0, 100, 199 }; | 260 int expected_x[3] = { 0, 100, 199 }; |
| 242 int input_y[3] = { -999, 50, 999 }; | 261 int input_y[3] = { -999, 50, 999 }; |
| 243 int expected_y[3] = { 0, 50, 99 }; | 262 int expected_y[3] = { 0, 50, 99 }; |
| 244 | 263 |
| 245 protocol::MouseEvent event; | 264 protocol::MouseEvent event; |
| 246 for (int j = 0; j < 3; j++) { | 265 for (int j = 0; j < 3; j++) { |
| 247 for (int i = 0; i < 3; i++) { | 266 for (int i = 0; i < 3; i++) { |
| 248 event.set_x(input_x[i]); | 267 event.set_x(input_x[i]); |
| 249 event.set_y(input_y[j]); | 268 event.set_y(input_y[j]); |
| 250 EXPECT_CALL(host_event_stub_, InjectMouseEvent(EqualsMouseEvent( | 269 EXPECT_CALL(host_event_stub_, InjectMouseEvent(EqualsMouseEvent( |
| 251 expected_x[i], expected_y[j]))); | 270 expected_x[i], expected_y[j]))); |
| 252 client_session_->InjectMouseEvent(event); | 271 client_session_->InjectMouseEvent(event); |
| 253 } | 272 } |
| 254 } | 273 } |
| 255 } | 274 } |
| 256 | 275 |
| 257 } // namespace remoting | 276 } // namespace remoting |
| OLD | NEW |