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

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

Issue 9646013: Add the plumbing that will carry a clipboard item from a chromoting client to a host. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix remoting_simple_host. 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
« no previous file with comments | « remoting/host/client_session.cc ('k') | remoting/host/desktop_environment.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/base/constants.h"
5 #include "remoting/host/client_session.h" 6 #include "remoting/host/client_session.h"
6 #include "remoting/host/host_mock_objects.h" 7 #include "remoting/host/host_mock_objects.h"
7 #include "remoting/protocol/protocol_mock_objects.h" 8 #include "remoting/protocol/protocol_mock_objects.h"
8 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
9 10
10 namespace remoting { 11 namespace remoting {
11 12
12 using protocol::MockConnectionToClient; 13 using protocol::MockConnectionToClient;
13 using protocol::MockConnectionToClientEventHandler; 14 using protocol::MockConnectionToClientEventHandler;
14 using protocol::MockHostStub; 15 using protocol::MockHostStub;
15 using protocol::MockInputStub; 16 using protocol::MockHostEventStub;
16 using protocol::MockSession; 17 using protocol::MockSession;
17 18
18 using testing::_; 19 using testing::_;
19 using testing::DeleteArg; 20 using testing::DeleteArg;
20 using testing::InSequence; 21 using testing::InSequence;
21 using testing::Return; 22 using testing::Return;
22 using testing::ReturnRef; 23 using testing::ReturnRef;
23 24
24 class ClientSessionTest : public testing::Test { 25 class ClientSessionTest : public testing::Test {
25 public: 26 public:
26 ClientSessionTest() {} 27 ClientSessionTest() {}
27 28
28 virtual void SetUp() OVERRIDE { 29 virtual void SetUp() OVERRIDE {
29 client_jid_ = "user@domain/rest-of-jid"; 30 client_jid_ = "user@domain/rest-of-jid";
30 31
31 // Set up a large default screen size that won't affect most tests. 32 // Set up a large default screen size that won't affect most tests.
32 default_screen_size_.set(1000, 1000); 33 default_screen_size_.set(1000, 1000);
33 EXPECT_CALL(capturer_, size_most_recent()) 34 EXPECT_CALL(capturer_, size_most_recent())
34 .WillRepeatedly(ReturnRef(default_screen_size_)); 35 .WillRepeatedly(ReturnRef(default_screen_size_));
35 36
36 protocol::MockSession* session = new MockSession(); 37 protocol::MockSession* session = new MockSession();
37 EXPECT_CALL(*session, jid()).WillRepeatedly(ReturnRef(client_jid_)); 38 EXPECT_CALL(*session, jid()).WillRepeatedly(ReturnRef(client_jid_));
38 EXPECT_CALL(*session, SetStateChangeCallback(_)); 39 EXPECT_CALL(*session, SetStateChangeCallback(_));
39 40
40 client_session_.reset(new ClientSession( 41 client_session_.reset(new ClientSession(
41 &session_event_handler_, 42 &session_event_handler_,
42 new protocol::ConnectionToClient(session), 43 new protocol::ConnectionToClient(session),
43 &input_stub_, &capturer_)); 44 &host_event_stub_, &capturer_));
44 } 45 }
45 46
46 virtual void TearDown() OVERRIDE { 47 virtual void TearDown() OVERRIDE {
47 client_session_.reset(); 48 client_session_.reset();
48 // Run message loop before destroying because protocol::Session is 49 // Run message loop before destroying because protocol::Session is
49 // destroyed asynchronously. 50 // destroyed asynchronously.
50 message_loop_.RunAllPending(); 51 message_loop_.RunAllPending();
51 } 52 }
52 53
53 protected: 54 protected:
54 SkISize default_screen_size_; 55 SkISize default_screen_size_;
55 MessageLoop message_loop_; 56 MessageLoop message_loop_;
56 std::string client_jid_; 57 std::string client_jid_;
57 MockHostStub host_stub_; 58 MockHostStub host_stub_;
58 MockInputStub input_stub_; 59 MockHostEventStub host_event_stub_;
59 MockCapturer capturer_; 60 MockCapturer capturer_;
60 MockClientSessionEventHandler session_event_handler_; 61 MockClientSessionEventHandler session_event_handler_;
61 scoped_ptr<ClientSession> client_session_; 62 scoped_ptr<ClientSession> client_session_;
62 }; 63 };
63 64
65 MATCHER_P2(EqualsClipboardEvent, m, d, "") {
66 return (strcmp(arg.mime_type().c_str(), m) == 0 &&
67 memcmp(arg.data().data(), d, arg.data().size()) == 0);
68 }
69
70 TEST_F(ClientSessionTest, ClipboardStubFilter) {
71 protocol::ClipboardEvent clipboard_event1;
72 clipboard_event1.set_mime_type(kMimeTypeText);
73 clipboard_event1.set_data("a");
74
75 protocol::ClipboardEvent clipboard_event2;
76 clipboard_event2.set_mime_type(kMimeTypeText);
77 clipboard_event2.set_data("b");
78
79 protocol::ClipboardEvent clipboard_event3;
80 clipboard_event3.set_mime_type(kMimeTypeText);
81 clipboard_event3.set_data("c");
82
83 InSequence s;
84 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_));
85 EXPECT_CALL(host_event_stub_, InjectClipboardEvent(EqualsClipboardEvent(
86 kMimeTypeText, "b")));
87
88 // This event should not get through to the clipboard stub,
89 // because the client isn't authenticated yet.
90 client_session_->InjectClipboardEvent(clipboard_event1);
91 client_session_->OnConnectionOpened(client_session_->connection());
92 // This event should get through to the clipboard stub.
93 client_session_->InjectClipboardEvent(clipboard_event2);
94 client_session_->Disconnect();
95 // This event should not get through to the clipboard stub,
96 // because the client has disconnected.
97 client_session_->InjectClipboardEvent(clipboard_event3);
98 }
99
64 MATCHER_P2(EqualsKeyEvent, keycode, pressed, "") { 100 MATCHER_P2(EqualsKeyEvent, keycode, pressed, "") {
65 return arg.keycode() == keycode && arg.pressed() == pressed; 101 return arg.keycode() == keycode && arg.pressed() == pressed;
66 } 102 }
67 103
68 MATCHER_P2(EqualsMouseEvent, x, y, "") { 104 MATCHER_P2(EqualsMouseEvent, x, y, "") {
69 return arg.x() == x && arg.y() == y; 105 return arg.x() == x && arg.y() == y;
70 } 106 }
71 107
72 MATCHER_P(EqualsMouseUpEvent, button, "") { 108 MATCHER_P(EqualsMouseUpEvent, button, "") {
73 return arg.button() == button && !arg.button_down(); 109 return arg.button() == button && !arg.button_down();
(...skipping 23 matching lines...) Expand all
97 protocol::MouseEvent mouse_event2; 133 protocol::MouseEvent mouse_event2;
98 mouse_event2.set_x(200); 134 mouse_event2.set_x(200);
99 mouse_event2.set_y(201); 135 mouse_event2.set_y(201);
100 136
101 protocol::MouseEvent mouse_event3; 137 protocol::MouseEvent mouse_event3;
102 mouse_event3.set_x(300); 138 mouse_event3.set_x(300);
103 mouse_event3.set_y(301); 139 mouse_event3.set_y(301);
104 140
105 InSequence s; 141 InSequence s;
106 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); 142 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_));
107 EXPECT_CALL(input_stub_, InjectKeyEvent(EqualsKeyEvent(2, true))); 143 EXPECT_CALL(host_event_stub_, InjectKeyEvent(EqualsKeyEvent(2, true)));
108 EXPECT_CALL(input_stub_, InjectKeyEvent(EqualsKeyEvent(2, false))); 144 EXPECT_CALL(host_event_stub_, InjectKeyEvent(EqualsKeyEvent(2, false)));
109 EXPECT_CALL(input_stub_, InjectMouseEvent(EqualsMouseEvent(200, 201))); 145 EXPECT_CALL(host_event_stub_, InjectMouseEvent(EqualsMouseEvent(200, 201)));
110 146
111 // These events should not get through to the input stub, 147 // These events should not get through to the input stub,
112 // because the client isn't authenticated yet. 148 // because the client isn't authenticated yet.
113 client_session_->InjectKeyEvent(key_event1); 149 client_session_->InjectKeyEvent(key_event1);
114 client_session_->InjectMouseEvent(mouse_event1); 150 client_session_->InjectMouseEvent(mouse_event1);
115 client_session_->OnConnectionOpened(client_session_->connection()); 151 client_session_->OnConnectionOpened(client_session_->connection());
116 // These events should get through to the input stub. 152 // These events should get through to the input stub.
117 client_session_->InjectKeyEvent(key_event2_down); 153 client_session_->InjectKeyEvent(key_event2_down);
118 client_session_->InjectKeyEvent(key_event2_up); 154 client_session_->InjectKeyEvent(key_event2_up);
119 client_session_->InjectMouseEvent(mouse_event2); 155 client_session_->InjectMouseEvent(mouse_event2);
(...skipping 11 matching lines...) Expand all
131 protocol::MouseEvent mouse_event2; 167 protocol::MouseEvent mouse_event2;
132 mouse_event2.set_x(200); 168 mouse_event2.set_x(200);
133 mouse_event2.set_y(201); 169 mouse_event2.set_y(201);
134 protocol::MouseEvent mouse_event3; 170 protocol::MouseEvent mouse_event3;
135 mouse_event3.set_x(300); 171 mouse_event3.set_x(300);
136 mouse_event3.set_y(301); 172 mouse_event3.set_y(301);
137 173
138 InSequence s; 174 InSequence s;
139 EXPECT_CALL(session_event_handler_, 175 EXPECT_CALL(session_event_handler_,
140 OnSessionAuthenticated(client_session_.get())); 176 OnSessionAuthenticated(client_session_.get()));
141 EXPECT_CALL(input_stub_, InjectMouseEvent(EqualsMouseEvent(100, 101))); 177 EXPECT_CALL(host_event_stub_, InjectMouseEvent(EqualsMouseEvent(100, 101)));
142 EXPECT_CALL(input_stub_, InjectMouseEvent(EqualsMouseEvent(200, 201))); 178 EXPECT_CALL(host_event_stub_, InjectMouseEvent(EqualsMouseEvent(200, 201)));
143 179
144 client_session_->OnConnectionOpened(client_session_->connection()); 180 client_session_->OnConnectionOpened(client_session_->connection());
145 // This event should get through to the input stub. 181 // This event should get through to the input stub.
146 client_session_->InjectMouseEvent(mouse_event1); 182 client_session_->InjectMouseEvent(mouse_event1);
147 // This one should too because the local event echoes the remote one. 183 // This one should too because the local event echoes the remote one.
148 client_session_->LocalMouseMoved(SkIPoint::Make(mouse_event1.x(), 184 client_session_->LocalMouseMoved(SkIPoint::Make(mouse_event1.x(),
149 mouse_event1.y())); 185 mouse_event1.y()));
150 client_session_->InjectMouseEvent(mouse_event2); 186 client_session_->InjectMouseEvent(mouse_event2);
151 // This one should not. 187 // This one should not.
152 client_session_->LocalMouseMoved(SkIPoint::Make(mouse_event1.x(), 188 client_session_->LocalMouseMoved(SkIPoint::Make(mouse_event1.x(),
(...skipping 14 matching lines...) Expand all
167 key2.set_keycode(2); 203 key2.set_keycode(2);
168 204
169 protocol::MouseEvent mousedown; 205 protocol::MouseEvent mousedown;
170 mousedown.set_button(protocol::MouseEvent::BUTTON_LEFT); 206 mousedown.set_button(protocol::MouseEvent::BUTTON_LEFT);
171 mousedown.set_button_down(true); 207 mousedown.set_button_down(true);
172 208
173 client_session_->RecordKeyEvent(key1); 209 client_session_->RecordKeyEvent(key1);
174 client_session_->RecordKeyEvent(key2); 210 client_session_->RecordKeyEvent(key2);
175 client_session_->RecordMouseButtonState(mousedown); 211 client_session_->RecordMouseButtonState(mousedown);
176 212
177 EXPECT_CALL(input_stub_, InjectKeyEvent(EqualsKeyEvent(1, false))); 213 EXPECT_CALL(host_event_stub_, InjectKeyEvent(EqualsKeyEvent(1, false)));
178 EXPECT_CALL(input_stub_, InjectKeyEvent(EqualsKeyEvent(2, false))); 214 EXPECT_CALL(host_event_stub_, InjectKeyEvent(EqualsKeyEvent(2, false)));
179 EXPECT_CALL(input_stub_, InjectMouseEvent(EqualsMouseUpEvent( 215 EXPECT_CALL(host_event_stub_, InjectMouseEvent(EqualsMouseUpEvent(
180 protocol::MouseEvent::BUTTON_LEFT))); 216 protocol::MouseEvent::BUTTON_LEFT)));
181 217
182 client_session_->RestoreEventState(); 218 client_session_->RestoreEventState();
183 } 219 }
184 220
185 TEST_F(ClientSessionTest, ClampMouseEvents) { 221 TEST_F(ClientSessionTest, ClampMouseEvents) {
186 SkISize screen(SkISize::Make(200, 100)); 222 SkISize screen(SkISize::Make(200, 100));
187 EXPECT_CALL(capturer_, size_most_recent()) 223 EXPECT_CALL(capturer_, size_most_recent())
188 .WillRepeatedly(ReturnRef(screen)); 224 .WillRepeatedly(ReturnRef(screen));
189 225
190 EXPECT_CALL(session_event_handler_, 226 EXPECT_CALL(session_event_handler_,
191 OnSessionAuthenticated(client_session_.get())); 227 OnSessionAuthenticated(client_session_.get()));
192 client_session_->OnConnectionOpened(client_session_->connection()); 228 client_session_->OnConnectionOpened(client_session_->connection());
193 229
194 int input_x[3] = { -999, 100, 999 }; 230 int input_x[3] = { -999, 100, 999 };
195 int expected_x[3] = { 0, 100, 199 }; 231 int expected_x[3] = { 0, 100, 199 };
196 int input_y[3] = { -999, 50, 999 }; 232 int input_y[3] = { -999, 50, 999 };
197 int expected_y[3] = { 0, 50, 99 }; 233 int expected_y[3] = { 0, 50, 99 };
198 234
199 protocol::MouseEvent event; 235 protocol::MouseEvent event;
200 for (int j = 0; j < 3; j++) { 236 for (int j = 0; j < 3; j++) {
201 for (int i = 0; i < 3; i++) { 237 for (int i = 0; i < 3; i++) {
202 event.set_x(input_x[i]); 238 event.set_x(input_x[i]);
203 event.set_y(input_y[j]); 239 event.set_y(input_y[j]);
204 EXPECT_CALL(input_stub_, InjectMouseEvent(EqualsMouseEvent( 240 EXPECT_CALL(host_event_stub_, InjectMouseEvent(EqualsMouseEvent(
205 expected_x[i], expected_y[j]))); 241 expected_x[i], expected_y[j])));
206 client_session_->InjectMouseEvent(event); 242 client_session_->InjectMouseEvent(event);
207 } 243 }
208 } 244 }
209 } 245 }
210 246
211 } // namespace remoting 247 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/client_session.cc ('k') | remoting/host/desktop_environment.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698