1 // Copyright (c) 2012 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 #ifndef CONTENT_RENDERER_MEDIA_MOCK_PEER_CONNECTION_IMPL_H_
6 #define CONTENT_RENDERER_MEDIA_MOCK_PEER_CONNECTION_IMPL_H_
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/logging.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "third_party/libjingle/source/talk/app/webrtc/peerconnectioninterface.h"
19 class MockPeerConnectionDependencyFactory
;
20 class MockStreamCollection
;
22 class MockPeerConnectionImpl
: public webrtc::PeerConnectionInterface
{
24 explicit MockPeerConnectionImpl(MockPeerConnectionDependencyFactory
* factory
);
26 // PeerConnectionInterface implementation.
27 virtual rtc::scoped_refptr
<webrtc::StreamCollectionInterface
>
28 local_streams() override
;
29 virtual rtc::scoped_refptr
<webrtc::StreamCollectionInterface
>
30 remote_streams() override
;
31 virtual bool AddStream(
32 webrtc::MediaStreamInterface
* local_stream
,
33 const webrtc::MediaConstraintsInterface
* constraints
) override
;
34 virtual void RemoveStream(
35 webrtc::MediaStreamInterface
* local_stream
) override
;
36 virtual rtc::scoped_refptr
<webrtc::DtmfSenderInterface
>
37 CreateDtmfSender(webrtc::AudioTrackInterface
* track
) override
;
38 virtual rtc::scoped_refptr
<webrtc::DataChannelInterface
>
39 CreateDataChannel(const std::string
& label
,
40 const webrtc::DataChannelInit
* config
) override
;
42 virtual bool GetStats(webrtc::StatsObserver
* observer
,
43 webrtc::MediaStreamTrackInterface
* track
) {
46 virtual bool GetStats(webrtc::StatsObserver
* observer
,
47 webrtc::MediaStreamTrackInterface
* track
,
48 StatsOutputLevel level
) override
;
50 // Set Call this function to make sure next call to GetStats fail.
51 void SetGetStatsResult(bool result
) { getstats_result_
= result
; }
53 virtual SignalingState
signaling_state() override
{
55 return PeerConnectionInterface::kStable
;
57 virtual IceState
ice_state() override
{
59 return PeerConnectionInterface::kIceNew
;
61 virtual IceConnectionState
ice_connection_state() override
{
63 return PeerConnectionInterface::kIceConnectionNew
;
65 virtual IceGatheringState
ice_gathering_state() override
{
67 return PeerConnectionInterface::kIceGatheringNew
;
69 virtual void Close() override
{
73 virtual const webrtc::SessionDescriptionInterface
* local_description()
75 virtual const webrtc::SessionDescriptionInterface
* remote_description()
79 virtual void CreateOffer(
80 webrtc::CreateSessionDescriptionObserver
* observer
,
81 const webrtc::MediaConstraintsInterface
* constraints
) override
;
82 virtual void CreateAnswer(
83 webrtc::CreateSessionDescriptionObserver
* observer
,
84 const webrtc::MediaConstraintsInterface
* constraints
) override
;
85 MOCK_METHOD2(SetLocalDescription
,
86 void(webrtc::SetSessionDescriptionObserver
* observer
,
87 webrtc::SessionDescriptionInterface
* desc
));
88 void SetLocalDescriptionWorker(
89 webrtc::SetSessionDescriptionObserver
* observer
,
90 webrtc::SessionDescriptionInterface
* desc
) ;
91 MOCK_METHOD2(SetRemoteDescription
,
92 void(webrtc::SetSessionDescriptionObserver
* observer
,
93 webrtc::SessionDescriptionInterface
* desc
));
94 void SetRemoteDescriptionWorker(
95 webrtc::SetSessionDescriptionObserver
* observer
,
96 webrtc::SessionDescriptionInterface
* desc
);
97 virtual bool UpdateIce(
98 const IceServers
& configuration
,
99 const webrtc::MediaConstraintsInterface
* constraints
) override
;
100 virtual bool AddIceCandidate(
101 const webrtc::IceCandidateInterface
* candidate
) override
;
102 virtual void RegisterUMAObserver(webrtc::UMAObserver
* observer
) override
;
104 void AddRemoteStream(webrtc::MediaStreamInterface
* stream
);
106 const std::string
& stream_label() const { return stream_label_
; }
107 bool hint_audio() const { return hint_audio_
; }
108 bool hint_video() const { return hint_video_
; }
109 const std::string
& description_sdp() const { return description_sdp_
; }
110 const std::string
& sdp_mid() const { return sdp_mid_
; }
111 int sdp_mline_index() const { return sdp_mline_index_
; }
112 const std::string
& ice_sdp() const { return ice_sdp_
; }
113 webrtc::SessionDescriptionInterface
* created_session_description() const {
114 return created_sessiondescription_
.get();
116 static const char kDummyOffer
[];
117 static const char kDummyAnswer
[];
120 virtual ~MockPeerConnectionImpl();
123 // Used for creating MockSessionDescription.
124 MockPeerConnectionDependencyFactory
* dependency_factory_
;
126 std::string stream_label_
;
127 rtc::scoped_refptr
<MockStreamCollection
> local_streams_
;
128 rtc::scoped_refptr
<MockStreamCollection
> remote_streams_
;
129 scoped_ptr
<webrtc::SessionDescriptionInterface
> local_desc_
;
130 scoped_ptr
<webrtc::SessionDescriptionInterface
> remote_desc_
;
131 scoped_ptr
<webrtc::SessionDescriptionInterface
> created_sessiondescription_
;
134 bool getstats_result_
;
135 std::string description_sdp_
;
136 std::string sdp_mid_
;
137 int sdp_mline_index_
;
138 std::string ice_sdp_
;
140 DISALLOW_COPY_AND_ASSIGN(MockPeerConnectionImpl
);
143 } // namespace content
145 #endif // CONTENT_RENDERER_MEDIA_MOCK_PEER_CONNECTION_IMPL_H_