OLD | NEW |
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; |
(...skipping 18 matching lines...) Expand all Loading... |
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 protocol::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, m, d, "") { |
| 67 return (strcmp(arg.mime_type().c_str(), m) == 0 && |
| 68 memcmp(arg.data().data(), d, arg.data().size()) == 0); |
| 69 } |
| 70 |
| 71 TEST_F(ClientSessionTest, ClipboardStubFilter) { |
| 72 protocol::ClipboardEvent clipboard_event1; |
| 73 clipboard_event1.set_mime_type(kMimeTypeText); |
| 74 clipboard_event1.set_data("a"); |
| 75 |
| 76 protocol::ClipboardEvent clipboard_event2; |
| 77 clipboard_event2.set_mime_type(kMimeTypeText); |
| 78 clipboard_event2.set_data("b"); |
| 79 |
| 80 protocol::ClipboardEvent clipboard_event3; |
| 81 clipboard_event3.set_mime_type(kMimeTypeText); |
| 82 clipboard_event3.set_data("c"); |
| 83 |
| 84 InSequence s; |
| 85 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); |
| 86 EXPECT_CALL(clipboard_stub_, InjectClipboardEvent(EqualsClipboardEvent( |
| 87 kMimeTypeText, "b"))); |
| 88 |
| 89 // This event should not get through to the clipboard stub, |
| 90 // because the client isn't authenticated yet. |
| 91 client_session_->InjectClipboardEvent(clipboard_event1); |
| 92 client_session_->OnConnectionOpened(client_session_->connection()); |
| 93 // This event should get through to the clipboard stub. |
| 94 client_session_->InjectClipboardEvent(clipboard_event2); |
| 95 client_session_->Disconnect(); |
| 96 // This event should not get through to the clipboard stub, |
| 97 // because the client has disconnected. |
| 98 client_session_->InjectClipboardEvent(clipboard_event3); |
| 99 } |
| 100 |
64 MATCHER_P2(EqualsKeyEvent, keycode, pressed, "") { | 101 MATCHER_P2(EqualsKeyEvent, keycode, pressed, "") { |
65 return arg.keycode() == keycode && arg.pressed() == pressed; | 102 return arg.keycode() == keycode && arg.pressed() == pressed; |
66 } | 103 } |
67 | 104 |
68 MATCHER_P2(EqualsMouseEvent, x, y, "") { | 105 MATCHER_P2(EqualsMouseEvent, x, y, "") { |
69 return arg.x() == x && arg.y() == y; | 106 return arg.x() == x && arg.y() == y; |
70 } | 107 } |
71 | 108 |
72 MATCHER_P(EqualsMouseUpEvent, button, "") { | 109 MATCHER_P(EqualsMouseUpEvent, button, "") { |
73 return arg.button() == button && !arg.button_down(); | 110 return arg.button() == button && !arg.button_down(); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 event.set_x(input_x[i]); | 239 event.set_x(input_x[i]); |
203 event.set_y(input_y[j]); | 240 event.set_y(input_y[j]); |
204 EXPECT_CALL(input_stub_, InjectMouseEvent(EqualsMouseEvent( | 241 EXPECT_CALL(input_stub_, InjectMouseEvent(EqualsMouseEvent( |
205 expected_x[i], expected_y[j]))); | 242 expected_x[i], expected_y[j]))); |
206 client_session_->InjectMouseEvent(event); | 243 client_session_->InjectMouseEvent(event); |
207 } | 244 } |
208 } | 245 } |
209 } | 246 } |
210 | 247 |
211 } // namespace remoting | 248 } // namespace remoting |
OLD | NEW |