Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
|
jennyz
2014/12/15 22:34:06
nit: no (c) with new code guideline. 2013->2014.
rkc
2014/12/15 22:44:43
Done.
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/audio/audio_devices_pref_handler_impl.h" | |
| 6 | |
| 7 #include "base/memory/ref_counted.h" | |
| 8 #include "base/prefs/testing_pref_service.h" | |
| 9 #include "chrome/browser/chromeos/audio/audio_devices_pref_handler_impl.h" | |
| 10 #include "chromeos/audio/audio_device.h" | |
| 11 #include "chromeos/audio/audio_devices_pref_handler.h" | |
| 12 #include "chromeos/dbus/audio_node.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 | |
| 15 namespace chromeos { | |
| 16 | |
| 17 const uint64 kInternalMicId = 10003; | |
| 18 const uint64 kHeadphoneId = 10002; | |
| 19 const uint64 kHDMIOutputId = 10006; | |
| 20 const uint64 kOtherTypeOutputId = 90001; | |
| 21 const uint64 kOtherTypeInputId = 90002; | |
| 22 | |
| 23 const AudioDevice kInternalMic(AudioNode(true, | |
| 24 kInternalMicId, | |
| 25 "Fake Mic", | |
| 26 "INTERNAL_MIC", | |
| 27 "Internal Mic", | |
| 28 false, | |
| 29 0)); | |
| 30 | |
| 31 const AudioDevice kHeadphone(AudioNode(false, | |
| 32 kHeadphoneId, | |
| 33 "Fake Headphone", | |
| 34 "HEADPHONE", | |
| 35 "Headphone", | |
| 36 false, | |
| 37 0)); | |
| 38 | |
| 39 const AudioDevice kHDMIOutput(AudioNode(false, | |
| 40 kHDMIOutputId, | |
| 41 "HDMI output", | |
| 42 "HDMI", | |
| 43 "HDMI output", | |
| 44 false, | |
| 45 0)); | |
| 46 | |
| 47 const AudioDevice kInputDeviceWithSpecialCharacters( | |
| 48 AudioNode(true, | |
| 49 kOtherTypeInputId, | |
| 50 "Fake ~!@#$%^&*()_+`-=<>?,./{}|[]\\\\Mic", | |
| 51 "SOME_OTHER_TYPE", | |
| 52 "Other Type Input Device", | |
| 53 true, | |
| 54 0)); | |
| 55 | |
| 56 const AudioDevice kOutputDeviceWithSpecialCharacters( | |
| 57 AudioNode(false, | |
| 58 kOtherTypeOutputId, | |
| 59 "Fake ~!@#$%^&*()_+`-=<>?,./{}|[]\\\\Headphone", | |
| 60 "SOME_OTHER_TYPE", | |
| 61 "Other Type Output Device", | |
| 62 false, | |
| 63 0)); | |
| 64 | |
| 65 class AudioDevicesPrefHandlerTest : public testing::Test { | |
| 66 public: | |
| 67 AudioDevicesPrefHandlerTest() {} | |
| 68 virtual ~AudioDevicesPrefHandlerTest() {} | |
|
jennyz
2014/12/15 22:34:07
no virtual, just override by new code guideline.
rkc
2014/12/15 22:44:43
Done.
| |
| 69 | |
| 70 virtual void SetUp() override { | |
|
jennyz
2014/12/15 22:34:07
Nit. no more virtual by code guide line.
rkc
2014/12/15 22:44:43
Done.
| |
| 71 pref_service_.reset(new TestingPrefServiceSimple()); | |
| 72 AudioDevicesPrefHandlerImpl::RegisterPrefs(pref_service_->registry()); | |
| 73 audio_pref_handler_ = new AudioDevicesPrefHandlerImpl(pref_service_.get()); | |
| 74 } | |
| 75 | |
| 76 virtual void TearDown() override { audio_pref_handler_ = NULL; } | |
|
jennyz
2014/12/15 22:34:07
ditto
rkc
2014/12/15 22:44:43
Done.
| |
| 77 | |
| 78 protected: | |
| 79 scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler_; | |
| 80 scoped_ptr<TestingPrefServiceSimple> pref_service_; | |
| 81 | |
| 82 private: | |
| 83 DISALLOW_COPY_AND_ASSIGN(AudioDevicesPrefHandlerTest); | |
| 84 }; | |
| 85 | |
| 86 TEST_F(AudioDevicesPrefHandlerTest, TestDefaultValues) { | |
| 87 // TODO(rkc): Once the bug with default preferences is fixed, fix this test | |
| 88 // also. http://crbug.com/442489 | |
| 89 EXPECT_EQ(75.0, audio_pref_handler_->GetInputGainValue(&kInternalMic)); | |
| 90 EXPECT_EQ(75.0, audio_pref_handler_->GetOutputVolumeValue(&kHeadphone)); | |
| 91 EXPECT_EQ(75.0, audio_pref_handler_->GetOutputVolumeValue(&kHDMIOutput)); | |
| 92 } | |
| 93 | |
| 94 TEST_F(AudioDevicesPrefHandlerTest, TestBasicInputOutputDevices) { | |
| 95 audio_pref_handler_->SetVolumeGainValue(kInternalMic, 13.37); | |
| 96 EXPECT_EQ(13.37, audio_pref_handler_->GetInputGainValue(&kInternalMic)); | |
| 97 audio_pref_handler_->SetVolumeGainValue(kHeadphone, 47.28); | |
| 98 EXPECT_EQ(47.28, audio_pref_handler_->GetOutputVolumeValue(&kHeadphone)); | |
| 99 } | |
| 100 | |
| 101 TEST_F(AudioDevicesPrefHandlerTest, TestSpecialCharactersInDeviceNames) { | |
| 102 audio_pref_handler_->SetVolumeGainValue(kInputDeviceWithSpecialCharacters, | |
| 103 73.31); | |
| 104 audio_pref_handler_->SetVolumeGainValue(kOutputDeviceWithSpecialCharacters, | |
| 105 85.92); | |
| 106 | |
| 107 EXPECT_EQ(73.31, audio_pref_handler_->GetInputGainValue( | |
| 108 &kInputDeviceWithSpecialCharacters)); | |
| 109 EXPECT_EQ(85.92, audio_pref_handler_->GetOutputVolumeValue( | |
| 110 &kOutputDeviceWithSpecialCharacters)); | |
| 111 } | |
| 112 | |
| 113 } // namespace chromeos | |
| OLD | NEW |