Add FakePeerConnectionBase

This provides an intermediate class for defining default, null
implementations of all the PeerConnectionInterface/
PeerConnectionInternal methods. Specific fake PeerConnections then can
inherit from this and only override the methods pertaining to the
scenarios it will be used in.

Bug: webrtc:8764
Change-Id: I7614303b5673747244053b54b839e58aada43d10
Reviewed-on: https://webrtc-review.googlesource.com/43245
Commit-Queue: Steve Anton <steveanton@webrtc.org>
Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21752}
diff --git a/pc/BUILD.gn b/pc/BUILD.gn
index 005a848..018ecfd 100644
--- a/pc/BUILD.gn
+++ b/pc/BUILD.gn
@@ -329,6 +329,7 @@
       "test/fakeaudiocapturemodule.cc",
       "test/fakeaudiocapturemodule.h",
       "test/fakedatachannelprovider.h",
+      "test/fakepeerconnectionbase.h",
       "test/fakeperiodicvideocapturer.h",
       "test/fakertccertificategenerator.h",
       "test/fakesctptransport.h",
diff --git a/pc/peerconnection.h b/pc/peerconnection.h
index c73f1ec..3ebe8fd 100644
--- a/pc/peerconnection.h
+++ b/pc/peerconnection.h
@@ -194,7 +194,7 @@
     return factory_->signaling_thread();
   }
 
-  const std::string& session_id() const override { return session_id_; }
+  std::string session_id() const override { return session_id_; }
 
   bool initial_offerer() const override {
     return initial_offerer_ && *initial_offerer_;
@@ -237,7 +237,7 @@
     return rtp_data_channel_;
   }
 
-  const std::vector<rtc::scoped_refptr<DataChannel>>& sctp_data_channels()
+  std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels()
       const override {
     return sctp_data_channels_;
   }
diff --git a/pc/peerconnectioninternal.h b/pc/peerconnectioninternal.h
index 4e179f5..7f06afe 100644
--- a/pc/peerconnectioninternal.h
+++ b/pc/peerconnectioninternal.h
@@ -51,7 +51,7 @@
   virtual rtc::Thread* signaling_thread() const = 0;
 
   // The SDP session ID as defined by RFC 3264.
-  virtual const std::string& session_id() const = 0;
+  virtual std::string session_id() const = 0;
 
   // Returns true if we were the initial offerer.
   virtual bool initial_offerer() const = 0;
@@ -74,8 +74,8 @@
   // Only valid when using deprecated RTP data channels.
   virtual cricket::RtpDataChannel* rtp_data_channel() const = 0;
 
-  virtual const std::vector<rtc::scoped_refptr<DataChannel>>&
-  sctp_data_channels() const = 0;
+  virtual std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels()
+      const = 0;
 
   virtual rtc::Optional<std::string> sctp_content_name() const = 0;
   virtual rtc::Optional<std::string> sctp_transport_name() const = 0;
diff --git a/pc/rtcstatscollector_unittest.cc b/pc/rtcstatscollector_unittest.cc
index 8ff35ef..e9adc3d 100644
--- a/pc/rtcstatscollector_unittest.cc
+++ b/pc/rtcstatscollector_unittest.cc
@@ -45,7 +45,6 @@
 using testing::Invoke;
 using testing::Return;
 using testing::ReturnNull;
-using testing::ReturnRef;
 using testing::SetArgPointee;
 
 namespace webrtc {
@@ -319,8 +318,8 @@
         std::vector<rtc::scoped_refptr<RtpSenderInterface>>()));
     EXPECT_CALL(pc_, GetReceivers()).WillRepeatedly(Return(
         std::vector<rtc::scoped_refptr<RtpReceiverInterface>>()));
-    EXPECT_CALL(pc_, sctp_data_channels()).WillRepeatedly(
-        ReturnRef(data_channels_));
+    EXPECT_CALL(pc_, sctp_data_channels())
+        .WillRepeatedly(Return(data_channels_));
     EXPECT_CALL(pc_, video_channel()).WillRepeatedly(ReturnNull());
     EXPECT_CALL(pc_, voice_channel()).WillRepeatedly(ReturnNull());
     EXPECT_CALL(pc_, GetSessionStats(_)).WillRepeatedly(ReturnNull());
