OLD | NEW |
---|---|
(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/libjingle/source/talk/p2p/client/httpportallocator.h" | |
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamDescrip tor.h" | |
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamSource. h" | |
22 | |
23 TEST(PeerConnectionHandlerTest, Basic) { | |
24 MessageLoop loop; | |
25 | |
26 scoped_ptr<WebKit::MockWebPeerConnectionHandlerClient> mock_client( | |
27 new WebKit::MockWebPeerConnectionHandlerClient()); | |
28 scoped_refptr<MockMediaStreamImpl> mock_ms_impl(new MockMediaStreamImpl()); | |
29 MockMediaStreamDependencyFactory* mock_dependency_factory = | |
30 new MockMediaStreamDependencyFactory(); | |
31 mock_dependency_factory->CreatePeerConnectionFactory(NULL, NULL, NULL); | |
32 scoped_ptr<cricket::HttpPortAllocator> port_allocator( | |
33 new cricket::HttpPortAllocator(NULL, "PeerConnection")); | |
34 scoped_ptr<PeerConnectionHandler> pc_handler( | |
35 new PeerConnectionHandler(mock_client.get(), | |
36 mock_ms_impl.get(), | |
37 mock_dependency_factory, | |
38 NULL, | |
39 port_allocator.get())); | |
40 | |
41 WebKit::WebString server_config( | |
42 WebKit::WebString::fromUTF8("STUN stun.l.google.com:19302")); | |
tommi (sloooow) - chröme
2011/11/22 16:11:38
should we also test the init function with bad inp
Henrik Grunell
2011/11/23 21:50:49
My intention was to do basic tests now, and expand
| |
43 WebKit::WebSecurityOrigin security_origin; | |
44 pc_handler->initialize(server_config, security_origin); | |
45 EXPECT_TRUE(pc_handler->native_peer_connection_.get()); | |
46 webrtc::MockPeerConnectionImpl* mock_peer_connection = | |
47 static_cast<webrtc::MockPeerConnectionImpl*>( | |
48 pc_handler->native_peer_connection_.get()); | |
49 EXPECT_EQ(static_cast<webrtc::PeerConnectionObserver*>(pc_handler.get()), | |
50 mock_peer_connection->observer()); | |
51 | |
52 std::string label("label"); | |
53 WebKit::WebVector<WebKit::WebMediaStreamSource> | |
54 source_vector(static_cast<size_t>(1)); | |
55 source_vector[0].initialize(WebKit::WebString::fromUTF8(label), | |
56 WebKit::WebMediaStreamSource::TypeVideo, | |
57 WebKit::WebString::fromUTF8("RemoteVideo")); | |
58 WebKit::WebVector<WebKit::WebMediaStreamDescriptor> | |
59 pendingAddStreams(static_cast<size_t>(1)); | |
60 pendingAddStreams[0].initialize(UTF8ToUTF16(label), source_vector); | |
61 pc_handler->produceInitialOffer(pendingAddStreams); | |
62 EXPECT_EQ(label, mock_ms_impl->video_label()); | |
63 EXPECT_EQ(label, mock_peer_connection->stream_id()); | |
64 EXPECT_TRUE(mock_peer_connection->video_stream()); | |
65 EXPECT_TRUE(mock_peer_connection->connected()); | |
66 EXPECT_TRUE(mock_peer_connection->video_capture_set()); | |
67 | |
68 std::string message("message1"); | |
69 pc_handler->handleInitialOffer(WebKit::WebString::fromUTF8(message)); | |
70 EXPECT_EQ(message, mock_peer_connection->signaling_message()); | |
71 | |
72 message = "message2"; | |
73 pc_handler->processSDP(WebKit::WebString::fromUTF8(message)); | |
74 EXPECT_EQ(message, mock_peer_connection->signaling_message()); | |
75 | |
76 message = "message3"; | |
77 pc_handler->OnSignalingMessage(message); | |
78 EXPECT_EQ(message, mock_client->sdp()); | |
79 | |
80 std::string remote_label(label); | |
81 remote_label.append("-remote"); | |
82 pc_handler->OnAddStream(remote_label, true); | |
83 EXPECT_EQ(remote_label, mock_client->stream_label()); | |
84 | |
85 RTCVideoDecoder* rtc_video_decoder = new RTCVideoDecoder(&loop, ""); | |
86 pc_handler->SetVideoRenderer(label, rtc_video_decoder); | |
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, | |
104 NULL, | |
105 port_allocator.get())); | |
106 pc_handler->initialize(server_config, security_origin); | |
107 EXPECT_TRUE(pc_handler->native_peer_connection_.get()); | |
108 mock_peer_connection = static_cast<webrtc::MockPeerConnectionImpl*>( | |
109 pc_handler->native_peer_connection_.get()); | |
110 | |
111 WebKit::WebVector<WebKit::WebMediaStreamDescriptor> | |
112 pendingRemoveStreams(static_cast<size_t>(0)); | |
113 pc_handler->processPendingStreams(pendingAddStreams, pendingRemoveStreams); | |
114 EXPECT_EQ(label, mock_ms_impl->video_label()); | |
115 EXPECT_EQ(label, mock_peer_connection->stream_id()); | |
116 EXPECT_TRUE(mock_peer_connection->video_stream()); | |
117 EXPECT_TRUE(mock_peer_connection->connected()); | |
118 EXPECT_TRUE(mock_peer_connection->video_capture_set()); | |
119 | |
120 pc_handler->stop(); | |
121 pc_handler.reset(); | |
122 } | |
OLD | NEW |