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

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

Issue 2800493002: [Mojo Video Capture] Create abstraction VideoCaptureProvider (Closed)
Patch Set: Incorporated suggestions from PatchSet 2 Created 3 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
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 "content/browser/renderer_host/media/media_stream_dispatcher_host.h" 5 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <memory> 8 #include <memory>
9 #include <queue> 9 #include <queue>
10 #include <string> 10 #include <string>
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 }; 230 };
231 231
232 class MockMediaStreamUIProxy : public FakeMediaStreamUIProxy { 232 class MockMediaStreamUIProxy : public FakeMediaStreamUIProxy {
233 public: 233 public:
234 MOCK_METHOD2( 234 MOCK_METHOD2(
235 OnStarted, 235 OnStarted,
236 void(const base::Closure& stop, 236 void(const base::Closure& stop,
237 const MediaStreamUIProxy::WindowIdCallback& window_id_callback)); 237 const MediaStreamUIProxy::WindowIdCallback& window_id_callback));
238 }; 238 };
239 239
240 class MockVideoCaptureSystem : public media::VideoCaptureSystem { 240 class MockVideoCaptureProvider : public VideoCaptureProvider {
241 public: 241 public:
242 MOCK_METHOD1(GetDeviceInfosAsync, 242 MOCK_METHOD1(GetDeviceInfosAsync,
243 void(const base::Callback< 243 void(const base::Callback<
244 void(const std::vector<media::VideoCaptureDeviceInfo>&)>& 244 void(const std::vector<media::VideoCaptureDeviceInfo>&)>&
245 result_callback)); 245 result_callback));
246 246
247 MOCK_METHOD1( 247 MOCK_METHOD2(CreateBuildableDevice,
248 CreateDevice, 248 std::unique_ptr<BuildableVideoCaptureDevice>(
249 std::unique_ptr<media::VideoCaptureDevice>(const std::string& device_id)); 249 const std::string& device_id,
250 MediaStreamType stream_type));
250 }; 251 };
251 252
252 class MediaStreamDispatcherHostTest : public testing::Test { 253 class MediaStreamDispatcherHostTest : public testing::Test {
253 public: 254 public:
254 MediaStreamDispatcherHostTest() 255 MediaStreamDispatcherHostTest()
255 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), 256 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
256 old_browser_client_(NULL), 257 old_browser_client_(NULL),
257 origin_(GURL("https://test.com")) { 258 origin_(GURL("https://test.com")) {
258 audio_manager_.reset( 259 audio_manager_.reset(
259 new media::MockAudioManager(base::ThreadTaskRunnerHandle::Get())); 260 new media::MockAudioManager(base::ThreadTaskRunnerHandle::Get()));
260 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); 261 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get());
261 // Make sure we use fake devices to avoid long delays. 262 // Make sure we use fake devices to avoid long delays.
262 base::CommandLine::ForCurrentProcess()->AppendSwitch( 263 base::CommandLine::ForCurrentProcess()->AppendSwitch(
263 switches::kUseFakeDeviceForMediaStream); 264 switches::kUseFakeDeviceForMediaStream);
264 auto mock_video_capture_system = base::MakeUnique<MockVideoCaptureSystem>(); 265 auto mock_video_capture_provider =
265 mock_video_capture_system_ = mock_video_capture_system.get(); 266 base::MakeUnique<MockVideoCaptureProvider>();
267 mock_video_capture_provider_ = mock_video_capture_provider.get();
266 // Create our own MediaStreamManager. 268 // Create our own MediaStreamManager.
267 media_stream_manager_ = base::MakeUnique<MediaStreamManager>( 269 media_stream_manager_ = base::MakeUnique<MediaStreamManager>(
268 audio_system_.get(), std::move(mock_video_capture_system), 270 audio_system_.get(), std::move(mock_video_capture_provider));
269 base::ThreadTaskRunnerHandle::Get());
270 271
271 MockResourceContext* mock_resource_context = 272 MockResourceContext* mock_resource_context =
272 static_cast<MockResourceContext*>( 273 static_cast<MockResourceContext*>(
273 browser_context_.GetResourceContext()); 274 browser_context_.GetResourceContext());
274 275
275 host_ = new MockMediaStreamDispatcherHost( 276 host_ = new MockMediaStreamDispatcherHost(
276 mock_resource_context->GetMediaDeviceIDSalt(), 277 mock_resource_context->GetMediaDeviceIDSalt(),
277 base::ThreadTaskRunnerHandle::Get(), media_stream_manager_.get()); 278 base::ThreadTaskRunnerHandle::Get(), media_stream_manager_.get());
278 279
279 // Use the fake content client and browser. 280 // Use the fake content client and browser.
280 content_client_.reset(new TestContentClient()); 281 content_client_.reset(new TestContentClient());
281 SetContentClient(content_client_.get()); 282 SetContentClient(content_client_.get());
282 old_browser_client_ = SetBrowserClientForTesting(host_.get()); 283 old_browser_client_ = SetBrowserClientForTesting(host_.get());
283 284
284 #if defined(OS_CHROMEOS) 285 #if defined(OS_CHROMEOS)
285 chromeos::CrasAudioHandler::InitializeForTesting(); 286 chromeos::CrasAudioHandler::InitializeForTesting();
286 #endif 287 #endif
287 } 288 }
288 289
289 ~MediaStreamDispatcherHostTest() override { 290 ~MediaStreamDispatcherHostTest() override {
290 #if defined(OS_CHROMEOS) 291 #if defined(OS_CHROMEOS)
291 chromeos::CrasAudioHandler::Shutdown(); 292 chromeos::CrasAudioHandler::Shutdown();
292 #endif 293 #endif
293 } 294 }
294 295
295 void SetUp() override { 296 void SetUp() override {
296 stub_video_device_ids_.emplace_back(kRegularVideoDeviceId); 297 stub_video_device_ids_.emplace_back(kRegularVideoDeviceId);
297 stub_video_device_ids_.emplace_back(kDepthVideoDeviceId); 298 stub_video_device_ids_.emplace_back(kDepthVideoDeviceId);
298 ON_CALL(*mock_video_capture_system_, GetDeviceInfosAsync(_)) 299 ON_CALL(*mock_video_capture_provider_, GetDeviceInfosAsync(_))
299 .WillByDefault(Invoke( 300 .WillByDefault(Invoke(
300 [this](const base::Callback<void( 301 [this](const base::Callback<void(
301 const std::vector<media::VideoCaptureDeviceInfo>&)>& 302 const std::vector<media::VideoCaptureDeviceInfo>&)>&
302 result_callback) { 303 result_callback) {
303 std::vector<media::VideoCaptureDeviceInfo> result; 304 std::vector<media::VideoCaptureDeviceInfo> result;
304 for (const auto& device_id : stub_video_device_ids_) { 305 for (const auto& device_id : stub_video_device_ids_) {
305 media::VideoCaptureDeviceInfo info; 306 media::VideoCaptureDeviceInfo info;
306 info.descriptor.device_id = device_id; 307 info.descriptor.device_id = device_id;
307 info.descriptor.capture_api = kStubCaptureApi; 308 info.descriptor.capture_api = kStubCaptureApi;
308 if (device_id == kDepthVideoDeviceId) { 309 if (device_id == kDepthVideoDeviceId) {
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 std::unique_ptr<media::AudioManager, media::AudioManagerDeleter> 467 std::unique_ptr<media::AudioManager, media::AudioManagerDeleter>
467 audio_manager_; 468 audio_manager_;
468 std::unique_ptr<media::AudioSystem> audio_system_; 469 std::unique_ptr<media::AudioSystem> audio_system_;
469 MockMediaStreamUIProxy* stream_ui_; 470 MockMediaStreamUIProxy* stream_ui_;
470 ContentBrowserClient* old_browser_client_; 471 ContentBrowserClient* old_browser_client_;
471 std::unique_ptr<ContentClient> content_client_; 472 std::unique_ptr<ContentClient> content_client_;
472 content::TestBrowserContext browser_context_; 473 content::TestBrowserContext browser_context_;
473 media::AudioDeviceDescriptions audio_device_descriptions_; 474 media::AudioDeviceDescriptions audio_device_descriptions_;
474 std::vector<std::string> stub_video_device_ids_; 475 std::vector<std::string> stub_video_device_ids_;
475 url::Origin origin_; 476 url::Origin origin_;
476 MockVideoCaptureSystem* mock_video_capture_system_; 477 MockVideoCaptureProvider* mock_video_capture_provider_;
477 }; 478 };
478 479
479 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithVideoOnly) { 480 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithVideoOnly) {
480 StreamControls controls(false, true); 481 StreamControls controls(false, true);
481 482
482 SetupFakeUI(true); 483 SetupFakeUI(true);
483 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); 484 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls);
484 485
485 EXPECT_EQ(host_->audio_devices_.size(), 0u); 486 EXPECT_EQ(host_->audio_devices_.size(), 0u);
486 EXPECT_EQ(host_->video_devices_.size(), 1u); 487 EXPECT_EQ(host_->video_devices_.size(), 1u);
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 base::RunLoop run_loop; 881 base::RunLoop run_loop;
881 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId)) 882 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId))
882 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 883 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
883 media_stream_manager_->media_devices_manager()->OnDevicesChanged( 884 media_stream_manager_->media_devices_manager()->OnDevicesChanged(
884 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE); 885 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE);
885 886
886 run_loop.Run(); 887 run_loop.Run();
887 } 888 }
888 889
889 }; // namespace content 890 }; // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698