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

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
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 client_session_ = new FakeSession();
68 client_connection_.reset(new ConnectionToHostImpl());
69 client_connection_->set_client_stub(&client_stub_);
70 client_connection_->set_clipboard_stub(&client_clipboard_stub_);
71 client_connection_->set_video_stub(&client_video_stub_);
72 }
73
74 void Connect() {
75 {
76 testing::InSequence sequence;
77 EXPECT_CALL(host_event_handler_,
78 OnConnectionAuthenticating(host_connection_.get()));
79 EXPECT_CALL(host_event_handler_,
80 OnConnectionAuthenticated(host_connection_.get()));
81 }
82 EXPECT_CALL(host_event_handler_,
83 OnConnectionChannelsConnected(host_connection_.get()));
84
85 {
86 testing::InSequence sequence;
87 EXPECT_CALL(client_event_handler_,
88 OnConnectionState(ConnectionToHost::CONNECTING, OK));
89 EXPECT_CALL(client_event_handler_,
90 OnConnectionState(ConnectionToHost::AUTHENTICATED, OK));
91 EXPECT_CALL(client_event_handler_,
92 OnConnectionState(ConnectionToHost::CONNECTED, OK));
93 }
94
95 client_connection_->Connect(make_scoped_ptr(client_session_),
96 &client_event_handler_);
97 client_session_->SimulateConnection(host_session_);
98 base::RunLoop().RunUntilIdle();
99
joedow 2015/12/17 17:29:11 nit: remove extra newline
Sergey Ulanov 2015/12/17 17:36:18 Done.
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
124 private:
125 DISALLOW_COPY_AND_ASSIGN(ConnectionTest);
126 };
127
128 TEST_F(ConnectionTest, RejectConnection) {
129 EXPECT_CALL(client_event_handler_,
130 OnConnectionState(ConnectionToHost::CONNECTING, OK));
131 EXPECT_CALL(client_event_handler_,
132 OnConnectionState(ConnectionToHost::CLOSED, OK));
133
134 client_connection_->Connect(make_scoped_ptr(client_session_),
135 &client_event_handler_);
136 client_session_->event_handler()->OnSessionStateChange(Session::CLOSED);
137 }
138
139 TEST_F(ConnectionTest, Disconnect) {
140 Connect();
141
142 EXPECT_CALL(client_event_handler_,
143 OnConnectionState(ConnectionToHost::CLOSED, OK));
144 EXPECT_CALL(host_event_handler_,
145 OnConnectionClosed(host_connection_.get(), OK));
146
147 client_session_->Close(OK);
148 base::RunLoop().RunUntilIdle();
149 }
150
151 TEST_F(ConnectionTest, Control) {
152 Connect();
153
154 Capabilities capabilities_msg;
155 capabilities_msg.set_capabilities("test_capability");
156
157 EXPECT_CALL(client_stub_,
158 SetCapabilities(EqualsCapabilitiesMessage(capabilities_msg)));
159
160 // Send capabilities from the host.
161 host_connection_->client_stub()->SetCapabilities(capabilities_msg);
162
163 base::RunLoop().RunUntilIdle();
164 }
165
166 TEST_F(ConnectionTest, Events) {
167 Connect();
168
169 KeyEvent event;
170 event.set_usb_keycode(3);
171 event.set_pressed(true);
172
173 EXPECT_CALL(host_event_handler_,
174 OnInputEventReceived(host_connection_.get(), _));
175 EXPECT_CALL(host_input_stub_, InjectKeyEvent(EqualsKeyEvent(event)));
176
177 // Send capabilities from the client.
178 client_connection_->input_stub()->InjectKeyEvent(event);
179
180 base::RunLoop().RunUntilIdle();
181 }
182
183 } // namespace protocol
184 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698