| 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 "content/renderer/media_capture_from_element/html_video_element_capture
r_source.h" |
| 5 #include "base/bind.h" | 6 #include "base/bind.h" |
| 6 #include "base/memory/weak_ptr.h" | 7 #include "base/memory/weak_ptr.h" |
| 7 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/test/scoped_task_environment.h" |
| 8 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| 9 #include "content/renderer/media_capture_from_element/html_video_element_capture
r_source.h" | |
| 10 #include "media/base/limits.h" | 11 #include "media/base/limits.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "third_party/WebKit/public/platform/WebMediaPlayer.h" | 14 #include "third_party/WebKit/public/platform/WebMediaPlayer.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::InSequence; | 18 using ::testing::InSequence; |
| 18 using ::testing::Mock; | 19 using ::testing::Mock; |
| 19 using ::testing::SaveArg; | 20 using ::testing::SaveArg; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 // We could fill in |canvas| with a meaningful pattern in ARGB and verify | 77 // We could fill in |canvas| with a meaningful pattern in ARGB and verify |
| 77 // that is correctly captured (as I420) by HTMLVideoElementCapturerSource | 78 // that is correctly captured (as I420) by HTMLVideoElementCapturerSource |
| 78 // but I don't think that'll be easy/useful/robust, so just let go here. | 79 // but I don't think that'll be easy/useful/robust, so just let go here. |
| 79 return; | 80 return; |
| 80 } | 81 } |
| 81 }; | 82 }; |
| 82 | 83 |
| 83 class HTMLVideoElementCapturerSourceTest : public testing::Test { | 84 class HTMLVideoElementCapturerSourceTest : public testing::Test { |
| 84 public: | 85 public: |
| 85 HTMLVideoElementCapturerSourceTest() | 86 HTMLVideoElementCapturerSourceTest() |
| 86 : web_media_player_(new MockWebMediaPlayer()), | 87 : scoped_task_environment_( |
| 88 base::test::ScopedTaskEnvironment::MainThreadType::UI), |
| 89 web_media_player_(new MockWebMediaPlayer()), |
| 87 html_video_capturer_(new HtmlVideoElementCapturerSource( | 90 html_video_capturer_(new HtmlVideoElementCapturerSource( |
| 88 web_media_player_->AsWeakPtr(), | 91 web_media_player_->AsWeakPtr(), |
| 89 base::ThreadTaskRunnerHandle::Get())) {} | 92 base::ThreadTaskRunnerHandle::Get())) {} |
| 90 | 93 |
| 91 // Necessary callbacks and MOCK_METHODS for them. | 94 // Necessary callbacks and MOCK_METHODS for them. |
| 92 MOCK_METHOD2(DoOnDeliverFrame, | 95 MOCK_METHOD2(DoOnDeliverFrame, |
| 93 void(const scoped_refptr<media::VideoFrame>&, base::TimeTicks)); | 96 void(const scoped_refptr<media::VideoFrame>&, base::TimeTicks)); |
| 94 void OnDeliverFrame(const scoped_refptr<media::VideoFrame>& video_frame, | 97 void OnDeliverFrame(const scoped_refptr<media::VideoFrame>& video_frame, |
| 95 base::TimeTicks estimated_capture_time) { | 98 base::TimeTicks estimated_capture_time) { |
| 96 DoOnDeliverFrame(video_frame, estimated_capture_time); | 99 DoOnDeliverFrame(video_frame, estimated_capture_time); |
| 97 } | 100 } |
| 98 | 101 |
| 99 MOCK_METHOD1(DoOnVideoCaptureDeviceFormats, | 102 MOCK_METHOD1(DoOnVideoCaptureDeviceFormats, |
| 100 void(const media::VideoCaptureFormats&)); | 103 void(const media::VideoCaptureFormats&)); |
| 101 void OnVideoCaptureDeviceFormats(const media::VideoCaptureFormats& formats) { | 104 void OnVideoCaptureDeviceFormats(const media::VideoCaptureFormats& formats) { |
| 102 DoOnVideoCaptureDeviceFormats(formats); | 105 DoOnVideoCaptureDeviceFormats(formats); |
| 103 } | 106 } |
| 104 | 107 |
| 105 MOCK_METHOD1(DoOnRunning, void(bool)); | 108 MOCK_METHOD1(DoOnRunning, void(bool)); |
| 106 void OnRunning(bool state) { DoOnRunning(state); } | 109 void OnRunning(bool state) { DoOnRunning(state); } |
| 107 | 110 |
| 108 protected: | 111 protected: |
| 109 // We need some kind of message loop to allow |html_video_capturer_| to | 112 // We need some kind of message loop to allow |html_video_capturer_| to |
| 110 // schedule capture events. | 113 // schedule capture events. |
| 111 const base::MessageLoopForUI message_loop_; | 114 const base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 112 | 115 |
| 113 std::unique_ptr<MockWebMediaPlayer> web_media_player_; | 116 std::unique_ptr<MockWebMediaPlayer> web_media_player_; |
| 114 std::unique_ptr<HtmlVideoElementCapturerSource> html_video_capturer_; | 117 std::unique_ptr<HtmlVideoElementCapturerSource> html_video_capturer_; |
| 115 }; | 118 }; |
| 116 | 119 |
| 117 // Constructs and destructs all objects, in particular |html_video_capturer_| | 120 // Constructs and destructs all objects, in particular |html_video_capturer_| |
| 118 // and its inner object(s). This is a non trivial sequence. | 121 // and its inner object(s). This is a non trivial sequence. |
| 119 TEST_F(HTMLVideoElementCapturerSourceTest, ConstructAndDestruct) {} | 122 TEST_F(HTMLVideoElementCapturerSourceTest, ConstructAndDestruct) {} |
| 120 | 123 |
| 121 // Checks that the usual sequence of GetCurrentSupportedFormats() -> | 124 // Checks that the usual sequence of GetCurrentSupportedFormats() -> |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 base::Bind(&HTMLVideoElementCapturerSourceTest::OnRunning, | 162 base::Bind(&HTMLVideoElementCapturerSourceTest::OnRunning, |
| 160 base::Unretained(this))); | 163 base::Unretained(this))); |
| 161 | 164 |
| 162 run_loop.Run(); | 165 run_loop.Run(); |
| 163 | 166 |
| 164 html_video_capturer_->StopCapture(); | 167 html_video_capturer_->StopCapture(); |
| 165 Mock::VerifyAndClearExpectations(this); | 168 Mock::VerifyAndClearExpectations(this); |
| 166 } | 169 } |
| 167 | 170 |
| 168 } // namespace content | 171 } // namespace content |
| OLD | NEW |