| OLD | NEW | 
|---|
| 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  Loading... | 
| 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       ResourceContext* resource_context) | 55       : MediaStreamDispatcherHost(kProcessId, salt_callback, manager), | 
| 56       : MediaStreamDispatcherHost(kProcessId, salt_callback, manager, |  | 
| 57                                   resource_context), |  | 
| 58         message_loop_(message_loop), | 56         message_loop_(message_loop), | 
| 59         current_ipc_(NULL) {} | 57         current_ipc_(NULL) {} | 
| 60 | 58 | 
| 61   // A list of mock methods. | 59   // A list of mock methods. | 
| 62   MOCK_METHOD4(OnStreamGenerated, | 60   MOCK_METHOD4(OnStreamGenerated, | 
| 63                void(int routing_id, int request_id, int audio_array_size, | 61                void(int routing_id, int request_id, int audio_array_size, | 
| 64                     int video_array_size)); | 62                     int video_array_size)); | 
| 65   MOCK_METHOD3(OnStreamGenerationFailed, void(int routing_id, | 63   MOCK_METHOD3(OnStreamGenerationFailed, void(int routing_id, | 
| 66                                               int request_id, | 64                                               int request_id, | 
| 67                                               MediaStreamRequestResult result)); | 65                                               MediaStreamRequestResult result)); | 
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 225     CommandLine::ForCurrentProcess()->AppendSwitch( | 223     CommandLine::ForCurrentProcess()->AppendSwitch( | 
| 226         switches::kUseFakeDeviceForMediaStream); | 224         switches::kUseFakeDeviceForMediaStream); | 
| 227     // Create our own MediaStreamManager. | 225     // Create our own MediaStreamManager. | 
| 228     media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); | 226     media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); | 
| 229     video_capture_device_factory_ = | 227     video_capture_device_factory_ = | 
| 230         static_cast<media::FakeVideoCaptureDeviceFactory*>( | 228         static_cast<media::FakeVideoCaptureDeviceFactory*>( | 
| 231             media_stream_manager_->video_capture_manager() | 229             media_stream_manager_->video_capture_manager() | 
| 232             ->video_capture_device_factory()); | 230             ->video_capture_device_factory()); | 
| 233     DCHECK(video_capture_device_factory_); | 231     DCHECK(video_capture_device_factory_); | 
| 234 | 232 | 
| 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 |  | 
| 241     host_ = new MockMediaStreamDispatcherHost( | 233     host_ = new MockMediaStreamDispatcherHost( | 
| 242         mock_resource_context->GetMediaDeviceIDSalt(), | 234         browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), | 
| 243         base::MessageLoopProxy::current(), | 235         base::MessageLoopProxy::current(), | 
| 244         media_stream_manager_.get(), | 236         media_stream_manager_.get()); | 
| 245         mock_resource_context); |  | 
| 246 | 237 | 
| 247     // Use the fake content client and browser. | 238     // Use the fake content client and browser. | 
| 248     content_client_.reset(new TestContentClient()); | 239     content_client_.reset(new TestContentClient()); | 
| 249     SetContentClient(content_client_.get()); | 240     SetContentClient(content_client_.get()); | 
| 250     old_browser_client_ = SetBrowserClientForTesting(host_.get()); | 241     old_browser_client_ = SetBrowserClientForTesting(host_.get()); | 
| 251   } | 242   } | 
| 252 | 243 | 
| 253   virtual ~MediaStreamDispatcherHostTest() { | 244   virtual ~MediaStreamDispatcherHostTest() { | 
| 254   } | 245   } | 
| 255 | 246 | 
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 382           EXPECT_FALSE(found_match); | 373           EXPECT_FALSE(found_match); | 
| 383           found_match = true; | 374           found_match = true; | 
| 384         } | 375         } | 
| 385       } | 376       } | 
| 386       if (!found_match) | 377       if (!found_match) | 
| 387         return false; | 378         return false; | 
| 388     } | 379     } | 
| 389     return true; | 380     return true; | 
| 390   } | 381   } | 
| 391 | 382 | 
| 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 |  | 
| 410   void AddSourceIdConstraint(const std::string& source_id, | 383   void AddSourceIdConstraint(const std::string& source_id, | 
| 411                              StreamOptions::Constraints* constraints) { | 384                              StreamOptions::Constraints* constraints) { | 
| 412     constraints->push_back(StreamOptions::Constraint(kMediaStreamSourceInfoId, | 385     constraints->push_back(StreamOptions::Constraint(kMediaStreamSourceInfoId, | 
| 413                                                      source_id)); | 386                                                      source_id)); | 
| 414   } | 387   } | 
| 415 | 388 | 
| 416   scoped_refptr<MockMediaStreamDispatcherHost> host_; | 389   scoped_refptr<MockMediaStreamDispatcherHost> host_; | 
| 417   scoped_ptr<media::AudioManager> audio_manager_; | 390   scoped_ptr<media::AudioManager> audio_manager_; | 
| 418   scoped_ptr<MediaStreamManager> media_stream_manager_; | 391   scoped_ptr<MediaStreamManager> media_stream_manager_; | 
| 419   ContentBrowserClient* old_browser_client_; | 392   ContentBrowserClient* old_browser_client_; | 
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 872       .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 845       .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 
| 873   media_stream_manager_->OnDevicesChanged( | 846   media_stream_manager_->OnDevicesChanged( | 
| 874       base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE); | 847       base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE); | 
| 875 | 848 | 
| 876   run_loop.Run(); | 849   run_loop.Run(); | 
| 877 } | 850 } | 
| 878 | 851 | 
| 879 TEST_F(MediaStreamDispatcherHostTest, EnumerateAudioDevices) { | 852 TEST_F(MediaStreamDispatcherHostTest, EnumerateAudioDevices) { | 
| 880   EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, | 853   EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, | 
| 881                                    MEDIA_DEVICE_AUDIO_CAPTURE); | 854                                    MEDIA_DEVICE_AUDIO_CAPTURE); | 
| 882   EXPECT_TRUE(DoesContainLabels(host_->enumerated_devices_)); |  | 
| 883 } | 855 } | 
| 884 | 856 | 
| 885 TEST_F(MediaStreamDispatcherHostTest, EnumerateVideoDevices) { | 857 TEST_F(MediaStreamDispatcherHostTest, EnumerateVideoDevices) { | 
| 886   EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, | 858   EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, | 
| 887                                    MEDIA_DEVICE_VIDEO_CAPTURE); | 859                                    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_)); |  | 
| 907 } | 860 } | 
| 908 | 861 | 
| 909 };  // namespace content | 862 };  // namespace content | 
| OLD | NEW | 
|---|