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

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

Issue 11781003: Connect to DesktopEnvironment's stubs only when audio/video schedulers are about to be created. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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) 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 "base/message_loop.h" 5 #include "base/message_loop.h"
6 #include "remoting/base/auto_thread_task_runner.h" 6 #include "remoting/base/auto_thread_task_runner.h"
7 #include "remoting/base/constants.h" 7 #include "remoting/base/constants.h"
8 #include "remoting/capturer/video_capturer_mock_objects.h" 8 #include "remoting/capturer/video_capturer_mock_objects.h"
9 #include "remoting/capturer/video_frame_capturer_fake.h"
9 #include "remoting/host/audio_capturer.h" 10 #include "remoting/host/audio_capturer.h"
10 #include "remoting/host/client_session.h" 11 #include "remoting/host/client_session.h"
11 #include "remoting/host/desktop_environment.h" 12 #include "remoting/host/desktop_environment.h"
12 #include "remoting/host/host_mock_objects.h" 13 #include "remoting/host/host_mock_objects.h"
13 #include "remoting/protocol/protocol_mock_objects.h" 14 #include "remoting/protocol/protocol_mock_objects.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 16
16 namespace remoting { 17 namespace remoting {
17 18
18 using protocol::MockConnectionToClient; 19 using protocol::MockConnectionToClient;
19 using protocol::MockClientStub; 20 using protocol::MockClientStub;
20 using protocol::MockHostStub; 21 using protocol::MockHostStub;
21 using protocol::MockInputStub; 22 using protocol::MockInputStub;
22 using protocol::MockSession; 23 using protocol::MockSession;
23 using protocol::MockVideoStub; 24 using protocol::MockVideoStub;
24 using protocol::SessionConfig; 25 using protocol::SessionConfig;
25 26
26 using testing::_; 27 using testing::_;
27 using testing::AnyNumber; 28 using testing::AnyNumber;
28 using testing::DeleteArg; 29 using testing::DeleteArg;
30 using testing::DoAll;
29 using testing::Expectation; 31 using testing::Expectation;
30 using testing::InSequence; 32 using testing::InSequence;
31 using testing::Return; 33 using testing::Return;
32 using testing::ReturnRef; 34 using testing::ReturnRef;
33 35
36 namespace {
37
38 ACTION_P2(InjectClipboardEvent, connection, event) {
39 connection->clipboard_stub()->InjectClipboardEvent(event);
40 }
41
42 ACTION_P2(InjectKeyEvent, connection, event) {
43 connection->input_stub()->InjectKeyEvent(event);
44 }
45
46 ACTION_P2(InjectMouseEvent, connection, event) {
47 connection->input_stub()->InjectMouseEvent(event);
48 }
49
50 ACTION_P2(LocalMouseMoved, client_session, event) {
51 client_session->LocalMouseMoved(SkIPoint::Make(event.x(), event.y()));
52 }
53
54 } // namespace
55
34 class ClientSessionTest : public testing::Test { 56 class ClientSessionTest : public testing::Test {
35 public: 57 public:
36 ClientSessionTest() : event_executor_(NULL) {} 58 ClientSessionTest() : event_executor_(NULL) {}
37 59
38 virtual void SetUp() OVERRIDE { 60 virtual void SetUp() OVERRIDE;
39 ui_task_runner_ = new AutoThreadTaskRunner( 61 virtual void TearDown() OVERRIDE;
40 message_loop_.message_loop_proxy(),
41 base::Bind(&ClientSessionTest::QuitMainMessageLoop,
42 base::Unretained(this)));
43 62
44 client_jid_ = "user@domain/rest-of-jid"; 63 // Disconnects the client session.
64 void DisconnectClientSession();
45 65
46 desktop_environment_factory_.reset(new MockDesktopEnvironmentFactory()); 66 // Stops the client session.
47 EXPECT_CALL(*desktop_environment_factory_, CreatePtr()) 67 void StopClientSession();
Wez 2013/01/08 18:34:00 nit: Update this comment to explain what it means
alexeypa (please no reviews) 2013/01/08 20:00:14 Done.
48 .Times(AnyNumber())
49 .WillRepeatedly(Invoke(this,
50 &ClientSessionTest::CreateDesktopEnvironment));
51
52 // Set up a large default screen size that won't affect most tests.
53 screen_size_.set(1000, 1000);
54
55 session_config_ = SessionConfig::ForTest();
56
57 // Mock protocol::Session APIs called directly by ClientSession.
58 protocol::MockSession* session = new MockSession();
59 EXPECT_CALL(*session, config()).WillRepeatedly(ReturnRef(session_config_));
60 EXPECT_CALL(*session, jid()).WillRepeatedly(ReturnRef(client_jid_));
61 EXPECT_CALL(*session, SetEventHandler(_));
62
63 // Mock protocol::ConnectionToClient APIs called directly by ClientSession.
64 // HostStub is not touched by ClientSession, so we can safely pass NULL.
65 scoped_ptr<MockConnectionToClient> connection(
66 new MockConnectionToClient(session, NULL));
67 EXPECT_CALL(*connection, session()).WillRepeatedly(Return(session));
68 EXPECT_CALL(*connection, client_stub())
69 .WillRepeatedly(Return(&client_stub_));
70 EXPECT_CALL(*connection, video_stub()).WillRepeatedly(Return(&video_stub_));
71 EXPECT_CALL(*connection, Disconnect());
72 connection_ = connection.get();
73
74 client_session_ = new ClientSession(
75 &session_event_handler_,
76 ui_task_runner_, // Audio thread.
77 ui_task_runner_, // Capture thread.
78 ui_task_runner_, // Encode thread.
79 ui_task_runner_, // Network thread.
80 connection.PassAs<protocol::ConnectionToClient>(),
81 desktop_environment_factory_.get(),
82 base::TimeDelta());
83 }
84
85 virtual void TearDown() OVERRIDE {
86 // MockClientSessionEventHandler won't trigger Stop, so fake it.
87 client_session_->Stop(base::Bind(
88 &ClientSessionTest::OnClientStopped, base::Unretained(this)));
89
90 // Run message loop before destroying because the session is destroyed
91 // asynchronously.
92 ui_task_runner_ = NULL;
93 message_loop_.Run();
94
95 // Verify that the client session has been stopped.
96 EXPECT_TRUE(client_session_.get() == NULL);
97 }
98 68
99 protected: 69 protected:
100 DesktopEnvironment* CreateDesktopEnvironment() { 70 // Mocks DesktopEnvironmentFactory::Create();
Wez 2013/01/08 18:34:00 nit: Creates a DesktopEnvironment with a fake Vide
alexeypa (please no reviews) 2013/01/08 20:00:14 Done.
101 MockVideoFrameCapturer* capturer = new MockVideoFrameCapturer(); 71 DesktopEnvironment* CreateDesktopEnvironment();
102 EXPECT_CALL(*capturer, Start(_));
103 EXPECT_CALL(*capturer, Stop());
104 EXPECT_CALL(*capturer, InvalidateRegion(_)).Times(AnyNumber());
105 EXPECT_CALL(*capturer, CaptureFrame()).Times(AnyNumber());
106 EXPECT_CALL(*capturer, size_most_recent())
107 .WillRepeatedly(ReturnRef(screen_size_));
108 72
109 EXPECT_TRUE(!event_executor_); 73 // Connects the client session.
Wez 2013/01/08 18:34:00 nit: To what? e.g. does it actually attach a fake
alexeypa (please no reviews) 2013/01/08 20:00:14 Done.
110 event_executor_ = new MockEventExecutor(); 74 void ConnectClientSession();
111 return new DesktopEnvironment(scoped_ptr<AudioCapturer>(NULL),
112 scoped_ptr<EventExecutor>(event_executor_),
113 scoped_ptr<VideoFrameCapturer>(capturer));
114 }
115 75
116 void DisconnectClientSession() { 76 // Quit the message loop.
Wez 2013/01/08 18:34:00 typo: Quit -> Quits nit: What affect does quittin
alexeypa (please no reviews) 2013/01/08 20:00:14 Done.
117 client_session_->Disconnect(); 77 void QuitMainMessageLoop();
118 // MockSession won't trigger OnConnectionClosed, so fake it.
119 client_session_->OnConnectionClosed(client_session_->connection(),
120 protocol::OK);
121 }
122 78
123 void QuitMainMessageLoop() { 79 // Invoked when the client session is fully stopped.
Wez 2013/01/08 18:34:00 nit: What does it do? It seems to just release the
alexeypa (please no reviews) 2013/01/08 20:00:14 Done.
124 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure()); 80 void OnClientStopped();
125 }
126
127 void OnClientStopped() {
128 client_session_ = NULL;
129 }
130 81
131 // Message loop passed to |client_session_| to perform all functions on. 82 // Message loop passed to |client_session_| to perform all functions on.
132 MessageLoop message_loop_; 83 MessageLoop message_loop_;
133 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_; 84 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_;
134 85
135 // ClientSession instance under test. 86 // ClientSession instance under test.
136 scoped_refptr<ClientSession> client_session_; 87 scoped_refptr<ClientSession> client_session_;
137 88
138 // ClientSession::EventHandler mock for use in tests. 89 // ClientSession::EventHandler mock for use in tests.
139 MockClientSessionEventHandler session_event_handler_; 90 MockClientSessionEventHandler session_event_handler_;
140 91
141 // Screen size that the fake VideoFrameCapturer should report.
142 SkISize screen_size_;
143
144 // Storage for values to be returned by the protocol::Session mock. 92 // Storage for values to be returned by the protocol::Session mock.
145 SessionConfig session_config_; 93 SessionConfig session_config_;
146 std::string client_jid_; 94 std::string client_jid_;
147 95
148 // Stubs returned to |client_session_| components by |connection_|. 96 // Stubs returned to |client_session_| components by |connection_|.
149 MockClientStub client_stub_; 97 MockClientStub client_stub_;
150 MockVideoStub video_stub_; 98 MockVideoStub video_stub_;
151 99
152 // DesktopEnvironment owns |event_executor_|, but input injection tests need 100 // DesktopEnvironment owns |event_executor_|, but input injection tests need
153 // to express expectations on it. 101 // to express expectations on it.
154 MockEventExecutor* event_executor_; 102 MockEventExecutor* event_executor_;
155 103
156 // ClientSession owns |connection_| but tests need it to inject fake events. 104 // ClientSession owns |connection_| but tests need it to inject fake events.
157 MockConnectionToClient* connection_; 105 MockConnectionToClient* connection_;
158 106
159 scoped_ptr<MockDesktopEnvironmentFactory> desktop_environment_factory_; 107 scoped_ptr<MockDesktopEnvironmentFactory> desktop_environment_factory_;
160 }; 108 };
161 109
110 void ClientSessionTest::SetUp() {
111 ui_task_runner_ = new AutoThreadTaskRunner(
Wez 2013/01/08 18:34:00 nit: Add some basic comments, e.g. "Arrange to run
alexeypa (please no reviews) 2013/01/08 20:00:14 Done.
112 message_loop_.message_loop_proxy(),
113 base::Bind(&ClientSessionTest::QuitMainMessageLoop,
114 base::Unretained(this)));
115
116 client_jid_ = "user@domain/rest-of-jid";
Wez 2013/01/08 18:34:00 This doesn't ever seem to be set to any other valu
alexeypa (please no reviews) 2013/01/08 20:00:14 It has to be a member variable. It is not a POD ty
Wez 2013/01/08 21:02:42 Ah, OK. Could it be a const member, initialized i
117
118 desktop_environment_factory_.reset(new MockDesktopEnvironmentFactory());
119 EXPECT_CALL(*desktop_environment_factory_, CreatePtr())
120 .Times(AnyNumber())
121 .WillRepeatedly(Invoke(this,
122 &ClientSessionTest::CreateDesktopEnvironment));
123
124 session_config_ = SessionConfig::ForTest();
125
126 // Mock protocol::Session APIs called directly by ClientSession.
127 protocol::MockSession* session = new MockSession();
128 EXPECT_CALL(*session, config()).WillRepeatedly(ReturnRef(session_config_));
129 EXPECT_CALL(*session, jid()).WillRepeatedly(ReturnRef(client_jid_));
130 EXPECT_CALL(*session, SetEventHandler(_));
131
132 // Mock protocol::ConnectionToClient APIs called directly by ClientSession.
133 // HostStub is not touched by ClientSession, so we can safely pass NULL.
134 scoped_ptr<MockConnectionToClient> connection(
135 new MockConnectionToClient(session, NULL));
136 EXPECT_CALL(*connection, session()).WillRepeatedly(Return(session));
137 EXPECT_CALL(*connection, client_stub())
138 .WillRepeatedly(Return(&client_stub_));
139 EXPECT_CALL(*connection, video_stub()).WillRepeatedly(Return(&video_stub_));
140 EXPECT_CALL(*connection, Disconnect());
141 connection_ = connection.get();
142
143 client_session_ = new ClientSession(
144 &session_event_handler_,
145 ui_task_runner_, // Audio thread.
146 ui_task_runner_, // Capture thread.
147 ui_task_runner_, // Encode thread.
148 ui_task_runner_, // Network thread.
149 connection.PassAs<protocol::ConnectionToClient>(),
150 desktop_environment_factory_.get(),
151 base::TimeDelta());
152 ui_task_runner_ = NULL;
Wez 2013/01/08 18:34:00 Looks like ui_task_runner_ doesn't need to be a me
alexeypa (please no reviews) 2013/01/08 20:00:14 Done.
alexeypa (please no reviews) 2013/01/08 21:30:24 Done.
153 }
154
155 void ClientSessionTest::TearDown() {
156 // Verify that the client session has been stopped.
157 EXPECT_TRUE(client_session_.get() == NULL);
158 }
159
160 void ClientSessionTest::DisconnectClientSession() {
161 client_session_->Disconnect();
162 // MockSession won't trigger OnConnectionClosed, so fake it.
163 client_session_->OnConnectionClosed(client_session_->connection(),
164 protocol::OK);
165 }
166
167 void ClientSessionTest::StopClientSession() {
168 // MockClientSessionEventHandler won't trigger Stop, so fake it.
169 client_session_->Stop(base::Bind(
170 &ClientSessionTest::OnClientStopped, base::Unretained(this)));
171 }
172
173 DesktopEnvironment* ClientSessionTest::CreateDesktopEnvironment() {
174 scoped_ptr<VideoFrameCapturer> video_capturer(new VideoFrameCapturerFake());
175
176 EXPECT_TRUE(!event_executor_);
177 event_executor_ = new MockEventExecutor();
178 return new DesktopEnvironment(scoped_ptr<AudioCapturer>(NULL),
179 scoped_ptr<EventExecutor>(event_executor_),
180 video_capturer.Pass());
181 }
182
183 void ClientSessionTest::ConnectClientSession() {
184 client_session_->OnConnectionAuthenticated(client_session_->connection());
185 client_session_->OnConnectionChannelsConnected(client_session_->connection());
186 }
187
188 void ClientSessionTest::QuitMainMessageLoop() {
189 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure());
190 }
191
192 void ClientSessionTest::OnClientStopped() {
193 client_session_ = NULL;
194 }
195
162 MATCHER_P2(EqualsClipboardEvent, m, d, "") { 196 MATCHER_P2(EqualsClipboardEvent, m, d, "") {
163 return (strcmp(arg.mime_type().c_str(), m) == 0 && 197 return (strcmp(arg.mime_type().c_str(), m) == 0 &&
164 memcmp(arg.data().data(), d, arg.data().size()) == 0); 198 memcmp(arg.data().data(), d, arg.data().size()) == 0);
165 } 199 }
166 200
167 TEST_F(ClientSessionTest, ClipboardStubFilter) { 201 TEST_F(ClientSessionTest, ClipboardStubFilter) {
168 protocol::ClipboardEvent clipboard_event1; 202 protocol::ClipboardEvent clipboard_event1;
169 clipboard_event1.set_mime_type(kMimeTypeTextUtf8); 203 clipboard_event1.set_mime_type(kMimeTypeTextUtf8);
170 clipboard_event1.set_data("a"); 204 clipboard_event1.set_data("a");
171 205
172 protocol::ClipboardEvent clipboard_event2; 206 protocol::ClipboardEvent clipboard_event2;
173 clipboard_event2.set_mime_type(kMimeTypeTextUtf8); 207 clipboard_event2.set_mime_type(kMimeTypeTextUtf8);
174 clipboard_event2.set_data("b"); 208 clipboard_event2.set_data("b");
175 209
176 protocol::ClipboardEvent clipboard_event3; 210 protocol::ClipboardEvent clipboard_event3;
177 clipboard_event3.set_mime_type(kMimeTypeTextUtf8); 211 clipboard_event3.set_mime_type(kMimeTypeTextUtf8);
178 clipboard_event3.set_data("c"); 212 clipboard_event3.set_data("c");
179 213
180 InSequence s; 214 InSequence s;
181 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); 215 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_));
182 EXPECT_CALL(*event_executor_, StartPtr(_)); 216 EXPECT_CALL(*event_executor_, StartPtr(_));
183 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); 217 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_));
218 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _))
Wez 2013/01/08 18:34:00 nit: Consider adding a comment to explain that thi
alexeypa (please no reviews) 2013/01/08 20:00:14 Done.
219 .WillOnce(DoAll(
220 // This event should get through to the clipboard stub.
221 InjectClipboardEvent(connection_, clipboard_event2),
222 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession),
223 // This event should not get through to the clipboard stub,
224 // because the client has disconnected.
225 InjectClipboardEvent(connection_, clipboard_event3),
226 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession)));
184 EXPECT_CALL(*event_executor_, InjectClipboardEvent(EqualsClipboardEvent( 227 EXPECT_CALL(*event_executor_, InjectClipboardEvent(EqualsClipboardEvent(
185 kMimeTypeTextUtf8, "b"))); 228 kMimeTypeTextUtf8, "b")));
186 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); 229 EXPECT_CALL(session_event_handler_, OnSessionClosed(_));
187 230
188 // This event should not get through to the clipboard stub, 231 // This event should not get through to the clipboard stub,
189 // because the client isn't authenticated yet. 232 // because the client isn't authenticated yet.
190 connection_->clipboard_stub()->InjectClipboardEvent(clipboard_event1); 233 connection_->clipboard_stub()->InjectClipboardEvent(clipboard_event1);
191 client_session_->OnConnectionAuthenticated(client_session_->connection()); 234
192 client_session_->OnConnectionChannelsConnected(client_session_->connection()); 235 ConnectClientSession();
193 // This event should get through to the clipboard stub. 236 message_loop_.Run();
194 connection_->clipboard_stub()->InjectClipboardEvent(clipboard_event2);
195 DisconnectClientSession();
196 // This event should not get through to the clipboard stub,
197 // because the client has disconnected.
198 connection_->clipboard_stub()->InjectClipboardEvent(clipboard_event3);
199 } 237 }
200 238
201 MATCHER_P2(EqualsUsbEvent, usb_keycode, pressed, "") { 239 MATCHER_P2(EqualsUsbEvent, usb_keycode, pressed, "") {
202 return arg.usb_keycode() == (unsigned int)usb_keycode && 240 return arg.usb_keycode() == (unsigned int)usb_keycode &&
203 arg.pressed() == pressed; 241 arg.pressed() == pressed;
204 } 242 }
205 243
206 MATCHER_P2(EqualsMouseEvent, x, y, "") { 244 MATCHER_P2(EqualsMouseEvent, x, y, "") {
207 return arg.x() == x && arg.y() == y; 245 return arg.x() == x && arg.y() == y;
208 } 246 }
(...skipping 28 matching lines...) Expand all
237 mouse_event2.set_y(201); 275 mouse_event2.set_y(201);
238 276
239 protocol::MouseEvent mouse_event3; 277 protocol::MouseEvent mouse_event3;
240 mouse_event3.set_x(300); 278 mouse_event3.set_x(300);
241 mouse_event3.set_y(301); 279 mouse_event3.set_y(301);
242 280
243 InSequence s; 281 InSequence s;
244 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); 282 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_));
245 EXPECT_CALL(*event_executor_, StartPtr(_)); 283 EXPECT_CALL(*event_executor_, StartPtr(_));
246 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); 284 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_));
285 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _))
286 .WillOnce(DoAll(
287 // These events should get through to the input stub.
288 InjectKeyEvent(connection_, key_event2_down),
289 InjectKeyEvent(connection_, key_event2_up),
290 InjectMouseEvent(connection_, mouse_event2),
291 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession),
292 // These events should not get through to the input stub,
293 // because the client has disconnected.
294 InjectKeyEvent(connection_, key_event3),
295 InjectMouseEvent(connection_, mouse_event3),
296 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession)));
247 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, true))); 297 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, true)));
248 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, false))); 298 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, false)));
249 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseEvent(200, 201))); 299 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseEvent(200, 201)));
250 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); 300 EXPECT_CALL(session_event_handler_, OnSessionClosed(_));
251 301
252 // These events should not get through to the input stub, 302 // These events should not get through to the input stub,
253 // because the client isn't authenticated yet. 303 // because the client isn't authenticated yet.
254 connection_->input_stub()->InjectKeyEvent(key_event1); 304 connection_->input_stub()->InjectKeyEvent(key_event1);
255 connection_->input_stub()->InjectMouseEvent(mouse_event1); 305 connection_->input_stub()->InjectMouseEvent(mouse_event1);
256 client_session_->OnConnectionAuthenticated(client_session_->connection()); 306
257 client_session_->OnConnectionChannelsConnected(client_session_->connection()); 307 ConnectClientSession();
258 // These events should get through to the input stub. 308 message_loop_.Run();
259 connection_->input_stub()->InjectKeyEvent(key_event2_down);
260 connection_->input_stub()->InjectKeyEvent(key_event2_up);
261 connection_->input_stub()->InjectMouseEvent(mouse_event2);
262 DisconnectClientSession();
263 // These events should not get through to the input stub,
264 // because the client has disconnected.
265 connection_->input_stub()->InjectKeyEvent(key_event3);
266 connection_->input_stub()->InjectMouseEvent(mouse_event3);
267 } 309 }
268 310
269 TEST_F(ClientSessionTest, LocalInputTest) { 311 TEST_F(ClientSessionTest, LocalInputTest) {
270 protocol::MouseEvent mouse_event1; 312 protocol::MouseEvent mouse_event1;
271 mouse_event1.set_x(100); 313 mouse_event1.set_x(100);
272 mouse_event1.set_y(101); 314 mouse_event1.set_y(101);
273 protocol::MouseEvent mouse_event2; 315 protocol::MouseEvent mouse_event2;
274 mouse_event2.set_x(200); 316 mouse_event2.set_x(200);
275 mouse_event2.set_y(201); 317 mouse_event2.set_y(201);
276 protocol::MouseEvent mouse_event3; 318 protocol::MouseEvent mouse_event3;
277 mouse_event3.set_x(300); 319 mouse_event3.set_x(300);
278 mouse_event3.set_y(301); 320 mouse_event3.set_y(301);
279 321
280 InSequence s; 322 InSequence s;
281 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); 323 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_));
282 EXPECT_CALL(*event_executor_, StartPtr(_)); 324 EXPECT_CALL(*event_executor_, StartPtr(_));
283 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); 325 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_));
326 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _))
327 .WillOnce(DoAll(
328 // This event should get through to the input stub.
329 InjectMouseEvent(connection_, mouse_event1),
330 // This one should too because the local event echoes the remote one.
331 LocalMouseMoved(client_session_.get(), mouse_event1),
332 InjectMouseEvent(connection_, mouse_event2),
333 // This one should not.
334 LocalMouseMoved(client_session_.get(), mouse_event1),
335 InjectMouseEvent(connection_, mouse_event3),
336 // TODO(jamiewalch): Verify that remote inputs are re-enabled
337 // eventually (via dependency injection, not sleep!)
338 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession),
339 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession)));
284 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseEvent(100, 101))); 340 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseEvent(100, 101)));
285 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseEvent(200, 201))); 341 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseEvent(200, 201)));
286 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); 342 EXPECT_CALL(session_event_handler_, OnSessionClosed(_));
287 343
288 client_session_->OnConnectionAuthenticated(client_session_->connection()); 344 ConnectClientSession();
289 client_session_->OnConnectionChannelsConnected(client_session_->connection()); 345 message_loop_.Run();
290 // This event should get through to the input stub.
291 connection_->input_stub()->InjectMouseEvent(mouse_event1);
292 // This one should too because the local event echoes the remote one.
293 client_session_->LocalMouseMoved(SkIPoint::Make(mouse_event1.x(),
294 mouse_event1.y()));
295 connection_->input_stub()->InjectMouseEvent(mouse_event2);
296 // This one should not.
297 client_session_->LocalMouseMoved(SkIPoint::Make(mouse_event1.x(),
298 mouse_event1.y()));
299 connection_->input_stub()->InjectMouseEvent(mouse_event3);
300 // TODO(jamiewalch): Verify that remote inputs are re-enabled eventually
301 // (via dependency injection, not sleep!)
302 DisconnectClientSession();
303 } 346 }
304 347
305 TEST_F(ClientSessionTest, RestoreEventState) { 348 TEST_F(ClientSessionTest, RestoreEventState) {
306 protocol::KeyEvent key1; 349 protocol::KeyEvent key1;
307 key1.set_pressed(true); 350 key1.set_pressed(true);
308 key1.set_usb_keycode(1); 351 key1.set_usb_keycode(1);
309 352
310 protocol::KeyEvent key2; 353 protocol::KeyEvent key2;
311 key2.set_pressed(true); 354 key2.set_pressed(true);
312 key2.set_usb_keycode(2); 355 key2.set_usb_keycode(2);
313 356
314 protocol::MouseEvent mousedown; 357 protocol::MouseEvent mousedown;
315 mousedown.set_button(protocol::MouseEvent::BUTTON_LEFT); 358 mousedown.set_button(protocol::MouseEvent::BUTTON_LEFT);
316 mousedown.set_button_down(true); 359 mousedown.set_button_down(true);
317 360
318 InSequence s; 361 InSequence s;
319 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); 362 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_));
320 EXPECT_CALL(*event_executor_, StartPtr(_)); 363 EXPECT_CALL(*event_executor_, StartPtr(_));
321 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); 364 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_));
365 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _))
366 .WillOnce(DoAll(
367 InjectKeyEvent(connection_, key1),
368 InjectKeyEvent(connection_, key2),
369 InjectMouseEvent(connection_, mousedown),
370 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession),
371 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession)));
322 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(1, true))); 372 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(1, true)));
323 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, true))); 373 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, true)));
324 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseButtonEvent( 374 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseButtonEvent(
325 protocol::MouseEvent::BUTTON_LEFT, true))); 375 protocol::MouseEvent::BUTTON_LEFT, true)));
326 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(1, false))); 376 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(1, false)));
327 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, false))); 377 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, false)));
328 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseButtonEvent( 378 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseButtonEvent(
329 protocol::MouseEvent::BUTTON_LEFT, false))); 379 protocol::MouseEvent::BUTTON_LEFT, false)));
330 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); 380 EXPECT_CALL(session_event_handler_, OnSessionClosed(_));
331 381
332 client_session_->OnConnectionAuthenticated(client_session_->connection()); 382 ConnectClientSession();
333 client_session_->OnConnectionChannelsConnected(client_session_->connection()); 383 message_loop_.Run();
334
335 connection_->input_stub()->InjectKeyEvent(key1);
336 connection_->input_stub()->InjectKeyEvent(key2);
337 connection_->input_stub()->InjectMouseEvent(mousedown);
338
339 DisconnectClientSession();
340 } 384 }
341 385
342 TEST_F(ClientSessionTest, ClampMouseEvents) { 386 TEST_F(ClientSessionTest, ClampMouseEvents) {
343 screen_size_.set(200, 100);
344
345 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); 387 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_));
346 EXPECT_CALL(*event_executor_, StartPtr(_)); 388 EXPECT_CALL(*event_executor_, StartPtr(_));
347 Expectation connected = 389 Expectation connected =
348 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); 390 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_));
349 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); 391 EXPECT_CALL(session_event_handler_, OnSessionClosed(_));
350 392
351 client_session_->OnConnectionAuthenticated(client_session_->connection()); 393 int input_x[3] = { -999, 100, 999 };
352 client_session_->OnConnectionChannelsConnected(client_session_->connection()); 394 int expected_x[3] = { 0, 100, VideoFrameCapturerFake::kWidth - 1 };
395 int input_y[3] = { -999, 50, 999 };
396 int expected_y[3] = { 0, 50, VideoFrameCapturerFake::kHeight - 1 };
353 397
354 int input_x[3] = { -999, 100, 999 }; 398 // Inject the 1st event after once a video packet has been received.
Wez 2013/01/08 18:34:00 typo: "... after once ..."
alexeypa (please no reviews) 2013/01/08 20:00:14 Done.
355 int expected_x[3] = { 0, 100, 199 }; 399 protocol::MouseEvent injected_event;
356 int input_y[3] = { -999, 50, 999 }; 400 injected_event.set_x(input_x[0]);
357 int expected_y[3] = { 0, 50, 99 }; 401 injected_event.set_y(input_y[0]);
402 connected =
403 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _))
404 .After(connected)
405 .WillOnce(InjectMouseEvent(connection_, injected_event));
358 406
359 protocol::MouseEvent event; 407 protocol::MouseEvent expected_event;
360 for (int j = 0; j < 3; j++) { 408 for (int j = 0; j < 3; j++) {
361 for (int i = 0; i < 3; i++) { 409 for (int i = 0; i < 3; i++) {
362 event.set_x(input_x[i]); 410 // Skip the first iteration since the 1st event has been injected already.
363 event.set_y(input_y[j]); 411 if (i > 0 || j > 0) {
364 connected = 412 injected_event.set_x(input_x[i]);
365 EXPECT_CALL(*event_executor_, 413 injected_event.set_y(input_y[j]);
366 InjectMouseEvent(EqualsMouseEvent(expected_x[i], 414 connected =
367 expected_y[j]))) 415 EXPECT_CALL(*event_executor_,
368 .After(connected); 416 InjectMouseEvent(EqualsMouseEvent(expected_event.x(),
369 connection_->input_stub()->InjectMouseEvent(event); 417 expected_event.y())))
418 .After(connected)
419 .WillOnce(InjectMouseEvent(connection_, injected_event));
420 }
421
422 expected_event.set_x(expected_x[i]);
423 expected_event.set_y(expected_y[j]);
370 } 424 }
371 } 425 }
372 426
373 DisconnectClientSession(); 427 // Shutdown the connection once the last event has been received.
428 EXPECT_CALL(*event_executor_,
429 InjectMouseEvent(EqualsMouseEvent(expected_event.x(),
430 expected_event.y())))
431 .After(connected)
432 .WillOnce(DoAll(
433 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession),
434 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession)));
435
436 ConnectClientSession();
437 message_loop_.Run();
374 } 438 }
375 439
376 } // namespace remoting 440 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698