| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "content/renderer/media/media_stream_video_capturer_source.h" | 7 #include "content/renderer/media/media_stream_video_capturer_source.h" |
| 8 #include "content/renderer/media/media_stream_video_track.h" | 8 #include "content/renderer/media/media_stream_video_track.h" |
| 9 #include "content/renderer/media/mock_media_constraint_factory.h" | 9 #include "content/renderer/media/mock_media_constraint_factory.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 namespace content { | 13 namespace content { |
| 14 | 14 |
| 15 class MockVideoCapturerDelegate : public VideoCapturerDelegate { | 15 class MockVideoCapturerDelegate : public VideoCapturerDelegate { |
| 16 public: | 16 public: |
| 17 explicit MockVideoCapturerDelegate(const StreamDeviceInfo& device_info) | 17 explicit MockVideoCapturerDelegate(const StreamDeviceInfo& device_info) |
| 18 : VideoCapturerDelegate(device_info) {} | 18 : VideoCapturerDelegate(device_info) {} |
| 19 | 19 |
| 20 MOCK_METHOD3(StartDeliver, | 20 MOCK_METHOD3(StartCapture, |
| 21 void(const media::VideoCaptureParams& params, | 21 void(const media::VideoCaptureParams& params, |
| 22 const NewFrameCallback& new_frame_callback, | 22 const VideoCaptureDeliverFrameCB& new_frame_callback, |
| 23 const StartedCallback& started_callback)); | 23 const StartedCallback& started_callback)); |
| 24 MOCK_METHOD0(StopDeliver,void()); | 24 MOCK_METHOD0(StopCapture,void()); |
| 25 | 25 |
| 26 private: | 26 private: |
| 27 virtual ~MockVideoCapturerDelegate() {} | 27 virtual ~MockVideoCapturerDelegate() {} |
| 28 }; | 28 }; |
| 29 | 29 |
| 30 class MediaStreamVideoCapturerSourceTest : public testing::Test { | 30 class MediaStreamVideoCapturerSourceTest : public testing::Test { |
| 31 public: | 31 public: |
| 32 void InitWithDeviceInfo(const StreamDeviceInfo& device_info) { | 32 void InitWithDeviceInfo(const StreamDeviceInfo& device_info) { |
| 33 delegate_ = new MockVideoCapturerDelegate(device_info); | 33 delegate_ = new MockVideoCapturerDelegate(device_info); |
| 34 source_ = new MediaStreamVideoCapturerSource( | 34 source_ = new MediaStreamVideoCapturerSource( |
| (...skipping 26 matching lines...) Expand all Loading... |
| 61 blink::WebMediaStreamSource webkit_source_; | 61 blink::WebMediaStreamSource webkit_source_; |
| 62 MediaStreamVideoCapturerSource* source_; // owned by webkit_source. | 62 MediaStreamVideoCapturerSource* source_; // owned by webkit_source. |
| 63 scoped_refptr<MockVideoCapturerDelegate> delegate_; | 63 scoped_refptr<MockVideoCapturerDelegate> delegate_; |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 TEST_F(MediaStreamVideoCapturerSourceTest, TabCaptureAllowResolutionChange) { | 66 TEST_F(MediaStreamVideoCapturerSourceTest, TabCaptureAllowResolutionChange) { |
| 67 StreamDeviceInfo device_info; | 67 StreamDeviceInfo device_info; |
| 68 device_info.device.type = MEDIA_TAB_VIDEO_CAPTURE; | 68 device_info.device.type = MEDIA_TAB_VIDEO_CAPTURE; |
| 69 InitWithDeviceInfo(device_info); | 69 InitWithDeviceInfo(device_info); |
| 70 | 70 |
| 71 EXPECT_CALL(*delegate_, StartDeliver( | 71 EXPECT_CALL(*delegate_, StartCapture( |
| 72 testing::Field(&media::VideoCaptureParams::allow_resolution_change, true), | 72 testing::Field(&media::VideoCaptureParams::allow_resolution_change, true), |
| 73 testing::_, | 73 testing::_, |
| 74 testing::_)).Times(1); | 74 testing::_)).Times(1); |
| 75 blink::WebMediaStreamTrack track = StartSource(); | 75 blink::WebMediaStreamTrack track = StartSource(); |
| 76 // When the track goes out of scope, the source will be stopped. | 76 // When the track goes out of scope, the source will be stopped. |
| 77 EXPECT_CALL(*delegate_, StopDeliver()); | 77 EXPECT_CALL(*delegate_, StopCapture()); |
| 78 } | 78 } |
| 79 | 79 |
| 80 TEST_F(MediaStreamVideoCapturerSourceTest, | 80 TEST_F(MediaStreamVideoCapturerSourceTest, |
| 81 DesktopCaptureAllowResolutionChange) { | 81 DesktopCaptureAllowResolutionChange) { |
| 82 StreamDeviceInfo device_info; | 82 StreamDeviceInfo device_info; |
| 83 device_info.device.type = MEDIA_DESKTOP_VIDEO_CAPTURE; | 83 device_info.device.type = MEDIA_DESKTOP_VIDEO_CAPTURE; |
| 84 InitWithDeviceInfo(device_info); | 84 InitWithDeviceInfo(device_info); |
| 85 | 85 |
| 86 EXPECT_CALL(*delegate_, StartDeliver( | 86 EXPECT_CALL(*delegate_, StartCapture( |
| 87 testing::Field(&media::VideoCaptureParams::allow_resolution_change, true), | 87 testing::Field(&media::VideoCaptureParams::allow_resolution_change, true), |
| 88 testing::_, | 88 testing::_, |
| 89 testing::_)).Times(1); | 89 testing::_)).Times(1); |
| 90 blink::WebMediaStreamTrack track = StartSource(); | 90 blink::WebMediaStreamTrack track = StartSource(); |
| 91 // When the track goes out of scope, the source will be stopped. | 91 // When the track goes out of scope, the source will be stopped. |
| 92 EXPECT_CALL(*delegate_, StopDeliver()); | 92 EXPECT_CALL(*delegate_, StopCapture()); |
| 93 } | 93 } |
| 94 | 94 |
| 95 } // namespace content | 95 } // namespace content |
| OLD | NEW |