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

Unified Diff: chromeos/dbus/cras_audio_client_stub_impl.cc

Issue 19861002: Add test coverage for CrasAudioHandler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nit. Created 7 years, 5 months 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 | « chromeos/dbus/cras_audio_client_stub_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/dbus/cras_audio_client_stub_impl.cc
diff --git a/chromeos/dbus/cras_audio_client_stub_impl.cc b/chromeos/dbus/cras_audio_client_stub_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b5b61c23aac227aa4cbb2e3c8196ca854c43745d
--- /dev/null
+++ b/chromeos/dbus/cras_audio_client_stub_impl.cc
@@ -0,0 +1,153 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chromeos/dbus/cras_audio_client_stub_impl.h"
+
+namespace chromeos {
+
+CrasAudioClientStubImpl::CrasAudioClientStubImpl() {
+ VLOG(1) << "CrasAudioClientStubImpl is created";
+
+ // Fake audio output nodes.
+ AudioNode node_1;
+ node_1.is_input = false;
+ node_1.id = 10001;
+ node_1.device_name = "Fake Speaker";
+ node_1.type = "INTERNAL_SPEAKER";
+ node_1.name = "Speaker";
+ node_1.active = false;
+ node_list_.push_back(node_1);
+
+ AudioNode node_2;
+ node_2.is_input = false;
+ node_2.id = 10002;
+ node_2.device_name = "Fake Headphone";
+ node_2.type = "HEADPHONE";
+ node_2.name = "Headphone";
+ node_2.active = false;
+ node_list_.push_back(node_2);
+ active_output_node_id_ = node_2.id;
+
+ AudioNode node_3;
+ node_3.is_input = false;
+ node_3.id = 10003;
+ node_3.device_name = "Fake Bluetooth Headphone";
+ node_3.type = "BLUETOOTH";
+ node_3.name = "Bluetooth Headphone";
+ node_3.active = false;
+ node_list_.push_back(node_3);
+
+ // Fake audio input ndoes
+ AudioNode node_4;
+ node_4.is_input = true;
+ node_4.id = 10004;
+ node_4.device_name = "Fake Internal Mic";
+ node_4.type = "INTERNAL_MIC";
+ node_4.name = "Internal Mic";
+ node_4.active = false;
+ node_list_.push_back(node_4);
+
+ AudioNode node_5;
+ node_5.is_input = true;
+ node_5.id = 10005;
+ node_5.device_name = "Fake USB Mic";
+ node_5.type = "USB";
+ node_5.name = "USB Mic";
+ node_5.active = true;
+ node_list_.push_back(node_5);
+
+ active_input_node_id_ = node_5.id;
+}
+
+CrasAudioClientStubImpl::~CrasAudioClientStubImpl() {
+}
+
+void CrasAudioClientStubImpl::AddObserver(Observer* observer) {
+ observers_.AddObserver(observer);
+}
+
+void CrasAudioClientStubImpl::RemoveObserver(Observer* observer) {
+ observers_.RemoveObserver(observer);
+}
+
+bool CrasAudioClientStubImpl::HasObserver(Observer* observer) {
+ return observers_.HasObserver(observer);
+}
+
+void CrasAudioClientStubImpl::GetVolumeState(
+ const GetVolumeStateCallback& callback) {
+ callback.Run(volume_state_, true);
+}
+
+void CrasAudioClientStubImpl::GetNodes(const GetNodesCallback& callback) {
+ callback.Run(node_list_, true);
+}
+
+void CrasAudioClientStubImpl::SetOutputNodeVolume(uint64 node_id,
+ int32 volume) {
+}
+
+void CrasAudioClientStubImpl::SetOutputUserMute(bool mute_on) {
+ volume_state_.output_user_mute = mute_on;
+ FOR_EACH_OBSERVER(Observer,
+ observers_,
+ OutputMuteChanged(volume_state_.output_user_mute));
+}
+
+void CrasAudioClientStubImpl::SetInputNodeGain(uint64 node_id,
+ int32 input_gain) {
+}
+
+void CrasAudioClientStubImpl::SetInputMute(bool mute_on) {
+ volume_state_.input_mute = mute_on;
+ FOR_EACH_OBSERVER(Observer,
+ observers_,
+ InputMuteChanged(volume_state_.input_mute));
+}
+
+void CrasAudioClientStubImpl::SetActiveOutputNode(uint64 node_id) {
+ if (active_output_node_id_ == node_id)
+ return;
+
+ for (size_t i = 0; i < node_list_.size(); ++i) {
+ if (node_list_[i].id == active_output_node_id_)
+ node_list_[i].active = false;
+ else if (node_list_[i].id == node_id)
+ node_list_[i].active = true;
+ }
+ active_output_node_id_ = node_id;
+ FOR_EACH_OBSERVER(Observer,
+ observers_,
+ ActiveOutputNodeChanged(node_id));
+}
+
+void CrasAudioClientStubImpl::SetActiveInputNode(uint64 node_id) {
+ if (active_input_node_id_ == node_id)
+ return;
+
+ for (size_t i = 0; i < node_list_.size(); ++i) {
+ if (node_list_[i].id == active_input_node_id_)
+ node_list_[i].active = false;
+ else if (node_list_[i].id == node_id)
+ node_list_[i].active = true;
+ }
+ active_input_node_id_ = node_id;
+ FOR_EACH_OBSERVER(Observer,
+ observers_,
+ ActiveInputNodeChanged(node_id));
+}
+
+void CrasAudioClientStubImpl::SetAudioDevices(
+ const AudioNodeList& audio_nodes) {
+ node_list_.clear();
+ for (size_t i = 0; i < audio_nodes.size(); ++i)
+ node_list_.push_back(audio_nodes[i]);
+}
+
+void CrasAudioClientStubImpl::ChangeAudioNodes(const AudioNodeList& new_nodes) {
+ SetAudioDevices(new_nodes);
+ FOR_EACH_OBSERVER(Observer, observers_, NodesChanged());
+}
+
+} // namespace chromeos
« no previous file with comments | « chromeos/dbus/cras_audio_client_stub_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698