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

Side by Side Diff: chromeos/dbus/cras_audio_client_unittest.cc

Issue 2510093003: Handle audio node stable device ID change (Closed)
Patch Set: fix a typo Created 4 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 unified diff | Download patch
« no previous file with comments | « chromeos/dbus/cras_audio_client.cc ('k') | chromeos/dbus/fake_cras_audio_client.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chromeos/dbus/cras_audio_client.h" 5 #include "chromeos/dbus/cras_audio_client.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 15 matching lines...) Expand all
26 namespace chromeos { 26 namespace chromeos {
27 27
28 namespace { 28 namespace {
29 29
30 // Audio nodes for GetNodes unit test. 30 // Audio nodes for GetNodes unit test.
31 const uint64_t kInternalSpeakerId = 10001; 31 const uint64_t kInternalSpeakerId = 10001;
32 const uint64_t kInternalMicId = 20001; 32 const uint64_t kInternalMicId = 20001;
33 33
34 const AudioNode kInternalSpeaker(false, 34 const AudioNode kInternalSpeaker(false,
35 kInternalSpeakerId, 35 kInternalSpeakerId,
36 kInternalSpeakerId, 36 false /* has_v2_stable_device_id */,
37 kInternalSpeakerId /* stable_device_id_v1 */,
38 0 /* stable_device_id_v2 */,
37 "Fake Speaker", 39 "Fake Speaker",
38 "INTERNAL_SPEAKER", 40 "INTERNAL_SPEAKER",
39 "Speaker", 41 "Speaker",
40 false, 42 false,
41 0); 43 0);
42 44
43 const AudioNode kInternalMic(true, 45 const AudioNode kInternalMic(true,
44 kInternalMicId, 46 kInternalMicId,
45 kInternalMicId, 47 false /* has_v2_stable_device_id */,
48 kInternalMicId /* stable_device_id_v1*/,
49 0 /* stable_device_id_v2 */,
46 "Fake Mic", 50 "Fake Mic",
47 "INTERNAL_MIC", 51 "INTERNAL_MIC",
48 "Internal Mic", 52 "Internal Mic",
49 false, 53 false,
50 0); 54 0);
55
56 const AudioNode kInternalSpeakerV2(
57 false,
58 kInternalSpeakerId,
59 true /* has_v2_stable_device_id */,
60 kInternalSpeakerId /* stable_device_id_v1 */,
61 // stable_device_id_v2: XOR to make sure the
62 // ID is different from |stable_device_id_v1|.
63 kInternalSpeakerId ^ 0xFF,
64 "Fake Speaker",
65 "INTERNAL_SPEAKER",
66 "Speaker",
67 false,
68 0);
69
70 const AudioNode kInternalMicV2(true,
71 kInternalMicId,
72 true /* has_v2_stable_device_id */,
73 kInternalMicId /* stable_device_id_v1 */,
74 // XOR to make sure the ID is different from
75 // |stable_device_id_v1|.
76 kInternalMicId ^ 0xFF /* stable_device_id_v2 */,
77 "Fake Mic",
78 "INTERNAL_MIC",
79 "Internal Mic",
80 false,
81 0);
82
51 // A mock ErrorCallback. 83 // A mock ErrorCallback.
52 class MockErrorCallback { 84 class MockErrorCallback {
53 public: 85 public:
54 MockErrorCallback() {} 86 MockErrorCallback() {}
55 ~MockErrorCallback() {} 87 ~MockErrorCallback() {}
56 MOCK_METHOD2(Run, void(const std::string& error_name, 88 MOCK_METHOD2(Run, void(const std::string& error_name,
57 const std::string& error_message)); 89 const std::string& error_message));
58 CrasAudioClient::ErrorCallback GetCallback() { 90 CrasAudioClient::ErrorCallback GetCallback() {
59 return base::Bind(&MockErrorCallback::Run, base::Unretained(this)); 91 return base::Bind(&MockErrorCallback::Run, base::Unretained(this));
60 } 92 }
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 sub_writer.OpenDictEntry(&entry_writer); 204 sub_writer.OpenDictEntry(&entry_writer);
173 entry_writer.AppendString(cras::kPluggedTimeProperty); 205 entry_writer.AppendString(cras::kPluggedTimeProperty);
174 entry_writer.AppendVariantOfUint64(node_list[i].plugged_time); 206 entry_writer.AppendVariantOfUint64(node_list[i].plugged_time);
175 sub_writer.CloseContainer(&entry_writer); 207 sub_writer.CloseContainer(&entry_writer);
176 sub_writer.OpenDictEntry(&entry_writer); 208 sub_writer.OpenDictEntry(&entry_writer);
177 entry_writer.AppendString(cras::kMicPositionsProperty); 209 entry_writer.AppendString(cras::kMicPositionsProperty);
178 entry_writer.AppendVariantOfString(node_list[i].mic_positions); 210 entry_writer.AppendVariantOfString(node_list[i].mic_positions);
179 sub_writer.CloseContainer(&entry_writer); 211 sub_writer.CloseContainer(&entry_writer);
180 sub_writer.OpenDictEntry(&entry_writer); 212 sub_writer.OpenDictEntry(&entry_writer);
181 entry_writer.AppendString(cras::kStableDeviceIdProperty); 213 entry_writer.AppendString(cras::kStableDeviceIdProperty);
182 entry_writer.AppendVariantOfUint64(node_list[i].stable_device_id); 214 entry_writer.AppendVariantOfUint64(node_list[i].stable_device_id_v1);
215 if (node_list[i].has_v2_stable_device_id) {
216 entry_writer.AppendString(cras::kStableDeviceIdNewProperty);
217 entry_writer.AppendVariantOfUint64(node_list[i].stable_device_id_v2);
218 }
183 sub_writer.CloseContainer(&entry_writer); 219 sub_writer.CloseContainer(&entry_writer);
184 writer.CloseContainer(&sub_writer); 220 writer.CloseContainer(&sub_writer);
185 } 221 }
186 } 222 }
187 223
188 // Expect the AudioNodeList result. 224 // Expect the AudioNodeList result.
189 void ExpectAudioNodeListResult(const AudioNodeList* expected_node_list, 225 void ExpectAudioNodeListResult(const AudioNodeList* expected_node_list,
190 const AudioNodeList& node_list, 226 const AudioNodeList& node_list,
191 bool call_status) { 227 bool call_status) {
192 EXPECT_EQ(true, call_status); 228 EXPECT_EQ(true, call_status);
193 EXPECT_EQ(expected_node_list->size(), node_list.size()); 229 EXPECT_EQ(expected_node_list->size(), node_list.size());
194 for (size_t i = 0; i < node_list.size(); ++i) { 230 for (size_t i = 0; i < node_list.size(); ++i) {
195 EXPECT_EQ((*expected_node_list)[i].is_input, node_list[i].is_input); 231 EXPECT_EQ((*expected_node_list)[i].is_input, node_list[i].is_input);
196 EXPECT_EQ((*expected_node_list)[i].id, node_list[i].id); 232 EXPECT_EQ((*expected_node_list)[i].id, node_list[i].id);
197 EXPECT_EQ((*expected_node_list)[i].stable_device_id, 233 EXPECT_EQ((*expected_node_list)[i].stable_device_id_v1,
198 node_list[i].stable_device_id); 234 node_list[i].stable_device_id_v1);
235 EXPECT_EQ((*expected_node_list)[i].stable_device_id_v2,
236 node_list[i].stable_device_id_v2);
199 EXPECT_EQ((*expected_node_list)[i].device_name, node_list[i].device_name); 237 EXPECT_EQ((*expected_node_list)[i].device_name, node_list[i].device_name);
200 EXPECT_EQ((*expected_node_list)[i].type, node_list[i].type); 238 EXPECT_EQ((*expected_node_list)[i].type, node_list[i].type);
201 EXPECT_EQ((*expected_node_list)[i].name, node_list[i].name); 239 EXPECT_EQ((*expected_node_list)[i].name, node_list[i].name);
202 EXPECT_EQ((*expected_node_list)[i].mic_positions, 240 EXPECT_EQ((*expected_node_list)[i].mic_positions,
203 node_list[i].mic_positions); 241 node_list[i].mic_positions);
204 EXPECT_EQ((*expected_node_list)[i].active, node_list[i].active); 242 EXPECT_EQ((*expected_node_list)[i].active, node_list[i].active);
205 EXPECT_EQ((*expected_node_list)[i].plugged_time, node_list[i].plugged_time); 243 EXPECT_EQ((*expected_node_list)[i].plugged_time, node_list[i].plugged_time);
244 EXPECT_EQ((*expected_node_list)[i].StableDeviceIdVersion(),
245 node_list[i].StableDeviceIdVersion());
206 } 246 }
207 } 247 }
208 248
209 } // namespace 249 } // namespace
210 250
211 class CrasAudioClientTest : public testing::Test { 251 class CrasAudioClientTest : public testing::Test {
212 public: 252 public:
213 CrasAudioClientTest() : interface_name_(cras::kCrasControlInterface), 253 CrasAudioClientTest() : interface_name_(cras::kCrasControlInterface),
214 response_(nullptr) {} 254 response_(nullptr) {}
215 255
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 // Call method. 741 // Call method.
702 MockErrorCallback error_callback; 742 MockErrorCallback error_callback;
703 client_->GetNodes(base::Bind(&ExpectAudioNodeListResult, 743 client_->GetNodes(base::Bind(&ExpectAudioNodeListResult,
704 &expected_node_list), 744 &expected_node_list),
705 error_callback.GetCallback()); 745 error_callback.GetCallback());
706 EXPECT_CALL(error_callback, Run(_, _)).Times(0); 746 EXPECT_CALL(error_callback, Run(_, _)).Times(0);
707 // Run the message loop. 747 // Run the message loop.
708 base::RunLoop().RunUntilIdle(); 748 base::RunLoop().RunUntilIdle();
709 } 749 }
710 750
751 TEST_F(CrasAudioClientTest, GetNodesV2) {
752 // Create the expected value.
753 AudioNodeList expected_node_list;
754 expected_node_list.push_back(kInternalSpeakerV2);
755 expected_node_list.push_back(kInternalMicV2);
756
757 // Create response.
758 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
759 dbus::MessageWriter writer(response.get());
760 WriteNodesToResponse(writer, expected_node_list);
761
762 // Set expectations.
763 PrepareForMethodCall(cras::kGetNodes, base::Bind(&ExpectNoArgument),
764 response.get());
765 // Call method.
766 MockErrorCallback error_callback;
767 client_->GetNodes(base::Bind(&ExpectAudioNodeListResult, &expected_node_list),
768 error_callback.GetCallback());
769 EXPECT_CALL(error_callback, Run(_, _)).Times(0);
770 // Run the message loop.
771 base::RunLoop().RunUntilIdle();
772 }
773
711 TEST_F(CrasAudioClientTest, SetOutputNodeVolume) { 774 TEST_F(CrasAudioClientTest, SetOutputNodeVolume) {
712 const uint64_t kNodeId = 10003; 775 const uint64_t kNodeId = 10003;
713 const int32_t kVolume = 80; 776 const int32_t kVolume = 80;
714 // Create response. 777 // Create response.
715 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 778 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
716 779
717 // Set expectations. 780 // Set expectations.
718 PrepareForMethodCall(cras::kSetOutputNodeVolume, 781 PrepareForMethodCall(cras::kSetOutputNodeVolume,
719 base::Bind(&ExpectUint64AndInt32Arguments, 782 base::Bind(&ExpectUint64AndInt32Arguments,
720 kNodeId, 783 kNodeId,
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 kMixer), 958 kMixer),
896 response.get()); 959 response.get());
897 960
898 // Call method. 961 // Call method.
899 client_->SetGlobalOutputChannelRemix(kChannels, kMixer); 962 client_->SetGlobalOutputChannelRemix(kChannels, kMixer);
900 // Run the message loop. 963 // Run the message loop.
901 base::RunLoop().RunUntilIdle(); 964 base::RunLoop().RunUntilIdle();
902 } 965 }
903 966
904 } // namespace chromeos 967 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/cras_audio_client.cc ('k') | chromeos/dbus/fake_cras_audio_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698