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

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

Issue 11412305: Use AutoThread in ChromotingHostContext & NPAPI plugin. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments. Created 8 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 | Annotate | Revision Log
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/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop_proxy.h" 8 #include "base/message_loop_proxy.h"
9 #include "remoting/base/auto_thread_task_runner.h" 9 #include "remoting/base/auto_thread_task_runner.h"
10 #include "remoting/jingle_glue/mock_objects.h" 10 #include "remoting/jingle_glue/mock_objects.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 public: 111 public:
112 ChromotingHostTest() { 112 ChromotingHostTest() {
113 } 113 }
114 114
115 virtual void SetUp() OVERRIDE { 115 virtual void SetUp() OVERRIDE {
116 ui_task_runner_ = new AutoThreadTaskRunner( 116 ui_task_runner_ = new AutoThreadTaskRunner(
117 message_loop_.message_loop_proxy(), 117 message_loop_.message_loop_proxy(),
118 base::Bind(&ChromotingHostTest::QuitMainMessageLoop, 118 base::Bind(&ChromotingHostTest::QuitMainMessageLoop,
119 base::Unretained(this))); 119 base::Unretained(this)));
120 120
121 EXPECT_CALL(context_, ui_task_runner())
122 .Times(AnyNumber())
123 .WillRepeatedly(Return(ui_task_runner_.get()));
124 EXPECT_CALL(context_, capture_task_runner())
125 .Times(AnyNumber())
126 .WillRepeatedly(Return(ui_task_runner_.get()));
127 EXPECT_CALL(context_, encode_task_runner())
128 .Times(AnyNumber())
129 .WillRepeatedly(Return(ui_task_runner_.get()));
130 EXPECT_CALL(context_, network_task_runner())
131 .Times(AnyNumber())
132 .WillRepeatedly(Return(ui_task_runner_.get()));
133
134 desktop_environment_factory_.reset(new MockDesktopEnvironmentFactory()); 121 desktop_environment_factory_.reset(new MockDesktopEnvironmentFactory());
135 EXPECT_CALL(*desktop_environment_factory_, CreatePtr(_)) 122 EXPECT_CALL(*desktop_environment_factory_, CreatePtr(_))
136 .Times(AnyNumber()) 123 .Times(AnyNumber())
137 .WillRepeatedly(Invoke(this, 124 .WillRepeatedly(Invoke(this,
138 &ChromotingHostTest::CreateDesktopEnvironment)); 125 &ChromotingHostTest::CreateDesktopEnvironment));
139 126
140 session_manager_ = new protocol::MockSessionManager(); 127 session_manager_ = new protocol::MockSessionManager();
141 128
142 host_ = new ChromotingHost( 129 host_ = new ChromotingHost(
143 &signal_strategy_, 130 &signal_strategy_,
144 desktop_environment_factory_.get(), 131 desktop_environment_factory_.get(),
145 scoped_ptr<protocol::SessionManager>(session_manager_), 132 scoped_ptr<protocol::SessionManager>(session_manager_),
146 context_.audio_task_runner(), 133 ui_task_runner_, // Audio
147 context_.capture_task_runner(), 134 ui_task_runner_, // Video capture
148 context_.encode_task_runner(), 135 ui_task_runner_, // Video encode
149 context_.network_task_runner()); 136 ui_task_runner_); // Network
150 host_->AddStatusObserver(&host_status_observer_); 137 host_->AddStatusObserver(&host_status_observer_);
151 138
152 disconnect_window_ = new MockDisconnectWindow(); 139 disconnect_window_ = new MockDisconnectWindow();
153 continue_window_ = new MockContinueWindow(); 140 continue_window_ = new MockContinueWindow();
154 local_input_monitor_ = new MockLocalInputMonitor(); 141 local_input_monitor_ = new MockLocalInputMonitor();
155 it2me_host_user_interface_.reset( 142 it2me_host_user_interface_.reset(
156 new MockIt2MeHostUserInterface(context_.network_task_runner(), 143 new MockIt2MeHostUserInterface(ui_task_runner_, ui_task_runner_));
157 context_.ui_task_runner()));
158 it2me_host_user_interface_->InitFrom( 144 it2me_host_user_interface_->InitFrom(
159 scoped_ptr<DisconnectWindow>(disconnect_window_), 145 scoped_ptr<DisconnectWindow>(disconnect_window_),
160 scoped_ptr<ContinueWindow>(continue_window_), 146 scoped_ptr<ContinueWindow>(continue_window_),
161 scoped_ptr<LocalInputMonitor>(local_input_monitor_)); 147 scoped_ptr<LocalInputMonitor>(local_input_monitor_));
162 148
163 it2me_host_user_interface_->Start( 149 it2me_host_user_interface_->Start(
164 host_, base::Bind(&ChromotingHost::Shutdown, host_, base::Closure())); 150 host_, base::Bind(&ChromotingHost::Shutdown, host_, base::Closure()));
165 151
166 xmpp_login_ = "host@domain"; 152 xmpp_login_ = "host@domain";
167 session1_ = new MockSession(); 153 session1_ = new MockSession();
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 229
244 // Helper method to pretend a client is connected to ChromotingHost. 230 // Helper method to pretend a client is connected to ChromotingHost.
245 void SimulateClientConnection(int connection_index, bool authenticate, 231 void SimulateClientConnection(int connection_index, bool authenticate,
246 bool reject) { 232 bool reject) {
247 scoped_ptr<protocol::ConnectionToClient> connection = 233 scoped_ptr<protocol::ConnectionToClient> connection =
248 ((connection_index == 0) ? owned_connection1_ : owned_connection2_). 234 ((connection_index == 0) ? owned_connection1_ : owned_connection2_).
249 PassAs<protocol::ConnectionToClient>(); 235 PassAs<protocol::ConnectionToClient>();
250 protocol::ConnectionToClient* connection_ptr = connection.get(); 236 protocol::ConnectionToClient* connection_ptr = connection.get();
251 scoped_refptr<ClientSession> client = new ClientSession( 237 scoped_refptr<ClientSession> client = new ClientSession(
252 host_.get(), 238 host_.get(),
253 context_.audio_task_runner(), 239 ui_task_runner_, // Audio
254 context_.capture_task_runner(), 240 ui_task_runner_, // Video capture
255 context_.encode_task_runner(), 241 ui_task_runner_, // Video encode
256 context_.network_task_runner(), 242 ui_task_runner_, // Network
257 connection.Pass(), 243 connection.Pass(),
258 desktop_environment_factory_.get(), 244 desktop_environment_factory_.get(),
259 base::TimeDelta()); 245 base::TimeDelta());
260 connection_ptr->set_host_stub(client); 246 connection_ptr->set_host_stub(client);
261 connection_ptr->set_input_stub( 247 connection_ptr->set_input_stub(
262 client->desktop_environment()->event_executor()); 248 client->desktop_environment()->event_executor());
263 249
264 context_.network_task_runner()->PostTask( 250 ui_task_runner_->PostTask(
265 FROM_HERE, base::Bind(&ChromotingHostTest::AddClientToHost, 251 FROM_HERE, base::Bind(&ChromotingHostTest::AddClientToHost,
266 host_, client)); 252 host_, client));
267 253
268 if (authenticate) { 254 if (authenticate) {
269 context_.network_task_runner()->PostTask( 255 ui_task_runner_->PostTask(
270 FROM_HERE, base::Bind(&ClientSession::OnConnectionAuthenticated, 256 FROM_HERE, base::Bind(&ClientSession::OnConnectionAuthenticated,
271 client, connection_ptr)); 257 client, connection_ptr));
272 if (!reject) { 258 if (!reject) {
273 context_.network_task_runner()->PostTask( 259 ui_task_runner_->PostTask(
274 FROM_HERE, 260 FROM_HERE,
275 base::Bind(&ClientSession::OnConnectionChannelsConnected, 261 base::Bind(&ClientSession::OnConnectionChannelsConnected,
276 client, connection_ptr)); 262 client, connection_ptr));
277 } 263 }
278 } else { 264 } else {
279 context_.network_task_runner()->PostTask( 265 ui_task_runner_->PostTask(
280 FROM_HERE, base::Bind(&ClientSession::OnConnectionClosed, 266 FROM_HERE, base::Bind(&ClientSession::OnConnectionClosed,
281 client, connection_ptr, 267 client, connection_ptr,
282 protocol::AUTHENTICATION_FAILED)); 268 protocol::AUTHENTICATION_FAILED));
283 } 269 }
284 270
285 get_client(connection_index) = client; 271 get_client(connection_index) = client;
286 } 272 }
287 273
288 virtual void TearDown() OVERRIDE { 274 virtual void TearDown() OVERRIDE {
289 // Make sure that the host has been properly deleted. 275 // Make sure that the host has been properly deleted.
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 EXPECT_CALL(host_status_observer_, OnClientDisconnected(session_jid)) 422 EXPECT_CALL(host_status_observer_, OnClientDisconnected(session_jid))
437 .After(after) 423 .After(after)
438 .WillOnce(action) 424 .WillOnce(action)
439 .RetiresOnSaturation(); 425 .RetiresOnSaturation();
440 } 426 }
441 } 427 }
442 428
443 protected: 429 protected:
444 MessageLoop message_loop_; 430 MessageLoop message_loop_;
445 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_; 431 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_;
446 MockChromotingHostContext context_;
447 MockConnectionToClientEventHandler handler_; 432 MockConnectionToClientEventHandler handler_;
448 MockSignalStrategy signal_strategy_; 433 MockSignalStrategy signal_strategy_;
449 scoped_ptr<MockDesktopEnvironmentFactory> desktop_environment_factory_; 434 scoped_ptr<MockDesktopEnvironmentFactory> desktop_environment_factory_;
450 scoped_ptr<MockIt2MeHostUserInterface> it2me_host_user_interface_; 435 scoped_ptr<MockIt2MeHostUserInterface> it2me_host_user_interface_;
451 scoped_refptr<ChromotingHost> host_; 436 scoped_refptr<ChromotingHost> host_;
452 MockHostStatusObserver host_status_observer_; 437 MockHostStatusObserver host_status_observer_;
453 protocol::MockSessionManager* session_manager_; 438 protocol::MockSessionManager* session_manager_;
454 std::string xmpp_login_; 439 std::string xmpp_login_;
455 MockConnectionToClient* connection1_; 440 MockConnectionToClient* connection1_;
456 scoped_ptr<MockConnectionToClient> owned_connection1_; 441 scoped_ptr<MockConnectionToClient> owned_connection1_;
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 ExpectClientDisconnected(0, true, video_packet_sent, 689 ExpectClientDisconnected(0, true, video_packet_sent,
705 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost)); 690 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost));
706 EXPECT_CALL(host_status_observer_, OnShutdown()); 691 EXPECT_CALL(host_status_observer_, OnShutdown());
707 692
708 host_->Start(xmpp_login_); 693 host_->Start(xmpp_login_);
709 SimulateClientConnection(0, true, false); 694 SimulateClientConnection(0, true, false);
710 message_loop_.Run(); 695 message_loop_.Run();
711 } 696 }
712 697
713 } // namespace remoting 698 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/chromoting_host_context_unittest.cc ('k') | remoting/host/desktop_environment_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698