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 { |
|
Jói
2014/01/15 16:37:05
Suggest naming MockMediaStreamVideoSource or Dummy
Ronghua Wu (Left Chromium)
2014/01/15 18:38:58
Was trying to follow Per's naming convention in hi
| |
| 14 : public ::testing::Test, | |
| 15 public MediaStreamVideoSource { | |
| 16 public: | 16 public: |
| 17 MediaStreamVideoSourceTest() {} | 17 MediaStreamVideoDummySource(MediaStreamDependencyFactory* factory) |
| 18 : MediaStreamVideoSource(factory) { | |
| 19 Init(); | |
| 20 SetVideoSource(GetAdapter()); | |
| 21 SetReadyState(blink::WebMediaStreamSource::ReadyStateLive); | |
| 22 } | |
| 23 | |
| 24 virtual ~MediaStreamVideoDummySource() { | |
| 25 SetReadyState(blink::WebMediaStreamSource::ReadyStateEnded); | |
| 26 } | |
| 27 | |
| 28 void OnNewFrame(const scoped_refptr<media::VideoFrame>& frame) { | |
| 29 MediaStreamVideoSource::DeliverVideoFrame(frame); | |
| 30 } | |
| 18 }; | 31 }; |
| 19 | 32 |
| 20 TEST_F(MediaStreamVideoSourceTest, OnVideoFrame) { | 33 class MediaStreamVideoSourceTest |
| 34 : public ::testing::Test { | |
| 35 public: | |
| 36 MediaStreamVideoSourceTest() { | |
| 37 factory_.EnsurePeerConnectionFactory(); | |
| 38 webkit_source_.initialize(base::UTF8ToUTF16("dummy_source_id"), | |
| 39 blink::WebMediaStreamSource::TypeVideo, | |
| 40 base::UTF8ToUTF16("dummy_source_name")); | |
| 41 webkit_source_.setExtraData(new MediaStreamVideoDummySource(&factory_)); | |
| 42 } | |
| 43 | |
| 44 protected: | |
| 45 // Create a track that's associated with |webkit_source_|. | |
| 46 blink::WebMediaStreamTrack CreateTrack(const std::string& id) { | |
| 47 blink::WebMediaStreamTrack track; | |
| 48 track.initialize(base::UTF8ToUTF16(id), webkit_source_); | |
| 49 return track; | |
| 50 } | |
| 51 | |
| 52 void VerifyFrame(int width, int height, int num) { | |
| 53 MediaStreamVideoDummySource* source = | |
| 54 static_cast<MediaStreamVideoDummySource*>(webkit_source_.extraData()); | |
| 55 MockVideoSource* adapter = | |
| 56 static_cast<MockVideoSource*>(source->GetAdapter()); | |
| 57 EXPECT_EQ(width, adapter->GetLastFrameWidth()); | |
| 58 EXPECT_EQ(height, adapter->GetLastFrameHeight()); | |
| 59 EXPECT_EQ(num, adapter->GetFrameNum()); | |
| 60 } | |
| 61 private: | |
| 62 MockMediaStreamDependencyFactory factory_; | |
| 63 blink::WebMediaStreamSource webkit_source_; | |
| 64 }; | |
| 65 | |
| 66 TEST_F(MediaStreamVideoSourceTest, DeliverVideoFrame) { | |
| 21 blink::WebMediaConstraints constraints; | 67 blink::WebMediaConstraints constraints; |
| 22 blink::WebMediaStreamTrack track; | 68 blink::WebMediaStreamTrack track = CreateTrack("123"); |
| 23 AddTrack(track, constraints); | 69 MediaStreamVideoDummySource* source = |
| 24 SetReadyState(blink::WebMediaStreamSource::ReadyStateLive); | 70 static_cast<MediaStreamVideoDummySource*>(track.source().extraData()); |
| 71 source->AddTrack(track, constraints); | |
| 72 VerifyFrame(0, 0, 0); | |
| 25 const int kWidth = 640; | 73 const int kWidth = 640; |
| 26 const int kHeight = 480; | 74 const int kHeight = 480; |
| 27 scoped_refptr<media::VideoFrame> frame = | 75 scoped_refptr<media::VideoFrame> frame = |
| 28 media::VideoFrame::CreateBlackFrame(gfx::Size(kWidth, kHeight)); | 76 media::VideoFrame::CreateBlackFrame(gfx::Size(kWidth, kHeight)); |
| 29 ASSERT_TRUE(frame.get()); | 77 ASSERT_TRUE(frame.get()); |
| 30 DeliverVideoFrame(frame); | 78 source->OnNewFrame(frame); |
| 31 SetReadyState(blink::WebMediaStreamSource::ReadyStateEnded); | 79 VerifyFrame(640, 480, 1); |
| 32 RemoveTrack(track); | 80 source->OnNewFrame(frame); |
| 81 VerifyFrame(640, 480, 2); | |
| 82 source->RemoveTrack(track); | |
| 33 } | 83 } |
| 34 | 84 |
| 35 } // namespace content | 85 } // namespace content |
| OLD | NEW |