Commit ce7ecc9b authored by Takumi Fujimoto's avatar Takumi Fujimoto Committed by Commit Bot

[Harmony Cast Dialog] Change status text/icon for various sink states

If a sink is DISCONNECTING, change the icon to a throbber and change the
status text to "Disconnecting...", but don't grey out the title text.

If a sink is AVAILABLE but does not support the selected source, change
the status text to "Source not supported".

The hashes for the screenshots are per the instructions here:
https://docs.google.com/document/d/1nwYWDny20icMSpLUuV_LgrlbWKrYpbXOERUIZNH636o/edit
And the screenshots are uploaded here:
https://storage.googleapis.com/chromium-translation-screenshots/7f85b1d7787495adf8153366ecc39cdd43762144
https://storage.googleapis.com/chromium-translation-screenshots/7f3bb4aeb5b577e98ab1415b31f967311af8747a

Bug: 902493, 899998, 883392
Change-Id: Ib556de3e5407500a63c729c7bd02001572fa91e8
Reviewed-on: https://chromium-review.googlesource.com/c/1325070Reviewed-by: default avatarmark a. foltz <mfoltz@chromium.org>
Commit-Queue: Takumi Fujimoto <takumif@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607297}
parent e13a84b7
......@@ -219,9 +219,15 @@
<message name="IDS_MEDIA_ROUTER_SINK_CONNECTING" desc="Text shown as the status of a Cast destination that we are starting a Cast session on.">
Connecting...
</message>
<message name="IDS_MEDIA_ROUTER_SINK_DISCONNECTING" desc="Text shown as the status of a Cast device that has a Cast session that is ending.">
Disconnecting...
</message>
<message name="IDS_MEDIA_ROUTER_STOP_CASTING" desc="Text shown when user hovers over the stop icon for a cast device.">
Stop casting
</message>
<message name="IDS_MEDIA_ROUTER_SOURCE_NOT_SUPPORTED" desc="Text shown as the status of a Cast device that is not compatible with the selected Cast source (contents).">
Source not supported
</message>
<!-- Sink Search -->
<message name="IDS_MEDIA_ROUTER_SEARCH_LABEL" desc="Label for search input in sink list.">
......
7f85b1d7787495adf8153366ecc39cdd43762144
\ No newline at end of file
7f3bb4aeb5b577e98ab1415b31f967311af8747a
\ No newline at end of file
......@@ -135,8 +135,7 @@ std::unique_ptr<views::View> CreatePrimaryIconForSink(
const UIMediaSink& sink,
int button_tag) {
// The stop button has the highest priority, and the issue icon comes second.
if (sink.state == UIMediaSinkState::CONNECTED ||
sink.state == UIMediaSinkState::DISCONNECTING) {
if (sink.state == UIMediaSinkState::CONNECTED) {
return std::make_unique<StopButton>(
sink_button, button_listener, sink, button_tag,
sink.state == UIMediaSinkState::CONNECTED);
......@@ -148,7 +147,8 @@ std::unique_ptr<views::View> CreatePrimaryIconForSink(
icon_view->SetBorder(
views::CreateEmptyBorder(gfx::Insets(kPrimaryIconBorderWidth)));
return icon_view;
} else if (sink.state == UIMediaSinkState::CONNECTING) {
} else if (sink.state == UIMediaSinkState::CONNECTING ||
sink.state == UIMediaSinkState::DISCONNECTING) {
return CreateThrobber();
}
auto icon_view = std::make_unique<views::ImageView>();
......@@ -161,6 +161,10 @@ std::unique_ptr<views::View> CreatePrimaryIconForSink(
base::string16 GetStatusTextForSink(const UIMediaSink& sink) {
if (sink.issue)
return base::UTF8ToUTF16(sink.issue->info().title);
// If the sink is disconnecting, say so instead of using the source info
// stored in |sink.status_text|.
if (sink.state == UIMediaSinkState::DISCONNECTING)
return l10n_util::GetStringUTF16(IDS_MEDIA_ROUTER_SINK_DISCONNECTING);
if (!sink.status_text.empty())
return sink.status_text;
switch (sink.state) {
......@@ -223,20 +227,25 @@ void CastDialogSinkButton::OnMouseReleased(const ui::MouseEvent& event) {
void CastDialogSinkButton::OnEnabledChanged() {
HoverButton::OnEnabledChanged();
// If the button has a state other than AVAILABLE (e.g. CONNECTED), there is
// no need to change the status or the icon.
if (sink_.state != UIMediaSinkState::AVAILABLE)
return;
SkColor background_color = GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_ProminentButtonColor);
if (enabled() || sink_.state == UIMediaSinkState::CONNECTED) {
if (enabled()) {
SetTitleTextStyle(views::style::STYLE_PRIMARY, background_color);
if (sink_.state == UIMediaSinkState::AVAILABLE) {
static_cast<views::ImageView*>(icon_view())
->SetImage(CreateSinkIcon(sink_.icon_type));
}
if (saved_status_text_)
RestoreStatusText();
static_cast<views::ImageView*>(icon_view())
->SetImage(CreateSinkIcon(sink_.icon_type));
} else {
SetTitleTextStyle(views::style::STYLE_DISABLED, background_color);
if (sink_.state == UIMediaSinkState::AVAILABLE) {
static_cast<views::ImageView*>(icon_view())
->SetImage(CreateDisabledSinkIcon(sink_.icon_type));
}
OverrideStatusText(
l10n_util::GetStringUTF16(IDS_MEDIA_ROUTER_SOURCE_NOT_SUPPORTED));
static_cast<views::ImageView*>(icon_view())
->SetImage(CreateDisabledSinkIcon(sink_.icon_type));
}
// Apply the style change to the title text.
title()->Layout();
......
......@@ -35,11 +35,18 @@ class CastDialogSinkButton : public HoverButton {
const UIMediaSink& sink() const { return sink_; }
private:
UIMediaSink sink_;
FRIEND_TEST_ALL_PREFIXES(CastDialogSinkButtonTest, OverrideStatusText);
FRIEND_TEST_ALL_PREFIXES(CastDialogSinkButtonTest,
SetStatusLabelForActiveSink);
FRIEND_TEST_ALL_PREFIXES(CastDialogSinkButtonTest,
SetStatusLabelForAvailableSink);
FRIEND_TEST_ALL_PREFIXES(CastDialogSinkButtonTest,
SetStatusLabelForSinkWithIssue);
const UIMediaSink sink_;
base::Optional<base::string16> saved_status_text_;
DISALLOW_COPY_AND_ASSIGN(CastDialogSinkButton);
FRIEND_TEST_ALL_PREFIXES(CastDialogSinkButtonTest, OverrideStatusText);
};
} // namespace media_router
......
......@@ -33,28 +33,55 @@ TEST_F(CastDialogSinkButtonTest, SetTitleLabel) {
EXPECT_EQ(sink.friendly_name, button.title()->text());
}
TEST_F(CastDialogSinkButtonTest, SetStatusLabel) {
TEST_F(CastDialogSinkButtonTest, SetStatusLabelForAvailableSink) {
UIMediaSink sink;
sink.state = UIMediaSinkState::AVAILABLE;
CastDialogSinkButton button1(nullptr, sink, 0);
CastDialogSinkButton button(nullptr, sink, 0);
EXPECT_EQ(l10n_util::GetStringUTF16(IDS_MEDIA_ROUTER_SINK_AVAILABLE),
button1.subtitle()->text());
button.subtitle()->text());
// Disabling an AVAILABLE sink button should change its label to "Source not
// supported".
button.SetEnabled(false);
EXPECT_EQ(l10n_util::GetStringUTF16(IDS_MEDIA_ROUTER_SOURCE_NOT_SUPPORTED),
button.subtitle()->text());
// Re-enabling it should make set the label to "Available" again.
button.SetEnabled(true);
EXPECT_EQ(l10n_util::GetStringUTF16(IDS_MEDIA_ROUTER_SINK_AVAILABLE),
button.subtitle()->text());
}
TEST_F(CastDialogSinkButtonTest, SetStatusLabelForActiveSink) {
UIMediaSink sink;
sink.state = UIMediaSinkState::CONNECTING;
CastDialogSinkButton button2(nullptr, sink, 1);
CastDialogSinkButton button1(nullptr, sink, 0);
EXPECT_EQ(l10n_util::GetStringUTF16(IDS_MEDIA_ROUTER_SINK_CONNECTING),
button2.subtitle()->text());
button1.subtitle()->text());
sink.state = UIMediaSinkState::CONNECTED;
sink.status_text = base::UTF8ToUTF16("status text");
CastDialogSinkButton button2(nullptr, sink, 1);
EXPECT_EQ(sink.status_text, button2.subtitle()->text());
// The status label should be "Disconnecting..." even if |status_text| is set.
sink.state = UIMediaSinkState::DISCONNECTING;
CastDialogSinkButton button3(nullptr, sink, 2);
EXPECT_EQ(sink.status_text, button3.subtitle()->text());
EXPECT_EQ(l10n_util::GetStringUTF16(IDS_MEDIA_ROUTER_SINK_DISCONNECTING),
button3.subtitle()->text());
}
TEST_F(CastDialogSinkButtonTest, SetStatusLabelForSinkWithIssue) {
UIMediaSink sink;
sink.issue = Issue(IssueInfo("issue", IssueInfo::Action::DISMISS,
IssueInfo::Severity::WARNING));
CastDialogSinkButton button4(nullptr, sink, 3);
// Issue info should be the status text regardless of the sink state.
sink.state = UIMediaSinkState::AVAILABLE;
CastDialogSinkButton button1(nullptr, sink, 0);
EXPECT_EQ(base::UTF8ToUTF16(sink.issue->info().title),
button4.subtitle()->text());
button1.subtitle()->text());
sink.state = UIMediaSinkState::CONNECTED;
CastDialogSinkButton button2(nullptr, sink, 1);
EXPECT_EQ(base::UTF8ToUTF16(sink.issue->info().title),
button2.subtitle()->text());
}
TEST_F(CastDialogSinkButtonTest, OverrideStatusText) {
......
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