Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: content/browser/renderer_host/media/video_capture_manager_unittest.cc

Issue 235353002: Extract VideoCaptureDeviceFactory out of VideoCaptureDevice and use for File and FakeVCD. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: perkj@ nit Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/renderer_host/media/video_capture_manager.cc ('k') | media/media.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "content/browser/browser_thread_impl.h" 14 #include "content/browser/browser_thread_impl.h"
15 #include "content/browser/renderer_host/media/media_stream_provider.h" 15 #include "content/browser/renderer_host/media/media_stream_provider.h"
16 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h" 16 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h"
17 #include "content/browser/renderer_host/media/video_capture_manager.h" 17 #include "content/browser/renderer_host/media/video_capture_manager.h"
18 #include "content/common/media/media_stream_options.h" 18 #include "content/common/media/media_stream_options.h"
19 #include "media/video/capture/fake_video_capture_device.h" 19 #include "media/video/capture/fake_video_capture_device_factory.h"
20 #include "media/video/capture/video_capture_device.h"
21 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
22 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
23 22
24 using ::testing::_; 23 using ::testing::_;
25 using ::testing::AnyNumber; 24 using ::testing::AnyNumber;
26 using ::testing::InSequence; 25 using ::testing::InSequence;
27 using ::testing::Return; 26 using ::testing::Return;
28 using ::testing::SaveArg; 27 using ::testing::SaveArg;
29 28
30 namespace content { 29 namespace content {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 public: 71 public:
73 VideoCaptureManagerTest() : next_client_id_(1) {} 72 VideoCaptureManagerTest() : next_client_id_(1) {}
74 virtual ~VideoCaptureManagerTest() {} 73 virtual ~VideoCaptureManagerTest() {}
75 74
76 protected: 75 protected:
77 virtual void SetUp() OVERRIDE { 76 virtual void SetUp() OVERRIDE {
78 listener_.reset(new MockMediaStreamProviderListener()); 77 listener_.reset(new MockMediaStreamProviderListener());
79 message_loop_.reset(new base::MessageLoopForIO); 78 message_loop_.reset(new base::MessageLoopForIO);
80 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO, 79 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO,
81 message_loop_.get())); 80 message_loop_.get()));
82 vcm_ = new VideoCaptureManager(); 81 vcm_ = new VideoCaptureManager(scoped_ptr<media::VideoCaptureDeviceFactory>(
83 vcm_->UseFakeDevice(); 82 new media::FakeVideoCaptureDeviceFactory()));
83 video_capture_device_factory_ =
84 static_cast<media::FakeVideoCaptureDeviceFactory*>(
85 vcm_->video_capture_device_factory());
86 const int32 kNumberOfFakeDevices = 2;
87 video_capture_device_factory_->set_number_of_devices(kNumberOfFakeDevices);
84 vcm_->Register(listener_.get(), message_loop_->message_loop_proxy().get()); 88 vcm_->Register(listener_.get(), message_loop_->message_loop_proxy().get());
85 frame_observer_.reset(new MockFrameObserver()); 89 frame_observer_.reset(new MockFrameObserver());
86 } 90 }
87 91
88 virtual void TearDown() OVERRIDE {} 92 virtual void TearDown() OVERRIDE {}
89 93
90 void OnGotControllerCallback( 94 void OnGotControllerCallback(
91 VideoCaptureControllerID id, 95 VideoCaptureControllerID id,
92 base::Closure quit_closure, 96 base::Closure quit_closure,
93 bool expect_success, 97 bool expect_success,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 controllers_.erase(client_id); 135 controllers_.erase(client_id);
132 } 136 }
133 137
134 int next_client_id_; 138 int next_client_id_;
135 std::map<VideoCaptureControllerID, VideoCaptureController*> controllers_; 139 std::map<VideoCaptureControllerID, VideoCaptureController*> controllers_;
136 scoped_refptr<VideoCaptureManager> vcm_; 140 scoped_refptr<VideoCaptureManager> vcm_;
137 scoped_ptr<MockMediaStreamProviderListener> listener_; 141 scoped_ptr<MockMediaStreamProviderListener> listener_;
138 scoped_ptr<base::MessageLoop> message_loop_; 142 scoped_ptr<base::MessageLoop> message_loop_;
139 scoped_ptr<BrowserThreadImpl> io_thread_; 143 scoped_ptr<BrowserThreadImpl> io_thread_;
140 scoped_ptr<MockFrameObserver> frame_observer_; 144 scoped_ptr<MockFrameObserver> frame_observer_;
145 media::FakeVideoCaptureDeviceFactory* video_capture_device_factory_;
141 146
142 private: 147 private:
143 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManagerTest); 148 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManagerTest);
144 }; 149 };
145 150
146 // Test cases 151 // Test cases
147 152
148 // Try to open, start, stop and close a device. 153 // Try to open, start, stop and close a device.
149 TEST_F(VideoCaptureManagerTest, CreateAndClose) { 154 TEST_F(VideoCaptureManagerTest, CreateAndClose) {
150 StreamDeviceInfoArray devices; 155 StreamDeviceInfoArray devices;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 203
199 // Wait to check callbacks before removing the listener. 204 // Wait to check callbacks before removing the listener.
200 message_loop_->RunUntilIdle(); 205 message_loop_->RunUntilIdle();
201 vcm_->Unregister(); 206 vcm_->Unregister();
202 } 207 }
203 208
204 // Connect and disconnect devices. 209 // Connect and disconnect devices.
205 TEST_F(VideoCaptureManagerTest, ConnectAndDisconnectDevices) { 210 TEST_F(VideoCaptureManagerTest, ConnectAndDisconnectDevices) {
206 StreamDeviceInfoArray devices; 211 StreamDeviceInfoArray devices;
207 int number_of_devices_keep = 212 int number_of_devices_keep =
208 media::FakeVideoCaptureDevice::NumberOfFakeDevices(); 213 video_capture_device_factory_->number_of_devices();
209 214
210 InSequence s; 215 InSequence s;
211 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) 216 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
212 .WillOnce(SaveArg<1>(&devices)); 217 .WillOnce(SaveArg<1>(&devices));
213 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); 218 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE);
214 message_loop_->RunUntilIdle(); 219 message_loop_->RunUntilIdle();
215 ASSERT_EQ(devices.size(), 2u); 220 ASSERT_EQ(devices.size(), 2u);
216 221
217 // Simulate we remove 1 fake device. 222 // Simulate we remove 1 fake device.
218 media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(1); 223 video_capture_device_factory_->set_number_of_devices(1);
219 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) 224 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
220 .WillOnce(SaveArg<1>(&devices)); 225 .WillOnce(SaveArg<1>(&devices));
221 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); 226 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE);
222 message_loop_->RunUntilIdle(); 227 message_loop_->RunUntilIdle();
223 ASSERT_EQ(devices.size(), 1u); 228 ASSERT_EQ(devices.size(), 1u);
224 229
225 // Simulate we add 2 fake devices. 230 // Simulate we add 2 fake devices.
226 media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(3); 231 video_capture_device_factory_->set_number_of_devices(3);
227 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) 232 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
228 .WillOnce(SaveArg<1>(&devices)); 233 .WillOnce(SaveArg<1>(&devices));
229 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); 234 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE);
230 message_loop_->RunUntilIdle(); 235 message_loop_->RunUntilIdle();
231 ASSERT_EQ(devices.size(), 3u); 236 ASSERT_EQ(devices.size(), 3u);
232 237
233 vcm_->Unregister(); 238 vcm_->Unregister();
234 media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(number_of_devices_keep); 239 video_capture_device_factory_->set_number_of_devices(number_of_devices_keep);
235 } 240 }
236 241
237 // Enumerate devices and open the first, then check the list of supported 242 // Enumerate devices and open the first, then check the list of supported
238 // formats. Then start the opened device. The capability list should stay the 243 // formats. Then start the opened device. The capability list should stay the
239 // same. Finally stop the device and check that the capabilities stay unchanged. 244 // same. Finally stop the device and check that the capabilities stay unchanged.
240 TEST_F(VideoCaptureManagerTest, ManipulateDeviceAndCheckCapabilities) { 245 TEST_F(VideoCaptureManagerTest, ManipulateDeviceAndCheckCapabilities) {
241 StreamDeviceInfoArray devices; 246 StreamDeviceInfoArray devices;
242 247
243 // Before enumerating the devices, requesting formats should return false. 248 // Before enumerating the devices, requesting formats should return false.
244 int video_session_id = 0; 249 int video_session_id = 0;
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 454
450 // Wait to check callbacks before removing the listener 455 // Wait to check callbacks before removing the listener
451 message_loop_->RunUntilIdle(); 456 message_loop_->RunUntilIdle();
452 vcm_->Unregister(); 457 vcm_->Unregister();
453 } 458 }
454 459
455 // TODO(mcasas): Add a test to check consolidation of the supported formats 460 // TODO(mcasas): Add a test to check consolidation of the supported formats
456 // provided by the device when http://crbug.com/323913 is closed. 461 // provided by the device when http://crbug.com/323913 is closed.
457 462
458 } // namespace content 463 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/media/video_capture_manager.cc ('k') | media/media.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698