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

Unified Diff: chrome/browser/chromeos/audio/audio_devices_pref_handler_impl_unittest.cc

Issue 803303002: Fix special character handling in audio preferences. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/audio/audio_devices_pref_handler_impl.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/audio/audio_devices_pref_handler_impl_unittest.cc
diff --git a/chrome/browser/chromeos/audio/audio_devices_pref_handler_impl_unittest.cc b/chrome/browser/chromeos/audio/audio_devices_pref_handler_impl_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b7df904a4a2113d89382328f3e41c88d035fc76c
--- /dev/null
+++ b/chrome/browser/chromeos/audio/audio_devices_pref_handler_impl_unittest.cc
@@ -0,0 +1,113 @@
+// 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.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/audio/audio_devices_pref_handler_impl.h"
+
+#include "base/memory/ref_counted.h"
+#include "base/prefs/testing_pref_service.h"
+#include "chrome/browser/chromeos/audio/audio_devices_pref_handler_impl.h"
+#include "chromeos/audio/audio_device.h"
+#include "chromeos/audio/audio_devices_pref_handler.h"
+#include "chromeos/dbus/audio_node.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace chromeos {
+
+const uint64 kInternalMicId = 10003;
+const uint64 kHeadphoneId = 10002;
+const uint64 kHDMIOutputId = 10006;
+const uint64 kOtherTypeOutputId = 90001;
+const uint64 kOtherTypeInputId = 90002;
+
+const AudioDevice kInternalMic(AudioNode(true,
+ kInternalMicId,
+ "Fake Mic",
+ "INTERNAL_MIC",
+ "Internal Mic",
+ false,
+ 0));
+
+const AudioDevice kHeadphone(AudioNode(false,
+ kHeadphoneId,
+ "Fake Headphone",
+ "HEADPHONE",
+ "Headphone",
+ false,
+ 0));
+
+const AudioDevice kHDMIOutput(AudioNode(false,
+ kHDMIOutputId,
+ "HDMI output",
+ "HDMI",
+ "HDMI output",
+ false,
+ 0));
+
+const AudioDevice kInputDeviceWithSpecialCharacters(
+ AudioNode(true,
+ kOtherTypeInputId,
+ "Fake ~!@#$%^&*()_+`-=<>?,./{}|[]\\\\Mic",
+ "SOME_OTHER_TYPE",
+ "Other Type Input Device",
+ true,
+ 0));
+
+const AudioDevice kOutputDeviceWithSpecialCharacters(
+ AudioNode(false,
+ kOtherTypeOutputId,
+ "Fake ~!@#$%^&*()_+`-=<>?,./{}|[]\\\\Headphone",
+ "SOME_OTHER_TYPE",
+ "Other Type Output Device",
+ false,
+ 0));
+
+class AudioDevicesPrefHandlerTest : public testing::Test {
+ public:
+ AudioDevicesPrefHandlerTest() {}
+ 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.
+
+ 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.
+ pref_service_.reset(new TestingPrefServiceSimple());
+ AudioDevicesPrefHandlerImpl::RegisterPrefs(pref_service_->registry());
+ audio_pref_handler_ = new AudioDevicesPrefHandlerImpl(pref_service_.get());
+ }
+
+ virtual void TearDown() override { audio_pref_handler_ = NULL; }
jennyz 2014/12/15 22:34:07 ditto
rkc 2014/12/15 22:44:43 Done.
+
+ protected:
+ scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler_;
+ scoped_ptr<TestingPrefServiceSimple> pref_service_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(AudioDevicesPrefHandlerTest);
+};
+
+TEST_F(AudioDevicesPrefHandlerTest, TestDefaultValues) {
+ // 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));
+}
+
+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));
+}
+
+} // namespace chromeos
« no previous file with comments | « chrome/browser/chromeos/audio/audio_devices_pref_handler_impl.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698