| OLD | NEW |
| 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 GetDeviceWithVersion(int version) { |
| 137 return CreateAudioDevice(GetParam() ? kInternalMic : kHeadphone, version); |
| 138 } |
| 139 |
| 140 std::string GetPresetDeviceDeprecatedPrefKey() { |
| 141 return GetParam() ? kPresetInputDeprecatedPrefKey |
| 142 : kPresetOutputDeprecatedPrefKey; |
| 143 } |
| 144 |
| 145 AudioDevice GetPresetDeviceWithVersion(int version) { |
| 146 return CreateAudioDevice(GetParam() ? kPresetInput : kPresetOutput, |
| 147 version); |
| 148 } |
| 149 |
| 150 AudioDevice GetSecondaryDeviceWithVersion(int version) { |
| 151 return CreateAudioDevice(GetParam() ? kUSBMic : kHDMIOutput, version); |
| 152 } |
| 153 |
| 154 AudioDevice GetDeviceWithSpecialCharactersWithVersion(int version) { |
| 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 = GetDeviceWithVersion(1); |
| 213 AudioDevice secondary_device = GetSecondaryDeviceWithVersion(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 = GetDeviceWithVersion(2); |
| 229 AudioDevice secondary_device = GetSecondaryDeviceWithVersion(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 = GetDeviceWithVersion(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 = GetPresetDeviceWithVersion(1); |
| 137 73.31); | 261 AudioDevice device_v2 = GetPresetDeviceWithVersion(2); |
| 138 audio_pref_handler_->SetVolumeGainValue(kOutputDeviceWithSpecialCharacters, | |
| 139 85.92); | |
| 140 | 262 |
| 141 EXPECT_EQ(73.31, audio_pref_handler_->GetInputGainValue( | 263 // Sanity check for test params - preset state should be different than the |
| 142 &kInputDeviceWithSpecialCharacters)); | 264 // default one in order for this test to make sense. |
| 143 EXPECT_EQ(85.92, audio_pref_handler_->GetOutputVolumeValue( | 265 ASSERT_NE(kDefaultSoundLevel, kPresetState.sound_level); |
| 144 &kOutputDeviceWithSpecialCharacters)); | 266 |
| 267 EXPECT_EQ(kPresetState.sound_level, GetSoundLevelValue(device_v1)); |
| 268 EXPECT_EQ(kPresetState.sound_level, GetSoundLevelValue(device_v2)); |
| 269 // Test that v1 entry does not exist after migration - the method should |
| 270 // return default value. |
| 271 EXPECT_EQ(kDefaultSoundLevel, GetSoundLevelValue(device_v1)); |
| 272 |
| 273 // Test that values are persisted when audio pref handler is reset. |
| 274 ReloadPrefHandler(); |
| 275 EXPECT_EQ(kDefaultSoundLevel, GetSoundLevelValue(device_v1)); |
| 276 EXPECT_EQ(kPresetState.sound_level, GetSoundLevelValue(device_v2)); |
| 145 } | 277 } |
| 146 | 278 |
| 147 TEST_F(AudioDevicesPrefHandlerTest, TestDeviceStates) { | 279 TEST_P(AudioDevicesPrefHandlerTest, SettingV2DeviceSoundLevelRemovesV1Entry) { |
| 148 audio_pref_handler_->SetDeviceActive(kInternalMic, true, true); | 280 AudioDevice device_v1 = GetDeviceWithVersion(1); |
| 149 bool active = false; | 281 AudioDevice device_v2 = GetDeviceWithVersion(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 | 282 |
| 156 audio_pref_handler_->SetDeviceActive(kHeadphone, true, false); | 283 SetSoundLevelValue(device_v1, 13.37); |
| 157 EXPECT_TRUE(audio_pref_handler_->GetDeviceActive(kHeadphone, &active, | 284 EXPECT_EQ(13.37, GetSoundLevelValue(device_v1)); |
| 158 &activate_by_user)); | |
| 159 EXPECT_TRUE(active); | |
| 160 EXPECT_FALSE(activate_by_user); | |
| 161 | 285 |
| 162 audio_pref_handler_->SetDeviceActive(kHDMIOutput, false, false); | 286 SetSoundLevelValue(device_v2, 13.38); |
| 163 EXPECT_TRUE(audio_pref_handler_->GetDeviceActive(kHDMIOutput, &active, | 287 EXPECT_EQ(kDefaultSoundLevel, GetSoundLevelValue(device_v1)); |
| 164 &activate_by_user)); | 288 EXPECT_EQ(13.38, GetSoundLevelValue(device_v2)); |
| 165 EXPECT_FALSE(active); | |
| 166 | 289 |
| 167 // Device not exist in device state prefs. | 290 // Test that values are persisted when audio pref handler is reset. |
| 168 EXPECT_FALSE(audio_pref_handler_->GetDeviceActive(kUSBMic, &active, | 291 ReloadPrefHandler(); |
| 169 &activate_by_user)); | 292 EXPECT_EQ(kDefaultSoundLevel, GetSoundLevelValue(device_v1)); |
| 293 EXPECT_EQ(13.38, GetSoundLevelValue(device_v2)); |
| 294 } |
| 295 |
| 296 TEST_P(AudioDevicesPrefHandlerTest, MigrateFromGlobalSoundLevelPref) { |
| 297 pref_service_->SetDouble(prefs::kAudioVolumePercent, 13.37); |
| 298 |
| 299 // For devices with v1 stable device id. |
| 300 EXPECT_EQ(13.37, GetSoundLevelValue(GetDeviceWithVersion(1))); |
| 301 EXPECT_EQ(13.37, GetSoundLevelValue(GetDeviceWithVersion(2))); |
| 302 |
| 303 // For devices with v2 stable id. |
| 304 EXPECT_EQ(13.37, GetSoundLevelValue(GetSecondaryDeviceWithVersion(2))); |
| 305 } |
| 306 |
| 307 TEST_P(AudioDevicesPrefHandlerTest, Mute) { |
| 308 AudioDevice device = GetDeviceWithVersion(2); |
| 309 SetMute(device, true); |
| 310 EXPECT_TRUE(GetMute(device)); |
| 311 |
| 312 SetMute(device, false); |
| 313 EXPECT_FALSE(GetMute(device)); |
| 314 } |
| 315 |
| 316 TEST_P(AudioDevicesPrefHandlerTest, MuteMigratedFromV1StableId) { |
| 317 AudioDevice device_v1 = GetPresetDeviceWithVersion(1); |
| 318 AudioDevice device_v2 = GetPresetDeviceWithVersion(2); |
| 319 |
| 320 // Sanity check for test params - preset state should be different than the |
| 321 // default one (mute = false) in order for this test to make sense. |
| 322 ASSERT_TRUE(kPresetState.mute); |
| 323 |
| 324 EXPECT_EQ(kPresetState.mute, GetMute(device_v1)); |
| 325 EXPECT_EQ(kPresetState.mute, GetMute(device_v2)); |
| 326 // Test that v1 entry does not exist after migration - the method should |
| 327 // return default value |
| 328 EXPECT_FALSE(GetMute(device_v1)); |
| 329 |
| 330 // Test that values are persisted when audio pref handler is reset. |
| 331 ReloadPrefHandler(); |
| 332 EXPECT_FALSE(GetMute(device_v1)); |
| 333 EXPECT_EQ(kPresetState.mute, GetMute(device_v2)); |
| 334 } |
| 335 |
| 336 TEST_P(AudioDevicesPrefHandlerTest, SettingV2DeviceMuteRemovesV1Entry) { |
| 337 AudioDevice device_v1 = GetDeviceWithVersion(1); |
| 338 AudioDevice device_v2 = GetDeviceWithVersion(2); |
| 339 |
| 340 SetMute(device_v1, true); |
| 341 EXPECT_TRUE(GetMute(device_v1)); |
| 342 |
| 343 SetMute(device_v2, true); |
| 344 EXPECT_FALSE(GetMute(device_v1)); |
| 345 EXPECT_TRUE(GetMute(device_v2)); |
| 346 |
| 347 // Test that values are persisted when audio pref handler is reset. |
| 348 ReloadPrefHandler(); |
| 349 EXPECT_FALSE(GetMute(device_v1)); |
| 350 EXPECT_TRUE(GetMute(device_v2)); |
| 351 } |
| 352 |
| 353 TEST_P(AudioDevicesPrefHandlerTest, MigrateFromGlobalMutePref) { |
| 354 pref_service_->SetInteger(prefs::kAudioMute, true); |
| 355 |
| 356 // For devices with v1 stable device id. |
| 357 EXPECT_TRUE(GetMute(GetDeviceWithVersion(1))); |
| 358 EXPECT_TRUE(GetMute(GetDeviceWithVersion(2))); |
| 359 |
| 360 // For devices with v2 stable id. |
| 361 EXPECT_TRUE(GetMute(GetSecondaryDeviceWithVersion(2))); |
| 362 } |
| 363 |
| 364 TEST_P(AudioDevicesPrefHandlerTest, TestSpecialCharactersInDeviceNames) { |
| 365 AudioDevice device = GetDeviceWithSpecialCharactersWithVersion(2); |
| 366 SetSoundLevelValue(device, 73.31); |
| 367 EXPECT_EQ(73.31, GetSoundLevelValue(device)); |
| 368 |
| 369 SetMute(device, true); |
| 370 EXPECT_TRUE(GetMute(device)); |
| 371 |
| 372 SetDeviceState(device, true, true); |
| 373 ExpectDeviceStateEquals(device, true, true); |
| 374 } |
| 375 |
| 376 TEST_P(AudioDevicesPrefHandlerTest, TestDeviceStates) { |
| 377 AudioDevice device = GetDeviceWithVersion(2); |
| 378 SetDeviceState(device, true, true); |
| 379 ExpectDeviceStateEquals(device, true, true); |
| 380 |
| 381 SetDeviceState(device, true, false); |
| 382 ExpectDeviceStateEquals(device, true, false); |
| 383 |
| 384 SetDeviceState(device, false, false); |
| 385 ExpectDeviceStateEquals(device, false, false); |
| 386 |
| 387 AudioDevice secondary_device = GetSecondaryDeviceWithVersion(2); |
| 388 EXPECT_FALSE(DeviceStateExists(secondary_device)); |
| 389 } |
| 390 |
| 391 TEST_P(AudioDevicesPrefHandlerTest, TestDeviceStatesMigrateFromV1StableId) { |
| 392 AudioDevice device_v1 = GetPresetDeviceWithVersion(1); |
| 393 AudioDevice device_v2 = GetPresetDeviceWithVersion(2); |
| 394 |
| 395 ExpectDeviceStateEquals(device_v1, kPresetState.active, |
| 396 kPresetState.activate_by_user); |
| 397 ExpectDeviceStateEquals(device_v2, kPresetState.active, |
| 398 kPresetState.activate_by_user); |
| 399 EXPECT_FALSE(DeviceStateExists(device_v1)); |
| 400 |
| 401 // Test that values are persisted when audio pref handler is reset. |
| 402 ReloadPrefHandler(); |
| 403 EXPECT_FALSE(DeviceStateExists(device_v1)); |
| 404 ExpectDeviceStateEquals(device_v2, kPresetState.active, |
| 405 kPresetState.activate_by_user); |
| 406 } |
| 407 |
| 408 TEST_P(AudioDevicesPrefHandlerTest, TestSettingV2DeviceStateRemovesV1Entry) { |
| 409 AudioDevice device_v1 = GetDeviceWithVersion(1); |
| 410 AudioDevice device_v2 = GetDeviceWithVersion(2); |
| 411 |
| 412 SetDeviceState(device_v1, true, true); |
| 413 ExpectDeviceStateEquals(device_v1, true, true); |
| 414 |
| 415 SetDeviceState(device_v2, false, false); |
| 416 EXPECT_FALSE(DeviceStateExists(device_v1)); |
| 417 ExpectDeviceStateEquals(device_v2, false, false); |
| 418 |
| 419 // Test that values are persisted when audio pref handler is reset. |
| 420 ReloadPrefHandler(); |
| 421 EXPECT_FALSE(DeviceStateExists(device_v1)); |
| 422 ExpectDeviceStateEquals(device_v2, false, false); |
| 170 } | 423 } |
| 171 | 424 |
| 172 } // namespace chromeos | 425 } // namespace chromeos |
| OLD | NEW |