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

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

Issue 1545743002: Move ownership of Transport out of Session. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move_not_pass_client
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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/protocol/jingle_session.h" 5 #include "remoting/protocol/jingle_session.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/test/test_timeouts.h" 10 #include "base/test/test_timeouts.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "jingle/glue/thread_wrapper.h"
13 #include "net/socket/socket.h" 12 #include "net/socket/socket.h"
14 #include "net/socket/stream_socket.h" 13 #include "net/socket/stream_socket.h"
15 #include "net/url_request/url_request_context_getter.h" 14 #include "net/url_request/url_request_context_getter.h"
16 #include "remoting/base/constants.h" 15 #include "remoting/base/constants.h"
17 #include "remoting/protocol/authenticator.h" 16 #include "remoting/protocol/authenticator.h"
18 #include "remoting/protocol/channel_authenticator.h" 17 #include "remoting/protocol/channel_authenticator.h"
19 #include "remoting/protocol/chromium_port_allocator.h" 18 #include "remoting/protocol/chromium_port_allocator.h"
20 #include "remoting/protocol/connection_tester.h" 19 #include "remoting/protocol/connection_tester.h"
21 #include "remoting/protocol/fake_authenticator.h" 20 #include "remoting/protocol/fake_authenticator.h"
22 #include "remoting/protocol/ice_transport.h"
23 #include "remoting/protocol/jingle_session_manager.h" 21 #include "remoting/protocol/jingle_session_manager.h"
24 #include "remoting/protocol/network_settings.h" 22 #include "remoting/protocol/network_settings.h"
23 #include "remoting/protocol/transport.h"
25 #include "remoting/protocol/transport_context.h" 24 #include "remoting/protocol/transport_context.h"
26 #include "remoting/signaling/fake_signal_strategy.h" 25 #include "remoting/signaling/fake_signal_strategy.h"
27 #include "testing/gmock/include/gmock/gmock.h" 26 #include "testing/gmock/include/gmock/gmock.h"
28 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
29 28
30 using testing::_; 29 using testing::_;
31 using testing::AtLeast; 30 using testing::AtLeast;
32 using testing::AtMost; 31 using testing::AtMost;
33 using testing::DeleteArg; 32 using testing::DeleteArg;
34 using testing::DoAll; 33 using testing::DoAll;
(...skipping 20 matching lines...) Expand all
55 SessionManager::IncomingSessionResponse*)); 54 SessionManager::IncomingSessionResponse*));
56 }; 55 };
57 56
58 class MockSessionEventHandler : public Session::EventHandler { 57 class MockSessionEventHandler : public Session::EventHandler {
59 public: 58 public:
60 MOCK_METHOD1(OnSessionStateChange, void(Session::State)); 59 MOCK_METHOD1(OnSessionStateChange, void(Session::State));
61 MOCK_METHOD2(OnSessionRouteChange, void(const std::string& channel_name, 60 MOCK_METHOD2(OnSessionRouteChange, void(const std::string& channel_name,
62 const TransportRoute& route)); 61 const TransportRoute& route));
63 }; 62 };
64 63
64 class MockTransport : public Transport {
65 public:
66 MOCK_METHOD2(Start,
67 void(Authenticator* authenticator,
68 SendTransportInfoCallback send_transport_info_callback));
69 MOCK_METHOD1(ProcessTransportInfo, bool(buzz::XmlElement* transport_info));
70 };
71
65 } // namespace 72 } // namespace
66 73
67 class JingleSessionTest : public testing::Test { 74 class JingleSessionTest : public testing::Test {
68 public: 75 public:
69 JingleSessionTest() { 76 JingleSessionTest() {
70 message_loop_.reset(new base::MessageLoopForIO()); 77 message_loop_.reset(new base::MessageLoopForIO());
71 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop();
72 network_settings_ = 78 network_settings_ =
73 NetworkSettings(NetworkSettings::NAT_TRAVERSAL_OUTGOING); 79 NetworkSettings(NetworkSettings::NAT_TRAVERSAL_OUTGOING);
74 } 80 }
75 81
76 // Helper method that handles OnIncomingSession(). 82 // Helper method that handles OnIncomingSession().
77 void SetHostSession(Session* session) { 83 void SetHostSession(Session* session) {
78 DCHECK(session); 84 DCHECK(session);
79 host_session_.reset(session); 85 host_session_.reset(session);
80 host_session_->SetEventHandler(&host_session_event_handler_); 86 host_session_->SetEventHandler(&host_session_event_handler_);
87 host_session_->SetTransport(&host_transport_);
81 } 88 }
82 89
83 void DeleteSession() { 90 void DeleteSession() {
84 host_session_.reset(); 91 host_session_.reset();
85 } 92 }
86 93
87 protected: 94 protected:
88 void TearDown() override { 95 void TearDown() override {
89 CloseSessions(); 96 CloseSessions();
90 CloseSessionManager(); 97 CloseSessionManager();
91 base::RunLoop().RunUntilIdle(); 98 base::RunLoop().RunUntilIdle();
92 } 99 }
93 100
94 void CloseSessions() { 101 void CloseSessions() {
95 host_session_.reset(); 102 host_session_.reset();
96 client_session_.reset(); 103 client_session_.reset();
97 } 104 }
98 105
99 void CreateSessionManagers(int auth_round_trips, int messages_till_start, 106 void CreateSessionManagers(int auth_round_trips, int messages_till_start,
100 FakeAuthenticator::Action auth_action) { 107 FakeAuthenticator::Action auth_action) {
101 host_signal_strategy_.reset(new FakeSignalStrategy(kHostJid)); 108 host_signal_strategy_.reset(new FakeSignalStrategy(kHostJid));
102 client_signal_strategy_.reset(new FakeSignalStrategy(kClientJid)); 109 client_signal_strategy_.reset(new FakeSignalStrategy(kClientJid));
103 FakeSignalStrategy::Connect(host_signal_strategy_.get(), 110 FakeSignalStrategy::Connect(host_signal_strategy_.get(),
104 client_signal_strategy_.get()); 111 client_signal_strategy_.get());
105 112
106 host_server_.reset(new JingleSessionManager( 113 host_server_.reset(new JingleSessionManager(host_signal_strategy_.get()));
107 make_scoped_ptr(new IceTransportFactory(new TransportContext(
108 nullptr, make_scoped_ptr(new ChromiumPortAllocatorFactory(nullptr)),
109 network_settings_, TransportRole::SERVER))),
110 host_signal_strategy_.get()));
111 host_server_->AcceptIncoming( 114 host_server_->AcceptIncoming(
112 base::Bind(&MockSessionManagerListener::OnIncomingSession, 115 base::Bind(&MockSessionManagerListener::OnIncomingSession,
113 base::Unretained(&host_server_listener_))); 116 base::Unretained(&host_server_listener_)));
114 117
115 scoped_ptr<AuthenticatorFactory> factory( 118 scoped_ptr<AuthenticatorFactory> factory(
116 new FakeHostAuthenticatorFactory(auth_round_trips, 119 new FakeHostAuthenticatorFactory(auth_round_trips,
117 messages_till_start, auth_action, true)); 120 messages_till_start, auth_action, true));
118 host_server_->set_authenticator_factory(std::move(factory)); 121 host_server_->set_authenticator_factory(std::move(factory));
119 122
120 client_server_.reset(new JingleSessionManager( 123 client_server_.reset(
121 make_scoped_ptr(new IceTransportFactory(new TransportContext( 124 new JingleSessionManager(client_signal_strategy_.get()));
122 nullptr, make_scoped_ptr(new ChromiumPortAllocatorFactory(nullptr)),
123 network_settings_, TransportRole::CLIENT))),
124 client_signal_strategy_.get()));
125 } 125 }
126 126
127 void CreateSessionManagers(int auth_round_trips, 127 void CreateSessionManagers(int auth_round_trips,
128 FakeAuthenticator::Action auth_action) { 128 FakeAuthenticator::Action auth_action) {
129 CreateSessionManagers(auth_round_trips, 0, auth_action); 129 CreateSessionManagers(auth_round_trips, 0, auth_action);
130 } 130 }
131 131
132 void CloseSessionManager() { 132 void CloseSessionManager() {
133 host_server_.reset(); 133 host_server_.reset();
134 client_server_.reset(); 134 client_server_.reset();
(...skipping 16 matching lines...) Expand all
151 OnSessionStateChange(Session::ACCEPTED)) 151 OnSessionStateChange(Session::ACCEPTED))
152 .Times(AtMost(1)); 152 .Times(AtMost(1));
153 EXPECT_CALL(host_session_event_handler_, 153 EXPECT_CALL(host_session_event_handler_,
154 OnSessionStateChange(Session::AUTHENTICATING)) 154 OnSessionStateChange(Session::AUTHENTICATING))
155 .Times(AtMost(1)); 155 .Times(AtMost(1));
156 if (expect_fail) { 156 if (expect_fail) {
157 EXPECT_CALL(host_session_event_handler_, 157 EXPECT_CALL(host_session_event_handler_,
158 OnSessionStateChange(Session::FAILED)) 158 OnSessionStateChange(Session::FAILED))
159 .Times(1); 159 .Times(1);
160 } else { 160 } else {
161 EXPECT_CALL(host_transport_, Start(_, _)).Times(1);
161 EXPECT_CALL(host_session_event_handler_, 162 EXPECT_CALL(host_session_event_handler_,
162 OnSessionStateChange(Session::AUTHENTICATED)) 163 OnSessionStateChange(Session::AUTHENTICATED))
163 .Times(1); 164 .Times(1);
165
164 // Expect that the connection will be closed eventually. 166 // Expect that the connection will be closed eventually.
165 EXPECT_CALL(host_session_event_handler_, 167 EXPECT_CALL(host_session_event_handler_,
166 OnSessionStateChange(Session::CLOSED)) 168 OnSessionStateChange(Session::CLOSED))
167 .Times(AtMost(1)); 169 .Times(AtMost(1));
168 } 170 }
169 } 171 }
170 172
171 { 173 {
172 InSequence dummy; 174 InSequence dummy;
173 175
174 EXPECT_CALL(client_session_event_handler_, 176 EXPECT_CALL(client_session_event_handler_,
175 OnSessionStateChange(Session::ACCEPTED)) 177 OnSessionStateChange(Session::ACCEPTED))
176 .Times(AtMost(1)); 178 .Times(AtMost(1));
177 EXPECT_CALL(client_session_event_handler_, 179 EXPECT_CALL(client_session_event_handler_,
178 OnSessionStateChange(Session::AUTHENTICATING)) 180 OnSessionStateChange(Session::AUTHENTICATING))
179 .Times(AtMost(1)); 181 .Times(AtMost(1));
180 if (expect_fail) { 182 if (expect_fail) {
181 EXPECT_CALL(client_session_event_handler_, 183 EXPECT_CALL(client_session_event_handler_,
182 OnSessionStateChange(Session::FAILED)) 184 OnSessionStateChange(Session::FAILED))
183 .Times(1); 185 .Times(1);
184 } else { 186 } else {
187 EXPECT_CALL(client_transport_, Start(_, _)).Times(1);
185 EXPECT_CALL(client_session_event_handler_, 188 EXPECT_CALL(client_session_event_handler_,
186 OnSessionStateChange(Session::AUTHENTICATED)) 189 OnSessionStateChange(Session::AUTHENTICATED))
187 .Times(1); 190 .Times(1);
191
188 // Expect that the connection will be closed eventually. 192 // Expect that the connection will be closed eventually.
189 EXPECT_CALL(client_session_event_handler_, 193 EXPECT_CALL(client_session_event_handler_,
190 OnSessionStateChange(Session::CLOSED)) 194 OnSessionStateChange(Session::CLOSED))
191 .Times(AtMost(1)); 195 .Times(AtMost(1));
192 } 196 }
193 } 197 }
194 198
195 scoped_ptr<Authenticator> authenticator(new FakeAuthenticator( 199 scoped_ptr<Authenticator> authenticator(new FakeAuthenticator(
196 FakeAuthenticator::CLIENT, auth_round_trips, auth_action, true)); 200 FakeAuthenticator::CLIENT, auth_round_trips, auth_action, true));
197 201
198 client_session_ = 202 client_session_ =
199 client_server_->Connect(kHostJid, std::move(authenticator)); 203 client_server_->Connect(kHostJid, std::move(authenticator));
200 client_session_->SetEventHandler(&client_session_event_handler_); 204 client_session_->SetEventHandler(&client_session_event_handler_);
205 client_session_->SetTransport(&client_transport_);
201 206
202 base::RunLoop().RunUntilIdle(); 207 base::RunLoop().RunUntilIdle();
203 } 208 }
204 209
205 void ExpectRouteChange(const std::string& channel_name) { 210 void ExpectRouteChange(const std::string& channel_name) {
206 EXPECT_CALL(host_session_event_handler_, 211 EXPECT_CALL(host_session_event_handler_,
207 OnSessionRouteChange(channel_name, _)) 212 OnSessionRouteChange(channel_name, _))
208 .Times(AtLeast(1)); 213 .Times(AtLeast(1));
209 EXPECT_CALL(client_session_event_handler_, 214 EXPECT_CALL(client_session_event_handler_,
210 OnSessionRouteChange(channel_name, _)) 215 OnSessionRouteChange(channel_name, _))
211 .Times(AtLeast(1)); 216 .Times(AtLeast(1));
212 } 217 }
213 218
214 scoped_ptr<base::MessageLoopForIO> message_loop_; 219 scoped_ptr<base::MessageLoopForIO> message_loop_;
215 220
216 NetworkSettings network_settings_; 221 NetworkSettings network_settings_;
217 222
218 scoped_ptr<FakeSignalStrategy> host_signal_strategy_; 223 scoped_ptr<FakeSignalStrategy> host_signal_strategy_;
219 scoped_ptr<FakeSignalStrategy> client_signal_strategy_; 224 scoped_ptr<FakeSignalStrategy> client_signal_strategy_;
220 225
221 scoped_ptr<JingleSessionManager> host_server_; 226 scoped_ptr<JingleSessionManager> host_server_;
222 MockSessionManagerListener host_server_listener_; 227 MockSessionManagerListener host_server_listener_;
223 scoped_ptr<JingleSessionManager> client_server_; 228 scoped_ptr<JingleSessionManager> client_server_;
224 229
225 scoped_ptr<Session> host_session_; 230 scoped_ptr<Session> host_session_;
226 MockSessionEventHandler host_session_event_handler_; 231 MockSessionEventHandler host_session_event_handler_;
232 MockTransport host_transport_;
227 scoped_ptr<Session> client_session_; 233 scoped_ptr<Session> client_session_;
228 MockSessionEventHandler client_session_event_handler_; 234 MockSessionEventHandler client_session_event_handler_;
235 MockTransport client_transport_;
229 }; 236 };
230 237
231 238
232 // Verify that we can create and destroy session managers without a 239 // Verify that we can create and destroy session managers without a
233 // connection. 240 // connection.
234 TEST_F(JingleSessionTest, CreateAndDestoy) { 241 TEST_F(JingleSessionTest, CreateAndDestoy) {
235 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); 242 CreateSessionManagers(1, FakeAuthenticator::ACCEPT);
236 } 243 }
237 244
238 // Verify that an incoming session can be rejected, and that the 245 // Verify that an incoming session can be rejected, and that the
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 405
399 // Verify that we can connect with multistep authentication. 406 // Verify that we can connect with multistep authentication.
400 TEST_F(JingleSessionTest, TestMultistepAuth) { 407 TEST_F(JingleSessionTest, TestMultistepAuth) {
401 CreateSessionManagers(3, FakeAuthenticator::ACCEPT); 408 CreateSessionManagers(3, FakeAuthenticator::ACCEPT);
402 ASSERT_NO_FATAL_FAILURE( 409 ASSERT_NO_FATAL_FAILURE(
403 InitiateConnection(3, FakeAuthenticator::ACCEPT, false)); 410 InitiateConnection(3, FakeAuthenticator::ACCEPT, false));
404 } 411 }
405 412
406 } // namespace protocol 413 } // namespace protocol
407 } // namespace remoting 414 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698