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

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

Issue 2510093003: Handle audio node stable device ID change (Closed)
Patch Set: update few comments Created 4 years 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 "chromeos/audio/audio_device.h" 11 #include "chromeos/audio/audio_device.h"
12 #include "chromeos/audio/audio_devices_pref_handler.h" 12 #include "chromeos/audio/audio_devices_pref_handler.h"
13 #include "chromeos/chromeos_pref_names.h" 13 #include "chromeos/chromeos_pref_names.h"
14 #include "chromeos/dbus/audio_node.h" 14 #include "chromeos/dbus/audio_node.h"
15 #include "components/prefs/scoped_user_pref_update.h"
15 #include "components/prefs/testing_pref_service.h" 16 #include "components/prefs/testing_pref_service.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 18
18 namespace chromeos { 19 namespace chromeos {
19 20
21 using testing::Values;
22
23 const uint64_t kPresetInputId = 10001;
24 const uint64_t kHeadphoneId = 10002;
20 const uint64_t kInternalMicId = 10003; 25 const uint64_t kInternalMicId = 10003;
21 const uint64_t kHeadphoneId = 10002; 26 const uint64_t kPresetOutputId = 10004;
27 const uint64_t kUSBMicId = 10005;
22 const uint64_t kHDMIOutputId = 10006; 28 const uint64_t kHDMIOutputId = 10006;
23 const uint64_t kUSBMicId = 10004;
24 const uint64_t kOtherTypeOutputId = 90001; 29 const uint64_t kOtherTypeOutputId = 90001;
25 const uint64_t kOtherTypeInputId = 90002; 30 const uint64_t kOtherTypeInputId = 90002;
26 31
27 const AudioDevice kInternalMic(AudioNode(true, 32 const char kPresetInputDeprecatedPrefKey[] = "10001 : 1";
28 kInternalMicId, 33 const char kPresetOutputDeprecatedPrefKey[] = "10004 : 0";
29 kInternalMicId,
30 "Fake Mic",
31 "INTERNAL_MIC",
32 "Internal Mic",
33 false,
34 0));
35 const AudioDevice kUSBMic(AudioNode(true,
36 kUSBMicId,
37 kUSBMicId,
38 "Fake USB Mic",
39 "USB",
40 "USB Microphone",
41 false,
42 0));
43 34
44 const AudioDevice kHeadphone(AudioNode(false, 35 const double kDefaultSoundLevel = 75.0;
45 kHeadphoneId,
46 kHeadphoneId,
47 "Fake Headphone",
48 "HEADPHONE",
49 "Headphone",
50 false,
51 0));
52 36
53 const AudioDevice kHDMIOutput(AudioNode(false, 37 const struct {
54 kHDMIOutputId, 38 bool active;
55 kHDMIOutputId, 39 bool activate_by_user;
56 "HDMI output", 40 double sound_level;
57 "HDMI", 41 bool mute;
58 "HDMI output", 42 } kPresetState = {true, true, 25.2, true};
59 false,
60 0));
61 43
62 const AudioDevice kInputDeviceWithSpecialCharacters( 44 struct AudioNodeInfo {
63 AudioNode(true, 45 bool is_input;
64 kOtherTypeInputId, 46 uint64_t id;
65 kOtherTypeInputId, 47 const char* const device_name;
66 "Fake ~!@#$%^&*()_+`-=<>?,./{}|[]\\\\Mic", 48 const char* const type;
67 "SOME_OTHER_TYPE", 49 const char* const name;
68 "Other Type Input Device", 50 };
69 true,
70 0));
71 51
72 const AudioDevice kOutputDeviceWithSpecialCharacters( 52 const AudioNodeInfo kPresetInput = {true, kPresetInputId, "Fake input",
73 AudioNode(false, 53 "INTERNAL_MIC", "Preset fake input"};
74 kOtherTypeOutputId,
75 kOtherTypeOutputId,
76 "Fake ~!@#$%^&*()_+`-=<>?,./{}|[]\\\\Headphone",
77 "SOME_OTHER_TYPE",
78 "Other Type Output Device",
79 false,
80 0));
81 54
82 class AudioDevicesPrefHandlerTest : public testing::Test { 55 const AudioNodeInfo kInternalMic = {true, kInternalMicId, "Fake Mic",
56 "INTERNAL_MIC", "Internal Mic"};
57
58 const AudioNodeInfo kUSBMic = {true, kUSBMicId, "Fake USB Mic", "USB",
59 "USB Microphone"};
60
61 const AudioNodeInfo kPresetOutput = {false, kPresetOutputId, "Fake output",
62 "HEADPHONE", "Preset fake output"};
63
64 const AudioNodeInfo kHeadphone = {false, kHeadphoneId, "Fake Headphone",
65 "HEADPHONE", "Headphone"};
66
67 const AudioNodeInfo kHDMIOutput = {false, kHDMIOutputId, "HDMI output", "HDMI",
68 "HDMI output"};
69
70 const AudioNodeInfo kInputDeviceWithSpecialCharacters = {
71 true, kOtherTypeInputId, "Fake ~!@#$%^&*()_+`-=<>?,./{}|[]\\\\Mic",
72 "SOME_OTHER_TYPE", "Other Type Input Device"};
73
74 const AudioNodeInfo kOutputDeviceWithSpecialCharacters = {
75 false, kOtherTypeOutputId, "Fake ~!@#$%^&*()_+`-=<>?,./{}|[]\\\\Headphone",
76 "SOME_OTHER_TYPE", "Other Type Output Device"};
77
78 AudioDevice CreateAudioDevice(const AudioNodeInfo& info, int version) {
79 return AudioDevice(AudioNode(
80 info.is_input, info.id, version == 2, info.id /* stable_device_id_v1 */,
81 version == 1 ? 0 : info.id ^ 0xFF /* stable_device_id_v2 */,
82 info.device_name, info.type, info.name, false, 0));
83 }
84
85 // Test param determines whether the test should test input or output devices
86 // true -> input devices
87 // false -> output_devices
88 class AudioDevicesPrefHandlerTest : public testing::TestWithParam<bool> {
83 public: 89 public:
84 AudioDevicesPrefHandlerTest() {} 90 AudioDevicesPrefHandlerTest() {}
85 ~AudioDevicesPrefHandlerTest() override {} 91 ~AudioDevicesPrefHandlerTest() override {}
86 92
87 void SetUp() override { 93 void SetUp() override {
88 pref_service_.reset(new TestingPrefServiceSimple()); 94 pref_service_.reset(new TestingPrefServiceSimple());
89 AudioDevicesPrefHandlerImpl::RegisterPrefs(pref_service_->registry()); 95 AudioDevicesPrefHandlerImpl::RegisterPrefs(pref_service_->registry());
96
97 // Set the preset pref values directly, to ensure it doesn't depend on pref
98 // handler implementation.
99 // This has to be done before audio_pref_hander_ is created, so the values
100 // are set when pref value sets up its internal state.
101 std::string preset_key = GetPresetDeviceDeprecatedPrefKey();
102 {
103 DictionaryPrefUpdate update(pref_service_.get(),
104 prefs::kAudioDevicesState);
105 base::DictionaryValue* pref = update.Get();
106 std::unique_ptr<base::DictionaryValue> state(new base::DictionaryValue());
107 state->SetBoolean("active", kPresetState.active);
108 state->SetBoolean("activate_by_user", kPresetState.activate_by_user);
109 pref->Set(preset_key, std::move(state));
110 }
111
112 {
113 DictionaryPrefUpdate update(pref_service_.get(),
114 prefs::kAudioDevicesVolumePercent);
115 base::DictionaryValue* pref = update.Get();
116 pref->SetDouble(preset_key, kPresetState.sound_level);
117 }
118
119 {
120 DictionaryPrefUpdate update(pref_service_.get(),
121 prefs::kAudioDevicesMute);
122 base::DictionaryValue* pref = update.Get();
123 pref->SetInteger(preset_key, kPresetState.mute ? 1 : 0);
124 }
125
90 audio_pref_handler_ = new AudioDevicesPrefHandlerImpl(pref_service_.get()); 126 audio_pref_handler_ = new AudioDevicesPrefHandlerImpl(pref_service_.get());
91 } 127 }
92 128
93 void TearDown() override { audio_pref_handler_ = NULL; } 129 void TearDown() override { audio_pref_handler_ = NULL; }
94 130
95 protected: 131 protected:
132 void ReloadPrefHandler() {
133 audio_pref_handler_ = new AudioDevicesPrefHandlerImpl(pref_service_.get());
134 }
135
136 AudioDevice GetDevice(int version) {
jennyz 2016/12/09 23:52:18 Can we rename it to GetDeviceWithVersion()? More s
tbarzic 2016/12/10 02:35:08 Done.
137 return CreateAudioDevice(GetParam() ? kInternalMic : kHeadphone, version);
138 }
139
140 std::string GetPresetDeviceDeprecatedPrefKey() {
141 return GetParam() ? kPresetInputDeprecatedPrefKey
142 : kPresetOutputDeprecatedPrefKey;
143 }
144
145 AudioDevice GetPresetDevice(int version) {
jennyz 2016/12/09 23:52:18 ditto
tbarzic 2016/12/10 02:35:08 Done.
146 return CreateAudioDevice(GetParam() ? kPresetInput : kPresetOutput,
147 version);
148 }
149
150 AudioDevice GetSecondaryDevice(int version) {
jennyz 2016/12/09 23:52:18 ditto
tbarzic 2016/12/10 02:35:08 Done.
151 return CreateAudioDevice(GetParam() ? kUSBMic : kHDMIOutput, version);
152 }
153
154 AudioDevice GetDeviceWithSpecialCharacters(int version) {
jennyz 2016/12/09 23:52:18 ditto
tbarzic 2016/12/10 02:35:08 Done.
155 return CreateAudioDevice(GetParam() ? kInputDeviceWithSpecialCharacters
156 : kOutputDeviceWithSpecialCharacters,
157 version);
158 }
159
160 double GetSoundLevelValue(const AudioDevice& device) {
161 return GetParam() ? audio_pref_handler_->GetInputGainValue(&device)
162 : audio_pref_handler_->GetOutputVolumeValue(&device);
163 }
164
165 void SetSoundLevelValue(const AudioDevice& device, double value) {
166 return audio_pref_handler_->SetVolumeGainValue(device, value);
167 }
168
169 void SetDeviceState(const AudioDevice& device,
170 bool active,
171 bool activated_by_user) {
172 audio_pref_handler_->SetDeviceActive(device, active, activated_by_user);
173 }
174
175 bool DeviceStateExists(const AudioDevice& device) {
176 bool unused;
177 return audio_pref_handler_->GetDeviceActive(device, &unused, &unused);
178 }
179
180 void ExpectDeviceStateEquals(const AudioDevice& device,
181 bool expect_active,
182 bool expect_activated_by_user) {
183 bool active = false;
184 bool activated_by_user = false;
185 ASSERT_TRUE(audio_pref_handler_->GetDeviceActive(device, &active,
186 &activated_by_user))
187 << " value for device " << device.id << " not found.";
188 EXPECT_EQ(expect_active, active) << " device " << device.id;
189 EXPECT_EQ(expect_activated_by_user, activated_by_user) << " device "
190 << device.id;
191 }
192
193 bool GetMute(const AudioDevice& device) {
194 return audio_pref_handler_->GetMuteValue(device);
195 }
196
197 void SetMute(const AudioDevice& device, bool value) {
198 audio_pref_handler_->SetMuteValue(device, value);
199 }
200
96 scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler_; 201 scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler_;
97 std::unique_ptr<TestingPrefServiceSimple> pref_service_; 202 std::unique_ptr<TestingPrefServiceSimple> pref_service_;
98 203
99 private: 204 private:
100 DISALLOW_COPY_AND_ASSIGN(AudioDevicesPrefHandlerTest); 205 DISALLOW_COPY_AND_ASSIGN(AudioDevicesPrefHandlerTest);
101 }; 206 };
102 207
103 TEST_F(AudioDevicesPrefHandlerTest, TestDefaultValues) { 208 INSTANTIATE_TEST_CASE_P(Input, AudioDevicesPrefHandlerTest, Values(true));
209 INSTANTIATE_TEST_CASE_P(Output, AudioDevicesPrefHandlerTest, Values(false));
210
211 TEST_P(AudioDevicesPrefHandlerTest, TestDefaultValuesV1) {
212 AudioDevice device = GetDevice(1);
213 AudioDevice secondary_device = GetSecondaryDevice(1);
214
104 // TODO(rkc): Once the bug with default preferences is fixed, fix this test 215 // TODO(rkc): Once the bug with default preferences is fixed, fix this test
105 // also. http://crbug.com/442489 216 // also. http://crbug.com/442489
106 EXPECT_EQ(75.0, audio_pref_handler_->GetInputGainValue(&kInternalMic)); 217 EXPECT_EQ(kDefaultSoundLevel, GetSoundLevelValue(device));
107 EXPECT_EQ(75.0, audio_pref_handler_->GetOutputVolumeValue(&kHeadphone)); 218 EXPECT_EQ(kDefaultSoundLevel, GetSoundLevelValue(secondary_device));
108 EXPECT_EQ(75.0, audio_pref_handler_->GetOutputVolumeValue(&kHDMIOutput)); 219
109 bool active, activate_by_user; 220 EXPECT_FALSE(DeviceStateExists(device));
110 EXPECT_FALSE(audio_pref_handler_->GetDeviceActive(kInternalMic, &active, 221 EXPECT_FALSE(DeviceStateExists(secondary_device));
111 &activate_by_user)); 222
112 EXPECT_FALSE(audio_pref_handler_->GetDeviceActive(kHeadphone, &active, 223 EXPECT_FALSE(GetMute(device));
113 &activate_by_user)); 224 EXPECT_FALSE(GetMute(secondary_device));
114 EXPECT_FALSE(audio_pref_handler_->GetDeviceActive(kHDMIOutput, &active,
115 &activate_by_user));
116 } 225 }
117 226
118 TEST_F(AudioDevicesPrefHandlerTest, PrefsRegistered) { 227 TEST_P(AudioDevicesPrefHandlerTest, TestDefaultValuesV2) {
228 AudioDevice device = GetDevice(2);
229 AudioDevice secondary_device = GetSecondaryDevice(2);
230
231 // TODO(rkc): Once the bug with default preferences is fixed, fix this test
232 // also. http://crbug.com/442489
233 EXPECT_EQ(kDefaultSoundLevel, GetSoundLevelValue(device));
234 EXPECT_EQ(kDefaultSoundLevel, GetSoundLevelValue(secondary_device));
235
236 EXPECT_FALSE(DeviceStateExists(device));
237 EXPECT_FALSE(DeviceStateExists(secondary_device));
238
239 EXPECT_FALSE(GetMute(device));
240 EXPECT_FALSE(GetMute(secondary_device));
241 }
242
243 TEST_P(AudioDevicesPrefHandlerTest, PrefsRegistered) {
119 // The standard audio prefs are registered. 244 // The standard audio prefs are registered.
120 EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioDevicesVolumePercent)); 245 EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioDevicesVolumePercent));
121 EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioDevicesMute)); 246 EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioDevicesMute));
122 EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioOutputAllowed)); 247 EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioOutputAllowed));
123 EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioVolumePercent)); 248 EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioVolumePercent));
124 EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioMute)); 249 EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioMute));
125 EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioDevicesState)); 250 EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioDevicesState));
126 } 251 }
127 252
128 TEST_F(AudioDevicesPrefHandlerTest, TestBasicInputOutputDevices) { 253 TEST_P(AudioDevicesPrefHandlerTest, SoundLevel) {
129 audio_pref_handler_->SetVolumeGainValue(kInternalMic, 13.37); 254 AudioDevice device = GetDevice(2);
130 EXPECT_EQ(13.37, audio_pref_handler_->GetInputGainValue(&kInternalMic)); 255 SetSoundLevelValue(device, 13.37);
131 audio_pref_handler_->SetVolumeGainValue(kHeadphone, 47.28); 256 EXPECT_EQ(13.37, GetSoundLevelValue(device));
132 EXPECT_EQ(47.28, audio_pref_handler_->GetOutputVolumeValue(&kHeadphone));
133 } 257 }
134 258
135 TEST_F(AudioDevicesPrefHandlerTest, TestSpecialCharactersInDeviceNames) { 259 TEST_P(AudioDevicesPrefHandlerTest, SoundLevelMigratedFromV1StableId) {
136 audio_pref_handler_->SetVolumeGainValue(kInputDeviceWithSpecialCharacters, 260 AudioDevice device_v1 = GetPresetDevice(1);
137 73.31); 261 AudioDevice device_v2 = GetPresetDevice(2);
138 audio_pref_handler_->SetVolumeGainValue(kOutputDeviceWithSpecialCharacters,
139 85.92);
140 262
141 EXPECT_EQ(73.31, audio_pref_handler_->GetInputGainValue( 263 EXPECT_EQ(kPresetState.sound_level, GetSoundLevelValue(device_v1));
142 &kInputDeviceWithSpecialCharacters)); 264 EXPECT_EQ(kPresetState.sound_level, GetSoundLevelValue(device_v2));
143 EXPECT_EQ(85.92, audio_pref_handler_->GetOutputVolumeValue( 265 // Test that v1 entry does not exist after migration - the method should
144 &kOutputDeviceWithSpecialCharacters)); 266 // return default value
jennyz 2016/12/09 23:52:18 Add a line to verify kDefaultSoundLevel is not equ
tbarzic 2016/12/10 02:35:08 Done.
267 EXPECT_EQ(kDefaultSoundLevel, GetSoundLevelValue(device_v1));
268
269 // Test that values are persisted when audio pref handler is reset.
270 ReloadPrefHandler();
271 EXPECT_EQ(kDefaultSoundLevel, GetSoundLevelValue(device_v1));
272 EXPECT_EQ(kPresetState.sound_level, GetSoundLevelValue(device_v2));
145 } 273 }
146 274
147 TEST_F(AudioDevicesPrefHandlerTest, TestDeviceStates) { 275 TEST_P(AudioDevicesPrefHandlerTest, SettingV2DeviceSoundLevelRemovesV1Entry) {
148 audio_pref_handler_->SetDeviceActive(kInternalMic, true, true); 276 AudioDevice device_v1 = GetDevice(1);
149 bool active = false; 277 AudioDevice device_v2 = GetDevice(2);
150 bool activate_by_user = false;
151 EXPECT_TRUE(audio_pref_handler_->GetDeviceActive(kInternalMic, &active,
152 &activate_by_user));
153 EXPECT_TRUE(active);
154 EXPECT_TRUE(activate_by_user);
155 278
156 audio_pref_handler_->SetDeviceActive(kHeadphone, true, false); 279 SetSoundLevelValue(device_v1, 13.37);
157 EXPECT_TRUE(audio_pref_handler_->GetDeviceActive(kHeadphone, &active, 280 EXPECT_EQ(13.37, GetSoundLevelValue(device_v1));
158 &activate_by_user));
159 EXPECT_TRUE(active);
160 EXPECT_FALSE(activate_by_user);
161 281
162 audio_pref_handler_->SetDeviceActive(kHDMIOutput, false, false); 282 SetSoundLevelValue(device_v2, 13.38);
163 EXPECT_TRUE(audio_pref_handler_->GetDeviceActive(kHDMIOutput, &active, 283 EXPECT_EQ(kDefaultSoundLevel, GetSoundLevelValue(device_v1));
164 &activate_by_user)); 284 EXPECT_EQ(13.38, GetSoundLevelValue(device_v2));
165 EXPECT_FALSE(active);
166 285
167 // Device not exist in device state prefs. 286 // Test that values are persisted when audio pref handler is reset.
168 EXPECT_FALSE(audio_pref_handler_->GetDeviceActive(kUSBMic, &active, 287 ReloadPrefHandler();
169 &activate_by_user)); 288 EXPECT_EQ(kDefaultSoundLevel, GetSoundLevelValue(device_v1));
289 EXPECT_EQ(13.38, GetSoundLevelValue(device_v2));
290 }
291
292 TEST_P(AudioDevicesPrefHandlerTest, MigrateFromGlobalSoundLevelPref) {
293 pref_service_->SetDouble(prefs::kAudioVolumePercent, 13.37);
294
295 // For devices with v1 stable device id.
296 EXPECT_EQ(13.37, GetSoundLevelValue(GetDevice(1)));
297 EXPECT_EQ(13.37, GetSoundLevelValue(GetDevice(2)));
298
299 // For devices with v2 stable id.
300 EXPECT_EQ(13.37, GetSoundLevelValue(GetSecondaryDevice(2)));
301 }
302
303 TEST_P(AudioDevicesPrefHandlerTest, Mute) {
304 AudioDevice device = GetDevice(2);
305 SetMute(device, true);
306 EXPECT_TRUE(GetMute(device));
307
308 SetMute(device, false);
309 EXPECT_FALSE(GetMute(device));
310 }
311
312 TEST_P(AudioDevicesPrefHandlerTest, MuteMigratedFromV1StableId) {
313 AudioDevice device_v1 = GetPresetDevice(1);
314 AudioDevice device_v2 = GetPresetDevice(2);
315
316 EXPECT_EQ(kPresetState.mute, GetMute(device_v1));
317 EXPECT_EQ(kPresetState.mute, GetMute(device_v2));
318 // Test that v1 entry does not exist after migration - the method should
319 // return default value
jennyz 2016/12/09 23:52:18 Add a line to verify kPresetState.mute is true, wh
tbarzic 2016/12/10 02:35:08 Done.
320 EXPECT_FALSE(GetMute(device_v1));
321
322 // Test that values are persisted when audio pref handler is reset.
323 ReloadPrefHandler();
324 EXPECT_FALSE(GetMute(device_v1));
325 EXPECT_EQ(kPresetState.mute, GetMute(device_v2));
326 }
327
328 TEST_P(AudioDevicesPrefHandlerTest, SettingV2DeviceMuteRemovesV1Entry) {
329 AudioDevice device_v1 = GetDevice(1);
330 AudioDevice device_v2 = GetDevice(2);
331
332 SetMute(device_v1, true);
333 EXPECT_TRUE(GetMute(device_v1));
334
335 SetMute(device_v2, true);
336 EXPECT_FALSE(GetMute(device_v1));
337 EXPECT_TRUE(GetMute(device_v2));
338
339 // Test that values are persisted when audio pref handler is reset.
340 ReloadPrefHandler();
341 EXPECT_FALSE(GetMute(device_v1));
342 EXPECT_TRUE(GetMute(device_v2));
343 }
344
345 TEST_P(AudioDevicesPrefHandlerTest, MigrateFromGlobalMutePref) {
346 pref_service_->SetInteger(prefs::kAudioMute, true);
347
348 // For devices with v1 stable device id.
349 EXPECT_TRUE(GetMute(GetDevice(1)));
350 EXPECT_TRUE(GetMute(GetDevice(2)));
351
352 // For devices with v2 stable id.
353 EXPECT_TRUE(GetMute(GetSecondaryDevice(2)));
354 }
355
356 TEST_P(AudioDevicesPrefHandlerTest, TestSpecialCharactersInDeviceNames) {
357 AudioDevice device = GetDeviceWithSpecialCharacters(2);
358 SetSoundLevelValue(device, 73.31);
359 EXPECT_EQ(73.31, GetSoundLevelValue(device));
360
361 SetMute(device, true);
362 EXPECT_TRUE(GetMute(device));
363
364 SetDeviceState(device, true, true);
365 ExpectDeviceStateEquals(device, true, true);
366 }
367
368 TEST_P(AudioDevicesPrefHandlerTest, TestDeviceStates) {
369 AudioDevice device = GetDevice(2);
370 SetDeviceState(device, true, true);
371 ExpectDeviceStateEquals(device, true, true);
372
373 SetDeviceState(device, true, false);
374 ExpectDeviceStateEquals(device, true, false);
375
376 SetDeviceState(device, false, false);
377 ExpectDeviceStateEquals(device, false, false);
378
379 AudioDevice secondary_device = GetSecondaryDevice(2);
380 EXPECT_FALSE(DeviceStateExists(secondary_device));
381 }
382
383 TEST_P(AudioDevicesPrefHandlerTest, TestDeviceStatesMigrateFromV1StableId) {
384 AudioDevice device_v1 = GetPresetDevice(1);
385 AudioDevice device_v2 = GetPresetDevice(2);
386
387 ExpectDeviceStateEquals(device_v1, kPresetState.active,
388 kPresetState.activate_by_user);
389 ExpectDeviceStateEquals(device_v2, kPresetState.active,
390 kPresetState.activate_by_user);
391 EXPECT_FALSE(DeviceStateExists(device_v1));
392
393 // Test that values are persisted when audio pref handler is reset.
394 ReloadPrefHandler();
395 EXPECT_FALSE(DeviceStateExists(device_v1));
396 ExpectDeviceStateEquals(device_v2, kPresetState.active,
397 kPresetState.activate_by_user);
398 }
399
400 TEST_P(AudioDevicesPrefHandlerTest, TestSettingV2DeviceStateRemovesV1Entry) {
401 AudioDevice device_v1 = GetDevice(1);
402 AudioDevice device_v2 = GetDevice(2);
403
404 SetDeviceState(device_v1, true, true);
405 ExpectDeviceStateEquals(device_v1, true, true);
406
407 SetDeviceState(device_v2, false, false);
408 EXPECT_FALSE(DeviceStateExists(device_v1));
409 ExpectDeviceStateEquals(device_v2, false, false);
410
411 // Test that values are persisted when audio pref handler is reset.
412 ReloadPrefHandler();
413 EXPECT_FALSE(DeviceStateExists(device_v1));
414 ExpectDeviceStateEquals(device_v2, false, false);
170 } 415 }
171 416
172 } // namespace chromeos 417 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698