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

Unified Diff: chromeos/audio/cras_audio_handler_unittest.cc

Issue 2190773002: Fix Volume slider is captured in screenshot done in touchview mode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 4 years, 4 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
« no previous file with comments | « chromeos/audio/cras_audio_handler.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 7ec72df18fa4354b38413884f88c771a07f803f1..a949bf03cda7085385b298e709df9f535c4fe75f 100644
--- a/chromeos/audio/cras_audio_handler_unittest.cc
+++ b/chromeos/audio/cras_audio_handler_unittest.cc
@@ -421,6 +421,11 @@ class CrasAudioHandlerTest : public testing::Test {
return cras_audio_handler_->hdmi_rediscovering();
}
+ void RestartAudioClient() {
+ cras_audio_handler_->AudioClientRestarted();
+ message_loop_.RunUntilIdle();
+ }
+
protected:
base::MessageLoopForUI message_loop_;
CrasAudioHandler* cras_audio_handler_; // Not owned.
@@ -1972,12 +1977,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 +1991,111 @@ 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, RestartAudioClientWithCrasReady) {
+ AudioNodeList audio_nodes;
+ audio_nodes.push_back(kInternalSpeaker);
+ SetUpCrasAudioHandler(audio_nodes);
+ EXPECT_EQ(0, test_observer_->output_volume_changed_count());
+
+ const int kDefaultVolume = cras_audio_handler_->GetOutputVolumePercent();
+ // Disable the auto OutputNodeVolumeChanged signal.
+ fake_cras_audio_client_->set_notify_volume_change_with_delay(true);
+
+ fake_cras_audio_client_->SetAudioNodesForTesting(audio_nodes);
+ RestartAudioClient();
+ EXPECT_EQ(0, test_observer_->output_volume_changed_count());
+ EXPECT_EQ(kDefaultVolume, cras_audio_handler_->GetOutputVolumePercent());
+
+ // The correct initialization OutputNodeVolumeChanged event is fired. We
+ // should avoid notifying observers.
+ fake_cras_audio_client_->NotifyOutputNodeVolumeChangedForTesting(
+ kInternalSpeaker.id, kDefaultVolume);
+ EXPECT_EQ(0, test_observer_->output_volume_changed_count());
+ EXPECT_EQ(kDefaultVolume, cras_audio_handler_->GetOutputVolumePercent());
+
+ // The later OutputNodeVolumeChanged event after initialization should notify
+ // observers.
+ const int kVolume = 60;
+ fake_cras_audio_client_->NotifyOutputNodeVolumeChangedForTesting(
+ kInternalSpeaker.id, kVolume);
+ EXPECT_EQ(1, test_observer_->output_volume_changed_count());
+ EXPECT_EQ(kVolume, cras_audio_handler_->GetOutputVolumePercent());
+}
+
+TEST_F(CrasAudioHandlerTest, RestartAudioClientWithCrasDropRequest) {
+ AudioNodeList audio_nodes;
+ audio_nodes.push_back(kInternalSpeaker);
+ SetUpCrasAudioHandler(audio_nodes);
+ EXPECT_EQ(0, test_observer_->output_volume_changed_count());
+
+ const int kDefaultVolume = cras_audio_handler_->GetOutputVolumePercent();
+ // Disable the auto OutputNodeVolumeChanged signal.
+ fake_cras_audio_client_->set_notify_volume_change_with_delay(true);
+
+ fake_cras_audio_client_->SetAudioNodesForTesting(audio_nodes);
+ RestartAudioClient();
+ EXPECT_EQ(0, test_observer_->output_volume_changed_count());
+ EXPECT_EQ(kDefaultVolume, cras_audio_handler_->GetOutputVolumePercent());
+
+ // A wrong initialization OutputNodeVolumeChanged event is fired. This may
+ // happen when Cras is not ready and drops request. The approach we use is
+ // to log warning message, clear the pending automated volume change reasons,
+ // and notify observers about this change.
+ const int kVolume1 = 30;
+ fake_cras_audio_client_->NotifyOutputNodeVolumeChangedForTesting(
+ kInternalSpeaker.id, kVolume1);
+ EXPECT_EQ(1, test_observer_->output_volume_changed_count());
+ EXPECT_EQ(kVolume1, cras_audio_handler_->GetOutputVolumePercent());
+
+ // The later OutputNodeVolumeChanged event should notify observers.
+ const int kVolume2 = 60;
+ fake_cras_audio_client_->NotifyOutputNodeVolumeChangedForTesting(
+ kInternalSpeaker.id, kVolume2);
+ EXPECT_EQ(2, test_observer_->output_volume_changed_count());
+ EXPECT_EQ(kVolume2, cras_audio_handler_->GetOutputVolumePercent());
+}
+
TEST_F(CrasAudioHandlerTest, SetOutputVolumeWithDelayedSignal) {
AudioNodeList audio_nodes;
audio_nodes.push_back(kInternalSpeaker);
« 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