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

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: rebase 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
« no previous file with comments | « media/audio/audio_system_impl.cc ('k') | media/audio/mock_audio_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 } 104 }
105 105
106 void OnGetDeviceDescriptions( 106 void OnGetDeviceDescriptions(
107 const AudioDeviceDescriptions& expected_descriptions, 107 const AudioDeviceDescriptions& expected_descriptions,
108 AudioDeviceDescriptions descriptions) { 108 AudioDeviceDescriptions descriptions) {
109 EXPECT_TRUE(thread_checker_.CalledOnValidThread()); 109 EXPECT_TRUE(thread_checker_.CalledOnValidThread());
110 EXPECT_EQ(expected_descriptions, descriptions); 110 EXPECT_EQ(expected_descriptions, descriptions);
111 DeviceDescriptionsReceived(); 111 DeviceDescriptionsReceived();
112 } 112 }
113 113
114 void OnInputDeviceInfo(const AudioParameters& expected_input,
115 const AudioParameters& expected_associated_output,
116 const std::string& expected_associated_device_id,
117 const AudioParameters& input,
118 const AudioParameters& associated_output,
119 const std::string& associated_device_id) {
120 EXPECT_TRUE(thread_checker_.CalledOnValidThread());
121 EXPECT_EQ(expected_input.AsHumanReadableString(),
122 input.AsHumanReadableString());
123 EXPECT_EQ(expected_associated_output.AsHumanReadableString(),
124 associated_output.AsHumanReadableString());
125 EXPECT_EQ(expected_associated_device_id, associated_device_id);
126 InputDeviceInfoReceived();
127 }
128
114 void WaitForCallback() { 129 void WaitForCallback() {
115 if (!use_audio_thread_) { 130 if (!use_audio_thread_) {
116 base::RunLoop().RunUntilIdle(); 131 base::RunLoop().RunUntilIdle();
117 return; 132 return;
118 } 133 }
119 WaitableMessageLoopEvent event; 134 WaitableMessageLoopEvent event;
120 audio_thread_.task_runner()->PostTaskAndReply( 135 audio_thread_.task_runner()->PostTaskAndReply(
121 FROM_HERE, base::Bind(&base::DoNothing), event.GetClosure()); 136 FROM_HERE, base::Bind(&base::DoNothing), event.GetClosure());
122 // Runs the loop and waits for the |audio_thread_| to call event's closure, 137 // Runs the loop and waits for the |audio_thread_| to call event's closure,
123 // which means AudioSystem reply containing device parameters is already 138 // which means AudioSystem reply containing device parameters is already
124 // queued on the main thread. 139 // queued on the main thread.
125 event.RunAndWait(); 140 event.RunAndWait();
126 base::RunLoop().RunUntilIdle(); 141 base::RunLoop().RunUntilIdle();
127 } 142 }
128 143
129 // Mocks to verify that AudioSystem replied with an expected callback. 144 // Mocks to verify that AudioSystem replied with an expected callback.
130 MOCK_METHOD0(AudioParametersReceived, void(void)); 145 MOCK_METHOD0(AudioParametersReceived, void(void));
131 MOCK_METHOD1(HasInputDevicesCallback, void(bool)); 146 MOCK_METHOD1(HasInputDevicesCallback, void(bool));
132 MOCK_METHOD1(HasOutputDevicesCallback, void(bool)); 147 MOCK_METHOD1(HasOutputDevicesCallback, void(bool));
133 MOCK_METHOD0(DeviceDescriptionsReceived, void(void)); 148 MOCK_METHOD0(DeviceDescriptionsReceived, void(void));
149 MOCK_METHOD1(AssociatedOutputDeviceIDReceived, void(const std::string&));
150 MOCK_METHOD0(InputDeviceInfoReceived, void(void));
134 151
135 protected: 152 protected:
136 base::MessageLoop message_loop_; 153 base::MessageLoop message_loop_;
137 base::ThreadChecker thread_checker_; 154 base::ThreadChecker thread_checker_;
138 bool use_audio_thread_; 155 bool use_audio_thread_;
139 base::Thread audio_thread_; 156 base::Thread audio_thread_;
140 MockAudioManager::UniquePtr audio_manager_; 157 MockAudioManager::UniquePtr audio_manager_;
141 std::unique_ptr<media::AudioSystem> audio_system_; 158 std::unique_ptr<media::AudioSystem> audio_system_;
142 AudioParameters input_params_; 159 AudioParameters input_params_;
143 AudioParameters output_params_; 160 AudioParameters output_params_;
(...skipping 14 matching lines...) Expand all
158 TEST_P(AudioSystemImplTest, GetInputStreamParametersNoDevice) { 175 TEST_P(AudioSystemImplTest, GetInputStreamParametersNoDevice) {
159 audio_manager_->SetHasInputDevices(false); 176 audio_manager_->SetHasInputDevices(false);
160 EXPECT_CALL(*this, AudioParametersReceived()); 177 EXPECT_CALL(*this, AudioParametersReceived());
161 audio_system_->GetInputStreamParameters( 178 audio_system_->GetInputStreamParameters(
162 media::AudioDeviceDescription::kDefaultDeviceId, 179 media::AudioDeviceDescription::kDefaultDeviceId,
163 base::Bind(&AudioSystemImplTest::OnAudioParams, base::Unretained(this), 180 base::Bind(&AudioSystemImplTest::OnAudioParams, base::Unretained(this),
164 media::AudioParameters())); 181 media::AudioParameters()));
165 WaitForCallback(); 182 WaitForCallback();
166 } 183 }
167 184
168 TEST_P(AudioSystemImplTest, GetStreamParameters) { 185 TEST_P(AudioSystemImplTest, GetOutputStreamParameters) {
169 EXPECT_CALL(*this, AudioParametersReceived()); 186 EXPECT_CALL(*this, AudioParametersReceived());
170 audio_system_->GetOutputStreamParameters( 187 audio_system_->GetOutputStreamParameters(
171 kNonDefaultDeviceId, base::Bind(&AudioSystemImplTest::OnAudioParams, 188 kNonDefaultDeviceId, base::Bind(&AudioSystemImplTest::OnAudioParams,
172 base::Unretained(this), output_params_)); 189 base::Unretained(this), output_params_));
173 WaitForCallback(); 190 WaitForCallback();
174 } 191 }
175 192
176 TEST_P(AudioSystemImplTest, GetDefaultOutputStreamParameters) { 193 TEST_P(AudioSystemImplTest, GetDefaultOutputStreamParameters) {
177 EXPECT_CALL(*this, AudioParametersReceived()); 194 EXPECT_CALL(*this, AudioParametersReceived());
178 audio_system_->GetOutputStreamParameters( 195 audio_system_->GetOutputStreamParameters(
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 EXPECT_EQ(2, static_cast<int>(output_device_descriptions_.size())); 299 EXPECT_EQ(2, static_cast<int>(output_device_descriptions_.size()));
283 EXPECT_EQ(1, static_cast<int>(input_device_descriptions_.size())); 300 EXPECT_EQ(1, static_cast<int>(input_device_descriptions_.size()));
284 EXPECT_CALL(*this, DeviceDescriptionsReceived()); 301 EXPECT_CALL(*this, DeviceDescriptionsReceived());
285 audio_system_->GetDeviceDescriptions( 302 audio_system_->GetDeviceDescriptions(
286 base::Bind(&AudioSystemImplTest::OnGetDeviceDescriptions, 303 base::Bind(&AudioSystemImplTest::OnGetDeviceDescriptions,
287 base::Unretained(this), output_device_descriptions_), 304 base::Unretained(this), output_device_descriptions_),
288 false); 305 false);
289 WaitForCallback(); 306 WaitForCallback();
290 } 307 }
291 308
309 TEST_P(AudioSystemImplTest, GetAssociatedOutputDeviceID) {
310 const std::string associated_id("associated_id");
311 audio_manager_->SetAssociatedOutputDeviceIDCallback(
312 base::Bind([](const std::string& result,
313 const std::string&) -> std::string { return result; },
314 associated_id));
315
316 EXPECT_CALL(*this, AssociatedOutputDeviceIDReceived(associated_id));
317
318 audio_system_->GetAssociatedOutputDeviceID(
319 std::string(),
320 base::Bind(&AudioSystemImplTest::AssociatedOutputDeviceIDReceived,
321 base::Unretained(this)));
322 WaitForCallback();
323 }
324
325 TEST_P(AudioSystemImplTest, GetInputDeviceInfoNoAssociation) {
326 EXPECT_CALL(*this, InputDeviceInfoReceived());
327
328 audio_system_->GetInputDeviceInfo(
329 kNonDefaultDeviceId, base::Bind(&AudioSystemImplTest::OnInputDeviceInfo,
330 base::Unretained(this), input_params_,
331 AudioParameters(), std::string()));
332 WaitForCallback();
333 }
334
335 TEST_P(AudioSystemImplTest, GetInputDeviceInfoWithAssociation) {
336 EXPECT_CALL(*this, InputDeviceInfoReceived());
337
338 const std::string associated_id("associated_id");
339 audio_manager_->SetAssociatedOutputDeviceIDCallback(
340 base::Bind([](const std::string& result,
341 const std::string&) -> std::string { return result; },
342 associated_id));
343
344 audio_system_->GetInputDeviceInfo(
345 kNonDefaultDeviceId, base::Bind(&AudioSystemImplTest::OnInputDeviceInfo,
346 base::Unretained(this), input_params_,
347 output_params_, associated_id));
348 WaitForCallback();
349 }
350
292 INSTANTIATE_TEST_CASE_P(, AudioSystemImplTest, testing::Values(false, true)); 351 INSTANTIATE_TEST_CASE_P(, AudioSystemImplTest, testing::Values(false, true));
293 352
294 } // namespace media 353 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_system_impl.cc ('k') | media/audio/mock_audio_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698