1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chromeos/audio/audio_devices_pref_handler_impl.h"
7 #include "base/memory/ref_counted.h"
8 #include "base/prefs/testing_pref_service.h"
9 #include "chromeos/audio/audio_device.h"
10 #include "chromeos/audio/audio_devices_pref_handler.h"
11 #include "chromeos/chromeos_pref_names.h"
12 #include "chromeos/dbus/audio_node.h"
13 #include "testing/gtest/include/gtest/gtest.h"
17 const uint64 kInternalMicId
= 10003;
18 const uint64 kHeadphoneId
= 10002;
19 const uint64 kHDMIOutputId
= 10006;
20 const uint64 kOtherTypeOutputId
= 90001;
21 const uint64 kOtherTypeInputId
= 90002;
23 const AudioDevice
kInternalMic(AudioNode(true,
31 const AudioDevice
kHeadphone(AudioNode(false,
39 const AudioDevice
kHDMIOutput(AudioNode(false,
47 const AudioDevice
kInputDeviceWithSpecialCharacters(
50 "Fake ~!@#$%^&*()_+`-=<>?,./{}|[]\\\\Mic",
52 "Other Type Input Device",
56 const AudioDevice
kOutputDeviceWithSpecialCharacters(
59 "Fake ~!@#$%^&*()_+`-=<>?,./{}|[]\\\\Headphone",
61 "Other Type Output Device",
65 class AudioDevicesPrefHandlerTest
: public testing::Test
{
67 AudioDevicesPrefHandlerTest() {}
68 ~AudioDevicesPrefHandlerTest() override
{}
70 void SetUp() override
{
71 pref_service_
.reset(new TestingPrefServiceSimple());
72 AudioDevicesPrefHandlerImpl::RegisterPrefs(pref_service_
->registry());
73 audio_pref_handler_
= new AudioDevicesPrefHandlerImpl(pref_service_
.get());
76 void TearDown() override
{ audio_pref_handler_
= NULL
; }
79 scoped_refptr
<AudioDevicesPrefHandler
> audio_pref_handler_
;
80 scoped_ptr
<TestingPrefServiceSimple
> pref_service_
;
83 DISALLOW_COPY_AND_ASSIGN(AudioDevicesPrefHandlerTest
);
86 TEST_F(AudioDevicesPrefHandlerTest
, TestDefaultValues
) {
87 // TODO(rkc): Once the bug with default preferences is fixed, fix this test
88 // also. http://crbug.com/442489
89 EXPECT_EQ(75.0, audio_pref_handler_
->GetInputGainValue(&kInternalMic
));
90 EXPECT_EQ(75.0, audio_pref_handler_
->GetOutputVolumeValue(&kHeadphone
));
91 EXPECT_EQ(75.0, audio_pref_handler_
->GetOutputVolumeValue(&kHDMIOutput
));
94 TEST_F(AudioDevicesPrefHandlerTest
, PrefsRegistered
) {
95 // The standard audio prefs are registered.
96 EXPECT_TRUE(pref_service_
->FindPreference(prefs::kAudioDevicesVolumePercent
));
97 EXPECT_TRUE(pref_service_
->FindPreference(prefs::kAudioDevicesMute
));
98 EXPECT_TRUE(pref_service_
->FindPreference(prefs::kAudioOutputAllowed
));
99 EXPECT_TRUE(pref_service_
->FindPreference(prefs::kAudioVolumePercent
));
100 EXPECT_TRUE(pref_service_
->FindPreference(prefs::kAudioMute
));
103 TEST_F(AudioDevicesPrefHandlerTest
, TestBasicInputOutputDevices
) {
104 audio_pref_handler_
->SetVolumeGainValue(kInternalMic
, 13.37);
105 EXPECT_EQ(13.37, audio_pref_handler_
->GetInputGainValue(&kInternalMic
));
106 audio_pref_handler_
->SetVolumeGainValue(kHeadphone
, 47.28);
107 EXPECT_EQ(47.28, audio_pref_handler_
->GetOutputVolumeValue(&kHeadphone
));
110 TEST_F(AudioDevicesPrefHandlerTest
, TestSpecialCharactersInDeviceNames
) {
111 audio_pref_handler_
->SetVolumeGainValue(kInputDeviceWithSpecialCharacters
,
113 audio_pref_handler_
->SetVolumeGainValue(kOutputDeviceWithSpecialCharacters
,
116 EXPECT_EQ(73.31, audio_pref_handler_
->GetInputGainValue(
117 &kInputDeviceWithSpecialCharacters
));
118 EXPECT_EQ(85.92, audio_pref_handler_
->GetOutputVolumeValue(
119 &kOutputDeviceWithSpecialCharacters
));
122 } // namespace chromeos