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

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

Issue 29423003: Added video capture capabilities retrieval and caching to VideoCaptureManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Defensive programming - against race conditions, id's not found, vectors that self-release etc. Created 7 years, 1 month 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
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"
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 VideoCaptureControllerID client_id = StartClient(video_session_id, true); 154 VideoCaptureControllerID client_id = StartClient(video_session_id, true);
155 155
156 StopClient(client_id); 156 StopClient(client_id);
157 vcm_->Close(video_session_id); 157 vcm_->Close(video_session_id);
158 158
159 // Wait to check callbacks before removing the listener. 159 // Wait to check callbacks before removing the listener.
160 message_loop_->RunUntilIdle(); 160 message_loop_->RunUntilIdle();
161 vcm_->Unregister(); 161 vcm_->Unregister();
162 } 162 }
163 163
164 // Open the same device twice. 164 // Enumerate devices and open the first, then check the capabilities. Then start
165 TEST_F(VideoCaptureManagerTest, OpenTwice) { 165 // the opened device. The capability list should be reduced to just one format,
166 // and this should be the one used when configuring-starting the device. Finally
167 // stop the device and check that the capabilities have been restored.
168 TEST_F(VideoCaptureManagerTest, ManipulateDeviceAndCheckCapabilities) {
166 StreamDeviceInfoArray devices; 169 StreamDeviceInfoArray devices;
167 170
168 InSequence s; 171 InSequence s;
169 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) 172 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
170 .Times(1).WillOnce(SaveArg<1>(&devices)); 173 .Times(1)
171 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); 174 .WillOnce(SaveArg<1>(&devices));
172 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2);
173
174 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); 175 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE);
175
176 // Wait to get device callback.
177 message_loop_->RunUntilIdle(); 176 message_loop_->RunUntilIdle();
178 177
179 int video_session_id_first = vcm_->Open(devices.front()); 178 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(1);
179 int video_session_id = vcm_->Open(devices.front());
180 message_loop_->RunUntilIdle();
180 181
181 // This should trigger an error callback with error code 182 // When the device has been opened, we should see all the devices'
182 // 'kDeviceAlreadyInUse'. 183 // capabilities.
183 int video_session_id_second = vcm_->Open(devices.front()); 184 media::VideoCaptureCapabilities device_capabilities;
184 EXPECT_NE(video_session_id_first, video_session_id_second); 185 vcm_->GetDeviceCapabilities(video_session_id, device_capabilities);
186 ASSERT_EQ(device_capabilities.size(), 2u);
187 media::VideoCaptureCapabilities::const_iterator format;
188 EXPECT_EQ(device_capabilities[0].width, 640);
189 EXPECT_EQ(device_capabilities[0].height, 480);
190 EXPECT_EQ(device_capabilities[0].frame_rate, 20);
191 EXPECT_EQ(device_capabilities[1].width, 320);
192 EXPECT_EQ(device_capabilities[1].height, 240);
193 EXPECT_EQ(device_capabilities[1].frame_rate, 20);
185 194
186 vcm_->Close(video_session_id_first); 195 VideoCaptureControllerID client_id = StartClient(video_session_id, true);
187 vcm_->Close(video_session_id_second); 196 message_loop_->RunUntilIdle();
197 // After StartClient(), the device's list of capabilities should be reduced
198 // to one, coinciding with the configured inside that method: 320x240@30fps.
199 vcm_->GetDeviceCapabilities(video_session_id, device_capabilities);
200 ASSERT_EQ(device_capabilities.size(), 1u);
201 EXPECT_EQ(device_capabilities[0].width, 320);
202 EXPECT_EQ(device_capabilities[0].height, 240);
203 EXPECT_EQ(device_capabilities[0].frame_rate, 30);
188 204
189 // Wait to check callbacks before removing the listener. 205 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(1);
206 StopClient(client_id);
207 message_loop_->RunUntilIdle();
208 // After StopClient(), the device's list of capabilities should be restored
209 // to the original one.
210 vcm_->GetDeviceCapabilities(video_session_id, device_capabilities);
211 ASSERT_EQ(device_capabilities.size(), 2u);
212 EXPECT_EQ(device_capabilities[0].width, 640);
213 EXPECT_EQ(device_capabilities[0].height, 480);
214 EXPECT_EQ(device_capabilities[0].frame_rate, 20);
215 EXPECT_EQ(device_capabilities[1].width, 320);
216 EXPECT_EQ(device_capabilities[1].height, 240);
217 EXPECT_EQ(device_capabilities[1].frame_rate, 20);
218
219 vcm_->Close(video_session_id);
190 message_loop_->RunUntilIdle(); 220 message_loop_->RunUntilIdle();
191 vcm_->Unregister(); 221 vcm_->Unregister();
192 } 222 }
193 223
194 // Open two different devices. 224 // Open two different devices.
195 TEST_F(VideoCaptureManagerTest, OpenTwo) { 225 TEST_F(VideoCaptureManagerTest, OpenTwo) {
196 StreamDeviceInfoArray devices; 226 StreamDeviceInfoArray devices;
197 227
198 InSequence s; 228 InSequence s;
199 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) 229 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 // VideoCaptureManager destructor otherwise. 315 // VideoCaptureManager destructor otherwise.
286 vcm_->Close(video_session_id); 316 vcm_->Close(video_session_id);
287 StopClient(client_id); 317 StopClient(client_id);
288 318
289 // Wait to check callbacks before removing the listener 319 // Wait to check callbacks before removing the listener
290 message_loop_->RunUntilIdle(); 320 message_loop_->RunUntilIdle();
291 vcm_->Unregister(); 321 vcm_->Unregister();
292 } 322 }
293 323
294 } // namespace content 324 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698