Moving mock classes around so that they may be reused in other unittests
New files, classes moved from statscollector_unittest.cc:
+webrtc/api/test/mock_peerconnection.h
for MockPeerConnectionFactory and MockPeerConnection
+webrtc/api/test/mock_webrtcsession.h
for MockWebRtcSession
+webrtc/media/base/test/mock_mediachannel.h
for MockVideoMediaChannel and MockVoiceMediaChannel
The webrtc/media/base/test folder is new.
BUG=chromium:627816
Review-Url: https://codereview.webrtc.org/2238933002
Cr-Commit-Position: refs/heads/master@{#13769}
diff --git a/webrtc/api/BUILD.gn b/webrtc/api/BUILD.gn
index 1a46191..a8e27d6 100644
--- a/webrtc/api/BUILD.gn
+++ b/webrtc/api/BUILD.gn
@@ -333,6 +333,8 @@
"test/fakeperiodicvideocapturer.h",
"test/fakertccertificategenerator.h",
"test/fakevideotrackrenderer.h",
+ "test/mock_peerconnection.h",
+ "test/mock_webrtcsession.h",
"test/mockpeerconnectionobservers.h",
"test/peerconnectiontestwrapper.cc",
"test/peerconnectiontestwrapper.h",
diff --git a/webrtc/api/api_tests.gyp b/webrtc/api/api_tests.gyp
index 5ff062a..73aebaa 100644
--- a/webrtc/api/api_tests.gyp
+++ b/webrtc/api/api_tests.gyp
@@ -49,6 +49,8 @@
'test/fakeperiodicvideocapturer.h',
'test/fakertccertificategenerator.h',
'test/fakevideotrackrenderer.h',
+ 'test/mock_peerconnection.h',
+ 'test/mock_webrtcsession.h',
'test/mockpeerconnectionobservers.h',
'test/peerconnectiontestwrapper.h',
'test/peerconnectiontestwrapper.cc',
diff --git a/webrtc/api/statscollector_unittest.cc b/webrtc/api/statscollector_unittest.cc
index e0657a1..f71a168 100644
--- a/webrtc/api/statscollector_unittest.cc
+++ b/webrtc/api/statscollector_unittest.cc
@@ -24,12 +24,15 @@
#include "webrtc/api/peerconnectionfactory.h"
#include "webrtc/api/test/fakedatachannelprovider.h"
#include "webrtc/api/test/fakevideotracksource.h"
+#include "webrtc/api/test/mock_peerconnection.h"
+#include "webrtc/api/test/mock_webrtcsession.h"
#include "webrtc/api/videotrack.h"
#include "webrtc/base/base64.h"
#include "webrtc/base/fakesslidentity.h"
#include "webrtc/base/gunit.h"
#include "webrtc/base/network.h"
#include "webrtc/media/base/fakemediaengine.h"
+#include "webrtc/media/base/test/mock_mediachannel.h"
#include "webrtc/p2p/base/faketransportcontroller.h"
#include "webrtc/pc/channelmanager.h"
@@ -65,73 +68,6 @@
const char kRemoteTrackId[] = "remote_track_id";
const uint32_t kSsrcOfTrack = 1234;
-class MockWebRtcSession : public webrtc::WebRtcSession {
- public:
- // TODO(nisse): Valid overrides commented out, because the gmock
- // methods don't use any override declarations, and we want to avoid
- // warnings from -Winconsistent-missing-override. See
- // http://crbug.com/428099.
- explicit MockWebRtcSession(webrtc::MediaControllerInterface* media_controller)
- : WebRtcSession(
- media_controller,
- rtc::Thread::Current(),
- rtc::Thread::Current(),
- rtc::Thread::Current(),
- nullptr,
- std::unique_ptr<cricket::TransportController>(
- new cricket::TransportController(rtc::Thread::Current(),
- rtc::Thread::Current(),
- nullptr))) {}
- MOCK_METHOD0(voice_channel, cricket::VoiceChannel*());
- MOCK_METHOD0(video_channel, cricket::VideoChannel*());
- // Libjingle uses "local" for a outgoing track, and "remote" for a incoming
- // track.
- MOCK_METHOD2(GetLocalTrackIdBySsrc, bool(uint32_t, std::string*));
- MOCK_METHOD2(GetRemoteTrackIdBySsrc, bool(uint32_t, std::string*));
- MOCK_METHOD1(GetTransportStats, bool(SessionStats*));
- MOCK_METHOD2(GetLocalCertificate,
- bool(const std::string& transport_name,
- rtc::scoped_refptr<rtc::RTCCertificate>* certificate));
-
- // Workaround for gmock's inability to cope with move-only return values.
- std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate(
- const std::string& transport_name) /* override */ {
- return std::unique_ptr<rtc::SSLCertificate>(
- GetRemoteSSLCertificate_ReturnsRawPointer(transport_name));
- }
- MOCK_METHOD1(GetRemoteSSLCertificate_ReturnsRawPointer,
- rtc::SSLCertificate*(const std::string& transport_name));
-};
-
-// The factory isn't really used; it just satisfies the base PeerConnection.
-class FakePeerConnectionFactory
- : public rtc::RefCountedObject<PeerConnectionFactory> {};
-
-class MockPeerConnection
- : public rtc::RefCountedObject<webrtc::PeerConnection> {
- public:
- MockPeerConnection()
- : rtc::RefCountedObject<webrtc::PeerConnection>(
- new FakePeerConnectionFactory()) {}
- MOCK_METHOD0(session, WebRtcSession*());
- MOCK_CONST_METHOD0(sctp_data_channels,
- const std::vector<rtc::scoped_refptr<DataChannel>>&());
-};
-
-class MockVideoMediaChannel : public cricket::FakeVideoMediaChannel {
- public:
- MockVideoMediaChannel() :
- cricket::FakeVideoMediaChannel(NULL, cricket::VideoOptions()) {}
- MOCK_METHOD1(GetStats, bool(cricket::VideoMediaInfo*));
-};
-
-class MockVoiceMediaChannel : public cricket::FakeVoiceMediaChannel {
- public:
- MockVoiceMediaChannel() :
- cricket::FakeVoiceMediaChannel(NULL, cricket::AudioOptions()) {}
- MOCK_METHOD1(GetStats, bool(cricket::VoiceMediaInfo*));
-};
-
class FakeAudioProcessor : public webrtc::AudioProcessorInterface {
public:
FakeAudioProcessor() {}
diff --git a/webrtc/api/test/mock_peerconnection.h b/webrtc/api/test/mock_peerconnection.h
new file mode 100644
index 0000000..21b24a9
--- /dev/null
+++ b/webrtc/api/test/mock_peerconnection.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2016 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 WEBRTC_API_TEST_MOCK_PEERCONNECTION_H_
+#define WEBRTC_API_TEST_MOCK_PEERCONNECTION_H_
+
+#include <vector>
+
+#include "webrtc/api/peerconnection.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+namespace webrtc {
+
+// The factory isn't really used; it just satisfies the base PeerConnection.
+class FakePeerConnectionFactory
+ : public rtc::RefCountedObject<webrtc::PeerConnectionFactory> {};
+
+class MockPeerConnection
+ : public rtc::RefCountedObject<webrtc::PeerConnection> {
+ public:
+ MockPeerConnection()
+ : rtc::RefCountedObject<webrtc::PeerConnection>(
+ new FakePeerConnectionFactory()) {}
+ MOCK_METHOD0(session, WebRtcSession*());
+ MOCK_CONST_METHOD0(sctp_data_channels,
+ const std::vector<rtc::scoped_refptr<DataChannel>>&());
+};
+
+} // namespace webrtc
+
+#endif // WEBRTC_API_TEST_MOCK_PEERCONNECTION_H_
diff --git a/webrtc/api/test/mock_webrtcsession.h b/webrtc/api/test/mock_webrtcsession.h
new file mode 100644
index 0000000..459e349
--- /dev/null
+++ b/webrtc/api/test/mock_webrtcsession.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2016 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 WEBRTC_API_TEST_MOCK_WEBRTCSESSION_H_
+#define WEBRTC_API_TEST_MOCK_WEBRTCSESSION_H_
+
+#include <memory>
+#include <string>
+
+#include "webrtc/api/webrtcsession.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+namespace webrtc {
+
+class MockWebRtcSession : public webrtc::WebRtcSession {
+ public:
+ // TODO(nisse): Valid overrides commented out, because the gmock
+ // methods don't use any override declarations, and we want to avoid
+ // warnings from -Winconsistent-missing-override. See
+ // http://crbug.com/428099.
+ explicit MockWebRtcSession(MediaControllerInterface* media_controller)
+ : WebRtcSession(
+ media_controller,
+ rtc::Thread::Current(),
+ rtc::Thread::Current(),
+ rtc::Thread::Current(),
+ nullptr,
+ std::unique_ptr<cricket::TransportController>(
+ new cricket::TransportController(rtc::Thread::Current(),
+ rtc::Thread::Current(),
+ nullptr))) {}
+ MOCK_METHOD0(voice_channel, cricket::VoiceChannel*());
+ MOCK_METHOD0(video_channel, cricket::VideoChannel*());
+ // Libjingle uses "local" for a outgoing track, and "remote" for a incoming
+ // track.
+ MOCK_METHOD2(GetLocalTrackIdBySsrc, bool(uint32_t, std::string*));
+ MOCK_METHOD2(GetRemoteTrackIdBySsrc, bool(uint32_t, std::string*));
+ MOCK_METHOD1(GetTransportStats, bool(SessionStats*));
+ MOCK_METHOD2(GetLocalCertificate,
+ bool(const std::string& transport_name,
+ rtc::scoped_refptr<rtc::RTCCertificate>* certificate));
+
+ // Workaround for gmock's inability to cope with move-only return values.
+ std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate(
+ const std::string& transport_name) /* override */ {
+ return std::unique_ptr<rtc::SSLCertificate>(
+ GetRemoteSSLCertificate_ReturnsRawPointer(transport_name));
+ }
+ MOCK_METHOD1(GetRemoteSSLCertificate_ReturnsRawPointer,
+ rtc::SSLCertificate*(const std::string& transport_name));
+};
+
+} // namespace webrtc
+
+#endif // WEBRTC_API_TEST_MOCK_WEBRTCSESSION_H_
diff --git a/webrtc/media/BUILD.gn b/webrtc/media/BUILD.gn
index 9689cd2..a00fe6f 100644
--- a/webrtc/media/BUILD.gn
+++ b/webrtc/media/BUILD.gn
@@ -229,6 +229,7 @@
"base/fakertp.h",
"base/fakevideocapturer.h",
"base/fakevideorenderer.h",
+ "base/test/mock_mediachannel.h",
"base/testutils.cc",
"base/testutils.h",
"engine/fakewebrtccall.cc",
diff --git a/webrtc/media/base/test/mock_mediachannel.h b/webrtc/media/base/test/mock_mediachannel.h
new file mode 100644
index 0000000..6330fe0
--- /dev/null
+++ b/webrtc/media/base/test/mock_mediachannel.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2016 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 WEBRTC_MEDIA_BASE_TEST_MOCK_MEDIACHANNEL_H_
+#define WEBRTC_MEDIA_BASE_TEST_MOCK_MEDIACHANNEL_H_
+
+#include "webrtc/media/base/fakemediaengine.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+namespace webrtc {
+
+class MockVideoMediaChannel : public cricket::FakeVideoMediaChannel {
+ public:
+ MockVideoMediaChannel() :
+ cricket::FakeVideoMediaChannel(NULL, cricket::VideoOptions()) {}
+ MOCK_METHOD1(GetStats, bool(cricket::VideoMediaInfo*));
+};
+
+class MockVoiceMediaChannel : public cricket::FakeVoiceMediaChannel {
+ public:
+ MockVoiceMediaChannel() :
+ cricket::FakeVoiceMediaChannel(NULL, cricket::AudioOptions()) {}
+ MOCK_METHOD1(GetStats, bool(cricket::VoiceMediaInfo*));
+};
+
+} // namespace webrtc
+
+#endif // WEBRTC_MEDIA_BASE_TEST_MOCK_MEDIACHANNEL_H_
diff --git a/webrtc/media/media.gyp b/webrtc/media/media.gyp
index 039fdc6..691f886 100644
--- a/webrtc/media/media.gyp
+++ b/webrtc/media/media.gyp
@@ -234,6 +234,7 @@
'base/fakertp.h',
'base/fakevideocapturer.h',
'base/fakevideorenderer.h',
+ 'base/test/mock_mediachannel.h',
'base/testutils.cc',
'base/testutils.h',
'engine/fakewebrtccall.cc',