fake_connection_to_host.cc 2.95 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "remoting/protocol/fake_connection_to_host.h"

#include "remoting/protocol/authenticator.h"
sergeyu's avatar
sergeyu committed
8
#include "remoting/protocol/transport_context.h"
9 10 11 12 13

namespace remoting {
namespace test {

FakeConnectionToHost::FakeConnectionToHost()
14 15
    : session_config_(protocol::SessionConfig::ForTest()) {}
FakeConnectionToHost::~FakeConnectionToHost() {}
16

17
void FakeConnectionToHost::set_client_stub(protocol::ClientStub* client_stub) {}
18 19

void FakeConnectionToHost::set_clipboard_stub(
20
    protocol::ClipboardStub* clipboard_stub) {}
21

22 23
void FakeConnectionToHost::set_video_renderer(
    protocol::VideoRenderer* video_renderer) {}
24

25 26 27
void FakeConnectionToHost::InitializeAudio(
    scoped_refptr<base::SingleThreadTaskRunner> audio_decode_task_runner,
    base::WeakPtr<protocol::AudioStub> audio_stub) {}
28

29
void FakeConnectionToHost::Connect(
30
    std::unique_ptr<protocol::Session> session,
31 32
    scoped_refptr<protocol::TransportContext> transport_context,
    HostEventCallback* event_callback) {
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
  DCHECK(event_callback);

  event_callback_ = event_callback;

  SetState(CONNECTING, protocol::OK);
}

void FakeConnectionToHost::SignalStateChange(protocol::Session::State state,
                                             protocol::ErrorCode error) {
  DCHECK(event_callback_);

  switch (state) {
    case protocol::Session::INITIALIZING:
    case protocol::Session::CONNECTING:
    case protocol::Session::ACCEPTING:
    case protocol::Session::AUTHENTICATING:
      // No updates for these events.
      break;

52
    case protocol::Session::ACCEPTED:
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
      SetState(CONNECTED, error);
      break;

    case protocol::Session::AUTHENTICATED:
      SetState(AUTHENTICATED, error);
      break;

    case protocol::Session::CLOSED:
      SetState(CLOSED, error);
      break;

    case protocol::Session::FAILED:
      DCHECK(error != protocol::ErrorCode::OK);
      SetState(FAILED, error);
      break;
  }
}

void FakeConnectionToHost::SignalConnectionReady(bool ready) {
  DCHECK(event_callback_);

  event_callback_->OnConnectionReady(ready);
}

const protocol::SessionConfig& FakeConnectionToHost::config() {
78
  return *session_config_;
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
}

protocol::ClipboardStub* FakeConnectionToHost::clipboard_forwarder() {
  return &mock_clipboard_stub_;
}

protocol::HostStub* FakeConnectionToHost::host_stub() {
  return &mock_host_stub_;
}

protocol::InputStub* FakeConnectionToHost::input_stub() {
  return &mock_input_stub_;
}

protocol::ConnectionToHost::State FakeConnectionToHost::state() const {
  return state_;
}

void FakeConnectionToHost::SetState(State state, protocol::ErrorCode error) {
  // |error| should be specified only when |state| is set to FAILED.
  DCHECK(state == FAILED || error == protocol::OK);

  if (state != state_) {
    state_ = state;
    event_callback_->OnConnectionState(state_, error);
  }
}

}  // namespace test
}  // namespace remoting