Skip to content

Commit

Permalink
Run clang-format on fake_cras_audio_client.cc
Browse files Browse the repository at this point in the history
I will modify this file in a follow-up CL, and this keeps
these style-only changes separate.

Bug: b/271813821
Change-Id: I8708641f173228637553996a9efb3d1f9b491fbf
Cq-Include-Trybots: luci.chrome.try:linux-chromeos-chrome
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4324038
Auto-Submit: Jeroen Dhollander <jeroendh@google.com>
Reviewed-by: Yu-Hsuan Hsu <yuhsuan@chromium.org>
Commit-Queue: Jeroen Dhollander <jeroendh@google.com>
Cr-Commit-Position: refs/heads/main@{#1115586}
  • Loading branch information
Jeroen Dhollander authored and Chromium LUCI CQ committed Mar 10, 2023
1 parent a5efe23 commit 7db70d3
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 43 deletions.
49 changes: 30 additions & 19 deletions chromeos/ash/components/audio/cras_audio_handler_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,9 @@ class SystemMonitorObserver
~SystemMonitorObserver() override = default;

void OnDevicesChanged(base::SystemMonitor::DeviceType device_type) override {
if (device_type == base::SystemMonitor::DeviceType::DEVTYPE_AUDIO)
if (device_type == base::SystemMonitor::DeviceType::DEVTYPE_AUDIO) {
device_changes_received_++;
}
}

int device_changes_received() const { return device_changes_received_; }
Expand All @@ -336,13 +337,15 @@ class FakeVideoCaptureManager {
void RemoveAllObservers() { observers_.Clear(); }

void NotifyVideoCaptureStarted(media::VideoFacingMode facing) {
for (auto& observer : observers_)
for (auto& observer : observers_) {
observer.OnVideoCaptureStarted(facing);
}
}

void NotifyVideoCaptureStopped(media::VideoFacingMode facing) {
for (auto& observer : observers_)
for (auto& observer : observers_) {
observer.OnVideoCaptureStopped(facing);
}
}

private:
Expand Down Expand Up @@ -505,8 +508,9 @@ class CrasAudioHandlerTest : public testing::TestWithParam<int> {
AudioDeviceList audio_devices;
cras_audio_handler_->GetAudioDevices(&audio_devices);
for (size_t i = 0; i < audio_devices.size(); ++i) {
if (audio_devices[i].active)
if (audio_devices[i].active) {
++num_active_nodes;
}
}
return num_active_nodes;
}
Expand Down Expand Up @@ -1448,8 +1452,9 @@ TEST_P(CrasAudioHandlerTest, OneActiveAudioOutputAfterLoginNewUserSession) {
EXPECT_EQ(kHeadphone->id, cras_audio_handler_->GetPrimaryActiveOutputNode());
EXPECT_TRUE(cras_audio_handler_->has_alternative_output());
for (size_t i = 0; i < audio_devices.size(); ++i) {
if (audio_devices[i].id != kHeadphone->id)
if (audio_devices[i].id != kHeadphone->id) {
EXPECT_FALSE(audio_devices[i].active);
}
}
}

Expand Down Expand Up @@ -1928,14 +1933,15 @@ TEST_P(CrasAudioHandlerTest, MultipleNodesChangedSignalsOnPlugInHeadphone) {
cras_audio_handler_->GetAudioDevices(&audio_devices);
EXPECT_EQ(init_nodes_size + 1, audio_devices.size());
for (size_t i = 0; i < audio_devices.size(); ++i) {
if (audio_devices[i].id == kInternalSpeaker->id)
if (audio_devices[i].id == kInternalSpeaker->id) {
EXPECT_FALSE(audio_devices[i].active);
else if (audio_devices[i].id == bluetooth_headset.id)
} else if (audio_devices[i].id == bluetooth_headset.id) {
EXPECT_FALSE(audio_devices[i].active);
else if (audio_devices[i].id == headphone.id)
} else if (audio_devices[i].id == headphone.id) {
EXPECT_TRUE(audio_devices[i].active);
else
} else {
NOTREACHED();
}
}
}

Expand Down Expand Up @@ -1981,12 +1987,13 @@ TEST_P(CrasAudioHandlerTest, MultipleNodesChangedSignalsOnPlugInUSBMic) {
cras_audio_handler_->GetAudioDevices(&audio_devices);
EXPECT_EQ(init_nodes_size + 1, audio_devices.size());
for (size_t i = 0; i < audio_devices.size(); ++i) {
if (audio_devices[i].id == kInternalMic->id)
if (audio_devices[i].id == kInternalMic->id) {
EXPECT_FALSE(audio_devices[i].active);
else if (audio_devices[i].id == usb_mic.id)
} else if (audio_devices[i].id == usb_mic.id) {
EXPECT_TRUE(audio_devices[i].active);
else
} else {
NOTREACHED();
}
}
}

Expand Down Expand Up @@ -2029,14 +2036,15 @@ TEST_P(CrasAudioHandlerTest, MultipleNodesChangedSignalsOnSystemBoot) {
cras_audio_handler_->GetAudioDevices(&audio_devices);
EXPECT_EQ(init_nodes_size, audio_devices.size());
for (size_t i = 0; i < audio_devices.size(); ++i) {
if (audio_devices[i].id == internal_speaker.id)
if (audio_devices[i].id == internal_speaker.id) {
EXPECT_FALSE(audio_devices[i].active);
else if (audio_devices[i].id == headphone.id)
} else if (audio_devices[i].id == headphone.id) {
EXPECT_TRUE(audio_devices[i].active);
else if (audio_devices[i].id == internal_mic.id)
} else if (audio_devices[i].id == internal_mic.id) {
EXPECT_TRUE(audio_devices[i].active);
else
} else {
NOTREACHED();
}
}
}

Expand Down Expand Up @@ -3143,8 +3151,9 @@ TEST_P(CrasAudioHandlerTest, UnplugHeadphoneLostActiveInternalSpeakerByCras) {
audio_nodes.clear();
audio_nodes.push_back(GenerateAudioNode(kInternalSpeaker));
audio_nodes.push_back(GenerateAudioNode(kUSBHeadphone1));
for (const auto& node : audio_nodes)
for (const auto& node : audio_nodes) {
ASSERT_FALSE(node.active) << node.id << " expexted to be inactive";
}
ChangeAudioNodes(audio_nodes);

// Verify the active output is set back to internal speaker.
Expand Down Expand Up @@ -4230,8 +4239,9 @@ TEST_P(CrasAudioHandlerTest, HotPlugHDMIChangeActiveOutput) {
// resuming from suspension state. See crbug.com/478968.
TEST_P(CrasAudioHandlerTest, ActiveNodeLostAfterResume) {
AudioNodeList audio_nodes = GenerateAudioNodeList({kHeadphone, kHDMIOutput});
for (const auto& node : audio_nodes)
for (const auto& node : audio_nodes) {
ASSERT_FALSE(node.active) << node.id << " expected to be inactive";
}
SetUpCrasAudioHandler(audio_nodes);

// Verify the headphone is selected as the active output.
Expand Down Expand Up @@ -4320,8 +4330,9 @@ TEST_P(CrasAudioHandlerTest, HDMIRemainInactiveAfterSuspendResume) {
// during this process. See crbug.com/478968.
TEST_P(CrasAudioHandlerTest, ActiveNodeLostDuringLoginSession) {
AudioNodeList audio_nodes = GenerateAudioNodeList({kHeadphone});
for (const auto& node : audio_nodes)
for (const auto& node : audio_nodes) {
ASSERT_FALSE(node.active) << node.id << " expected to be inactive";
}
SetUpCrasAudioHandler(audio_nodes);

// Verify the headphone is selected as the active output.
Expand Down
69 changes: 45 additions & 24 deletions chromeos/ash/components/dbus/audio/fake_cras_audio_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,16 @@ void FakeCrasAudioClient::GetSpeakOnMuteDetectionEnabled(

void FakeCrasAudioClient::SetOutputNodeVolume(uint64_t node_id,
int32_t volume) {
if (!notify_volume_change_with_delay_)
if (!notify_volume_change_with_delay_) {
NotifyOutputNodeVolumeChangedForTesting(node_id, volume);
}
}

void FakeCrasAudioClient::SetOutputUserMute(bool mute_on) {
volume_state_.output_user_mute = mute_on;
for (auto& observer : observers_)
for (auto& observer : observers_) {
observer.OutputMuteChanged(volume_state_.output_user_mute);
}
}

void FakeCrasAudioClient::SetInputNodeGain(uint64_t node_id,
Expand All @@ -222,8 +224,9 @@ void FakeCrasAudioClient::SetInputNodeGain(uint64_t node_id,

void FakeCrasAudioClient::SetInputMute(bool mute_on) {
volume_state_.input_mute = mute_on;
for (auto& observer : observers_)
for (auto& observer : observers_) {
observer.InputMuteChanged(volume_state_.input_mute);
}
}

void FakeCrasAudioClient::SetNoiseCancellationSupported(
Expand Down Expand Up @@ -254,33 +257,39 @@ void FakeCrasAudioClient::SetNumberOfNonChromeOutputStreams(int32_t streams) {
}

void FakeCrasAudioClient::SetActiveOutputNode(uint64_t node_id) {
if (active_output_node_id_ == 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_)
if (node_list_[i].id == active_output_node_id_) {
node_list_[i].active = false;
else if (node_list_[i].id == node_id)
} else if (node_list_[i].id == node_id) {
node_list_[i].active = true;
}
}
active_output_node_id_ = node_id;
for (auto& observer : observers_)
for (auto& observer : observers_) {
observer.ActiveOutputNodeChanged(node_id);
}
}

void FakeCrasAudioClient::SetActiveInputNode(uint64_t node_id) {
if (active_input_node_id_ == 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_)
if (node_list_[i].id == active_input_node_id_) {
node_list_[i].active = false;
else if (node_list_[i].id == node_id)
} else if (node_list_[i].id == node_id) {
node_list_[i].active = true;
}
}
active_input_node_id_ = node_id;
for (auto& observer : observers_)
for (auto& observer : observers_) {
observer.ActiveInputNodeChanged(node_id);
}
}

void FakeCrasAudioClient::SetHotwordModel(
Expand All @@ -296,15 +305,17 @@ void FakeCrasAudioClient::SetSpeakOnMuteDetection(bool enabled) {}

void FakeCrasAudioClient::AddActiveInputNode(uint64_t node_id) {
for (size_t i = 0; i < node_list_.size(); ++i) {
if (node_list_[i].id == node_id)
if (node_list_[i].id == node_id) {
node_list_[i].active = true;
}
}
}

void FakeCrasAudioClient::RemoveActiveInputNode(uint64_t node_id) {
for (size_t i = 0; i < node_list_.size(); ++i) {
if (node_list_[i].id == node_id)
if (node_list_[i].id == node_id) {
node_list_[i].active = false;
}
}
}

Expand Down Expand Up @@ -332,14 +343,16 @@ void FakeCrasAudioClient::SetPlayerMetadata(

void FakeCrasAudioClient::AddActiveOutputNode(uint64_t node_id) {
for (size_t i = 0; i < node_list_.size(); ++i) {
if (node_list_[i].id == node_id)
if (node_list_[i].id == node_id) {
node_list_[i].active = true;
}
}
}

void FakeCrasAudioClient::ResendBluetoothBattery() {
for (auto& observer : observers_)
for (auto& observer : observers_) {
observer.BluetoothBatteryChanged("11:22:33:44:55:66", battery_level_);
}
}

void FakeCrasAudioClient::WaitForServiceToBeAvailable(
Expand All @@ -349,27 +362,31 @@ void FakeCrasAudioClient::WaitForServiceToBeAvailable(

void FakeCrasAudioClient::RemoveActiveOutputNode(uint64_t node_id) {
for (size_t i = 0; i < node_list_.size(); ++i) {
if (node_list_[i].id == node_id)
if (node_list_[i].id == node_id) {
node_list_[i].active = false;
}
}
}

void FakeCrasAudioClient::InsertAudioNodeToList(const AudioNode& audio_node) {
auto iter = FindNode(audio_node.id);
if (iter != node_list_.end())
if (iter != node_list_.end()) {
(*iter) = audio_node;
else
} else {
node_list_.push_back(audio_node);
for (auto& observer : observers_)
}
for (auto& observer : observers_) {
observer.NodesChanged();
}
}

void FakeCrasAudioClient::RemoveAudioNodeFromList(const uint64_t& node_id) {
auto iter = FindNode(node_id);
if (iter != node_list_.end()) {
node_list_.erase(iter);
for (auto& observer : observers_)
for (auto& observer : observers_) {
observer.NodesChanged();
}
}
}

Expand All @@ -381,15 +398,17 @@ void FakeCrasAudioClient::SetAudioNodesForTesting(
void FakeCrasAudioClient::SetAudioNodesAndNotifyObserversForTesting(
const AudioNodeList& new_nodes) {
SetAudioNodesForTesting(new_nodes);
for (auto& observer : observers_)
for (auto& observer : observers_) {
observer.NodesChanged();
}
}

void FakeCrasAudioClient::NotifyOutputNodeVolumeChangedForTesting(
uint64_t node_id,
int volume) {
for (auto& observer : observers_)
for (auto& observer : observers_) {
observer.OutputNodeVolumeChanged(node_id, volume);
}
}

void FakeCrasAudioClient::NotifyInputNodeGainChangedForTesting(uint64_t node_id,
Expand All @@ -401,8 +420,9 @@ void FakeCrasAudioClient::NotifyInputNodeGainChangedForTesting(uint64_t node_id,

void FakeCrasAudioClient::NotifyHotwordTriggeredForTesting(uint64_t tv_sec,
uint64_t tv_nsec) {
for (auto& observer : observers_)
for (auto& observer : observers_) {
observer.HotwordTriggered(tv_sec, tv_nsec);
}
}

void FakeCrasAudioClient::SetBluetoothBattteryLevelForTesting(uint32_t level) {
Expand All @@ -412,8 +432,9 @@ void FakeCrasAudioClient::SetBluetoothBattteryLevelForTesting(uint32_t level) {
void FakeCrasAudioClient::SetActiveInputStreamsWithPermission(
const ClientTypeToInputStreamCount& input_streams) {
active_input_streams_ = input_streams;
for (auto& observer : observers_)
for (auto& observer : observers_) {
observer.NumberOfInputStreamsWithPermissionChanged(active_input_streams_);
}
}

AudioNodeList::iterator FakeCrasAudioClient::FindNode(uint64_t node_id) {
Expand Down

0 comments on commit 7db70d3

Please sign in to comment.