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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
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 "chromeos/dbus/cras_audio_client_stub_impl.h"
6
7 namespace chromeos {
8
9 CrasAudioClientStubImpl::CrasAudioClientStubImpl() {
10 VLOG(1) << "CrasAudioClientStubImpl is created";
11
12 // Fake audio output nodes.
13 AudioNode node_1;
14 node_1.is_input = false;
15 node_1.id = 10001;
16 node_1.device_name = "Fake Speaker";
17 node_1.type = "INTERNAL_SPEAKER";
18 node_1.name = "Speaker";
19 node_1.active = false;
20 node_list_.push_back(node_1);
21
22 AudioNode node_2;
23 node_2.is_input = false;
24 node_2.id = 10002;
25 node_2.device_name = "Fake Headphone";
26 node_2.type = "HEADPHONE";
27 node_2.name = "Headphone";
28 node_2.active = false;
29 node_list_.push_back(node_2);
30 active_output_node_id_ = node_2.id;
31
32 AudioNode node_3;
33 node_3.is_input = false;
34 node_3.id = 10003;
35 node_3.device_name = "Fake Bluetooth Headphone";
36 node_3.type = "BLUETOOTH";
37 node_3.name = "Bluetooth Headphone";
38 node_3.active = false;
39 node_list_.push_back(node_3);
40
41 // Fake audio input ndoes
42 AudioNode node_4;
43 node_4.is_input = true;
44 node_4.id = 10004;
45 node_4.device_name = "Fake Internal Mic";
46 node_4.type = "INTERNAL_MIC";
47 node_4.name = "Internal Mic";
48 node_4.active = false;
49 node_list_.push_back(node_4);
50
51 AudioNode node_5;
52 node_5.is_input = true;
53 node_5.id = 10005;
54 node_5.device_name = "Fake USB Mic";
55 node_5.type = "USB";
56 node_5.name = "USB Mic";
57 node_5.active = true;
58 node_list_.push_back(node_5);
59 active_input_node_id_ = node_5.id;
60 }
61
62 CrasAudioClientStubImpl::~CrasAudioClientStubImpl() {
63 }
64
65 void CrasAudioClientStubImpl::AddObserver(Observer* observer) {
66 observers_.AddObserver(observer);
67 }
68
69 void CrasAudioClientStubImpl::RemoveObserver(Observer* observer) {
70 observers_.RemoveObserver(observer);
71 }
72
73 bool CrasAudioClientStubImpl::HasObserver(Observer* observer) {
74 return observers_.HasObserver(observer);
75 }
76
77 void CrasAudioClientStubImpl::GetVolumeState(
78 const GetVolumeStateCallback& callback) {
79 callback.Run(volume_state_, true);
80 }
81
82 void CrasAudioClientStubImpl::GetNodes(const GetNodesCallback& callback) {
83 callback.Run(node_list_, true);
84 }
85
86 void CrasAudioClientStubImpl::SetOutputNodeVolume(uint64 node_id,
87 int32 volume) {
88 }
89
90 void CrasAudioClientStubImpl::SetOutputUserMute(bool mute_on) {
91 volume_state_.output_user_mute = mute_on;
92 FOR_EACH_OBSERVER(Observer,
93 observers_,
94 OutputMuteChanged(volume_state_.output_user_mute));
95 }
96
97 void CrasAudioClientStubImpl::SetInputNodeGain(uint64 node_id,
98 int32 input_gain) {
99 }
100
101 void CrasAudioClientStubImpl::SetInputMute(bool mute_on) {
102 volume_state_.input_mute = mute_on;
103 FOR_EACH_OBSERVER(Observer,
104 observers_,
105 InputMuteChanged(volume_state_.input_mute));
106 }
107
108 void CrasAudioClientStubImpl::SetActiveOutputNode(uint64 node_id) {
109 if (active_output_node_id_ == node_id)
110 return;
111
112 for (size_t i = 0; i < node_list_.size(); ++i) {
113 if (node_list_[i].id == active_output_node_id_)
114 node_list_[i].active = false;
115 else if (node_list_[i].id == node_id)
116 node_list_[i].active = true;
117 }
118 active_output_node_id_ = node_id;
119 FOR_EACH_OBSERVER(Observer,
120 observers_,
121 ActiveOutputNodeChanged(node_id));
122 }
123
124 void CrasAudioClientStubImpl::SetActiveInputNode(uint64 node_id) {
125 if (active_input_node_id_ == node_id)
126 return;
127
128 for (size_t i = 0; i < node_list_.size(); ++i) {
129 if (node_list_[i].id == active_input_node_id_)
130 node_list_[i].active = false;
131 else if (node_list_[i].id == node_id)
132 node_list_[i].active = true;
133 }
134 active_input_node_id_ = node_id;
135 FOR_EACH_OBSERVER(Observer,
136 observers_,
137 ActiveInputNodeChanged(node_id));
138 }
139
140 void CrasAudioClientStubImpl::SetAudioDevices(
141 const AudioNodeList& audio_nodes) {
142 node_list_.clear();
143 for (size_t i = 0; i < audio_nodes.size(); ++i)
144 node_list_.push_back(audio_nodes[i]);
145 }
146
147 void CrasAudioClientStubImpl::ChangeAudioNodes(const AudioNodeList& new_nodes) {
148 SetAudioDevices(new_nodes);
149 FOR_EACH_OBSERVER(Observer, observers_, NodesChanged());
150 }
151
152 } // namespace chromeos
OLDNEW
« chromeos/audio/cras_audio_handler_unittest.cc ('K') | « 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