Chromium Code Reviews| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 public: | 33 public: |
| 34 MockMediaStreamProviderListener() {} | 34 MockMediaStreamProviderListener() {} |
| 35 ~MockMediaStreamProviderListener() {} | 35 ~MockMediaStreamProviderListener() {} |
| 36 | 36 |
| 37 MOCK_METHOD2(Opened, void(MediaStreamType, int)); | 37 MOCK_METHOD2(Opened, void(MediaStreamType, int)); |
| 38 MOCK_METHOD2(Closed, void(MediaStreamType, int)); | 38 MOCK_METHOD2(Closed, void(MediaStreamType, int)); |
| 39 MOCK_METHOD2(DevicesEnumerated, void(MediaStreamType, | 39 MOCK_METHOD2(DevicesEnumerated, void(MediaStreamType, |
| 40 const StreamDeviceInfoArray&)); | 40 const StreamDeviceInfoArray&)); |
| 41 MOCK_METHOD3(Error, void(MediaStreamType, int, | 41 MOCK_METHOD3(Error, void(MediaStreamType, int, |
| 42 MediaStreamProviderError)); | 42 MediaStreamProviderError)); |
| 43 MOCK_METHOD2( | |
| 44 DeviceCapabilitiesEnumerated, | |
| 45 void(const StreamDeviceInfo&, const media::VideoCaptureCapabilities&)); | |
| 43 }; // class MockMediaStreamProviderListener | 46 }; // class MockMediaStreamProviderListener |
| 44 | 47 |
| 45 // Needed as an input argument to StartCaptureForClient(). | 48 // Needed as an input argument to StartCaptureForClient(). |
| 46 class MockFrameObserver : public VideoCaptureControllerEventHandler { | 49 class MockFrameObserver : public VideoCaptureControllerEventHandler { |
| 47 public: | 50 public: |
| 48 MOCK_METHOD1(OnError, void(const VideoCaptureControllerID& id)); | 51 MOCK_METHOD1(OnError, void(const VideoCaptureControllerID& id)); |
| 49 | 52 |
| 50 virtual void OnBufferCreated(const VideoCaptureControllerID& id, | 53 virtual void OnBufferCreated(const VideoCaptureControllerID& id, |
| 51 base::SharedMemoryHandle handle, | 54 base::SharedMemoryHandle handle, |
| 52 int length, int buffer_id) OVERRIDE {} | 55 int length, int buffer_id) OVERRIDE {} |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 VideoCaptureControllerID client_id = StartClient(video_session_id, true); | 157 VideoCaptureControllerID client_id = StartClient(video_session_id, true); |
| 155 | 158 |
| 156 StopClient(client_id); | 159 StopClient(client_id); |
| 157 vcm_->Close(video_session_id); | 160 vcm_->Close(video_session_id); |
| 158 | 161 |
| 159 // Wait to check callbacks before removing the listener. | 162 // Wait to check callbacks before removing the listener. |
| 160 message_loop_->RunUntilIdle(); | 163 message_loop_->RunUntilIdle(); |
| 161 vcm_->Unregister(); | 164 vcm_->Unregister(); |
| 162 } | 165 } |
| 163 | 166 |
| 167 // Try to enumerate devices, then check their capture capabilities. | |
| 168 TEST_F(VideoCaptureManagerTest, EnumerateDevicesAndCheckCapabilities) { | |
| 169 StreamDeviceInfoArray devices; | |
| 170 | |
| 171 InSequence s; | |
| 172 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) | |
| 173 .Times(1).WillOnce(SaveArg<1>(&devices)); | |
| 174 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); | |
| 175 message_loop_->RunUntilIdle(); | |
| 176 | |
|
tommi (sloooow) - chröme
2013/10/25 14:15:34
1 empty line
mcasas
2013/10/28 12:50:08
Done.
| |
| 177 | |
| 178 media::VideoCaptureCapabilities device_capabilities; | |
| 179 StreamDeviceInfoArray::iterator device_it; | |
| 180 for (device_it = devices.begin(); device_it != devices.end(); ++device_it) { | |
| 181 EXPECT_CALL(*listener_, DeviceCapabilitiesEnumerated(_, _)) | |
| 182 .Times(1).WillOnce(SaveArg<1>(&device_capabilities)); | |
| 183 | |
| 184 vcm_->EnumerateDeviceCapabilities(*device_it); | |
| 185 message_loop_->RunUntilIdle(); | |
|
tommi (sloooow) - chröme
2013/10/25 14:15:34
can you add a comment that explains what happens d
mcasas
2013/10/28 12:50:08
(Tentatively) Done.
| |
| 186 DCHECK_GE(device_capabilities.size(), 1u); | |
|
tommi (sloooow) - chröme
2013/10/25 14:15:34
ASSERT_GE?
mcasas
2013/10/28 12:50:08
Hmm device documentation says devices may return e
| |
| 187 | |
| 188 media::VideoCaptureCapabilities::const_iterator format; | |
| 189 for (format = device_capabilities.begin(); | |
| 190 format != device_capabilities.end(); | |
| 191 ++format) { | |
| 192 DCHECK_GE(format->width, 1); | |
|
tommi (sloooow) - chröme
2013/10/25 14:15:34
EXPECT_GE? (same below)
mcasas
2013/10/28 12:50:08
Oops :) Yes, all should be EXPECT_GE
| |
| 193 DCHECK_GE(format->height, 1); | |
| 194 DCHECK_GE(format->frame_rate, 1); | |
| 195 DVLOG(1) << " Device name: " << device_it->device.name << ", format (" | |
| 196 << format->width << "x" << format->height << ")@" | |
| 197 << format->frame_rate << "fps"; | |
| 198 } | |
| 199 } | |
| 200 vcm_->Unregister(); | |
| 201 } | |
| 202 | |
| 164 // Open the same device twice. | 203 // Open the same device twice. |
| 165 TEST_F(VideoCaptureManagerTest, OpenTwice) { | 204 TEST_F(VideoCaptureManagerTest, OpenTwice) { |
| 166 StreamDeviceInfoArray devices; | 205 StreamDeviceInfoArray devices; |
| 167 | 206 |
| 168 InSequence s; | 207 InSequence s; |
| 169 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) | 208 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
| 170 .Times(1).WillOnce(SaveArg<1>(&devices)); | 209 .Times(1).WillOnce(SaveArg<1>(&devices)); |
| 171 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); | 210 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); |
| 172 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); | 211 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); |
| 173 | 212 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 // VideoCaptureManager destructor otherwise. | 324 // VideoCaptureManager destructor otherwise. |
| 286 vcm_->Close(video_session_id); | 325 vcm_->Close(video_session_id); |
| 287 StopClient(client_id); | 326 StopClient(client_id); |
| 288 | 327 |
| 289 // Wait to check callbacks before removing the listener | 328 // Wait to check callbacks before removing the listener |
| 290 message_loop_->RunUntilIdle(); | 329 message_loop_->RunUntilIdle(); |
| 291 vcm_->Unregister(); | 330 vcm_->Unregister(); |
| 292 } | 331 } |
| 293 | 332 |
| 294 } // namespace content | 333 } // namespace content |
| OLD | NEW |