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

Side by Side 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 unified diff | Download patch
« 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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 } 414 }
415 415
416 void SetHDMIRediscoverGracePeriodDuration(int duration_in_ms) { 416 void SetHDMIRediscoverGracePeriodDuration(int duration_in_ms) {
417 cras_audio_handler_->SetHDMIRediscoverGracePeriodForTesting(duration_in_ms); 417 cras_audio_handler_->SetHDMIRediscoverGracePeriodForTesting(duration_in_ms);
418 } 418 }
419 419
420 bool IsDuringHDMIRediscoverGracePeriod() { 420 bool IsDuringHDMIRediscoverGracePeriod() {
421 return cras_audio_handler_->hdmi_rediscovering(); 421 return cras_audio_handler_->hdmi_rediscovering();
422 } 422 }
423 423
424 void RestartAudioClient() {
425 cras_audio_handler_->AudioClientRestarted();
426 message_loop_.RunUntilIdle();
427 }
428
424 protected: 429 protected:
425 base::MessageLoopForUI message_loop_; 430 base::MessageLoopForUI message_loop_;
426 CrasAudioHandler* cras_audio_handler_; // Not owned. 431 CrasAudioHandler* cras_audio_handler_; // Not owned.
427 FakeCrasAudioClient* fake_cras_audio_client_; // Not owned. 432 FakeCrasAudioClient* fake_cras_audio_client_; // Not owned.
428 std::unique_ptr<TestObserver> test_observer_; 433 std::unique_ptr<TestObserver> test_observer_;
429 scoped_refptr<AudioDevicesPrefHandlerStub> audio_pref_handler_; 434 scoped_refptr<AudioDevicesPrefHandlerStub> audio_pref_handler_;
430 435
431 private: 436 private:
432 DISALLOW_COPY_AND_ASSIGN(CrasAudioHandlerTest); 437 DISALLOW_COPY_AND_ASSIGN(CrasAudioHandlerTest);
433 }; 438 };
(...skipping 1531 matching lines...) Expand 10 before | Expand all | Expand 10 after
1965 EXPECT_FALSE(cras_audio_handler_->IsInputMuted()); 1970 EXPECT_FALSE(cras_audio_handler_->IsInputMuted());
1966 EXPECT_EQ(2, test_observer_->input_mute_changed_count()); 1971 EXPECT_EQ(2, test_observer_->input_mute_changed_count());
1967 } 1972 }
1968 1973
1969 TEST_F(CrasAudioHandlerTest, SetOutputVolumePercent) { 1974 TEST_F(CrasAudioHandlerTest, SetOutputVolumePercent) {
1970 AudioNodeList audio_nodes; 1975 AudioNodeList audio_nodes;
1971 audio_nodes.push_back(kInternalSpeaker); 1976 audio_nodes.push_back(kInternalSpeaker);
1972 SetUpCrasAudioHandler(audio_nodes); 1977 SetUpCrasAudioHandler(audio_nodes);
1973 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); 1978 EXPECT_EQ(0, test_observer_->output_volume_changed_count());
1974 1979
1975 cras_audio_handler_->SetOutputVolumePercent(60); 1980 const int kVolume = 60;
1981 cras_audio_handler_->SetOutputVolumePercent(kVolume);
1976 1982
1977 // Verify the output volume is changed to the designated value, 1983 // Verify the output volume is changed to the designated value,
1978 // OnOutputNodeVolumeChanged event is fired, and the device volume value 1984 // OnOutputNodeVolumeChanged event is fired, and the device volume value
1979 // is saved the preferences. 1985 // is saved in the preferences.
1980 const int kVolume = 60;
1981 EXPECT_EQ(kVolume, cras_audio_handler_->GetOutputVolumePercent()); 1986 EXPECT_EQ(kVolume, cras_audio_handler_->GetOutputVolumePercent());
1982 EXPECT_EQ(1, test_observer_->output_volume_changed_count()); 1987 EXPECT_EQ(1, test_observer_->output_volume_changed_count());
1983 AudioDevice device; 1988 AudioDevice device;
1984 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(&device)); 1989 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(&device));
1985 EXPECT_EQ(device.id, kInternalSpeaker.id); 1990 EXPECT_EQ(device.id, kInternalSpeaker.id);
1986 EXPECT_EQ(kVolume, audio_pref_handler_->GetOutputVolumeValue(&device)); 1991 EXPECT_EQ(kVolume, audio_pref_handler_->GetOutputVolumeValue(&device));
1987 } 1992 }
1988 1993
1994 TEST_F(CrasAudioHandlerTest, SetOutputVolumePercentWithoutNotifyingObservers) {
1995 AudioNodeList audio_nodes;
1996 audio_nodes.push_back(kInternalSpeaker);
1997 SetUpCrasAudioHandler(audio_nodes);
1998 EXPECT_EQ(0, test_observer_->output_volume_changed_count());
1999
2000 const int kVolume1 = 60;
2001 const int kVolume2 = 80;
2002 cras_audio_handler_->SetOutputVolumePercentWithoutNotifyingObservers(
2003 kVolume1, CrasAudioHandler::VOLUME_CHANGE_MAXIMIZE_MODE_SCREENSHOT);
2004 // Verify the output volume is changed to the designated value,
2005 // OnOutputNodeVolumeChanged event is not fired, and the device volume value
2006 // is saved in the preferences.
2007 EXPECT_EQ(kVolume1, cras_audio_handler_->GetOutputVolumePercent());
2008 EXPECT_EQ(0, test_observer_->output_volume_changed_count());
2009 AudioDevice device;
2010 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(&device));
2011 EXPECT_EQ(device.id, kInternalSpeaker.id);
2012 EXPECT_EQ(kVolume1, audio_pref_handler_->GetOutputVolumeValue(&device));
2013
2014 // Make another SetOutputVolumePercentWithoutNotifyingObservers call to make
2015 // sure everything is right.
2016 cras_audio_handler_->SetOutputVolumePercentWithoutNotifyingObservers(
2017 kVolume2, CrasAudioHandler::VOLUME_CHANGE_MAXIMIZE_MODE_SCREENSHOT);
2018 EXPECT_EQ(kVolume2, cras_audio_handler_->GetOutputVolumePercent());
2019 EXPECT_EQ(0, test_observer_->output_volume_changed_count());
2020 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(&device));
2021 EXPECT_EQ(device.id, kInternalSpeaker.id);
2022 EXPECT_EQ(kVolume2, audio_pref_handler_->GetOutputVolumeValue(&device));
2023
2024 // Make a final SetOutputVolumePercent call to check if
2025 // SetOutputVolumePercentWithoutNotifyingObservers may block subsequent
2026 // notifying observers.
2027 cras_audio_handler_->SetOutputVolumePercent(kVolume1);
2028 EXPECT_EQ(kVolume1, cras_audio_handler_->GetOutputVolumePercent());
2029 EXPECT_EQ(1, test_observer_->output_volume_changed_count());
2030 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(&device));
2031 EXPECT_EQ(device.id, kInternalSpeaker.id);
2032 EXPECT_EQ(kVolume1, audio_pref_handler_->GetOutputVolumeValue(&device));
2033 }
2034
2035 TEST_F(CrasAudioHandlerTest, RestartAudioClientWithCrasReady) {
2036 AudioNodeList audio_nodes;
2037 audio_nodes.push_back(kInternalSpeaker);
2038 SetUpCrasAudioHandler(audio_nodes);
2039 EXPECT_EQ(0, test_observer_->output_volume_changed_count());
2040
2041 const int kDefaultVolume = cras_audio_handler_->GetOutputVolumePercent();
2042 // Disable the auto OutputNodeVolumeChanged signal.
2043 fake_cras_audio_client_->set_notify_volume_change_with_delay(true);
2044
2045 fake_cras_audio_client_->SetAudioNodesForTesting(audio_nodes);
2046 RestartAudioClient();
2047 EXPECT_EQ(0, test_observer_->output_volume_changed_count());
2048 EXPECT_EQ(kDefaultVolume, cras_audio_handler_->GetOutputVolumePercent());
2049
2050 // The correct initialization OutputNodeVolumeChanged event is fired. We
2051 // should avoid notifying observers.
2052 fake_cras_audio_client_->NotifyOutputNodeVolumeChangedForTesting(
2053 kInternalSpeaker.id, kDefaultVolume);
2054 EXPECT_EQ(0, test_observer_->output_volume_changed_count());
2055 EXPECT_EQ(kDefaultVolume, cras_audio_handler_->GetOutputVolumePercent());
2056
2057 // The later OutputNodeVolumeChanged event after initialization should notify
2058 // observers.
2059 const int kVolume = 60;
2060 fake_cras_audio_client_->NotifyOutputNodeVolumeChangedForTesting(
2061 kInternalSpeaker.id, kVolume);
2062 EXPECT_EQ(1, test_observer_->output_volume_changed_count());
2063 EXPECT_EQ(kVolume, cras_audio_handler_->GetOutputVolumePercent());
2064 }
2065
2066 TEST_F(CrasAudioHandlerTest, RestartAudioClientWithCrasDropRequest) {
2067 AudioNodeList audio_nodes;
2068 audio_nodes.push_back(kInternalSpeaker);
2069 SetUpCrasAudioHandler(audio_nodes);
2070 EXPECT_EQ(0, test_observer_->output_volume_changed_count());
2071
2072 const int kDefaultVolume = cras_audio_handler_->GetOutputVolumePercent();
2073 // Disable the auto OutputNodeVolumeChanged signal.
2074 fake_cras_audio_client_->set_notify_volume_change_with_delay(true);
2075
2076 fake_cras_audio_client_->SetAudioNodesForTesting(audio_nodes);
2077 RestartAudioClient();
2078 EXPECT_EQ(0, test_observer_->output_volume_changed_count());
2079 EXPECT_EQ(kDefaultVolume, cras_audio_handler_->GetOutputVolumePercent());
2080
2081 // A wrong initialization OutputNodeVolumeChanged event is fired. This may
2082 // happen when Cras is not ready and drops request. The approach we use is
2083 // to log warning message, clear the pending automated volume change reasons,
2084 // and notify observers about this change.
2085 const int kVolume1 = 30;
2086 fake_cras_audio_client_->NotifyOutputNodeVolumeChangedForTesting(
2087 kInternalSpeaker.id, kVolume1);
2088 EXPECT_EQ(1, test_observer_->output_volume_changed_count());
2089 EXPECT_EQ(kVolume1, cras_audio_handler_->GetOutputVolumePercent());
2090
2091 // The later OutputNodeVolumeChanged event should notify observers.
2092 const int kVolume2 = 60;
2093 fake_cras_audio_client_->NotifyOutputNodeVolumeChangedForTesting(
2094 kInternalSpeaker.id, kVolume2);
2095 EXPECT_EQ(2, test_observer_->output_volume_changed_count());
2096 EXPECT_EQ(kVolume2, cras_audio_handler_->GetOutputVolumePercent());
2097 }
2098
1989 TEST_F(CrasAudioHandlerTest, SetOutputVolumeWithDelayedSignal) { 2099 TEST_F(CrasAudioHandlerTest, SetOutputVolumeWithDelayedSignal) {
1990 AudioNodeList audio_nodes; 2100 AudioNodeList audio_nodes;
1991 audio_nodes.push_back(kInternalSpeaker); 2101 audio_nodes.push_back(kInternalSpeaker);
1992 SetUpCrasAudioHandler(audio_nodes); 2102 SetUpCrasAudioHandler(audio_nodes);
1993 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); 2103 EXPECT_EQ(0, test_observer_->output_volume_changed_count());
1994 2104
1995 const int kDefaultVolume = 75; 2105 const int kDefaultVolume = 75;
1996 EXPECT_EQ(kDefaultVolume, cras_audio_handler_->GetOutputVolumePercent()); 2106 EXPECT_EQ(kDefaultVolume, cras_audio_handler_->GetOutputVolumePercent());
1997 2107
1998 // Disable the auto OutputNodeVolumeChanged signal. 2108 // Disable the auto OutputNodeVolumeChanged signal.
(...skipping 1294 matching lines...) Expand 10 before | Expand all | Expand 10 after
3293 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); 3403 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output));
3294 EXPECT_EQ(kInternalSpeaker.id, active_output.id); 3404 EXPECT_EQ(kInternalSpeaker.id, active_output.id);
3295 EXPECT_EQ(kInternalSpeaker.id, 3405 EXPECT_EQ(kInternalSpeaker.id,
3296 cras_audio_handler_->GetPrimaryActiveOutputNode()); 3406 cras_audio_handler_->GetPrimaryActiveOutputNode());
3297 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); 3407 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted());
3298 EXPECT_EQ(1, test_observer_->output_mute_changed_count()); 3408 EXPECT_EQ(1, test_observer_->output_mute_changed_count());
3299 EXPECT_TRUE(test_observer_->output_mute_by_system()); 3409 EXPECT_TRUE(test_observer_->output_mute_by_system());
3300 } 3410 }
3301 3411
3302 } // namespace chromeos 3412 } // 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