1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   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
   78
   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
  109
  110
  111
  112
  113
  114
  115
  116

mojo / core / test / mock_node_channel_delegate.h [blame]

// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MOJO_CORE_TEST_MOCK_NODE_CHANNEL_DELEGATE_H_
#define MOJO_CORE_TEST_MOCK_NODE_CHANNEL_DELEGATE_H_

#include "build/build_config.h"
#include "mojo/core/node_channel.h"
#include "testing/gmock/include/gmock/gmock.h"

namespace mojo {
namespace core {

// A NodeChannel Delegate implementation which can be used by NodeChannel unit
// tests and fuzzers.
class MockNodeChannelDelegate
    : public testing::NiceMock<NodeChannel::Delegate> {
 public:
  using NodeName = ports::NodeName;
  using PortName = ports::PortName;

  MockNodeChannelDelegate();
  MockNodeChannelDelegate(const MockNodeChannelDelegate&) = delete;
  MockNodeChannelDelegate& operator=(const MockNodeChannelDelegate&) = delete;
  ~MockNodeChannelDelegate() override;

  // testing::NiceMock<NodeChannel::Delegate> implementation:
  MOCK_METHOD(void,
              OnAcceptInvitee,
              (const NodeName& from_node,
               const NodeName& inviter_name,
               const NodeName& token),
              (override));
  MOCK_METHOD(void,
              OnAcceptInvitation,
              (const NodeName& from_node,
               const NodeName& token,
               const NodeName& invitee_name),
              (override));
  MOCK_METHOD(void,
              OnAddBrokerClient,
              (const NodeName& from_node,
               const NodeName& client_name,
               base::ProcessHandle process_handle),
              (override));
  MOCK_METHOD(void,
              OnBrokerClientAdded,
              (const NodeName& from_node,
               const NodeName& client_name,
               PlatformHandle broker_channel),
              (override));
  MOCK_METHOD(void,
              OnAcceptBrokerClient,
              (const NodeName& from_node,
               const NodeName& broker_name,
               PlatformHandle broker_channel,
               const uint64_t capabilities),
              (override));
  MOCK_METHOD(void,
              OnEventMessage,
              (const NodeName& from_node, Channel::MessagePtr message),
              (override));
  MOCK_METHOD(void,
              OnRequestPortMerge,
              (const NodeName& from_node,
               const PortName& connector_port_name,
               const std::string& token),
              (override));
  MOCK_METHOD(void,
              OnRequestIntroduction,
              (const NodeName& from_node, const NodeName& name),
              (override));
  MOCK_METHOD(void,
              OnIntroduce,
              (const NodeName& from_node,
               const NodeName& name,
               PlatformHandle channel_handle,
               const uint64_t remote_capabilites),
              (override));
  MOCK_METHOD(void,
              OnBroadcast,
              (const NodeName& from_node, Channel::MessagePtr message),
              (override));
#if BUILDFLAG(IS_WIN)
  MOCK_METHOD(void,
              OnRelayEventMessage,
              (const NodeName& from_node,
               base::ProcessHandle from_process,
               const NodeName& destination,
               Channel::MessagePtr message),
              (override));
  MOCK_METHOD(void,
              OnEventMessageFromRelay,
              (const NodeName& from_node,
               const NodeName& source_node,
               Channel::MessagePtr message),
              (override));
#endif
  MOCK_METHOD(void,
              OnAcceptPeer,
              (const NodeName& from_node,
               const NodeName& token,
               const NodeName& peer_name,
               const PortName& port_name),
              (override));
  MOCK_METHOD(void,
              OnChannelError,
              (const NodeName& node, NodeChannel* channel),
              (override));
};

}  // namespace core
}  // namespace mojo

#endif  // MOJO_CORE_TEST_MOCK_NODE_CHANNEL_DELEGATE_H_