blob: e6b74ded23e75ae83fb3bfbf32a85af3918b15fc [file] [log] [blame]
zijiehedd0b05c2016-05-05 18:44:151// 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
23namespace remoting {
24namespace test {
25
26namespace {
27
zijiehef32ccbbf2016-05-06 18:18:2328void OutputFakeConnectionEventLogger(const FakeConnectionEventLogger& logger) {
29 std::cout << logger;
zijiehedd0b05c2016-05-05 18:44:1530}
31
32constexpr char kSessionJid[] = "user@domain/rest-of-jid";
33
34} // namespace
35
36using ::remoting::protocol::MockSession;
37
38It2MeStandaloneHost::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_) {
zijiehedd0b05c2016-05-05 18:44:1557 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_));
zijiehedd0b05c2016-05-05 18:44:1561 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
68It2MeStandaloneHost::~It2MeStandaloneHost() {}
69
70void It2MeStandaloneHost::Run() {
71 main_task_runner_->PostTask(
72 FROM_HERE,
73 base::Bind(&It2MeStandaloneHost::Connect, base::Unretained(this)));
74 run_loop_.Run();
75}
76
77void It2MeStandaloneHost::StartOutputTimer() {
78 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(1),
zijiehef32ccbbf2016-05-06 18:18:2379 base::Bind(&OutputFakeConnectionEventLogger,
80 base::ConstRef(event_logger_)));
zijiehedd0b05c2016-05-05 18:44:1581}
82
83void It2MeStandaloneHost::Connect() {
zijiehe4aa6ea42016-11-12 01:28:1684 DesktopEnvironmentOptions options =
85 DesktopEnvironmentOptions::CreateDefault();
86 options.set_enable_user_interface(false);
zijiehedd0b05c2016-05-05 18:44:1587 session_.reset(new ClientSession(
sergeyucd16e2062016-09-12 19:28:3588 &handler_, std::unique_ptr<protocol::ConnectionToClient>(&connection_),
zijiehe4aa6ea42016-11-12 01:28:1689 &factory_, options, base::TimeDelta(),
90 scoped_refptr<protocol::PairingRegistry>(),
zijiehedd0b05c2016-05-05 18:44:1591 std::vector<HostExtension*>()));
sergeyu4e1f4cd2016-09-27 00:42:5292 session_->OnConnectionAuthenticated();
93 session_->OnConnectionChannelsConnected();
94 session_->CreateMediaStreams();
zijiehedd0b05c2016-05-05 18:44:1595}
96
97} // namespace test
98} // namespace remoting