Commit ce870175 authored by Noah Rose Ledesma's avatar Noah Rose Ledesma Committed by Commit Bot

GMC: Hide the audio device picker when there is only one device

This change hides the MediaNotificationAudioDeviceSelectorView when
there is only one unique device.

Bug: 1116113
Change-Id: Ie5799b29a691ead0b0225751e18e4019452f38e6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2354831
Commit-Queue: Noah Rose Ledesma <noahrose@google.com>
Reviewed-by: default avatarTommy Steimel <steimel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799822}
parent afcb4dd2
......@@ -102,6 +102,9 @@ MediaNotificationAudioDeviceSelectorView::
expand_button_, kKeyboardArrowUpIcon, kExpandButtonSize, SK_ColorBLACK,
SK_ColorBLACK);
// This view will become visible when devices are discovered.
SetVisible(false);
// Get a list of the connected audio output devices
audio_device_subscription_ =
service_->RegisterAudioOutputDeviceDescriptionsCallback(
......@@ -117,6 +120,10 @@ MediaNotificationAudioDeviceSelectorView::
void MediaNotificationAudioDeviceSelectorView::UpdateAvailableAudioDevices(
const media::AudioDeviceDescriptions& device_descriptions) {
bool is_visible = ShouldBeVisible(device_descriptions);
SetVisible(is_visible);
delegate_->OnAudioDeviceSelectorViewSizeChanged();
sink_id_map_.clear();
device_button_container_->RemoveAllChildViews(true);
current_device_button_ = nullptr;
......@@ -182,3 +189,8 @@ void MediaNotificationAudioDeviceSelectorView::CreateDeviceButton(
device_button_container_->AddChildView(std::move(button));
device_button_container_->Layout();
}
bool MediaNotificationAudioDeviceSelectorView::ShouldBeVisible(
const media::AudioDeviceDescriptions& device_descriptions) {
return device_descriptions.size() > 2;
}
......@@ -57,6 +57,9 @@ class MediaNotificationAudioDeviceSelectorView : public views::View,
void CreateDeviceButton(
const media::AudioDeviceDescription& device_description);
bool ShouldBeVisible(
const media::AudioDeviceDescriptions& device_descriptions);
MediaNotificationAudioDeviceSelectorViewDelegate* const delegate_;
MediaNotificationService* const service_;
......
......@@ -217,8 +217,9 @@ TEST_F(MediaNotificationAudioDeviceSelectorViewTest, DeviceButtonsChange) {
auto* provider = provider_.get();
service_->set_device_provider_for_testing(std::move(provider_));
MockMediaNotificationAudioDeviceSelectorViewDelegate delegate;
view_ = std::make_unique<MediaNotificationAudioDeviceSelectorView>(
nullptr, service_.get(), gfx::Size(), "1");
&delegate, service_.get(), gfx::Size(), "1");
std::vector<std::string> button_texts;
ASSERT_TRUE(view_->device_button_container_ != nullptr);
......@@ -239,3 +240,27 @@ TEST_F(MediaNotificationAudioDeviceSelectorViewTest, DeviceButtonsChange) {
// to highlighting the default device.
EXPECT_TRUE(button->GetProminent());
}
TEST_F(MediaNotificationAudioDeviceSelectorViewTest, VisibilityChanges) {
// The audio device selector view should become hidden when there is only one
// unique device.
provider_->AddDevice("Speaker", "1");
provider_->AddDevice("default",
media::AudioDeviceDescription::kDefaultDeviceId);
auto* provider = provider_.get();
service_->set_device_provider_for_testing(std::move(provider_));
MockMediaNotificationAudioDeviceSelectorViewDelegate delegate;
EXPECT_CALL(delegate, OnAudioDeviceSelectorViewSizeChanged).Times(1);
view_ = std::make_unique<MediaNotificationAudioDeviceSelectorView>(
&delegate, service_.get(), gfx::Size(), "1");
EXPECT_FALSE(view_->GetVisible());
testing::Mock::VerifyAndClearExpectations(&delegate);
provider->AddDevice("Headphones", "2");
EXPECT_CALL(delegate, OnAudioDeviceSelectorViewSizeChanged).Times(1);
provider->RunUICallback();
EXPECT_TRUE(view_->GetVisible());
testing::Mock::VerifyAndClearExpectations(&delegate);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment