| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "content/child/child_process.h" | 8 #include "content/child/child_process.h" |
| 9 #include "content/renderer/media/media_stream_video_renderer_sink.h" | 9 #include "content/renderer/media/media_stream_video_renderer_sink.h" |
| 10 #include "content/renderer/media/mock_media_stream_registry.h" | 10 #include "content/renderer/media/mock_media_stream_registry.h" |
| 11 #include "media/base/video_frame.h" | 11 #include "media/base/video_frame.h" |
| 12 #include "media/renderers/gpu_video_accelerator_factories.h" |
| 12 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "third_party/WebKit/public/platform/WebString.h" | 15 #include "third_party/WebKit/public/platform/WebString.h" |
| 15 | 16 |
| 16 using ::testing::_; | 17 using ::testing::_; |
| 17 using ::testing::AtLeast; | 18 using ::testing::AtLeast; |
| 18 using ::testing::InSequence; | 19 using ::testing::InSequence; |
| 19 using ::testing::Lt; | 20 using ::testing::Lt; |
| 20 using ::testing::Mock; | 21 using ::testing::Mock; |
| 21 | 22 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 37 // Extract the Blink Video Track for the MSVRSink. | 38 // Extract the Blink Video Track for the MSVRSink. |
| 38 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; | 39 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; |
| 39 registry_.test_stream().videoTracks(video_tracks); | 40 registry_.test_stream().videoTracks(video_tracks); |
| 40 EXPECT_EQ(1u, video_tracks.size()); | 41 EXPECT_EQ(1u, video_tracks.size()); |
| 41 | 42 |
| 42 media_stream_video_renderer_sink_ = new MediaStreamVideoRendererSink( | 43 media_stream_video_renderer_sink_ = new MediaStreamVideoRendererSink( |
| 43 video_tracks[0], | 44 video_tracks[0], |
| 44 base::Bind(&MediaStreamVideoRendererSinkTest::ErrorCallback, | 45 base::Bind(&MediaStreamVideoRendererSinkTest::ErrorCallback, |
| 45 base::Unretained(this)), | 46 base::Unretained(this)), |
| 46 base::Bind(&MediaStreamVideoRendererSinkTest::RepaintCallback, | 47 base::Bind(&MediaStreamVideoRendererSinkTest::RepaintCallback, |
| 47 base::Unretained(this))); | 48 base::Unretained(this)), |
| 49 message_loop_.task_runner(), message_loop_.task_runner().get(), |
| 50 nullptr /* gpu_factories */); |
| 48 | 51 |
| 49 EXPECT_TRUE(IsInStoppedState()); | 52 EXPECT_TRUE(IsInStoppedState()); |
| 50 } | 53 } |
| 51 | 54 |
| 52 MOCK_METHOD1(RepaintCallback, void(const scoped_refptr<media::VideoFrame>&)); | 55 MOCK_METHOD1(RepaintCallback, void(const scoped_refptr<media::VideoFrame>&)); |
| 53 MOCK_METHOD0(ErrorCallback, void(void)); | 56 MOCK_METHOD0(ErrorCallback, void(void)); |
| 54 | 57 |
| 55 bool IsInStartedState() const { | 58 bool IsInStartedState() const { |
| 56 return media_stream_video_renderer_sink_->state_ == | 59 return media_stream_video_renderer_sink_->state_ == |
| 57 MediaStreamVideoRendererSink::STARTED; | 60 MediaStreamVideoRendererSink::STARTED; |
| 58 } | 61 } |
| 59 bool IsInStoppedState() const { | 62 bool IsInStoppedState() const { |
| 60 return media_stream_video_renderer_sink_->state_ == | 63 return media_stream_video_renderer_sink_->state_ == |
| 61 MediaStreamVideoRendererSink::STOPPED; | 64 MediaStreamVideoRendererSink::STOPPED; |
| 62 } | 65 } |
| 63 bool IsInPausedState() const { | 66 bool IsInPausedState() const { |
| 64 return media_stream_video_renderer_sink_->state_ == | 67 return media_stream_video_renderer_sink_->state_ == |
| 65 MediaStreamVideoRendererSink::PAUSED; | 68 MediaStreamVideoRendererSink::PAUSED; |
| 66 } | 69 } |
| 67 | 70 |
| 68 void OnVideoFrame(const scoped_refptr<media::VideoFrame>& frame) { | 71 void OnVideoFrame(const scoped_refptr<media::VideoFrame>& frame) { |
| 69 media_stream_video_renderer_sink_->OnVideoFrame(frame, | 72 media_stream_video_renderer_sink_->OnVideoFrame(frame, |
| 70 base::TimeTicks::Now()); | 73 base::TimeTicks::Now()); |
| 71 } | 74 } |
| 72 | 75 |
| 73 scoped_refptr<MediaStreamVideoRendererSink> media_stream_video_renderer_sink_; | 76 scoped_refptr<MediaStreamVideoRendererSink> media_stream_video_renderer_sink_; |
| 74 | 77 |
| 75 // A ChildProcess and a MessageLoopForUI are both needed to fool the Tracks | 78 // A ChildProcess and a MessageLoopForUI are both needed to fool the Tracks |
| 76 // and Sources in |registry_| into believing they are on the right threads. | 79 // and Sources in |registry_| into believing they are on the right threads. |
| 77 const base::MessageLoopForUI message_loop_; | 80 base::MessageLoopForUI message_loop_; |
| 78 const ChildProcess child_process_; | 81 const ChildProcess child_process_; |
| 79 MockMediaStreamRegistry registry_; | 82 MockMediaStreamRegistry registry_; |
| 80 | 83 |
| 81 private: | 84 private: |
| 82 DISALLOW_COPY_AND_ASSIGN(MediaStreamVideoRendererSinkTest); | 85 DISALLOW_COPY_AND_ASSIGN(MediaStreamVideoRendererSinkTest); |
| 83 }; | 86 }; |
| 84 | 87 |
| 85 // Checks that the initialization-destruction sequence works fine. | 88 // Checks that the initialization-destruction sequence works fine. |
| 86 TEST_F(MediaStreamVideoRendererSinkTest, StartStop) { | 89 TEST_F(MediaStreamVideoRendererSinkTest, StartStop) { |
| 87 EXPECT_TRUE(IsInStoppedState()); | 90 EXPECT_TRUE(IsInStoppedState()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 107 const scoped_refptr<media::VideoFrame> video_frame = | 110 const scoped_refptr<media::VideoFrame> video_frame = |
| 108 media::VideoFrame::CreateBlackFrame(gfx::Size(160, 80)); | 111 media::VideoFrame::CreateBlackFrame(gfx::Size(160, 80)); |
| 109 | 112 |
| 110 EXPECT_CALL(*this, RepaintCallback(video_frame)).Times(1); | 113 EXPECT_CALL(*this, RepaintCallback(video_frame)).Times(1); |
| 111 OnVideoFrame(video_frame); | 114 OnVideoFrame(video_frame); |
| 112 | 115 |
| 113 media_stream_video_renderer_sink_->Stop(); | 116 media_stream_video_renderer_sink_->Stop(); |
| 114 } | 117 } |
| 115 | 118 |
| 116 } // namespace content | 119 } // namespace content |
| OLD | NEW |