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/memory/scoped_ptr.h"
13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "third_party/libjingle/source/talk/app/webrtc/peerconnectioninterface.h"
18 class MockMediaStreamDependencyFactory
;
19 class MockStreamCollection
;
21 class MockPeerConnectionImpl
: public webrtc::PeerConnectionInterface
{
23 explicit MockPeerConnectionImpl(MockMediaStreamDependencyFactory
* factory
);
25 // PeerConnectionInterface implementation.
26 virtual talk_base::scoped_refptr
<webrtc::StreamCollectionInterface
>
27 local_streams() OVERRIDE
;
28 virtual talk_base::scoped_refptr
<webrtc::StreamCollectionInterface
>
29 remote_streams() OVERRIDE
;
30 virtual bool AddStream(
31 webrtc::MediaStreamInterface
* local_stream
,
32 const webrtc::MediaConstraintsInterface
* constraints
) OVERRIDE
;
33 virtual void RemoveStream(
34 webrtc::MediaStreamInterface
* local_stream
) OVERRIDE
;
35 virtual talk_base::scoped_refptr
<webrtc::DtmfSenderInterface
>
36 CreateDtmfSender(webrtc::AudioTrackInterface
* track
) OVERRIDE
;
37 virtual talk_base::scoped_refptr
<webrtc::DataChannelInterface
>
38 CreateDataChannel(const std::string
& label
,
39 const webrtc::DataChannelInit
* config
) OVERRIDE
;
41 virtual bool GetStats(webrtc::StatsObserver
* observer
,
42 webrtc::MediaStreamTrackInterface
* track
) {
45 virtual bool GetStats(webrtc::StatsObserver
* observer
,
46 webrtc::MediaStreamTrackInterface
* track
,
47 StatsOutputLevel level
) OVERRIDE
;
49 // Set Call this function to make sure next call to GetStats fail.
50 void SetGetStatsResult(bool result
) { getstats_result_
= result
; }
52 virtual SignalingState
signaling_state() OVERRIDE
{
54 return PeerConnectionInterface::kStable
;
56 virtual IceState
ice_state() OVERRIDE
{
58 return PeerConnectionInterface::kIceNew
;
60 virtual IceConnectionState
ice_connection_state() OVERRIDE
{
62 return PeerConnectionInterface::kIceConnectionNew
;
64 virtual IceGatheringState
ice_gathering_state() OVERRIDE
{
66 return PeerConnectionInterface::kIceGatheringNew
;
68 virtual void Close() OVERRIDE
{
72 virtual const webrtc::SessionDescriptionInterface
* local_description()
74 virtual const webrtc::SessionDescriptionInterface
* remote_description()
78 virtual void CreateOffer(
79 webrtc::CreateSessionDescriptionObserver
* observer
,
80 const webrtc::MediaConstraintsInterface
* constraints
) OVERRIDE
;
81 virtual void CreateAnswer(
82 webrtc::CreateSessionDescriptionObserver
* observer
,
83 const webrtc::MediaConstraintsInterface
* constraints
) OVERRIDE
;
84 MOCK_METHOD2(SetLocalDescription
,
85 void(webrtc::SetSessionDescriptionObserver
* observer
,
86 webrtc::SessionDescriptionInterface
* desc
));
87 void SetLocalDescriptionWorker(
88 webrtc::SetSessionDescriptionObserver
* observer
,
89 webrtc::SessionDescriptionInterface
* desc
) ;
90 MOCK_METHOD2(SetRemoteDescription
,
91 void(webrtc::SetSessionDescriptionObserver
* observer
,
92 webrtc::SessionDescriptionInterface
* desc
));
93 void SetRemoteDescriptionWorker(
94 webrtc::SetSessionDescriptionObserver
* observer
,
95 webrtc::SessionDescriptionInterface
* desc
);
96 virtual bool UpdateIce(
97 const IceServers
& configuration
,
98 const webrtc::MediaConstraintsInterface
* constraints
) OVERRIDE
;
99 virtual bool AddIceCandidate(
100 const webrtc::IceCandidateInterface
* candidate
) OVERRIDE
;
102 void AddRemoteStream(webrtc::MediaStreamInterface
* stream
);
104 const std::string
& stream_label() const { return stream_label_
; }
105 bool hint_audio() const { return hint_audio_
; }
106 bool hint_video() const { return hint_video_
; }
107 const std::string
& description_sdp() const { return description_sdp_
; }
108 const std::string
& sdp_mid() const { return sdp_mid_
; }
109 int sdp_mline_index() const { return sdp_mline_index_
; }
110 const std::string
& ice_sdp() const { return ice_sdp_
; }
111 webrtc::SessionDescriptionInterface
* created_session_description() const {
112 return created_sessiondescription_
.get();
114 static const char kDummyOffer
[];
115 static const char kDummyAnswer
[];
118 virtual ~MockPeerConnectionImpl();
121 // Used for creating MockSessionDescription.
122 MockMediaStreamDependencyFactory
* dependency_factory_
;
124 std::string stream_label_
;
125 talk_base::scoped_refptr
<MockStreamCollection
> local_streams_
;
126 talk_base::scoped_refptr
<MockStreamCollection
> remote_streams_
;
127 scoped_ptr
<webrtc::SessionDescriptionInterface
> local_desc_
;
128 scoped_ptr
<webrtc::SessionDescriptionInterface
> remote_desc_
;
129 scoped_ptr
<webrtc::SessionDescriptionInterface
> created_sessiondescription_
;
132 bool getstats_result_
;
133 std::string description_sdp_
;
134 std::string sdp_mid_
;
135 int sdp_mline_index_
;
136 std::string ice_sdp_
;
138 DISALLOW_COPY_AND_ASSIGN(MockPeerConnectionImpl
);
141 } // namespace content
143 #endif // CONTENT_RENDERER_MEDIA_MOCK_PEER_CONNECTION_IMPL_H_