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

Side by Side Diff: chromeos/audio/audio_devices_pref_handler_impl_unittest.cc

Issue 1380103003: Store audio device's active state in preference (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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/audio_devices_pref_handler_impl.h" 5 #include "chromeos/audio/audio_devices_pref_handler_impl.h"
6 6
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/prefs/testing_pref_service.h" 8 #include "base/prefs/testing_pref_service.h"
9 #include "chromeos/audio/audio_device.h" 9 #include "chromeos/audio/audio_device.h"
10 #include "chromeos/audio/audio_devices_pref_handler.h" 10 #include "chromeos/audio/audio_devices_pref_handler.h"
11 #include "chromeos/chromeos_pref_names.h" 11 #include "chromeos/chromeos_pref_names.h"
12 #include "chromeos/dbus/audio_node.h" 12 #include "chromeos/dbus/audio_node.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace chromeos { 15 namespace chromeos {
16 16
17 const uint64 kInternalMicId = 10003; 17 const uint64 kInternalMicId = 10003;
18 const uint64 kHeadphoneId = 10002; 18 const uint64 kHeadphoneId = 10002;
19 const uint64 kHDMIOutputId = 10006; 19 const uint64 kHDMIOutputId = 10006;
20 const uint64 kOtherTypeOutputId = 90001; 20 const uint64 kOtherTypeOutputId = 90001;
21 const uint64 kOtherTypeInputId = 90002; 21 const uint64 kOtherTypeInputId = 90002;
22 22
23 const AudioDevice kInternalMic(AudioNode(true, 23 const AudioDevice kInternalMic(AudioNode(true,
24 kInternalMicId, 24 kInternalMicId,
25 kInternalMicId,
25 "Fake Mic", 26 "Fake Mic",
26 "INTERNAL_MIC", 27 "INTERNAL_MIC",
27 "Internal Mic", 28 "Internal Mic",
28 false, 29 false,
29 0)); 30 0));
30 31
31 const AudioDevice kHeadphone(AudioNode(false, 32 const AudioDevice kHeadphone(AudioNode(false,
32 kHeadphoneId, 33 kHeadphoneId,
34 kHeadphoneId,
33 "Fake Headphone", 35 "Fake Headphone",
34 "HEADPHONE", 36 "HEADPHONE",
35 "Headphone", 37 "Headphone",
36 false, 38 false,
37 0)); 39 0));
38 40
39 const AudioDevice kHDMIOutput(AudioNode(false, 41 const AudioDevice kHDMIOutput(AudioNode(false,
40 kHDMIOutputId, 42 kHDMIOutputId,
43 kHDMIOutputId,
41 "HDMI output", 44 "HDMI output",
42 "HDMI", 45 "HDMI",
43 "HDMI output", 46 "HDMI output",
44 false, 47 false,
45 0)); 48 0));
46 49
47 const AudioDevice kInputDeviceWithSpecialCharacters( 50 const AudioDevice kInputDeviceWithSpecialCharacters(
48 AudioNode(true, 51 AudioNode(true,
49 kOtherTypeInputId, 52 kOtherTypeInputId,
53 kOtherTypeInputId,
50 "Fake ~!@#$%^&*()_+`-=<>?,./{}|[]\\\\Mic", 54 "Fake ~!@#$%^&*()_+`-=<>?,./{}|[]\\\\Mic",
51 "SOME_OTHER_TYPE", 55 "SOME_OTHER_TYPE",
52 "Other Type Input Device", 56 "Other Type Input Device",
53 true, 57 true,
54 0)); 58 0));
55 59
56 const AudioDevice kOutputDeviceWithSpecialCharacters( 60 const AudioDevice kOutputDeviceWithSpecialCharacters(
57 AudioNode(false, 61 AudioNode(false,
58 kOtherTypeOutputId, 62 kOtherTypeOutputId,
63 kOtherTypeOutputId,
59 "Fake ~!@#$%^&*()_+`-=<>?,./{}|[]\\\\Headphone", 64 "Fake ~!@#$%^&*()_+`-=<>?,./{}|[]\\\\Headphone",
60 "SOME_OTHER_TYPE", 65 "SOME_OTHER_TYPE",
61 "Other Type Output Device", 66 "Other Type Output Device",
62 false, 67 false,
63 0)); 68 0));
64 69
65 class AudioDevicesPrefHandlerTest : public testing::Test { 70 class AudioDevicesPrefHandlerTest : public testing::Test {
66 public: 71 public:
67 AudioDevicesPrefHandlerTest() {} 72 AudioDevicesPrefHandlerTest() {}
68 ~AudioDevicesPrefHandlerTest() override {} 73 ~AudioDevicesPrefHandlerTest() override {}
(...skipping 13 matching lines...) Expand all
82 private: 87 private:
83 DISALLOW_COPY_AND_ASSIGN(AudioDevicesPrefHandlerTest); 88 DISALLOW_COPY_AND_ASSIGN(AudioDevicesPrefHandlerTest);
84 }; 89 };
85 90
86 TEST_F(AudioDevicesPrefHandlerTest, TestDefaultValues) { 91 TEST_F(AudioDevicesPrefHandlerTest, TestDefaultValues) {
87 // TODO(rkc): Once the bug with default preferences is fixed, fix this test 92 // TODO(rkc): Once the bug with default preferences is fixed, fix this test
88 // also. http://crbug.com/442489 93 // also. http://crbug.com/442489
89 EXPECT_EQ(75.0, audio_pref_handler_->GetInputGainValue(&kInternalMic)); 94 EXPECT_EQ(75.0, audio_pref_handler_->GetInputGainValue(&kInternalMic));
90 EXPECT_EQ(75.0, audio_pref_handler_->GetOutputVolumeValue(&kHeadphone)); 95 EXPECT_EQ(75.0, audio_pref_handler_->GetOutputVolumeValue(&kHeadphone));
91 EXPECT_EQ(75.0, audio_pref_handler_->GetOutputVolumeValue(&kHDMIOutput)); 96 EXPECT_EQ(75.0, audio_pref_handler_->GetOutputVolumeValue(&kHDMIOutput));
97 EXPECT_EQ(AUDIO_STATE_NOT_AVAILABLE,
98 audio_pref_handler_->GetDeviceState(kInternalMic));
99 EXPECT_EQ(AUDIO_STATE_NOT_AVAILABLE,
100 audio_pref_handler_->GetDeviceState(kHeadphone));
101 EXPECT_EQ(AUDIO_STATE_NOT_AVAILABLE,
102 audio_pref_handler_->GetDeviceState(kHDMIOutput));
92 } 103 }
93 104
94 TEST_F(AudioDevicesPrefHandlerTest, PrefsRegistered) { 105 TEST_F(AudioDevicesPrefHandlerTest, PrefsRegistered) {
95 // The standard audio prefs are registered. 106 // The standard audio prefs are registered.
96 EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioDevicesVolumePercent)); 107 EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioDevicesVolumePercent));
97 EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioDevicesMute)); 108 EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioDevicesMute));
98 EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioOutputAllowed)); 109 EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioOutputAllowed));
99 EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioVolumePercent)); 110 EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioVolumePercent));
100 EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioMute)); 111 EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioMute));
112 EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioDevicesState));
101 } 113 }
102 114
103 TEST_F(AudioDevicesPrefHandlerTest, TestBasicInputOutputDevices) { 115 TEST_F(AudioDevicesPrefHandlerTest, TestBasicInputOutputDevices) {
104 audio_pref_handler_->SetVolumeGainValue(kInternalMic, 13.37); 116 audio_pref_handler_->SetVolumeGainValue(kInternalMic, 13.37);
105 EXPECT_EQ(13.37, audio_pref_handler_->GetInputGainValue(&kInternalMic)); 117 EXPECT_EQ(13.37, audio_pref_handler_->GetInputGainValue(&kInternalMic));
106 audio_pref_handler_->SetVolumeGainValue(kHeadphone, 47.28); 118 audio_pref_handler_->SetVolumeGainValue(kHeadphone, 47.28);
107 EXPECT_EQ(47.28, audio_pref_handler_->GetOutputVolumeValue(&kHeadphone)); 119 EXPECT_EQ(47.28, audio_pref_handler_->GetOutputVolumeValue(&kHeadphone));
108 } 120 }
109 121
110 TEST_F(AudioDevicesPrefHandlerTest, TestSpecialCharactersInDeviceNames) { 122 TEST_F(AudioDevicesPrefHandlerTest, TestSpecialCharactersInDeviceNames) {
111 audio_pref_handler_->SetVolumeGainValue(kInputDeviceWithSpecialCharacters, 123 audio_pref_handler_->SetVolumeGainValue(kInputDeviceWithSpecialCharacters,
112 73.31); 124 73.31);
113 audio_pref_handler_->SetVolumeGainValue(kOutputDeviceWithSpecialCharacters, 125 audio_pref_handler_->SetVolumeGainValue(kOutputDeviceWithSpecialCharacters,
114 85.92); 126 85.92);
115 127
116 EXPECT_EQ(73.31, audio_pref_handler_->GetInputGainValue( 128 EXPECT_EQ(73.31, audio_pref_handler_->GetInputGainValue(
117 &kInputDeviceWithSpecialCharacters)); 129 &kInputDeviceWithSpecialCharacters));
118 EXPECT_EQ(85.92, audio_pref_handler_->GetOutputVolumeValue( 130 EXPECT_EQ(85.92, audio_pref_handler_->GetOutputVolumeValue(
119 &kOutputDeviceWithSpecialCharacters)); 131 &kOutputDeviceWithSpecialCharacters));
120 } 132 }
121 133
jennyz 2015/12/17 22:50:21 Would you please add a test case to test the write
hychao 2015/12/29 10:57:25 Done.
122 } // namespace chromeos 134 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698