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

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

Issue 11028128: [Chromoting] Request the daemon to open a terminal once a connection has been accepted. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 8 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 | Annotate | Revision Log
« 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/message_loop_proxy.h" 7 #include "base/message_loop_proxy.h"
8 #include "remoting/base/auto_thread_task_runner.h" 8 #include "remoting/base/auto_thread_task_runner.h"
9 #include "remoting/jingle_glue/mock_objects.h" 9 #include "remoting/jingle_glue/mock_objects.h"
10 #include "remoting/host/audio_capturer.h" 10 #include "remoting/host/audio_capturer.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 // done callbacks. 59 // done callbacks.
60 ACTION(RunDoneTask) { 60 ACTION(RunDoneTask) {
61 arg1.Run(); 61 arg1.Run();
62 } 62 }
63 63
64 void DoNothing() { 64 void DoNothing() {
65 } 65 }
66 66
67 } // namespace 67 } // namespace
68 68
69 class MockDesktopEnvironmentFactory : public DesktopEnvironmentFactory {
70 public:
71 MockDesktopEnvironmentFactory();
72 virtual ~MockDesktopEnvironmentFactory();
73
74 virtual scoped_ptr<DesktopEnvironment> Create() OVERRIDE;
75
76 private:
77 DISALLOW_COPY_AND_ASSIGN(MockDesktopEnvironmentFactory);
78 };
79
80 MockDesktopEnvironmentFactory::MockDesktopEnvironmentFactory()
81 : DesktopEnvironmentFactory(NULL, NULL) {
82 }
83
84 MockDesktopEnvironmentFactory::~MockDesktopEnvironmentFactory() {
85 }
86
87 scoped_ptr<DesktopEnvironment> MockDesktopEnvironmentFactory::Create() {
88 scoped_ptr<EventExecutor> event_executor(new EventExecutorFake());
89 scoped_ptr<VideoFrameCapturer> video_capturer(new VideoFrameCapturerFake());
90 return scoped_ptr<DesktopEnvironment>(new DesktopEnvironment(
91 scoped_ptr<AudioCapturer>(NULL),
92 event_executor.Pass(),
93 video_capturer.Pass()));
94 }
95
96 class ChromotingHostTest : public testing::Test { 69 class ChromotingHostTest : public testing::Test {
97 public: 70 public:
98 ChromotingHostTest() { 71 ChromotingHostTest() {
99 } 72 }
100 73
101 virtual void SetUp() OVERRIDE { 74 virtual void SetUp() OVERRIDE {
102 ui_task_runner_ = new AutoThreadTaskRunner( 75 ui_task_runner_ = new AutoThreadTaskRunner(
103 message_loop_.message_loop_proxy(), 76 message_loop_.message_loop_proxy(),
104 base::Bind(&ChromotingHostTest::QuitMainMessageLoop, 77 base::Bind(&ChromotingHostTest::QuitMainMessageLoop,
105 base::Unretained(this))); 78 base::Unretained(this)));
106 79
107 EXPECT_CALL(context_, ui_task_runner()) 80 EXPECT_CALL(context_, ui_task_runner())
108 .Times(AnyNumber()) 81 .Times(AnyNumber())
109 .WillRepeatedly(Return(ui_task_runner_.get())); 82 .WillRepeatedly(Return(ui_task_runner_.get()));
110 EXPECT_CALL(context_, capture_task_runner()) 83 EXPECT_CALL(context_, capture_task_runner())
111 .Times(AnyNumber()) 84 .Times(AnyNumber())
112 .WillRepeatedly(Return(ui_task_runner_.get())); 85 .WillRepeatedly(Return(ui_task_runner_.get()));
113 EXPECT_CALL(context_, encode_task_runner()) 86 EXPECT_CALL(context_, encode_task_runner())
114 .Times(AnyNumber()) 87 .Times(AnyNumber())
115 .WillRepeatedly(Return(ui_task_runner_.get())); 88 .WillRepeatedly(Return(ui_task_runner_.get()));
116 EXPECT_CALL(context_, network_task_runner()) 89 EXPECT_CALL(context_, network_task_runner())
117 .Times(AnyNumber()) 90 .Times(AnyNumber())
118 .WillRepeatedly(Return(ui_task_runner_.get())); 91 .WillRepeatedly(Return(ui_task_runner_.get()));
119 92
120 desktop_environment_factory_.reset(new MockDesktopEnvironmentFactory()); 93 desktop_environment_factory_.reset(new MockDesktopEnvironmentFactory());
94 EXPECT_CALL(*desktop_environment_factory_, CreatePtr(_))
95 .Times(AnyNumber())
96 .WillRepeatedly(Invoke(this,
97 &ChromotingHostTest::CreateDesktopEnvironment));
98
121 session_manager_ = new protocol::MockSessionManager(); 99 session_manager_ = new protocol::MockSessionManager();
122 100
123 host_ = new ChromotingHost( 101 host_ = new ChromotingHost(
124 &signal_strategy_, 102 &signal_strategy_,
125 desktop_environment_factory_.get(), 103 desktop_environment_factory_.get(),
126 scoped_ptr<protocol::SessionManager>(session_manager_), 104 scoped_ptr<protocol::SessionManager>(session_manager_),
127 context_.capture_task_runner(), 105 context_.capture_task_runner(),
128 context_.encode_task_runner(), 106 context_.encode_task_runner(),
129 context_.network_task_runner()); 107 context_.network_task_runner());
130 host_->AddStatusObserver(&host_status_observer_); 108 host_->AddStatusObserver(&host_status_observer_);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 protocol::CandidateSessionConfig::CreateDefault(); 198 protocol::CandidateSessionConfig::CreateDefault();
221 } 199 }
222 200
223 // Helper method to pretend a client is connected to ChromotingHost. 201 // Helper method to pretend a client is connected to ChromotingHost.
224 void SimulateClientConnection(int connection_index, bool authenticate, 202 void SimulateClientConnection(int connection_index, bool authenticate,
225 bool reject) { 203 bool reject) {
226 scoped_ptr<protocol::ConnectionToClient> connection = 204 scoped_ptr<protocol::ConnectionToClient> connection =
227 ((connection_index == 0) ? owned_connection1_ : owned_connection2_). 205 ((connection_index == 0) ? owned_connection1_ : owned_connection2_).
228 PassAs<protocol::ConnectionToClient>(); 206 PassAs<protocol::ConnectionToClient>();
229 protocol::ConnectionToClient* connection_ptr = connection.get(); 207 protocol::ConnectionToClient* connection_ptr = connection.get();
230 scoped_ptr<DesktopEnvironment> desktop_environment =
231 host_->desktop_environment_factory_->Create();
232 connection_ptr->set_input_stub(desktop_environment->event_executor());
233
234 scoped_refptr<ClientSession> client = new ClientSession( 208 scoped_refptr<ClientSession> client = new ClientSession(
235 host_.get(), 209 host_.get(),
236 context_.capture_task_runner(), 210 context_.capture_task_runner(),
237 context_.encode_task_runner(), 211 context_.encode_task_runner(),
238 context_.network_task_runner(), 212 context_.network_task_runner(),
239 connection.Pass(), 213 connection.Pass(),
240 desktop_environment.Pass(), 214 desktop_environment_factory_.get(),
241 base::TimeDelta()); 215 base::TimeDelta());
242 connection_ptr->set_host_stub(client); 216 connection_ptr->set_host_stub(client);
217 connection_ptr->set_input_stub(
218 client->desktop_environment()->event_executor());
243 219
244 context_.network_task_runner()->PostTask( 220 context_.network_task_runner()->PostTask(
245 FROM_HERE, base::Bind(&ChromotingHostTest::AddClientToHost, 221 FROM_HERE, base::Bind(&ChromotingHostTest::AddClientToHost,
246 host_, client)); 222 host_, client));
247 223
248 if (authenticate) { 224 if (authenticate) {
249 context_.network_task_runner()->PostTask( 225 context_.network_task_runner()->PostTask(
250 FROM_HERE, base::Bind(&ClientSession::OnConnectionAuthenticated, 226 FROM_HERE, base::Bind(&ClientSession::OnConnectionAuthenticated,
251 client, connection_ptr)); 227 client, connection_ptr));
252 if (!reject) { 228 if (!reject) {
(...skipping 16 matching lines...) Expand all
269 // Make sure that the host has been properly deleted. 245 // Make sure that the host has been properly deleted.
270 DCHECK(host_.get() == NULL); 246 DCHECK(host_.get() == NULL);
271 } 247 }
272 248
273 // Change the session route for |client1_|. 249 // Change the session route for |client1_|.
274 void ChangeSessionRoute(const std::string& channel_name, 250 void ChangeSessionRoute(const std::string& channel_name,
275 const protocol::TransportRoute& route) { 251 const protocol::TransportRoute& route) {
276 host_->OnSessionRouteChange(get_client(0), channel_name, route); 252 host_->OnSessionRouteChange(get_client(0), channel_name, route);
277 } 253 }
278 254
255 DesktopEnvironment* CreateDesktopEnvironment(ClientSession* client) {
256 scoped_ptr<EventExecutor> event_executor(new EventExecutorFake());
257 scoped_ptr<VideoFrameCapturer> video_capturer(new VideoFrameCapturerFake());
258 return new DesktopEnvironment(scoped_ptr<AudioCapturer>(NULL),
259 event_executor.Pass(),
260 video_capturer.Pass());
261 }
262
279 void DisconnectAllClients() { 263 void DisconnectAllClients() {
280 host_->DisconnectAllClients(); 264 host_->DisconnectAllClients();
281 } 265 }
282 266
283 // Helper method to disconnect client 1 from the host. 267 // Helper method to disconnect client 1 from the host.
284 void DisconnectClient1() { 268 void DisconnectClient1() {
285 client1_->OnConnectionClosed(connection1_, protocol::OK); 269 client1_->OnConnectionClosed(connection1_, protocol::OK);
286 } 270 }
287 271
288 // Notify |host_| that the authenticating client has been rejected. 272 // Notify |host_| that the authenticating client has been rejected.
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 .RetiresOnSaturation(); 395 .RetiresOnSaturation();
412 } 396 }
413 } 397 }
414 398
415 protected: 399 protected:
416 MessageLoop message_loop_; 400 MessageLoop message_loop_;
417 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_; 401 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_;
418 MockChromotingHostContext context_; 402 MockChromotingHostContext context_;
419 MockConnectionToClientEventHandler handler_; 403 MockConnectionToClientEventHandler handler_;
420 MockSignalStrategy signal_strategy_; 404 MockSignalStrategy signal_strategy_;
421 scoped_ptr<DesktopEnvironmentFactory> desktop_environment_factory_; 405 scoped_ptr<MockDesktopEnvironmentFactory> desktop_environment_factory_;
422 scoped_ptr<It2MeHostUserInterface> it2me_host_user_interface_; 406 scoped_ptr<It2MeHostUserInterface> it2me_host_user_interface_;
423 scoped_refptr<ChromotingHost> host_; 407 scoped_refptr<ChromotingHost> host_;
424 MockHostStatusObserver host_status_observer_; 408 MockHostStatusObserver host_status_observer_;
425 protocol::MockSessionManager* session_manager_; 409 protocol::MockSessionManager* session_manager_;
426 std::string xmpp_login_; 410 std::string xmpp_login_;
427 MockConnectionToClient* connection1_; 411 MockConnectionToClient* connection1_;
428 scoped_ptr<MockConnectionToClient> owned_connection1_; 412 scoped_ptr<MockConnectionToClient> owned_connection1_;
429 ClientSession* client1_; 413 ClientSession* client1_;
430 std::string session_jid1_; 414 std::string session_jid1_;
431 MockSession* session1_; // Owned by |connection_|. 415 MockSession* session1_; // Owned by |connection_|.
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 ExpectClientDisconnected(0, true, video_packet_sent, 659 ExpectClientDisconnected(0, true, video_packet_sent,
676 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost)); 660 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost));
677 EXPECT_CALL(host_status_observer_, OnShutdown()); 661 EXPECT_CALL(host_status_observer_, OnShutdown());
678 662
679 host_->Start(xmpp_login_); 663 host_->Start(xmpp_login_);
680 SimulateClientConnection(0, true, false); 664 SimulateClientConnection(0, true, false);
681 message_loop_.Run(); 665 message_loop_.Run();
682 } 666 }
683 667
684 } // namespace remoting 668 } // 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