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

Unified Diff: media/audio/audio_system_impl_unittest.cc

Issue 2692203003: Switching AudioOutputAuthorizationHandler from using AudioManager interface to AudioSystem one. (Closed)
Patch Set: AudioSystem comments updated according to discussion with tommi@ Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: media/audio/audio_system_impl_unittest.cc
diff --git a/media/audio/audio_system_impl_unittest.cc b/media/audio/audio_system_impl_unittest.cc
index 04f6f645a6752f44d43d9d2af910f8fbb53159ba..ba4de578db69d155b0d56f6c2dcff091b7422dbd 100644
--- a/media/audio/audio_system_impl_unittest.cc
+++ b/media/audio/audio_system_impl_unittest.cc
@@ -16,12 +16,31 @@
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
+namespace {
+const char* kNonDefaultDeviceId = "non-default-device-id";
+}
namespace media {
class AudioSystemImplTest : public testing::TestWithParam<bool> {
public:
AudioSystemImplTest()
- : use_audio_thread_(GetParam()), audio_thread_("AudioSystemThread") {
+ : use_audio_thread_(GetParam()),
+ audio_thread_("AudioSystemThread"),
+ input_params_(AudioParameters::AUDIO_PCM_LINEAR,
+ CHANNEL_LAYOUT_MONO,
+ AudioParameters::kTelephoneSampleRate,
+ 16,
+ AudioParameters::kTelephoneSampleRate / 10),
+ output_params_(AudioParameters::AUDIO_PCM_LINEAR,
+ CHANNEL_LAYOUT_MONO,
+ AudioParameters::kTelephoneSampleRate,
+ 16,
+ AudioParameters::kTelephoneSampleRate / 20),
+ default_output_params_(AudioParameters::AUDIO_PCM_LINEAR,
+ CHANNEL_LAYOUT_MONO,
+ AudioParameters::kTelephoneSampleRate,
+ 16,
+ AudioParameters::kTelephoneSampleRate / 30) {
if (use_audio_thread_) {
audio_thread_.StartAndWaitForTesting();
audio_manager_.reset(
@@ -30,8 +49,11 @@ class AudioSystemImplTest : public testing::TestWithParam<bool> {
audio_manager_.reset(new media::MockAudioManager(
base::ThreadTaskRunnerHandle::Get().get()));
}
- audio_manager_->SetInputStreamParameters(
- media::AudioParameters::UnavailableDeviceParams());
+
+ audio_manager_->SetInputStreamParameters(input_params_);
+ audio_manager_->SetOutputStreamParameters(output_params_);
+ audio_manager_->SetDefaultOutputStreamParameters(default_output_params_);
+
audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get());
EXPECT_EQ(AudioSystem::Get(), audio_system_.get());
}
@@ -52,12 +74,17 @@ class AudioSystemImplTest : public testing::TestWithParam<bool> {
AudioParametersReceived();
}
+ void OnHasInputDevices(bool result) {
+ EXPECT_TRUE(thread_checker_.CalledOnValidThread());
+ HasInputDevicesCallback(result);
+ }
+
void WaitForCallback() {
if (!use_audio_thread_) {
base::RunLoop().RunUntilIdle();
return;
}
- media::WaitableMessageLoopEvent event;
+ WaitableMessageLoopEvent event;
audio_thread_.task_runner()->PostTaskAndReply(
FROM_HERE, base::Bind(&base::DoNothing), event.GetClosure());
// Runs the loop and waits for the |audio_thread_| to call event's closure,
@@ -77,6 +104,9 @@ class AudioSystemImplTest : public testing::TestWithParam<bool> {
base::Thread audio_thread_;
MockAudioManager::UniquePtr audio_manager_;
std::unique_ptr<media::AudioSystem> audio_system_;
+ AudioParameters input_params_;
+ AudioParameters output_params_;
+ AudioParameters default_output_params_;
};
TEST_P(AudioSystemImplTest, GetInputStreamParameters) {
@@ -84,7 +114,7 @@ TEST_P(AudioSystemImplTest, GetInputStreamParameters) {
audio_system_->GetInputStreamParameters(
media::AudioDeviceDescription::kDefaultDeviceId,
base::Bind(&AudioSystemImplTest::OnAudioParams, base::Unretained(this),
- media::AudioParameters::UnavailableDeviceParams()));
+ input_params_));
WaitForCallback();
}
@@ -98,10 +128,44 @@ TEST_P(AudioSystemImplTest, GetInputStreamParametersNoDevice) {
WaitForCallback();
}
+TEST_P(AudioSystemImplTest, GetStreamParameters) {
+ EXPECT_CALL(*this, AudioParametersReceived());
+ audio_system_->GetOutputStreamParameters(
+ kNonDefaultDeviceId, base::Bind(&AudioSystemImplTest::OnAudioParams,
+ base::Unretained(this), output_params_));
+ WaitForCallback();
+}
+
+TEST_P(AudioSystemImplTest, GetDefaultOutputStreamParameters) {
+ EXPECT_CALL(*this, AudioParametersReceived());
+ audio_system_->GetOutputStreamParameters(
+ media::AudioDeviceDescription::kDefaultDeviceId,
+ base::Bind(&AudioSystemImplTest::OnAudioParams, base::Unretained(this),
+ default_output_params_));
+ WaitForCallback();
+}
+
+TEST_P(AudioSystemImplTest, GetOutputStreamParametersNoDevice) {
+ audio_manager_->SetHasOutputDevices(false);
+ EXPECT_CALL(*this, AudioParametersReceived()).Times(2);
+
+ audio_system_->GetOutputStreamParameters(
+ media::AudioDeviceDescription::kDefaultDeviceId,
+ base::Bind(&AudioSystemImplTest::OnAudioParams, base::Unretained(this),
+ media::AudioParameters()));
+ WaitForCallback();
+
+ audio_system_->GetOutputStreamParameters(
+ kNonDefaultDeviceId,
+ base::Bind(&AudioSystemImplTest::OnAudioParams, base::Unretained(this),
+ media::AudioParameters()));
+ WaitForCallback();
+}
+
TEST_P(AudioSystemImplTest, HasInputDevices) {
EXPECT_CALL(*this, HasInputDevicesCallback(true));
audio_system_->HasInputDevices(base::Bind(
- &AudioSystemImplTest::HasInputDevicesCallback, base::Unretained(this)));
+ &AudioSystemImplTest::OnHasInputDevices, base::Unretained(this)));
WaitForCallback();
}
@@ -109,7 +173,7 @@ TEST_P(AudioSystemImplTest, HasNoInputDevices) {
audio_manager_->SetHasInputDevices(false);
EXPECT_CALL(*this, HasInputDevicesCallback(false));
audio_system_->HasInputDevices(base::Bind(
- &AudioSystemImplTest::HasInputDevicesCallback, base::Unretained(this)));
+ &AudioSystemImplTest::OnHasInputDevices, base::Unretained(this)));
WaitForCallback();
}

Powered by Google App Engine
This is Rietveld 408576698