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

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: initialization audio state unittest 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 // Simulating CrasAudioHandler::SetupAudioOutputState during initializing
425 // audio state by using fake_cras_audio_client_ to SetOutputNodeVolume,
426 // so that we can disable the auto OutputNodeVolumeChanged signal.
427 void SetupAudioOutputStateDuringInitialization() {
428 cras_audio_handler_->initializing_audio_state_ = true;
429 uint64_t active_output_node_id =
430 cras_audio_handler_->GetPrimaryActiveOutputNode();
431 int output_volume = cras_audio_handler_->GetOutputVolumePercent();
432 cras_audio_handler_->init_node_id_ = active_output_node_id;
Daniel Erat 2016/08/04 23:08:59 please don't reach directly into the object being
Qiang(Joe) Xu 2016/08/04 23:41:03 Sorry wrong local branch.
433 cras_audio_handler_->init_volume_ = output_volume;
434 cras_audio_handler_->automated_volume_change_reasons_.push_back(
435 CrasAudioHandler::VOLUME_CHANGE_INITIALIZING_AUDIO_STATE);
436 fake_cras_audio_client_->SetOutputNodeVolume(active_output_node_id,
437 output_volume);
438 }
439
424 protected: 440 protected:
425 base::MessageLoopForUI message_loop_; 441 base::MessageLoopForUI message_loop_;
426 CrasAudioHandler* cras_audio_handler_; // Not owned. 442 CrasAudioHandler* cras_audio_handler_; // Not owned.
427 FakeCrasAudioClient* fake_cras_audio_client_; // Not owned. 443 FakeCrasAudioClient* fake_cras_audio_client_; // Not owned.
428 std::unique_ptr<TestObserver> test_observer_; 444 std::unique_ptr<TestObserver> test_observer_;
429 scoped_refptr<AudioDevicesPrefHandlerStub> audio_pref_handler_; 445 scoped_refptr<AudioDevicesPrefHandlerStub> audio_pref_handler_;
430 446
431 private: 447 private:
432 DISALLOW_COPY_AND_ASSIGN(CrasAudioHandlerTest); 448 DISALLOW_COPY_AND_ASSIGN(CrasAudioHandlerTest);
433 }; 449 };
(...skipping 1531 matching lines...) Expand 10 before | Expand all | Expand 10 after
1965 EXPECT_FALSE(cras_audio_handler_->IsInputMuted()); 1981 EXPECT_FALSE(cras_audio_handler_->IsInputMuted());
1966 EXPECT_EQ(2, test_observer_->input_mute_changed_count()); 1982 EXPECT_EQ(2, test_observer_->input_mute_changed_count());
1967 } 1983 }
1968 1984
1969 TEST_F(CrasAudioHandlerTest, SetOutputVolumePercent) { 1985 TEST_F(CrasAudioHandlerTest, SetOutputVolumePercent) {
1970 AudioNodeList audio_nodes; 1986 AudioNodeList audio_nodes;
1971 audio_nodes.push_back(kInternalSpeaker); 1987 audio_nodes.push_back(kInternalSpeaker);
1972 SetUpCrasAudioHandler(audio_nodes); 1988 SetUpCrasAudioHandler(audio_nodes);
1973 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); 1989 EXPECT_EQ(0, test_observer_->output_volume_changed_count());
1974 1990
1975 cras_audio_handler_->SetOutputVolumePercent(60); 1991 const int kVolume = 60;
1992 cras_audio_handler_->SetOutputVolumePercent(kVolume);
1976 1993
1977 // Verify the output volume is changed to the designated value, 1994 // Verify the output volume is changed to the designated value,
1978 // OnOutputNodeVolumeChanged event is fired, and the device volume value 1995 // OnOutputNodeVolumeChanged event is fired, and the device volume value
1979 // is saved the preferences. 1996 // is saved in the preferences.
1980 const int kVolume = 60;
1981 EXPECT_EQ(kVolume, cras_audio_handler_->GetOutputVolumePercent()); 1997 EXPECT_EQ(kVolume, cras_audio_handler_->GetOutputVolumePercent());
1982 EXPECT_EQ(1, test_observer_->output_volume_changed_count()); 1998 EXPECT_EQ(1, test_observer_->output_volume_changed_count());
1983 AudioDevice device; 1999 AudioDevice device;
1984 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(&device)); 2000 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(&device));
1985 EXPECT_EQ(device.id, kInternalSpeaker.id); 2001 EXPECT_EQ(device.id, kInternalSpeaker.id);
1986 EXPECT_EQ(kVolume, audio_pref_handler_->GetOutputVolumeValue(&device)); 2002 EXPECT_EQ(kVolume, audio_pref_handler_->GetOutputVolumeValue(&device));
1987 } 2003 }
1988 2004
2005 TEST_F(CrasAudioHandlerTest, SetOutputVolumePercentWithoutNotifyingObservers) {
2006 AudioNodeList audio_nodes;
2007 audio_nodes.push_back(kInternalSpeaker);
2008 SetUpCrasAudioHandler(audio_nodes);
2009 EXPECT_EQ(0, test_observer_->output_volume_changed_count());
2010
2011 const int kVolume1 = 60;
2012 const int kVolume2 = 80;
2013 cras_audio_handler_->SetOutputVolumePercentWithoutNotifyingObservers(
2014 kVolume1, CrasAudioHandler::VOLUME_CHANGE_MAXIMIZE_MODE_SCREENSHOT);
2015 // Verify the output volume is changed to the designated value,
2016 // OnOutputNodeVolumeChanged event is not fired, and the device volume value
2017 // is saved in the preferences.
2018 EXPECT_EQ(kVolume1, cras_audio_handler_->GetOutputVolumePercent());
2019 EXPECT_EQ(0, test_observer_->output_volume_changed_count());
2020 AudioDevice device;
2021 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(&device));
2022 EXPECT_EQ(device.id, kInternalSpeaker.id);
2023 EXPECT_EQ(kVolume1, audio_pref_handler_->GetOutputVolumeValue(&device));
2024
2025 // Make another SetOutputVolumePercentWithoutNotifyingObservers call to make
2026 // sure everything is right.
2027 cras_audio_handler_->SetOutputVolumePercentWithoutNotifyingObservers(
2028 kVolume2, CrasAudioHandler::VOLUME_CHANGE_MAXIMIZE_MODE_SCREENSHOT);
2029 EXPECT_EQ(kVolume2, cras_audio_handler_->GetOutputVolumePercent());
2030 EXPECT_EQ(0, test_observer_->output_volume_changed_count());
2031 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(&device));
2032 EXPECT_EQ(device.id, kInternalSpeaker.id);
2033 EXPECT_EQ(kVolume2, audio_pref_handler_->GetOutputVolumeValue(&device));
2034
2035 // Make a final SetOutputVolumePercent call to check if
2036 // SetOutputVolumePercentWithoutNotifyingObservers may block subsequent
2037 // notifying observers.
2038 cras_audio_handler_->SetOutputVolumePercent(kVolume1);
2039 EXPECT_EQ(kVolume1, cras_audio_handler_->GetOutputVolumePercent());
2040 EXPECT_EQ(1, test_observer_->output_volume_changed_count());
2041 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(&device));
2042 EXPECT_EQ(device.id, kInternalSpeaker.id);
2043 EXPECT_EQ(kVolume1, audio_pref_handler_->GetOutputVolumeValue(&device));
2044 }
2045
2046 TEST_F(CrasAudioHandlerTest,
2047 SetupAudioOutputStateDuringInitializationWithCrasReady) {
2048 AudioNodeList audio_nodes;
2049 audio_nodes.push_back(kInternalSpeaker);
2050 SetUpCrasAudioHandler(audio_nodes);
2051 EXPECT_EQ(0, test_observer_->output_volume_changed_count());
2052
2053 const int kDefaultVolume = 75;
2054 EXPECT_EQ(kDefaultVolume, cras_audio_handler_->GetOutputVolumePercent());
2055
2056 // Disable the auto OutputNodeVolumeChanged signal.
2057 fake_cras_audio_client_->set_notify_volume_change_with_delay(true);
2058
2059 SetupAudioOutputStateDuringInitialization();
2060 EXPECT_EQ(0, test_observer_->output_volume_changed_count());
2061 EXPECT_EQ(kDefaultVolume, cras_audio_handler_->GetOutputVolumePercent());
2062
2063 // The correct initialization OutputNodeVolumeChanged event is fired. We
2064 // should avoid notify observers.
2065 fake_cras_audio_client_->NotifyOutputNodeVolumeChangedForTesting(
2066 kInternalSpeaker.id, kDefaultVolume);
2067 EXPECT_EQ(0, test_observer_->output_volume_changed_count());
2068 EXPECT_EQ(kDefaultVolume, cras_audio_handler_->GetOutputVolumePercent());
2069
2070 // The later OutputNodeVolumeChanged event after initialization should notify
2071 // observers.
2072 const int kVolume = 60;
2073 fake_cras_audio_client_->NotifyOutputNodeVolumeChangedForTesting(
2074 kInternalSpeaker.id, kVolume);
2075 EXPECT_EQ(1, test_observer_->output_volume_changed_count());
2076 EXPECT_EQ(kVolume, cras_audio_handler_->GetOutputVolumePercent());
2077 }
2078
2079 TEST_F(CrasAudioHandlerTest,
2080 SetupAudioOutputStateDuringInitializationWithCrasDropRequest) {
2081 AudioNodeList audio_nodes;
2082 audio_nodes.push_back(kInternalSpeaker);
2083 SetUpCrasAudioHandler(audio_nodes);
2084 EXPECT_EQ(0, test_observer_->output_volume_changed_count());
2085
2086 const int kDefaultVolume = 75;
2087 EXPECT_EQ(kDefaultVolume, cras_audio_handler_->GetOutputVolumePercent());
2088
2089 // Disable the auto OutputNodeVolumeChanged signal.
2090 fake_cras_audio_client_->set_notify_volume_change_with_delay(true);
2091
2092 SetupAudioOutputStateDuringInitialization();
2093 EXPECT_EQ(0, test_observer_->output_volume_changed_count());
2094 EXPECT_EQ(kDefaultVolume, cras_audio_handler_->GetOutputVolumePercent());
2095
2096 // A wrong initialization OutputNodeVolumeChanged event is fired. This may
2097 // happen when Cras is not ready and drops request. The approach we use is
2098 // to log warning message, clear the penging automated volume change reasons,
2099 // and notify observers about this change.
2100 const int kVolume1 = 30;
2101 fake_cras_audio_client_->NotifyOutputNodeVolumeChangedForTesting(
2102 kInternalSpeaker.id, kVolume1);
2103 EXPECT_EQ(1, test_observer_->output_volume_changed_count());
2104 EXPECT_EQ(kVolume1, cras_audio_handler_->GetOutputVolumePercent());
2105
2106 // The later OutputNodeVolumeChanged event should notify observers.
2107 const int kVolume2 = 60;
2108 fake_cras_audio_client_->NotifyOutputNodeVolumeChangedForTesting(
2109 kInternalSpeaker.id, kVolume2);
2110 EXPECT_EQ(2, test_observer_->output_volume_changed_count());
2111 EXPECT_EQ(kVolume2, cras_audio_handler_->GetOutputVolumePercent());
2112 }
2113
1989 TEST_F(CrasAudioHandlerTest, SetOutputVolumeWithDelayedSignal) { 2114 TEST_F(CrasAudioHandlerTest, SetOutputVolumeWithDelayedSignal) {
1990 AudioNodeList audio_nodes; 2115 AudioNodeList audio_nodes;
1991 audio_nodes.push_back(kInternalSpeaker); 2116 audio_nodes.push_back(kInternalSpeaker);
1992 SetUpCrasAudioHandler(audio_nodes); 2117 SetUpCrasAudioHandler(audio_nodes);
1993 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); 2118 EXPECT_EQ(0, test_observer_->output_volume_changed_count());
1994 2119
1995 const int kDefaultVolume = 75; 2120 const int kDefaultVolume = 75;
1996 EXPECT_EQ(kDefaultVolume, cras_audio_handler_->GetOutputVolumePercent()); 2121 EXPECT_EQ(kDefaultVolume, cras_audio_handler_->GetOutputVolumePercent());
1997 2122
1998 // Disable the auto OutputNodeVolumeChanged signal. 2123 // Disable the auto OutputNodeVolumeChanged signal.
(...skipping 1294 matching lines...) Expand 10 before | Expand all | Expand 10 after
3293 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); 3418 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output));
3294 EXPECT_EQ(kInternalSpeaker.id, active_output.id); 3419 EXPECT_EQ(kInternalSpeaker.id, active_output.id);
3295 EXPECT_EQ(kInternalSpeaker.id, 3420 EXPECT_EQ(kInternalSpeaker.id,
3296 cras_audio_handler_->GetPrimaryActiveOutputNode()); 3421 cras_audio_handler_->GetPrimaryActiveOutputNode());
3297 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); 3422 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted());
3298 EXPECT_EQ(1, test_observer_->output_mute_changed_count()); 3423 EXPECT_EQ(1, test_observer_->output_mute_changed_count());
3299 EXPECT_TRUE(test_observer_->output_mute_by_system()); 3424 EXPECT_TRUE(test_observer_->output_mute_by_system());
3300 } 3425 }
3301 3426
3302 } // namespace chromeos 3427 } // 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