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

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

Issue 2872913003: Do not pass the origin to MediaDevicesDispatcherHost. (Closed)
Patch Set: fix Created 3 years, 7 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_devices_dispatcher_host.h" 5 #include "content/browser/renderer_host/media/media_devices_dispatcher_host.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <queue> 10 #include <queue>
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 kNumFakeVideoDevices, kDefaultVideoDeviceID)); 83 kNumFakeVideoDevices, kDefaultVideoDeviceID));
84 audio_manager_.reset( 84 audio_manager_.reset(
85 new media::MockAudioManager(base::ThreadTaskRunnerHandle::Get())); 85 new media::MockAudioManager(base::ThreadTaskRunnerHandle::Get()));
86 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); 86 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get());
87 media_stream_manager_ = 87 media_stream_manager_ =
88 base::MakeUnique<MediaStreamManager>(audio_system_.get()); 88 base::MakeUnique<MediaStreamManager>(audio_system_.get());
89 89
90 host_ = base::MakeUnique<MediaDevicesDispatcherHost>( 90 host_ = base::MakeUnique<MediaDevicesDispatcherHost>(
91 kProcessId, kRenderId, browser_context_.GetMediaDeviceIDSalt(), 91 kProcessId, kRenderId, browser_context_.GetMediaDeviceIDSalt(),
92 media_stream_manager_.get()); 92 media_stream_manager_.get());
93 host_->SetSecurityOriginForTesting(origin_);
93 } 94 }
94 95
95 void SetUp() override { 96 void SetUp() override {
96 base::RunLoop run_loop; 97 base::RunLoop run_loop;
97 MediaDevicesManager::BoolDeviceTypes devices_to_enumerate; 98 MediaDevicesManager::BoolDeviceTypes devices_to_enumerate;
98 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_INPUT] = true; 99 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_INPUT] = true;
99 devices_to_enumerate[MEDIA_DEVICE_TYPE_VIDEO_INPUT] = true; 100 devices_to_enumerate[MEDIA_DEVICE_TYPE_VIDEO_INPUT] = true;
100 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT] = true; 101 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT] = true;
101 media_stream_manager_->media_devices_manager()->EnumerateDevices( 102 media_stream_manager_->media_devices_manager()->EnumerateDevices(
102 devices_to_enumerate, 103 devices_to_enumerate,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 151
151 void EnumerateDevicesAndWaitForResult(bool enumerate_audio_input, 152 void EnumerateDevicesAndWaitForResult(bool enumerate_audio_input,
152 bool enumerate_video_input, 153 bool enumerate_video_input,
153 bool enumerate_audio_output, 154 bool enumerate_audio_output,
154 bool permission_override_value = true) { 155 bool permission_override_value = true) {
155 host_->SetPermissionChecker(base::MakeUnique<MediaDevicesPermissionChecker>( 156 host_->SetPermissionChecker(base::MakeUnique<MediaDevicesPermissionChecker>(
156 permission_override_value)); 157 permission_override_value));
157 base::RunLoop run_loop; 158 base::RunLoop run_loop;
158 host_->EnumerateDevices( 159 host_->EnumerateDevices(
159 enumerate_audio_input, enumerate_video_input, enumerate_audio_output, 160 enumerate_audio_input, enumerate_video_input, enumerate_audio_output,
160 origin_, base::Bind(&MediaDevicesDispatcherHostTest::DevicesEnumerated, 161 base::Bind(&MediaDevicesDispatcherHostTest::DevicesEnumerated,
161 base::Unretained(this), run_loop.QuitClosure())); 162 base::Unretained(this), run_loop.QuitClosure()));
162 run_loop.Run(); 163 run_loop.Run();
163 164
164 ASSERT_FALSE(enumerated_devices_.empty()); 165 ASSERT_FALSE(enumerated_devices_.empty());
165 if (enumerate_audio_input) 166 if (enumerate_audio_input)
166 EXPECT_FALSE(enumerated_devices_[MEDIA_DEVICE_TYPE_AUDIO_INPUT].empty()); 167 EXPECT_FALSE(enumerated_devices_[MEDIA_DEVICE_TYPE_AUDIO_INPUT].empty());
167 if (enumerate_video_input) 168 if (enumerate_video_input)
168 EXPECT_FALSE(enumerated_devices_[MEDIA_DEVICE_TYPE_VIDEO_INPUT].empty()); 169 EXPECT_FALSE(enumerated_devices_[MEDIA_DEVICE_TYPE_VIDEO_INPUT].empty());
169 if (enumerate_audio_output) 170 if (enumerate_audio_output)
170 EXPECT_FALSE(enumerated_devices_[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT].empty()); 171 EXPECT_FALSE(enumerated_devices_[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT].empty());
171 172
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 if (!DoesNotContainLabels(device_infos)) 250 if (!DoesNotContainLabels(device_infos))
250 return false; 251 return false;
251 } 252 }
252 return true; 253 return true;
253 } 254 }
254 255
255 void SubscribeAndWaitForResult(bool has_permission) { 256 void SubscribeAndWaitForResult(bool has_permission) {
256 host_->SetPermissionChecker( 257 host_->SetPermissionChecker(
257 base::MakeUnique<MediaDevicesPermissionChecker>(has_permission)); 258 base::MakeUnique<MediaDevicesPermissionChecker>(has_permission));
258 uint32_t subscription_id = 0u; 259 uint32_t subscription_id = 0u;
259 uint32_t unique_origin_subscription_id = 1u;
260 url::Origin origin(GURL("http://localhost"));
261 url::Origin unique_origin;
262 for (size_t i = 0; i < NUM_MEDIA_DEVICE_TYPES; ++i) { 260 for (size_t i = 0; i < NUM_MEDIA_DEVICE_TYPES; ++i) {
263 MediaDeviceType type = static_cast<MediaDeviceType>(i); 261 MediaDeviceType type = static_cast<MediaDeviceType>(i);
264 host_->SubscribeDeviceChangeNotifications(type, subscription_id, origin); 262 host_->SubscribeDeviceChangeNotifications(type, subscription_id);
265 MockMediaDevicesListener device_change_listener; 263 MockMediaDevicesListener device_change_listener;
266 host_->SetDeviceChangeListenerForTesting( 264 host_->SetDeviceChangeListenerForTesting(
267 device_change_listener.CreateInterfacePtrAndBind()); 265 device_change_listener.CreateInterfacePtrAndBind());
268 MediaDeviceInfoArray changed_devices; 266 MediaDeviceInfoArray changed_devices;
269 EXPECT_CALL(device_change_listener, 267 EXPECT_CALL(device_change_listener,
270 OnDevicesChanged(type, subscription_id, testing::_)) 268 OnDevicesChanged(type, subscription_id, testing::_))
271 .WillRepeatedly(SaveArg<2>(&changed_devices)); 269 .WillRepeatedly(SaveArg<2>(&changed_devices));
272 // The subscription with unique origin is ignored, so it should not get
273 // notifications.
274 EXPECT_CALL(
275 device_change_listener,
276 OnDevicesChanged(type, unique_origin_subscription_id, testing::_))
277 .Times(0);
278 270
279 // Simulate device-change notification 271 // Simulate device-change notification
280 MediaDeviceInfoArray updated_devices = { 272 MediaDeviceInfoArray updated_devices = {
281 {"fake_device_id", "fake_label", "fake_group"}}; 273 {"fake_device_id", "fake_label", "fake_group"}};
282 host_->OnDevicesChanged(type, updated_devices); 274 host_->OnDevicesChanged(type, updated_devices);
283 base::RunLoop().RunUntilIdle(); 275 base::RunLoop().RunUntilIdle();
284 host_->UnsubscribeDeviceChangeNotifications(type, subscription_id); 276 host_->UnsubscribeDeviceChangeNotifications(type, subscription_id);
285 277
286 if (has_permission) 278 if (has_permission)
287 EXPECT_TRUE(DoesContainLabels(changed_devices)); 279 EXPECT_TRUE(DoesContainLabels(changed_devices));
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 } 341 }
350 342
351 TEST_F(MediaDevicesDispatcherHostTest, SubscribeDeviceChange) { 343 TEST_F(MediaDevicesDispatcherHostTest, SubscribeDeviceChange) {
352 SubscribeAndWaitForResult(true); 344 SubscribeAndWaitForResult(true);
353 } 345 }
354 346
355 TEST_F(MediaDevicesDispatcherHostTest, SubscribeDeviceChangeNoAccess) { 347 TEST_F(MediaDevicesDispatcherHostTest, SubscribeDeviceChangeNoAccess) {
356 SubscribeAndWaitForResult(false); 348 SubscribeAndWaitForResult(false);
357 } 349 }
358 350
359 TEST_F(MediaDevicesDispatcherHostTest, EnumerateAllDevicesUniqueOrigin) {
360 EXPECT_CALL(*this, UniqueOriginCallback(testing::_)).Times(0);
361 host_->EnumerateDevices(
362 true, true, true, url::Origin(),
363 base::Bind(&MediaDevicesDispatcherHostTest::UniqueOriginCallback,
364 base::Unretained(this)));
365 base::RunLoop().RunUntilIdle();
366
367 // Verify that the callback for a valid origin does get called.
368 base::RunLoop run_loop;
369 EXPECT_CALL(*this, ValidOriginCallback(testing::_))
370 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); }));
371 host_->EnumerateDevices(
372 true, true, true, url::Origin(GURL("http://localhost")),
373 base::Bind(&MediaDevicesDispatcherHostTest::ValidOriginCallback,
374 base::Unretained(this)));
375 run_loop.Run();
376 }
377
378 TEST_F(MediaDevicesDispatcherHostTest, GetVideoInputCapabilities) { 351 TEST_F(MediaDevicesDispatcherHostTest, GetVideoInputCapabilities) {
379 base::RunLoop run_loop; 352 base::RunLoop run_loop;
380 EXPECT_CALL(*this, MockVideoInputCapabilitiesCallback()) 353 EXPECT_CALL(*this, MockVideoInputCapabilitiesCallback())
381 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); 354 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); }));
382 host_->GetVideoInputCapabilities( 355 host_->GetVideoInputCapabilities(
383 origin_,
384 base::Bind( 356 base::Bind(
385 &MediaDevicesDispatcherHostTest::VideoInputCapabilitiesCallback, 357 &MediaDevicesDispatcherHostTest::VideoInputCapabilitiesCallback,
386 base::Unretained(this))); 358 base::Unretained(this)));
387 run_loop.Run(); 359 run_loop.Run();
388 } 360 }
389 361
390 TEST_F(MediaDevicesDispatcherHostTest, GetVideoInputCapabilitiesUniqueOrigin) {
391 base::RunLoop run_loop;
392 EXPECT_CALL(*this, MockVideoInputCapabilitiesCallback())
393 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); }));
394 host_->GetVideoInputCapabilities(
395 url::Origin(), base::Bind(&MediaDevicesDispatcherHostTest::
396 VideoInputCapabilitiesUniqueOriginCallback,
397 base::Unretained(this)));
398 run_loop.Run();
399 }
400
401 }; // namespace content 362 }; // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698