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

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

Issue 2474923002: Fix race in MediaDevicesPermissionChecker. (Closed)
Patch Set: Fix rebase Created 4 years, 1 month 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
« no previous file with comments | « content/browser/renderer_host/media/media_devices_dispatcher_host.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
11 #include <utility> 11 #include <utility>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/memory/ptr_util.h"
16 #include "base/run_loop.h" 17 #include "base/run_loop.h"
17 #include "base/threading/thread_task_runner_handle.h" 18 #include "base/threading/thread_task_runner_handle.h"
18 #include "content/browser/renderer_host/media/media_stream_manager.h" 19 #include "content/browser/renderer_host/media/media_stream_manager.h"
19 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" 20 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h"
20 #include "content/browser/renderer_host/media/video_capture_manager.h" 21 #include "content/browser/renderer_host/media/video_capture_manager.h"
21 #include "content/public/browser/media_device_id.h" 22 #include "content/public/browser/media_device_id.h"
22 #include "content/public/test/mock_resource_context.h" 23 #include "content/public/test/mock_resource_context.h"
23 #include "content/public/test/test_browser_context.h" 24 #include "content/public/test/test_browser_context.h"
24 #include "content/public/test/test_browser_thread_bundle.h" 25 #include "content/public/test/test_browser_thread_bundle.h"
25 #include "media/audio/audio_device_description.h" 26 #include "media/audio/audio_device_description.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 const base::Closure& closure, 109 const base::Closure& closure,
109 const std::vector<std::vector<MediaDeviceInfo>>& devices) { 110 const std::vector<std::vector<MediaDeviceInfo>>& devices) {
110 enumerated_devices_ = devices; 111 enumerated_devices_ = devices;
111 closure.Run(); 112 closure.Run();
112 } 113 }
113 114
114 void EnumerateDevicesAndWaitForResult(bool enumerate_audio_input, 115 void EnumerateDevicesAndWaitForResult(bool enumerate_audio_input,
115 bool enumerate_video_input, 116 bool enumerate_video_input,
116 bool enumerate_audio_output, 117 bool enumerate_audio_output,
117 bool permission_override_value = true) { 118 bool permission_override_value = true) {
118 MediaDevicesPermissionChecker permission_checker; 119 host_->SetPermissionChecker(base::MakeUnique<MediaDevicesPermissionChecker>(
119 permission_checker.OverridePermissionsForTesting(permission_override_value); 120 permission_override_value));
120 host_->SetPermissionChecker(permission_checker);
121 base::RunLoop run_loop; 121 base::RunLoop run_loop;
122 host_->EnumerateDevices( 122 host_->EnumerateDevices(
123 enumerate_audio_input, enumerate_video_input, enumerate_audio_output, 123 enumerate_audio_input, enumerate_video_input, enumerate_audio_output,
124 origin_, base::Bind(&MediaDevicesDispatcherHostTest::DevicesEnumerated, 124 origin_, base::Bind(&MediaDevicesDispatcherHostTest::DevicesEnumerated,
125 base::Unretained(this), run_loop.QuitClosure())); 125 base::Unretained(this), run_loop.QuitClosure()));
126 run_loop.Run(); 126 run_loop.Run();
127 127
128 ASSERT_FALSE(enumerated_devices_.empty()); 128 ASSERT_FALSE(enumerated_devices_.empty());
129 if (enumerate_audio_input) 129 if (enumerate_audio_input)
130 EXPECT_FALSE(enumerated_devices_[MEDIA_DEVICE_TYPE_AUDIO_INPUT].empty()); 130 EXPECT_FALSE(enumerated_devices_[MEDIA_DEVICE_TYPE_AUDIO_INPUT].empty());
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 bool DoesNotContainLabels( 210 bool DoesNotContainLabels(
211 const std::vector<std::vector<MediaDeviceInfo>>& enumeration) { 211 const std::vector<std::vector<MediaDeviceInfo>>& enumeration) {
212 for (const auto& device_infos : enumeration) { 212 for (const auto& device_infos : enumeration) {
213 if (!DoesNotContainLabels(device_infos)) 213 if (!DoesNotContainLabels(device_infos))
214 return false; 214 return false;
215 } 215 }
216 return true; 216 return true;
217 } 217 }
218 218
219 void SubscribeAndWaitForResult(bool has_permission) { 219 void SubscribeAndWaitForResult(bool has_permission) {
220 MediaDevicesPermissionChecker permission_checker; 220 host_->SetPermissionChecker(
221 permission_checker.OverridePermissionsForTesting(has_permission); 221 base::MakeUnique<MediaDevicesPermissionChecker>(has_permission));
222 host_->SetPermissionChecker(permission_checker);
223 uint32_t subscription_id = 0u; 222 uint32_t subscription_id = 0u;
224 url::Origin origin(GURL("http://localhost")); 223 url::Origin origin(GURL("http://localhost"));
225 for (size_t i = 0; i < NUM_MEDIA_DEVICE_TYPES; ++i) { 224 for (size_t i = 0; i < NUM_MEDIA_DEVICE_TYPES; ++i) {
226 MediaDeviceType type = static_cast<MediaDeviceType>(i); 225 MediaDeviceType type = static_cast<MediaDeviceType>(i);
227 host_->SubscribeDeviceChangeNotifications(type, subscription_id, origin); 226 host_->SubscribeDeviceChangeNotifications(type, subscription_id, origin);
228 MockMediaDevicesListener device_change_listener; 227 MockMediaDevicesListener device_change_listener;
229 host_->SetDeviceChangeListenerForTesting( 228 host_->SetDeviceChangeListenerForTesting(
230 device_change_listener.CreateInterfacePtrAndBind()); 229 device_change_listener.CreateInterfacePtrAndBind());
231 MediaDeviceInfoArray changed_devices; 230 MediaDeviceInfoArray changed_devices;
232 EXPECT_CALL(device_change_listener, 231 EXPECT_CALL(device_change_listener,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 300
302 TEST_F(MediaDevicesDispatcherHostTest, SubscribeDeviceChange) { 301 TEST_F(MediaDevicesDispatcherHostTest, SubscribeDeviceChange) {
303 SubscribeAndWaitForResult(true); 302 SubscribeAndWaitForResult(true);
304 } 303 }
305 304
306 TEST_F(MediaDevicesDispatcherHostTest, SubscribeDeviceChangeNoAccess) { 305 TEST_F(MediaDevicesDispatcherHostTest, SubscribeDeviceChangeNoAccess) {
307 SubscribeAndWaitForResult(false); 306 SubscribeAndWaitForResult(false);
308 } 307 }
309 308
310 }; // namespace content 309 }; // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/media/media_devices_dispatcher_host.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698