Index: chromeos/audio/cras_audio_handler_unittest.cc |
diff --git a/chromeos/audio/cras_audio_handler_unittest.cc b/chromeos/audio/cras_audio_handler_unittest.cc |
index 7375b4dfa8f0c94e72e3eef31fa6e7789fdfbb4d..49536a29a2bb00c4bde89c3c5029a8190cc31351 100644 |
--- a/chromeos/audio/cras_audio_handler_unittest.cc |
+++ b/chromeos/audio/cras_audio_handler_unittest.cc |
@@ -1972,12 +1972,12 @@ TEST_F(CrasAudioHandlerTest, SetOutputVolumePercent) { |
SetUpCrasAudioHandler(audio_nodes); |
EXPECT_EQ(0, test_observer_->output_volume_changed_count()); |
- cras_audio_handler_->SetOutputVolumePercent(60); |
+ const int kVolume = 60; |
+ cras_audio_handler_->SetOutputVolumePercent(kVolume); |
// Verify the output volume is changed to the designated value, |
// OnOutputNodeVolumeChanged event is fired, and the device volume value |
- // is saved the preferences. |
- const int kVolume = 60; |
+ // is saved in the preferences. |
EXPECT_EQ(kVolume, cras_audio_handler_->GetOutputVolumePercent()); |
EXPECT_EQ(1, test_observer_->output_volume_changed_count()); |
AudioDevice device; |
@@ -1986,6 +1986,47 @@ TEST_F(CrasAudioHandlerTest, SetOutputVolumePercent) { |
EXPECT_EQ(kVolume, audio_pref_handler_->GetOutputVolumeValue(&device)); |
} |
+TEST_F(CrasAudioHandlerTest, SetOutputVolumePercentWithoutNotifyingObservers) { |
+ AudioNodeList audio_nodes; |
+ audio_nodes.push_back(kInternalSpeaker); |
+ SetUpCrasAudioHandler(audio_nodes); |
+ EXPECT_EQ(0, test_observer_->output_volume_changed_count()); |
+ |
+ const int kVolume1 = 60; |
+ const int kVolume2 = 80; |
+ cras_audio_handler_->SetOutputVolumePercentWithoutNotifyingObservers( |
+ kVolume1, CrasAudioHandler::VOLUME_CHANGE_MAXIMIZE_MODE_SCREENSHOT); |
+ // Verify the output volume is changed to the designated value, |
+ // OnOutputNodeVolumeChanged event is not fired, and the device volume value |
+ // is saved in the preferences. |
+ EXPECT_EQ(kVolume1, cras_audio_handler_->GetOutputVolumePercent()); |
+ EXPECT_EQ(0, test_observer_->output_volume_changed_count()); |
+ AudioDevice device; |
+ EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(&device)); |
+ EXPECT_EQ(device.id, kInternalSpeaker.id); |
+ EXPECT_EQ(kVolume1, audio_pref_handler_->GetOutputVolumeValue(&device)); |
+ |
+ // Make another SetOutputVolumePercentWithoutNotifyingObservers call to make |
+ // sure everything is right. |
+ cras_audio_handler_->SetOutputVolumePercentWithoutNotifyingObservers( |
+ kVolume2, CrasAudioHandler::VOLUME_CHANGE_MAXIMIZE_MODE_SCREENSHOT); |
+ EXPECT_EQ(kVolume2, cras_audio_handler_->GetOutputVolumePercent()); |
+ EXPECT_EQ(0, test_observer_->output_volume_changed_count()); |
+ EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(&device)); |
+ EXPECT_EQ(device.id, kInternalSpeaker.id); |
+ EXPECT_EQ(kVolume2, audio_pref_handler_->GetOutputVolumeValue(&device)); |
+ |
+ // Make a final SetOutputVolumePercent call to check if |
+ // SetOutputVolumePercentWithoutNotifyingObservers may block subsequent |
+ // notifying observers. |
+ cras_audio_handler_->SetOutputVolumePercent(kVolume1); |
+ EXPECT_EQ(kVolume1, cras_audio_handler_->GetOutputVolumePercent()); |
+ EXPECT_EQ(1, test_observer_->output_volume_changed_count()); |
+ EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(&device)); |
+ EXPECT_EQ(device.id, kInternalSpeaker.id); |
+ EXPECT_EQ(kVolume1, audio_pref_handler_->GetOutputVolumeValue(&device)); |
+} |
+ |
TEST_F(CrasAudioHandlerTest, SetOutputVolumeWithDelayedSignal) { |
AudioNodeList audio_nodes; |
audio_nodes.push_back(kInternalSpeaker); |