| OLD | NEW |
| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 EXPECT_EQ(expected.AsHumanReadableString(), | 91 EXPECT_EQ(expected.AsHumanReadableString(), |
| 92 received.AsHumanReadableString()); | 92 received.AsHumanReadableString()); |
| 93 AudioParametersReceived(); | 93 AudioParametersReceived(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 void OnHasInputDevices(bool result) { | 96 void OnHasInputDevices(bool result) { |
| 97 EXPECT_TRUE(thread_checker_.CalledOnValidThread()); | 97 EXPECT_TRUE(thread_checker_.CalledOnValidThread()); |
| 98 HasInputDevicesCallback(result); | 98 HasInputDevicesCallback(result); |
| 99 } | 99 } |
| 100 | 100 |
| 101 void OnHasOutputDevices(bool result) { |
| 102 EXPECT_TRUE(thread_checker_.CalledOnValidThread()); |
| 103 HasOutputDevicesCallback(result); |
| 104 } |
| 105 |
| 101 void OnGetDeviceDescriptions( | 106 void OnGetDeviceDescriptions( |
| 102 const AudioDeviceDescriptions& expected_descriptions, | 107 const AudioDeviceDescriptions& expected_descriptions, |
| 103 AudioDeviceDescriptions descriptions) { | 108 AudioDeviceDescriptions descriptions) { |
| 104 EXPECT_TRUE(thread_checker_.CalledOnValidThread()); | 109 EXPECT_TRUE(thread_checker_.CalledOnValidThread()); |
| 105 EXPECT_EQ(expected_descriptions, descriptions); | 110 EXPECT_EQ(expected_descriptions, descriptions); |
| 106 DeviceDescriptionsReceived(); | 111 DeviceDescriptionsReceived(); |
| 107 } | 112 } |
| 108 | 113 |
| 109 void WaitForCallback() { | 114 void WaitForCallback() { |
| 110 if (!use_audio_thread_) { | 115 if (!use_audio_thread_) { |
| 111 base::RunLoop().RunUntilIdle(); | 116 base::RunLoop().RunUntilIdle(); |
| 112 return; | 117 return; |
| 113 } | 118 } |
| 114 WaitableMessageLoopEvent event; | 119 WaitableMessageLoopEvent event; |
| 115 audio_thread_.task_runner()->PostTaskAndReply( | 120 audio_thread_.task_runner()->PostTaskAndReply( |
| 116 FROM_HERE, base::Bind(&base::DoNothing), event.GetClosure()); | 121 FROM_HERE, base::Bind(&base::DoNothing), event.GetClosure()); |
| 117 // Runs the loop and waits for the |audio_thread_| to call event's closure, | 122 // Runs the loop and waits for the |audio_thread_| to call event's closure, |
| 118 // which means AudioSystem reply containing device parameters is already | 123 // which means AudioSystem reply containing device parameters is already |
| 119 // queued on the main thread. | 124 // queued on the main thread. |
| 120 event.RunAndWait(); | 125 event.RunAndWait(); |
| 121 base::RunLoop().RunUntilIdle(); | 126 base::RunLoop().RunUntilIdle(); |
| 122 } | 127 } |
| 123 | 128 |
| 124 // Mocks to verify that AudioSystem replied with an expected callback. | 129 // Mocks to verify that AudioSystem replied with an expected callback. |
| 125 MOCK_METHOD0(AudioParametersReceived, void(void)); | 130 MOCK_METHOD0(AudioParametersReceived, void(void)); |
| 126 MOCK_METHOD1(HasInputDevicesCallback, void(bool)); | 131 MOCK_METHOD1(HasInputDevicesCallback, void(bool)); |
| 132 MOCK_METHOD1(HasOutputDevicesCallback, void(bool)); |
| 127 MOCK_METHOD0(DeviceDescriptionsReceived, void(void)); | 133 MOCK_METHOD0(DeviceDescriptionsReceived, void(void)); |
| 128 | 134 |
| 129 protected: | 135 protected: |
| 130 base::MessageLoop message_loop_; | 136 base::MessageLoop message_loop_; |
| 131 base::ThreadChecker thread_checker_; | 137 base::ThreadChecker thread_checker_; |
| 132 bool use_audio_thread_; | 138 bool use_audio_thread_; |
| 133 base::Thread audio_thread_; | 139 base::Thread audio_thread_; |
| 134 MockAudioManager::UniquePtr audio_manager_; | 140 MockAudioManager::UniquePtr audio_manager_; |
| 135 std::unique_ptr<media::AudioSystem> audio_system_; | 141 std::unique_ptr<media::AudioSystem> audio_system_; |
| 136 AudioParameters input_params_; | 142 AudioParameters input_params_; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 } | 207 } |
| 202 | 208 |
| 203 TEST_P(AudioSystemImplTest, HasNoInputDevices) { | 209 TEST_P(AudioSystemImplTest, HasNoInputDevices) { |
| 204 audio_manager_->SetHasInputDevices(false); | 210 audio_manager_->SetHasInputDevices(false); |
| 205 EXPECT_CALL(*this, HasInputDevicesCallback(false)); | 211 EXPECT_CALL(*this, HasInputDevicesCallback(false)); |
| 206 audio_system_->HasInputDevices(base::Bind( | 212 audio_system_->HasInputDevices(base::Bind( |
| 207 &AudioSystemImplTest::OnHasInputDevices, base::Unretained(this))); | 213 &AudioSystemImplTest::OnHasInputDevices, base::Unretained(this))); |
| 208 WaitForCallback(); | 214 WaitForCallback(); |
| 209 } | 215 } |
| 210 | 216 |
| 217 TEST_P(AudioSystemImplTest, HasOutputDevices) { |
| 218 EXPECT_CALL(*this, HasOutputDevicesCallback(true)); |
| 219 audio_system_->HasOutputDevices(base::Bind( |
| 220 &AudioSystemImplTest::OnHasOutputDevices, base::Unretained(this))); |
| 221 WaitForCallback(); |
| 222 } |
| 223 |
| 224 TEST_P(AudioSystemImplTest, HasNoOutputDevices) { |
| 225 audio_manager_->SetHasOutputDevices(false); |
| 226 EXPECT_CALL(*this, HasOutputDevicesCallback(false)); |
| 227 audio_system_->HasOutputDevices(base::Bind( |
| 228 &AudioSystemImplTest::OnHasOutputDevices, base::Unretained(this))); |
| 229 WaitForCallback(); |
| 230 } |
| 231 |
| 211 TEST_P(AudioSystemImplTest, GetInputDeviceDescriptionsNoInputDevices) { | 232 TEST_P(AudioSystemImplTest, GetInputDeviceDescriptionsNoInputDevices) { |
| 212 output_device_descriptions_.emplace_back("output_device_name", | 233 output_device_descriptions_.emplace_back("output_device_name", |
| 213 "output_device_id", "group_id"); | 234 "output_device_id", "group_id"); |
| 214 EXPECT_EQ(0, static_cast<int>(input_device_descriptions_.size())); | 235 EXPECT_EQ(0, static_cast<int>(input_device_descriptions_.size())); |
| 215 EXPECT_EQ(1, static_cast<int>(output_device_descriptions_.size())); | 236 EXPECT_EQ(1, static_cast<int>(output_device_descriptions_.size())); |
| 216 EXPECT_CALL(*this, DeviceDescriptionsReceived()); | 237 EXPECT_CALL(*this, DeviceDescriptionsReceived()); |
| 217 audio_system_->GetDeviceDescriptions( | 238 audio_system_->GetDeviceDescriptions( |
| 218 base::Bind(&AudioSystemImplTest::OnGetDeviceDescriptions, | 239 base::Bind(&AudioSystemImplTest::OnGetDeviceDescriptions, |
| 219 base::Unretained(this), input_device_descriptions_), | 240 base::Unretained(this), input_device_descriptions_), |
| 220 true); | 241 true); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 audio_system_->GetDeviceDescriptions( | 285 audio_system_->GetDeviceDescriptions( |
| 265 base::Bind(&AudioSystemImplTest::OnGetDeviceDescriptions, | 286 base::Bind(&AudioSystemImplTest::OnGetDeviceDescriptions, |
| 266 base::Unretained(this), output_device_descriptions_), | 287 base::Unretained(this), output_device_descriptions_), |
| 267 false); | 288 false); |
| 268 WaitForCallback(); | 289 WaitForCallback(); |
| 269 } | 290 } |
| 270 | 291 |
| 271 INSTANTIATE_TEST_CASE_P(, AudioSystemImplTest, testing::Values(false, true)); | 292 INSTANTIATE_TEST_CASE_P(, AudioSystemImplTest, testing::Values(false, true)); |
| 272 | 293 |
| 273 } // namespace media | 294 } // namespace media |
| OLD | NEW |