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

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

Issue 2431513003: Revert of Don't use barcodes in ProtocolPerfTests (Closed)
Patch Set: 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(std::move(client)); 139 host_->clients_.push_back(client.release());
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
247 const std::string& get_session_jid(int connection_index) { 252 const std::string& get_session_jid(int connection_index) {
248 return (connection_index == 0) ? session_jid1_ : session_jid2_; 253 return (connection_index == 0) ? session_jid1_ : session_jid2_;
249 } 254 }
250 }; 255 };
251 256
252 TEST_F(ChromotingHostTest, StartAndShutdown) { 257 TEST_F(ChromotingHostTest, StartAndShutdown) {
253 StartHost(); 258 StartHost();
254 } 259 }
255 260
256 TEST_F(ChromotingHostTest, Connect) { 261 TEST_F(ChromotingHostTest, Connect) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 StartHost(); 331 StartHost();
327 332
328 protocol::SessionManager::IncomingSessionResponse response = 333 protocol::SessionManager::IncomingSessionResponse response =
329 protocol::SessionManager::DECLINE; 334 protocol::SessionManager::DECLINE;
330 335
331 EXPECT_CALL(*session_unowned1_, Close(_)).WillOnce( 336 EXPECT_CALL(*session_unowned1_, Close(_)).WillOnce(
332 InvokeWithoutArgs(this, &ChromotingHostTest::NotifyConnectionClosed1)); 337 InvokeWithoutArgs(this, &ChromotingHostTest::NotifyConnectionClosed1));
333 host_->OnIncomingSession(session_unowned1_.release(), &response); 338 host_->OnIncomingSession(session_unowned1_.release(), &response);
334 EXPECT_EQ(protocol::SessionManager::ACCEPT, response); 339 EXPECT_EQ(protocol::SessionManager::ACCEPT, response);
335 340
336 host_->OnSessionAuthenticating( 341 host_->OnSessionAuthenticating(get_clients_from_host().front());
337 host_->client_sessions_for_tests().front().get());
338 host_->OnIncomingSession(session_unowned2_.get(), &response); 342 host_->OnIncomingSession(session_unowned2_.get(), &response);
339 EXPECT_EQ(protocol::SessionManager::OVERLOAD, response); 343 EXPECT_EQ(protocol::SessionManager::OVERLOAD, response);
340 } 344 }
341 345
342 TEST_F(ChromotingHostTest, LoginBackOffUponAuthenticating) { 346 TEST_F(ChromotingHostTest, LoginBackOffUponAuthenticating) {
343 StartHost(); 347 StartHost();
344 348
345 EXPECT_CALL(*session_unowned1_, Close(_)).WillOnce( 349 EXPECT_CALL(*session_unowned1_, Close(_)).WillOnce(
346 InvokeWithoutArgs(this, &ChromotingHostTest::NotifyConnectionClosed1)); 350 InvokeWithoutArgs(this, &ChromotingHostTest::NotifyConnectionClosed1));
347 351
348 EXPECT_CALL(*session_unowned2_, Close(_)).WillOnce( 352 EXPECT_CALL(*session_unowned2_, Close(_)).WillOnce(
349 InvokeWithoutArgs(this, &ChromotingHostTest::NotifyConnectionClosed2)); 353 InvokeWithoutArgs(this, &ChromotingHostTest::NotifyConnectionClosed2));
350 354
351 protocol::SessionManager::IncomingSessionResponse response = 355 protocol::SessionManager::IncomingSessionResponse response =
352 protocol::SessionManager::DECLINE; 356 protocol::SessionManager::DECLINE;
353 357
354 host_->OnIncomingSession(session_unowned1_.release(), &response); 358 host_->OnIncomingSession(session_unowned1_.release(), &response);
355 EXPECT_EQ(protocol::SessionManager::ACCEPT, response); 359 EXPECT_EQ(protocol::SessionManager::ACCEPT, response);
356 360
357 host_->OnIncomingSession(session_unowned2_.release(), &response); 361 host_->OnIncomingSession(session_unowned2_.release(), &response);
358 EXPECT_EQ(protocol::SessionManager::ACCEPT, response); 362 EXPECT_EQ(protocol::SessionManager::ACCEPT, response);
359 363
360 // This will set the backoff. 364 // This will set the backoff.
361 host_->OnSessionAuthenticating( 365 host_->OnSessionAuthenticating(get_clients_from_host().front());
362 host_->client_sessions_for_tests().front().get());
363 366
364 // This should disconnect client2. 367 // This should disconnect client2.
365 host_->OnSessionAuthenticating( 368 host_->OnSessionAuthenticating(get_clients_from_host().back());
366 host_->client_sessions_for_tests().back().get());
367 369
368 // Verify that the host only has 1 client at this point. 370 // Verify that the host only has 1 client at this point.
369 EXPECT_EQ(host_->client_sessions_for_tests().size(), 1U); 371 EXPECT_EQ(get_clients_from_host().size(), 1U);
370 } 372 }
371 373
372 TEST_F(ChromotingHostTest, OnSessionRouteChange) { 374 TEST_F(ChromotingHostTest, OnSessionRouteChange) {
373 StartHost(); 375 StartHost();
374 376
375 377
376 ExpectClientConnected(0); 378 ExpectClientConnected(0);
377 SimulateClientConnection(0, true, false); 379 SimulateClientConnection(0, true, false);
378 380
379 std::string channel_name("ChannelName"); 381 std::string channel_name("ChannelName");
380 protocol::TransportRoute route; 382 protocol::TransportRoute route;
381 EXPECT_CALL(host_status_observer_, 383 EXPECT_CALL(host_status_observer_,
382 OnClientRouteChange(session_jid1_, channel_name, _)); 384 OnClientRouteChange(session_jid1_, channel_name, _));
383 host_->OnSessionRouteChange(get_client(0), channel_name, route); 385 host_->OnSessionRouteChange(get_client(0), channel_name, route);
384 } 386 }
385 387
386 TEST_F(ChromotingHostTest, DisconnectAllClients) { 388 TEST_F(ChromotingHostTest, DisconnectAllClients) {
387 StartHost(); 389 StartHost();
388 390
389 ExpectClientConnected(0); 391 ExpectClientConnected(0);
390 SimulateClientConnection(0, true, false); 392 SimulateClientConnection(0, true, false);
391 393
392 ExpectClientDisconnected(0); 394 ExpectClientDisconnected(0);
393 DisconnectAllClients(); 395 DisconnectAllClients();
394 testing::Mock::VerifyAndClearExpectations(&host_status_observer_); 396 testing::Mock::VerifyAndClearExpectations(&host_status_observer_);
395 } 397 }
396 398
397 } // namespace remoting 399 } // 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