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

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

Issue 287383002: Implement getMediaDevices. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 6 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 <string> 5 #include <string>
6 #include <queue> 6 #include <queue>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 const int kPageRequestId = 7; 44 const int kPageRequestId = 7;
45 45
46 namespace content { 46 namespace content {
47 47
48 class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost, 48 class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost,
49 public TestContentBrowserClient { 49 public TestContentBrowserClient {
50 public: 50 public:
51 MockMediaStreamDispatcherHost( 51 MockMediaStreamDispatcherHost(
52 const ResourceContext::SaltCallback salt_callback, 52 const ResourceContext::SaltCallback salt_callback,
53 const scoped_refptr<base::MessageLoopProxy>& message_loop, 53 const scoped_refptr<base::MessageLoopProxy>& message_loop,
54 MediaStreamManager* manager) 54 MediaStreamManager* manager,
55 : MediaStreamDispatcherHost(kProcessId, salt_callback, manager), 55 ResourceContext* resource_context)
56 : MediaStreamDispatcherHost(kProcessId, salt_callback, manager,
57 resource_context),
56 message_loop_(message_loop), 58 message_loop_(message_loop),
57 current_ipc_(NULL) {} 59 current_ipc_(NULL) {}
58 60
59 // A list of mock methods. 61 // A list of mock methods.
60 MOCK_METHOD4(OnStreamGenerated, 62 MOCK_METHOD4(OnStreamGenerated,
61 void(int routing_id, int request_id, int audio_array_size, 63 void(int routing_id, int request_id, int audio_array_size,
62 int video_array_size)); 64 int video_array_size));
63 MOCK_METHOD3(OnStreamGenerationFailed, void(int routing_id, 65 MOCK_METHOD3(OnStreamGenerationFailed, void(int routing_id,
64 int request_id, 66 int request_id,
65 MediaStreamRequestResult result)); 67 MediaStreamRequestResult result));
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 CommandLine::ForCurrentProcess()->AppendSwitch( 225 CommandLine::ForCurrentProcess()->AppendSwitch(
224 switches::kUseFakeDeviceForMediaStream); 226 switches::kUseFakeDeviceForMediaStream);
225 // Create our own MediaStreamManager. 227 // Create our own MediaStreamManager.
226 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); 228 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get()));
227 video_capture_device_factory_ = 229 video_capture_device_factory_ =
228 static_cast<media::FakeVideoCaptureDeviceFactory*>( 230 static_cast<media::FakeVideoCaptureDeviceFactory*>(
229 media_stream_manager_->video_capture_manager() 231 media_stream_manager_->video_capture_manager()
230 ->video_capture_device_factory()); 232 ->video_capture_device_factory());
231 DCHECK(video_capture_device_factory_); 233 DCHECK(video_capture_device_factory_);
232 234
235 MockResourceContext* mock_resource_context =
236 static_cast<MockResourceContext*>(
237 browser_context_.GetResourceContext());
238 mock_resource_context->set_mic_access(true);
239 mock_resource_context->set_camera_access(true);
240
233 host_ = new MockMediaStreamDispatcherHost( 241 host_ = new MockMediaStreamDispatcherHost(
234 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), 242 mock_resource_context->GetMediaDeviceIDSalt(),
235 base::MessageLoopProxy::current(), 243 base::MessageLoopProxy::current(),
236 media_stream_manager_.get()); 244 media_stream_manager_.get(),
245 mock_resource_context);
237 246
238 // Use the fake content client and browser. 247 // Use the fake content client and browser.
239 content_client_.reset(new TestContentClient()); 248 content_client_.reset(new TestContentClient());
240 SetContentClient(content_client_.get()); 249 SetContentClient(content_client_.get());
241 old_browser_client_ = SetBrowserClientForTesting(host_.get()); 250 old_browser_client_ = SetBrowserClientForTesting(host_.get());
242 } 251 }
243 252
244 virtual ~MediaStreamDispatcherHostTest() { 253 virtual ~MediaStreamDispatcherHostTest() {
245 } 254 }
246 255
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 EXPECT_FALSE(found_match); 382 EXPECT_FALSE(found_match);
374 found_match = true; 383 found_match = true;
375 } 384 }
376 } 385 }
377 if (!found_match) 386 if (!found_match)
378 return false; 387 return false;
379 } 388 }
380 return true; 389 return true;
381 } 390 }
382 391
392 // Returns true if all devices have labels, false otherwise.
393 bool DoesContainLabels(const StreamDeviceInfoArray& devices) {
394 for (size_t i = 0; i < devices.size(); ++i) {
395 if (devices[i].device.name.empty())
396 return false;
397 }
398 return true;
399 }
400
401 // Returns true if no devices have labels, false otherwise.
402 bool DoesNotContainLabels(const StreamDeviceInfoArray& devices) {
403 for (size_t i = 0; i < devices.size(); ++i) {
404 if (!devices[i].device.name.empty())
405 return false;
406 }
407 return true;
408 }
409
383 void AddSourceIdConstraint(const std::string& source_id, 410 void AddSourceIdConstraint(const std::string& source_id,
384 StreamOptions::Constraints* constraints) { 411 StreamOptions::Constraints* constraints) {
385 constraints->push_back(StreamOptions::Constraint(kMediaStreamSourceInfoId, 412 constraints->push_back(StreamOptions::Constraint(kMediaStreamSourceInfoId,
386 source_id)); 413 source_id));
387 } 414 }
388 415
389 scoped_refptr<MockMediaStreamDispatcherHost> host_; 416 scoped_refptr<MockMediaStreamDispatcherHost> host_;
390 scoped_ptr<media::AudioManager> audio_manager_; 417 scoped_ptr<media::AudioManager> audio_manager_;
391 scoped_ptr<MediaStreamManager> media_stream_manager_; 418 scoped_ptr<MediaStreamManager> media_stream_manager_;
392 ContentBrowserClient* old_browser_client_; 419 ContentBrowserClient* old_browser_client_;
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 872 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
846 media_stream_manager_->OnDevicesChanged( 873 media_stream_manager_->OnDevicesChanged(
847 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE); 874 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE);
848 875
849 run_loop.Run(); 876 run_loop.Run();
850 } 877 }
851 878
852 TEST_F(MediaStreamDispatcherHostTest, EnumerateAudioDevices) { 879 TEST_F(MediaStreamDispatcherHostTest, EnumerateAudioDevices) {
853 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, 880 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId,
854 MEDIA_DEVICE_AUDIO_CAPTURE); 881 MEDIA_DEVICE_AUDIO_CAPTURE);
882 EXPECT_TRUE(DoesContainLabels(host_->enumerated_devices_));
855 } 883 }
856 884
857 TEST_F(MediaStreamDispatcherHostTest, EnumerateVideoDevices) { 885 TEST_F(MediaStreamDispatcherHostTest, EnumerateVideoDevices) {
858 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, 886 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId,
859 MEDIA_DEVICE_VIDEO_CAPTURE); 887 MEDIA_DEVICE_VIDEO_CAPTURE);
888 EXPECT_TRUE(DoesContainLabels(host_->enumerated_devices_));
889 }
890
891 TEST_F(MediaStreamDispatcherHostTest, EnumerateAudioDevicesNoAccess) {
892 MockResourceContext* mock_resource_context =
893 static_cast<MockResourceContext*>(browser_context_.GetResourceContext());
894 mock_resource_context->set_mic_access(false);
895 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId,
896 MEDIA_DEVICE_AUDIO_CAPTURE);
897 EXPECT_TRUE(DoesNotContainLabels(host_->enumerated_devices_));
898 }
899
900 TEST_F(MediaStreamDispatcherHostTest, EnumerateVideoDevicesNoAccess) {
901 MockResourceContext* mock_resource_context =
902 static_cast<MockResourceContext*>(browser_context_.GetResourceContext());
903 mock_resource_context->set_camera_access(false);
904 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId,
905 MEDIA_DEVICE_VIDEO_CAPTURE);
906 EXPECT_TRUE(DoesNotContainLabels(host_->enumerated_devices_));
860 } 907 }
861 908
862 }; // namespace content 909 }; // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698