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

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

Issue 10912004: Begin adding support for tab mirroring via the MediaStream audio/video capturing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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
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.h" 12 #include "base/message_loop.h"
13 #include "base/process_util.h" 13 #include "base/process_util.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_manager.h" 16 #include "content/browser/renderer_host/media/video_capture_manager.h"
17 #include "content/common/media/media_stream_options.h" 17 #include "content/common/media/media_stream_options.h"
18 #include "content/public/common/media_stream_request.h"
18 #include "media/video/capture/video_capture_device.h" 19 #include "media/video/capture/video_capture_device.h"
19 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 22
22 using ::testing::_; 23 using ::testing::_;
23 using ::testing::AnyNumber; 24 using ::testing::AnyNumber;
24 using ::testing::InSequence; 25 using ::testing::InSequence;
25 using ::testing::Return; 26 using ::testing::Return;
26 using content::BrowserThread; 27 using content::BrowserThread;
27 28
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 public: 77 public:
77 VideoCaptureManagerTest() {} 78 VideoCaptureManagerTest() {}
78 virtual ~VideoCaptureManagerTest() {} 79 virtual ~VideoCaptureManagerTest() {}
79 80
80 protected: 81 protected:
81 virtual void SetUp() OVERRIDE { 82 virtual void SetUp() OVERRIDE {
82 listener_.reset(new media_stream::MockMediaStreamProviderListener()); 83 listener_.reset(new media_stream::MockMediaStreamProviderListener());
83 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO)); 84 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO));
84 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO, 85 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO,
85 message_loop_.get())); 86 message_loop_.get()));
86 vcm_ = new media_stream::VideoCaptureManager(); 87 vcm_ = new media_stream::VideoCaptureManager(
88 content::MEDIA_STREAM_DEVICE_TYPE_USER_VIDEO_CAPTURE);
87 vcm_->UseFakeDevice(); 89 vcm_->UseFakeDevice();
88 vcm_->Register(listener_.get(), message_loop_->message_loop_proxy()); 90 vcm_->Register(listener_.get(), message_loop_->message_loop_proxy());
89 frame_observer_.reset(new MockFrameObserver()); 91 frame_observer_.reset(new MockFrameObserver());
90 } 92 }
91 93
92 virtual void TearDown() OVERRIDE {} 94 virtual void TearDown() OVERRIDE {}
93 95
94 scoped_refptr<media_stream::VideoCaptureManager> vcm_; 96 scoped_refptr<media_stream::VideoCaptureManager> vcm_;
95 scoped_ptr<media_stream::MockMediaStreamProviderListener> listener_; 97 scoped_ptr<media_stream::MockMediaStreamProviderListener> listener_;
96 scoped_ptr<MessageLoop> message_loop_; 98 scoped_ptr<MessageLoop> message_loop_;
97 scoped_ptr<BrowserThreadImpl> io_thread_; 99 scoped_ptr<BrowserThreadImpl> io_thread_;
98 scoped_ptr<MockFrameObserver> frame_observer_; 100 scoped_ptr<MockFrameObserver> frame_observer_;
99 101
100 private: 102 private:
101 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManagerTest); 103 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManagerTest);
102 }; 104 };
103 105
104 // Test cases 106 // Test cases
105 107
106 // Try to open, start, stop and close a device. 108 // Try to open, start, stop and close a device.
107 TEST_F(VideoCaptureManagerTest, CreateAndClose) { 109 TEST_F(VideoCaptureManagerTest, CreateAndClose) {
108 InSequence s; 110 InSequence s;
109 EXPECT_CALL(*listener_, DevicesEnumerated(_)) 111 EXPECT_CALL(*listener_, DevicesEnumerated(_))
110 .Times(1); 112 .Times(1);
111 EXPECT_CALL(*listener_, 113 EXPECT_CALL(*listener_,
112 Opened(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, _)) 114 Opened(content::MEDIA_STREAM_DEVICE_TYPE_USER_VIDEO_CAPTURE, _))
113 .Times(1); 115 .Times(1);
114 EXPECT_CALL(*listener_, 116 EXPECT_CALL(*listener_,
115 Closed(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, _)) 117 Closed(content::MEDIA_STREAM_DEVICE_TYPE_USER_VIDEO_CAPTURE, _))
116 .Times(1); 118 .Times(1);
117 119
118 vcm_->EnumerateDevices(); 120 vcm_->EnumerateDevices();
119 121
120 // Wait to get device callback. 122 // Wait to get device callback.
121 message_loop_->RunAllPending(); 123 message_loop_->RunAllPending();
122 124
123 int video_session_id = vcm_->Open(listener_->devices_.front()); 125 int video_session_id = vcm_->Open(listener_->devices_.front());
124 126
125 media::VideoCaptureParams capture_params; 127 media::VideoCaptureParams capture_params;
(...skipping 10 matching lines...) Expand all
136 message_loop_->RunAllPending(); 138 message_loop_->RunAllPending();
137 vcm_->Unregister(); 139 vcm_->Unregister();
138 } 140 }
139 141
140 // Open the same device twice. 142 // Open the same device twice.
141 TEST_F(VideoCaptureManagerTest, OpenTwice) { 143 TEST_F(VideoCaptureManagerTest, OpenTwice) {
142 InSequence s; 144 InSequence s;
143 EXPECT_CALL(*listener_, DevicesEnumerated(_)) 145 EXPECT_CALL(*listener_, DevicesEnumerated(_))
144 .Times(1); 146 .Times(1);
145 EXPECT_CALL(*listener_, 147 EXPECT_CALL(*listener_,
146 Opened(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, _)) 148 Opened(content::MEDIA_STREAM_DEVICE_TYPE_USER_VIDEO_CAPTURE, _))
147 .Times(2); 149 .Times(2);
148 EXPECT_CALL(*listener_, 150 EXPECT_CALL(*listener_,
149 Closed(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, _)) 151 Closed(content::MEDIA_STREAM_DEVICE_TYPE_USER_VIDEO_CAPTURE, _))
150 .Times(2); 152 .Times(2);
151 153
152 vcm_->EnumerateDevices(); 154 vcm_->EnumerateDevices();
153 155
154 // Wait to get device callback. 156 // Wait to get device callback.
155 message_loop_->RunAllPending(); 157 message_loop_->RunAllPending();
156 158
157 int video_session_id_first = vcm_->Open(listener_->devices_.front()); 159 int video_session_id_first = vcm_->Open(listener_->devices_.front());
158 160
159 // This should trigger an error callback with error code 161 // This should trigger an error callback with error code
160 // 'kDeviceAlreadyInUse'. 162 // 'kDeviceAlreadyInUse'.
161 int video_session_id_second = vcm_->Open(listener_->devices_.front()); 163 int video_session_id_second = vcm_->Open(listener_->devices_.front());
162 EXPECT_NE(video_session_id_first, video_session_id_second); 164 EXPECT_NE(video_session_id_first, video_session_id_second);
163 165
164 vcm_->Close(video_session_id_first); 166 vcm_->Close(video_session_id_first);
165 vcm_->Close(video_session_id_second); 167 vcm_->Close(video_session_id_second);
166 168
167 // Wait to check callbacks before removing the listener. 169 // Wait to check callbacks before removing the listener.
168 message_loop_->RunAllPending(); 170 message_loop_->RunAllPending();
169 vcm_->Unregister(); 171 vcm_->Unregister();
170 } 172 }
171 173
172 // Open two different devices. 174 // Open two different devices.
173 TEST_F(VideoCaptureManagerTest, OpenTwo) { 175 TEST_F(VideoCaptureManagerTest, OpenTwo) {
174 InSequence s; 176 InSequence s;
175 EXPECT_CALL(*listener_, DevicesEnumerated(_)) 177 EXPECT_CALL(*listener_, DevicesEnumerated(_))
176 .Times(1); 178 .Times(1);
177 EXPECT_CALL(*listener_, 179 EXPECT_CALL(*listener_,
178 Opened(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, _)) 180 Opened(content::MEDIA_STREAM_DEVICE_TYPE_USER_VIDEO_CAPTURE, _))
179 .Times(2); 181 .Times(2);
180 EXPECT_CALL(*listener_, 182 EXPECT_CALL(*listener_,
181 Closed(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, _)) 183 Closed(content::MEDIA_STREAM_DEVICE_TYPE_USER_VIDEO_CAPTURE, _))
182 .Times(2); 184 .Times(2);
183 185
184 vcm_->EnumerateDevices(); 186 vcm_->EnumerateDevices();
185 187
186 // Wait to get device callback. 188 // Wait to get device callback.
187 message_loop_->RunAllPending(); 189 message_loop_->RunAllPending();
188 190
189 media_stream::StreamDeviceInfoArray::iterator it = 191 media_stream::StreamDeviceInfoArray::iterator it =
190 listener_->devices_.begin(); 192 listener_->devices_.begin();
191 193
192 int video_session_id_first = vcm_->Open(*it); 194 int video_session_id_first = vcm_->Open(*it);
193 ++it; 195 ++it;
194 int video_session_id_second = vcm_->Open(*it); 196 int video_session_id_second = vcm_->Open(*it);
195 197
196 vcm_->Close(video_session_id_first); 198 vcm_->Close(video_session_id_first);
197 vcm_->Close(video_session_id_second); 199 vcm_->Close(video_session_id_second);
198 200
199 // Wait to check callbacks before removing the listener. 201 // Wait to check callbacks before removing the listener.
200 message_loop_->RunAllPending(); 202 message_loop_->RunAllPending();
201 vcm_->Unregister(); 203 vcm_->Unregister();
202 } 204 }
203 205
204 // Try open a non-existing device. 206 // Try open a non-existing device.
205 TEST_F(VideoCaptureManagerTest, OpenNotExisting) { 207 TEST_F(VideoCaptureManagerTest, OpenNotExisting) {
206 InSequence s; 208 InSequence s;
207 EXPECT_CALL(*listener_, DevicesEnumerated(_)) 209 EXPECT_CALL(*listener_, DevicesEnumerated(_))
208 .Times(1); 210 .Times(1);
209 EXPECT_CALL(*listener_, Error(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, 211 EXPECT_CALL(*listener_,
210 _, media_stream::kDeviceNotAvailable)) 212 Error(content::MEDIA_STREAM_DEVICE_TYPE_USER_VIDEO_CAPTURE,
213 _, media_stream::kDeviceNotAvailable))
211 .Times(1); 214 .Times(1);
212 215
213 vcm_->EnumerateDevices(); 216 vcm_->EnumerateDevices();
214 217
215 // Wait to get device callback. 218 // Wait to get device callback.
216 message_loop_->RunAllPending(); 219 message_loop_->RunAllPending();
217 220
218 media_stream::MediaStreamType stream_type = 221 media_stream::MediaStreamType stream_type =
219 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE; 222 content::MEDIA_STREAM_DEVICE_TYPE_USER_VIDEO_CAPTURE;
220 std::string device_name("device_doesnt_exist"); 223 std::string device_name("device_doesnt_exist");
221 std::string device_id("id_doesnt_exist"); 224 std::string device_id("id_doesnt_exist");
222 media_stream::StreamDeviceInfo dummy_device(stream_type, device_name, 225 media_stream::StreamDeviceInfo dummy_device(stream_type, device_name,
223 device_id, false); 226 device_id, false);
224 227
225 // This should fail with error code 'kDeviceNotAvailable'. 228 // This should fail with error code 'kDeviceNotAvailable'.
226 vcm_->Open(dummy_device); 229 vcm_->Open(dummy_device);
227 230
228 // Wait to check callbacks before removing the listener. 231 // Wait to check callbacks before removing the listener.
229 message_loop_->RunAllPending(); 232 message_loop_->RunAllPending();
230 vcm_->Unregister(); 233 vcm_->Unregister();
231 } 234 }
232 235
233 // Start a device using "magic" id, i.e. call Start without calling Open. 236 // Start a device using "magic" id, i.e. call Start without calling Open.
234 TEST_F(VideoCaptureManagerTest, StartUsingId) { 237 TEST_F(VideoCaptureManagerTest, StartUsingId) {
235 InSequence s; 238 InSequence s;
236 EXPECT_CALL(*listener_, 239 EXPECT_CALL(*listener_,
237 Opened(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, _)) 240 Opened(content::MEDIA_STREAM_DEVICE_TYPE_USER_VIDEO_CAPTURE, _))
238 .Times(1); 241 .Times(1);
239 EXPECT_CALL(*listener_, 242 EXPECT_CALL(*listener_,
240 Closed(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, _)) 243 Closed(content::MEDIA_STREAM_DEVICE_TYPE_USER_VIDEO_CAPTURE, _))
241 .Times(1); 244 .Times(1);
242 245
243 media::VideoCaptureParams capture_params; 246 media::VideoCaptureParams capture_params;
244 capture_params.session_id = 247 capture_params.session_id =
245 media_stream::VideoCaptureManager::kStartOpenSessionId; 248 media_stream::VideoCaptureManager::kStartOpenSessionId;
246 capture_params.width = 320; 249 capture_params.width = 320;
247 capture_params.height = 240; 250 capture_params.height = 240;
248 capture_params.frame_per_second = 30; 251 capture_params.frame_per_second = 30;
249 252
250 // Start shall trigger the Open callback. 253 // Start shall trigger the Open callback.
251 vcm_->Start(capture_params, frame_observer_.get()); 254 vcm_->Start(capture_params, frame_observer_.get());
252 255
253 // Stop shall trigger the Close callback 256 // Stop shall trigger the Close callback
254 vcm_->Stop(media_stream::VideoCaptureManager::kStartOpenSessionId, 257 vcm_->Stop(media_stream::VideoCaptureManager::kStartOpenSessionId,
255 base::Closure()); 258 base::Closure());
256 259
257 // Wait to check callbacks before removing the listener. 260 // Wait to check callbacks before removing the listener.
258 message_loop_->RunAllPending(); 261 message_loop_->RunAllPending();
259 vcm_->Unregister(); 262 vcm_->Unregister();
260 } 263 }
261 264
262 // Open and start a device, close it before calling Stop. 265 // Open and start a device, close it before calling Stop.
263 TEST_F(VideoCaptureManagerTest, CloseWithoutStop) { 266 TEST_F(VideoCaptureManagerTest, CloseWithoutStop) {
264 InSequence s; 267 InSequence s;
265 EXPECT_CALL(*listener_, DevicesEnumerated(_)) 268 EXPECT_CALL(*listener_, DevicesEnumerated(_))
266 .Times(1); 269 .Times(1);
267 EXPECT_CALL(*listener_, 270 EXPECT_CALL(*listener_,
268 Opened(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, _)) 271 Opened(content::MEDIA_STREAM_DEVICE_TYPE_USER_VIDEO_CAPTURE, _))
269 .Times(1); 272 .Times(1);
270 EXPECT_CALL(*listener_, 273 EXPECT_CALL(*listener_,
271 Closed(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, _)) 274 Closed(content::MEDIA_STREAM_DEVICE_TYPE_USER_VIDEO_CAPTURE, _))
272 .Times(1); 275 .Times(1);
273 276
274 vcm_->EnumerateDevices(); 277 vcm_->EnumerateDevices();
275 278
276 // Wait to get device callback. 279 // Wait to get device callback.
277 message_loop_->RunAllPending(); 280 message_loop_->RunAllPending();
278 281
279 int video_session_id = vcm_->Open(listener_->devices_.front()); 282 int video_session_id = vcm_->Open(listener_->devices_.front());
280 283
281 media::VideoCaptureParams capture_params; 284 media::VideoCaptureParams capture_params;
282 capture_params.session_id = video_session_id; 285 capture_params.session_id = video_session_id;
283 capture_params.width = 320; 286 capture_params.width = 320;
284 capture_params.height = 240; 287 capture_params.height = 240;
285 capture_params.frame_per_second = 30; 288 capture_params.frame_per_second = 30;
286 vcm_->Start(capture_params, frame_observer_.get()); 289 vcm_->Start(capture_params, frame_observer_.get());
287 290
288 // Close will stop the running device, an assert will be triggered in 291 // Close will stop the running device, an assert will be triggered in
289 // VideoCaptureManager destructor otherwise. 292 // VideoCaptureManager destructor otherwise.
290 vcm_->Close(video_session_id); 293 vcm_->Close(video_session_id);
291 vcm_->Stop(video_session_id, base::Closure()); 294 vcm_->Stop(video_session_id, base::Closure());
292 295
293 // Wait to check callbacks before removing the listener 296 // Wait to check callbacks before removing the listener
294 message_loop_->RunAllPending(); 297 message_loop_->RunAllPending();
295 vcm_->Unregister(); 298 vcm_->Unregister();
296 } 299 }
297 300
298 } // namespace 301 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698