Commit 5ca75c3b authored by Lukasz Krakowiak's avatar Lukasz Krakowiak Committed by Commit Bot

Add test cases for AudioManagerTest

Add test cases to fulfill expectations from ticket:
* LookupDefaultInputDeviceWithProperGroupId
* LookupDefaultOutputDeviceWithProperGroupId

R=olka@chromium.org

Bug: 764291
Change-Id: Ie1586febb83802df5a836d98c8a65d1bec643dd2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2199062Reviewed-by: default avatarOlga Sharonova <olka@chromium.org>
Commit-Queue: Olga Sharonova <olka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#774605}
parent 45c1dbcf
...@@ -104,6 +104,10 @@ using chromeos::AudioNodeList; ...@@ -104,6 +104,10 @@ using chromeos::AudioNodeList;
const int kDefaultSampleRate = 48000; const int kDefaultSampleRate = 48000;
const uint64_t kInternalSpeakerId = 10001;
const uint64_t kInternalSpeakerStableDeviceId = 10001;
const uint64_t kInternalMicId = 10002;
const uint64_t kInternalMicStableDeviceId = 10002;
const uint64_t kJabraSpeaker1Id = 30001; const uint64_t kJabraSpeaker1Id = 30001;
const uint64_t kJabraSpeaker1StableDeviceId = 80001; const uint64_t kJabraSpeaker1StableDeviceId = 80001;
const uint64_t kJabraSpeaker2Id = 30002; const uint64_t kJabraSpeaker2Id = 30002;
...@@ -117,6 +121,30 @@ const uint64_t kJabraMic2StableDeviceId = 90002; ...@@ -117,6 +121,30 @@ const uint64_t kJabraMic2StableDeviceId = 90002;
const uint64_t kWebcamMicId = 40003; const uint64_t kWebcamMicId = 40003;
const uint64_t kWebcamMicStableDeviceId = 90003; const uint64_t kWebcamMicStableDeviceId = 90003;
const AudioNode kInternalSpeaker(false,
kInternalSpeakerId,
true,
kInternalSpeakerStableDeviceId,
kInternalSpeakerStableDeviceId ^ 0xFF,
"Internal Speaker",
"INTERNAL_SPEAKER",
"Speaker",
false,
0,
2);
const AudioNode kInternalMic(true,
kInternalMicId,
true,
kInternalMicStableDeviceId,
kInternalMicStableDeviceId ^ 0xFF,
"Internal Mic",
"INTERNAL_MIC",
"Internal Mic",
false,
0,
1);
const AudioNode kJabraSpeaker1(false, const AudioNode kJabraSpeaker1(false,
kJabraSpeaker1Id, kJabraSpeaker1Id,
true, true,
...@@ -396,6 +424,19 @@ class AudioManagerTest : public ::testing::Test { ...@@ -396,6 +424,19 @@ class AudioManagerTest : public ::testing::Test {
LOG(WARNING) << "No input devices detected"; LOG(WARNING) << "No input devices detected";
} }
} }
// Helper method for (USE_CRAS) which returns |group_id| from |device_id|.
std::string getGroupID(const AudioDeviceDescriptions& device_descriptions,
const std::string device_id) {
AudioDeviceDescriptions::const_iterator it =
std::find_if(device_descriptions.begin(), device_descriptions.end(),
[&device_id](const auto& audio_device_desc) {
return audio_device_desc.unique_id == device_id;
});
EXPECT_NE(it, device_descriptions.end());
return it->group_id;
}
#endif // defined(USE_CRAS) #endif // defined(USE_CRAS)
bool InputDevicesAvailable() { bool InputDevicesAvailable() {
...@@ -504,6 +545,7 @@ TEST_F(AudioManagerTest, CheckOutputStreamParametersCras) { ...@@ -504,6 +545,7 @@ TEST_F(AudioManagerTest, CheckOutputStreamParametersCras) {
audio_nodes.push_back(kHDMIOutput); audio_nodes.push_back(kHDMIOutput);
audio_nodes.push_back(kJabraSpeaker1); audio_nodes.push_back(kJabraSpeaker1);
audio_nodes.push_back(kJabraSpeaker2); audio_nodes.push_back(kJabraSpeaker2);
SetUpCrasAudioHandlerWithTestingNodes(audio_nodes); SetUpCrasAudioHandlerWithTestingNodes(audio_nodes);
ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable()); ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable());
...@@ -572,6 +614,95 @@ TEST_F(AudioManagerTest, CheckOutputStreamParametersCras) { ...@@ -572,6 +614,95 @@ TEST_F(AudioManagerTest, CheckOutputStreamParametersCras) {
ChannelLayout::CHANNEL_LAYOUT_STEREO, 2048); ChannelLayout::CHANNEL_LAYOUT_STEREO, 2048);
EXPECT_TRUE(params.Equals(golden_params)); EXPECT_TRUE(params.Equals(golden_params));
} }
TEST_F(AudioManagerTest, LookupDefaultInputDeviceWithProperGroupId) {
// Setup devices with external microphone as active device.
// Switch active device to the internal microphone.
// Check if default device has the same group id as internal microphone.
AudioNodeList audio_nodes;
audio_nodes.push_back(kInternalMic);
audio_nodes.push_back(kJabraMic1);
SetUpCrasAudioHandlerWithTestingNodes(audio_nodes);
ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable());
// Setup expectation with physical devices.
std::map<uint64_t, std::string> expectation;
expectation[kInternalMic.id] =
cras_audio_handler_->GetDeviceFromId(kInternalMic.id)->display_name;
expectation[kJabraMic1.id] =
cras_audio_handler_->GetDeviceFromId(kJabraMic1.id)->display_name;
CreateAudioManagerForTesting<AudioManagerCras>();
auto previous_default_device_id =
device_info_accessor_->GetDefaultInputDeviceID();
EXPECT_EQ(base::NumberToString(kJabraMic1.id), previous_default_device_id);
AudioDeviceDescriptions device_descriptions;
device_info_accessor_->GetAudioInputDeviceDescriptions(&device_descriptions);
CheckDeviceDescriptions(device_descriptions);
// Set internal microphone as active.
chromeos::AudioDevice internal_microphone(kInternalMic);
cras_audio_handler_->SwitchToDevice(
internal_microphone, true, chromeos::CrasAudioHandler::ACTIVATE_BY_USER);
auto new_default_device_id = device_info_accessor_->GetDefaultInputDeviceID();
EXPECT_NE(previous_default_device_id, new_default_device_id);
auto default_device_group_id =
getGroupID(device_descriptions, new_default_device_id);
auto mic_group_id =
getGroupID(device_descriptions, base::NumberToString(kInternalMic.id));
EXPECT_EQ(default_device_group_id, mic_group_id);
EXPECT_EQ(base::NumberToString(kInternalMic.id), new_default_device_id);
}
TEST_F(AudioManagerTest, LookupDefaultOutputDeviceWithProperGroupId) {
// Setup devices with external speaker as active device.
// Switch active device to the internal speaker.
// Check if default device has the same group id as internal speaker.
AudioNodeList audio_nodes;
audio_nodes.push_back(kInternalSpeaker);
audio_nodes.push_back(kJabraSpeaker1);
SetUpCrasAudioHandlerWithTestingNodes(audio_nodes);
ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable());
// Setup expectation with physical devices.
std::map<uint64_t, std::string> expectation;
expectation[kInternalSpeaker.id] =
cras_audio_handler_->GetDeviceFromId(kInternalSpeaker.id)->display_name;
expectation[kJabraSpeaker1.id] =
cras_audio_handler_->GetDeviceFromId(kJabraSpeaker1.id)->display_name;
CreateAudioManagerForTesting<AudioManagerCras>();
auto previous_default_device_id =
device_info_accessor_->GetDefaultOutputDeviceID();
EXPECT_EQ(base::NumberToString(kJabraSpeaker1.id),
previous_default_device_id);
AudioDeviceDescriptions device_descriptions;
device_info_accessor_->GetAudioOutputDeviceDescriptions(&device_descriptions);
CheckDeviceDescriptions(device_descriptions);
// Set internal speaker as active.
chromeos::AudioDevice internal_speaker(kInternalSpeaker);
cras_audio_handler_->SwitchToDevice(
internal_speaker, true, chromeos::CrasAudioHandler::ACTIVATE_BY_USER);
auto new_default_device_id =
device_info_accessor_->GetDefaultOutputDeviceID();
EXPECT_NE(previous_default_device_id, new_default_device_id);
auto default_device_group_id =
getGroupID(device_descriptions, new_default_device_id);
auto speaker_group_id = getGroupID(device_descriptions,
base::NumberToString(kInternalSpeaker.id));
EXPECT_EQ(default_device_group_id, speaker_group_id);
EXPECT_EQ(base::NumberToString(kInternalSpeaker.id), new_default_device_id);
}
#else // !defined(USE_CRAS) #else // !defined(USE_CRAS)
TEST_F(AudioManagerTest, HandleDefaultDeviceIDs) { TEST_F(AudioManagerTest, HandleDefaultDeviceIDs) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment