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

Side by Side Diff: chromeos/audio/cras_audio_handler_unittest.cc

Issue 23536034: Set up hdmi output device default volume to 100. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix nits. Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « chromeos/audio/cras_audio_handler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "chromeos/audio/cras_audio_handler.h" 5 #include "chromeos/audio/cras_audio_handler.h"
6 6
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 1068
1069 // Verify the output volume is changed to the designated value, 1069 // Verify the output volume is changed to the designated value,
1070 // OnOutputVolumeChanged event is fired, and the device volume value 1070 // OnOutputVolumeChanged event is fired, and the device volume value
1071 // is saved the preferences. 1071 // is saved the preferences.
1072 const int kVolume = 60; 1072 const int kVolume = 60;
1073 EXPECT_EQ(kVolume, cras_audio_handler_->GetOutputVolumePercent()); 1073 EXPECT_EQ(kVolume, cras_audio_handler_->GetOutputVolumePercent());
1074 EXPECT_EQ(1, test_observer_->output_volume_changed_count()); 1074 EXPECT_EQ(1, test_observer_->output_volume_changed_count());
1075 AudioDevice device; 1075 AudioDevice device;
1076 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&device)); 1076 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&device));
1077 EXPECT_EQ(device.id, kInternalSpeaker.id); 1077 EXPECT_EQ(device.id, kInternalSpeaker.id);
1078 EXPECT_EQ(kVolume, audio_pref_handler_->GetVolumeGainValue(device)); 1078 EXPECT_EQ(kVolume, audio_pref_handler_->GetOutputVolumeValue(&device));
1079 } 1079 }
1080 1080
1081 TEST_F(CrasAudioHandlerTest, SetInputGainPercent) { 1081 TEST_F(CrasAudioHandlerTest, SetInputGainPercent) {
1082 AudioNodeList audio_nodes; 1082 AudioNodeList audio_nodes;
1083 audio_nodes.push_back(kInternalMic); 1083 audio_nodes.push_back(kInternalMic);
1084 SetUpCrasAudioHandler(audio_nodes); 1084 SetUpCrasAudioHandler(audio_nodes);
1085 EXPECT_EQ(0, test_observer_->input_gain_changed_count()); 1085 EXPECT_EQ(0, test_observer_->input_gain_changed_count());
1086 1086
1087 cras_audio_handler_->SetInputGainPercent(60); 1087 cras_audio_handler_->SetInputGainPercent(60);
1088 1088
1089 // Verify the input gain changed to the designated value, 1089 // Verify the input gain changed to the designated value,
1090 // OnInputGainChanged event is fired, and the device gain value 1090 // OnInputGainChanged event is fired, and the device gain value
1091 // is saved in the preferences. 1091 // is saved in the preferences.
1092 const int kGain = 60; 1092 const int kGain = 60;
1093 EXPECT_EQ(kGain, cras_audio_handler_->GetInputGainPercent()); 1093 EXPECT_EQ(kGain, cras_audio_handler_->GetInputGainPercent());
1094 EXPECT_EQ(1, test_observer_->input_gain_changed_count()); 1094 EXPECT_EQ(1, test_observer_->input_gain_changed_count());
1095 AudioDevice internal_mic(kInternalMic); 1095 AudioDevice internal_mic(kInternalMic);
1096 EXPECT_EQ(kGain, audio_pref_handler_->GetVolumeGainValue(internal_mic)); 1096 EXPECT_EQ(kGain, audio_pref_handler_->GetInputGainValue(&internal_mic));
1097 } 1097 }
1098 1098
1099 TEST_F(CrasAudioHandlerTest, SetMuteForDevice) { 1099 TEST_F(CrasAudioHandlerTest, SetMuteForDevice) {
1100 AudioNodeList audio_nodes; 1100 AudioNodeList audio_nodes;
1101 audio_nodes.push_back(kInternalSpeaker); 1101 audio_nodes.push_back(kInternalSpeaker);
1102 audio_nodes.push_back(kHeadphone); 1102 audio_nodes.push_back(kHeadphone);
1103 audio_nodes.push_back(kInternalMic); 1103 audio_nodes.push_back(kInternalMic);
1104 audio_nodes.push_back(kUSBMic); 1104 audio_nodes.push_back(kUSBMic);
1105 SetUpCrasAudioHandler(audio_nodes); 1105 SetUpCrasAudioHandler(audio_nodes);
1106 1106
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1154 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetActiveOutputNode()); 1154 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetActiveOutputNode());
1155 cras_audio_handler_->SetVolumeGainPercentForDevice(kHeadphone.id, 1155 cras_audio_handler_->SetVolumeGainPercentForDevice(kHeadphone.id,
1156 kHeadphoneVolume); 1156 kHeadphoneVolume);
1157 1157
1158 // Verify the volume percent of headphone is set, and saved in preferences. 1158 // Verify the volume percent of headphone is set, and saved in preferences.
1159 EXPECT_EQ(kHeadphoneVolume, 1159 EXPECT_EQ(kHeadphoneVolume,
1160 cras_audio_handler_->GetOutputVolumePercentForDevice( 1160 cras_audio_handler_->GetOutputVolumePercentForDevice(
1161 kHeadphone.id)); 1161 kHeadphone.id));
1162 AudioDevice headphone(kHeadphone); 1162 AudioDevice headphone(kHeadphone);
1163 EXPECT_EQ(kHeadphoneVolume, 1163 EXPECT_EQ(kHeadphoneVolume,
1164 audio_pref_handler_->GetVolumeGainValue(headphone)); 1164 audio_pref_handler_->GetOutputVolumeValue(&headphone));
1165 1165
1166 // Set volume percent for non-active output device. 1166 // Set volume percent for non-active output device.
1167 const int kSpeakerVolume = 60; 1167 const int kSpeakerVolume = 60;
1168 cras_audio_handler_->SetVolumeGainPercentForDevice(kInternalSpeaker.id, 1168 cras_audio_handler_->SetVolumeGainPercentForDevice(kInternalSpeaker.id,
1169 kSpeakerVolume); 1169 kSpeakerVolume);
1170 1170
1171 // Verify the volume percent of speaker is set, and saved in preferences. 1171 // Verify the volume percent of speaker is set, and saved in preferences.
1172 EXPECT_EQ(kSpeakerVolume, 1172 EXPECT_EQ(kSpeakerVolume,
1173 cras_audio_handler_->GetOutputVolumePercentForDevice( 1173 cras_audio_handler_->GetOutputVolumePercentForDevice(
1174 kInternalSpeaker.id)); 1174 kInternalSpeaker.id));
1175 AudioDevice speaker(kInternalSpeaker); 1175 AudioDevice speaker(kInternalSpeaker);
1176 EXPECT_EQ(kSpeakerVolume, 1176 EXPECT_EQ(kSpeakerVolume,
1177 audio_pref_handler_->GetVolumeGainValue(speaker)); 1177 audio_pref_handler_->GetOutputVolumeValue(&speaker));
1178 1178
1179 // Set gain percent for active input device. 1179 // Set gain percent for active input device.
1180 const int kUSBMicGain = 30; 1180 const int kUSBMicGain = 30;
1181 EXPECT_EQ(kUSBMic.id, cras_audio_handler_->GetActiveInputNode()); 1181 EXPECT_EQ(kUSBMic.id, cras_audio_handler_->GetActiveInputNode());
1182 cras_audio_handler_->SetVolumeGainPercentForDevice(kUSBMic.id, 1182 cras_audio_handler_->SetVolumeGainPercentForDevice(kUSBMic.id,
1183 kUSBMicGain); 1183 kUSBMicGain);
1184 1184
1185 // Verify the gain percent of USB mic is set, and saved in preferences. 1185 // Verify the gain percent of USB mic is set, and saved in preferences.
1186 EXPECT_EQ(kUSBMicGain, 1186 EXPECT_EQ(kUSBMicGain,
1187 cras_audio_handler_->GetOutputVolumePercentForDevice(kUSBMic.id)); 1187 cras_audio_handler_->GetOutputVolumePercentForDevice(kUSBMic.id));
1188 AudioDevice usb_mic(kHeadphone); 1188 AudioDevice usb_mic(kHeadphone);
1189 EXPECT_EQ(kUSBMicGain, 1189 EXPECT_EQ(kUSBMicGain,
1190 audio_pref_handler_->GetVolumeGainValue(usb_mic)); 1190 audio_pref_handler_->GetInputGainValue(&usb_mic));
1191 1191
1192 // Set gain percent for non-active input device. 1192 // Set gain percent for non-active input device.
1193 const int kInternalMicGain = 60; 1193 const int kInternalMicGain = 60;
1194 cras_audio_handler_->SetVolumeGainPercentForDevice(kInternalMic.id, 1194 cras_audio_handler_->SetVolumeGainPercentForDevice(kInternalMic.id,
1195 kInternalMicGain); 1195 kInternalMicGain);
1196 1196
1197 // Verify the gain percent of internal mic is set, and saved in preferences. 1197 // Verify the gain percent of internal mic is set, and saved in preferences.
1198 EXPECT_EQ(kInternalMicGain, 1198 EXPECT_EQ(kInternalMicGain,
1199 cras_audio_handler_->GetOutputVolumePercentForDevice( 1199 cras_audio_handler_->GetOutputVolumePercentForDevice(
1200 kInternalMic.id)); 1200 kInternalMic.id));
1201 AudioDevice internal_mic(kInternalMic); 1201 AudioDevice internal_mic(kInternalMic);
1202 EXPECT_EQ(kInternalMicGain, 1202 EXPECT_EQ(kInternalMicGain,
1203 audio_pref_handler_->GetVolumeGainValue(internal_mic)); 1203 audio_pref_handler_->GetInputGainValue(&internal_mic));
1204 } 1204 }
1205 1205
1206 TEST_F(CrasAudioHandlerTest, HandleOtherDeviceType) { 1206 TEST_F(CrasAudioHandlerTest, HandleOtherDeviceType) {
1207 const size_t kNumValidAudioDevices = 4; 1207 const size_t kNumValidAudioDevices = 4;
1208 AudioNodeList audio_nodes; 1208 AudioNodeList audio_nodes;
1209 audio_nodes.push_back(kInternalSpeaker); 1209 audio_nodes.push_back(kInternalSpeaker);
1210 audio_nodes.push_back(kOtherTypeOutput); 1210 audio_nodes.push_back(kOtherTypeOutput);
1211 audio_nodes.push_back(kInternalMic); 1211 audio_nodes.push_back(kInternalMic);
1212 audio_nodes.push_back(kOtherTypeInput); 1212 audio_nodes.push_back(kOtherTypeInput);
1213 SetUpCrasAudioHandler(audio_nodes); 1213 SetUpCrasAudioHandler(audio_nodes);
(...skipping 12 matching lines...) Expand all
1226 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); 1226 EXPECT_TRUE(cras_audio_handler_->has_alternative_output());
1227 1227
1228 // Ensure the internal microphone has been selected as the active input, 1228 // Ensure the internal microphone has been selected as the active input,
1229 // and the input device with some random unknown type is handled gracefully. 1229 // and the input device with some random unknown type is handled gracefully.
1230 AudioDevice active_input; 1230 AudioDevice active_input;
1231 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetActiveInputNode()); 1231 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetActiveInputNode());
1232 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); 1232 EXPECT_TRUE(cras_audio_handler_->has_alternative_input());
1233 } 1233 }
1234 1234
1235 } // namespace chromeos 1235 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/audio/cras_audio_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698