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

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

Issue 8476018: Move ConnectionToClient::EventHandler from ChromotingHost to ClientSession (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merged Created 9 years, 1 month 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
« no previous file with comments | « remoting/host/client_session.cc ('k') | remoting/host/host_mock_objects.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 {
11 11
12 using protocol::MockConnectionToClient; 12 using protocol::MockConnectionToClient;
13 using protocol::MockConnectionToClientEventHandler; 13 using protocol::MockConnectionToClientEventHandler;
14 using protocol::MockHostStub; 14 using protocol::MockHostStub;
15 using protocol::MockInputStub; 15 using protocol::MockInputStub;
16 using protocol::MockSession; 16 using protocol::MockSession;
17 17
18 using testing::_; 18 using testing::_;
19 using testing::DeleteArg; 19 using testing::DeleteArg;
20 using testing::InSequence; 20 using testing::InSequence;
21 using testing::Return; 21 using testing::Return;
22 using testing::ReturnRef; 22 using testing::ReturnRef;
23 23
24 class ClientSessionTest : public testing::Test { 24 class ClientSessionTest : public testing::Test {
25 public: 25 public:
26 ClientSessionTest() {} 26 ClientSessionTest() {}
27 27
28 virtual void SetUp() { 28 virtual void SetUp() {
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_));
31
32 connection_ = new MockConnectionToClient(
33 &connection_event_handler_, &host_stub_, &input_stub_);
34
35 EXPECT_CALL(*connection_, session()).WillRepeatedly(Return(&session_));
36 30
37 // Set up a large default screen size that won't affect most tests. 31 // Set up a large default screen size that won't affect most tests.
38 default_screen_size_.set(1000, 1000); 32 default_screen_size_.set(1000, 1000);
39 EXPECT_CALL(capturer_, size_most_recent()) 33 EXPECT_CALL(capturer_, size_most_recent())
40 .WillRepeatedly(ReturnRef(default_screen_size_)); 34 .WillRepeatedly(ReturnRef(default_screen_size_));
41 35
36 protocol::MockSession* session = new MockSession();
37 EXPECT_CALL(*session, jid()).WillRepeatedly(ReturnRef(client_jid_));
38 EXPECT_CALL(*session, SetStateChangeCallback(_));
39
42 client_session_ = new ClientSession( 40 client_session_ = new ClientSession(
43 &session_event_handler_, 41 &session_event_handler_,
44 connection_, 42 new protocol::ConnectionToClient(
45 &input_stub_, 43 base::MessageLoopProxy::current(), session),
46 &capturer_); 44 &input_stub_, &capturer_);
47 } 45 }
48 46
49 protected: 47 protected:
50 SkISize default_screen_size_; 48 SkISize default_screen_size_;
51 MessageLoop message_loop_; 49 MessageLoop message_loop_;
52 std::string client_jid_; 50 std::string client_jid_;
53 MockSession session_;
54 MockConnectionToClientEventHandler connection_event_handler_;
55 MockHostStub host_stub_; 51 MockHostStub host_stub_;
56 MockInputStub input_stub_; 52 MockInputStub input_stub_;
57 MockCapturer capturer_; 53 MockCapturer capturer_;
58 MockClientSessionEventHandler session_event_handler_; 54 MockClientSessionEventHandler session_event_handler_;
59 scoped_refptr<MockConnectionToClient> connection_;
60 scoped_refptr<ClientSession> client_session_; 55 scoped_refptr<ClientSession> client_session_;
61 }; 56 };
62 57
63 MATCHER_P2(EqualsKeyEvent, keycode, pressed, "") { 58 MATCHER_P2(EqualsKeyEvent, keycode, pressed, "") {
64 return arg.keycode() == keycode && arg.pressed() == pressed; 59 return arg.keycode() == keycode && arg.pressed() == pressed;
65 } 60 }
66 61
67 MATCHER_P2(EqualsMouseEvent, x, y, "") { 62 MATCHER_P2(EqualsMouseEvent, x, y, "") {
68 return arg.x() == x && arg.y() == y; 63 return arg.x() == x && arg.y() == y;
69 } 64 }
(...skipping 25 matching lines...) Expand all
95 90
96 protocol::MouseEvent mouse_event2; 91 protocol::MouseEvent mouse_event2;
97 mouse_event2.set_x(200); 92 mouse_event2.set_x(200);
98 mouse_event2.set_y(201); 93 mouse_event2.set_y(201);
99 94
100 protocol::MouseEvent mouse_event3; 95 protocol::MouseEvent mouse_event3;
101 mouse_event3.set_x(300); 96 mouse_event3.set_x(300);
102 mouse_event3.set_y(301); 97 mouse_event3.set_y(301);
103 98
104 InSequence s; 99 InSequence s;
105 EXPECT_CALL(session_event_handler_, OnAuthenticationComplete(_)); 100 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_));
106 EXPECT_CALL(input_stub_, InjectKeyEvent(EqualsKeyEvent(2, true))); 101 EXPECT_CALL(input_stub_, InjectKeyEvent(EqualsKeyEvent(2, true)));
107 EXPECT_CALL(input_stub_, InjectKeyEvent(EqualsKeyEvent(2, false))); 102 EXPECT_CALL(input_stub_, InjectKeyEvent(EqualsKeyEvent(2, false)));
108 EXPECT_CALL(input_stub_, InjectMouseEvent(EqualsMouseEvent(200, 201))); 103 EXPECT_CALL(input_stub_, InjectMouseEvent(EqualsMouseEvent(200, 201)));
109 104
110 // These events should not get through to the input stub, 105 // These events should not get through to the input stub,
111 // because the client isn't authenticated yet. 106 // because the client isn't authenticated yet.
112 client_session_->InjectKeyEvent(key_event1); 107 client_session_->InjectKeyEvent(key_event1);
113 client_session_->InjectMouseEvent(mouse_event1); 108 client_session_->InjectMouseEvent(mouse_event1);
114 client_session_->OnAuthenticationComplete(); 109 client_session_->OnConnectionOpened(client_session_->connection());
115 // These events should get through to the input stub. 110 // These events should get through to the input stub.
116 client_session_->InjectKeyEvent(key_event2_down); 111 client_session_->InjectKeyEvent(key_event2_down);
117 client_session_->InjectKeyEvent(key_event2_up); 112 client_session_->InjectKeyEvent(key_event2_up);
118 client_session_->InjectMouseEvent(mouse_event2); 113 client_session_->InjectMouseEvent(mouse_event2);
119 client_session_->OnDisconnected(); 114 client_session_->Disconnect();
120 // These events should not get through to the input stub, 115 // These events should not get through to the input stub,
121 // because the client has disconnected. 116 // because the client has disconnected.
122 client_session_->InjectKeyEvent(key_event3); 117 client_session_->InjectKeyEvent(key_event3);
123 client_session_->InjectMouseEvent(mouse_event3); 118 client_session_->InjectMouseEvent(mouse_event3);
124 } 119 }
125 120
126 TEST_F(ClientSessionTest, LocalInputTest) { 121 TEST_F(ClientSessionTest, LocalInputTest) {
127 protocol::MouseEvent mouse_event1; 122 protocol::MouseEvent mouse_event1;
128 mouse_event1.set_x(100); 123 mouse_event1.set_x(100);
129 mouse_event1.set_y(101); 124 mouse_event1.set_y(101);
130 protocol::MouseEvent mouse_event2; 125 protocol::MouseEvent mouse_event2;
131 mouse_event2.set_x(200); 126 mouse_event2.set_x(200);
132 mouse_event2.set_y(201); 127 mouse_event2.set_y(201);
133 protocol::MouseEvent mouse_event3; 128 protocol::MouseEvent mouse_event3;
134 mouse_event3.set_x(300); 129 mouse_event3.set_x(300);
135 mouse_event3.set_y(301); 130 mouse_event3.set_y(301);
136 131
137 InSequence s; 132 InSequence s;
138 EXPECT_CALL(session_event_handler_, OnAuthenticationComplete(_)); 133 EXPECT_CALL(session_event_handler_,
134 OnSessionAuthenticated(client_session_.get()));
139 EXPECT_CALL(input_stub_, InjectMouseEvent(EqualsMouseEvent(100, 101))); 135 EXPECT_CALL(input_stub_, InjectMouseEvent(EqualsMouseEvent(100, 101)));
140 EXPECT_CALL(input_stub_, InjectMouseEvent(EqualsMouseEvent(200, 201))); 136 EXPECT_CALL(input_stub_, InjectMouseEvent(EqualsMouseEvent(200, 201)));
141 137
142 client_session_->OnAuthenticationComplete(); 138 client_session_->OnConnectionOpened(client_session_->connection());
143 // This event should get through to the input stub. 139 // This event should get through to the input stub.
144 client_session_->InjectMouseEvent(mouse_event1); 140 client_session_->InjectMouseEvent(mouse_event1);
145 // This one should too because the local event echoes the remote one. 141 // This one should too because the local event echoes the remote one.
146 client_session_->LocalMouseMoved(SkIPoint::Make(mouse_event1.x(), 142 client_session_->LocalMouseMoved(SkIPoint::Make(mouse_event1.x(),
147 mouse_event1.y())); 143 mouse_event1.y()));
148 client_session_->InjectMouseEvent(mouse_event2); 144 client_session_->InjectMouseEvent(mouse_event2);
149 // This one should not. 145 // This one should not.
150 client_session_->LocalMouseMoved(SkIPoint::Make(mouse_event1.x(), 146 client_session_->LocalMouseMoved(SkIPoint::Make(mouse_event1.x(),
151 mouse_event1.y())); 147 mouse_event1.y()));
152 client_session_->InjectMouseEvent(mouse_event3); 148 client_session_->InjectMouseEvent(mouse_event3);
153 // TODO(jamiewalch): Verify that remote inputs are re-enabled eventually 149 // TODO(jamiewalch): Verify that remote inputs are re-enabled eventually
154 // (via dependency injection, not sleep!) 150 // (via dependency injection, not sleep!)
155 client_session_->OnDisconnected(); 151 client_session_->Disconnect();
156 } 152 }
157 153
158 TEST_F(ClientSessionTest, RestoreEventState) { 154 TEST_F(ClientSessionTest, RestoreEventState) {
159 protocol::KeyEvent key1; 155 protocol::KeyEvent key1;
160 key1.set_pressed(true); 156 key1.set_pressed(true);
161 key1.set_keycode(1); 157 key1.set_keycode(1);
162 158
163 protocol::KeyEvent key2; 159 protocol::KeyEvent key2;
164 key2.set_pressed(true); 160 key2.set_pressed(true);
165 key2.set_keycode(2); 161 key2.set_keycode(2);
(...skipping 12 matching lines...) Expand all
178 protocol::MouseEvent::BUTTON_LEFT))); 174 protocol::MouseEvent::BUTTON_LEFT)));
179 175
180 client_session_->RestoreEventState(); 176 client_session_->RestoreEventState();
181 } 177 }
182 178
183 TEST_F(ClientSessionTest, ClampMouseEvents) { 179 TEST_F(ClientSessionTest, ClampMouseEvents) {
184 SkISize screen(SkISize::Make(200, 100)); 180 SkISize screen(SkISize::Make(200, 100));
185 EXPECT_CALL(capturer_, size_most_recent()) 181 EXPECT_CALL(capturer_, size_most_recent())
186 .WillRepeatedly(ReturnRef(screen)); 182 .WillRepeatedly(ReturnRef(screen));
187 183
188 EXPECT_CALL(session_event_handler_, OnAuthenticationComplete(_)); 184 EXPECT_CALL(session_event_handler_,
189 client_session_->OnAuthenticationComplete(); 185 OnSessionAuthenticated(client_session_.get()));
186 client_session_->OnConnectionOpened(client_session_->connection());
190 187
191 int input_x[3] = { -999, 100, 999 }; 188 int input_x[3] = { -999, 100, 999 };
192 int expected_x[3] = { 0, 100, 199 }; 189 int expected_x[3] = { 0, 100, 199 };
193 int input_y[3] = { -999, 50, 999 }; 190 int input_y[3] = { -999, 50, 999 };
194 int expected_y[3] = { 0, 50, 99 }; 191 int expected_y[3] = { 0, 50, 99 };
195 192
196 protocol::MouseEvent event; 193 protocol::MouseEvent event;
197 for (int j = 0; j < 3; j++) { 194 for (int j = 0; j < 3; j++) {
198 for (int i = 0; i < 3; i++) { 195 for (int i = 0; i < 3; i++) {
199 event.set_x(input_x[i]); 196 event.set_x(input_x[i]);
200 event.set_y(input_y[j]); 197 event.set_y(input_y[j]);
201 EXPECT_CALL(input_stub_, InjectMouseEvent(EqualsMouseEvent( 198 EXPECT_CALL(input_stub_, InjectMouseEvent(EqualsMouseEvent(
202 expected_x[i], expected_y[j]))); 199 expected_x[i], expected_y[j])));
203 client_session_->InjectMouseEvent(event); 200 client_session_->InjectMouseEvent(event);
204 } 201 }
205 } 202 }
206 } 203 }
207 204
208 } // namespace remoting 205 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/client_session.cc ('k') | remoting/host/host_mock_objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698