Commit 418f62a9 authored by Abigail Klein's avatar Abigail Klein Committed by Commit Bot

[Live Caption] Add download progress updates to Zenith.

Make the MediaDialogView observer the SODAInstaller and update the
live_caption_title with a download message as SODA installs.

Bug: 1055150
Change-Id: I54317158bf6678c98ba823490157e510c2fd3d10
AX-Relnotes: N/A (feature has not launched)
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2495922
Commit-Queue: Abigail Klein <abigailbklein@google.com>
Reviewed-by: default avatarTommy Steimel <steimel@chromium.org>
Reviewed-by: default avatarDana Fried <dfried@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825227}
parent 2195f13d
......@@ -19,4 +19,7 @@
<message name="IDS_GLOBAL_MEDIA_CONTROLS_LIVE_CAPTION" desc="Label for the toggle that enables the Live Caption feature. Live Caption only works for English captions.">
Live Caption (English only)
</message>
<message name="IDS_GLOBAL_MEDIA_CONTROLS_LIVE_CAPTION_DOWNLOAD_PROGRESS" desc="Download progress indicator after Live Caption is enabled. The user needs to download certain files for the feature to work.">
Downloading... <ph name="PERCENT">$1<ex>17</ex></ph>%
</message>
</grit-part>
......@@ -76,6 +76,7 @@ views::Widget* MediaDialogView::ShowDialog(views::View* anchor_view,
void MediaDialogView::HideDialog() {
if (IsShowing()) {
instance_->service_->SetDialogDelegate(nullptr);
speech::SODAInstaller::GetInstance()->RemoveObserver(instance_);
instance_->GetWidget()->Close();
}
......@@ -144,6 +145,7 @@ void MediaDialogView::AddedToWidget() {
layer()->SetFillsBoundsOpaquely(false);
}
service_->SetDialogDelegate(this);
speech::SODAInstaller::GetInstance()->AddObserver(this);
}
gfx::Size MediaDialogView::CalculatePreferredSize() const {
......@@ -207,10 +209,6 @@ const MediaNotificationListView* MediaDialogView::GetListViewForTesting()
return active_sessions_view_;
}
views::Button* MediaDialogView::GetLiveCaptionButtonForTesting() {
return live_caption_button_;
}
MediaDialogView::MediaDialogView(views::View* anchor_view,
MediaNotificationService* service,
Profile* profile)
......@@ -259,28 +257,43 @@ void MediaDialogView::Init() {
live_caption_image->SetImage(
gfx::CreateVectorIcon(kLiveCaptionIcon, kLiveCaptionImageWidthDip,
SkColor(gfx::kGoogleGrey700)));
// TODO(crbug.com/1055150): Replace NewBadgeLabel with Label by M93.
auto live_caption_title = std::make_unique<NewBadgeLabel>(
live_caption_container->AddChildView(std::move(live_caption_image));
auto live_caption_title = std::make_unique<views::Label>(
l10n_util::GetStringUTF16(IDS_GLOBAL_MEDIA_CONTROLS_LIVE_CAPTION));
live_caption_title->SetHorizontalAlignment(
gfx::HorizontalAlignment::ALIGN_LEFT);
live_caption_title_ =
live_caption_container->AddChildView(std::move(live_caption_title));
live_caption_container_layout->SetFlexForView(live_caption_title_, 1);
// Only create and show the new badge if Live Caption is not enabled at the
// initialization of the MediaDialogView.
if (!profile_->GetPrefs()->GetBoolean(prefs::kLiveCaptionEnabled)) {
auto live_caption_title_new_badge = std::make_unique<NewBadgeLabel>(
l10n_util::GetStringUTF16(IDS_GLOBAL_MEDIA_CONTROLS_LIVE_CAPTION));
live_caption_title_new_badge->SetHorizontalAlignment(
gfx::HorizontalAlignment::ALIGN_LEFT);
live_caption_title_new_badge_ = live_caption_container->AddChildView(
std::move(live_caption_title_new_badge));
live_caption_container_layout->SetFlexForView(live_caption_title_new_badge_,
1);
live_caption_title_->SetVisible(false);
}
auto live_caption_button =
std::make_unique<views::ToggleButton>(base::BindRepeating(
&MediaDialogView::ToggleLiveCaption, base::Unretained(this)));
&MediaDialogView::LiveCaptionButtonPressed, base::Unretained(this)));
live_caption_button->SetIsOn(
profile_->GetPrefs()->GetBoolean(prefs::kLiveCaptionEnabled));
live_caption_button->SetAccessibleName(live_caption_title->GetText());
live_caption_button->SetAccessibleName(live_caption_title_->GetText());
live_caption_button->SetThumbOnColor(SkColor(gfx::kGoogleBlue600));
live_caption_button->SetTrackOnColor(SkColorSetA(gfx::kGoogleBlue600, 128));
live_caption_button->SetThumbOffColor(SK_ColorWHITE);
live_caption_button->SetTrackOffColor(SkColor(gfx::kGoogleGrey400));
live_caption_container->AddChildView(std::move(live_caption_image));
live_caption_container_layout->SetFlexForView(
live_caption_container->AddChildView(std::move(live_caption_title)), 1);
live_caption_button_ =
live_caption_container->AddChildView(std::move(live_caption_button));
live_caption_container_ = AddChildView(std::move(live_caption_container));
}
......@@ -288,11 +301,38 @@ void MediaDialogView::WindowClosing() {
if (instance_ == this) {
instance_ = nullptr;
service_->SetDialogDelegate(nullptr);
speech::SODAInstaller::GetInstance()->RemoveObserver(this);
}
}
void MediaDialogView::ToggleLiveCaption(const ui::Event& event) {
void MediaDialogView::LiveCaptionButtonPressed(const ui::Event& event) {
bool enabled = !profile_->GetPrefs()->GetBoolean(prefs::kLiveCaptionEnabled);
ToggleLiveCaption(enabled);
}
void MediaDialogView::ToggleLiveCaption(bool enabled) {
profile_->GetPrefs()->SetBoolean(prefs::kLiveCaptionEnabled, enabled);
live_caption_button_->SetIsOn(enabled);
if (live_caption_title_new_badge_ &&
live_caption_title_new_badge_->GetVisible()) {
live_caption_title_->SetVisible(true);
live_caption_title_new_badge_->SetVisible(false);
}
}
void MediaDialogView::OnSODAInstalled() {
live_caption_title_->SetText(
l10n_util::GetStringUTF16(IDS_GLOBAL_MEDIA_CONTROLS_LIVE_CAPTION));
}
void MediaDialogView::OnSODAError() {
ToggleLiveCaption(false);
live_caption_title_->SetText(
l10n_util::GetStringUTF16(IDS_GLOBAL_MEDIA_CONTROLS_LIVE_CAPTION));
// TODO(crbug.com/1055150): Show an error message as a toast.
}
void MediaDialogView::OnSODAProgress(int progress) {
live_caption_title_->SetText(l10n_util::GetStringFUTF16Int(
IDS_GLOBAL_MEDIA_CONTROLS_LIVE_CAPTION_DOWNLOAD_PROGRESS, progress));
}
......@@ -11,6 +11,7 @@
#include "base/observer_list.h"
#include "base/optional.h"
#include "chrome/browser/accessibility/soda_installer.h"
#include "chrome/browser/ui/global_media_controls/media_dialog_delegate.h"
#include "chrome/browser/ui/global_media_controls/media_notification_container_observer.h"
#include "ui/views/bubble/bubble_dialog_delegate_view.h"
......@@ -19,16 +20,19 @@ class MediaDialogViewObserver;
class MediaNotificationContainerImplView;
class MediaNotificationListView;
class MediaNotificationService;
class NewBadgeLabel;
class Profile;
namespace views {
class Label;
class ToggleButton;
}
// Dialog that shows media controls that control the active media session.
class MediaDialogView : public views::BubbleDialogDelegateView,
public MediaDialogDelegate,
public MediaNotificationContainerObserver {
public MediaNotificationContainerObserver,
public speech::SODAInstaller::Observer {
public:
static views::Widget* ShowDialog(views::View* anchor_view,
MediaNotificationService* service,
......@@ -71,9 +75,8 @@ class MediaDialogView : public views::BubbleDialogDelegateView,
const MediaNotificationListView* GetListViewForTesting() const;
views::Button* GetLiveCaptionButtonForTesting();
private:
friend class MediaDialogViewBrowserTest;
explicit MediaDialogView(views::View* anchor_view,
MediaNotificationService* service,
Profile* profile);
......@@ -89,10 +92,16 @@ class MediaDialogView : public views::BubbleDialogDelegateView,
void WindowClosing() override;
// views::Button::PressedCallback
void ToggleLiveCaption(const ui::Event& event);
void LiveCaptionButtonPressed(const ui::Event& event);
void ToggleLiveCaption(bool enabled);
void UpdateBubbleSize();
// SODAInstaller::Observer overrides:
void OnSODAInstalled() override;
void OnSODAError() override;
void OnSODAProgress(int progress) override;
MediaNotificationService* const service_;
Profile* const profile_;
......@@ -106,7 +115,9 @@ class MediaDialogView : public views::BubbleDialogDelegateView,
observed_containers_;
views::View* live_caption_container_ = nullptr;
// TODO(crbug.com/1055150): Remove live_caption_title_new_badge_ by M93.
NewBadgeLabel* live_caption_title_new_badge_ = nullptr;
views::Label* live_caption_title_ = nullptr;
views::ToggleButton* live_caption_button_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(MediaDialogView);
......
......@@ -17,6 +17,7 @@
#include "chrome/browser/ui/views/global_media_controls/media_notification_list_view.h"
#include "chrome/browser/ui/views/global_media_controls/media_toolbar_button_view.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "chrome/browser/ui/views/user_education/new_badge_label.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/interactive_test_utils.h"
......@@ -31,6 +32,7 @@
#include "media/base/media_switches.h"
#include "services/media_session/public/mojom/media_session.mojom.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/button/toggle_button.h"
#include "ui/views/view_utils.h"
using media_session::mojom::MediaSessionAction;
......@@ -478,8 +480,8 @@ class MediaDialogViewBrowserTest : public InProcessBrowserTest {
void ClickEnableLiveCaptionOnDialog() {
base::RunLoop().RunUntilIdle();
ASSERT_TRUE(MediaDialogView::IsShowing());
auto* live_caption_button = MediaDialogView::GetDialogViewForTesting()
->GetLiveCaptionButtonForTesting();
views::Button* live_caption_button = static_cast<views::Button*>(
MediaDialogView::GetDialogViewForTesting()->live_caption_button_);
ClickButton(live_caption_button);
}
......@@ -529,6 +531,23 @@ class MediaDialogViewBrowserTest : public InProcessBrowserTest {
return false;
}
views::Label* GetLiveCaptionTitleLabel() {
return MediaDialogView::GetDialogViewForTesting()->live_caption_title_;
}
views::Label* GetLiveCaptionTitleNewBadgeLabel() {
return MediaDialogView::GetDialogViewForTesting()
->live_caption_title_new_badge_;
}
void OnSODAProgress(int progress) {
MediaDialogView::GetDialogViewForTesting()->OnSODAProgress(progress);
}
void OnSODAInstalled() {
MediaDialogView::GetDialogViewForTesting()->OnSODAInstalled();
}
protected:
std::unique_ptr<TestWebContentsPresentationManager> presentation_manager_;
TestMediaRouter* media_router_ = nullptr;
......@@ -873,13 +892,26 @@ IN_PROC_BROWSER_TEST_F(MediaDialogViewBrowserTest, LiveCaption) {
WaitForDialogOpened();
EXPECT_TRUE(IsDialogVisible());
// When media dialog opens and Live Caption is disabled, the New badge is
// visible and the regular title is not visible.
EXPECT_NE(GetLiveCaptionTitleNewBadgeLabel(), nullptr);
EXPECT_TRUE(GetLiveCaptionTitleNewBadgeLabel()->GetVisible());
EXPECT_FALSE(GetLiveCaptionTitleLabel()->GetVisible());
ClickEnableLiveCaptionOnDialog();
EXPECT_TRUE(
browser()->profile()->GetPrefs()->GetBoolean(prefs::kLiveCaptionEnabled));
// The New Badge disappears when Live Caption is enabled. The regular title
// appears.
EXPECT_FALSE(GetLiveCaptionTitleNewBadgeLabel()->GetVisible());
EXPECT_TRUE(GetLiveCaptionTitleLabel()->GetVisible());
ClickEnableLiveCaptionOnDialog();
EXPECT_FALSE(
browser()->profile()->GetPrefs()->GetBoolean(prefs::kLiveCaptionEnabled));
// The New Badge doesn't reappear after Live Caption is disabled again.
EXPECT_FALSE(GetLiveCaptionTitleNewBadgeLabel()->GetVisible());
EXPECT_TRUE(GetLiveCaptionTitleLabel()->GetVisible());
// Close dialog and enable live caption preference. Reopen dialog.
ClickToolbarIcon();
......@@ -889,8 +921,48 @@ IN_PROC_BROWSER_TEST_F(MediaDialogViewBrowserTest, LiveCaption) {
ClickToolbarIcon();
WaitForDialogOpened();
EXPECT_TRUE(IsDialogVisible());
// When media dialog opens and Live Caption is enabled, the New badge is not
// created. The regular title is visible.
EXPECT_EQ(GetLiveCaptionTitleNewBadgeLabel(), nullptr);
EXPECT_TRUE(GetLiveCaptionTitleLabel()->GetVisible());
ClickEnableLiveCaptionOnDialog();
EXPECT_FALSE(
browser()->profile()->GetPrefs()->GetBoolean(prefs::kLiveCaptionEnabled));
// The New badge is still not created. The regular title is still visible.
EXPECT_EQ(GetLiveCaptionTitleNewBadgeLabel(), nullptr);
EXPECT_TRUE(GetLiveCaptionTitleLabel()->GetVisible());
}
IN_PROC_BROWSER_TEST_F(MediaDialogViewBrowserTest, LiveCaptionProgressUpdate) {
// Open a tab and play media.
OpenTestURL();
StartPlayback();
WaitForStart();
// Open the media dialog.
WaitForVisibleToolbarIcon();
ClickToolbarIcon();
WaitForDialogOpened();
EXPECT_TRUE(IsDialogVisible());
EXPECT_EQ("Live Caption (English only)",
base::UTF16ToUTF8(GetLiveCaptionTitleNewBadgeLabel()->GetText()));
ClickEnableLiveCaptionOnDialog();
OnSODAProgress(0);
EXPECT_EQ("Downloading… 0%",
base::UTF16ToUTF8(GetLiveCaptionTitleLabel()->GetText()));
OnSODAProgress(12);
EXPECT_EQ("Downloading… 12%",
base::UTF16ToUTF8(GetLiveCaptionTitleLabel()->GetText()));
OnSODAProgress(100);
EXPECT_EQ("Downloading… 100%",
base::UTF16ToUTF8(GetLiveCaptionTitleLabel()->GetText()));
OnSODAInstalled();
EXPECT_EQ("Live Caption (English only)",
base::UTF16ToUTF8(GetLiveCaptionTitleLabel()->GetText()));
}
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