OLD | NEW |
(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 "base/memory/scoped_ptr.h" |
| 6 #include "content/common/media/media_stream_options.h" |
| 7 #include "content/renderer/media/media_stream_extra_data.h" |
| 8 #include "content/renderer/media/media_stream_source_extra_data.h" |
| 9 #include "content/renderer/media/mock_media_stream_dependency_factory.h" |
| 10 #include "content/renderer/media/mock_web_peer_connection_00_handler_client.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre
amComponent.h" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre
amDescriptor.h" |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre
amSource.h" |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConne
ction00Handler.h" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConne
ctionHandler.h" |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" |
| 18 |
| 19 |
| 20 class MediaStreamDependencyFactoryTest : public ::testing::Test { |
| 21 public: |
| 22 void SetUp() { |
| 23 dependency_factory_.reset(new MockMediaStreamDependencyFactory()); |
| 24 } |
| 25 |
| 26 WebKit::WebMediaStreamDescriptor CreateWebKitMediaStream(bool audio, |
| 27 bool video) { |
| 28 WebKit::WebVector<WebKit::WebMediaStreamSource> audio_sources( |
| 29 audio ? static_cast<size_t>(1) : 0); |
| 30 WebKit::WebVector<WebKit::WebMediaStreamSource> video_sources( |
| 31 video ? static_cast<size_t>(1) : 0); |
| 32 |
| 33 if (audio) { |
| 34 media_stream::StreamDeviceInfo info; |
| 35 info.stream_type = content::MEDIA_DEVICE_AUDIO_CAPTURE; |
| 36 info.name = "audio"; |
| 37 info.session_id = 99; |
| 38 audio_sources[0].initialize("audio", |
| 39 WebKit::WebMediaStreamSource::TypeAudio, |
| 40 "audio"); |
| 41 audio_sources[0].setExtraData( |
| 42 new MediaStreamSourceExtraData(info)); |
| 43 } |
| 44 if (video) { |
| 45 media_stream::StreamDeviceInfo info; |
| 46 info.stream_type = content::MEDIA_DEVICE_VIDEO_CAPTURE; |
| 47 info.name = "video"; |
| 48 info.session_id = 98; |
| 49 video_sources[0].initialize("video", |
| 50 WebKit::WebMediaStreamSource::TypeVideo, |
| 51 "video"); |
| 52 video_sources[0].setExtraData( |
| 53 new MediaStreamSourceExtraData(info)); |
| 54 } |
| 55 WebKit::WebMediaStreamDescriptor stream_desc; |
| 56 stream_desc.initialize("media stream", audio_sources, video_sources); |
| 57 |
| 58 return stream_desc; |
| 59 } |
| 60 |
| 61 protected: |
| 62 scoped_ptr<MockMediaStreamDependencyFactory> dependency_factory_; |
| 63 }; |
| 64 |
| 65 TEST_F(MediaStreamDependencyFactoryTest, CreatePeerConnectionHandlerJsep) { |
| 66 // Create JSEP PeerConnection. |
| 67 WebKit::MockWebPeerConnection00HandlerClient client_jsep; |
| 68 scoped_ptr<WebKit::WebPeerConnection00Handler> pc_handler_jsep( |
| 69 dependency_factory_->CreatePeerConnectionHandlerJsep(&client_jsep)); |
| 70 EXPECT_TRUE(pc_handler_jsep.get() != NULL); |
| 71 pc_handler_jsep.reset(); |
| 72 } |
| 73 |
| 74 TEST_F(MediaStreamDependencyFactoryTest, CreateNativeMediaStream) { |
| 75 WebKit::WebMediaStreamDescriptor stream_desc = CreateWebKitMediaStream(true, |
| 76 true); |
| 77 EXPECT_TRUE(dependency_factory_->CreateNativeLocalMediaStream(&stream_desc)); |
| 78 |
| 79 MediaStreamExtraData* extra_data = static_cast<MediaStreamExtraData*>( |
| 80 stream_desc.extraData()); |
| 81 ASSERT_TRUE(extra_data && extra_data->local_stream()); |
| 82 EXPECT_EQ(1u, extra_data->local_stream()->audio_tracks()->count()); |
| 83 EXPECT_EQ(1u, extra_data->local_stream()->video_tracks()->count()); |
| 84 } |
| 85 |
| 86 // Test that we don't crash if a MediaStream is created in WebKit with unknown |
| 87 // sources. This can for example happen if a MediaStream is created with |
| 88 // remote tracks. |
| 89 TEST_F(MediaStreamDependencyFactoryTest, CreateNativeMediaStreamWithoutSource) { |
| 90 // Create a WebKit MediaStream description. |
| 91 WebKit::WebMediaStreamDescriptor stream_desc; |
| 92 WebKit::WebVector<WebKit::WebMediaStreamSource> audio_sources( |
| 93 static_cast<size_t>(1)); |
| 94 audio_sources[0].initialize("audio source", |
| 95 WebKit::WebMediaStreamSource::TypeAudio, |
| 96 "something"); |
| 97 WebKit::WebVector<WebKit::WebMediaStreamSource> video_sources( |
| 98 static_cast<size_t>(1)); |
| 99 video_sources[0].initialize("video source", |
| 100 WebKit::WebMediaStreamSource::TypeVideo, |
| 101 "something"); |
| 102 stream_desc.initialize("new stream", audio_sources, video_sources); |
| 103 |
| 104 EXPECT_TRUE(dependency_factory_->CreateNativeLocalMediaStream(&stream_desc)); |
| 105 MediaStreamExtraData* extra_data = static_cast<MediaStreamExtraData*>( |
| 106 stream_desc.extraData()); |
| 107 ASSERT_TRUE(extra_data && extra_data->local_stream()); |
| 108 EXPECT_EQ(0u, extra_data->local_stream()->video_tracks()->count()); |
| 109 EXPECT_EQ(0u, extra_data->local_stream()->audio_tracks()->count()); |
| 110 } |
OLD | NEW |