Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: content/renderer/media/peer_connection_handler_jsep_unittest.cc

Issue 9699069: Adding JSEP PeerConnection glue. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed missing export. Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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 #include <string>
6
7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop.h"
9 #include "base/utf_string_conversions.h"
10 #include "content/renderer/media/mock_media_stream_dependency_factory.h"
11 #include "content/renderer/media/mock_media_stream_impl.h"
12 #include "content/renderer/media/mock_web_peer_connection_00_handler_client.h"
13 #include "content/renderer/media/mock_peer_connection_impl.h"
14 #include "content/renderer/media/peer_connection_handler_jsep.h"
15 #include "content/renderer/media/rtc_video_decoder.h"
16 #include "jingle/glue/thread_wrapper.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "third_party/libjingle/source/talk/app/webrtc/peerconnection.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebICECandid ateDescriptor.h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebICEOption s.h"
21 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaHint s.h"
22 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre amDescriptor.h"
23 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre amSource.h"
24 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSessionDe scriptionDescriptor.h"
25 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
26
27 namespace webrtc {
28
29 class MockVideoRendererWrapper : public VideoRendererWrapperInterface {
30 public:
31 virtual cricket::VideoRenderer* renderer() OVERRIDE { return NULL; }
32
33 protected:
34 virtual ~MockVideoRendererWrapper() {}
35 };
36
37 } // namespace webrtc
38
39 TEST(PeerConnectionHandlerJsepTest, Basic) {
40 MessageLoop loop;
41
42 scoped_ptr<WebKit::MockWebPeerConnection00HandlerClient> mock_client(
43 new WebKit::MockWebPeerConnection00HandlerClient());
44 scoped_refptr<MockMediaStreamImpl> mock_ms_impl(new MockMediaStreamImpl());
45 scoped_ptr<MockMediaStreamDependencyFactory> mock_dependency_factory(
46 new MockMediaStreamDependencyFactory());
47 mock_dependency_factory->CreatePeerConnectionFactory(NULL,
48 NULL,
49 NULL,
50 NULL,
51 NULL);
52 scoped_ptr<PeerConnectionHandlerJsep> pc_handler(
53 new PeerConnectionHandlerJsep(mock_client.get(),
54 mock_ms_impl.get(),
55 mock_dependency_factory.get()));
56
57 WebKit::WebString server_config(
58 WebKit::WebString::fromUTF8("STUN stun.l.google.com:19302"));
59 WebKit::WebString username;
60 pc_handler->initialize(server_config, username);
61 EXPECT_TRUE(pc_handler->native_peer_connection_.get());
62 webrtc::MockPeerConnectionImpl* mock_peer_connection =
63 static_cast<webrtc::MockPeerConnectionImpl*>(
64 pc_handler->native_peer_connection_.get());
65
66 // Create offer.
67 WebKit::WebMediaHints hints;
68 hints.initialize(true, true);
69 WebKit::WebSessionDescriptionDescriptor offer =
70 pc_handler->createOffer(hints);
71 EXPECT_FALSE(offer.isNull());
72 EXPECT_EQ(std::string(mock_peer_connection->kDummyOffer),
73 UTF16ToUTF8(offer.initialSDP()));
74 EXPECT_EQ(hints.audio(), mock_peer_connection->hint_audio());
75 EXPECT_EQ(hints.video(), mock_peer_connection->hint_video());
76
77 // Create answer.
78 WebKit::WebString offer_string = "offer";
79 hints.reset();
80 hints.initialize(false, false);
81 WebKit::WebSessionDescriptionDescriptor answer =
82 pc_handler->createAnswer(offer_string, hints);
83 EXPECT_FALSE(answer.isNull());
84 EXPECT_EQ(UTF16ToUTF8(offer_string), UTF16ToUTF8(answer.initialSDP()));
85 EXPECT_EQ(UTF16ToUTF8(offer_string), mock_peer_connection->description_sdp());
86 EXPECT_EQ(hints.audio(), mock_peer_connection->hint_audio());
87 EXPECT_EQ(hints.video(), mock_peer_connection->hint_video());
88
89 // Set local description.
90 PeerConnectionHandlerJsep::Action action =
91 PeerConnectionHandlerJsep::ActionSDPOffer;
92 WebKit::WebSessionDescriptionDescriptor description;
93 WebKit::WebString sdp = "test sdp";
94 description.initialize(sdp);
95 EXPECT_TRUE(pc_handler->setLocalDescription(action, description));
96 EXPECT_EQ(webrtc::PeerConnectionInterface::kOffer,
97 mock_peer_connection->action());
98 EXPECT_EQ(UTF16ToUTF8(sdp), mock_peer_connection->description_sdp());
99
100 // Get local description.
101 description.reset();
102 description = pc_handler->localDescription();
103 EXPECT_FALSE(description.isNull());
104 EXPECT_EQ(UTF16ToUTF8(sdp), UTF16ToUTF8(description.initialSDP()));
105
106 // Set remote description.
107 action = PeerConnectionHandlerJsep::ActionSDPAnswer;
108 sdp = "test sdp 2";
109 description.reset();
110 description.initialize(sdp);
111 EXPECT_TRUE(pc_handler->setRemoteDescription(action, description));
112 EXPECT_EQ(webrtc::PeerConnectionInterface::kAnswer,
113 mock_peer_connection->action());
114 EXPECT_EQ(UTF16ToUTF8(sdp), mock_peer_connection->description_sdp());
115
116 // Get remote description.
117 description.reset();
118 description = pc_handler->remoteDescription();
119 EXPECT_FALSE(description.isNull());
120 EXPECT_EQ(UTF16ToUTF8(sdp), UTF16ToUTF8(description.initialSDP()));
121
122 // Start ICE.
123 WebKit::WebICEOptions options;
124 options.initialize(WebKit::WebICEOptions::CandidateTypeAll);
125 EXPECT_TRUE(pc_handler->startIce(options));
126 EXPECT_EQ(webrtc::PeerConnectionInterface::kUseAll,
127 mock_peer_connection->ice_options());
128
129 // Process ICE message.
130 WebKit::WebICECandidateDescriptor candidate;
131 WebKit::WebString label = "test label";
132 sdp = "test sdp";
133 candidate.initialize(label, sdp);
134 EXPECT_TRUE(pc_handler->processIceMessage(candidate));
135 EXPECT_EQ(UTF16ToUTF8(label), mock_peer_connection->ice_label());
136 EXPECT_EQ(UTF16ToUTF8(sdp), mock_peer_connection->ice_sdp());
137
138 // Add stream.
139 // TODO(grunell): Add an audio track as well.
140 std::string stream_label("stream-label");
141 std::string video_track_label("video-label");
142 talk_base::scoped_refptr<webrtc::LocalVideoTrackInterface> local_video_track(
143 mock_dependency_factory->CreateLocalVideoTrack(video_track_label, NULL));
144 mock_ms_impl->AddTrack(video_track_label, local_video_track);
145 WebKit::WebVector<WebKit::WebMediaStreamSource> source_vector(
146 static_cast<size_t>(1));
147 source_vector[0].initialize(WebKit::WebString::fromUTF8(video_track_label),
148 WebKit::WebMediaStreamSource::TypeVideo,
149 WebKit::WebString::fromUTF8("RemoteVideo"));
150 WebKit::WebMediaStreamDescriptor local_stream;
151 local_stream.initialize(UTF8ToUTF16(stream_label), source_vector);
152 pc_handler->addStream(local_stream);
153 EXPECT_EQ(stream_label, mock_peer_connection->stream_label());
154 EXPECT_TRUE(mock_peer_connection->stream_changes_committed());
155
156 // On add stream.
157 std::string remote_stream_label(stream_label);
158 remote_stream_label += "-remote";
159 std::string remote_video_track_label(video_track_label);
160 remote_video_track_label += "-remote";
161 // We use a local stream as a remote since for testing purposes we really
162 // only need the MediaStreamInterface.
163 talk_base::scoped_refptr<webrtc::LocalMediaStreamInterface> remote_stream(
164 mock_dependency_factory->CreateLocalMediaStream(remote_stream_label));
165 talk_base::scoped_refptr<webrtc::LocalVideoTrackInterface> remote_video_track(
166 mock_dependency_factory->CreateLocalVideoTrack(remote_video_track_label,
167 NULL));
168 remote_video_track->set_enabled(true);
169 remote_stream->AddTrack(remote_video_track);
170 mock_peer_connection->AddRemoteStream(remote_stream);
171 pc_handler->OnAddStream(remote_stream);
172 EXPECT_EQ(remote_stream_label, mock_client->stream_label());
173
174 // Set renderer.
175 talk_base::scoped_refptr<webrtc::MockVideoRendererWrapper> renderer(
176 new talk_base::RefCountedObject<webrtc::MockVideoRendererWrapper>());
177 pc_handler->SetVideoRenderer(remote_stream_label, renderer);
178 EXPECT_EQ(renderer, static_cast<webrtc::MockLocalVideoTrack*>(
179 remote_video_track.get())->renderer());
180
181 // Remove stream.
182 WebKit::WebVector<WebKit::WebMediaStreamDescriptor> empty_streams(
183 static_cast<size_t>(0));
184 pc_handler->removeStream(local_stream);
185 EXPECT_EQ("", mock_peer_connection->stream_label());
186 mock_peer_connection->ClearStreamChangesCommitted();
187 EXPECT_TRUE(!mock_peer_connection->stream_changes_committed());
188
189 // On remove stream.
190 pc_handler->OnRemoveStream(remote_stream);
191 EXPECT_TRUE(mock_client->stream_label().empty());
192
193 // Add stream again.
194 pc_handler->addStream(local_stream);
195 EXPECT_EQ(stream_label, mock_peer_connection->stream_label());
196 EXPECT_TRUE(mock_peer_connection->stream_changes_committed());
197
198 // On state change.
199 mock_peer_connection->SetReadyState(webrtc::PeerConnectionInterface::kActive);
200 webrtc::PeerConnectionObserver::StateType state =
201 webrtc::PeerConnectionObserver::kReadyState;
202 pc_handler->OnStateChange(state);
203 EXPECT_EQ(WebKit::WebPeerConnection00HandlerClient::ReadyStateActive,
204 mock_client->ready_state());
205
206 // On ICE candidate.
207 std::string candidate_label = "test label";
208 std::string candidate_sdp = "test sdp";
209 webrtc::IceCandidateInterface* native_candidate =
210 mock_dependency_factory->CreateIceCandidate(candidate_label,
211 candidate_sdp);
212 pc_handler->OnIceCandidate(native_candidate);
213 EXPECT_EQ(candidate_label, mock_client->candidate_label());
214 EXPECT_EQ(candidate_sdp, mock_client->candidate_sdp());
215 EXPECT_TRUE(mock_client->more_to_follow());
216
217 // On ICE complete.
218 pc_handler->OnIceComplete();
219 EXPECT_TRUE(mock_client->candidate_label().empty());
220 EXPECT_TRUE(mock_client->candidate_sdp().empty());
221 EXPECT_FALSE(mock_client->more_to_follow());
222
223 // Stop.
224 pc_handler->stop();
225 EXPECT_FALSE(pc_handler->native_peer_connection_.get());
226
227 // PC handler is expected to be deleted when stop calls
228 // MediaStreamImpl::ClosePeerConnection. We own and delete it here instead of
229 // in the mock.
230 pc_handler.reset();
231 }
OLDNEW
« no previous file with comments | « content/renderer/media/peer_connection_handler_jsep.cc ('k') | content/renderer/render_view_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698