| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/strings/string_number_conversions.h" | 5 #include "base/strings/string_number_conversions.h" |
| 6 #include "content/browser/renderer_host/media/device_request_message_filter.h" | 6 #include "content/browser/renderer_host/media/device_request_message_filter.h" |
| 7 #include "content/browser/renderer_host/media/media_stream_manager.h" | 7 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 8 #include "content/common/media/media_stream_messages.h" | 8 #include "content/common/media/media_stream_messages.h" |
| 9 #include "content/public/browser/media_device_id.h" | |
| 10 #include "content/public/test/mock_resource_context.h" | 9 #include "content/public/test/mock_resource_context.h" |
| 11 #include "content/public/test/test_browser_thread.h" | 10 #include "content/public/test/test_browser_thread.h" |
| 12 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 13 |
| 15 using ::testing::_; | 14 using ::testing::_; |
| 16 using ::testing::Invoke; | 15 using ::testing::Invoke; |
| 17 | 16 |
| 18 namespace content { | 17 namespace content { |
| 19 | 18 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 // After the video device callback is fired, |message| should be populated. | 110 // After the video device callback is fired, |message| should be populated. |
| 112 EXPECT_CALL(*media_stream_manager_, CancelRequest(kAudioLabel)) | 111 EXPECT_CALL(*media_stream_manager_, CancelRequest(kAudioLabel)) |
| 113 .Times(1); | 112 .Times(1); |
| 114 EXPECT_CALL(*media_stream_manager_, CancelRequest(kVideoLabel)) | 113 EXPECT_CALL(*media_stream_manager_, CancelRequest(kVideoLabel)) |
| 115 .Times(1); | 114 .Times(1); |
| 116 FireVideoDeviceCallback(); | 115 FireVideoDeviceCallback(); |
| 117 EXPECT_EQ(static_cast<size_t>(number_audio_devices + number_video_devices), | 116 EXPECT_EQ(static_cast<size_t>(number_audio_devices + number_video_devices), |
| 118 host_->requested_devices().size()); | 117 host_->requested_devices().size()); |
| 119 | 118 |
| 120 EXPECT_EQ(kRequestId, host_->received_id()); | 119 EXPECT_EQ(kRequestId, host_->received_id()); |
| 121 // Check to make sure no devices have raw ids. | |
| 122 EXPECT_FALSE(DoesContainRawIds(host_->requested_devices())); | |
| 123 | |
| 124 // Check to make sure every GUID produced matches a raw device id. | |
| 125 EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->requested_devices(), origin)); | |
| 126 } | 120 } |
| 127 | 121 |
| 128 bool AreLabelsPresent(MediaStreamType type) { | 122 bool AreLabelsPresent(MediaStreamType type) { |
| 129 const StreamDeviceInfoArray& devices = host_->requested_devices(); | 123 const StreamDeviceInfoArray& devices = host_->requested_devices(); |
| 130 for (size_t i = 0; i < devices.size(); i++) { | 124 for (size_t i = 0; i < devices.size(); i++) { |
| 131 if (devices[i].device.type == type && !devices[i].device.name.empty()) | 125 if (devices[i].device.type == type && !devices[i].device.name.empty()) |
| 132 return true; | 126 return true; |
| 133 } | 127 } |
| 134 return false; | 128 return false; |
| 135 } | 129 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 } | 186 } |
| 193 | 187 |
| 194 void FireAudioDeviceCallback() { | 188 void FireAudioDeviceCallback() { |
| 195 host_->DevicesEnumerated(kAudioLabel, physical_audio_devices_); | 189 host_->DevicesEnumerated(kAudioLabel, physical_audio_devices_); |
| 196 } | 190 } |
| 197 | 191 |
| 198 void FireVideoDeviceCallback() { | 192 void FireVideoDeviceCallback() { |
| 199 host_->DevicesEnumerated(kVideoLabel, physical_video_devices_); | 193 host_->DevicesEnumerated(kVideoLabel, physical_video_devices_); |
| 200 } | 194 } |
| 201 | 195 |
| 202 bool DoesContainRawIds(const StreamDeviceInfoArray& devices) { | |
| 203 for (size_t i = 0; i < devices.size(); i++) { | |
| 204 for (size_t j = 0; j < physical_audio_devices_.size(); ++j) { | |
| 205 if (physical_audio_devices_[j].device.id == devices[i].device.id) | |
| 206 return true; | |
| 207 } | |
| 208 for (size_t j = 0; j < physical_video_devices_.size(); ++j) { | |
| 209 if (physical_video_devices_[j].device.id == devices[i].device.id) | |
| 210 return true; | |
| 211 } | |
| 212 } | |
| 213 return false; | |
| 214 } | |
| 215 | |
| 216 bool DoesEveryDeviceMapToRawId(const StreamDeviceInfoArray& devices, | |
| 217 const GURL& origin) { | |
| 218 for (size_t i = 0; i < devices.size(); i++) { | |
| 219 bool found_match = false; | |
| 220 for (size_t j = 0; j < physical_audio_devices_.size(); ++j) { | |
| 221 if (content::DoesMediaDeviceIDMatchHMAC( | |
| 222 origin, | |
| 223 devices[i].device.id, | |
| 224 physical_audio_devices_[j].device.id)) { | |
| 225 EXPECT_FALSE(found_match); | |
| 226 found_match = true; | |
| 227 } | |
| 228 } | |
| 229 for (size_t j = 0; j < physical_video_devices_.size(); ++j) { | |
| 230 if (content::DoesMediaDeviceIDMatchHMAC( | |
| 231 origin, | |
| 232 devices[i].device.id, | |
| 233 physical_video_devices_[j].device.id)) { | |
| 234 EXPECT_FALSE(found_match); | |
| 235 found_match = true; | |
| 236 } | |
| 237 } | |
| 238 if (!found_match) | |
| 239 return false; | |
| 240 } | |
| 241 return true; | |
| 242 } | |
| 243 | |
| 244 int next_device_id_; | 196 int next_device_id_; |
| 245 }; | 197 }; |
| 246 | 198 |
| 247 TEST_F(DeviceRequestMessageFilterTest, TestGetSources_AudioAndVideoDevices) { | 199 TEST_F(DeviceRequestMessageFilterTest, TestGetSources_AudioAndVideoDevices) { |
| 248 // Runs through test with 1 audio and 1 video device. | 200 // Runs through test with 1 audio and 1 video device. |
| 249 RunTest(1, 1); | 201 RunTest(1, 1); |
| 250 } | 202 } |
| 251 | 203 |
| 252 TEST_F(DeviceRequestMessageFilterTest, | 204 TEST_F(DeviceRequestMessageFilterTest, |
| 253 TestGetSources_MultipleAudioAndVideoDevices) { | 205 TestGetSources_MultipleAudioAndVideoDevices) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 | 248 |
| 297 TEST_F(DeviceRequestMessageFilterTest, TestGetSources_AllowMicAllowCamera) { | 249 TEST_F(DeviceRequestMessageFilterTest, TestGetSources_AllowMicAllowCamera) { |
| 298 resource_context_->set_mic_access(true); | 250 resource_context_->set_mic_access(true); |
| 299 resource_context_->set_camera_access(true); | 251 resource_context_->set_camera_access(true); |
| 300 RunTest(3, 3); | 252 RunTest(3, 3); |
| 301 EXPECT_TRUE(AreLabelsPresent(MEDIA_DEVICE_AUDIO_CAPTURE)); | 253 EXPECT_TRUE(AreLabelsPresent(MEDIA_DEVICE_AUDIO_CAPTURE)); |
| 302 EXPECT_TRUE(AreLabelsPresent(MEDIA_DEVICE_VIDEO_CAPTURE)); | 254 EXPECT_TRUE(AreLabelsPresent(MEDIA_DEVICE_VIDEO_CAPTURE)); |
| 303 } | 255 } |
| 304 | 256 |
| 305 }; // namespace content | 257 }; // namespace content |
| OLD | NEW |