blob: 9dbaff3b4da3ffe0563892bd24479f83a45d9949 [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
28void OutputFakeConnectionEventLogger(const FakeConnectionEventLogger* logger) {
29 DCHECK(logger);
30 std::cout << *logger;
31}
32
33constexpr char kSessionJid[] = "user@domain/rest-of-jid";
34
35} // namespace
36
37using ::remoting::protocol::MockSession;
38
39It2MeStandaloneHost::It2MeStandaloneHost()
40 : context_(ChromotingHostContext::Create(
41 new AutoThreadTaskRunner(
42 message_loop_.task_runner(), run_loop_.QuitClosure()))),
43 main_task_runner_(context_->file_task_runner()),
44 factory_(main_task_runner_,
45 context_->video_capture_task_runner(),
46 context_->input_task_runner(),
47 context_->ui_task_runner()),
48 connection_(base::WrapUnique(new testing::NiceMock<MockSession>())),
49 session_jid_(kSessionJid),
50#if defined(OS_LINUX)
51 // We cannot support audio capturing for linux, since a pipe name is
52 // needed to initialize AudioCapturerLinux.
53 config_(protocol::SessionConfig::ForTest()),
54#else
55 config_(protocol::SessionConfig::ForTestWithAudio()),
56#endif
57 event_logger_(&connection_) {
58 factory_.set_enable_user_interface(false);
59 EXPECT_CALL(*static_cast<MockSession*>(connection_.session()), jid())
60 .WillRepeatedly(testing::ReturnRef(session_jid_));
61 EXPECT_CALL(*static_cast<MockSession*>(connection_.session()), config())
62 .WillRepeatedly(testing::ReturnRef(*config_));
63 connection_.set_audio_stub(event_logger_.audio_stub());
64 connection_.set_video_stub(event_logger_.video_stub());
65 connection_.set_client_stub(event_logger_.client_stub());
66 connection_.set_host_stub(event_logger_.host_stub());
67 connection_.set_video_encode_task_runner(
68 context_->video_encode_task_runner());
69}
70
71It2MeStandaloneHost::~It2MeStandaloneHost() {}
72
73void It2MeStandaloneHost::Run() {
74 main_task_runner_->PostTask(
75 FROM_HERE,
76 base::Bind(&It2MeStandaloneHost::Connect, base::Unretained(this)));
77 run_loop_.Run();
78}
79
80void It2MeStandaloneHost::StartOutputTimer() {
81 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(1),
82 base::Bind(&OutputFakeConnectionEventLogger, &event_logger_));
83}
84
85void It2MeStandaloneHost::Connect() {
86 session_.reset(new ClientSession(
87 &handler_,
88 context_->audio_task_runner(),
89 std::unique_ptr<protocol::ConnectionToClient>(&connection_),
90 &factory_,
91 base::TimeDelta(),
92 scoped_refptr<protocol::PairingRegistry>(),
93 std::vector<HostExtension*>()));
94 session_->OnConnectionAuthenticated(&connection_);
95 session_->OnConnectionChannelsConnected(&connection_);
96 session_->CreateVideoStreams(&connection_);
97}
98
99} // namespace test
100} // namespace remoting