Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 AudioClientRestarted(const AudioNodeList& audio_nodes) { | |
|
Daniel Erat
2016/08/04 00:58:19
nit: rename to RestartAudioClient()?
Qiang(Joe) Xu
2016/08/04 04:02:15
Done.
| |
| 425 fake_cras_audio_client_->NotifyAudioClientRestartedForTesting(audio_nodes); | |
| 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 Loading... | |
| 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, InitializingAudioState) { | |
| 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 AudioClientRestarted(audio_nodes); | |
| 2042 // On AudioClientRestarted, InitializingAudioState will be called, we need | |
| 2043 // to make sure the OutputNodeVolumeChanged signal returned from CRAS will | |
| 2044 // not notify UI. | |
|
Daniel Erat
2016/08/04 00:58:19
i'm confused. it doesn't look like you're calling
Qiang(Joe) Xu
2016/08/04 04:02:15
First, AudioClientRestarted is simulating (and wil
| |
| 2045 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); | |
| 2046 } | |
| 2047 | |
| 1989 TEST_F(CrasAudioHandlerTest, SetOutputVolumeWithDelayedSignal) { | 2048 TEST_F(CrasAudioHandlerTest, SetOutputVolumeWithDelayedSignal) { |
| 1990 AudioNodeList audio_nodes; | 2049 AudioNodeList audio_nodes; |
| 1991 audio_nodes.push_back(kInternalSpeaker); | 2050 audio_nodes.push_back(kInternalSpeaker); |
| 1992 SetUpCrasAudioHandler(audio_nodes); | 2051 SetUpCrasAudioHandler(audio_nodes); |
| 1993 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); | 2052 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); |
| 1994 | 2053 |
| 1995 const int kDefaultVolume = 75; | 2054 const int kDefaultVolume = 75; |
| 1996 EXPECT_EQ(kDefaultVolume, cras_audio_handler_->GetOutputVolumePercent()); | 2055 EXPECT_EQ(kDefaultVolume, cras_audio_handler_->GetOutputVolumePercent()); |
| 1997 | 2056 |
| 1998 // Disable the auto OutputNodeVolumeChanged signal. | 2057 // Disable the auto OutputNodeVolumeChanged signal. |
| (...skipping 1294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3293 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 3352 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 3294 EXPECT_EQ(kInternalSpeaker.id, active_output.id); | 3353 EXPECT_EQ(kInternalSpeaker.id, active_output.id); |
| 3295 EXPECT_EQ(kInternalSpeaker.id, | 3354 EXPECT_EQ(kInternalSpeaker.id, |
| 3296 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 3355 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 3297 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); | 3356 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); |
| 3298 EXPECT_EQ(1, test_observer_->output_mute_changed_count()); | 3357 EXPECT_EQ(1, test_observer_->output_mute_changed_count()); |
| 3299 EXPECT_TRUE(test_observer_->output_mute_by_system()); | 3358 EXPECT_TRUE(test_observer_->output_mute_by_system()); |
| 3300 } | 3359 } |
| 3301 | 3360 |
| 3302 } // namespace chromeos | 3361 } // namespace chromeos |
| OLD | NEW |