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

Side by Side Diff: remoting/host/chromoting_host_unittest.cc

Issue 2420183002: Don't use barcodes in ProtocolPerfTests (Closed)
Patch Set: Update ChromotingHost::OnSessionAuthenticated() to fix test crash Created 4 years, 2 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 | « remoting/host/chromoting_host.cc ('k') | remoting/host/client_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
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/host/chromoting_host.h" 5 #include "remoting/host/chromoting_host.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 protocol::ConnectionToClient* connection_ptr = connection.get(); 129 protocol::ConnectionToClient* connection_ptr = connection.get();
130 std::unique_ptr<ClientSession> client(new ClientSession( 130 std::unique_ptr<ClientSession> client(new ClientSession(
131 host_.get(), std::move(connection), desktop_environment_factory_.get(), 131 host_.get(), std::move(connection), desktop_environment_factory_.get(),
132 base::TimeDelta(), nullptr, std::vector<HostExtension*>())); 132 base::TimeDelta(), nullptr, std::vector<HostExtension*>()));
133 ClientSession* client_ptr = client.get(); 133 ClientSession* client_ptr = client.get();
134 134
135 connection_ptr->set_host_stub(client.get()); 135 connection_ptr->set_host_stub(client.get());
136 get_client(connection_index) = client_ptr; 136 get_client(connection_index) = client_ptr;
137 137
138 // |host| is responsible for deleting |client| from now on. 138 // |host| is responsible for deleting |client| from now on.
139 host_->clients_.push_back(client.release()); 139 host_->clients_.push_back(std::move(client));
140 140
141 if (authenticate) { 141 if (authenticate) {
142 client_ptr->OnConnectionAuthenticated(); 142 client_ptr->OnConnectionAuthenticated();
143 if (!reject) 143 if (!reject)
144 client_ptr->OnConnectionChannelsConnected(); 144 client_ptr->OnConnectionChannelsConnected();
145 } else { 145 } else {
146 client_ptr->OnConnectionClosed(protocol::AUTHENTICATION_FAILED); 146 client_ptr->OnConnectionClosed(protocol::AUTHENTICATION_FAILED);
147 } 147 }
148 } 148 }
149 149
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 237
238 protocol::FakeConnectionToClient*& get_connection(int connection_index) { 238 protocol::FakeConnectionToClient*& get_connection(int connection_index) {
239 return (connection_index == 0) ? connection1_ : connection2_; 239 return (connection_index == 0) ? connection1_ : connection2_;
240 } 240 }
241 241
242 // Returns the cached client pointers client1_ or client2_. 242 // Returns the cached client pointers client1_ or client2_.
243 ClientSession*& get_client(int connection_index) { 243 ClientSession*& get_client(int connection_index) {
244 return (connection_index == 0) ? client1_ : client2_; 244 return (connection_index == 0) ? client1_ : client2_;
245 } 245 }
246 246
247 // Returns the list of clients of the host_.
248 std::list<ClientSession*>& get_clients_from_host() {
249 return host_->clients_;
250 }
251
252 const std::string& get_session_jid(int connection_index) { 247 const std::string& get_session_jid(int connection_index) {
253 return (connection_index == 0) ? session_jid1_ : session_jid2_; 248 return (connection_index == 0) ? session_jid1_ : session_jid2_;
254 } 249 }
255 }; 250 };
256 251
257 TEST_F(ChromotingHostTest, StartAndShutdown) { 252 TEST_F(ChromotingHostTest, StartAndShutdown) {
258 StartHost(); 253 StartHost();
259 } 254 }
260 255
261 TEST_F(ChromotingHostTest, Connect) { 256 TEST_F(ChromotingHostTest, Connect) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 StartHost(); 326 StartHost();
332 327
333 protocol::SessionManager::IncomingSessionResponse response = 328 protocol::SessionManager::IncomingSessionResponse response =
334 protocol::SessionManager::DECLINE; 329 protocol::SessionManager::DECLINE;
335 330
336 EXPECT_CALL(*session_unowned1_, Close(_)).WillOnce( 331 EXPECT_CALL(*session_unowned1_, Close(_)).WillOnce(
337 InvokeWithoutArgs(this, &ChromotingHostTest::NotifyConnectionClosed1)); 332 InvokeWithoutArgs(this, &ChromotingHostTest::NotifyConnectionClosed1));
338 host_->OnIncomingSession(session_unowned1_.release(), &response); 333 host_->OnIncomingSession(session_unowned1_.release(), &response);
339 EXPECT_EQ(protocol::SessionManager::ACCEPT, response); 334 EXPECT_EQ(protocol::SessionManager::ACCEPT, response);
340 335
341 host_->OnSessionAuthenticating(get_clients_from_host().front()); 336 host_->OnSessionAuthenticating(
337 host_->client_sessions_for_tests().front().get());
342 host_->OnIncomingSession(session_unowned2_.get(), &response); 338 host_->OnIncomingSession(session_unowned2_.get(), &response);
343 EXPECT_EQ(protocol::SessionManager::OVERLOAD, response); 339 EXPECT_EQ(protocol::SessionManager::OVERLOAD, response);
344 } 340 }
345 341
346 TEST_F(ChromotingHostTest, LoginBackOffUponAuthenticating) { 342 TEST_F(ChromotingHostTest, LoginBackOffUponAuthenticating) {
347 StartHost(); 343 StartHost();
348 344
349 EXPECT_CALL(*session_unowned1_, Close(_)).WillOnce( 345 EXPECT_CALL(*session_unowned1_, Close(_)).WillOnce(
350 InvokeWithoutArgs(this, &ChromotingHostTest::NotifyConnectionClosed1)); 346 InvokeWithoutArgs(this, &ChromotingHostTest::NotifyConnectionClosed1));
351 347
352 EXPECT_CALL(*session_unowned2_, Close(_)).WillOnce( 348 EXPECT_CALL(*session_unowned2_, Close(_)).WillOnce(
353 InvokeWithoutArgs(this, &ChromotingHostTest::NotifyConnectionClosed2)); 349 InvokeWithoutArgs(this, &ChromotingHostTest::NotifyConnectionClosed2));
354 350
355 protocol::SessionManager::IncomingSessionResponse response = 351 protocol::SessionManager::IncomingSessionResponse response =
356 protocol::SessionManager::DECLINE; 352 protocol::SessionManager::DECLINE;
357 353
358 host_->OnIncomingSession(session_unowned1_.release(), &response); 354 host_->OnIncomingSession(session_unowned1_.release(), &response);
359 EXPECT_EQ(protocol::SessionManager::ACCEPT, response); 355 EXPECT_EQ(protocol::SessionManager::ACCEPT, response);
360 356
361 host_->OnIncomingSession(session_unowned2_.release(), &response); 357 host_->OnIncomingSession(session_unowned2_.release(), &response);
362 EXPECT_EQ(protocol::SessionManager::ACCEPT, response); 358 EXPECT_EQ(protocol::SessionManager::ACCEPT, response);
363 359
364 // This will set the backoff. 360 // This will set the backoff.
365 host_->OnSessionAuthenticating(get_clients_from_host().front()); 361 host_->OnSessionAuthenticating(
362 host_->client_sessions_for_tests().front().get());
366 363
367 // This should disconnect client2. 364 // This should disconnect client2.
368 host_->OnSessionAuthenticating(get_clients_from_host().back()); 365 host_->OnSessionAuthenticating(
366 host_->client_sessions_for_tests().back().get());
369 367
370 // Verify that the host only has 1 client at this point. 368 // Verify that the host only has 1 client at this point.
371 EXPECT_EQ(get_clients_from_host().size(), 1U); 369 EXPECT_EQ(host_->client_sessions_for_tests().size(), 1U);
372 } 370 }
373 371
374 TEST_F(ChromotingHostTest, OnSessionRouteChange) { 372 TEST_F(ChromotingHostTest, OnSessionRouteChange) {
375 StartHost(); 373 StartHost();
376 374
377 375
378 ExpectClientConnected(0); 376 ExpectClientConnected(0);
379 SimulateClientConnection(0, true, false); 377 SimulateClientConnection(0, true, false);
380 378
381 std::string channel_name("ChannelName"); 379 std::string channel_name("ChannelName");
382 protocol::TransportRoute route; 380 protocol::TransportRoute route;
383 EXPECT_CALL(host_status_observer_, 381 EXPECT_CALL(host_status_observer_,
384 OnClientRouteChange(session_jid1_, channel_name, _)); 382 OnClientRouteChange(session_jid1_, channel_name, _));
385 host_->OnSessionRouteChange(get_client(0), channel_name, route); 383 host_->OnSessionRouteChange(get_client(0), channel_name, route);
386 } 384 }
387 385
388 TEST_F(ChromotingHostTest, DisconnectAllClients) { 386 TEST_F(ChromotingHostTest, DisconnectAllClients) {
389 StartHost(); 387 StartHost();
390 388
391 ExpectClientConnected(0); 389 ExpectClientConnected(0);
392 SimulateClientConnection(0, true, false); 390 SimulateClientConnection(0, true, false);
393 391
394 ExpectClientDisconnected(0); 392 ExpectClientDisconnected(0);
395 DisconnectAllClients(); 393 DisconnectAllClients();
396 testing::Mock::VerifyAndClearExpectations(&host_status_observer_); 394 testing::Mock::VerifyAndClearExpectations(&host_status_observer_);
397 } 395 }
398 396
399 } // namespace remoting 397 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/chromoting_host.cc ('k') | remoting/host/client_session.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698