Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | |
| 7 #include "content/renderer/media/media_stream_video_source.h" | 8 #include "content/renderer/media/media_stream_video_source.h" |
| 9 #include "content/renderer/media/mock_media_stream_dependency_factory.h" | |
| 8 #include "media/base/video_frame.h" | 10 #include "media/base/video_frame.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 12 |
| 11 namespace content { | 13 namespace content { |
| 12 | 14 |
| 13 class MediaStreamVideoSourceTest | 15 class MediaStreamVideoDummySource : public MediaStreamVideoSource { |
| 14 : public ::testing::Test, | |
| 15 public MediaStreamVideoSource { | |
| 16 public: | 16 public: |
| 17 MediaStreamVideoSourceTest() {} | 17 MediaStreamVideoDummySource(MediaStreamDependencyFactory* factory) |
| 18 : MediaStreamVideoSource(factory, NULL) { | |
|
perkj_chrome
2014/01/14 08:29:10
Instead of NULL here and since I can not pass in t
Ronghua Wu (Left Chromium)
2014/01/14 19:42:10
Done.
| |
| 19 SetReadyState(blink::WebMediaStreamSource::ReadyStateLive); | |
| 20 } | |
| 21 | |
| 22 ~MediaStreamVideoDummySource() { | |
| 23 SetReadyState(blink::WebMediaStreamSource::ReadyStateEnded); | |
| 24 } | |
| 25 | |
| 26 void OnNewFrame(const scoped_refptr<media::VideoFrame>& frame) { | |
| 27 MediaStreamVideoSource::DeliverVideoFrame(frame); | |
| 28 } | |
| 18 }; | 29 }; |
| 19 | 30 |
| 20 TEST_F(MediaStreamVideoSourceTest, OnVideoFrame) { | 31 class MediaStreamVideoSourceTest |
| 32 : public ::testing::Test { | |
| 33 public: | |
| 34 MediaStreamVideoSourceTest() { | |
| 35 factory_.EnsurePeerConnectionFactory(); | |
| 36 webkit_source_.initialize(base::UTF8ToUTF16("dummy_source_id"), | |
| 37 blink::WebMediaStreamSource::TypeVideo, | |
| 38 base::UTF8ToUTF16("dummy_source_name")); | |
| 39 webkit_source_.setExtraData(new MediaStreamVideoDummySource(&factory_)); | |
| 40 } | |
| 41 | |
| 42 protected: | |
| 43 // Create a track that's associated with |webkit_source_|. | |
| 44 blink::WebMediaStreamTrack CreateTrack(const std::string& id) { | |
| 45 blink::WebMediaStreamTrack track; | |
| 46 track.initialize(base::UTF8ToUTF16(id), webkit_source_); | |
| 47 return track; | |
| 48 } | |
| 49 | |
| 50 blink::WebMediaStreamSource webkit_source_; | |
| 51 | |
| 52 private: | |
| 53 MockMediaStreamDependencyFactory factory_; | |
| 54 }; | |
| 55 | |
| 56 TEST_F(MediaStreamVideoSourceTest, DeliverVideoFrame) { | |
| 21 blink::WebMediaConstraints constraints; | 57 blink::WebMediaConstraints constraints; |
| 22 blink::WebMediaStreamTrack track; | 58 blink::WebMediaStreamTrack webkit_track = CreateTrack("123"); |
| 23 AddTrack(track, constraints); | 59 MediaStreamVideoDummySource* source = |
| 24 SetReadyState(blink::WebMediaStreamSource::ReadyStateLive); | 60 static_cast<MediaStreamVideoDummySource*>(webkit_source_.extraData()); |
| 61 source->AddTrack(webkit_track, constraints); | |
| 25 const int kWidth = 640; | 62 const int kWidth = 640; |
| 26 const int kHeight = 480; | 63 const int kHeight = 480; |
| 27 scoped_refptr<media::VideoFrame> frame = | 64 scoped_refptr<media::VideoFrame> frame = |
| 28 media::VideoFrame::CreateBlackFrame(gfx::Size(kWidth, kHeight)); | 65 media::VideoFrame::CreateBlackFrame(gfx::Size(kWidth, kHeight)); |
| 29 ASSERT_TRUE(frame.get()); | 66 ASSERT_TRUE(frame.get()); |
| 30 DeliverVideoFrame(frame); | 67 source->OnNewFrame(frame); |
| 31 SetReadyState(blink::WebMediaStreamSource::ReadyStateEnded); | 68 source->RemoveTrack(webkit_track); |
| 32 RemoveTrack(track); | |
| 33 } | 69 } |
| 34 | 70 |
| 35 } // namespace content | 71 } // namespace content |
| OLD | NEW |