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

Side by Side Diff: remoting/protocol/connection_unittest.cc

Issue 1531983002: Replace ice_connection_to_client_unittest.cc with connection_unittest.cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « remoting/protocol/BUILD.gn ('k') | remoting/protocol/fake_session.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/bind.h"
6 #include "base/message_loop/message_loop.h"
7 #include "base/run_loop.h"
8 #include "remoting/base/constants.h"
9 #include "remoting/protocol/connection_to_host_impl.h"
10 #include "remoting/protocol/fake_session.h"
11 #include "remoting/protocol/ice_connection_to_client.h"
12 #include "remoting/protocol/protocol_mock_objects.h"
13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 using ::testing::_;
17 using ::testing::InvokeWithoutArgs;
18 using ::testing::NotNull;
19 using ::testing::StrictMock;
20
21 namespace remoting {
22 namespace protocol {
23
24 namespace {
25
26 MATCHER_P(EqualsCapabilitiesMessage, message, "") {
27 return arg.capabilities() == message.capabilities();
28 }
29
30 MATCHER_P(EqualsKeyEvent, event, "") {
31 return arg.usb_keycode() == event.usb_keycode() &&
32 arg.pressed() == event.pressed();
33 }
34
35 class MockConnectionToHostEventCallback
36 : public ConnectionToHost::HostEventCallback {
37 public:
38 MockConnectionToHostEventCallback() {}
39 ~MockConnectionToHostEventCallback() override {}
40
41 MOCK_METHOD2(OnConnectionState,
42 void(ConnectionToHost::State state, ErrorCode error));
43 MOCK_METHOD1(OnConnectionReady, void(bool ready));
44 MOCK_METHOD2(OnRouteChanged,
45 void(const std::string& channel_name,
46 const TransportRoute& route));
47 };
48
49 } // namespace
50
51 class ConnectionTest : public testing::Test {
52 public:
53 ConnectionTest() {}
54
55 protected:
56 void SetUp() override {
57 // Setup host side.
58 host_session_ = new FakeSession();
59 host_connection_.reset(new IceConnectionToClient(
60 make_scoped_ptr(host_session_), message_loop_.task_runner()));
61 host_connection_->SetEventHandler(&host_event_handler_);
62 host_connection_->set_clipboard_stub(&host_clipboard_stub_);
63 host_connection_->set_host_stub(&host_stub_);
64 host_connection_->set_input_stub(&host_input_stub_);
65
66 // Setup client side.
67 owned_client_session_.reset(new FakeSession());
68 client_session_ = owned_client_session_.get();
69 client_connection_.reset(new ConnectionToHostImpl());
70 client_connection_->set_client_stub(&client_stub_);
71 client_connection_->set_clipboard_stub(&client_clipboard_stub_);
72 client_connection_->set_video_stub(&client_video_stub_);
73 }
74
75 void Connect() {
76 {
77 testing::InSequence sequence;
78 EXPECT_CALL(host_event_handler_,
79 OnConnectionAuthenticating(host_connection_.get()));
80 EXPECT_CALL(host_event_handler_,
81 OnConnectionAuthenticated(host_connection_.get()));
82 }
83 EXPECT_CALL(host_event_handler_,
84 OnConnectionChannelsConnected(host_connection_.get()));
85
86 {
87 testing::InSequence sequence;
88 EXPECT_CALL(client_event_handler_,
89 OnConnectionState(ConnectionToHost::CONNECTING, OK));
90 EXPECT_CALL(client_event_handler_,
91 OnConnectionState(ConnectionToHost::AUTHENTICATED, OK));
92 EXPECT_CALL(client_event_handler_,
93 OnConnectionState(ConnectionToHost::CONNECTED, OK));
94 }
95
96 client_connection_->Connect(owned_client_session_.Pass(),
97 &client_event_handler_);
98 client_session_->SimulateConnection(host_session_);
99 base::RunLoop().RunUntilIdle();
100 }
101
102 void TearDown() override {
103 client_connection_.reset();
104 host_connection_.reset();
105 base::RunLoop().RunUntilIdle();
106 }
107
108 base::MessageLoop message_loop_;
109
110 MockConnectionToClientEventHandler host_event_handler_;
111 MockClipboardStub host_clipboard_stub_;
112 MockHostStub host_stub_;
113 MockInputStub host_input_stub_;
114 scoped_ptr<ConnectionToClient> host_connection_;
115 FakeSession* host_session_; // Owned by |host_connection_|.
116
117 MockConnectionToHostEventCallback client_event_handler_;
118 MockClientStub client_stub_;
119 MockClipboardStub client_clipboard_stub_;
120 MockVideoStub client_video_stub_;
121 scoped_ptr<ConnectionToHost> client_connection_;
122 FakeSession* client_session_; // Owned by |client_connection_|.
123 scoped_ptr<FakeSession> owned_client_session_;
124
125 private:
126 DISALLOW_COPY_AND_ASSIGN(ConnectionTest);
127 };
128
129 TEST_F(ConnectionTest, RejectConnection) {
130 EXPECT_CALL(client_event_handler_,
131 OnConnectionState(ConnectionToHost::CONNECTING, OK));
132 EXPECT_CALL(client_event_handler_,
133 OnConnectionState(ConnectionToHost::CLOSED, OK));
134
135 client_connection_->Connect(owned_client_session_.Pass(),
136 &client_event_handler_);
137 client_session_->event_handler()->OnSessionStateChange(Session::CLOSED);
138 }
139
140 TEST_F(ConnectionTest, Disconnect) {
141 Connect();
142
143 EXPECT_CALL(client_event_handler_,
144 OnConnectionState(ConnectionToHost::CLOSED, OK));
145 EXPECT_CALL(host_event_handler_,
146 OnConnectionClosed(host_connection_.get(), OK));
147
148 client_session_->Close(OK);
149 base::RunLoop().RunUntilIdle();
150 }
151
152 TEST_F(ConnectionTest, Control) {
153 Connect();
154
155 Capabilities capabilities_msg;
156 capabilities_msg.set_capabilities("test_capability");
157
158 EXPECT_CALL(client_stub_,
159 SetCapabilities(EqualsCapabilitiesMessage(capabilities_msg)));
160
161 // Send capabilities from the host.
162 host_connection_->client_stub()->SetCapabilities(capabilities_msg);
163
164 base::RunLoop().RunUntilIdle();
165 }
166
167 TEST_F(ConnectionTest, Events) {
168 Connect();
169
170 KeyEvent event;
171 event.set_usb_keycode(3);
172 event.set_pressed(true);
173
174 EXPECT_CALL(host_event_handler_,
175 OnInputEventReceived(host_connection_.get(), _));
176 EXPECT_CALL(host_input_stub_, InjectKeyEvent(EqualsKeyEvent(event)));
177
178 // Send capabilities from the client.
179 client_connection_->input_stub()->InjectKeyEvent(event);
180
181 base::RunLoop().RunUntilIdle();
182 }
183
184 } // namespace protocol
185 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/BUILD.gn ('k') | remoting/protocol/fake_session.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698