Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/process_util.h" | 11 #include "base/process_util.h" |
| 12 #include "content/browser/browser_thread.h" | 12 #include "content/browser/browser_thread.h" |
| 13 #include "content/browser/renderer_host/media/media_stream_provider.h" | 13 #include "content/browser/renderer_host/media/media_stream_provider.h" |
| 14 #include "content/browser/renderer_host/media/video_capture_manager.h" | 14 #include "content/browser/renderer_host/media/video_capture_manager.h" |
| 15 #include "content/common/media/media_stream_options.h" | |
| 15 #include "media/video/capture/video_capture_device.h" | 16 #include "media/video/capture/video_capture_device.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 19 |
| 19 using ::testing::_; | 20 using ::testing::_; |
| 20 using ::testing::AnyNumber; | 21 using ::testing::AnyNumber; |
| 21 using ::testing::InSequence; | 22 using ::testing::InSequence; |
| 22 using ::testing::Return; | 23 using ::testing::Return; |
| 23 | 24 |
| 24 namespace media_stream { | 25 namespace media_stream { |
| 25 | 26 |
| 26 // Listener class used to track progress of VideoCaptureManager test | 27 // Listener class used to track progress of VideoCaptureManager test |
| 27 class MockMediaStreamProviderListener : public MediaStreamProviderListener { | 28 class MockMediaStreamProviderListener : public MediaStreamProviderListener { |
| 28 public: | 29 public: |
| 29 MockMediaStreamProviderListener() | 30 MockMediaStreamProviderListener() |
| 30 : devices_() { | 31 : devices_() { |
| 31 } | 32 } |
| 32 ~MockMediaStreamProviderListener() {} | 33 ~MockMediaStreamProviderListener() {} |
| 33 | 34 |
| 34 MOCK_METHOD2(Opened, void(MediaStreamType, MediaCaptureSessionId)); | 35 MOCK_METHOD2(Opened, void(MediaStreamType, int)); |
| 35 MOCK_METHOD2(Closed, void(MediaStreamType, MediaCaptureSessionId)); | 36 MOCK_METHOD2(Closed, void(MediaStreamType, int)); |
| 36 MOCK_METHOD1(DevicesEnumerated, void(const MediaCaptureDevices&)); | 37 MOCK_METHOD1(DevicesEnumerated, void(const StreamDeviceInfoArray&)); |
| 37 MOCK_METHOD3(Error, void(MediaStreamType, MediaCaptureSessionId, | 38 MOCK_METHOD3(Error, void(MediaStreamType, int, |
| 38 MediaStreamProviderError)); | 39 MediaStreamProviderError)); |
| 39 | 40 |
| 40 virtual void DevicesEnumerated(MediaStreamType stream_type, | 41 virtual void DevicesEnumerated(MediaStreamType stream_type, |
| 41 const MediaCaptureDevices& devices) { | 42 const StreamDeviceInfoArray& devices) { |
| 42 devices_.clear(); | 43 devices_.clear(); |
| 43 for (MediaCaptureDevices::const_iterator it = devices.begin(); | 44 for (StreamDeviceInfoArray::const_iterator it = devices.begin(); |
| 44 it != devices.end(); | 45 it != devices.end(); |
| 45 ++it) { | 46 ++it) { |
| 46 devices_.push_back(*it); | 47 devices_.push_back(*it); |
| 47 } | 48 } |
| 48 DevicesEnumerated(devices); | 49 DevicesEnumerated(devices); |
| 49 } | 50 } |
| 50 | 51 |
| 51 media_stream::MediaCaptureDevices devices_; | 52 media_stream::StreamDeviceInfoArray devices_; |
| 52 }; // class MockMediaStreamProviderListener | 53 }; // class MockMediaStreamProviderListener |
| 53 | 54 |
| 54 } // namespace media_stream | 55 } // namespace media_stream |
| 55 | 56 |
| 56 namespace { | 57 namespace { |
| 57 | 58 |
| 58 // Needed as an input argument to Start() | 59 // Needed as an input argument to Start() |
| 59 class MockFrameObserver: public media::VideoCaptureDevice::EventHandler { | 60 class MockFrameObserver: public media::VideoCaptureDevice::EventHandler { |
| 60 public: | 61 public: |
| 61 virtual void OnError() {} | 62 virtual void OnError() {} |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 media_stream::VideoCaptureManager* vcm = | 206 media_stream::VideoCaptureManager* vcm = |
| 206 media_stream::VideoCaptureManager::Get(); | 207 media_stream::VideoCaptureManager::Get(); |
| 207 // Make sure fake devices are used | 208 // Make sure fake devices are used |
| 208 vcm->UseFakeDevice(); | 209 vcm->UseFakeDevice(); |
| 209 vcm->Register(listener_.get()); | 210 vcm->Register(listener_.get()); |
| 210 vcm->EnumerateDevices(); | 211 vcm->EnumerateDevices(); |
| 211 | 212 |
| 212 // Wait to get device callback... | 213 // Wait to get device callback... |
| 213 SyncWithVideoCaptureManagerThread(); | 214 SyncWithVideoCaptureManagerThread(); |
| 214 | 215 |
| 215 media_stream::MediaCaptureDevices::iterator it = | 216 media_stream::StreamDeviceInfoArray::iterator it = |
| 216 listener_->devices_.begin(); | 217 listener_->devices_.begin(); |
| 217 | 218 |
| 218 int video_session_id_first = vcm->Open(*it); | 219 int video_session_id_first = vcm->Open(*it); |
| 219 | 220 |
| 220 // This should trigger an error callback with error code 'kDeviceAlreadyInUse' | 221 // This should trigger an error callback with error code 'kDeviceAlreadyInUse' |
| 221 ++it; | 222 ++it; |
| 222 int video_session_id_second = vcm->Open(*it); | 223 int video_session_id_second = vcm->Open(*it); |
| 223 | 224 |
| 224 vcm->Close(video_session_id_first); | 225 vcm->Close(video_session_id_first); |
| 225 vcm->Close(video_session_id_second); | 226 vcm->Close(video_session_id_second); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 244 vcm->UseFakeDevice(); | 245 vcm->UseFakeDevice(); |
| 245 vcm->Register(listener_.get()); | 246 vcm->Register(listener_.get()); |
| 246 vcm->EnumerateDevices(); | 247 vcm->EnumerateDevices(); |
| 247 | 248 |
| 248 // Wait to get device callback... | 249 // Wait to get device callback... |
| 249 SyncWithVideoCaptureManagerThread(); | 250 SyncWithVideoCaptureManagerThread(); |
| 250 | 251 |
| 251 media_stream::MediaStreamType stream_type = media_stream::kVideoCapture; | 252 media_stream::MediaStreamType stream_type = media_stream::kVideoCapture; |
| 252 std::string device_name("device_doesnt_exist"); | 253 std::string device_name("device_doesnt_exist"); |
| 253 std::string device_id("id_doesnt_exist"); | 254 std::string device_id("id_doesnt_exist"); |
| 254 media_stream::MediaCaptureDeviceInfo dummy_device(stream_type, device_name, | 255 media_stream::StreamDeviceInfo dummy_device(stream_type, device_name, |
| 255 device_id, false); | 256 device_id, false); |
|
John Knottenbelt
2011/06/16 15:20:43
nit: indentation
mflodman1
2011/06/20 19:48:03
Done.
| |
| 256 | 257 |
| 257 // This should fail with error code 'kDeviceNotAvailable' | 258 // This should fail with error code 'kDeviceNotAvailable' |
| 258 vcm->Open(dummy_device); | 259 vcm->Open(dummy_device); |
| 259 | 260 |
| 260 // Wait to check callbacks before removing the listener | 261 // Wait to check callbacks before removing the listener |
| 261 SyncWithVideoCaptureManagerThread(); | 262 SyncWithVideoCaptureManagerThread(); |
| 262 vcm->Unregister(); | 263 vcm->Unregister(); |
| 263 } | 264 } |
| 264 | 265 |
| 265 // Start a device using "magic" id, i.e. call Start without calling Open. | 266 // Start a device using "magic" id, i.e. call Start without calling Open. |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 287 | 288 |
| 288 // Stop shall trigger the Close callback | 289 // Stop shall trigger the Close callback |
| 289 vcm->Stop(media_stream::VideoCaptureManager::kStartOpenSessionId, NULL); | 290 vcm->Stop(media_stream::VideoCaptureManager::kStartOpenSessionId, NULL); |
| 290 | 291 |
| 291 // Wait to check callbacks before removing the listener | 292 // Wait to check callbacks before removing the listener |
| 292 SyncWithVideoCaptureManagerThread(); | 293 SyncWithVideoCaptureManagerThread(); |
| 293 vcm->Unregister(); | 294 vcm->Unregister(); |
| 294 } | 295 } |
| 295 | 296 |
| 296 } // namespace | 297 } // namespace |
| OLD | NEW |