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

Side by Side Diff: content/browser/renderer_host/media/video_capture_host_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: Renamed MEDIA_USER_*_CAPTURE to MEDIA_*_DEVICE_CAPTURE, as suggested by wjia@. 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 #include <map> 5 #include <map>
6 #include <string> 6 #include <string>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/process_util.h" 12 #include "base/process_util.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/stringprintf.h" 14 #include "base/stringprintf.h"
15 #include "content/browser/browser_thread_impl.h" 15 #include "content/browser/browser_thread_impl.h"
16 #include "content/browser/renderer_host/media/audio_input_device_manager.h"
17 #include "content/browser/renderer_host/media/media_stream_manager.h" 16 #include "content/browser/renderer_host/media/media_stream_manager.h"
18 #include "content/browser/renderer_host/media/video_capture_host.h" 17 #include "content/browser/renderer_host/media/video_capture_host.h"
19 #include "content/browser/renderer_host/media/video_capture_manager.h" 18 #include "content/browser/renderer_host/media/video_capture_manager.h"
20 #include "content/common/media/video_capture_messages.h" 19 #include "content/common/media/video_capture_messages.h"
20 #include "content/public/common/media_stream_request.h"
21 #include "content/public/test/mock_resource_context.h" 21 #include "content/public/test/mock_resource_context.h"
22 #include "media/audio/audio_manager.h"
23 #include "media/video/capture/video_capture_types.h" 22 #include "media/video/capture/video_capture_types.h"
24 #include "net/url_request/url_request_context.h" 23 #include "net/url_request/url_request_context.h"
25 #include "testing/gmock/include/gmock/gmock.h" 24 #include "testing/gmock/include/gmock/gmock.h"
26 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
27 26
28 using ::testing::_; 27 using ::testing::_;
29 using ::testing::AtLeast; 28 using ::testing::AtLeast;
30 using ::testing::AnyNumber; 29 using ::testing::AnyNumber;
31 using ::testing::DoAll; 30 using ::testing::DoAll;
32 using ::testing::InSequence; 31 using ::testing::InSequence;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 IPC_MESSAGE_HANDLER(VideoCaptureMsg_DeviceInfo, OnDeviceInfoDispatch) 138 IPC_MESSAGE_HANDLER(VideoCaptureMsg_DeviceInfo, OnDeviceInfoDispatch)
140 IPC_MESSAGE_UNHANDLED(handled = false) 139 IPC_MESSAGE_UNHANDLED(handled = false)
141 IPC_END_MESSAGE_MAP() 140 IPC_END_MESSAGE_MAP()
142 EXPECT_TRUE(handled); 141 EXPECT_TRUE(handled);
143 142
144 delete message; 143 delete message;
145 return true; 144 return true;
146 } 145 }
147 146
148 virtual media_stream::VideoCaptureManager* GetVideoCaptureManager() OVERRIDE { 147 virtual media_stream::VideoCaptureManager* GetVideoCaptureManager() OVERRIDE {
149 return manager_->video_capture_manager(); 148 return manager_->GetVideoCaptureManager(
149 content::MEDIA_VIDEO_DEVICE_CAPTURE);
150 } 150 }
151 151
152 // These handler methods do minimal things and delegate to the mock methods. 152 // These handler methods do minimal things and delegate to the mock methods.
153 void OnNewBufferCreatedDispatch(int device_id, 153 void OnNewBufferCreatedDispatch(int device_id,
154 base::SharedMemoryHandle handle, 154 base::SharedMemoryHandle handle,
155 int length, int buffer_id) { 155 int length, int buffer_id) {
156 OnNewBufferCreated(device_id, handle, length, buffer_id); 156 OnNewBufferCreated(device_id, handle, length, buffer_id);
157 base::SharedMemory* dib = new base::SharedMemory(handle, false); 157 base::SharedMemory* dib = new base::SharedMemory(handle, false);
158 dib->Map(length); 158 dib->Map(length);
159 filled_dib_[buffer_id] = dib; 159 filled_dib_[buffer_id] = dib;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 protected: 204 protected:
205 virtual void SetUp() OVERRIDE { 205 virtual void SetUp() OVERRIDE {
206 // Create a message loop so VideoCaptureHostTest can use it. 206 // Create a message loop so VideoCaptureHostTest can use it.
207 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO)); 207 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO));
208 208
209 // MediaStreamManager must be created on the IO thread. 209 // MediaStreamManager must be created on the IO thread.
210 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO, 210 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO,
211 message_loop_.get())); 211 message_loop_.get()));
212 212
213 // Create our own MediaStreamManager. 213 // Create our own MediaStreamManager.
214 audio_manager_.reset(media::AudioManager::Create()); 214 media_stream_manager_.reset(new media_stream::MediaStreamManager());
215 scoped_refptr<media_stream::AudioInputDeviceManager>
216 audio_input_device_manager(
217 new media_stream::AudioInputDeviceManager(audio_manager_.get()));
218 scoped_refptr<media_stream::VideoCaptureManager> video_capture_manager(
219 new media_stream::VideoCaptureManager());
220 media_stream_manager_.reset(new media_stream::MediaStreamManager(
221 audio_input_device_manager, video_capture_manager));
222
223 #ifndef TEST_REAL_CAPTURE_DEVICE 215 #ifndef TEST_REAL_CAPTURE_DEVICE
224 media_stream_manager_->UseFakeDevice(); 216 media_stream_manager_->UseFakeDevice();
225 #endif 217 #endif
226 218
227 host_ = new MockVideoCaptureHost(media_stream_manager_.get()); 219 host_ = new MockVideoCaptureHost(media_stream_manager_.get());
228 220
229 // Simulate IPC channel connected. 221 // Simulate IPC channel connected.
230 host_->OnChannelConnected(base::GetCurrentProcId()); 222 host_->OnChannelConnected(base::GetCurrentProcId());
231 } 223 }
232 224
233 virtual void TearDown() OVERRIDE { 225 virtual void TearDown() OVERRIDE {
234 // Verifies and removes the expectations on host_ and 226 // Verifies and removes the expectations on host_ and
235 // returns true iff successful. 227 // returns true iff successful.
236 Mock::VerifyAndClearExpectations(host_); 228 Mock::VerifyAndClearExpectations(host_);
237 229
238 EXPECT_CALL(*host_, OnStateChanged(kDeviceId, 230 EXPECT_CALL(*host_, OnStateChanged(kDeviceId,
239 video_capture::kStopped)) 231 video_capture::kStopped))
240 .Times(AnyNumber()); 232 .Times(AnyNumber());
241 233
242 // Simulate closing the IPC channel. 234 // Simulate closing the IPC channel.
243 host_->OnChannelClosing(); 235 host_->OnChannelClosing();
244 236
245 // Release the reference to the mock object. The object will be destructed 237 // Release the reference to the mock object. The object will be destructed
246 // on message_loop_. 238 // on message_loop_.
247 host_ = NULL; 239 host_ = NULL;
248 240
249 // We need to continue running message_loop_ to complete all destructions. 241 // We need to continue running message_loop_ to complete all destructions.
250 message_loop_->RunAllPending(); 242 message_loop_->RunAllPending();
251 243
252 // Delete the IO message loop to delete the device thread, 244 // Delete the IO message loop. This will cause the MediaStreamManager to be
253 // AudioInputDeviceManager and VideoCaptureManager. 245 // notified so it will stop its device thread and device managers.
254 message_loop_.reset(); 246 message_loop_.reset();
255 } 247 }
256 248
257 void StartCapture() { 249 void StartCapture() {
258 InSequence s; 250 InSequence s;
259 // 1. First - get info about the new resolution 251 // 1. First - get info about the new resolution
260 EXPECT_CALL(*host_, OnDeviceInfo(kDeviceId)); 252 EXPECT_CALL(*host_, OnDeviceInfo(kDeviceId));
261 253
262 // 2. Change state to started 254 // 2. Change state to started
263 EXPECT_CALL(*host_, OnStateChanged(kDeviceId, 255 EXPECT_CALL(*host_, OnStateChanged(kDeviceId,
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 host_->OnError(id); 337 host_->OnError(id);
346 // Wait for the error callback. 338 // Wait for the error callback.
347 message_loop_->RunAllPending(); 339 message_loop_->RunAllPending();
348 } 340 }
349 341
350 scoped_refptr<MockVideoCaptureHost> host_; 342 scoped_refptr<MockVideoCaptureHost> host_;
351 343
352 private: 344 private:
353 scoped_ptr<MessageLoop> message_loop_; 345 scoped_ptr<MessageLoop> message_loop_;
354 scoped_ptr<BrowserThreadImpl> io_thread_; 346 scoped_ptr<BrowserThreadImpl> io_thread_;
355 scoped_ptr<media::AudioManager> audio_manager_;
356 scoped_ptr<media_stream::MediaStreamManager> media_stream_manager_; 347 scoped_ptr<media_stream::MediaStreamManager> media_stream_manager_;
357 348
358 DISALLOW_COPY_AND_ASSIGN(VideoCaptureHostTest); 349 DISALLOW_COPY_AND_ASSIGN(VideoCaptureHostTest);
359 }; 350 };
360 351
361 TEST_F(VideoCaptureHostTest, StartCapture) { 352 TEST_F(VideoCaptureHostTest, StartCapture) {
362 StartCapture(); 353 StartCapture();
363 } 354 }
364 355
365 TEST_F(VideoCaptureHostTest, StartCapturePlayStop) { 356 TEST_F(VideoCaptureHostTest, StartCapturePlayStop) {
(...skipping 21 matching lines...) Expand all
387 } 378 }
388 379
389 #ifdef DUMP_VIDEO 380 #ifdef DUMP_VIDEO
390 TEST_F(VideoCaptureHostTest, CaptureAndDumpVideoVga) { 381 TEST_F(VideoCaptureHostTest, CaptureAndDumpVideoVga) {
391 CaptureAndDumpVideo(640, 480, 30); 382 CaptureAndDumpVideo(640, 480, 30);
392 } 383 }
393 TEST_F(VideoCaptureHostTest, CaptureAndDump720P) { 384 TEST_F(VideoCaptureHostTest, CaptureAndDump720P) {
394 CaptureAndDumpVideo(1280, 720, 30); 385 CaptureAndDumpVideo(1280, 720, 30);
395 } 386 }
396 #endif 387 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698