1 // Copyright 2015 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.
5 #include "remoting/protocol/fake_connection_to_host.h"
7 #include "remoting/protocol/authenticator.h"
12 FakeConnectionToHost::FakeConnectionToHost()
13 : state_(INITIALIZING
),
14 session_config_(protocol::SessionConfig::ForTest()) {
17 FakeConnectionToHost::~FakeConnectionToHost() {
20 void FakeConnectionToHost::set_candidate_config(
21 scoped_ptr
<protocol::CandidateSessionConfig
> config
) {
24 void FakeConnectionToHost::set_client_stub(protocol::ClientStub
* client_stub
) {
27 void FakeConnectionToHost::set_clipboard_stub(
28 protocol::ClipboardStub
* clipboard_stub
) {
31 void FakeConnectionToHost::set_video_stub(protocol::VideoStub
* video_stub
) {
34 void FakeConnectionToHost::set_audio_stub(protocol::AudioStub
* audio_stub
) {
37 void FakeConnectionToHost::Connect(
38 SignalStrategy
* signal_strategy
,
39 scoped_ptr
<protocol::TransportFactory
> transport_factory
,
40 scoped_ptr
<protocol::Authenticator
> authenticator
,
41 const std::string
& host_jid
,
42 HostEventCallback
* event_callback
) {
43 DCHECK(event_callback
);
45 event_callback_
= event_callback
;
47 SetState(CONNECTING
, protocol::OK
);
50 void FakeConnectionToHost::SignalStateChange(protocol::Session::State state
,
51 protocol::ErrorCode error
) {
52 DCHECK(event_callback_
);
55 case protocol::Session::INITIALIZING
:
56 case protocol::Session::CONNECTING
:
57 case protocol::Session::ACCEPTING
:
58 case protocol::Session::AUTHENTICATING
:
59 // No updates for these events.
62 case protocol::Session::CONNECTED
:
63 SetState(CONNECTED
, error
);
66 case protocol::Session::AUTHENTICATED
:
67 SetState(AUTHENTICATED
, error
);
70 case protocol::Session::CLOSED
:
71 SetState(CLOSED
, error
);
74 case protocol::Session::FAILED
:
75 DCHECK(error
!= protocol::ErrorCode::OK
);
76 SetState(FAILED
, error
);
81 void FakeConnectionToHost::SignalConnectionReady(bool ready
) {
82 DCHECK(event_callback_
);
84 event_callback_
->OnConnectionReady(ready
);
87 const protocol::SessionConfig
& FakeConnectionToHost::config() {
88 return session_config_
;
91 protocol::ClipboardStub
* FakeConnectionToHost::clipboard_forwarder() {
92 return &mock_clipboard_stub_
;
95 protocol::HostStub
* FakeConnectionToHost::host_stub() {
96 return &mock_host_stub_
;
99 protocol::InputStub
* FakeConnectionToHost::input_stub() {
100 return &mock_input_stub_
;
103 protocol::ConnectionToHost::State
FakeConnectionToHost::state() const {
107 void FakeConnectionToHost::SetState(State state
, protocol::ErrorCode error
) {
108 // |error| should be specified only when |state| is set to FAILED.
109 DCHECK(state
== FAILED
|| error
== protocol::OK
);
111 if (state
!= state_
) {
113 event_callback_
->OnConnectionState(state_
, error
);
118 } // namespace remoting