| Index: chromeos/audio/audio_devices_pref_handler_impl_unittest.cc
|
| diff --git a/chromeos/audio/audio_devices_pref_handler_impl_unittest.cc b/chromeos/audio/audio_devices_pref_handler_impl_unittest.cc
|
| index 5f61c7c87fc2d08e3be5669a798f1e990d80a8cb..7744f28e37b50f2cde569938ba70e96f0e80d1be 100644
|
| --- a/chromeos/audio/audio_devices_pref_handler_impl_unittest.cc
|
| +++ b/chromeos/audio/audio_devices_pref_handler_impl_unittest.cc
|
| @@ -12,74 +12,80 @@
|
| #include "chromeos/audio/audio_devices_pref_handler.h"
|
| #include "chromeos/chromeos_pref_names.h"
|
| #include "chromeos/dbus/audio_node.h"
|
| +#include "components/prefs/scoped_user_pref_update.h"
|
| #include "components/prefs/testing_pref_service.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| namespace chromeos {
|
|
|
| -const uint64_t kInternalMicId = 10003;
|
| +using testing::Values;
|
| +
|
| +const uint64_t kPresetInputId = 10001;
|
| const uint64_t kHeadphoneId = 10002;
|
| +const uint64_t kInternalMicId = 10003;
|
| +const uint64_t kPresetOutputId = 10004;
|
| +const uint64_t kUSBMicId = 10005;
|
| const uint64_t kHDMIOutputId = 10006;
|
| -const uint64_t kUSBMicId = 10004;
|
| const uint64_t kOtherTypeOutputId = 90001;
|
| const uint64_t kOtherTypeInputId = 90002;
|
|
|
| -const AudioDevice kInternalMic(AudioNode(true,
|
| - kInternalMicId,
|
| - kInternalMicId,
|
| - "Fake Mic",
|
| - "INTERNAL_MIC",
|
| - "Internal Mic",
|
| - false,
|
| - 0));
|
| -const AudioDevice kUSBMic(AudioNode(true,
|
| - kUSBMicId,
|
| - kUSBMicId,
|
| - "Fake USB Mic",
|
| - "USB",
|
| - "USB Microphone",
|
| - false,
|
| - 0));
|
| -
|
| -const AudioDevice kHeadphone(AudioNode(false,
|
| - kHeadphoneId,
|
| - kHeadphoneId,
|
| - "Fake Headphone",
|
| - "HEADPHONE",
|
| - "Headphone",
|
| - false,
|
| - 0));
|
| -
|
| -const AudioDevice kHDMIOutput(AudioNode(false,
|
| - kHDMIOutputId,
|
| - kHDMIOutputId,
|
| - "HDMI output",
|
| - "HDMI",
|
| - "HDMI output",
|
| - false,
|
| - 0));
|
| -
|
| -const AudioDevice kInputDeviceWithSpecialCharacters(
|
| - AudioNode(true,
|
| - kOtherTypeInputId,
|
| - kOtherTypeInputId,
|
| - "Fake ~!@#$%^&*()_+`-=<>?,./{}|[]\\\\Mic",
|
| - "SOME_OTHER_TYPE",
|
| - "Other Type Input Device",
|
| - true,
|
| - 0));
|
| -
|
| -const AudioDevice kOutputDeviceWithSpecialCharacters(
|
| - AudioNode(false,
|
| - kOtherTypeOutputId,
|
| - kOtherTypeOutputId,
|
| - "Fake ~!@#$%^&*()_+`-=<>?,./{}|[]\\\\Headphone",
|
| - "SOME_OTHER_TYPE",
|
| - "Other Type Output Device",
|
| - false,
|
| - 0));
|
| -
|
| -class AudioDevicesPrefHandlerTest : public testing::Test {
|
| +const char kPresetInputDeprecatedPrefKey[] = "10001 : 1";
|
| +const char kPresetOutputDeprecatedPrefKey[] = "10004 : 0";
|
| +
|
| +const double kDefaultSoundLevel = 75.0;
|
| +
|
| +const struct {
|
| + bool active;
|
| + bool activate_by_user;
|
| + double sound_level;
|
| + bool mute;
|
| +} kPresetState = {true, true, 25.2, true};
|
| +
|
| +struct AudioNodeInfo {
|
| + bool is_input;
|
| + uint64_t id;
|
| + const char* const device_name;
|
| + const char* const type;
|
| + const char* const name;
|
| +};
|
| +
|
| +const AudioNodeInfo kPresetInput = {true, kPresetInputId, "Fake input",
|
| + "INTERNAL_MIC", "Preset fake input"};
|
| +
|
| +const AudioNodeInfo kInternalMic = {true, kInternalMicId, "Fake Mic",
|
| + "INTERNAL_MIC", "Internal Mic"};
|
| +
|
| +const AudioNodeInfo kUSBMic = {true, kUSBMicId, "Fake USB Mic", "USB",
|
| + "USB Microphone"};
|
| +
|
| +const AudioNodeInfo kPresetOutput = {false, kPresetOutputId, "Fake output",
|
| + "HEADPHONE", "Preset fake output"};
|
| +
|
| +const AudioNodeInfo kHeadphone = {false, kHeadphoneId, "Fake Headphone",
|
| + "HEADPHONE", "Headphone"};
|
| +
|
| +const AudioNodeInfo kHDMIOutput = {false, kHDMIOutputId, "HDMI output", "HDMI",
|
| + "HDMI output"};
|
| +
|
| +const AudioNodeInfo kInputDeviceWithSpecialCharacters = {
|
| + true, kOtherTypeInputId, "Fake ~!@#$%^&*()_+`-=<>?,./{}|[]\\\\Mic",
|
| + "SOME_OTHER_TYPE", "Other Type Input Device"};
|
| +
|
| +const AudioNodeInfo kOutputDeviceWithSpecialCharacters = {
|
| + false, kOtherTypeOutputId, "Fake ~!@#$%^&*()_+`-=<>?,./{}|[]\\\\Headphone",
|
| + "SOME_OTHER_TYPE", "Other Type Output Device"};
|
| +
|
| +AudioDevice CreateAudioDevice(const AudioNodeInfo& info, int version) {
|
| + return AudioDevice(AudioNode(
|
| + info.is_input, info.id, version == 2, info.id /* stable_device_id_v1 */,
|
| + version == 1 ? 0 : info.id ^ 0xFF /* stable_device_id_v2 */,
|
| + info.device_name, info.type, info.name, false, 0));
|
| +}
|
| +
|
| +// Test param determines whether the test should test input or output devices
|
| +// true -> input devices
|
| +// false -> output_devices
|
| +class AudioDevicesPrefHandlerTest : public testing::TestWithParam<bool> {
|
| public:
|
| AudioDevicesPrefHandlerTest() {}
|
| ~AudioDevicesPrefHandlerTest() override {}
|
| @@ -87,12 +93,111 @@ class AudioDevicesPrefHandlerTest : public testing::Test {
|
| void SetUp() override {
|
| pref_service_.reset(new TestingPrefServiceSimple());
|
| AudioDevicesPrefHandlerImpl::RegisterPrefs(pref_service_->registry());
|
| +
|
| + // Set the preset pref values directly, to ensure it doesn't depend on pref
|
| + // handler implementation.
|
| + // This has to be done before audio_pref_hander_ is created, so the values
|
| + // are set when pref value sets up its internal state.
|
| + std::string preset_key = GetPresetDeviceDeprecatedPrefKey();
|
| + {
|
| + DictionaryPrefUpdate update(pref_service_.get(),
|
| + prefs::kAudioDevicesState);
|
| + base::DictionaryValue* pref = update.Get();
|
| + std::unique_ptr<base::DictionaryValue> state(new base::DictionaryValue());
|
| + state->SetBoolean("active", kPresetState.active);
|
| + state->SetBoolean("activate_by_user", kPresetState.activate_by_user);
|
| + pref->Set(preset_key, std::move(state));
|
| + }
|
| +
|
| + {
|
| + DictionaryPrefUpdate update(pref_service_.get(),
|
| + prefs::kAudioDevicesVolumePercent);
|
| + base::DictionaryValue* pref = update.Get();
|
| + pref->SetDouble(preset_key, kPresetState.sound_level);
|
| + }
|
| +
|
| + {
|
| + DictionaryPrefUpdate update(pref_service_.get(),
|
| + prefs::kAudioDevicesMute);
|
| + base::DictionaryValue* pref = update.Get();
|
| + pref->SetInteger(preset_key, kPresetState.mute ? 1 : 0);
|
| + }
|
| +
|
| audio_pref_handler_ = new AudioDevicesPrefHandlerImpl(pref_service_.get());
|
| }
|
|
|
| void TearDown() override { audio_pref_handler_ = NULL; }
|
|
|
| protected:
|
| + void ReloadPrefHandler() {
|
| + audio_pref_handler_ = new AudioDevicesPrefHandlerImpl(pref_service_.get());
|
| + }
|
| +
|
| + AudioDevice GetDeviceWithVersion(int version) {
|
| + return CreateAudioDevice(GetParam() ? kInternalMic : kHeadphone, version);
|
| + }
|
| +
|
| + std::string GetPresetDeviceDeprecatedPrefKey() {
|
| + return GetParam() ? kPresetInputDeprecatedPrefKey
|
| + : kPresetOutputDeprecatedPrefKey;
|
| + }
|
| +
|
| + AudioDevice GetPresetDeviceWithVersion(int version) {
|
| + return CreateAudioDevice(GetParam() ? kPresetInput : kPresetOutput,
|
| + version);
|
| + }
|
| +
|
| + AudioDevice GetSecondaryDeviceWithVersion(int version) {
|
| + return CreateAudioDevice(GetParam() ? kUSBMic : kHDMIOutput, version);
|
| + }
|
| +
|
| + AudioDevice GetDeviceWithSpecialCharactersWithVersion(int version) {
|
| + return CreateAudioDevice(GetParam() ? kInputDeviceWithSpecialCharacters
|
| + : kOutputDeviceWithSpecialCharacters,
|
| + version);
|
| + }
|
| +
|
| + double GetSoundLevelValue(const AudioDevice& device) {
|
| + return GetParam() ? audio_pref_handler_->GetInputGainValue(&device)
|
| + : audio_pref_handler_->GetOutputVolumeValue(&device);
|
| + }
|
| +
|
| + void SetSoundLevelValue(const AudioDevice& device, double value) {
|
| + return audio_pref_handler_->SetVolumeGainValue(device, value);
|
| + }
|
| +
|
| + void SetDeviceState(const AudioDevice& device,
|
| + bool active,
|
| + bool activated_by_user) {
|
| + audio_pref_handler_->SetDeviceActive(device, active, activated_by_user);
|
| + }
|
| +
|
| + bool DeviceStateExists(const AudioDevice& device) {
|
| + bool unused;
|
| + return audio_pref_handler_->GetDeviceActive(device, &unused, &unused);
|
| + }
|
| +
|
| + void ExpectDeviceStateEquals(const AudioDevice& device,
|
| + bool expect_active,
|
| + bool expect_activated_by_user) {
|
| + bool active = false;
|
| + bool activated_by_user = false;
|
| + ASSERT_TRUE(audio_pref_handler_->GetDeviceActive(device, &active,
|
| + &activated_by_user))
|
| + << " value for device " << device.id << " not found.";
|
| + EXPECT_EQ(expect_active, active) << " device " << device.id;
|
| + EXPECT_EQ(expect_activated_by_user, activated_by_user) << " device "
|
| + << device.id;
|
| + }
|
| +
|
| + bool GetMute(const AudioDevice& device) {
|
| + return audio_pref_handler_->GetMuteValue(device);
|
| + }
|
| +
|
| + void SetMute(const AudioDevice& device, bool value) {
|
| + audio_pref_handler_->SetMuteValue(device, value);
|
| + }
|
| +
|
| scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler_;
|
| std::unique_ptr<TestingPrefServiceSimple> pref_service_;
|
|
|
| @@ -100,22 +205,42 @@ class AudioDevicesPrefHandlerTest : public testing::Test {
|
| DISALLOW_COPY_AND_ASSIGN(AudioDevicesPrefHandlerTest);
|
| };
|
|
|
| -TEST_F(AudioDevicesPrefHandlerTest, TestDefaultValues) {
|
| +INSTANTIATE_TEST_CASE_P(Input, AudioDevicesPrefHandlerTest, Values(true));
|
| +INSTANTIATE_TEST_CASE_P(Output, AudioDevicesPrefHandlerTest, Values(false));
|
| +
|
| +TEST_P(AudioDevicesPrefHandlerTest, TestDefaultValuesV1) {
|
| + AudioDevice device = GetDeviceWithVersion(1);
|
| + AudioDevice secondary_device = GetSecondaryDeviceWithVersion(1);
|
| +
|
| // TODO(rkc): Once the bug with default preferences is fixed, fix this test
|
| // also. http://crbug.com/442489
|
| - EXPECT_EQ(75.0, audio_pref_handler_->GetInputGainValue(&kInternalMic));
|
| - EXPECT_EQ(75.0, audio_pref_handler_->GetOutputVolumeValue(&kHeadphone));
|
| - EXPECT_EQ(75.0, audio_pref_handler_->GetOutputVolumeValue(&kHDMIOutput));
|
| - bool active, activate_by_user;
|
| - EXPECT_FALSE(audio_pref_handler_->GetDeviceActive(kInternalMic, &active,
|
| - &activate_by_user));
|
| - EXPECT_FALSE(audio_pref_handler_->GetDeviceActive(kHeadphone, &active,
|
| - &activate_by_user));
|
| - EXPECT_FALSE(audio_pref_handler_->GetDeviceActive(kHDMIOutput, &active,
|
| - &activate_by_user));
|
| -}
|
| -
|
| -TEST_F(AudioDevicesPrefHandlerTest, PrefsRegistered) {
|
| + EXPECT_EQ(kDefaultSoundLevel, GetSoundLevelValue(device));
|
| + EXPECT_EQ(kDefaultSoundLevel, GetSoundLevelValue(secondary_device));
|
| +
|
| + EXPECT_FALSE(DeviceStateExists(device));
|
| + EXPECT_FALSE(DeviceStateExists(secondary_device));
|
| +
|
| + EXPECT_FALSE(GetMute(device));
|
| + EXPECT_FALSE(GetMute(secondary_device));
|
| +}
|
| +
|
| +TEST_P(AudioDevicesPrefHandlerTest, TestDefaultValuesV2) {
|
| + AudioDevice device = GetDeviceWithVersion(2);
|
| + AudioDevice secondary_device = GetSecondaryDeviceWithVersion(2);
|
| +
|
| + // TODO(rkc): Once the bug with default preferences is fixed, fix this test
|
| + // also. http://crbug.com/442489
|
| + EXPECT_EQ(kDefaultSoundLevel, GetSoundLevelValue(device));
|
| + EXPECT_EQ(kDefaultSoundLevel, GetSoundLevelValue(secondary_device));
|
| +
|
| + EXPECT_FALSE(DeviceStateExists(device));
|
| + EXPECT_FALSE(DeviceStateExists(secondary_device));
|
| +
|
| + EXPECT_FALSE(GetMute(device));
|
| + EXPECT_FALSE(GetMute(secondary_device));
|
| +}
|
| +
|
| +TEST_P(AudioDevicesPrefHandlerTest, PrefsRegistered) {
|
| // The standard audio prefs are registered.
|
| EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioDevicesVolumePercent));
|
| EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioDevicesMute));
|
| @@ -125,48 +250,176 @@ TEST_F(AudioDevicesPrefHandlerTest, PrefsRegistered) {
|
| EXPECT_TRUE(pref_service_->FindPreference(prefs::kAudioDevicesState));
|
| }
|
|
|
| -TEST_F(AudioDevicesPrefHandlerTest, TestBasicInputOutputDevices) {
|
| - audio_pref_handler_->SetVolumeGainValue(kInternalMic, 13.37);
|
| - EXPECT_EQ(13.37, audio_pref_handler_->GetInputGainValue(&kInternalMic));
|
| - audio_pref_handler_->SetVolumeGainValue(kHeadphone, 47.28);
|
| - EXPECT_EQ(47.28, audio_pref_handler_->GetOutputVolumeValue(&kHeadphone));
|
| -}
|
| -
|
| -TEST_F(AudioDevicesPrefHandlerTest, TestSpecialCharactersInDeviceNames) {
|
| - audio_pref_handler_->SetVolumeGainValue(kInputDeviceWithSpecialCharacters,
|
| - 73.31);
|
| - audio_pref_handler_->SetVolumeGainValue(kOutputDeviceWithSpecialCharacters,
|
| - 85.92);
|
| -
|
| - EXPECT_EQ(73.31, audio_pref_handler_->GetInputGainValue(
|
| - &kInputDeviceWithSpecialCharacters));
|
| - EXPECT_EQ(85.92, audio_pref_handler_->GetOutputVolumeValue(
|
| - &kOutputDeviceWithSpecialCharacters));
|
| -}
|
| -
|
| -TEST_F(AudioDevicesPrefHandlerTest, TestDeviceStates) {
|
| - audio_pref_handler_->SetDeviceActive(kInternalMic, true, true);
|
| - bool active = false;
|
| - bool activate_by_user = false;
|
| - EXPECT_TRUE(audio_pref_handler_->GetDeviceActive(kInternalMic, &active,
|
| - &activate_by_user));
|
| - EXPECT_TRUE(active);
|
| - EXPECT_TRUE(activate_by_user);
|
| -
|
| - audio_pref_handler_->SetDeviceActive(kHeadphone, true, false);
|
| - EXPECT_TRUE(audio_pref_handler_->GetDeviceActive(kHeadphone, &active,
|
| - &activate_by_user));
|
| - EXPECT_TRUE(active);
|
| - EXPECT_FALSE(activate_by_user);
|
| -
|
| - audio_pref_handler_->SetDeviceActive(kHDMIOutput, false, false);
|
| - EXPECT_TRUE(audio_pref_handler_->GetDeviceActive(kHDMIOutput, &active,
|
| - &activate_by_user));
|
| - EXPECT_FALSE(active);
|
| -
|
| - // Device not exist in device state prefs.
|
| - EXPECT_FALSE(audio_pref_handler_->GetDeviceActive(kUSBMic, &active,
|
| - &activate_by_user));
|
| +TEST_P(AudioDevicesPrefHandlerTest, SoundLevel) {
|
| + AudioDevice device = GetDeviceWithVersion(2);
|
| + SetSoundLevelValue(device, 13.37);
|
| + EXPECT_EQ(13.37, GetSoundLevelValue(device));
|
| +}
|
| +
|
| +TEST_P(AudioDevicesPrefHandlerTest, SoundLevelMigratedFromV1StableId) {
|
| + AudioDevice device_v1 = GetPresetDeviceWithVersion(1);
|
| + AudioDevice device_v2 = GetPresetDeviceWithVersion(2);
|
| +
|
| + // Sanity check for test params - preset state should be different than the
|
| + // default one in order for this test to make sense.
|
| + ASSERT_NE(kDefaultSoundLevel, kPresetState.sound_level);
|
| +
|
| + EXPECT_EQ(kPresetState.sound_level, GetSoundLevelValue(device_v1));
|
| + EXPECT_EQ(kPresetState.sound_level, GetSoundLevelValue(device_v2));
|
| + // Test that v1 entry does not exist after migration - the method should
|
| + // return default value.
|
| + EXPECT_EQ(kDefaultSoundLevel, GetSoundLevelValue(device_v1));
|
| +
|
| + // Test that values are persisted when audio pref handler is reset.
|
| + ReloadPrefHandler();
|
| + EXPECT_EQ(kDefaultSoundLevel, GetSoundLevelValue(device_v1));
|
| + EXPECT_EQ(kPresetState.sound_level, GetSoundLevelValue(device_v2));
|
| +}
|
| +
|
| +TEST_P(AudioDevicesPrefHandlerTest, SettingV2DeviceSoundLevelRemovesV1Entry) {
|
| + AudioDevice device_v1 = GetDeviceWithVersion(1);
|
| + AudioDevice device_v2 = GetDeviceWithVersion(2);
|
| +
|
| + SetSoundLevelValue(device_v1, 13.37);
|
| + EXPECT_EQ(13.37, GetSoundLevelValue(device_v1));
|
| +
|
| + SetSoundLevelValue(device_v2, 13.38);
|
| + EXPECT_EQ(kDefaultSoundLevel, GetSoundLevelValue(device_v1));
|
| + EXPECT_EQ(13.38, GetSoundLevelValue(device_v2));
|
| +
|
| + // Test that values are persisted when audio pref handler is reset.
|
| + ReloadPrefHandler();
|
| + EXPECT_EQ(kDefaultSoundLevel, GetSoundLevelValue(device_v1));
|
| + EXPECT_EQ(13.38, GetSoundLevelValue(device_v2));
|
| +}
|
| +
|
| +TEST_P(AudioDevicesPrefHandlerTest, MigrateFromGlobalSoundLevelPref) {
|
| + pref_service_->SetDouble(prefs::kAudioVolumePercent, 13.37);
|
| +
|
| + // For devices with v1 stable device id.
|
| + EXPECT_EQ(13.37, GetSoundLevelValue(GetDeviceWithVersion(1)));
|
| + EXPECT_EQ(13.37, GetSoundLevelValue(GetDeviceWithVersion(2)));
|
| +
|
| + // For devices with v2 stable id.
|
| + EXPECT_EQ(13.37, GetSoundLevelValue(GetSecondaryDeviceWithVersion(2)));
|
| +}
|
| +
|
| +TEST_P(AudioDevicesPrefHandlerTest, Mute) {
|
| + AudioDevice device = GetDeviceWithVersion(2);
|
| + SetMute(device, true);
|
| + EXPECT_TRUE(GetMute(device));
|
| +
|
| + SetMute(device, false);
|
| + EXPECT_FALSE(GetMute(device));
|
| +}
|
| +
|
| +TEST_P(AudioDevicesPrefHandlerTest, MuteMigratedFromV1StableId) {
|
| + AudioDevice device_v1 = GetPresetDeviceWithVersion(1);
|
| + AudioDevice device_v2 = GetPresetDeviceWithVersion(2);
|
| +
|
| + // Sanity check for test params - preset state should be different than the
|
| + // default one (mute = false) in order for this test to make sense.
|
| + ASSERT_TRUE(kPresetState.mute);
|
| +
|
| + EXPECT_EQ(kPresetState.mute, GetMute(device_v1));
|
| + EXPECT_EQ(kPresetState.mute, GetMute(device_v2));
|
| + // Test that v1 entry does not exist after migration - the method should
|
| + // return default value
|
| + EXPECT_FALSE(GetMute(device_v1));
|
| +
|
| + // Test that values are persisted when audio pref handler is reset.
|
| + ReloadPrefHandler();
|
| + EXPECT_FALSE(GetMute(device_v1));
|
| + EXPECT_EQ(kPresetState.mute, GetMute(device_v2));
|
| +}
|
| +
|
| +TEST_P(AudioDevicesPrefHandlerTest, SettingV2DeviceMuteRemovesV1Entry) {
|
| + AudioDevice device_v1 = GetDeviceWithVersion(1);
|
| + AudioDevice device_v2 = GetDeviceWithVersion(2);
|
| +
|
| + SetMute(device_v1, true);
|
| + EXPECT_TRUE(GetMute(device_v1));
|
| +
|
| + SetMute(device_v2, true);
|
| + EXPECT_FALSE(GetMute(device_v1));
|
| + EXPECT_TRUE(GetMute(device_v2));
|
| +
|
| + // Test that values are persisted when audio pref handler is reset.
|
| + ReloadPrefHandler();
|
| + EXPECT_FALSE(GetMute(device_v1));
|
| + EXPECT_TRUE(GetMute(device_v2));
|
| +}
|
| +
|
| +TEST_P(AudioDevicesPrefHandlerTest, MigrateFromGlobalMutePref) {
|
| + pref_service_->SetInteger(prefs::kAudioMute, true);
|
| +
|
| + // For devices with v1 stable device id.
|
| + EXPECT_TRUE(GetMute(GetDeviceWithVersion(1)));
|
| + EXPECT_TRUE(GetMute(GetDeviceWithVersion(2)));
|
| +
|
| + // For devices with v2 stable id.
|
| + EXPECT_TRUE(GetMute(GetSecondaryDeviceWithVersion(2)));
|
| +}
|
| +
|
| +TEST_P(AudioDevicesPrefHandlerTest, TestSpecialCharactersInDeviceNames) {
|
| + AudioDevice device = GetDeviceWithSpecialCharactersWithVersion(2);
|
| + SetSoundLevelValue(device, 73.31);
|
| + EXPECT_EQ(73.31, GetSoundLevelValue(device));
|
| +
|
| + SetMute(device, true);
|
| + EXPECT_TRUE(GetMute(device));
|
| +
|
| + SetDeviceState(device, true, true);
|
| + ExpectDeviceStateEquals(device, true, true);
|
| +}
|
| +
|
| +TEST_P(AudioDevicesPrefHandlerTest, TestDeviceStates) {
|
| + AudioDevice device = GetDeviceWithVersion(2);
|
| + SetDeviceState(device, true, true);
|
| + ExpectDeviceStateEquals(device, true, true);
|
| +
|
| + SetDeviceState(device, true, false);
|
| + ExpectDeviceStateEquals(device, true, false);
|
| +
|
| + SetDeviceState(device, false, false);
|
| + ExpectDeviceStateEquals(device, false, false);
|
| +
|
| + AudioDevice secondary_device = GetSecondaryDeviceWithVersion(2);
|
| + EXPECT_FALSE(DeviceStateExists(secondary_device));
|
| +}
|
| +
|
| +TEST_P(AudioDevicesPrefHandlerTest, TestDeviceStatesMigrateFromV1StableId) {
|
| + AudioDevice device_v1 = GetPresetDeviceWithVersion(1);
|
| + AudioDevice device_v2 = GetPresetDeviceWithVersion(2);
|
| +
|
| + ExpectDeviceStateEquals(device_v1, kPresetState.active,
|
| + kPresetState.activate_by_user);
|
| + ExpectDeviceStateEquals(device_v2, kPresetState.active,
|
| + kPresetState.activate_by_user);
|
| + EXPECT_FALSE(DeviceStateExists(device_v1));
|
| +
|
| + // Test that values are persisted when audio pref handler is reset.
|
| + ReloadPrefHandler();
|
| + EXPECT_FALSE(DeviceStateExists(device_v1));
|
| + ExpectDeviceStateEquals(device_v2, kPresetState.active,
|
| + kPresetState.activate_by_user);
|
| +}
|
| +
|
| +TEST_P(AudioDevicesPrefHandlerTest, TestSettingV2DeviceStateRemovesV1Entry) {
|
| + AudioDevice device_v1 = GetDeviceWithVersion(1);
|
| + AudioDevice device_v2 = GetDeviceWithVersion(2);
|
| +
|
| + SetDeviceState(device_v1, true, true);
|
| + ExpectDeviceStateEquals(device_v1, true, true);
|
| +
|
| + SetDeviceState(device_v2, false, false);
|
| + EXPECT_FALSE(DeviceStateExists(device_v1));
|
| + ExpectDeviceStateEquals(device_v2, false, false);
|
| +
|
| + // Test that values are persisted when audio pref handler is reset.
|
| + ReloadPrefHandler();
|
| + EXPECT_FALSE(DeviceStateExists(device_v1));
|
| + ExpectDeviceStateEquals(device_v2, false, false);
|
| }
|
|
|
| } // namespace chromeos
|
|
|