OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Unit test for VideoCaptureManager. | 5 // Unit test for VideoCaptureManager. |
6 | 6 |
7 #include "content/browser/renderer_host/media/video_capture_manager.h" | 7 #include "content/browser/renderer_host/media/video_capture_manager.h" |
8 | 8 |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 device_->TakePhoto(std::move(callback)); | 87 device_->TakePhoto(std::move(callback)); |
88 } | 88 } |
89 | 89 |
90 private: | 90 private: |
91 const std::unique_ptr<media::VideoCaptureDevice> device_; | 91 const std::unique_ptr<media::VideoCaptureDevice> device_; |
92 WrappedDeviceFactory* const factory_; | 92 WrappedDeviceFactory* const factory_; |
93 | 93 |
94 DISALLOW_COPY_AND_ASSIGN(WrappedDevice); | 94 DISALLOW_COPY_AND_ASSIGN(WrappedDevice); |
95 }; | 95 }; |
96 | 96 |
| 97 static const media::VideoFacingMode DEFAULT_FACING = |
| 98 media::VideoFacingMode::MEDIA_VIDEO_FACING_USER; |
| 99 |
97 WrappedDeviceFactory() : FakeVideoCaptureDeviceFactory() {} | 100 WrappedDeviceFactory() : FakeVideoCaptureDeviceFactory() {} |
98 ~WrappedDeviceFactory() final {} | 101 ~WrappedDeviceFactory() final {} |
99 | 102 |
100 std::unique_ptr<media::VideoCaptureDevice> CreateDevice( | 103 std::unique_ptr<media::VideoCaptureDevice> CreateDevice( |
101 const media::VideoCaptureDeviceDescriptor& device_descriptor) final { | 104 const media::VideoCaptureDeviceDescriptor& device_descriptor) final { |
102 return base::MakeUnique<WrappedDevice>( | 105 return base::MakeUnique<WrappedDevice>( |
103 FakeVideoCaptureDeviceFactory::CreateDevice(device_descriptor), this); | 106 FakeVideoCaptureDeviceFactory::CreateDevice(device_descriptor), this); |
104 } | 107 } |
105 | 108 |
| 109 void GetDeviceDescriptors( |
| 110 media::VideoCaptureDeviceDescriptors* device_descriptors) override { |
| 111 media::FakeVideoCaptureDeviceFactory::GetDeviceDescriptors( |
| 112 device_descriptors); |
| 113 for (auto& descriptor : *device_descriptors) { |
| 114 if (descriptor.facing == media::VideoFacingMode::MEDIA_VIDEO_FACING_NONE) |
| 115 descriptor.facing = DEFAULT_FACING; |
| 116 } |
| 117 } |
| 118 |
106 MOCK_METHOD0(WillSuspendDevice, void()); | 119 MOCK_METHOD0(WillSuspendDevice, void()); |
107 MOCK_METHOD0(WillResumeDevice, void()); | 120 MOCK_METHOD0(WillResumeDevice, void()); |
108 | 121 |
109 private: | 122 private: |
110 void OnDeviceCreated(WrappedDevice* device) { | 123 void OnDeviceCreated(WrappedDevice* device) { |
111 devices_.push_back(device); | 124 devices_.push_back(device); |
112 } | 125 } |
113 | 126 |
114 void OnDeviceDestroyed(WrappedDevice* device) { | 127 void OnDeviceDestroyed(WrappedDevice* device) { |
115 const auto it = std::find(devices_.begin(), devices_.end(), device); | 128 const auto it = std::find(devices_.begin(), devices_.end(), device); |
(...skipping 27 matching lines...) Expand all Loading... |
143 int length, int buffer_id) override {} | 156 int length, int buffer_id) override {} |
144 void OnBufferDestroyed(VideoCaptureControllerID id, int buffer_id) override {} | 157 void OnBufferDestroyed(VideoCaptureControllerID id, int buffer_id) override {} |
145 void OnBufferReady(VideoCaptureControllerID id, | 158 void OnBufferReady(VideoCaptureControllerID id, |
146 int buffer_id, | 159 int buffer_id, |
147 const scoped_refptr<media::VideoFrame>& frame) override {} | 160 const scoped_refptr<media::VideoFrame>& frame) override {} |
148 void OnEnded(VideoCaptureControllerID id) override {} | 161 void OnEnded(VideoCaptureControllerID id) override {} |
149 | 162 |
150 void OnGotControllerCallback(VideoCaptureControllerID) {} | 163 void OnGotControllerCallback(VideoCaptureControllerID) {} |
151 }; | 164 }; |
152 | 165 |
| 166 // Input argument for testing AddVideoCaptureObserver(). |
| 167 class MockVideoCaptureObserver : public media::VideoCaptureObserver { |
| 168 public: |
| 169 MOCK_METHOD1(OnVideoCaptureStarted, void(media::VideoFacingMode)); |
| 170 MOCK_METHOD1(OnVideoCaptureStopped, void(media::VideoFacingMode)); |
| 171 }; |
| 172 |
153 } // namespace | 173 } // namespace |
154 | 174 |
155 // Test class | 175 // Test class |
156 class VideoCaptureManagerTest : public testing::Test { | 176 class VideoCaptureManagerTest : public testing::Test { |
157 public: | 177 public: |
158 VideoCaptureManagerTest() : next_client_id_(1) {} | 178 VideoCaptureManagerTest() : next_client_id_(1) {} |
159 ~VideoCaptureManagerTest() override {} | 179 ~VideoCaptureManagerTest() override {} |
160 | 180 |
161 void HandleEnumerationResult( | 181 void HandleEnumerationResult( |
162 const base::Closure& quit_closure, | 182 const base::Closure& quit_closure, |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 base::RunLoop().RunUntilIdle(); | 344 base::RunLoop().RunUntilIdle(); |
325 | 345 |
326 vcm_->StopCaptureForClient(controllers_[client_id], client_id, | 346 vcm_->StopCaptureForClient(controllers_[client_id], client_id, |
327 frame_observer_.get(), true); | 347 frame_observer_.get(), true); |
328 | 348 |
329 // Wait to check callbacks before removing the listener. | 349 // Wait to check callbacks before removing the listener. |
330 base::RunLoop().RunUntilIdle(); | 350 base::RunLoop().RunUntilIdle(); |
331 vcm_->UnregisterListener(); | 351 vcm_->UnregisterListener(); |
332 } | 352 } |
333 | 353 |
| 354 TEST_F(VideoCaptureManagerTest, AddObserver) { |
| 355 InSequence s; |
| 356 MockVideoCaptureObserver observer; |
| 357 vcm_->AddVideoCaptureObserver(&observer); |
| 358 |
| 359 EXPECT_CALL(observer, |
| 360 OnVideoCaptureStarted(WrappedDeviceFactory::DEFAULT_FACING)); |
| 361 EXPECT_CALL(observer, |
| 362 OnVideoCaptureStopped(WrappedDeviceFactory::DEFAULT_FACING)); |
| 363 |
| 364 int video_session_id = vcm_->Open(devices_.front()); |
| 365 VideoCaptureControllerID client_id = StartClient(video_session_id, true); |
| 366 |
| 367 StopClient(client_id); |
| 368 vcm_->Close(video_session_id); |
| 369 |
| 370 // Wait to check callbacks before removing the listener. |
| 371 base::RunLoop().RunUntilIdle(); |
| 372 vcm_->UnregisterListener(); |
| 373 } |
| 374 |
334 // Open the same device twice. | 375 // Open the same device twice. |
335 TEST_F(VideoCaptureManagerTest, OpenTwice) { | 376 TEST_F(VideoCaptureManagerTest, OpenTwice) { |
336 InSequence s; | 377 InSequence s; |
337 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); | 378 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); |
338 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); | 379 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); |
339 | 380 |
340 int video_session_id_first = vcm_->Open(devices_.front()); | 381 int video_session_id_first = vcm_->Open(devices_.front()); |
341 | 382 |
342 // This should trigger an error callback with error code | 383 // This should trigger an error callback with error code |
343 // 'kDeviceAlreadyInUse'. | 384 // 'kDeviceAlreadyInUse'. |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 // Wait to check callbacks before removing the listener. | 774 // Wait to check callbacks before removing the listener. |
734 base::RunLoop().RunUntilIdle(); | 775 base::RunLoop().RunUntilIdle(); |
735 vcm_->UnregisterListener(); | 776 vcm_->UnregisterListener(); |
736 } | 777 } |
737 #endif | 778 #endif |
738 | 779 |
739 // TODO(mcasas): Add a test to check consolidation of the supported formats | 780 // TODO(mcasas): Add a test to check consolidation of the supported formats |
740 // provided by the device when http://crbug.com/323913 is closed. | 781 // provided by the device when http://crbug.com/323913 is closed. |
741 | 782 |
742 } // namespace content | 783 } // namespace content |
OLD | NEW |