• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CONTENT_RENDERER_MEDIA_MOCK_PEER_CONNECTION_IMPL_H_
6 #define CONTENT_RENDERER_MEDIA_MOCK_PEER_CONNECTION_IMPL_H_
7 
8 #include <string>
9 
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"
16 
17 namespace content {
18 
19 class MockPeerConnectionDependencyFactory;
20 class MockStreamCollection;
21 
22 class MockPeerConnectionImpl : public webrtc::PeerConnectionInterface {
23  public:
24   explicit MockPeerConnectionImpl(MockPeerConnectionDependencyFactory* factory);
25 
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;
41 
GetStats(webrtc::StatsObserver * observer,webrtc::MediaStreamTrackInterface * track)42   virtual bool GetStats(webrtc::StatsObserver* observer,
43                         webrtc::MediaStreamTrackInterface* track) {
44     return false;
45   }
46   virtual bool GetStats(webrtc::StatsObserver* observer,
47                         webrtc::MediaStreamTrackInterface* track,
48                         StatsOutputLevel level) OVERRIDE;
49 
50   // Set Call this function to make sure next call to GetStats fail.
SetGetStatsResult(bool result)51   void SetGetStatsResult(bool result) { getstats_result_ = result; }
52 
signaling_state()53   virtual SignalingState signaling_state() OVERRIDE {
54     NOTIMPLEMENTED();
55     return PeerConnectionInterface::kStable;
56   }
ice_state()57   virtual IceState ice_state() OVERRIDE {
58     NOTIMPLEMENTED();
59     return PeerConnectionInterface::kIceNew;
60   }
ice_connection_state()61   virtual IceConnectionState ice_connection_state() OVERRIDE {
62     NOTIMPLEMENTED();
63     return PeerConnectionInterface::kIceConnectionNew;
64   }
ice_gathering_state()65   virtual IceGatheringState ice_gathering_state() OVERRIDE {
66     NOTIMPLEMENTED();
67     return PeerConnectionInterface::kIceGatheringNew;
68   }
Close()69   virtual void Close() OVERRIDE {
70     NOTIMPLEMENTED();
71   }
72 
73   virtual const webrtc::SessionDescriptionInterface* local_description()
74       const OVERRIDE;
75   virtual const webrtc::SessionDescriptionInterface* remote_description()
76       const OVERRIDE;
77 
78   // JSEP01 APIs
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;
103 
104   void AddRemoteStream(webrtc::MediaStreamInterface* stream);
105 
stream_label()106   const std::string& stream_label() const { return stream_label_; }
hint_audio()107   bool hint_audio() const { return hint_audio_; }
hint_video()108   bool hint_video() const { return hint_video_; }
description_sdp()109   const std::string& description_sdp() const { return description_sdp_; }
sdp_mid()110   const std::string& sdp_mid() const { return sdp_mid_; }
sdp_mline_index()111   int sdp_mline_index() const { return sdp_mline_index_; }
ice_sdp()112   const std::string& ice_sdp() const { return ice_sdp_; }
created_session_description()113   webrtc::SessionDescriptionInterface* created_session_description() const {
114     return created_sessiondescription_.get();
115   }
116   static const char kDummyOffer[];
117   static const char kDummyAnswer[];
118 
119  protected:
120   virtual ~MockPeerConnectionImpl();
121 
122  private:
123   // Used for creating MockSessionDescription.
124   MockPeerConnectionDependencyFactory* dependency_factory_;
125 
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_;
132   bool hint_audio_;
133   bool hint_video_;
134   bool getstats_result_;
135   std::string description_sdp_;
136   std::string sdp_mid_;
137   int sdp_mline_index_;
138   std::string ice_sdp_;
139 
140   DISALLOW_COPY_AND_ASSIGN(MockPeerConnectionImpl);
141 };
142 
143 }  // namespace content
144 
145 #endif  // CONTENT_RENDERER_MEDIA_MOCK_PEER_CONNECTION_IMPL_H_
146