zijiehe | dd0b05c | 2016-05-05 18:44:15 | [diff] [blame] | 1 | // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "remoting/test/it2me_standalone_host.h" |
| 6 | |
| 7 | #include <iostream> |
| 8 | #include <vector> |
| 9 | |
| 10 | #include "base/bind.h" |
| 11 | #include "base/location.h" |
| 12 | #include "base/logging.h" |
| 13 | #include "base/memory/ptr_util.h" |
| 14 | #include "base/memory/ref_counted.h" |
| 15 | #include "base/time/time.h" |
| 16 | #include "remoting/base/auto_thread_task_runner.h" |
| 17 | #include "remoting/host/chromoting_host_context.h" |
| 18 | #include "remoting/host/host_extension.h" |
| 19 | #include "remoting/protocol/pairing_registry.h" |
| 20 | #include "remoting/protocol/protocol_mock_objects.h" |
| 21 | #include "remoting/protocol/session_config.h" |
| 22 | |
| 23 | namespace remoting { |
| 24 | namespace test { |
| 25 | |
| 26 | namespace { |
| 27 | |
zijiehe | f32ccbbf | 2016-05-06 18:18:23 | [diff] [blame] | 28 | void OutputFakeConnectionEventLogger(const FakeConnectionEventLogger& logger) { |
| 29 | std::cout << logger; |
zijiehe | dd0b05c | 2016-05-05 18:44:15 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | constexpr char kSessionJid[] = "user@domain/rest-of-jid"; |
| 33 | |
| 34 | } // namespace |
| 35 | |
| 36 | using ::remoting::protocol::MockSession; |
| 37 | |
| 38 | It2MeStandaloneHost::It2MeStandaloneHost() |
| 39 | : context_(ChromotingHostContext::Create( |
| 40 | new AutoThreadTaskRunner( |
| 41 | message_loop_.task_runner(), run_loop_.QuitClosure()))), |
| 42 | main_task_runner_(context_->file_task_runner()), |
| 43 | factory_(main_task_runner_, |
| 44 | context_->video_capture_task_runner(), |
| 45 | context_->input_task_runner(), |
| 46 | context_->ui_task_runner()), |
| 47 | connection_(base::WrapUnique(new testing::NiceMock<MockSession>())), |
| 48 | session_jid_(kSessionJid), |
| 49 | #if defined(OS_LINUX) |
| 50 | // We cannot support audio capturing for linux, since a pipe name is |
| 51 | // needed to initialize AudioCapturerLinux. |
| 52 | config_(protocol::SessionConfig::ForTest()), |
| 53 | #else |
| 54 | config_(protocol::SessionConfig::ForTestWithAudio()), |
| 55 | #endif |
| 56 | event_logger_(&connection_) { |
zijiehe | dd0b05c | 2016-05-05 18:44:15 | [diff] [blame] | 57 | EXPECT_CALL(*static_cast<MockSession*>(connection_.session()), jid()) |
| 58 | .WillRepeatedly(testing::ReturnRef(session_jid_)); |
| 59 | EXPECT_CALL(*static_cast<MockSession*>(connection_.session()), config()) |
| 60 | .WillRepeatedly(testing::ReturnRef(*config_)); |
zijiehe | dd0b05c | 2016-05-05 18:44:15 | [diff] [blame] | 61 | connection_.set_video_stub(event_logger_.video_stub()); |
| 62 | connection_.set_client_stub(event_logger_.client_stub()); |
| 63 | connection_.set_host_stub(event_logger_.host_stub()); |
| 64 | connection_.set_video_encode_task_runner( |
| 65 | context_->video_encode_task_runner()); |
| 66 | } |
| 67 | |
| 68 | It2MeStandaloneHost::~It2MeStandaloneHost() {} |
| 69 | |
| 70 | void It2MeStandaloneHost::Run() { |
| 71 | main_task_runner_->PostTask( |
| 72 | FROM_HERE, |
| 73 | base::Bind(&It2MeStandaloneHost::Connect, base::Unretained(this))); |
| 74 | run_loop_.Run(); |
| 75 | } |
| 76 | |
| 77 | void It2MeStandaloneHost::StartOutputTimer() { |
| 78 | timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(1), |
zijiehe | f32ccbbf | 2016-05-06 18:18:23 | [diff] [blame] | 79 | base::Bind(&OutputFakeConnectionEventLogger, |
| 80 | base::ConstRef(event_logger_))); |
zijiehe | dd0b05c | 2016-05-05 18:44:15 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | void It2MeStandaloneHost::Connect() { |
zijiehe | 4aa6ea4 | 2016-11-12 01:28:16 | [diff] [blame] | 84 | DesktopEnvironmentOptions options = |
| 85 | DesktopEnvironmentOptions::CreateDefault(); |
| 86 | options.set_enable_user_interface(false); |
zijiehe | dd0b05c | 2016-05-05 18:44:15 | [diff] [blame] | 87 | session_.reset(new ClientSession( |
sergeyu | cd16e206 | 2016-09-12 19:28:35 | [diff] [blame] | 88 | &handler_, std::unique_ptr<protocol::ConnectionToClient>(&connection_), |
zijiehe | 4aa6ea4 | 2016-11-12 01:28:16 | [diff] [blame] | 89 | &factory_, options, base::TimeDelta(), |
| 90 | scoped_refptr<protocol::PairingRegistry>(), |
zijiehe | dd0b05c | 2016-05-05 18:44:15 | [diff] [blame] | 91 | std::vector<HostExtension*>())); |
sergeyu | 4e1f4cd | 2016-09-27 00:42:52 | [diff] [blame] | 92 | session_->OnConnectionAuthenticated(); |
| 93 | session_->OnConnectionChannelsConnected(); |
| 94 | session_->CreateMediaStreams(); |
zijiehe | dd0b05c | 2016-05-05 18:44:15 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | } // namespace test |
| 98 | } // namespace remoting |