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

Unified Diff: content/renderer/media/media_stream_dependency_factory_unittest.cc

Issue 10919122: Move creation of PeerConnection from the RenderView to the RenderThreadImpl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: #if defined(ENABLE_WEBRTC) in RendererWebKitPlatformSupportImpl::createPeerConnection00Handler to b… Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/media/media_stream_dependency_factory_unittest.cc
diff --git a/content/renderer/media/media_stream_dependency_factory_unittest.cc b/content/renderer/media/media_stream_dependency_factory_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a1a11310217bd534e7093f447d964a1b5cddda86
--- /dev/null
+++ b/content/renderer/media/media_stream_dependency_factory_unittest.cc
@@ -0,0 +1,110 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/memory/scoped_ptr.h"
+#include "content/common/media/media_stream_options.h"
+#include "content/renderer/media/media_stream_extra_data.h"
+#include "content/renderer/media/media_stream_source_extra_data.h"
+#include "content/renderer/media/mock_media_stream_dependency_factory.h"
+#include "content/renderer/media/mock_web_peer_connection_00_handler_client.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStreamComponent.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStreamDescriptor.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStreamSource.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnection00Handler.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandler.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
+
+
+class MediaStreamDependencyFactoryTest : public ::testing::Test {
+ public:
+ void SetUp() {
+ dependency_factory_.reset(new MockMediaStreamDependencyFactory());
+ }
+
+ WebKit::WebMediaStreamDescriptor CreateWebKitMediaStream(bool audio,
+ bool video) {
+ WebKit::WebVector<WebKit::WebMediaStreamSource> audio_sources(
+ audio ? static_cast<size_t>(1) : 0);
+ WebKit::WebVector<WebKit::WebMediaStreamSource> video_sources(
+ video ? static_cast<size_t>(1) : 0);
+
+ if (audio) {
+ media_stream::StreamDeviceInfo info;
+ info.stream_type = content::MEDIA_DEVICE_AUDIO_CAPTURE;
+ info.name = "audio";
+ info.session_id = 99;
+ audio_sources[0].initialize("audio",
+ WebKit::WebMediaStreamSource::TypeAudio,
+ "audio");
+ audio_sources[0].setExtraData(
+ new MediaStreamSourceExtraData(info));
+ }
+ if (video) {
+ media_stream::StreamDeviceInfo info;
+ info.stream_type = content::MEDIA_DEVICE_VIDEO_CAPTURE;
+ info.name = "video";
+ info.session_id = 98;
+ video_sources[0].initialize("video",
+ WebKit::WebMediaStreamSource::TypeVideo,
+ "video");
+ video_sources[0].setExtraData(
+ new MediaStreamSourceExtraData(info));
+ }
+ WebKit::WebMediaStreamDescriptor stream_desc;
+ stream_desc.initialize("media stream", audio_sources, video_sources);
+
+ return stream_desc;
+ }
+
+ protected:
+ scoped_ptr<MockMediaStreamDependencyFactory> dependency_factory_;
+};
+
+TEST_F(MediaStreamDependencyFactoryTest, CreatePeerConnectionHandlerJsep) {
+ // Create JSEP PeerConnection.
+ WebKit::MockWebPeerConnection00HandlerClient client_jsep;
+ scoped_ptr<WebKit::WebPeerConnection00Handler> pc_handler_jsep(
+ dependency_factory_->CreatePeerConnectionHandlerJsep(&client_jsep));
+ EXPECT_TRUE(pc_handler_jsep.get() != NULL);
+ pc_handler_jsep.reset();
+}
+
+TEST_F(MediaStreamDependencyFactoryTest, CreateNativeMediaStream) {
+ WebKit::WebMediaStreamDescriptor stream_desc = CreateWebKitMediaStream(true,
+ true);
+ EXPECT_TRUE(dependency_factory_->CreateNativeLocalMediaStream(&stream_desc));
+
+ MediaStreamExtraData* extra_data = static_cast<MediaStreamExtraData*>(
+ stream_desc.extraData());
+ ASSERT_TRUE(extra_data && extra_data->local_stream());
+ EXPECT_EQ(1u, extra_data->local_stream()->audio_tracks()->count());
+ EXPECT_EQ(1u, extra_data->local_stream()->video_tracks()->count());
+}
+
+// Test that we don't crash if a MediaStream is created in WebKit with unknown
+// sources. This can for example happen if a MediaStream is created with
+// remote tracks.
+TEST_F(MediaStreamDependencyFactoryTest, CreateNativeMediaStreamWithoutSource) {
+ // Create a WebKit MediaStream description.
+ WebKit::WebMediaStreamDescriptor stream_desc;
+ WebKit::WebVector<WebKit::WebMediaStreamSource> audio_sources(
+ static_cast<size_t>(1));
+ audio_sources[0].initialize("audio source",
+ WebKit::WebMediaStreamSource::TypeAudio,
+ "something");
+ WebKit::WebVector<WebKit::WebMediaStreamSource> video_sources(
+ static_cast<size_t>(1));
+ video_sources[0].initialize("video source",
+ WebKit::WebMediaStreamSource::TypeVideo,
+ "something");
+ stream_desc.initialize("new stream", audio_sources, video_sources);
+
+ EXPECT_TRUE(dependency_factory_->CreateNativeLocalMediaStream(&stream_desc));
+ MediaStreamExtraData* extra_data = static_cast<MediaStreamExtraData*>(
+ stream_desc.extraData());
+ ASSERT_TRUE(extra_data && extra_data->local_stream());
+ EXPECT_EQ(0u, extra_data->local_stream()->video_tracks()->count());
+ EXPECT_EQ(0u, extra_data->local_stream()->audio_tracks()->count());
+}
« no previous file with comments | « content/renderer/media/media_stream_dependency_factory.cc ('k') | content/renderer/media/media_stream_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698