@@ -335,8 +334,11 @@
   rtc::Thread* signaling_thread() { return signaling_thread_; }
   cricket::FakeMediaEngine* media_engine() { return media_engine_; }
   MockPeerConnection& pc() { return pc_; }
-  std::vector<rtc::scoped_refptr<DataChannel>>& data_channels() {
-    return data_channels_;
+
+  void AddDataChannel(rtc::scoped_refptr<DataChannel> data_channel) {
+    data_channels_.push_back(data_channel);
+    EXPECT_CALL(pc_, sctp_data_channels())
+        .WillRepeatedly(Return(data_channels_));
   }
 
   // SetSessionDescriptionObserver overrides.
@@ -1025,10 +1027,9 @@
 }
 
 TEST_F(RTCStatsCollectorTest, CollectRTCDataChannelStats) {
-  test_->data_channels().push_back(
-      new MockDataChannel(
-          0, "MockDataChannel0", DataChannelInterface::kConnecting, "udp",
-          1, 2, 3, 4));
+  test_->AddDataChannel(new MockDataChannel(0, "MockDataChannel0",
+                                            DataChannelInterface::kConnecting,
+                                            "udp", 1, 2, 3, 4));
   RTCDataChannelStats expected_data_channel0("RTCDataChannel_0", 0);
   expected_data_channel0.label = "MockDataChannel0";
   expected_data_channel0.protocol = "udp";
@@ -1039,10 +1040,8 @@
   expected_data_channel0.messages_received = 3;
   expected_data_channel0.bytes_received = 4;
 
-  test_->data_channels().push_back(
-      new MockDataChannel(
-          1, "MockDataChannel1", DataChannelInterface::kOpen, "tcp",
-          5, 6, 7, 8));
+  test_->AddDataChannel(new MockDataChannel(
+      1, "MockDataChannel1", DataChannelInterface::kOpen, "tcp", 5, 6, 7, 8));
   RTCDataChannelStats expected_data_channel1("RTCDataChannel_1", 0);
   expected_data_channel1.label = "MockDataChannel1";
   expected_data_channel1.protocol = "tcp";
@@ -1053,10 +1052,9 @@
   expected_data_channel1.messages_received = 7;
   expected_data_channel1.bytes_received = 8;
 
-  test_->data_channels().push_back(
-      new MockDataChannel(
-          2, "MockDataChannel2", DataChannelInterface::kClosing, "udp",
-          9, 10, 11, 12));
+  test_->AddDataChannel(new MockDataChannel(2, "MockDataChannel2",
+                                            DataChannelInterface::kClosing,
+                                            "udp", 9, 10, 11, 12));
   RTCDataChannelStats expected_data_channel2("RTCDataChannel_2", 0);
   expected_data_channel2.label = "MockDataChannel2";
   expected_data_channel2.protocol = "udp";
@@ -1067,10 +1065,9 @@
   expected_data_channel2.messages_received = 11;
   expected_data_channel2.bytes_received = 12;
 
-  test_->data_channels().push_back(
-      new MockDataChannel(
-          3, "MockDataChannel3", DataChannelInterface::kClosed, "tcp",
-          13, 14, 15, 16));
+  test_->AddDataChannel(new MockDataChannel(3, "MockDataChannel3",
+                                            DataChannelInterface::kClosed,
+                                            "tcp", 13, 14, 15, 16));
   RTCDataChannelStats expected_data_channel3("RTCDataChannel_3", 0);
   expected_data_channel3.label = "MockDataChannel3";
   expected_data_channel3.protocol = "tcp";
diff --git a/pc/statscollector_unittest.cc b/pc/statscollector_unittest.cc
index 4973fd3..eb2081d 100644
--- a/pc/statscollector_unittest.cc
+++ b/pc/statscollector_unittest.cc
@@ -41,7 +41,6 @@
 using testing::Invoke;
 using testing::Return;
 using testing::ReturnNull;
-using testing::ReturnRef;
 using testing::SetArgPointee;
 using webrtc::PeerConnectionInterface;
 using webrtc::StatsReport;
@@ -614,7 +613,7 @@
     EXPECT_CALL(pc_, video_channel()).WillRepeatedly(ReturnNull());
     EXPECT_CALL(pc_, voice_channel()).WillRepeatedly(ReturnNull());
     EXPECT_CALL(pc_, sctp_data_channels())
-        .WillRepeatedly(ReturnRef(data_channels_));
+        .WillRepeatedly(Return(data_channels_));
     EXPECT_CALL(pc_, GetSenders()).WillRepeatedly(Return(
         std::vector<rtc::scoped_refptr<RtpSenderInterface>>()));
     EXPECT_CALL(pc_, GetReceivers()).WillRepeatedly(Return(
@@ -648,6 +647,8 @@
 
     data_channels_.push_back(DataChannel::Create(
         &data_channel_provider_, cricket::DCT_SCTP, label, config));
+    EXPECT_CALL(pc_, sctp_data_channels())
+        .WillRepeatedly(Return(data_channels_));
   }
 
   StatsReport* AddCandidateReport(StatsCollector* collector,
diff --git a/pc/test/fakepeerconnectionbase.h b/pc/test/fakepeerconnectionbase.h
new file mode 100644
index 0000000..a42b6e3
--- /dev/null
+++ b/pc/test/fakepeerconnectionbase.h
@@ -0,0 +1,319 @@
+/*
+ *  Copyright 2018 The WebRTC project authors. All Rights Reserved.
+ *
+ *  Use of this source code is governed by a BSD-style license
+ *  that can be found in the LICENSE file in the root of the source
+ *  tree. An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef PC_TEST_FAKEPEERCONNECTIONBASE_H_
+#define PC_TEST_FAKEPEERCONNECTIONBASE_H_
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "pc/peerconnectioninternal.h"
+
+namespace webrtc {
+
+// Customized PeerConnection fakes can be created by subclassing
+// FakePeerConnectionBase then overriding the interesting methods. This class
+// takes care of providing default implementations for all the pure virtual
+// functions specified in the interfaces.
+class FakePeerConnectionBase : public PeerConnectionInternal {
+ public:
+  // PeerConnectionInterface implementation.
+
+  rtc::scoped_refptr<StreamCollectionInterface> local_streams() override {
+    return nullptr;
+  }
+
+  rtc::scoped_refptr<StreamCollectionInterface> remote_streams() override {
+    return nullptr;
+  }
+
+  bool AddStream(MediaStreamInterface* stream) override { return false; }
+
+  void RemoveStream(MediaStreamInterface* stream) override {}
+
+  RTCErrorOr<rtc::scoped_refptr<RtpSenderInterface>> AddTrack(
+      rtc::scoped_refptr<MediaStreamTrackInterface> track,
+      const std::vector<std::string>& stream_labels) override {
+    return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented");
+  }
+
+  rtc::scoped_refptr<RtpSenderInterface> AddTrack(
+      MediaStreamTrackInterface* track,
+      std::vector<MediaStreamInterface*> streams) override {
+    return nullptr;
+  }
+
+  bool RemoveTrack(RtpSenderInterface* sender) override { return false; }
+
+  RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver(
+      rtc::scoped_refptr<MediaStreamTrackInterface> track) override {
+    return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented");
+  }
+
+  RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver(
+      rtc::scoped_refptr<MediaStreamTrackInterface> track,
+      const RtpTransceiverInit& init) override {
+    return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented");
+  }
+
+  RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver(
+      cricket::MediaType media_type) override {
+    return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented");
+  }
+
+  RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver(
+      cricket::MediaType media_type,
+      const RtpTransceiverInit& init) override {
+    return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented");
+  }
+
+  rtc::scoped_refptr<DtmfSenderInterface> CreateDtmfSender(
+      AudioTrackInterface* track) override {
+    return nullptr;
+  }
+
+  rtc::scoped_refptr<RtpSenderInterface> CreateSender(
+      const std::string& kind,
+      const std::string& stream_id) override {
+    return nullptr;
+  }
+
+  std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders()
+      const override {
+    return {};
+  }
+
+  std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers()
+      const override {
+    return {};
+  }
+
+  std::vector<rtc::scoped_refptr<RtpTransceiverInterface>> GetTransceivers()
+      const override {
+    return {};
+  }
+
+  bool GetStats(StatsObserver* observer,
+                MediaStreamTrackInterface* track,
+                StatsOutputLevel level) override {
+    return false;
+  }
+
+  void GetStats(RTCStatsCollectorCallback* callback) override {}
+
+  void ClearStatsCache() override {}
+
+  rtc::scoped_refptr<DataChannelInterface> CreateDataChannel(
+      const std::string& label,
+      const DataChannelInit* config) override {
+    return nullptr;
+  }
+
+  const SessionDescriptionInterface* local_description() const override {
+    return nullptr;
+  }
+  const SessionDescriptionInterface* remote_description() const override {
+    return nullptr;
+  }
+
+  const SessionDescriptionInterface* current_local_description()
+      const override {
+    return nullptr;
+  }
+  const SessionDescriptionInterface* current_remote_description()
+      const override {
+    return nullptr;
+  }
+
+  const SessionDescriptionInterface* pending_local_description()
+      const override {
+    return nullptr;
+  }
+  const SessionDescriptionInterface* pending_remote_description()
+      const override {
+    return nullptr;
+  }
+
+  void CreateOffer(CreateSessionDescriptionObserver* observer,
+                   const MediaConstraintsInterface* constraints) override {}
+
+  void CreateOffer(CreateSessionDescriptionObserver* observer,
+                   const RTCOfferAnswerOptions& options) override {}
+
+  void CreateAnswer(CreateSessionDescriptionObserver* observer,
+                    const RTCOfferAnswerOptions& options) override {}
+
+  void CreateAnswer(CreateSessionDescriptionObserver* observer,
+                    const MediaConstraintsInterface* constraints) override {}
+
+  void SetLocalDescription(SetSessionDescriptionObserver* observer,
+                           SessionDescriptionInterface* desc) override {}
+
+  void SetRemoteDescription(SetSessionDescriptionObserver* observer,
+                            SessionDescriptionInterface* desc) override {}
+
+  void SetRemoteDescription(
+      std::unique_ptr<SessionDescriptionInterface> desc,
+      rtc::scoped_refptr<SetRemoteDescriptionObserverInterface> observer)
+      override {}
+
+  bool UpdateIce(const IceServers& configuration,
+                 const MediaConstraintsInterface* constraints) override {
+    return false;
+  }
+
+  bool UpdateIce(const IceServers& configuration) override { return false; }
+
+  RTCConfiguration GetConfiguration() override { return RTCConfiguration(); }
+
+  bool SetConfiguration(const PeerConnectionInterface::RTCConfiguration& config,
+                        RTCError* error) override {
+    return false;
+  }
+
+  bool SetConfiguration(
+      const PeerConnectionInterface::RTCConfiguration& config) override {
+    return false;
+  }
+
+  bool AddIceCandidate(const IceCandidateInterface* candidate) override {
+    return false;
+  }
+
+  bool RemoveIceCandidates(
+      const std::vector<cricket::Candidate>& candidates) override {
+    return false;
+  }
+
+  void RegisterUMAObserver(UMAObserver* observer) override {}
+
+  RTCError SetBitrate(const BitrateParameters& bitrate) override {
+    return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented");
+  }
+
+  void SetBitrateAllocationStrategy(
+      std::unique_ptr<rtc::BitrateAllocationStrategy>
+          bitrate_allocation_strategy) override {}
+
+  void SetAudioPlayout(bool playout) override {}
+
+  void SetAudioRecording(bool recording) override {}
+
+  SignalingState signaling_state() override { return SignalingState::kStable; }
+
+  IceConnectionState ice_connection_state() override {
+    return IceConnectionState::kIceConnectionNew;
+  }
+
+  IceGatheringState ice_gathering_state() override {
+    return IceGatheringState::kIceGatheringNew;
+  }
+
+  bool StartRtcEventLog(rtc::PlatformFile file,
+                        int64_t max_size_bytes) override {
+    return false;
+  }
+
+  bool StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output,
+                        int64_t output_period_ms) override {
+    return false;
+  }
+
+  void StopRtcEventLog() override {}
+
+  void Close() override {}
+
+  // PeerConnectionInternal implementation.
+
+  rtc::Thread* network_thread() const override { return nullptr; }
+  rtc::Thread* worker_thread() const override { return nullptr; }
+  rtc::Thread* signaling_thread() const override { return nullptr; }
+
+  std::string session_id() const override { return ""; }
+
+  bool initial_offerer() const override { return false; }
+
+  cricket::VoiceChannel* voice_channel() const override { return nullptr; }
+
+  cricket::VideoChannel* video_channel() const override { return nullptr; }
+
+  std::vector<
+      rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>>
+  GetTransceiversForTesting() const override {
+    return {};
+  }
+
+  bool GetLocalTrackIdBySsrc(uint32_t ssrc, std::string* track_id) override {
+    return false;
+  }
+  bool GetRemoteTrackIdBySsrc(uint32_t ssrc, std::string* track_id) override {
+    return false;
+  }
+
+  sigslot::signal1<DataChannel*>& SignalDataChannelCreated() override {
+    return SignalDataChannelCreated_;
+  }
+
+  cricket::RtpDataChannel* rtp_data_channel() const override { return nullptr; }
+
+  std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels()
+      const override {
+    return {};
+  }
+
+  rtc::Optional<std::string> sctp_content_name() const override {
+    return rtc::nullopt;
+  }
+
+  rtc::Optional<std::string> sctp_transport_name() const override {
+    return rtc::nullopt;
+  }
+
+  std::unique_ptr<SessionStats> GetSessionStats_s() override { return nullptr; }
+
+  std::unique_ptr<SessionStats> GetSessionStats(
+      const ChannelNamePairs& channel_name_pairs) override {
+    return nullptr;
+  }
+
+  Call::Stats GetCallStats() override { return Call::Stats(); }
+
+  bool GetLocalCertificate(
+      const std::string& transport_name,
+      rtc::scoped_refptr<rtc::RTCCertificate>* certificate) override {
+    return false;
+  }
+
+  std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate(
+      const std::string& transport_name) override {
+    return nullptr;
+  }
+
+  bool IceRestartPending(const std::string& content_name) const override {
+    return false;
+  }
+
+  bool NeedsIceRestart(const std::string& content_name) const override {
+    return false;
+  }
+
+  bool GetSslRole(const std::string& content_name,
+                  rtc::SSLRole* role) override {
+    return false;
+  }
+
+ protected:
+  sigslot::signal1<DataChannel*> SignalDataChannelCreated_;
+};
+
+}  // namespace webrtc
+
+#endif  // PC_TEST_FAKEPEERCONNECTIONBASE_H_
diff --git a/pc/test/mock_peerconnection.h b/pc/test/mock_peerconnection.h
index cf11593..c7a542f 100644
--- a/pc/test/mock_peerconnection.h
+++ b/pc/test/mock_peerconnection.h
@@ -60,7 +60,7 @@
   MOCK_CONST_METHOD0(GetReceivers,
                      std::vector<rtc::scoped_refptr<RtpReceiverInterface>>());
   MOCK_CONST_METHOD0(sctp_data_channels,
-                     const std::vector<rtc::scoped_refptr<DataChannel>>&());
+                     std::vector<rtc::scoped_refptr<DataChannel>>());
   MOCK_CONST_METHOD0(voice_channel, cricket::VoiceChannel*());
   MOCK_CONST_METHOD0(video_channel, cricket::VideoChannel*());
   // Libjingle uses "local" for a outgoing track, and "remote" for a incoming