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

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

Issue 9455070: Remove the dependency to ws2_32.dll from talk_base::ThreadManager and talk_base::Thread. (Closed) Base URL: https://src.chromium.org/svn/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
« no previous file with comments | « jingle/glue/thread_wrapper.cc ('k') | third_party/libjingle/libjingle.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.h" 8 #include "base/message_loop.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "base/test/test_timeouts.h" 10 #include "base/test/test_timeouts.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 74
75 class MockStreamChannelCallback { 75 class MockStreamChannelCallback {
76 public: 76 public:
77 MOCK_METHOD1(OnDone, void(net::StreamSocket* socket)); 77 MOCK_METHOD1(OnDone, void(net::StreamSocket* socket));
78 }; 78 };
79 79
80 } // namespace 80 } // namespace
81 81
82 class JingleSessionTest : public testing::Test { 82 class JingleSessionTest : public testing::Test {
83 public: 83 public:
84 JingleSessionTest() 84 JingleSessionTest() {
85 : message_loop_(talk_base::Thread::Current()) { 85 talk_base::ThreadManager::Instance()->WrapCurrentThread();
86 message_loop_.reset(
87 new JingleThreadMessageLoop(talk_base::Thread::Current()));
86 } 88 }
87 89
88 // Helper method that handles OnIncomingSession(). 90 // Helper method that handles OnIncomingSession().
89 void SetHostSession(Session* session) { 91 void SetHostSession(Session* session) {
90 DCHECK(session); 92 DCHECK(session);
91 host_session_.reset(session); 93 host_session_.reset(session);
92 host_session_->SetStateChangeCallback( 94 host_session_->SetStateChangeCallback(
93 base::Bind(&MockSessionCallback::OnStateChange, 95 base::Bind(&MockSessionCallback::OnStateChange,
94 base::Unretained(&host_connection_callback_))); 96 base::Unretained(&host_connection_callback_)));
95 97
(...skipping 10 matching lines...) Expand all
106 host_socket_ = socket.Pass(); 108 host_socket_ = socket.Pass();
107 } 109 }
108 110
109 protected: 111 protected:
110 virtual void SetUp() { 112 virtual void SetUp() {
111 } 113 }
112 114
113 virtual void TearDown() { 115 virtual void TearDown() {
114 CloseSessions(); 116 CloseSessions();
115 CloseSessionManager(); 117 CloseSessionManager();
116 message_loop_.RunAllPending(); 118 message_loop_->RunAllPending();
117 } 119 }
118 120
119 void CloseSessions() { 121 void CloseSessions() {
120 host_socket_.reset(); 122 host_socket_.reset();
121 host_session_.reset(); 123 host_session_.reset();
122 client_socket_.reset(); 124 client_socket_.reset();
123 client_session_.reset(); 125 client_session_.reset();
124 } 126 }
125 127
126 void CreateSessionManagers(int auth_round_trips, 128 void CreateSessionManagers(int auth_round_trips,
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 219
218 scoped_ptr<Authenticator> authenticator(new FakeAuthenticator( 220 scoped_ptr<Authenticator> authenticator(new FakeAuthenticator(
219 FakeAuthenticator::CLIENT, auth_round_trips, auth_action, true)); 221 FakeAuthenticator::CLIENT, auth_round_trips, auth_action, true));
220 222
221 client_session_ = client_server_->Connect( 223 client_session_ = client_server_->Connect(
222 kHostJid, authenticator.Pass(), 224 kHostJid, authenticator.Pass(),
223 CandidateSessionConfig::CreateDefault(), 225 CandidateSessionConfig::CreateDefault(),
224 base::Bind(&MockSessionCallback::OnStateChange, 226 base::Bind(&MockSessionCallback::OnStateChange,
225 base::Unretained(&client_connection_callback_))); 227 base::Unretained(&client_connection_callback_)));
226 228
227 message_loop_.RunAllPending(); 229 message_loop_->RunAllPending();
228 } 230 }
229 231
230 void CreateChannel(bool expect_fail) { 232 void CreateChannel(bool expect_fail) {
231 client_session_->CreateStreamChannel(kChannelName, base::Bind( 233 client_session_->CreateStreamChannel(kChannelName, base::Bind(
232 &JingleSessionTest::OnClientChannelCreated, base::Unretained(this))); 234 &JingleSessionTest::OnClientChannelCreated, base::Unretained(this)));
233 host_session_->CreateStreamChannel(kChannelName, base::Bind( 235 host_session_->CreateStreamChannel(kChannelName, base::Bind(
234 &JingleSessionTest::OnHostChannelCreated, base::Unretained(this))); 236 &JingleSessionTest::OnHostChannelCreated, base::Unretained(this)));
235 237
236 int counter = 2; 238 int counter = 2;
237 EXPECT_CALL(client_channel_callback_, OnDone(_)) 239 EXPECT_CALL(client_channel_callback_, OnDone(_))
238 .WillOnce(QuitThreadOnCounter(&counter)); 240 .WillOnce(QuitThreadOnCounter(&counter));
239 EXPECT_CALL(host_channel_callback_, OnDone(_)) 241 EXPECT_CALL(host_channel_callback_, OnDone(_))
240 .WillOnce(QuitThreadOnCounter(&counter)); 242 .WillOnce(QuitThreadOnCounter(&counter));
241 message_loop_.Run(); 243 message_loop_->Run();
242 244
243 if (expect_fail) { 245 if (expect_fail) {
244 // At least one socket should fail to connect. 246 // At least one socket should fail to connect.
245 EXPECT_TRUE((!client_socket_.get()) || (!host_socket_.get())); 247 EXPECT_TRUE((!client_socket_.get()) || (!host_socket_.get()));
246 } else { 248 } else {
247 EXPECT_TRUE(client_socket_.get()); 249 EXPECT_TRUE(client_socket_.get());
248 EXPECT_TRUE(host_socket_.get()); 250 EXPECT_TRUE(host_socket_.get());
249 } 251 }
250 } 252 }
251 253
252 JingleThreadMessageLoop message_loop_; 254 scoped_ptr<JingleThreadMessageLoop> message_loop_;
253 255
254 scoped_ptr<FakeSignalStrategy> host_signal_strategy_; 256 scoped_ptr<FakeSignalStrategy> host_signal_strategy_;
255 scoped_ptr<FakeSignalStrategy> client_signal_strategy_; 257 scoped_ptr<FakeSignalStrategy> client_signal_strategy_;
256 258
257 scoped_ptr<JingleSessionManager> host_server_; 259 scoped_ptr<JingleSessionManager> host_server_;
258 MockSessionManagerListener host_server_listener_; 260 MockSessionManagerListener host_server_listener_;
259 scoped_ptr<JingleSessionManager> client_server_; 261 scoped_ptr<JingleSessionManager> client_server_;
260 MockSessionManagerListener client_server_listener_; 262 MockSessionManagerListener client_server_listener_;
261 263
262 scoped_ptr<Session> host_session_; 264 scoped_ptr<Session> host_session_;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 .Times(1); 300 .Times(1);
299 } 301 }
300 302
301 scoped_ptr<Authenticator> authenticator(new FakeAuthenticator( 303 scoped_ptr<Authenticator> authenticator(new FakeAuthenticator(
302 FakeAuthenticator::CLIENT, 1, FakeAuthenticator::ACCEPT, true)); 304 FakeAuthenticator::CLIENT, 1, FakeAuthenticator::ACCEPT, true));
303 client_session_ = client_server_->Connect( 305 client_session_ = client_server_->Connect(
304 kHostJid, authenticator.Pass(), CandidateSessionConfig::CreateDefault(), 306 kHostJid, authenticator.Pass(), CandidateSessionConfig::CreateDefault(),
305 base::Bind(&MockSessionCallback::OnStateChange, 307 base::Bind(&MockSessionCallback::OnStateChange,
306 base::Unretained(&client_connection_callback_))); 308 base::Unretained(&client_connection_callback_)));
307 309
308 message_loop_.RunAllPending(); 310 message_loop_->RunAllPending();
309 } 311 }
310 312
311 // Verify that we can connect two endpoints with single-step authentication. 313 // Verify that we can connect two endpoints with single-step authentication.
312 TEST_F(JingleSessionTest, Connect) { 314 TEST_F(JingleSessionTest, Connect) {
313 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); 315 CreateSessionManagers(1, FakeAuthenticator::ACCEPT);
314 InitiateConnection(1, FakeAuthenticator::ACCEPT, false); 316 InitiateConnection(1, FakeAuthenticator::ACCEPT, false);
315 317
316 // Verify that the client specified correct initiator value. 318 // Verify that the client specified correct initiator value.
317 ASSERT_GT(host_signal_strategy_->received_messages().size(), 0U); 319 ASSERT_GT(host_signal_strategy_->received_messages().size(), 0U);
318 const buzz::XmlElement* initiate_xml = 320 const buzz::XmlElement* initiate_xml =
(...skipping 27 matching lines...) Expand all
346 TEST_F(JingleSessionTest, TestStreamChannel) { 348 TEST_F(JingleSessionTest, TestStreamChannel) {
347 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); 349 CreateSessionManagers(1, FakeAuthenticator::ACCEPT);
348 ASSERT_NO_FATAL_FAILURE( 350 ASSERT_NO_FATAL_FAILURE(
349 InitiateConnection(1, FakeAuthenticator::ACCEPT, false)); 351 InitiateConnection(1, FakeAuthenticator::ACCEPT, false));
350 352
351 ASSERT_NO_FATAL_FAILURE(CreateChannel(false)); 353 ASSERT_NO_FATAL_FAILURE(CreateChannel(false));
352 354
353 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), 355 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(),
354 kMessageSize, kMessages); 356 kMessageSize, kMessages);
355 tester.Start(); 357 tester.Start();
356 message_loop_.Run(); 358 message_loop_->Run();
357 tester.CheckResults(); 359 tester.CheckResults();
358 } 360 }
359 361
360 // Verify that we can connect channels with multistep auth. 362 // Verify that we can connect channels with multistep auth.
361 TEST_F(JingleSessionTest, TestMultistepAuthStreamChannel) { 363 TEST_F(JingleSessionTest, TestMultistepAuthStreamChannel) {
362 CreateSessionManagers(3, FakeAuthenticator::ACCEPT); 364 CreateSessionManagers(3, FakeAuthenticator::ACCEPT);
363 ASSERT_NO_FATAL_FAILURE( 365 ASSERT_NO_FATAL_FAILURE(
364 InitiateConnection(3, FakeAuthenticator::ACCEPT, false)); 366 InitiateConnection(3, FakeAuthenticator::ACCEPT, false));
365 367
366 ASSERT_NO_FATAL_FAILURE(CreateChannel(false)); 368 ASSERT_NO_FATAL_FAILURE(CreateChannel(false));
367 369
368 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), 370 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(),
369 kMessageSize, kMessages); 371 kMessageSize, kMessages);
370 tester.Start(); 372 tester.Start();
371 message_loop_.Run(); 373 message_loop_->Run();
372 tester.CheckResults(); 374 tester.CheckResults();
373 } 375 }
374 376
375 // Verify that we shutdown properly when channel authentication fails. 377 // Verify that we shutdown properly when channel authentication fails.
376 TEST_F(JingleSessionTest, TestFailedChannelAuth) { 378 TEST_F(JingleSessionTest, TestFailedChannelAuth) {
377 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); 379 CreateSessionManagers(1, FakeAuthenticator::ACCEPT);
378 ASSERT_NO_FATAL_FAILURE( 380 ASSERT_NO_FATAL_FAILURE(
379 InitiateConnection(1, FakeAuthenticator::REJECT_CHANNEL, false)); 381 InitiateConnection(1, FakeAuthenticator::REJECT_CHANNEL, false));
380 382
381 ASSERT_NO_FATAL_FAILURE(CreateChannel(true)); 383 ASSERT_NO_FATAL_FAILURE(CreateChannel(true));
382 } 384 }
383 385
384 } // namespace protocol 386 } // namespace protocol
385 } // namespace remoting 387 } // namespace remoting
OLDNEW
« no previous file with comments | « jingle/glue/thread_wrapper.cc ('k') | third_party/libjingle/libjingle.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698