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

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: 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 {
11 11
12 using protocol::MockClipboardStub;
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::MockInputStub;
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;
(...skipping 11 matching lines...) Expand all
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 &clipboard_stub_, &input_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_;
58 MockClipboardStub clipboard_stub_;
57 MockHostStub host_stub_; 59 MockHostStub host_stub_;
58 MockInputStub input_stub_; 60 MockInputStub input_stub_;
59 MockCapturer capturer_; 61 MockCapturer capturer_;
60 MockClientSessionEventHandler session_event_handler_; 62 MockClientSessionEventHandler session_event_handler_;
61 scoped_ptr<ClientSession> client_session_; 63 scoped_ptr<ClientSession> client_session_;
62 }; 64 };
63 65
66 MATCHER_P2(EqualsClipboardEvent, t, d, "") {
67 return (arg.datatype() == t && memcmp(arg.data().data(), d, strlen(d)) == 0);
68 }
69
70 TEST_F(ClientSessionTest, ClipboardStubFilter) {
71 protocol::ClipboardEvent clipboard_event1;
72 clipboard_event1.set_datatype(protocol::ClipboardEvent::DATA_TYPE_TEXT_UTF8);
73 clipboard_event1.set_data("a");
74
75 protocol::ClipboardEvent clipboard_event2;
76 clipboard_event2.set_datatype(protocol::ClipboardEvent::DATA_TYPE_TEXT_UTF8);
77 clipboard_event2.set_data("b");
78
79 protocol::ClipboardEvent clipboard_event3;
80 clipboard_event3.set_datatype(protocol::ClipboardEvent::DATA_TYPE_TEXT_UTF8);
81 clipboard_event3.set_data("c");
82
83 InSequence s;
84 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_));
85 EXPECT_CALL(clipboard_stub_, InjectClipboardEvent(EqualsClipboardEvent(
86 protocol::ClipboardEvent::DATA_TYPE_TEXT_UTF8, "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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(input_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

Powered by Google App Engine
This is Rietveld 408576698