Commit d6bfa043 authored by Abigail Klein's avatar Abigail Klein Committed by Chromium LUCI CQ

[Live Caption] Fix caption bubble error state.

Do not show the expand/collapse buttons when there is an error,
and set the error state to false if the caption bubble starts
receiving text.

Bug: 1055150
Change-Id: Id5e8a7b4fd93058643673a7707eda22f94baf5dc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2598619Reviewed-by: default avatarJosiah Krutz <josiahk@google.com>
Commit-Queue: Abigail Klein <abigailbklein@google.com>
Cr-Commit-Position: refs/heads/master@{#839779}
parent dfa5f181
...@@ -648,6 +648,8 @@ void CaptionBubble::OnErrorChanged() { ...@@ -648,6 +648,8 @@ void CaptionBubble::OnErrorChanged() {
bool has_error = model_->HasError(); bool has_error = model_->HasError();
label_->SetVisible(!has_error); label_->SetVisible(!has_error);
error_message_->SetVisible(has_error); error_message_->SetVisible(has_error);
expand_button_->SetVisible(!has_error && !is_expanded_);
collapse_button_->SetVisible(!has_error && is_expanded_);
// The error is only 1 line, so redraw the bubble. // The error is only 1 line, so redraw the bubble.
Redraw(); Redraw();
......
...@@ -395,21 +395,24 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, ShowsAndHidesError) { ...@@ -395,21 +395,24 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, ShowsAndHidesError) {
EXPECT_TRUE(GetLabel()->GetVisible()); EXPECT_TRUE(GetLabel()->GetVisible());
EXPECT_FALSE(GetErrorMessage()->GetVisible()); EXPECT_FALSE(GetErrorMessage()->GetVisible());
OnError(0); OnError();
EXPECT_FALSE(GetTitle()->GetVisible()); EXPECT_FALSE(GetTitle()->GetVisible());
EXPECT_FALSE(GetLabel()->GetVisible()); EXPECT_FALSE(GetLabel()->GetVisible());
EXPECT_TRUE(GetErrorMessage()->GetVisible()); EXPECT_TRUE(GetErrorMessage()->GetVisible());
// Setting text during an error shouldn't cause the error to disappear. // Setting text during an error should cause the error to disappear.
OnPartialTranscription("Elephant tails average 4-5 feet long."); OnPartialTranscription("Elephant tails average 4-5 feet long.");
EXPECT_FALSE(GetTitle()->GetVisible()); EXPECT_TRUE(GetTitle()->GetVisible());
EXPECT_FALSE(GetLabel()->GetVisible()); EXPECT_TRUE(GetLabel()->GetVisible());
EXPECT_TRUE(GetErrorMessage()->GetVisible()); EXPECT_FALSE(GetErrorMessage()->GetVisible());
// Set the error again.
OnError();
// The error should not be visible on a new tab. // The error should not be visible on a new tab.
InsertNewTab(); InsertNewTab();
ActivateTabAt(1); ActivateTabAt(1);
OnPartialTranscription("Elephants are vegetarians."); OnPartialTranscription("Elephants are vegetarians.", 1);
EXPECT_TRUE(GetTitle()->GetVisible()); EXPECT_TRUE(GetTitle()->GetVisible());
EXPECT_TRUE(GetLabel()->GetVisible()); EXPECT_TRUE(GetLabel()->GetVisible());
EXPECT_FALSE(GetErrorMessage()->GetVisible()); EXPECT_FALSE(GetErrorMessage()->GetVisible());
...@@ -880,7 +883,7 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, ExpandsAndCollapses) { ...@@ -880,7 +883,7 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, ExpandsAndCollapses) {
ActivateTabAt(1); ActivateTabAt(1);
EXPECT_FALSE(IsWidgetVisible()); EXPECT_FALSE(IsWidgetVisible());
OnPartialTranscription("Nearly all ants are female."); OnPartialTranscription("Nearly all ants are female.", 1);
EXPECT_TRUE(GetCollapseButton()->GetVisible()); EXPECT_TRUE(GetCollapseButton()->GetVisible());
EXPECT_FALSE(GetExpandButton()->GetVisible()); EXPECT_FALSE(GetExpandButton()->GetVisible());
EXPECT_EQ(7 * line_height, GetLabel()->GetBoundsInScreen().height()); EXPECT_EQ(7 * line_height, GetLabel()->GetBoundsInScreen().height());
...@@ -889,6 +892,17 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, ExpandsAndCollapses) { ...@@ -889,6 +892,17 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, ExpandsAndCollapses) {
EXPECT_TRUE(GetExpandButton()->GetVisible()); EXPECT_TRUE(GetExpandButton()->GetVisible());
EXPECT_FALSE(GetCollapseButton()->GetVisible()); EXPECT_FALSE(GetCollapseButton()->GetVisible());
EXPECT_EQ(line_height, GetLabel()->GetBoundsInScreen().height()); EXPECT_EQ(line_height, GetLabel()->GetBoundsInScreen().height());
// The expand and collapse buttons are not visible when there is an error.
OnError(1);
EXPECT_FALSE(GetCollapseButton()->GetVisible());
EXPECT_FALSE(GetExpandButton()->GetVisible());
// Clear the error message. The expand button should appear.
OnPartialTranscription("An ant can lift 20 times its own body weight.", 1);
EXPECT_TRUE(GetExpandButton()->GetVisible());
EXPECT_FALSE(GetCollapseButton()->GetVisible());
EXPECT_EQ(line_height, GetLabel()->GetBoundsInScreen().height());
} }
IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, NonAsciiCharacter) { IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, NonAsciiCharacter) {
......
...@@ -46,6 +46,11 @@ void CaptionBubbleModel::OnTextChanged() { ...@@ -46,6 +46,11 @@ void CaptionBubbleModel::OnTextChanged() {
void CaptionBubbleModel::SetPartialText(const std::string& partial_text) { void CaptionBubbleModel::SetPartialText(const std::string& partial_text) {
partial_text_ = partial_text; partial_text_ = partial_text;
OnTextChanged(); OnTextChanged();
if (has_error_) {
has_error_ = false;
if (observer_)
observer_->OnErrorChanged();
}
} }
void CaptionBubbleModel::Close() { void CaptionBubbleModel::Close() {
......
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