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

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: Fix string format Created 4 years, 11 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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/prefs/testing_pref_service.h" 11 #include "base/prefs/testing_pref_service.h"
12 #include "chromeos/audio/audio_device.h" 12 #include "chromeos/audio/audio_device.h"
13 #include "chromeos/audio/audio_devices_pref_handler.h" 13 #include "chromeos/audio/audio_devices_pref_handler.h"
14 #include "chromeos/chromeos_pref_names.h" 14 #include "chromeos/chromeos_pref_names.h"
15 #include "chromeos/dbus/audio_node.h" 15 #include "chromeos/dbus/audio_node.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 namespace chromeos { 18 namespace chromeos {
19 19
20 const uint64_t kInternalMicId = 10003; 20 const uint64_t kInternalMicId = 10003;
21 const uint64_t kHeadphoneId = 10002; 21 const uint64_t kHeadphoneId = 10002;
22 const uint64_t kHDMIOutputId = 10006; 22 const uint64_t kHDMIOutputId = 10006;
23 const uint64_t kOtherTypeOutputId = 90001; 23 const uint64_t kOtherTypeOutputId = 90001;
24 const uint64_t kOtherTypeInputId = 90002; 24 const uint64_t kOtherTypeInputId = 90002;
25 25
26 const AudioDevice kInternalMic(AudioNode(true, 26 const AudioDevice kInternalMic(AudioNode(true,
27 kInternalMicId, 27 kInternalMicId,
28 kInternalMicId,
28 "Fake Mic", 29 "Fake Mic",
29 "INTERNAL_MIC", 30 "INTERNAL_MIC",
30 "Internal Mic", 31 "Internal Mic",
31 false, 32 false,
32 0)); 33 0));
33 34
34 const AudioDevice kHeadphone(AudioNode(false, 35 const AudioDevice kHeadphone(AudioNode(false,
35 kHeadphoneId, 36 kHeadphoneId,
37 kHeadphoneId,
36 "Fake Headphone", 38 "Fake Headphone",
37 "HEADPHONE", 39 "HEADPHONE",
38 "Headphone", 40 "Headphone",
39 false, 41 false,
40 0)); 42 0));
41 43
42 const AudioDevice kHDMIOutput(AudioNode(false, 44 const AudioDevice kHDMIOutput(AudioNode(false,
43 kHDMIOutputId, 45 kHDMIOutputId,
46 kHDMIOutputId,
44 "HDMI output", 47 "HDMI output",
45 "HDMI", 48 "HDMI",
46 "HDMI output", 49 "HDMI output",
47 false, 50 false,
48 0)); 51 0));
49 52
50 const AudioDevice kInputDeviceWithSpecialCharacters( 53 const AudioDevice kInputDeviceWithSpecialCharacters(
51 AudioNode(true, 54 AudioNode(true,
52 kOtherTypeInputId, 55 kOtherTypeInputId,
56 kOtherTypeInputId,
53 "Fake ~!@#$%^&*()_+`-=<>?,./{}|[]\\\\Mic", 57 "Fake ~!@#$%^&*()_+`-=<>?,./{}|[]\\\\Mic",
54 "SOME_OTHER_TYPE", 58 "SOME_OTHER_TYPE",
55 "Other Type Input Device", 59 "Other Type Input Device",
56 true, 60 true,
57 0)); 61 0));
58 62
59 const AudioDevice kOutputDeviceWithSpecialCharacters( 63 const AudioDevice kOutputDeviceWithSpecialCharacters(
60 AudioNode(false, 64 AudioNode(false,
61 kOtherTypeOutputId, 65 kOtherTypeOutputId,
66 kOtherTypeOutputId,
62 "Fake ~!@#$%^&*()_+`-=<>?,./{}|[]\\\\Headphone", 67 "Fake ~!@#$%^&*()_+`-=<>?,./{}|[]\\\\Headphone",
63 "SOME_OTHER_TYPE", 68 "SOME_OTHER_TYPE",
64 "Other Type Output Device", 69 "Other Type Output Device",
65 false, 70 false,
66 0)); 71 0));
67 72
68 class AudioDevicesPrefHandlerTest : public testing::Test { 73 class AudioDevicesPrefHandlerTest : public testing::Test {
69 public: 74 public:
70 AudioDevicesPrefHandlerTest() {} 75 AudioDevicesPrefHandlerTest() {}
71 ~AudioDevicesPrefHandlerTest() override {} 76 ~AudioDevicesPrefHandlerTest() override {}
(...skipping 13 matching lines...) Expand all
85 private: 90 private:
86 DISALLOW_COPY_AND_ASSIGN(AudioDevicesPrefHandlerTest); 91 DISALLOW_COPY_AND_ASSIGN(AudioDevicesPrefHandlerTest);
87 }; 92 };
88 93
89 TEST_F(AudioDevicesPrefHandlerTest, TestDefaultValues) { 94 TEST_F(AudioDevicesPrefHandlerTest, TestDefaultValues) {
90 // TODO(rkc): Once the bug with default preferences is fixed, fix this test 95 // TODO(rkc): Once the bug with default preferences is fixed, fix this test
91 // also. http://crbug.com/442489 96 // also. http://crbug.com/442489
92 EXPECT_EQ(75.0, audio_pref_handler_->GetInputGainValue(&kInternalMic)); 97 EXPECT_EQ(75.0, audio_pref_handler_->GetInputGainValue(&kInternalMic));
93 EXPECT_EQ(75.0, audio_pref_handler_->GetOutputVolumeValue(&kHeadphone)); 98 EXPECT_EQ(75.0, audio_pref_handler_->GetOutputVolumeValue(&kHeadphone));
94 EXPECT_EQ(75.0, audio_pref_handler_->GetOutputVolumeValue(&kHDMIOutput)); 99 EXPECT_EQ(75.0, audio_pref_handler_->GetOutputVolumeValue(&kHDMIOutput));
100 EXPECT_EQ(AUDIO_STATE_NOT_AVAILABLE,
101 audio_pref_handler_->GetDeviceState(kInternalMic));
102 EXPECT_EQ(AUDIO_STATE_NOT_AVAILABLE,
103 audio_pref_handler_->GetDeviceState(kHeadphone));
104 EXPECT_EQ(AUDIO_STATE_NOT_AVAILABLE,
105 audio_pref_handler_->GetDeviceState(kHDMIOutput));
95 } 106 }
96 107
97 TEST_F(AudioDevicesPrefHandlerTest, PrefsRegistered) { 108 TEST_F(AudioDevicesPrefHandlerTest, PrefsRegistered) {
98 // The standard audio prefs are registered. 109 // The standard audio prefs are registered.
99 EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioDevicesVolumePercent)); 110 EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioDevicesVolumePercent));
100 EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioDevicesMute)); 111 EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioDevicesMute));
101 EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioOutputAllowed)); 112 EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioOutputAllowed));
102 EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioVolumePercent)); 113 EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioVolumePercent));
103 EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioMute)); 114 EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioMute));
115 EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioDevicesState));
104 } 116 }
105 117
106 TEST_F(AudioDevicesPrefHandlerTest, TestBasicInputOutputDevices) { 118 TEST_F(AudioDevicesPrefHandlerTest, TestBasicInputOutputDevices) {
107 audio_pref_handler_->SetVolumeGainValue(kInternalMic, 13.37); 119 audio_pref_handler_->SetVolumeGainValue(kInternalMic, 13.37);
108 EXPECT_EQ(13.37, audio_pref_handler_->GetInputGainValue(&kInternalMic)); 120 EXPECT_EQ(13.37, audio_pref_handler_->GetInputGainValue(&kInternalMic));
109 audio_pref_handler_->SetVolumeGainValue(kHeadphone, 47.28); 121 audio_pref_handler_->SetVolumeGainValue(kHeadphone, 47.28);
110 EXPECT_EQ(47.28, audio_pref_handler_->GetOutputVolumeValue(&kHeadphone)); 122 EXPECT_EQ(47.28, audio_pref_handler_->GetOutputVolumeValue(&kHeadphone));
111 } 123 }
112 124
113 TEST_F(AudioDevicesPrefHandlerTest, TestSpecialCharactersInDeviceNames) { 125 TEST_F(AudioDevicesPrefHandlerTest, TestSpecialCharactersInDeviceNames) {
114 audio_pref_handler_->SetVolumeGainValue(kInputDeviceWithSpecialCharacters, 126 audio_pref_handler_->SetVolumeGainValue(kInputDeviceWithSpecialCharacters,
115 73.31); 127 73.31);
116 audio_pref_handler_->SetVolumeGainValue(kOutputDeviceWithSpecialCharacters, 128 audio_pref_handler_->SetVolumeGainValue(kOutputDeviceWithSpecialCharacters,
117 85.92); 129 85.92);
118 130
119 EXPECT_EQ(73.31, audio_pref_handler_->GetInputGainValue( 131 EXPECT_EQ(73.31, audio_pref_handler_->GetInputGainValue(
120 &kInputDeviceWithSpecialCharacters)); 132 &kInputDeviceWithSpecialCharacters));
121 EXPECT_EQ(85.92, audio_pref_handler_->GetOutputVolumeValue( 133 EXPECT_EQ(85.92, audio_pref_handler_->GetOutputVolumeValue(
122 &kOutputDeviceWithSpecialCharacters)); 134 &kOutputDeviceWithSpecialCharacters));
123 } 135 }
124 136
137 TEST_F(AudioDevicesPrefHandlerTest, TestDeviceStates) {
138 audio_pref_handler_->SetDeviceState(kInternalMic, AUDIO_STATE_NOT_AVAILABLE);
139 EXPECT_EQ(AUDIO_STATE_NOT_AVAILABLE,
140 audio_pref_handler_->GetDeviceState(kInternalMic));
141 audio_pref_handler_->SetDeviceState(kHeadphone, AUDIO_STATE_ACTIVE);
142 EXPECT_EQ(AUDIO_STATE_ACTIVE,
143 audio_pref_handler_->GetDeviceState(kHeadphone));
144 audio_pref_handler_->SetDeviceState(kHDMIOutput, AUDIO_STATE_INACTIVE);
145 EXPECT_EQ(AUDIO_STATE_INACTIVE,
146 audio_pref_handler_->GetDeviceState(kHDMIOutput));
147 }
148
125 } // namespace chromeos 149 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/audio/audio_devices_pref_handler_impl.cc ('k') | chromeos/audio/audio_devices_pref_handler_stub.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698