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

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

Issue 8060055: Adding support for MediaStream and PeerConnection functionality (Closed) Base URL: http://git.chromium.org/chromium/chromium.git@trunk
Patch Set: Code review fixes. Created 9 years 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
OLDNEW
(Empty)
1 // Copyright (c) 2011 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_handler_client.h"
13 #include "content/renderer/media/mock_peer_connection_impl.h"
14 #include "content/renderer/media/peer_connection_handler.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/WebMediaStre amDescriptor.h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre amSource.h"
21
22 TEST(PeerConnectionHandlerTest, Basic) {
23 MessageLoop loop;
24
25 scoped_ptr<WebKit::MockWebPeerConnectionHandlerClient> mock_client(
26 new WebKit::MockWebPeerConnectionHandlerClient());
27 scoped_refptr<MockMediaStreamImpl> mock_ms_impl(new MockMediaStreamImpl());
28 scoped_ptr<MockMediaStreamDependencyFactory> mock_dependency_factory(
29 new MockMediaStreamDependencyFactory());
30 mock_dependency_factory->CreatePeerConnectionFactory(NULL, NULL);
31 scoped_ptr<PeerConnectionHandler> pc_handler(
32 new PeerConnectionHandler(mock_client.get(),
33 mock_ms_impl.get(),
34 mock_dependency_factory.get(),
35 NULL,
36 NULL,
37 NULL,
38 NULL));
39
40 WebKit::WebString server_config(
41 WebKit::WebString::fromUTF8("STUN stun.l.google.com:19302"));
42 WebKit::WebSecurityOrigin security_origin;
43 pc_handler->initialize(server_config, security_origin);
44 EXPECT_TRUE(pc_handler->native_peer_connection_.get());
45 webrtc::MockPeerConnectionImpl* mock_peer_connection =
46 static_cast<webrtc::MockPeerConnectionImpl*>(
47 pc_handler->native_peer_connection_.get());
48 EXPECT_EQ(static_cast<webrtc::PeerConnectionObserver*>(pc_handler.get()),
49 mock_peer_connection->observer());
50
51 std::string label("label");
52 WebKit::WebVector<WebKit::WebMediaStreamSource> source_vector(
53 static_cast<size_t>(1));
54 source_vector[0].initialize(WebKit::WebString::fromUTF8(label),
55 WebKit::WebMediaStreamSource::TypeVideo,
56 WebKit::WebString::fromUTF8("RemoteVideo"));
57 WebKit::WebVector<WebKit::WebMediaStreamDescriptor> pendingAddStreams(
58 static_cast<size_t>(1));
59 pendingAddStreams[0].initialize(UTF8ToUTF16(label), source_vector);
60 pc_handler->produceInitialOffer(pendingAddStreams);
61 EXPECT_EQ(label, mock_ms_impl->video_label());
62 EXPECT_EQ(label, mock_peer_connection->stream_id());
63 EXPECT_TRUE(mock_peer_connection->video_stream());
64 EXPECT_TRUE(mock_peer_connection->connected());
65 EXPECT_TRUE(mock_peer_connection->video_capture_set());
66
67 std::string message("message1");
68 pc_handler->handleInitialOffer(WebKit::WebString::fromUTF8(message));
69 EXPECT_EQ(message, mock_peer_connection->signaling_message());
70
71 message = "message2";
72 pc_handler->processSDP(WebKit::WebString::fromUTF8(message));
73 EXPECT_EQ(message, mock_peer_connection->signaling_message());
74
75 message = "message3";
76 pc_handler->OnSignalingMessage(message);
77 EXPECT_EQ(message, mock_client->sdp());
78
79 std::string remote_label(label);
80 remote_label.append("-remote");
81 pc_handler->OnAddStream(remote_label, true);
82 EXPECT_EQ(remote_label, mock_client->stream_label());
83
84 scoped_refptr<RTCVideoDecoder> rtc_video_decoder(
85 new RTCVideoDecoder(&loop, ""));
86 pc_handler->SetVideoRenderer(label, rtc_video_decoder.get());
87 EXPECT_EQ(label, mock_peer_connection->video_renderer_stream_id());
88
89 pc_handler->OnRemoveStream(remote_label, true);
90 EXPECT_TRUE(mock_client->stream_label().empty());
91
92 pc_handler->stop();
93 EXPECT_FALSE(pc_handler->native_peer_connection_.get());
94 // PC handler is expected to be deleted when stop calls
95 // MediaStreamImpl::ClosePeerConnection. We own and delete it here instead of
96 // in the mock.
97 pc_handler.reset();
98
99 // processPendingStreams must be tested on a new PC handler since removing
100 // streams is currently not supported.
101 pc_handler.reset(new PeerConnectionHandler(mock_client.get(),
102 mock_ms_impl.get(),
103 mock_dependency_factory.get(),
104 NULL,
105 NULL,
106 NULL,
107 NULL));
108 pc_handler->initialize(server_config, security_origin);
109 EXPECT_TRUE(pc_handler->native_peer_connection_.get());
110 mock_peer_connection = static_cast<webrtc::MockPeerConnectionImpl*>(
111 pc_handler->native_peer_connection_.get());
112
113 WebKit::WebVector<WebKit::WebMediaStreamDescriptor> pendingRemoveStreams(
114 static_cast<size_t>(0));
115 pc_handler->processPendingStreams(pendingAddStreams, pendingRemoveStreams);
116 EXPECT_EQ(label, mock_ms_impl->video_label());
117 EXPECT_EQ(label, mock_peer_connection->stream_id());
118 EXPECT_TRUE(mock_peer_connection->video_stream());
119 EXPECT_TRUE(mock_peer_connection->connected());
120 EXPECT_TRUE(mock_peer_connection->video_capture_set());
121
122 pc_handler->stop();
123 pc_handler.reset();
124 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698