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

Side by Side Diff: media/audio/audio_system_impl_unittest.cc

Issue 2763383002: Switching AudioInputDeviceManager from using AudioManager interface to AudioSystem one. (Closed)
Patch Set: review comments addressed 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "media/audio/audio_system_impl.h" 5 #include "media/audio/audio_system_impl.h"
6 #include "base/memory/ptr_util.h" 6 #include "base/memory/ptr_util.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/single_thread_task_runner.h" 8 #include "base/single_thread_task_runner.h"
9 #include "base/task_runner_util.h" 9 #include "base/task_runner_util.h"
10 #include "base/threading/thread.h" 10 #include "base/threading/thread.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 } 99 }
100 100
101 void OnGetDeviceDescriptions( 101 void OnGetDeviceDescriptions(
102 const AudioDeviceDescriptions& expected_descriptions, 102 const AudioDeviceDescriptions& expected_descriptions,
103 AudioDeviceDescriptions descriptions) { 103 AudioDeviceDescriptions descriptions) {
104 EXPECT_TRUE(thread_checker_.CalledOnValidThread()); 104 EXPECT_TRUE(thread_checker_.CalledOnValidThread());
105 EXPECT_EQ(expected_descriptions, descriptions); 105 EXPECT_EQ(expected_descriptions, descriptions);
106 DeviceDescriptionsReceived(); 106 DeviceDescriptionsReceived();
107 } 107 }
108 108
109 void OnInputDeviceInfo(const AudioParameters& expected_input,
110 const AudioParameters& expected_associated_output,
111 const std::string& expected_associated_device_id,
112 const AudioParameters& input,
113 const AudioParameters& associated_output,
114 const std::string& associated_device_id) {
115 EXPECT_TRUE(thread_checker_.CalledOnValidThread());
116 EXPECT_EQ(expected_input.AsHumanReadableString(),
117 input.AsHumanReadableString());
118 EXPECT_EQ(expected_associated_output.AsHumanReadableString(),
119 associated_output.AsHumanReadableString());
120 EXPECT_EQ(expected_associated_device_id, associated_device_id);
121 InputDeviceInfoReceived();
122 }
123
109 void WaitForCallback() { 124 void WaitForCallback() {
110 if (!use_audio_thread_) { 125 if (!use_audio_thread_) {
111 base::RunLoop().RunUntilIdle(); 126 base::RunLoop().RunUntilIdle();
112 return; 127 return;
113 } 128 }
114 WaitableMessageLoopEvent event; 129 WaitableMessageLoopEvent event;
115 audio_thread_.task_runner()->PostTaskAndReply( 130 audio_thread_.task_runner()->PostTaskAndReply(
116 FROM_HERE, base::Bind(&base::DoNothing), event.GetClosure()); 131 FROM_HERE, base::Bind(&base::DoNothing), event.GetClosure());
117 // Runs the loop and waits for the |audio_thread_| to call event's closure, 132 // Runs the loop and waits for the |audio_thread_| to call event's closure,
118 // which means AudioSystem reply containing device parameters is already 133 // which means AudioSystem reply containing device parameters is already
119 // queued on the main thread. 134 // queued on the main thread.
120 event.RunAndWait(); 135 event.RunAndWait();
121 base::RunLoop().RunUntilIdle(); 136 base::RunLoop().RunUntilIdle();
122 } 137 }
123 138
124 // Mocks to verify that AudioSystem replied with an expected callback. 139 // Mocks to verify that AudioSystem replied with an expected callback.
125 MOCK_METHOD0(AudioParametersReceived, void(void)); 140 MOCK_METHOD0(AudioParametersReceived, void(void));
126 MOCK_METHOD1(HasInputDevicesCallback, void(bool)); 141 MOCK_METHOD1(HasInputDevicesCallback, void(bool));
127 MOCK_METHOD0(DeviceDescriptionsReceived, void(void)); 142 MOCK_METHOD0(DeviceDescriptionsReceived, void(void));
143 MOCK_METHOD1(AssociatedOutputDeviceIDReceived, void(const std::string&));
144 MOCK_METHOD0(InputDeviceInfoReceived, void(void));
128 145
129 protected: 146 protected:
130 base::MessageLoop message_loop_; 147 base::MessageLoop message_loop_;
131 base::ThreadChecker thread_checker_; 148 base::ThreadChecker thread_checker_;
132 bool use_audio_thread_; 149 bool use_audio_thread_;
133 base::Thread audio_thread_; 150 base::Thread audio_thread_;
134 MockAudioManager::UniquePtr audio_manager_; 151 MockAudioManager::UniquePtr audio_manager_;
135 std::unique_ptr<media::AudioSystem> audio_system_; 152 std::unique_ptr<media::AudioSystem> audio_system_;
136 AudioParameters input_params_; 153 AudioParameters input_params_;
137 AudioParameters output_params_; 154 AudioParameters output_params_;
(...skipping 14 matching lines...) Expand all
152 TEST_P(AudioSystemImplTest, GetInputStreamParametersNoDevice) { 169 TEST_P(AudioSystemImplTest, GetInputStreamParametersNoDevice) {
153 audio_manager_->SetHasInputDevices(false); 170 audio_manager_->SetHasInputDevices(false);
154 EXPECT_CALL(*this, AudioParametersReceived()); 171 EXPECT_CALL(*this, AudioParametersReceived());
155 audio_system_->GetInputStreamParameters( 172 audio_system_->GetInputStreamParameters(
156 media::AudioDeviceDescription::kDefaultDeviceId, 173 media::AudioDeviceDescription::kDefaultDeviceId,
157 base::Bind(&AudioSystemImplTest::OnAudioParams, base::Unretained(this), 174 base::Bind(&AudioSystemImplTest::OnAudioParams, base::Unretained(this),
158 media::AudioParameters())); 175 media::AudioParameters()));
159 WaitForCallback(); 176 WaitForCallback();
160 } 177 }
161 178
162 TEST_P(AudioSystemImplTest, GetStreamParameters) { 179 TEST_P(AudioSystemImplTest, GetOutputStreamParameters) {
163 EXPECT_CALL(*this, AudioParametersReceived()); 180 EXPECT_CALL(*this, AudioParametersReceived());
164 audio_system_->GetOutputStreamParameters( 181 audio_system_->GetOutputStreamParameters(
165 kNonDefaultDeviceId, base::Bind(&AudioSystemImplTest::OnAudioParams, 182 kNonDefaultDeviceId, base::Bind(&AudioSystemImplTest::OnAudioParams,
166 base::Unretained(this), output_params_)); 183 base::Unretained(this), output_params_));
167 WaitForCallback(); 184 WaitForCallback();
168 } 185 }
169 186
170 TEST_P(AudioSystemImplTest, GetDefaultOutputStreamParameters) { 187 TEST_P(AudioSystemImplTest, GetDefaultOutputStreamParameters) {
171 EXPECT_CALL(*this, AudioParametersReceived()); 188 EXPECT_CALL(*this, AudioParametersReceived());
172 audio_system_->GetOutputStreamParameters( 189 audio_system_->GetOutputStreamParameters(
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 EXPECT_EQ(2, static_cast<int>(output_device_descriptions_.size())); 278 EXPECT_EQ(2, static_cast<int>(output_device_descriptions_.size()));
262 EXPECT_EQ(1, static_cast<int>(input_device_descriptions_.size())); 279 EXPECT_EQ(1, static_cast<int>(input_device_descriptions_.size()));
263 EXPECT_CALL(*this, DeviceDescriptionsReceived()); 280 EXPECT_CALL(*this, DeviceDescriptionsReceived());
264 audio_system_->GetDeviceDescriptions( 281 audio_system_->GetDeviceDescriptions(
265 base::Bind(&AudioSystemImplTest::OnGetDeviceDescriptions, 282 base::Bind(&AudioSystemImplTest::OnGetDeviceDescriptions,
266 base::Unretained(this), output_device_descriptions_), 283 base::Unretained(this), output_device_descriptions_),
267 false); 284 false);
268 WaitForCallback(); 285 WaitForCallback();
269 } 286 }
270 287
288 TEST_P(AudioSystemImplTest, GetAssociatedOutputDeviceID) {
289 const std::string associated_id("associated_id");
290 audio_manager_->SetAssociatedOutputDeviceIDCallback(
291 base::Bind([](const std::string& result,
292 const std::string&) -> std::string { return result; },
293 associated_id));
294
295 EXPECT_CALL(*this, AssociatedOutputDeviceIDReceived(associated_id));
296
297 audio_system_->GetAssociatedOutputDeviceID(
298 std::string(),
299 base::Bind(&AudioSystemImplTest::AssociatedOutputDeviceIDReceived,
300 base::Unretained(this)));
301 WaitForCallback();
302 }
303
304 TEST_P(AudioSystemImplTest, GetInputDeviceInfoNoAssociation) {
305 EXPECT_CALL(*this, InputDeviceInfoReceived());
306
307 audio_system_->GetInputDeviceInfo(
308 kNonDefaultDeviceId, base::Bind(&AudioSystemImplTest::OnInputDeviceInfo,
309 base::Unretained(this), input_params_,
310 AudioParameters(), std::string()));
311 WaitForCallback();
312 }
313
314 TEST_P(AudioSystemImplTest, GetInputDeviceInfoWithAssociation) {
315 EXPECT_CALL(*this, InputDeviceInfoReceived());
316
317 const std::string associated_id("associated_id");
318 audio_manager_->SetAssociatedOutputDeviceIDCallback(
319 base::Bind([](const std::string& result,
320 const std::string&) -> std::string { return result; },
321 associated_id));
322
323 audio_system_->GetInputDeviceInfo(
324 kNonDefaultDeviceId, base::Bind(&AudioSystemImplTest::OnInputDeviceInfo,
325 base::Unretained(this), input_params_,
326 output_params_, associated_id));
327 WaitForCallback();
328 }
329
271 INSTANTIATE_TEST_CASE_P(, AudioSystemImplTest, testing::Values(false, true)); 330 INSTANTIATE_TEST_CASE_P(, AudioSystemImplTest, testing::Values(false, true));
272 331
273 } // namespace media 332 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698