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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 const base::Closure& quit_closure) { | 92 const base::Closure& quit_closure) { |
93 quit_closures_.push(quit_closure); | 93 quit_closures_.push(quit_closure); |
94 MediaStreamDispatcherHost::OnOpenDevice( | 94 MediaStreamDispatcherHost::OnOpenDevice( |
95 render_view_id, page_request_id, device_id, type, security_origin); | 95 render_view_id, page_request_id, device_id, type, security_origin); |
96 } | 96 } |
97 | 97 |
98 void OnEnumerateDevices(int render_view_id, | 98 void OnEnumerateDevices(int render_view_id, |
99 int page_request_id, | 99 int page_request_id, |
100 MediaStreamType type, | 100 MediaStreamType type, |
101 const GURL& security_origin, | 101 const GURL& security_origin, |
| 102 bool hide_labels_if_no_access, |
102 const base::Closure& quit_closure) { | 103 const base::Closure& quit_closure) { |
103 quit_closures_.push(quit_closure); | 104 quit_closures_.push(quit_closure); |
104 MediaStreamDispatcherHost::OnEnumerateDevices( | 105 MediaStreamDispatcherHost::OnEnumerateDevices( |
105 render_view_id, page_request_id, type, security_origin); | 106 render_view_id, page_request_id, type, security_origin, |
| 107 hide_labels_if_no_access); |
106 } | 108 } |
107 | 109 |
108 std::string label_; | 110 std::string label_; |
109 StreamDeviceInfoArray audio_devices_; | 111 StreamDeviceInfoArray audio_devices_; |
110 StreamDeviceInfoArray video_devices_; | 112 StreamDeviceInfoArray video_devices_; |
111 StreamDeviceInfo opened_device_; | 113 StreamDeviceInfo opened_device_; |
112 StreamDeviceInfoArray enumerated_devices_; | 114 StreamDeviceInfoArray enumerated_devices_; |
113 | 115 |
114 private: | 116 private: |
115 virtual ~MockMediaStreamDispatcherHost() {} | 117 virtual ~MockMediaStreamDispatcherHost() {} |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 host_->OnOpenDevice(render_view_id, page_request_id, device_id, | 322 host_->OnOpenDevice(render_view_id, page_request_id, device_id, |
321 MEDIA_DEVICE_VIDEO_CAPTURE, origin_, | 323 MEDIA_DEVICE_VIDEO_CAPTURE, origin_, |
322 run_loop.QuitClosure()); | 324 run_loop.QuitClosure()); |
323 run_loop.Run(); | 325 run_loop.Run(); |
324 EXPECT_FALSE(DoesContainRawIds(host_->video_devices_)); | 326 EXPECT_FALSE(DoesContainRawIds(host_->video_devices_)); |
325 EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->video_devices_, origin_)); | 327 EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->video_devices_, origin_)); |
326 } | 328 } |
327 | 329 |
328 void EnumerateDevicesAndWaitForResult(int render_view_id, | 330 void EnumerateDevicesAndWaitForResult(int render_view_id, |
329 int page_request_id, | 331 int page_request_id, |
330 MediaStreamType type) { | 332 MediaStreamType type, |
| 333 bool hide_labels_if_no_access) { |
331 base::RunLoop run_loop; | 334 base::RunLoop run_loop; |
332 host_->OnEnumerateDevices(render_view_id, page_request_id, type, origin_, | 335 host_->OnEnumerateDevices(render_view_id, page_request_id, type, origin_, |
333 run_loop.QuitClosure()); | 336 hide_labels_if_no_access, run_loop.QuitClosure()); |
334 run_loop.Run(); | 337 run_loop.Run(); |
335 ASSERT_FALSE(host_->enumerated_devices_.empty()); | 338 ASSERT_FALSE(host_->enumerated_devices_.empty()); |
336 EXPECT_FALSE(DoesContainRawIds(host_->enumerated_devices_)); | 339 EXPECT_FALSE(DoesContainRawIds(host_->enumerated_devices_)); |
337 EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->enumerated_devices_, origin_)); | 340 EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->enumerated_devices_, origin_)); |
338 } | 341 } |
339 | 342 |
340 bool DoesContainRawIds(const StreamDeviceInfoArray& devices) { | 343 bool DoesContainRawIds(const StreamDeviceInfoArray& devices) { |
341 for (size_t i = 0; i < devices.size(); ++i) { | 344 for (size_t i = 0; i < devices.size(); ++i) { |
342 media::AudioDeviceNames::const_iterator audio_it = | 345 media::AudioDeviceNames::const_iterator audio_it = |
343 physical_audio_devices_.begin(); | 346 physical_audio_devices_.begin(); |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId)) | 874 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId)) |
872 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 875 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
873 media_stream_manager_->OnDevicesChanged( | 876 media_stream_manager_->OnDevicesChanged( |
874 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE); | 877 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE); |
875 | 878 |
876 run_loop.Run(); | 879 run_loop.Run(); |
877 } | 880 } |
878 | 881 |
879 TEST_F(MediaStreamDispatcherHostTest, EnumerateAudioDevices) { | 882 TEST_F(MediaStreamDispatcherHostTest, EnumerateAudioDevices) { |
880 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, | 883 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, |
881 MEDIA_DEVICE_AUDIO_CAPTURE); | 884 MEDIA_DEVICE_AUDIO_CAPTURE, true); |
882 EXPECT_TRUE(DoesContainLabels(host_->enumerated_devices_)); | 885 EXPECT_TRUE(DoesContainLabels(host_->enumerated_devices_)); |
883 } | 886 } |
884 | 887 |
885 TEST_F(MediaStreamDispatcherHostTest, EnumerateVideoDevices) { | 888 TEST_F(MediaStreamDispatcherHostTest, EnumerateVideoDevices) { |
886 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, | 889 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, |
887 MEDIA_DEVICE_VIDEO_CAPTURE); | 890 MEDIA_DEVICE_VIDEO_CAPTURE, true); |
888 EXPECT_TRUE(DoesContainLabels(host_->enumerated_devices_)); | 891 EXPECT_TRUE(DoesContainLabels(host_->enumerated_devices_)); |
889 } | 892 } |
890 | 893 |
891 TEST_F(MediaStreamDispatcherHostTest, EnumerateAudioDevicesNoAccess) { | 894 TEST_F(MediaStreamDispatcherHostTest, EnumerateAudioDevicesNoAccessHideLabels) { |
892 MockResourceContext* mock_resource_context = | 895 MockResourceContext* mock_resource_context = |
893 static_cast<MockResourceContext*>(browser_context_.GetResourceContext()); | 896 static_cast<MockResourceContext*>(browser_context_.GetResourceContext()); |
894 mock_resource_context->set_mic_access(false); | 897 mock_resource_context->set_mic_access(false); |
895 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, | 898 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, |
896 MEDIA_DEVICE_AUDIO_CAPTURE); | 899 MEDIA_DEVICE_AUDIO_CAPTURE, true); |
897 EXPECT_TRUE(DoesNotContainLabels(host_->enumerated_devices_)); | 900 EXPECT_TRUE(DoesNotContainLabels(host_->enumerated_devices_)); |
898 } | 901 } |
899 | 902 |
900 TEST_F(MediaStreamDispatcherHostTest, EnumerateVideoDevicesNoAccess) { | 903 TEST_F(MediaStreamDispatcherHostTest, EnumerateVideoDevicesNoAccessHideLabels) { |
901 MockResourceContext* mock_resource_context = | 904 MockResourceContext* mock_resource_context = |
902 static_cast<MockResourceContext*>(browser_context_.GetResourceContext()); | 905 static_cast<MockResourceContext*>(browser_context_.GetResourceContext()); |
903 mock_resource_context->set_camera_access(false); | 906 mock_resource_context->set_camera_access(false); |
904 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, | 907 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, |
905 MEDIA_DEVICE_VIDEO_CAPTURE); | 908 MEDIA_DEVICE_VIDEO_CAPTURE, true); |
906 EXPECT_TRUE(DoesNotContainLabels(host_->enumerated_devices_)); | 909 EXPECT_TRUE(DoesNotContainLabels(host_->enumerated_devices_)); |
907 } | 910 } |
908 | 911 |
| 912 TEST_F(MediaStreamDispatcherHostTest, |
| 913 EnumerateAudioDevicesNoAccessNoHideLabels) { |
| 914 MockResourceContext* mock_resource_context = |
| 915 static_cast<MockResourceContext*>(browser_context_.GetResourceContext()); |
| 916 mock_resource_context->set_mic_access(false); |
| 917 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, |
| 918 MEDIA_DEVICE_AUDIO_CAPTURE, false); |
| 919 EXPECT_TRUE(DoesContainLabels(host_->enumerated_devices_)); |
| 920 } |
| 921 |
| 922 TEST_F(MediaStreamDispatcherHostTest, |
| 923 EnumerateVideoDevicesNoAccessNoHideLabels) { |
| 924 MockResourceContext* mock_resource_context = |
| 925 static_cast<MockResourceContext*>(browser_context_.GetResourceContext()); |
| 926 mock_resource_context->set_camera_access(false); |
| 927 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, |
| 928 MEDIA_DEVICE_VIDEO_CAPTURE, false); |
| 929 EXPECT_TRUE(DoesContainLabels(host_->enumerated_devices_)); |
| 930 } |
| 931 |
909 }; // namespace content | 932 }; // namespace content |
OLD | NEW |