| Index: remoting/host/chromoting_host_unittest.cc
|
| diff --git a/remoting/host/chromoting_host_unittest.cc b/remoting/host/chromoting_host_unittest.cc
|
| index 3a82f0c23a101bbe497ce35a6a2410b815f11c12..ce1f68e7c1aa59b6422007c69a7ffec9a0273215 100644
|
| --- a/remoting/host/chromoting_host_unittest.cc
|
| +++ b/remoting/host/chromoting_host_unittest.cc
|
| @@ -5,10 +5,14 @@
|
| #include "base/bind.h"
|
| #include "base/memory/scoped_ptr.h"
|
| #include "base/message_loop_proxy.h"
|
| +#include "remoting/base/auto_thread_task_runner.h"
|
| #include "remoting/jingle_glue/mock_objects.h"
|
| #include "remoting/host/audio_capturer.h"
|
| #include "remoting/host/chromoting_host_context.h"
|
| #include "remoting/host/chromoting_host.h"
|
| +#include "remoting/host/desktop_environment.h"
|
| +#include "remoting/host/desktop_environment_factory.h"
|
| +#include "remoting/host/event_executor_fake.h"
|
| #include "remoting/host/host_mock_objects.h"
|
| #include "remoting/host/it2me_host_user_interface.h"
|
| #include "remoting/host/video_frame_capturer_fake.h"
|
| @@ -62,39 +66,63 @@ void DoNothing() {
|
|
|
| } // namespace
|
|
|
| +class MockDesktopEnvironmentFactory : public DesktopEnvironmentFactory {
|
| + public:
|
| + MockDesktopEnvironmentFactory();
|
| + virtual ~MockDesktopEnvironmentFactory();
|
| +
|
| + virtual scoped_ptr<DesktopEnvironment> Create(
|
| + ChromotingHostContext* context) OVERRIDE;
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(MockDesktopEnvironmentFactory);
|
| +};
|
| +
|
| +MockDesktopEnvironmentFactory::MockDesktopEnvironmentFactory() {
|
| +}
|
| +
|
| +MockDesktopEnvironmentFactory::~MockDesktopEnvironmentFactory() {
|
| +}
|
| +
|
| +scoped_ptr<DesktopEnvironment> MockDesktopEnvironmentFactory::Create(
|
| + ChromotingHostContext* context) {
|
| + scoped_ptr<EventExecutor> event_executor(new EventExecutorFake());
|
| + scoped_ptr<VideoFrameCapturer> video_capturer(new VideoFrameCapturerFake());
|
| + return scoped_ptr<DesktopEnvironment>(new DesktopEnvironment(
|
| + scoped_ptr<AudioCapturer>(NULL),
|
| + event_executor.Pass(),
|
| + video_capturer.Pass()));
|
| +}
|
| +
|
| class ChromotingHostTest : public testing::Test {
|
| public:
|
| ChromotingHostTest() {
|
| }
|
|
|
| virtual void SetUp() OVERRIDE {
|
| - message_loop_proxy_ = base::MessageLoopProxy::current();
|
| + ui_task_runner_ = new AutoThreadTaskRunner(
|
| + message_loop_.message_loop_proxy(),
|
| + base::Bind(&ChromotingHostTest::QuitMainMessageLoop,
|
| + base::Unretained(this)));
|
|
|
| EXPECT_CALL(context_, ui_task_runner())
|
| .Times(AnyNumber())
|
| - .WillRepeatedly(Return(message_loop_proxy_.get()));
|
| + .WillRepeatedly(Return(ui_task_runner_.get()));
|
| EXPECT_CALL(context_, capture_task_runner())
|
| .Times(AnyNumber())
|
| - .WillRepeatedly(Return(message_loop_proxy_.get()));
|
| + .WillRepeatedly(Return(ui_task_runner_.get()));
|
| EXPECT_CALL(context_, encode_task_runner())
|
| .Times(AnyNumber())
|
| - .WillRepeatedly(Return(message_loop_proxy_.get()));
|
| + .WillRepeatedly(Return(ui_task_runner_.get()));
|
| EXPECT_CALL(context_, network_task_runner())
|
| .Times(AnyNumber())
|
| - .WillRepeatedly(Return(message_loop_proxy_.get()));
|
| -
|
| - scoped_ptr<VideoFrameCapturer> capturer(new VideoFrameCapturerFake());
|
| - scoped_ptr<AudioCapturer> audio_capturer(NULL);
|
| - event_executor_ = new MockEventExecutor();
|
| - desktop_environment_ = DesktopEnvironment::CreateFake(
|
| - &context_,
|
| - capturer.Pass(),
|
| - scoped_ptr<EventExecutor>(event_executor_),
|
| - audio_capturer.Pass());
|
| + .WillRepeatedly(Return(ui_task_runner_.get()));
|
| +
|
| + desktop_environment_factory_.reset(new MockDesktopEnvironmentFactory());
|
| session_manager_ = new protocol::MockSessionManager();
|
|
|
| host_ = new ChromotingHost(
|
| - &context_, &signal_strategy_, desktop_environment_.get(),
|
| + &context_, &signal_strategy_, desktop_environment_factory_.get(),
|
| scoped_ptr<protocol::SessionManager>(session_manager_));
|
| host_->AddStatusObserver(&host_status_observer_);
|
|
|
| @@ -145,11 +173,11 @@ class ChromotingHostTest : public testing::Test {
|
| EXPECT_CALL(*session2_, config())
|
| .WillRepeatedly(ReturnRef(session_config2_));
|
|
|
| - owned_connection1_.reset(new MockConnectionToClient(
|
| - session1_, &host_stub1_, desktop_environment_->event_executor()));
|
| + owned_connection1_.reset(new MockConnectionToClient(session1_,
|
| + &host_stub1_));
|
| connection1_ = owned_connection1_.get();
|
| - owned_connection2_.reset(new MockConnectionToClient(
|
| - session2_, &host_stub2_, desktop_environment_->event_executor()));
|
| + owned_connection2_.reset(new MockConnectionToClient(session2_,
|
| + &host_stub2_));
|
| connection2_ = owned_connection2_.get();
|
|
|
| ON_CALL(video_stub1_, ProcessVideoPacketPtr(_, _))
|
| @@ -194,12 +222,17 @@ class ChromotingHostTest : public testing::Test {
|
| ((connection_index == 0) ? owned_connection1_ : owned_connection2_).
|
| PassAs<protocol::ConnectionToClient>();
|
| protocol::ConnectionToClient* connection_ptr = connection.get();
|
| + scoped_ptr<DesktopEnvironment> desktop_environment =
|
| + host_->desktop_environment_factory_->Create(&context_);
|
| + connection_ptr->set_input_stub(desktop_environment->event_executor());
|
| +
|
| ClientSession* client = new ClientSession(
|
| host_.get(),
|
| + context_.capture_task_runner(),
|
| + context_.encode_task_runner(),
|
| + context_.network_task_runner(),
|
| connection.Pass(),
|
| - desktop_environment_->event_executor(),
|
| - desktop_environment_->event_executor(),
|
| - desktop_environment_->capturer(),
|
| + host_->desktop_environment_factory_->Create(&context_),
|
| base::TimeDelta());
|
| connection_ptr->set_host_stub(client);
|
|
|
| @@ -265,12 +298,20 @@ class ChromotingHostTest : public testing::Test {
|
| static void AddClientToHost(scoped_refptr<ChromotingHost> host,
|
| ClientSession* session) {
|
| host->clients_.push_back(session);
|
| + host->clients_count_++;
|
| }
|
|
|
| void ShutdownHost() {
|
| - message_loop_.PostTask(
|
| - FROM_HERE, base::Bind(&ChromotingHost::Shutdown, host_,
|
| - base::Bind(&PostQuitTask, &message_loop_)));
|
| + ui_task_runner_->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&ChromotingHost::Shutdown, host_,
|
| + base::Bind(&ChromotingHostTest::ReleaseUiTaskRunner,
|
| + base::Unretained(this))));
|
| + }
|
| +
|
| + void ReleaseUiTaskRunner() {
|
| + it2me_host_user_interface_.reset();
|
| + ui_task_runner_ = NULL;
|
| }
|
|
|
| void QuitMainMessageLoop() {
|
| @@ -304,12 +345,9 @@ class ChromotingHostTest : public testing::Test {
|
| EXPECT_CALL(host_status_observer_, OnClientAuthenticated(session_jid));
|
| EXPECT_CALL(host_status_observer_, OnClientConnected(session_jid))
|
| .After(client_authenticated);
|
| - Expectation session_started =
|
| - EXPECT_CALL(*event_executor_, OnSessionStartedPtr(_))
|
| - .After(client_authenticated);
|
| Expectation video_packet_sent =
|
| EXPECT_CALL(video_stub, ProcessVideoPacketPtr(_, _))
|
| - .After(session_started)
|
| + .After(client_authenticated)
|
| .WillOnce(DoAll(
|
| action,
|
| RunDoneTask()))
|
| @@ -355,24 +393,21 @@ class ChromotingHostTest : public testing::Test {
|
| A action) {
|
| const std::string& session_jid = get_session_jid(connection_index);
|
|
|
| - EXPECT_CALL(*event_executor_, OnSessionFinished())
|
| - .After(after)
|
| - .WillOnce(action);
|
| if (expect_host_status_change) {
|
| EXPECT_CALL(host_status_observer_, OnClientDisconnected(session_jid))
|
| .After(after)
|
| + .WillOnce(action)
|
| .RetiresOnSaturation();
|
| }
|
| }
|
|
|
| protected:
|
| MessageLoop message_loop_;
|
| - scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
|
| + scoped_refptr<AutoThreadTaskRunner> ui_task_runner_;
|
| MockChromotingHostContext context_;
|
| MockConnectionToClientEventHandler handler_;
|
| MockSignalStrategy signal_strategy_;
|
| - MockEventExecutor* event_executor_;
|
| - scoped_ptr<DesktopEnvironment> desktop_environment_;
|
| + scoped_ptr<DesktopEnvironmentFactory> desktop_environment_factory_;
|
| scoped_ptr<It2MeHostUserInterface> it2me_host_user_interface_;
|
| scoped_refptr<ChromotingHost> host_;
|
| MockHostStatusObserver host_status_observer_;
|
| @@ -433,10 +468,7 @@ TEST_F(ChromotingHostTest, StartAndShutdown) {
|
| EXPECT_CALL(host_status_observer_, OnShutdown()).After(start);
|
|
|
| host_->Start(xmpp_login_);
|
| - message_loop_.PostTask(
|
| - FROM_HERE, base::Bind(
|
| - &ChromotingHost::Shutdown, host_.get(),
|
| - base::Bind(&PostQuitTask, &message_loop_)));
|
| + ShutdownHost();
|
| message_loop_.Run();
|
| }
|
|
|
|
|