Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1999)

Side by Side Diff: remoting/host/client_session_unittest.cc

Issue 9465035: Move ClientSession's input logic into separate components. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move filtering based on local input to RemoteInputFilter. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 }; 62 };
63 63
64 MATCHER_P2(EqualsKeyEvent, keycode, pressed, "") { 64 MATCHER_P2(EqualsKeyEvent, keycode, pressed, "") {
65 return arg.keycode() == keycode && arg.pressed() == pressed; 65 return arg.keycode() == keycode && arg.pressed() == pressed;
66 } 66 }
67 67
68 MATCHER_P2(EqualsMouseEvent, x, y, "") { 68 MATCHER_P2(EqualsMouseEvent, x, y, "") {
69 return arg.x() == x && arg.y() == y; 69 return arg.x() == x && arg.y() == y;
70 } 70 }
71 71
72 MATCHER_P(EqualsMouseUpEvent, button, "") { 72 MATCHER_P2(EqualsMouseButtonEvent, button, down, "") {
73 return arg.button() == button && !arg.button_down(); 73 return arg.button() == button && arg.button_down() == down;
74 } 74 }
75 75
76 TEST_F(ClientSessionTest, InputStubFilter) { 76 TEST_F(ClientSessionTest, InputStubFilter) {
77 protocol::KeyEvent key_event1; 77 protocol::KeyEvent key_event1;
78 key_event1.set_pressed(true); 78 key_event1.set_pressed(true);
79 key_event1.set_keycode(1); 79 key_event1.set_keycode(1);
80 80
81 protocol::KeyEvent key_event2_down; 81 protocol::KeyEvent key_event2_down;
82 key_event2_down.set_pressed(true); 82 key_event2_down.set_pressed(true);
83 key_event2_down.set_keycode(2); 83 key_event2_down.set_keycode(2);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 key1.set_keycode(1); 163 key1.set_keycode(1);
164 164
165 protocol::KeyEvent key2; 165 protocol::KeyEvent key2;
166 key2.set_pressed(true); 166 key2.set_pressed(true);
167 key2.set_keycode(2); 167 key2.set_keycode(2);
168 168
169 protocol::MouseEvent mousedown; 169 protocol::MouseEvent mousedown;
170 mousedown.set_button(protocol::MouseEvent::BUTTON_LEFT); 170 mousedown.set_button(protocol::MouseEvent::BUTTON_LEFT);
171 mousedown.set_button_down(true); 171 mousedown.set_button_down(true);
172 172
173 client_session_->RecordKeyEvent(key1); 173 InSequence s;
174 client_session_->RecordKeyEvent(key2); 174 EXPECT_CALL(input_stub_, InjectKeyEvent(EqualsKeyEvent(1, true)));
175 client_session_->RecordMouseButtonState(mousedown); 175 EXPECT_CALL(input_stub_, InjectKeyEvent(EqualsKeyEvent(2, true)));
176 176 EXPECT_CALL(input_stub_, InjectMouseEvent(EqualsMouseButtonEvent(
177 protocol::MouseEvent::BUTTON_LEFT, true)));
177 EXPECT_CALL(input_stub_, InjectKeyEvent(EqualsKeyEvent(1, false))); 178 EXPECT_CALL(input_stub_, InjectKeyEvent(EqualsKeyEvent(1, false)));
178 EXPECT_CALL(input_stub_, InjectKeyEvent(EqualsKeyEvent(2, false))); 179 EXPECT_CALL(input_stub_, InjectKeyEvent(EqualsKeyEvent(2, false)));
179 EXPECT_CALL(input_stub_, InjectMouseEvent(EqualsMouseUpEvent( 180 EXPECT_CALL(input_stub_, InjectMouseEvent(EqualsMouseButtonEvent(
180 protocol::MouseEvent::BUTTON_LEFT))); 181 protocol::MouseEvent::BUTTON_LEFT, false)));
181 182
182 client_session_->RestoreEventState(); 183 client_session_->OnConnectionOpened(client_session_->connection());
184
185 client_session_->InjectKeyEvent(key1);
186 client_session_->InjectKeyEvent(key2);
187 client_session_->InjectMouseEvent(mousedown);
188
189 client_session_->Disconnect();
183 } 190 }
184 191
185 TEST_F(ClientSessionTest, ClampMouseEvents) { 192 TEST_F(ClientSessionTest, ClampMouseEvents) {
186 SkISize screen(SkISize::Make(200, 100)); 193 SkISize screen(SkISize::Make(200, 100));
187 EXPECT_CALL(capturer_, size_most_recent()) 194 EXPECT_CALL(capturer_, size_most_recent())
188 .WillRepeatedly(ReturnRef(screen)); 195 .WillRepeatedly(ReturnRef(screen));
189 196
190 EXPECT_CALL(session_event_handler_, 197 EXPECT_CALL(session_event_handler_,
191 OnSessionAuthenticated(client_session_.get())); 198 OnSessionAuthenticated(client_session_.get()));
192 client_session_->OnConnectionOpened(client_session_->connection()); 199 client_session_->OnConnectionOpened(client_session_->connection());
193 200
194 int input_x[3] = { -999, 100, 999 }; 201 int input_x[3] = { -999, 100, 999 };
195 int expected_x[3] = { 0, 100, 199 }; 202 int expected_x[3] = { 0, 100, 199 };
196 int input_y[3] = { -999, 50, 999 }; 203 int input_y[3] = { -999, 50, 999 };
197 int expected_y[3] = { 0, 50, 99 }; 204 int expected_y[3] = { 0, 50, 99 };
198 205
199 protocol::MouseEvent event; 206 protocol::MouseEvent event;
200 for (int j = 0; j < 3; j++) { 207 for (int j = 0; j < 3; j++) {
201 for (int i = 0; i < 3; i++) { 208 for (int i = 0; i < 3; i++) {
202 event.set_x(input_x[i]); 209 event.set_x(input_x[i]);
203 event.set_y(input_y[j]); 210 event.set_y(input_y[j]);
204 EXPECT_CALL(input_stub_, InjectMouseEvent(EqualsMouseEvent( 211 EXPECT_CALL(input_stub_, InjectMouseEvent(EqualsMouseEvent(
205 expected_x[i], expected_y[j]))); 212 expected_x[i], expected_y[j])));
206 client_session_->InjectMouseEvent(event); 213 client_session_->InjectMouseEvent(event);
207 } 214 }
208 } 215 }
209 } 216 }
210 217
211 } // namespace remoting 218 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698