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

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

Issue 2820163002: Move MediaDeviceIDSalt from ProfileIOData to ProfileImpl. (Closed)
Patch Set: merge Created 3 years, 8 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>
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/memory/ptr_util.h"
17 #include "base/run_loop.h" 17 #include "base/run_loop.h"
18 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
19 #include "base/threading/thread_task_runner_handle.h" 19 #include "base/threading/thread_task_runner_handle.h"
20 #include "content/browser/renderer_host/media/media_stream_manager.h" 20 #include "content/browser/renderer_host/media/media_stream_manager.h"
21 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" 21 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h"
22 #include "content/browser/renderer_host/media/video_capture_manager.h" 22 #include "content/browser/renderer_host/media/video_capture_manager.h"
23 #include "content/public/browser/browser_context.h"
23 #include "content/public/browser/media_device_id.h" 24 #include "content/public/browser/media_device_id.h"
24 #include "content/public/test/mock_resource_context.h"
25 #include "content/public/test/test_browser_context.h" 25 #include "content/public/test/test_browser_context.h"
26 #include "content/public/test/test_browser_thread_bundle.h" 26 #include "content/public/test/test_browser_thread_bundle.h"
27 #include "media/audio/audio_device_description.h" 27 #include "media/audio/audio_device_description.h"
28 #include "media/audio/audio_system_impl.h" 28 #include "media/audio/audio_system_impl.h"
29 #include "media/audio/mock_audio_manager.h" 29 #include "media/audio/mock_audio_manager.h"
30 #include "media/base/media_switches.h" 30 #include "media/base/media_switches.h"
31 #include "media/capture/video/fake_video_capture_device_factory.h" 31 #include "media/capture/video/fake_video_capture_device_factory.h"
32 #include "mojo/public/cpp/bindings/binding.h" 32 #include "mojo/public/cpp/bindings/binding.h"
33 #include "testing/gmock/include/gmock/gmock.h" 33 #include "testing/gmock/include/gmock/gmock.h"
34 #include "testing/gtest/include/gtest/gtest.h" 34 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 80 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
81 switches::kUseFakeDeviceForMediaStream, 81 switches::kUseFakeDeviceForMediaStream,
82 base::StringPrintf("device-count=%zu, video-input-default-id=%s", 82 base::StringPrintf("device-count=%zu, video-input-default-id=%s",
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 MockResourceContext* mock_resource_context =
91 static_cast<MockResourceContext*>(
92 browser_context_.GetResourceContext());
93
94 host_ = base::MakeUnique<MediaDevicesDispatcherHost>( 90 host_ = base::MakeUnique<MediaDevicesDispatcherHost>(
95 kProcessId, kRenderId, mock_resource_context->GetMediaDeviceIDSalt(), 91 kProcessId, kRenderId, browser_context_.GetMediaDeviceIDSalt(),
96 media_stream_manager_.get()); 92 media_stream_manager_.get());
97 } 93 }
98 94
99 void SetUp() override { 95 void SetUp() override {
100 base::RunLoop run_loop; 96 base::RunLoop run_loop;
101 MediaDevicesManager::BoolDeviceTypes devices_to_enumerate; 97 MediaDevicesManager::BoolDeviceTypes devices_to_enumerate;
102 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_INPUT] = true; 98 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_INPUT] = true;
103 devices_to_enumerate[MEDIA_DEVICE_TYPE_VIDEO_INPUT] = true; 99 devices_to_enumerate[MEDIA_DEVICE_TYPE_VIDEO_INPUT] = true;
104 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT] = true; 100 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT] = true;
105 media_stream_manager_->media_devices_manager()->EnumerateDevices( 101 media_stream_manager_->media_devices_manager()->EnumerateDevices(
106 devices_to_enumerate, 102 devices_to_enumerate,
107 base::Bind(&PhysicalDevicesEnumerated, run_loop.QuitClosure(), 103 base::Bind(&PhysicalDevicesEnumerated, run_loop.QuitClosure(),
108 &physical_devices_)); 104 &physical_devices_));
109 run_loop.Run(); 105 run_loop.Run();
110 106
111 ASSERT_GT(physical_devices_[MEDIA_DEVICE_TYPE_AUDIO_INPUT].size(), 0u); 107 ASSERT_GT(physical_devices_[MEDIA_DEVICE_TYPE_AUDIO_INPUT].size(), 0u);
112 ASSERT_GT(physical_devices_[MEDIA_DEVICE_TYPE_VIDEO_INPUT].size(), 0u); 108 ASSERT_GT(physical_devices_[MEDIA_DEVICE_TYPE_VIDEO_INPUT].size(), 0u);
113 ASSERT_GT(physical_devices_[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT].size(), 0u); 109 ASSERT_GT(physical_devices_[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT].size(), 0u);
114 } 110 }
115 111
116 MOCK_METHOD1(UniqueOriginCallback, 112 MOCK_METHOD1(UniqueOriginCallback,
117 void(const std::vector<std::vector<MediaDeviceInfo>>&)); 113 void(const std::vector<std::vector<MediaDeviceInfo>>&));
118 MOCK_METHOD1(ValidOriginCallback, 114 MOCK_METHOD1(ValidOriginCallback,
119 void(const std::vector<std::vector<MediaDeviceInfo>>&)); 115 void(const std::vector<std::vector<MediaDeviceInfo>>&));
120 MOCK_METHOD0(MockVideoInputCapabilitiesCallback, void()); 116 MOCK_METHOD0(MockVideoInputCapabilitiesCallback, void());
121 117
122 void VideoInputCapabilitiesCallback( 118 void VideoInputCapabilitiesCallback(
123 std::vector<::mojom::VideoInputDeviceCapabilitiesPtr> capabilities) { 119 std::vector<::mojom::VideoInputDeviceCapabilitiesPtr> capabilities) {
124 MockVideoInputCapabilitiesCallback(); 120 MockVideoInputCapabilitiesCallback();
125 std::string expected_first_device_id = GetHMACForMediaDeviceID( 121 std::string expected_first_device_id =
126 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), origin_, 122 GetHMACForMediaDeviceID(browser_context_.GetMediaDeviceIDSalt(),
127 kDefaultVideoDeviceID); 123 origin_, kDefaultVideoDeviceID);
128 EXPECT_EQ(kNumFakeVideoDevices, capabilities.size()); 124 EXPECT_EQ(kNumFakeVideoDevices, capabilities.size());
129 EXPECT_EQ(expected_first_device_id, capabilities[0]->device_id); 125 EXPECT_EQ(expected_first_device_id, capabilities[0]->device_id);
130 for (const auto& capability : capabilities) { 126 for (const auto& capability : capabilities) {
131 EXPECT_GT(capability->formats.size(), 1u); 127 EXPECT_GT(capability->formats.size(), 1u);
132 EXPECT_GT(capability->formats[0].frame_size.width(), 1); 128 EXPECT_GT(capability->formats[0].frame_size.width(), 1);
133 EXPECT_GT(capability->formats[0].frame_size.height(), 1); 129 EXPECT_GT(capability->formats[0].frame_size.height(), 1);
134 EXPECT_GT(capability->formats[0].frame_rate, 1); 130 EXPECT_GT(capability->formats[0].frame_rate, 1);
135 EXPECT_GT(capability->formats[1].frame_size.width(), 1); 131 EXPECT_GT(capability->formats[1].frame_size.width(), 1);
136 EXPECT_GT(capability->formats[1].frame_size.height(), 1); 132 EXPECT_GT(capability->formats[1].frame_size.height(), 1);
137 EXPECT_GT(capability->formats[1].frame_rate, 1); 133 EXPECT_GT(capability->formats[1].frame_rate, 1);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 } 189 }
194 190
195 bool DoesEveryDeviceMapToRawId( 191 bool DoesEveryDeviceMapToRawId(
196 const std::vector<std::vector<MediaDeviceInfo>>& enumeration, 192 const std::vector<std::vector<MediaDeviceInfo>>& enumeration,
197 const url::Origin& origin) { 193 const url::Origin& origin) {
198 for (size_t i = 0; i < NUM_MEDIA_DEVICE_TYPES; ++i) { 194 for (size_t i = 0; i < NUM_MEDIA_DEVICE_TYPES; ++i) {
199 for (const auto& device_info : enumeration[i]) { 195 for (const auto& device_info : enumeration[i]) {
200 bool found_match = false; 196 bool found_match = false;
201 for (const auto& raw_device_info : physical_devices_[i]) { 197 for (const auto& raw_device_info : physical_devices_[i]) {
202 if (DoesMediaDeviceIDMatchHMAC( 198 if (DoesMediaDeviceIDMatchHMAC(
203 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), 199 browser_context_.GetMediaDeviceIDSalt(), origin,
204 origin, device_info.device_id, raw_device_info.device_id)) { 200 device_info.device_id, raw_device_info.device_id)) {
205 EXPECT_FALSE(found_match); 201 EXPECT_FALSE(found_match);
206 found_match = true; 202 found_match = true;
207 } 203 }
208 } 204 }
209 if (!found_match) 205 if (!found_match)
210 return false; 206 return false;
211 } 207 }
212 } 208 }
213 return true; 209 return true;
214 } 210 }
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); 367 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); }));
372 host_->GetVideoInputCapabilities( 368 host_->GetVideoInputCapabilities(
373 origin_, 369 origin_,
374 base::Bind( 370 base::Bind(
375 &MediaDevicesDispatcherHostTest::VideoInputCapabilitiesCallback, 371 &MediaDevicesDispatcherHostTest::VideoInputCapabilitiesCallback,
376 base::Unretained(this))); 372 base::Unretained(this)));
377 run_loop.Run(); 373 run_loop.Run();
378 } 374 }
379 375
380 }; // namespace content 376 }; // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698