Commit f857cc1f authored by Abigail Klein's avatar Abigail Klein Committed by Commit Bot

[Live Caption] Remove "Detecting speech..." message.

The UI showed a "Detecting speech..." message in the caption bubble as
soon as audio started playing to alert the user that Live Caption was
beginning to detect speech. This caused a bug in which the caption
bubble appeared when audio that does not contain speech began to play,
such as short pings. The team decided to remove the "Detecting
speech..." message from the UI as a result.

This CL removes the text from the UI and removes the
OnSpeechRecognitionReady message sent from the
ChromeSpeechRecognitionClient to the caption UI, which is no longer
necessary. It also introduces a new accessible label for the caption
bubble, which is necessary so that the bubble can set the AXNodeData
name when the bubble label does not contain any text.

Bug: 1055150, 1114232
Change-Id: I85fdab48a34176e67733f4540ec534c6e7e0109f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2368464Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Commit-Queue: Abigail Klein <abigailbklein@google.com>
Cr-Commit-Position: refs/heads/master@{#801097}
parent 086209a8
...@@ -9319,9 +9319,6 @@ Please help our engineers fix this problem. Tell us what happened right before y ...@@ -9319,9 +9319,6 @@ Please help our engineers fix this problem. Tell us what happened right before y
</message> </message>
<!-- Live caption. --> <!-- Live caption. -->
<message name="IDS_LIVE_CAPTION_BUBBLE_WAIT_TEXT" desc="Text displayed in the Live Caption bubble when it is waiting for captions from the speech service">
Detecting speech...
</message>
<message name="IDS_LIVE_CAPTION_BUBBLE_CLOSE" desc="Tooltip for the Live Caption close button"> <message name="IDS_LIVE_CAPTION_BUBBLE_CLOSE" desc="Tooltip for the Live Caption close button">
Turn off Live Caption for now Turn off Live Caption for now
</message> </message>
...@@ -9334,6 +9331,9 @@ Please help our engineers fix this problem. Tell us what happened right before y ...@@ -9334,6 +9331,9 @@ Please help our engineers fix this problem. Tell us what happened right before y
<message name="IDS_LIVE_CAPTION_BUBBLE_ERROR" desc="Error message for the Live Caption bubble when Live Captions are unavailable."> <message name="IDS_LIVE_CAPTION_BUBBLE_ERROR" desc="Error message for the Live Caption bubble when Live Captions are unavailable.">
Live Caption is not available right now Live Caption is not available right now
</message> </message>
<message name="IDS_LIVE_CAPTION_BUBBLE_ACCESSIBLE_NAME" desc="Label of the Live Caption bubble for accessibility.">
Live Caption
</message>
<!-- Caret browsing. --> <!-- Caret browsing. -->
<if expr="not chromeos"> <if expr="not chromeos">
......
5230947232906708b0262c0f093cbe3e7617b65e
\ No newline at end of file
879ad09cc2870b9ee0ebac0bfc2e31338adf2144
\ No newline at end of file
...@@ -182,15 +182,6 @@ void CaptionController::OnBrowserRemoved(Browser* browser) { ...@@ -182,15 +182,6 @@ void CaptionController::OnBrowserRemoved(Browser* browser) {
caption_bubble_controllers_.erase(browser); caption_bubble_controllers_.erase(browser);
} }
bool CaptionController::OnSpeechRecognitionReady(
content::WebContents* web_contents) {
Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
if (!browser || !caption_bubble_controllers_.count(browser))
return false;
return caption_bubble_controllers_[browser]->OnSpeechRecognitionReady(
web_contents);
}
bool CaptionController::DispatchTranscription( bool CaptionController::DispatchTranscription(
content::WebContents* web_contents, content::WebContents* web_contents,
const chrome::mojom::TranscriptionResultPtr& transcription_result) { const chrome::mojom::TranscriptionResultPtr& transcription_result) {
......
...@@ -64,12 +64,6 @@ class CaptionController : public BrowserListObserver, public KeyedService { ...@@ -64,12 +64,6 @@ class CaptionController : public BrowserListObserver, public KeyedService {
void Init(); void Init();
// Alerts the CaptionBubbleController that belongs to the appropriate browser
// that speech recognition is ready to start for the given web contents.
// Returns whether this message was routed successfully. Transcriptions will
// not proceed if this returns false.
bool OnSpeechRecognitionReady(content::WebContents* web_contents);
// Routes a transcription to the CaptionBubbleController that belongs to the // Routes a transcription to the CaptionBubbleController that belongs to the
// appropriate browser. Returns whether the transcription result was routed // appropriate browser. Returns whether the transcription result was routed
// successfully. Transcriptions will halt if this returns false. // successfully. Transcriptions will halt if this returns false.
......
...@@ -83,21 +83,6 @@ class CaptionControllerTest : public InProcessBrowserTest { ...@@ -83,21 +83,6 @@ class CaptionControllerTest : public InProcessBrowserTest {
->GetCaptionBubbleControllerForBrowser(browser); ->GetCaptionBubbleControllerForBrowser(browser);
} }
bool OnSpeechRecognitionReady() {
return OnSpeechRecognitionReadyOnBrowser(browser());
}
bool OnSpeechRecognitionReadyOnBrowser(Browser* browser) {
return OnSpeechRecognitionReadyOnBrowserForProfile(browser,
browser->profile());
}
bool OnSpeechRecognitionReadyOnBrowserForProfile(Browser* browser,
Profile* profile) {
return GetControllerForProfile(profile)->OnSpeechRecognitionReady(
browser->tab_strip_model()->GetActiveWebContents());
}
bool DispatchTranscription(std::string text) { bool DispatchTranscription(std::string text) {
return DispatchTranscriptionToBrowser(text, browser()); return DispatchTranscriptionToBrowser(text, browser());
} }
...@@ -199,8 +184,9 @@ IN_PROC_BROWSER_TEST_F(CaptionControllerTest, LiveCaptionEnabledChanged) { ...@@ -199,8 +184,9 @@ IN_PROC_BROWSER_TEST_F(CaptionControllerTest, LiveCaptionEnabledChanged) {
IN_PROC_BROWSER_TEST_F(CaptionControllerTest, IN_PROC_BROWSER_TEST_F(CaptionControllerTest,
LiveCaptionEnabledChanged_BubbleVisible) { LiveCaptionEnabledChanged_BubbleVisible) {
SetLiveCaptionEnabled(true); SetLiveCaptionEnabled(true);
// Make the bubble visible. // Make the bubble visible by dispatching a transcription.
OnSpeechRecognitionReady(); DispatchTranscription(
"In Switzerland it is illegal to own just one guinea pig.");
// The CaptionBubbleController is currently only implemented in Views. // The CaptionBubbleController is currently only implemented in Views.
#if defined(TOOLKIT_VIEWS) #if defined(TOOLKIT_VIEWS)
EXPECT_TRUE(IsWidgetVisible()); EXPECT_TRUE(IsWidgetVisible());
...@@ -273,8 +259,9 @@ IN_PROC_BROWSER_TEST_F(CaptionControllerTest, OnBrowserRemoved) { ...@@ -273,8 +259,9 @@ IN_PROC_BROWSER_TEST_F(CaptionControllerTest, OnBrowserRemoved) {
controller->GetCaptionBubbleControllerForBrowser(browser4)); controller->GetCaptionBubbleControllerForBrowser(browser4));
EXPECT_EQ(3, NumBubbleControllers()); EXPECT_EQ(3, NumBubbleControllers());
// Make the bubble on browser3 visible. // Make the bubble on browser3 visible by dispatching a transcription.
OnSpeechRecognitionReadyOnBrowser(browser3); DispatchTranscriptionToBrowser(
"If you lift a kangaroo's tail off the ground it can't hop.", browser3);
// The CaptionBubbleController is currently only implemented in Views. // The CaptionBubbleController is currently only implemented in Views.
#if defined(TOOLKIT_VIEWS) #if defined(TOOLKIT_VIEWS)
EXPECT_TRUE(IsWidgetVisibleOnBrowser(browser3)); EXPECT_TRUE(IsWidgetVisibleOnBrowser(browser3));
...@@ -287,8 +274,9 @@ IN_PROC_BROWSER_TEST_F(CaptionControllerTest, OnBrowserRemoved) { ...@@ -287,8 +274,9 @@ IN_PROC_BROWSER_TEST_F(CaptionControllerTest, OnBrowserRemoved) {
controller->GetCaptionBubbleControllerForBrowser(browser3)); controller->GetCaptionBubbleControllerForBrowser(browser3));
EXPECT_EQ(2, NumBubbleControllers()); EXPECT_EQ(2, NumBubbleControllers());
// Make the bubble on browser2 visible. // Make the bubble on browser2 visible by dispatching a transcription.
OnSpeechRecognitionReadyOnBrowser(browser2); DispatchTranscriptionToBrowser(
"A lion's roar can be heard from 5 miles away.", browser2);
// The CaptionBubbleController is currently only implemented in Views. // The CaptionBubbleController is currently only implemented in Views.
#if defined(TOOLKIT_VIEWS) #if defined(TOOLKIT_VIEWS)
EXPECT_TRUE(IsWidgetVisibleOnBrowser(browser2)); EXPECT_TRUE(IsWidgetVisibleOnBrowser(browser2));
...@@ -324,8 +312,11 @@ IN_PROC_BROWSER_TEST_F(CaptionControllerTest, OnBrowserRemoved_Incognito) { ...@@ -324,8 +312,11 @@ IN_PROC_BROWSER_TEST_F(CaptionControllerTest, OnBrowserRemoved_Incognito) {
incognito_browser2)); incognito_browser2));
EXPECT_EQ(2, NumBubbleControllers()); EXPECT_EQ(2, NumBubbleControllers());
// Make the bubble on incognito_browser1 visible. // Make the bubble on incognito_browser1 visible by dispatching a
OnSpeechRecognitionReadyOnBrowser(incognito_browser1); // transcription.
DispatchTranscriptionToBrowser(
"If you lift a kangaroo's tail off the ground it can't hop.",
incognito_browser1);
// The CaptionBubbleController is currently only implemented in Views. // The CaptionBubbleController is currently only implemented in Views.
#if defined(TOOLKIT_VIEWS) #if defined(TOOLKIT_VIEWS)
EXPECT_TRUE(IsWidgetVisibleOnBrowser(incognito_browser1)); EXPECT_TRUE(IsWidgetVisibleOnBrowser(incognito_browser1));
...@@ -339,77 +330,12 @@ IN_PROC_BROWSER_TEST_F(CaptionControllerTest, OnBrowserRemoved_Incognito) { ...@@ -339,77 +330,12 @@ IN_PROC_BROWSER_TEST_F(CaptionControllerTest, OnBrowserRemoved_Incognito) {
EXPECT_EQ(1, NumBubbleControllers()); EXPECT_EQ(1, NumBubbleControllers());
} }
IN_PROC_BROWSER_TEST_F(CaptionControllerTest, OnSpeechRecognitionReady) {
bool success = OnSpeechRecognitionReady();
EXPECT_FALSE(success);
EXPECT_EQ(0, NumBubbleControllers());
SetLiveCaptionEnabled(true);
success = OnSpeechRecognitionReady();
EXPECT_TRUE(success);
// The CaptionBubbleController is currently only implemented in Views.
#if defined(TOOLKIT_VIEWS)
EXPECT_TRUE(IsWidgetVisible());
#else
EXPECT_FALSE(IsWidgetVisible());
#endif
SetLiveCaptionEnabled(false);
success = OnSpeechRecognitionReady();
EXPECT_FALSE(success);
EXPECT_EQ(0, NumBubbleControllers());
}
IN_PROC_BROWSER_TEST_F(CaptionControllerTest,
OnSpeechRecognitionReady_MultipleBrowsers) {
Browser* browser1 = browser();
Browser* browser2 = CreateBrowser(browser()->profile());
Browser* incognito_browser = CreateIncognitoBrowser();
SetLiveCaptionEnabled(true);
// OnSpeechRecognitionReady routes to the right browser.
bool success = OnSpeechRecognitionReadyOnBrowser(browser1);
EXPECT_TRUE(success);
// The CaptionBubbleController is currently only implemented in Views.
#if defined(TOOLKIT_VIEWS)
EXPECT_TRUE(IsWidgetVisibleOnBrowser(browser1));
EXPECT_FALSE(IsWidgetVisibleOnBrowser(browser2));
EXPECT_FALSE(IsWidgetVisibleOnBrowser(incognito_browser));
#else
EXPECT_FALSE(IsWidgetVisibleOnBrowser(browser1));
#endif
success = OnSpeechRecognitionReadyOnBrowser(browser2);
EXPECT_TRUE(success);
// The CaptionBubbleController is currently only implemented in Views.
#if defined(TOOLKIT_VIEWS)
EXPECT_TRUE(IsWidgetVisibleOnBrowser(browser1));
EXPECT_TRUE(IsWidgetVisibleOnBrowser(browser2));
EXPECT_FALSE(IsWidgetVisibleOnBrowser(incognito_browser));
#else
EXPECT_FALSE(IsWidgetVisibleOnBrowser(browser2));
#endif
success = OnSpeechRecognitionReadyOnBrowser(incognito_browser);
EXPECT_TRUE(success);
// The CaptionBubbleController is currently only implemented in Views.
#if defined(TOOLKIT_VIEWS)
EXPECT_TRUE(IsWidgetVisibleOnBrowser(browser1));
EXPECT_TRUE(IsWidgetVisibleOnBrowser(browser2));
EXPECT_TRUE(IsWidgetVisibleOnBrowser(incognito_browser));
#else
EXPECT_FALSE(IsWidgetVisibleOnBrowser(incognito_browser));
#endif
}
IN_PROC_BROWSER_TEST_F(CaptionControllerTest, DispatchTranscription) { IN_PROC_BROWSER_TEST_F(CaptionControllerTest, DispatchTranscription) {
OnSpeechRecognitionReady();
bool success = DispatchTranscription("A baby spider is called a spiderling."); bool success = DispatchTranscription("A baby spider is called a spiderling.");
EXPECT_FALSE(success); EXPECT_FALSE(success);
EXPECT_EQ(0, NumBubbleControllers()); EXPECT_EQ(0, NumBubbleControllers());
SetLiveCaptionEnabled(true); SetLiveCaptionEnabled(true);
OnSpeechRecognitionReady();
success = DispatchTranscription( success = DispatchTranscription(
"A baby octopus is about the size of a flea when it is born."); "A baby octopus is about the size of a flea when it is born.");
EXPECT_TRUE(success); EXPECT_TRUE(success);
...@@ -423,7 +349,6 @@ IN_PROC_BROWSER_TEST_F(CaptionControllerTest, DispatchTranscription) { ...@@ -423,7 +349,6 @@ IN_PROC_BROWSER_TEST_F(CaptionControllerTest, DispatchTranscription) {
#endif #endif
SetLiveCaptionEnabled(false); SetLiveCaptionEnabled(false);
OnSpeechRecognitionReady();
success = DispatchTranscription( success = DispatchTranscription(
"Approximately 10-20% of power outages in the US are caused by " "Approximately 10-20% of power outages in the US are caused by "
"squirrels."); "squirrels.");
...@@ -439,7 +364,6 @@ IN_PROC_BROWSER_TEST_F(CaptionControllerTest, ...@@ -439,7 +364,6 @@ IN_PROC_BROWSER_TEST_F(CaptionControllerTest,
SetLiveCaptionEnabled(true); SetLiveCaptionEnabled(true);
// Dispatch transcription routes the transcription to the right browser. // Dispatch transcription routes the transcription to the right browser.
OnSpeechRecognitionReadyOnBrowser(browser1);
bool success = DispatchTranscriptionToBrowser( bool success = DispatchTranscriptionToBrowser(
"Honeybees can recognize human faces.", browser1); "Honeybees can recognize human faces.", browser1);
EXPECT_TRUE(success); EXPECT_TRUE(success);
...@@ -456,7 +380,6 @@ IN_PROC_BROWSER_TEST_F(CaptionControllerTest, ...@@ -456,7 +380,6 @@ IN_PROC_BROWSER_TEST_F(CaptionControllerTest,
EXPECT_FALSE(IsWidgetVisibleOnBrowser(browser1)); EXPECT_FALSE(IsWidgetVisibleOnBrowser(browser1));
#endif #endif
OnSpeechRecognitionReadyOnBrowser(browser2);
success = DispatchTranscriptionToBrowser( success = DispatchTranscriptionToBrowser(
"A blue whale's heart is the size of a small car.", browser2); "A blue whale's heart is the size of a small car.", browser2);
EXPECT_TRUE(success); EXPECT_TRUE(success);
...@@ -474,7 +397,6 @@ IN_PROC_BROWSER_TEST_F(CaptionControllerTest, ...@@ -474,7 +397,6 @@ IN_PROC_BROWSER_TEST_F(CaptionControllerTest,
EXPECT_FALSE(IsWidgetVisibleOnBrowser(browser2)); EXPECT_FALSE(IsWidgetVisibleOnBrowser(browser2));
#endif #endif
OnSpeechRecognitionReadyOnBrowser(incognito_browser);
success = DispatchTranscriptionToBrowser( success = DispatchTranscriptionToBrowser(
"Squirrels forget where they hide about half of their nuts.", "Squirrels forget where they hide about half of their nuts.",
incognito_browser); incognito_browser);
...@@ -646,8 +568,10 @@ IN_PROC_BROWSER_TEST_F(CaptionControllerTest, ...@@ -646,8 +568,10 @@ IN_PROC_BROWSER_TEST_F(CaptionControllerTest,
EXPECT_EQ(1, NumBubbleControllersForProfile(profile1)); EXPECT_EQ(1, NumBubbleControllersForProfile(profile1));
EXPECT_EQ(0, NumBubbleControllersForProfile(profile2)); EXPECT_EQ(0, NumBubbleControllersForProfile(profile2));
// Make the bubble on incognito_browser1 visible. // Make the bubble on incognito_browser1 visible by dispatching a
OnSpeechRecognitionReadyOnBrowser(browser1); // transcription.
DispatchTranscriptionToBrowser(
"If you lift a kangaroo's tail off the ground it can't hop.", browser1);
// The CaptionBubbleController is currently only implemented in Views. // The CaptionBubbleController is currently only implemented in Views.
#if defined(TOOLKIT_VIEWS) #if defined(TOOLKIT_VIEWS)
EXPECT_TRUE(IsWidgetVisibleOnBrowser(browser1)); EXPECT_TRUE(IsWidgetVisibleOnBrowser(browser1));
...@@ -662,52 +586,6 @@ IN_PROC_BROWSER_TEST_F(CaptionControllerTest, ...@@ -662,52 +586,6 @@ IN_PROC_BROWSER_TEST_F(CaptionControllerTest,
EXPECT_EQ(0, NumBubbleControllersForProfile(profile2)); EXPECT_EQ(0, NumBubbleControllersForProfile(profile2));
} }
IN_PROC_BROWSER_TEST_F(CaptionControllerTest,
OnSpeechRecognitionReady_MultipleProfiles) {
Profile* profile1 = browser()->profile();
Profile* profile2 = CreateProfile();
Browser* browser1 = browser();
Browser* browser2 = CreateBrowser(profile2);
// Enable live caption on both profiles.
SetLiveCaptionEnabled(true);
profile2->GetPrefs()->SetBoolean(prefs::kLiveCaptionEnabled, true);
// OnSpeechRecognitionReady routes to the right browser on the right profile.
bool success =
OnSpeechRecognitionReadyOnBrowserForProfile(browser1, profile1);
EXPECT_TRUE(success);
// The CaptionBubbleController is currently only implemented in Views.
#if defined(TOOLKIT_VIEWS)
EXPECT_TRUE(IsWidgetVisibleOnBrowser(browser1));
EXPECT_FALSE(IsWidgetVisibleOnBrowser(browser2));
#else
EXPECT_FALSE(IsWidgetVisibleOnBrowser(browser1));
#endif
success = OnSpeechRecognitionReadyOnBrowserForProfile(browser2, profile2);
EXPECT_TRUE(success);
// The CaptionBubbleController is currently only implemented in Views.
#if defined(TOOLKIT_VIEWS)
EXPECT_TRUE(IsWidgetVisibleOnBrowser(browser1));
EXPECT_TRUE(IsWidgetVisibleOnBrowser(browser2));
#else
EXPECT_FALSE(IsWidgetVisibleOnBrowser(browser1));
#endif
// OnSpeechRecognitionReady returns false for browsers on different profiles.
success = OnSpeechRecognitionReadyOnBrowserForProfile(browser1, profile2);
EXPECT_FALSE(success);
// The CaptionBubbleController is currently only implemented in Views.
#if defined(TOOLKIT_VIEWS)
EXPECT_TRUE(IsWidgetVisibleOnBrowser(browser1));
EXPECT_TRUE(IsWidgetVisibleOnBrowser(browser2));
#else
EXPECT_FALSE(IsWidgetVisibleOnBrowser(browser1));
EXPECT_FALSE(IsWidgetVisibleOnBrowser(browser2));
#endif
}
IN_PROC_BROWSER_TEST_F(CaptionControllerTest, IN_PROC_BROWSER_TEST_F(CaptionControllerTest,
DispatchTranscription_MultipleProfiles) { DispatchTranscription_MultipleProfiles) {
Profile* profile1 = browser()->profile(); Profile* profile1 = browser()->profile();
...@@ -721,7 +599,6 @@ IN_PROC_BROWSER_TEST_F(CaptionControllerTest, ...@@ -721,7 +599,6 @@ IN_PROC_BROWSER_TEST_F(CaptionControllerTest,
// Dispatch transcription routes the transcription to the right browser on the // Dispatch transcription routes the transcription to the right browser on the
// right profile. // right profile.
OnSpeechRecognitionReadyOnBrowserForProfile(browser1, profile1);
bool success = DispatchTranscriptionToBrowserForProfile( bool success = DispatchTranscriptionToBrowserForProfile(
"Only female mosquitos bite.", browser1, profile1); "Only female mosquitos bite.", browser1, profile1);
EXPECT_TRUE(success); EXPECT_TRUE(success);
...@@ -736,7 +613,6 @@ IN_PROC_BROWSER_TEST_F(CaptionControllerTest, ...@@ -736,7 +613,6 @@ IN_PROC_BROWSER_TEST_F(CaptionControllerTest,
EXPECT_FALSE(IsWidgetVisibleOnBrowser(browser1)); EXPECT_FALSE(IsWidgetVisibleOnBrowser(browser1));
#endif #endif
OnSpeechRecognitionReadyOnBrowserForProfile(browser2, profile2);
success = DispatchTranscriptionToBrowserForProfile( success = DispatchTranscriptionToBrowserForProfile(
"Mosquitos were around at the time of the dinosaurs.", browser2, "Mosquitos were around at the time of the dinosaurs.", browser2,
profile2); profile2);
......
...@@ -34,22 +34,6 @@ CaptionHostImpl::CaptionHostImpl(content::RenderFrameHost* frame_host) ...@@ -34,22 +34,6 @@ CaptionHostImpl::CaptionHostImpl(content::RenderFrameHost* frame_host)
CaptionHostImpl::~CaptionHostImpl() = default; CaptionHostImpl::~CaptionHostImpl() = default;
void CaptionHostImpl::OnSpeechRecognitionReady(
OnSpeechRecognitionReadyCallback reply) {
content::WebContents* web_contents = GetWebContents();
if (!web_contents) {
std::move(reply).Run(false);
return;
}
CaptionController* caption_controller = GetCaptionController(web_contents);
if (!caption_controller) {
std::move(reply).Run(false);
return;
}
std::move(reply).Run(
caption_controller->OnSpeechRecognitionReady(web_contents));
}
void CaptionHostImpl::OnTranscription( void CaptionHostImpl::OnTranscription(
chrome::mojom::TranscriptionResultPtr transcription_result, chrome::mojom::TranscriptionResultPtr transcription_result,
OnTranscriptionCallback reply) { OnTranscriptionCallback reply) {
......
...@@ -39,8 +39,6 @@ class CaptionHostImpl : public chrome::mojom::CaptionHost, ...@@ -39,8 +39,6 @@ class CaptionHostImpl : public chrome::mojom::CaptionHost,
mojo::PendingReceiver<chrome::mojom::CaptionHost> receiver); mojo::PendingReceiver<chrome::mojom::CaptionHost> receiver);
// chrome::mojom::CaptionHost: // chrome::mojom::CaptionHost:
void OnSpeechRecognitionReady(
OnSpeechRecognitionReadyCallback reply) override;
void OnTranscription( void OnTranscription(
chrome::mojom::TranscriptionResultPtr transcription_result, chrome::mojom::TranscriptionResultPtr transcription_result,
OnTranscriptionCallback reply) override; OnTranscriptionCallback reply) override;
......
...@@ -37,10 +37,6 @@ class CaptionBubbleController { ...@@ -37,10 +37,6 @@ class CaptionBubbleController {
static std::unique_ptr<CaptionBubbleController> Create(Browser* browser); static std::unique_ptr<CaptionBubbleController> Create(Browser* browser);
// Called when speech recognition is ready to start for the given web
// contents.
virtual bool OnSpeechRecognitionReady(content::WebContents* web_contents) = 0;
// Called when a transcription is received from the service. Returns whether // Called when a transcription is received from the service. Returns whether
// the transcription result was set on the caption bubble successfully. // the transcription result was set on the caption bubble successfully.
// Transcriptions will halt if this returns false. // Transcriptions will halt if this returns false.
......
...@@ -324,13 +324,6 @@ void CaptionBubble::Init() { ...@@ -324,13 +324,6 @@ void CaptionBubble::Init() {
// set the truncate_length to 0 to ensure that it never truncates. // set the truncate_length to 0 to ensure that it never truncates.
label->SetTruncateLength(0); label->SetTruncateLength(0);
auto wait_text = std::make_unique<views::Label>();
wait_text->SetEnabledColor(gfx::kGoogleGrey500);
wait_text->SetBackgroundColor(SK_ColorTRANSPARENT);
wait_text->SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_LEFT);
wait_text->SetText(
l10n_util::GetStringUTF16(IDS_LIVE_CAPTION_BUBBLE_WAIT_TEXT));
auto error_text = std::make_unique<views::Label>(); auto error_text = std::make_unique<views::Label>();
error_text->SetEnabledColor(SK_ColorWHITE); error_text->SetEnabledColor(SK_ColorWHITE);
error_text->SetBackgroundColor(SK_ColorTRANSPARENT); error_text->SetBackgroundColor(SK_ColorTRANSPARENT);
...@@ -360,7 +353,6 @@ void CaptionBubble::Init() { ...@@ -360,7 +353,6 @@ void CaptionBubble::Init() {
auto close_button = BuildImageButton(vector_icons::kCloseRoundedIcon, auto close_button = BuildImageButton(vector_icons::kCloseRoundedIcon,
IDS_LIVE_CAPTION_BUBBLE_CLOSE); IDS_LIVE_CAPTION_BUBBLE_CLOSE);
wait_text_ = content_container->AddChildView(std::move(wait_text));
label_ = content_container->AddChildView(std::move(label)); label_ = content_container->AddChildView(std::move(label));
error_icon_ = error_message->AddChildView(std::move(error_icon)); error_icon_ = error_message->AddChildView(std::move(error_icon));
...@@ -470,14 +462,16 @@ void CaptionBubble::GetAccessibleNodeData(ui::AXNodeData* node_data) { ...@@ -470,14 +462,16 @@ void CaptionBubble::GetAccessibleNodeData(ui::AXNodeData* node_data) {
if (model_ && model_->HasError()) { if (model_ && model_->HasError()) {
node_data->SetName(error_text_->GetText()); node_data->SetName(error_text_->GetText());
node_data->SetNameFrom(ax::mojom::NameFrom::kContents); node_data->SetNameFrom(ax::mojom::NameFrom::kContents);
} else if (label_->GetText().size()) { } else if (model_ && !model_->GetFullText().empty()) {
node_data->SetName(label_->GetText()); node_data->SetName(model_->GetFullText());
node_data->SetNameFrom(ax::mojom::NameFrom::kContents); node_data->SetNameFrom(ax::mojom::NameFrom::kContents);
} else { } else {
node_data->SetName(wait_text_->GetText()); node_data->SetName(
l10n_util::GetStringUTF16(IDS_LIVE_CAPTION_BUBBLE_ACCESSIBLE_NAME));
node_data->SetNameFrom(ax::mojom::NameFrom::kContents); node_data->SetNameFrom(ax::mojom::NameFrom::kContents);
} }
node_data->SetDescription(wait_text_->GetText()); node_data->SetDescription(
l10n_util::GetStringUTF16(IDS_LIVE_CAPTION_BUBBLE_ACCESSIBLE_NAME));
node_data->role = ax::mojom::Role::kCaption; node_data->role = ax::mojom::Role::kCaption;
} }
...@@ -526,7 +520,7 @@ void CaptionBubble::SetModel(CaptionBubbleModel* model) { ...@@ -526,7 +520,7 @@ void CaptionBubble::SetModel(CaptionBubbleModel* model) {
void CaptionBubble::OnTextChanged() { void CaptionBubble::OnTextChanged() {
DCHECK(model_); DCHECK(model_);
label_->SetText(base::UTF8ToUTF16(model_->GetFullText())); label_->SetText(base::UTF8ToUTF16(model_->GetFullText()));
UpdateBubbleAndWaitTextVisibility(); UpdateBubbleVisibility();
} }
void CaptionBubble::OnErrorChanged() { void CaptionBubble::OnErrorChanged() {
...@@ -539,19 +533,6 @@ void CaptionBubble::OnErrorChanged() { ...@@ -539,19 +533,6 @@ void CaptionBubble::OnErrorChanged() {
Redraw(); Redraw();
} }
void CaptionBubble::OnReadyChanged() {
DCHECK(model_);
// There is a bug in RenderText in which the label text must not be empty when
// it is displayed, or otherwise subsequent calculation of the number of lines
// (CaptionBubble::GetNumLinesInLabel) will be incorrect. The label text here
// is set to a space character.
// TODO(1055150): Fix the bug in RenderText and then remove this workaround.
if (model_->IsReady()) {
label_->SetText(base::ASCIIToUTF16("\u0020"));
UpdateBubbleAndWaitTextVisibility();
}
}
void CaptionBubble::OnIsExpandedChanged() { void CaptionBubble::OnIsExpandedChanged() {
expand_button_->SetVisible(!is_expanded_); expand_button_->SetVisible(!is_expanded_);
collapse_button_->SetVisible(is_expanded_); collapse_button_->SetVisible(is_expanded_);
...@@ -561,14 +542,6 @@ void CaptionBubble::OnIsExpandedChanged() { ...@@ -561,14 +542,6 @@ void CaptionBubble::OnIsExpandedChanged() {
Redraw(); Redraw();
} }
void CaptionBubble::UpdateBubbleAndWaitTextVisibility() {
// Show the wait text if there is room for it and no error.
wait_text_->SetVisible(model_ && !model_->HasError() &&
GetNumLinesInLabel() <
static_cast<size_t>(GetNumLinesVisible()));
UpdateBubbleVisibility();
}
void CaptionBubble::UpdateBubbleVisibility() { void CaptionBubble::UpdateBubbleVisibility() {
DCHECK(GetWidget()); DCHECK(GetWidget());
if (!model_) { if (!model_) {
...@@ -579,14 +552,14 @@ void CaptionBubble::UpdateBubbleVisibility() { ...@@ -579,14 +552,14 @@ void CaptionBubble::UpdateBubbleVisibility() {
// Hide the widget if there is no room for it or the model is closed. // Hide the widget if there is no room for it or the model is closed.
if (GetWidget()->IsVisible()) if (GetWidget()->IsVisible())
GetWidget()->Hide(); GetWidget()->Hide();
} else if (model_->IsReady() || model_->HasError()) { } else if (!model_->GetFullText().empty() || model_->HasError()) {
// Show the widget if it is ready to receive transcriptions or it has an // Show the widget if it has text or an error to display. Only show the
// error to display. Only show the widget if it isn't already visible. // widget if it isn't already visible. Always calling Widget::Show() will
// Always calling Widget::Show() will mean the widget gets focus each time. // mean the widget gets focus each time.
if (!GetWidget()->IsVisible()) if (!GetWidget()->IsVisible())
GetWidget()->Show(); GetWidget()->Show();
} else if (GetWidget()->IsVisible()) { } else if (GetWidget()->IsVisible()) {
// Not ready and no error. Hide it. // No text and no error. Hide it.
GetWidget()->Hide(); GetWidget()->Hide();
} }
} }
...@@ -630,11 +603,9 @@ void CaptionBubble::UpdateTextSize() { ...@@ -630,11 +603,9 @@ void CaptionBubble::UpdateTextSize() {
gfx::Font::FontStyle::NORMAL, kFontSizePx * textScaleFactor, gfx::Font::FontStyle::NORMAL, kFontSizePx * textScaleFactor,
gfx::Font::Weight::NORMAL); gfx::Font::Weight::NORMAL);
label_->SetFontList(font_list); label_->SetFontList(font_list);
wait_text_->SetFontList(font_list);
error_text_->SetFontList(font_list); error_text_->SetFontList(font_list);
label_->SetLineHeight(kLineHeightDip * textScaleFactor); label_->SetLineHeight(kLineHeightDip * textScaleFactor);
wait_text_->SetLineHeight(kLineHeightDip * textScaleFactor);
error_text_->SetLineHeight(kLineHeightDip * textScaleFactor); error_text_->SetLineHeight(kLineHeightDip * textScaleFactor);
error_icon_->SetImageSize(gfx::Size(kErrorImageSizeDip * textScaleFactor, error_icon_->SetImageSize(gfx::Size(kErrorImageSizeDip * textScaleFactor,
kErrorImageSizeDip * textScaleFactor)); kErrorImageSizeDip * textScaleFactor));
...@@ -646,12 +617,8 @@ void CaptionBubble::UpdateContentSize() { ...@@ -646,12 +617,8 @@ void CaptionBubble::UpdateContentSize() {
(model_ && model_->HasError()) (model_ && model_->HasError())
? kLineHeightDip * text_scale_factor ? kLineHeightDip * text_scale_factor
: kLineHeightDip * GetNumLinesVisible() * text_scale_factor; : kLineHeightDip * GetNumLinesVisible() * text_scale_factor;
// The wait text takes up 1 line.
int label_height = wait_text_->GetVisible()
? content_height - kLineHeightDip * text_scale_factor
: content_height;
label_->SetPreferredSize( label_->SetPreferredSize(
gfx::Size(kMaxWidthDip - kSidePaddingDip, label_height)); gfx::Size(kMaxWidthDip - kSidePaddingDip, content_height));
content_container_->SetPreferredSize(gfx::Size(kMaxWidthDip, content_height)); content_container_->SetPreferredSize(gfx::Size(kMaxWidthDip, content_height));
SetPreferredSize( SetPreferredSize(
gfx::Size(kMaxWidthDip, content_height + gfx::Size(kMaxWidthDip, content_height +
...@@ -660,7 +627,7 @@ void CaptionBubble::UpdateContentSize() { ...@@ -660,7 +627,7 @@ void CaptionBubble::UpdateContentSize() {
} }
void CaptionBubble::Redraw() { void CaptionBubble::Redraw() {
UpdateBubbleAndWaitTextVisibility(); UpdateBubbleVisibility();
UpdateContentSize(); UpdateContentSize();
SizeToContents(); SizeToContents();
} }
......
...@@ -105,16 +105,10 @@ class CaptionBubble : public views::BubbleDialogDelegateView, ...@@ -105,16 +105,10 @@ class CaptionBubble : public views::BubbleDialogDelegateView,
// the model has an error, otherwise displays the latest text. // the model has an error, otherwise displays the latest text.
void OnErrorChanged(); void OnErrorChanged();
// Called by the CaptionBubbleModel to notify this object that the model's
// on ready state has changed. Makes the caption bubble become visible and
// show the wait text.
void OnReadyChanged();
// Called when the caption bubble expanded state has changed. Changes the // Called when the caption bubble expanded state has changed. Changes the
// number of lines displayed. // number of lines displayed.
void OnIsExpandedChanged(); void OnIsExpandedChanged();
void UpdateBubbleAndWaitTextVisibility();
// The caption bubble manages its own visibility based on whether there's // The caption bubble manages its own visibility based on whether there's
// space for it to be shown, and if it has an error or text to display. // space for it to be shown, and if it has an error or text to display.
void UpdateBubbleVisibility(); void UpdateBubbleVisibility();
...@@ -129,7 +123,6 @@ class CaptionBubble : public views::BubbleDialogDelegateView, ...@@ -129,7 +123,6 @@ class CaptionBubble : public views::BubbleDialogDelegateView,
// Unowned. Owned by views hierarchy. // Unowned. Owned by views hierarchy.
views::Label* label_; views::Label* label_;
views::Label* wait_text_;
views::Label* error_text_; views::Label* error_text_;
views::ImageView* error_icon_; views::ImageView* error_icon_;
views::View* error_message_; views::View* error_message_;
......
...@@ -69,18 +69,6 @@ void CaptionBubbleControllerViews::OnCaptionBubbleDestroyed() { ...@@ -69,18 +69,6 @@ void CaptionBubbleControllerViews::OnCaptionBubbleDestroyed() {
browser_ = nullptr; browser_ = nullptr;
} }
bool CaptionBubbleControllerViews::OnSpeechRecognitionReady(
content::WebContents* web_contents) {
if (!caption_bubble_ || !caption_bubble_models_.count(web_contents) ||
caption_bubble_models_[web_contents]->IsClosed())
return false;
CaptionBubbleModel* caption_bubble_model =
caption_bubble_models_[web_contents].get();
caption_bubble_model->OnReady();
return true;
}
bool CaptionBubbleControllerViews::OnTranscription( bool CaptionBubbleControllerViews::OnTranscription(
const chrome::mojom::TranscriptionResultPtr& transcription_result, const chrome::mojom::TranscriptionResultPtr& transcription_result,
content::WebContents* web_contents) { content::WebContents* web_contents) {
......
...@@ -38,10 +38,6 @@ class CaptionBubbleControllerViews : public CaptionBubbleController, ...@@ -38,10 +38,6 @@ class CaptionBubbleControllerViews : public CaptionBubbleController,
CaptionBubbleControllerViews& operator=(const CaptionBubbleControllerViews&) = CaptionBubbleControllerViews& operator=(const CaptionBubbleControllerViews&) =
delete; delete;
// Called when speech recognition is ready to start for the given web
// contents.
bool OnSpeechRecognitionReady(content::WebContents* web_contents) override;
// Called when a transcription is received from the service. Returns whether // Called when a transcription is received from the service. Returns whether
// the transcription result was set on the caption bubble successfully. // the transcription result was set on the caption bubble successfully.
// Transcriptions will halt if this returns false. // Transcriptions will halt if this returns false.
......
...@@ -61,10 +61,6 @@ class CaptionBubbleControllerViewsTest : public InProcessBrowserTest { ...@@ -61,10 +61,6 @@ class CaptionBubbleControllerViewsTest : public InProcessBrowserTest {
return controller_ ? controller_->caption_bubble_->label_ : nullptr; return controller_ ? controller_->caption_bubble_->label_ : nullptr;
} }
views::Label* GetWaitText() {
return controller_ ? controller_->caption_bubble_->wait_text_ : nullptr;
}
views::Button* GetCloseButton() { views::Button* GetCloseButton() {
return controller_ ? controller_->caption_bubble_->close_button_ : nullptr; return controller_ ? controller_->caption_bubble_->close_button_ : nullptr;
} }
...@@ -136,11 +132,6 @@ class CaptionBubbleControllerViewsTest : public InProcessBrowserTest { ...@@ -136,11 +132,6 @@ class CaptionBubbleControllerViewsTest : public InProcessBrowserTest {
browser()->tab_strip_model()->GetWebContentsAt(tab_index)); browser()->tab_strip_model()->GetWebContentsAt(tab_index));
} }
bool OnSpeechRecognitionReady(int tab_index = 0) {
return GetController()->OnSpeechRecognitionReady(
browser()->tab_strip_model()->GetWebContentsAt(tab_index));
}
void ActivateTabAt(int index) { void ActivateTabAt(int index) {
browser()->tab_strip_model()->ActivateTabAt(index); browser()->tab_strip_model()->ActivateTabAt(index);
} }
...@@ -162,27 +153,33 @@ class CaptionBubbleControllerViewsTest : public InProcessBrowserTest { ...@@ -162,27 +153,33 @@ class CaptionBubbleControllerViewsTest : public InProcessBrowserTest {
}; };
IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, ShowsCaptionInBubble) { IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, ShowsCaptionInBubble) {
OnSpeechRecognitionReady();
OnPartialTranscription("Taylor"); OnPartialTranscription("Taylor");
EXPECT_TRUE(IsWidgetVisible()); EXPECT_TRUE(IsWidgetVisible());
EXPECT_EQ("Taylor", GetLabelText()); EXPECT_EQ("Taylor", GetLabelText());
OnPartialTranscription("Taylor Alison Swift\n(born December 13, 1989)"); OnPartialTranscription(
EXPECT_EQ("Taylor Alison Swift\n(born December 13, 1989)", GetLabelText()); "Taylor Alison Swift (born December 13, "
EXPECT_FALSE(GetWaitText()->GetVisible()); "1989)");
EXPECT_EQ("Taylor Alison Swift (born December 13, 1989)", GetLabelText());
// The bubble is still visible when set to the empty string. The wait text // Hides the bubble when set to the empty string.
// becomes visible.
OnPartialTranscription(""); OnPartialTranscription("");
EXPECT_FALSE(IsWidgetVisible());
// Shows it again when the caption is no longer empty.
OnPartialTranscription(
"Taylor Alison Swift (born December 13, "
"1989) is an American singer-songwriter.");
EXPECT_TRUE(IsWidgetVisible()); EXPECT_TRUE(IsWidgetVisible());
EXPECT_EQ("", GetLabelText()); EXPECT_EQ(
EXPECT_TRUE(GetWaitText()->GetVisible()); "Taylor Alison Swift (born December 13, 1989) is an American "
"singer-songwriter.",
GetLabelText());
} }
IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, LaysOutCaptionLabel) { IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, LaysOutCaptionLabel) {
// A short caption is bottom-aligned with the bubble. The bubble bounds // A short caption is bottom-aligned with the bubble. The bubble bounds
// are inset by 18 dip on the the sides and 24 dip on the bottom. The label // are inset by 18 dip on the the sides and 24 dip on the bottom. The label
// top can change, but the bubble height and width should not change. // top can change, but the bubble height and width should not change.
OnSpeechRecognitionReady();
OnPartialTranscription("Cats rock"); OnPartialTranscription("Cats rock");
gfx::Rect label_bounds = GetLabel()->GetBoundsInScreen(); gfx::Rect label_bounds = GetLabel()->GetBoundsInScreen();
gfx::Rect bubble_bounds = GetBubble()->GetBoundsInScreen(); gfx::Rect bubble_bounds = GetBubble()->GetBoundsInScreen();
...@@ -209,30 +206,6 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, LaysOutCaptionLabel) { ...@@ -209,30 +206,6 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, LaysOutCaptionLabel) {
EXPECT_EQ(bubble_width, bubble_bounds.width()); EXPECT_EQ(bubble_width, bubble_bounds.width());
} }
IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest,
CaptionWaitTextShownAtFirst) {
OnSpeechRecognitionReady();
EXPECT_TRUE(GetWaitText()->GetVisible());
// With one line of text, the wait text is visible and positioned between the
// top of the bubble and top of the label.
OnPartialTranscription("Cats rock");
EXPECT_TRUE(GetWaitText()->GetVisible());
EXPECT_EQ(GetWaitText()->GetBoundsInScreen().bottom(),
GetLabel()->GetBoundsInScreen().y());
OnPartialTranscription("Cats rock\nDogs too");
EXPECT_FALSE(GetWaitText()->GetVisible());
OnPartialTranscription(
"Taylor Alison Swift (born December 13, 1989) is an American "
"singer-songwriter. She is known for narrative songs about her personal "
"life, which have received widespread media coverage. At age 14, Swift "
"became the youngest artist signed by the Sony/ATV Music publishing "
"house and, at age 15, she signed her first record deal.");
EXPECT_FALSE(GetWaitText()->GetVisible());
}
IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, BubblePositioning) { IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, BubblePositioning) {
int bubble_width = 536; int bubble_width = 536;
gfx::Insets bubble_margins(6); gfx::Insets bubble_margins(6);
...@@ -240,7 +213,6 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, BubblePositioning) { ...@@ -240,7 +213,6 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, BubblePositioning) {
BrowserView::GetBrowserViewForBrowser(browser())->GetContentsView(); BrowserView::GetBrowserViewForBrowser(browser())->GetContentsView();
browser()->window()->SetBounds(gfx::Rect(10, 10, 800, 600)); browser()->window()->SetBounds(gfx::Rect(10, 10, 800, 600));
OnSpeechRecognitionReady();
OnPartialTranscription("Mantis shrimp have 12-16 photoreceptors"); OnPartialTranscription("Mantis shrimp have 12-16 photoreceptors");
ExpectInBottomCenter(contents_view->GetBoundsInScreen(), ExpectInBottomCenter(contents_view->GetBoundsInScreen(),
GetCaptionWidget()->GetClientAreaBoundsInScreen()); GetCaptionWidget()->GetClientAreaBoundsInScreen());
...@@ -369,35 +341,28 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, BubblePositioning) { ...@@ -369,35 +341,28 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, BubblePositioning) {
} }
IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, ShowsAndHidesError) { IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, ShowsAndHidesError) {
OnSpeechRecognitionReady();
OnPartialTranscription("Elephants' trunks average 6 feet long."); OnPartialTranscription("Elephants' trunks average 6 feet long.");
EXPECT_TRUE(GetWaitText()->GetVisible());
EXPECT_TRUE(GetLabel()->GetVisible()); EXPECT_TRUE(GetLabel()->GetVisible());
EXPECT_FALSE(GetErrorMessage()->GetVisible()); EXPECT_FALSE(GetErrorMessage()->GetVisible());
OnError(0); OnError(0);
EXPECT_FALSE(GetWaitText()->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 shouldn't cause the error to disappear.
OnPartialTranscription("Elephant tails average 4-5 feet long."); OnPartialTranscription("Elephant tails average 4-5 feet long.");
EXPECT_FALSE(GetWaitText()->GetVisible());
EXPECT_FALSE(GetLabel()->GetVisible()); EXPECT_FALSE(GetLabel()->GetVisible());
EXPECT_TRUE(GetErrorMessage()->GetVisible()); EXPECT_TRUE(GetErrorMessage()->GetVisible());
// 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);
OnSpeechRecognitionReady();
OnPartialTranscription("Elephants are vegetarians."); OnPartialTranscription("Elephants are vegetarians.");
EXPECT_TRUE(GetWaitText()->GetVisible());
EXPECT_TRUE(GetLabel()->GetVisible()); EXPECT_TRUE(GetLabel()->GetVisible());
EXPECT_FALSE(GetErrorMessage()->GetVisible()); EXPECT_FALSE(GetErrorMessage()->GetVisible());
// The error should still be visible when switching back to the tab. // The error should still be visible when switching back to the tab.
ActivateTabAt(0); ActivateTabAt(0);
EXPECT_FALSE(GetWaitText()->GetVisible());
EXPECT_FALSE(GetLabel()->GetVisible()); EXPECT_FALSE(GetLabel()->GetVisible());
EXPECT_TRUE(GetErrorMessage()->GetVisible()); EXPECT_TRUE(GetErrorMessage()->GetVisible());
...@@ -405,17 +370,13 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, ShowsAndHidesError) { ...@@ -405,17 +370,13 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, ShowsAndHidesError) {
chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB);
content::WaitForLoadStop( content::WaitForLoadStop(
browser()->tab_strip_model()->GetActiveWebContents()); browser()->tab_strip_model()->GetActiveWebContents());
OnSpeechRecognitionReady();
OnPartialTranscription("Elephants can communicate through seismic signals."); OnPartialTranscription("Elephants can communicate through seismic signals.");
EXPECT_TRUE(GetWaitText()->GetVisible());
EXPECT_TRUE(GetLabel()->GetVisible()); EXPECT_TRUE(GetLabel()->GetVisible());
EXPECT_FALSE(GetErrorMessage()->GetVisible()); EXPECT_FALSE(GetErrorMessage()->GetVisible());
} }
IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, CloseButtonCloses) { IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, CloseButtonCloses) {
bool success = OnSpeechRecognitionReady(); bool success = OnFinalTranscription("Elephants have 3-4 toenails per foot");
EXPECT_TRUE(success);
success = OnFinalTranscription("Elephants have 3-4 toenails per foot");
EXPECT_TRUE(success); EXPECT_TRUE(success);
EXPECT_TRUE(GetCaptionWidget()); EXPECT_TRUE(GetCaptionWidget());
EXPECT_TRUE(IsWidgetVisible()); EXPECT_TRUE(IsWidgetVisible());
...@@ -423,8 +384,6 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, CloseButtonCloses) { ...@@ -423,8 +384,6 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, CloseButtonCloses) {
ClickButton(GetCloseButton()); ClickButton(GetCloseButton());
EXPECT_TRUE(GetCaptionWidget()); EXPECT_TRUE(GetCaptionWidget());
EXPECT_FALSE(IsWidgetVisible()); EXPECT_FALSE(IsWidgetVisible());
success = OnSpeechRecognitionReady();
EXPECT_FALSE(success);
success = OnFinalTranscription( success = OnFinalTranscription(
"Elephants wander 35 miles a day in search of water"); "Elephants wander 35 miles a day in search of water");
EXPECT_FALSE(success); EXPECT_FALSE(success);
...@@ -433,9 +392,7 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, CloseButtonCloses) { ...@@ -433,9 +392,7 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, CloseButtonCloses) {
IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest,
MovesWithArrowsWhenFocused) { MovesWithArrowsWhenFocused) {
OnSpeechRecognitionReady(); OnPartialTranscription("Nearly all ants are female.");
OnPartialTranscription(
"Honeybees have tiny hairs on their eyes to help them collect pollen");
// Not focused initially. // Not focused initially.
EXPECT_FALSE(GetBubble()->HasFocus()); EXPECT_FALSE(GetBubble()->HasFocus());
...@@ -484,7 +441,6 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, ...@@ -484,7 +441,6 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest,
} }
IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, FocusableInTabOrder) { IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, FocusableInTabOrder) {
OnSpeechRecognitionReady();
OnPartialTranscription( OnPartialTranscription(
"A narwhal's tusk is an enlarged tooth containing " "A narwhal's tusk is an enlarged tooth containing "
"millions of nerve endings"); "millions of nerve endings");
...@@ -551,12 +507,9 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, ...@@ -551,12 +507,9 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest,
int errorIconHeight = 20; int errorIconHeight = 20;
GetController()->UpdateCaptionStyle(base::nullopt); GetController()->UpdateCaptionStyle(base::nullopt);
OnSpeechRecognitionReady();
OnPartialTranscription("Hamsters' teeth never stop growing"); OnPartialTranscription("Hamsters' teeth never stop growing");
EXPECT_EQ(textSize, GetLabel()->font_list().GetFontSize()); EXPECT_EQ(textSize, GetLabel()->font_list().GetFontSize());
EXPECT_EQ(textSize, GetWaitText()->font_list().GetFontSize());
EXPECT_EQ(lineHeight, GetLabel()->GetLineHeight()); EXPECT_EQ(lineHeight, GetLabel()->GetLineHeight());
EXPECT_EQ(lineHeight, GetWaitText()->GetLineHeight());
EXPECT_GT(GetBubble()->GetPreferredSize().height(), bubbleHeight); EXPECT_GT(GetBubble()->GetPreferredSize().height(), bubbleHeight);
// Set the text size to 200%. // Set the text size to 200%.
...@@ -564,44 +517,34 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, ...@@ -564,44 +517,34 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest,
caption_style.text_size = "200%"; caption_style.text_size = "200%";
GetController()->UpdateCaptionStyle(caption_style); GetController()->UpdateCaptionStyle(caption_style);
EXPECT_EQ(textSize * 2, GetLabel()->font_list().GetFontSize()); EXPECT_EQ(textSize * 2, GetLabel()->font_list().GetFontSize());
EXPECT_EQ(textSize * 2, GetWaitText()->font_list().GetFontSize());
EXPECT_EQ(lineHeight * 2, GetLabel()->GetLineHeight()); EXPECT_EQ(lineHeight * 2, GetLabel()->GetLineHeight());
EXPECT_EQ(lineHeight * 2, GetWaitText()->GetLineHeight());
EXPECT_GT(GetBubble()->GetPreferredSize().height(), bubbleHeight * 2); EXPECT_GT(GetBubble()->GetPreferredSize().height(), bubbleHeight * 2);
// Set the text size to the empty string. // Set the text size to the empty string.
caption_style.text_size = ""; caption_style.text_size = "";
GetController()->UpdateCaptionStyle(caption_style); GetController()->UpdateCaptionStyle(caption_style);
EXPECT_EQ(textSize, GetLabel()->font_list().GetFontSize()); EXPECT_EQ(textSize, GetLabel()->font_list().GetFontSize());
EXPECT_EQ(textSize, GetWaitText()->font_list().GetFontSize());
EXPECT_EQ(lineHeight, GetLabel()->GetLineHeight()); EXPECT_EQ(lineHeight, GetLabel()->GetLineHeight());
EXPECT_EQ(lineHeight, GetWaitText()->GetLineHeight());
EXPECT_GT(GetBubble()->GetPreferredSize().height(), bubbleHeight); EXPECT_GT(GetBubble()->GetPreferredSize().height(), bubbleHeight);
// Set the text size to 50% !important. // Set the text size to 50% !important.
caption_style.text_size = "50% !important"; caption_style.text_size = "50% !important";
GetController()->UpdateCaptionStyle(caption_style); GetController()->UpdateCaptionStyle(caption_style);
EXPECT_EQ(textSize / 2, GetLabel()->font_list().GetFontSize()); EXPECT_EQ(textSize / 2, GetLabel()->font_list().GetFontSize());
EXPECT_EQ(textSize / 2, GetWaitText()->font_list().GetFontSize());
EXPECT_EQ(lineHeight / 2, GetLabel()->GetLineHeight()); EXPECT_EQ(lineHeight / 2, GetLabel()->GetLineHeight());
EXPECT_EQ(lineHeight / 2, GetWaitText()->GetLineHeight());
EXPECT_GT(GetBubble()->GetPreferredSize().height(), bubbleHeight / 2); EXPECT_GT(GetBubble()->GetPreferredSize().height(), bubbleHeight / 2);
// Set the text size to a bad string. // Set the text size to a bad string.
caption_style.text_size = "Ostriches can run up to 45mph"; caption_style.text_size = "Ostriches can run up to 45mph";
GetController()->UpdateCaptionStyle(caption_style); GetController()->UpdateCaptionStyle(caption_style);
EXPECT_EQ(textSize, GetLabel()->font_list().GetFontSize()); EXPECT_EQ(textSize, GetLabel()->font_list().GetFontSize());
EXPECT_EQ(textSize, GetWaitText()->font_list().GetFontSize());
EXPECT_EQ(lineHeight, GetLabel()->GetLineHeight()); EXPECT_EQ(lineHeight, GetLabel()->GetLineHeight());
EXPECT_EQ(lineHeight, GetWaitText()->GetLineHeight());
EXPECT_GT(GetBubble()->GetPreferredSize().height(), bubbleHeight); EXPECT_GT(GetBubble()->GetPreferredSize().height(), bubbleHeight);
// Set the caption style to nullopt. // Set the caption style to nullopt.
GetController()->UpdateCaptionStyle(base::nullopt); GetController()->UpdateCaptionStyle(base::nullopt);
EXPECT_EQ(textSize, GetLabel()->font_list().GetFontSize()); EXPECT_EQ(textSize, GetLabel()->font_list().GetFontSize());
EXPECT_EQ(textSize, GetWaitText()->font_list().GetFontSize());
EXPECT_EQ(lineHeight, GetLabel()->GetLineHeight()); EXPECT_EQ(lineHeight, GetLabel()->GetLineHeight());
EXPECT_EQ(lineHeight, GetWaitText()->GetLineHeight());
EXPECT_GT(GetBubble()->GetPreferredSize().height(), bubbleHeight); EXPECT_GT(GetBubble()->GetPreferredSize().height(), bubbleHeight);
// Set the error message. // Set the error message.
...@@ -615,7 +558,6 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, ...@@ -615,7 +558,6 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest,
IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest,
PartialAndFinalTranscriptions) { PartialAndFinalTranscriptions) {
OnSpeechRecognitionReady();
OnPartialTranscription("No"); OnPartialTranscription("No");
EXPECT_EQ("No", GetLabelText()); EXPECT_EQ("No", GetLabelText());
OnPartialTranscription("No human"); OnPartialTranscription("No human");
...@@ -646,15 +588,11 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, ShowsAndHidesBubble) { ...@@ -646,15 +588,11 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, ShowsAndHidesBubble) {
browser()->tab_strip_model()->GetActiveWebContents()); browser()->tab_strip_model()->GetActiveWebContents());
EXPECT_FALSE(IsWidgetVisible()); EXPECT_FALSE(IsWidgetVisible());
// It is shown if the bubble is ready and should not show if it is not. // It is shown if there is text, and hidden if the text is removed.
OnPartialTranscription("Newborn kangaroos are less than 1 in long"); OnPartialTranscription("Newborn kangaroos are less than 1 in long");
EXPECT_FALSE(IsWidgetVisible());
// Visible when the bubble is ready.
OnSpeechRecognitionReady();
EXPECT_TRUE(IsWidgetVisible()); EXPECT_TRUE(IsWidgetVisible());
// Even if the text is removed, still visible because it is ready.
OnFinalTranscription(""); OnFinalTranscription("");
EXPECT_TRUE(IsWidgetVisible()); EXPECT_FALSE(IsWidgetVisible());
#if !defined(OS_MAC) #if !defined(OS_MAC)
// Shrink it so small the caption bubble can't fit. Ensure it's hidden. // Shrink it so small the caption bubble can't fit. Ensure it's hidden.
...@@ -664,7 +602,7 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, ShowsAndHidesBubble) { ...@@ -664,7 +602,7 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, ShowsAndHidesBubble) {
// Make it bigger again and ensure it's still not visible. // Make it bigger again and ensure it's still not visible.
browser()->window()->SetBounds(gfx::Rect(50, 50, 800, 400)); browser()->window()->SetBounds(gfx::Rect(50, 50, 800, 400));
EXPECT_TRUE(IsWidgetVisible()); EXPECT_FALSE(IsWidgetVisible());
// Now set some text, and ensure it hides when shrunk but re-shows when // Now set some text, and ensure it hides when shrunk but re-shows when
// grown. // grown.
...@@ -689,7 +627,6 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, ChangeActiveTab) { ...@@ -689,7 +627,6 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, ChangeActiveTab) {
// Tab 1 will have the text "A snail can sleep for three years". // Tab 1 will have the text "A snail can sleep for three years".
// Tab 2 will have the text "A rhino's horn is made of hair". // Tab 2 will have the text "A rhino's horn is made of hair".
OnSpeechRecognitionReady(0);
OnPartialTranscription("Polar bears are the largest carnivores on land", 0); OnPartialTranscription("Polar bears are the largest carnivores on land", 0);
EXPECT_TRUE(IsWidgetVisible()); EXPECT_TRUE(IsWidgetVisible());
EXPECT_EQ("Polar bears are the largest carnivores on land", GetLabelText()); EXPECT_EQ("Polar bears are the largest carnivores on land", GetLabelText());
...@@ -707,7 +644,6 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, ChangeActiveTab) { ...@@ -707,7 +644,6 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, ChangeActiveTab) {
// Switch back to tab 1 and send transcriptions. // Switch back to tab 1 and send transcriptions.
ActivateTabAt(1); ActivateTabAt(1);
OnSpeechRecognitionReady(1);
OnFinalTranscription("A snail can sleep", 1); OnFinalTranscription("A snail can sleep", 1);
OnPartialTranscription("for two years", 1); OnPartialTranscription("for two years", 1);
EXPECT_TRUE(IsWidgetVisible()); EXPECT_TRUE(IsWidgetVisible());
...@@ -715,7 +651,6 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, ChangeActiveTab) { ...@@ -715,7 +651,6 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, ChangeActiveTab) {
// Send a transcription to tab 2 before activating it. // Send a transcription to tab 2 before activating it.
InsertNewTab(); InsertNewTab();
OnSpeechRecognitionReady(2);
OnPartialTranscription("A rhino's horn is made of hair", 2); OnPartialTranscription("A rhino's horn is made of hair", 2);
ActivateTabAt(2); ActivateTabAt(2);
EXPECT_TRUE(IsWidgetVisible()); EXPECT_TRUE(IsWidgetVisible());
...@@ -757,7 +692,6 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, TruncatesFinalText) { ...@@ -757,7 +692,6 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, TruncatesFinalText) {
for (int i = 10; i < 40; i++) { for (int i = 10; i < 40; i++) {
text += base::NumberToString(i) + line + " "; text += base::NumberToString(i) + line + " ";
} }
OnSpeechRecognitionReady();
OnFinalTranscription(text); OnFinalTranscription(text);
EXPECT_EQ(text.substr(10500, 15000), GetLabelText()); EXPECT_EQ(text.substr(10500, 15000), GetLabelText());
EXPECT_EQ(9u, GetBubble()->GetNumLinesInLabel()); EXPECT_EQ(9u, GetBubble()->GetNumLinesInLabel());
...@@ -773,7 +707,6 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, TabNavigation) { ...@@ -773,7 +707,6 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, TabNavigation) {
ui_test_utils::NavigateToURL(browser(), GURL("http://www.google.com")); ui_test_utils::NavigateToURL(browser(), GURL("http://www.google.com"));
content::WaitForLoadStop( content::WaitForLoadStop(
browser()->tab_strip_model()->GetActiveWebContents()); browser()->tab_strip_model()->GetActiveWebContents());
OnSpeechRecognitionReady();
OnFinalTranscription("Elephant calves can stand within 20 minutes of birth"); OnFinalTranscription("Elephant calves can stand within 20 minutes of birth");
EXPECT_TRUE(IsWidgetVisible()); EXPECT_TRUE(IsWidgetVisible());
EXPECT_EQ("Elephant calves can stand within 20 minutes of birth", EXPECT_EQ("Elephant calves can stand within 20 minutes of birth",
...@@ -787,7 +720,6 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, TabNavigation) { ...@@ -787,7 +720,6 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, TabNavigation) {
// The caption bubble reappears when a transcription is received on the new // The caption bubble reappears when a transcription is received on the new
// page. // page.
OnSpeechRecognitionReady();
OnFinalTranscription("A group of toads is called a knot"); OnFinalTranscription("A group of toads is called a knot");
EXPECT_TRUE(IsWidgetVisible()); EXPECT_TRUE(IsWidgetVisible());
EXPECT_EQ("A group of toads is called a knot", GetLabelText()); EXPECT_EQ("A group of toads is called a knot", GetLabelText());
...@@ -799,7 +731,6 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, TabNavigation) { ...@@ -799,7 +731,6 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, TabNavigation) {
EXPECT_FALSE(IsWidgetVisible()); EXPECT_FALSE(IsWidgetVisible());
// The caption bubble reappears when a transcription is received. // The caption bubble reappears when a transcription is received.
OnSpeechRecognitionReady();
OnFinalTranscription("Lemurs, like dogs, have wet noses"); OnFinalTranscription("Lemurs, like dogs, have wet noses");
EXPECT_TRUE(IsWidgetVisible()); EXPECT_TRUE(IsWidgetVisible());
EXPECT_EQ("Lemurs, like dogs, have wet noses", GetLabelText()); EXPECT_EQ("Lemurs, like dogs, have wet noses", GetLabelText());
...@@ -811,7 +742,6 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, TabNavigation) { ...@@ -811,7 +742,6 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, TabNavigation) {
EXPECT_FALSE(IsWidgetVisible()); EXPECT_FALSE(IsWidgetVisible());
// The caption bubble reappears when a transcription is received. // The caption bubble reappears when a transcription is received.
OnSpeechRecognitionReady();
OnFinalTranscription("A blue whale's tongue weighs more than most elephants"); OnFinalTranscription("A blue whale's tongue weighs more than most elephants");
EXPECT_TRUE(IsWidgetVisible()); EXPECT_TRUE(IsWidgetVisible());
EXPECT_EQ("A blue whale's tongue weighs more than most elephants", EXPECT_EQ("A blue whale's tongue weighs more than most elephants",
...@@ -824,7 +754,6 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, TabNavigation) { ...@@ -824,7 +754,6 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, TabNavigation) {
EXPECT_FALSE(IsWidgetVisible()); EXPECT_FALSE(IsWidgetVisible());
// The caption bubble reappears when a transcription is received. // The caption bubble reappears when a transcription is received.
OnSpeechRecognitionReady();
OnFinalTranscription("All polar bears are left-pawed"); OnFinalTranscription("All polar bears are left-pawed");
EXPECT_TRUE(IsWidgetVisible()); EXPECT_TRUE(IsWidgetVisible());
EXPECT_EQ("All polar bears are left-pawed", GetLabelText()); EXPECT_EQ("All polar bears are left-pawed", GetLabelText());
...@@ -837,7 +766,6 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, TabNavigation) { ...@@ -837,7 +766,6 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, TabNavigation) {
content::WaitForLoadStop( content::WaitForLoadStop(
browser()->tab_strip_model()->GetActiveWebContents()); browser()->tab_strip_model()->GetActiveWebContents());
EXPECT_FALSE(IsWidgetVisible()); EXPECT_FALSE(IsWidgetVisible());
OnSpeechRecognitionReady();
OnFinalTranscription("Rats laugh when they are tickled"); OnFinalTranscription("Rats laugh when they are tickled");
EXPECT_TRUE(IsWidgetVisible()); EXPECT_TRUE(IsWidgetVisible());
EXPECT_EQ("Rats laugh when they are tickled", GetLabelText()); EXPECT_EQ("Rats laugh when they are tickled", GetLabelText());
...@@ -854,11 +782,9 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, TabNavigation) { ...@@ -854,11 +782,9 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, TabNavigation) {
IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest,
DestroysWithoutCrashing) { DestroysWithoutCrashing) {
// Test passes if destroying the controller does not crash. // Test passes if destroying the controller does not crash.
OnSpeechRecognitionReady();
OnPartialTranscription("Deer have a four-chambered stomach"); OnPartialTranscription("Deer have a four-chambered stomach");
DestroyController(); DestroyController();
OnSpeechRecognitionReady();
OnPartialTranscription("Deer antlers fall off and regrow every year"); OnPartialTranscription("Deer antlers fall off and regrow every year");
ClickButton(GetCloseButton()); ClickButton(GetCloseButton());
DestroyController(); DestroyController();
...@@ -867,32 +793,31 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, ...@@ -867,32 +793,31 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest,
IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, ExpandsAndCollapses) { IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, ExpandsAndCollapses) {
int line_height = 24; int line_height = 24;
OnSpeechRecognitionReady();
OnPartialTranscription("Seahorses are monogamous"); OnPartialTranscription("Seahorses are monogamous");
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(2 * line_height, GetLabel()->GetBoundsInScreen().height());
ClickButton(GetExpandButton()); ClickButton(GetExpandButton());
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(8 * line_height, GetLabel()->GetBoundsInScreen().height());
// Switch tabs. The bubble should remain expanded. // Switch tabs. The bubble should remain expanded.
InsertNewTab(); InsertNewTab();
ActivateTabAt(1); ActivateTabAt(1);
EXPECT_FALSE(IsWidgetVisible()); EXPECT_FALSE(IsWidgetVisible());
OnSpeechRecognitionReady(1); OnPartialTranscription(
OnPartialTranscription("Nearly all ants are female."); "Honeybees have tiny hairs on their eyes to help them collect pollen");
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(8 * line_height, GetLabel()->GetBoundsInScreen().height());
ClickButton(GetCollapseButton()); ClickButton(GetCollapseButton());
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(2 * line_height, GetLabel()->GetBoundsInScreen().height());
} }
IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, NonAsciiCharacter) { IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, NonAsciiCharacter) {
......
...@@ -29,7 +29,6 @@ void CaptionBubbleModel::SetObserver(CaptionBubble* observer) { ...@@ -29,7 +29,6 @@ void CaptionBubbleModel::SetObserver(CaptionBubble* observer) {
return; return;
observer_ = observer; observer_ = observer;
if (observer_) { if (observer_) {
observer_->OnReadyChanged();
observer_->OnTextChanged(); observer_->OnTextChanged();
observer_->OnErrorChanged(); observer_->OnErrorChanged();
} }
...@@ -53,23 +52,9 @@ void CaptionBubbleModel::Close() { ...@@ -53,23 +52,9 @@ void CaptionBubbleModel::Close() {
final_text_.clear(); final_text_.clear();
partial_text_.clear(); partial_text_.clear();
is_closed_ = true; is_closed_ = true;
is_ready_ = false;
OnTextChanged(); OnTextChanged();
} }
void CaptionBubbleModel::OnReady() {
final_text_.clear();
partial_text_.clear();
is_ready_ = true;
// The label text must not be empty when it is displayed, so there is a
// special OnReadyChanged() function in the CaptionBubble that handles the
// on_ready state change.
// TODO(1055150): Fix the bug in RenderText and then change this to
// OnTextChanged().
if (observer_)
observer_->OnReadyChanged();
}
void CaptionBubbleModel::OnError() { void CaptionBubbleModel::OnError() {
has_error_ = true; has_error_ = true;
if (observer_) if (observer_)
...@@ -85,10 +70,8 @@ void CaptionBubbleModel::DidFinishNavigation( ...@@ -85,10 +70,8 @@ void CaptionBubbleModel::DidFinishNavigation(
final_text_.clear(); final_text_.clear();
partial_text_.clear(); partial_text_.clear();
is_closed_ = false; is_closed_ = false;
is_ready_ = false;
has_error_ = false; has_error_ = false;
if (observer_) { if (observer_) {
observer_->OnReadyChanged();
observer_->OnTextChanged(); observer_->OnTextChanged();
observer_->OnErrorChanged(); observer_->OnErrorChanged();
} }
......
...@@ -57,10 +57,7 @@ class CaptionBubbleModel : public content::WebContentsObserver { ...@@ -57,10 +57,7 @@ class CaptionBubbleModel : public content::WebContentsObserver {
// observer. // observer.
void Close(); void Close();
void OnReady();
bool IsClosed() const { return is_closed_; } bool IsClosed() const { return is_closed_; }
bool IsReady() const { return is_ready_; }
bool HasError() const { return has_error_; } bool HasError() const { return has_error_; }
std::string GetFullText() const { return final_text_ + partial_text_; } std::string GetFullText() const { return final_text_ + partial_text_; }
...@@ -79,9 +76,6 @@ class CaptionBubbleModel : public content::WebContentsObserver { ...@@ -79,9 +76,6 @@ class CaptionBubbleModel : public content::WebContentsObserver {
// Whether the bubble has been closed by the user. // Whether the bubble has been closed by the user.
bool is_closed_ = false; bool is_closed_ = false;
// Whether bubble is ready to receive transcriptions.
bool is_ready_ = false;
// Whether an error should be displayed one the bubble. // Whether an error should be displayed one the bubble.
bool has_error_ = false; bool has_error_ = false;
......
...@@ -397,11 +397,9 @@ IN_PROC_BROWSER_TEST_F(BrowserViewTest, F6CyclesThroughCaptionBubbleToo) { ...@@ -397,11 +397,9 @@ IN_PROC_BROWSER_TEST_F(BrowserViewTest, F6CyclesThroughCaptionBubbleToo) {
caption_controller->GetCaptionBubbleControllerForBrowser(browser())); caption_controller->GetCaptionBubbleControllerForBrowser(browser()));
EXPECT_FALSE(bubble_controller->GetFocusableCaptionBubble()); EXPECT_FALSE(bubble_controller->GetFocusableCaptionBubble());
content::WebContents* contents =
browser()->tab_strip_model()->GetActiveWebContents();
caption_controller->OnSpeechRecognitionReady(contents);
caption_controller->DispatchTranscription( caption_controller->DispatchTranscription(
contents, chrome::mojom::TranscriptionResult::New("Hello, world", false)); browser()->tab_strip_model()->GetActiveWebContents(),
chrome::mojom::TranscriptionResult::New("Hello, world", false));
// Now the caption bubble exists but is not focused. // Now the caption bubble exists but is not focused.
views::View* bubble = bubble_controller->GetFocusableCaptionBubble(); views::View* bubble = bubble_controller->GetFocusableCaptionBubble();
EXPECT_TRUE(bubble); EXPECT_TRUE(bubble);
......
...@@ -7,9 +7,6 @@ module chrome.mojom; ...@@ -7,9 +7,6 @@ module chrome.mojom;
// Browser process interface exposed to the renderer for communication about // Browser process interface exposed to the renderer for communication about
// the Live Caption feature. // the Live Caption feature.
interface CaptionHost { interface CaptionHost {
// Called when speech recognition service is ready to send transcriptions.
OnSpeechRecognitionReady() => (bool success);
// Called when the speech recognition client receives a transcription from the // Called when the speech recognition client receives a transcription from the
// speech service. Returns whether the transcription result was received // speech service. Returns whether the transcription result was received
// successfully. Transcriptions will halt if this returns false. // successfully. Transcriptions will halt if this returns false.
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "chrome/renderer/media/chrome_speech_recognition_client.h" #include "chrome/renderer/media/chrome_speech_recognition_client.h"
#include <utility> #include <utility>
#include <vector>
#include "base/metrics/field_trial_params.h" #include "base/metrics/field_trial_params.h"
#include "content/public/renderer/render_frame.h" #include "content/public/renderer/render_frame.h"
...@@ -65,6 +64,7 @@ void ChromeSpeechRecognitionClient::OnRecognizerBound( ...@@ -65,6 +64,7 @@ void ChromeSpeechRecognitionClient::OnRecognizerBound(
bool is_multichannel_supported) { bool is_multichannel_supported) {
is_multichannel_supported_ = is_multichannel_supported; is_multichannel_supported_ = is_multichannel_supported;
is_recognizer_bound_ = true; is_recognizer_bound_ = true;
if (on_ready_callback_) if (on_ready_callback_)
std::move(on_ready_callback_).Run(); std::move(on_ready_callback_).Run();
} }
...@@ -118,11 +118,11 @@ void ChromeSpeechRecognitionClient::OnSpeechRecognitionRecognitionEvent( ...@@ -118,11 +118,11 @@ void ChromeSpeechRecognitionClient::OnSpeechRecognitionRecognitionEvent(
caption_host_->OnTranscription( caption_host_->OnTranscription(
chrome::mojom::TranscriptionResult::New(result->transcription, chrome::mojom::TranscriptionResult::New(result->transcription,
result->is_final), result->is_final),
base::BindOnce(&ChromeSpeechRecognitionClient::OnBrowserCallback, base::BindOnce(&ChromeSpeechRecognitionClient::OnTranscriptionCallback,
base::Unretained(this))); base::Unretained(this)));
} }
void ChromeSpeechRecognitionClient::OnBrowserCallback(bool success) { void ChromeSpeechRecognitionClient::OnTranscriptionCallback(bool success) {
is_browser_requesting_transcription_ = success; is_browser_requesting_transcription_ = success;
} }
...@@ -161,17 +161,6 @@ void ChromeSpeechRecognitionClient::SendAudioToSpeechRecognitionService( ...@@ -161,17 +161,6 @@ void ChromeSpeechRecognitionClient::SendAudioToSpeechRecognitionService(
if (IsSpeechRecognitionAvailable()) { if (IsSpeechRecognitionAvailable()) {
speech_recognition_recognizer_->SendAudioToSpeechRecognitionService( speech_recognition_recognizer_->SendAudioToSpeechRecognitionService(
std::move(audio_data)); std::move(audio_data));
// When the speech recognition client receives speech, it alerts the
// live caption host in the browser that it is ready so that the UI can
// display a message. This happens at the time of playing the video and not
// at the time of construction of this object.
if (!on_ready_message_sent_to_caption_host_) {
caption_host_->OnSpeechRecognitionReady(
base::BindOnce(&ChromeSpeechRecognitionClient::OnBrowserCallback,
base::Unretained(this)));
on_ready_message_sent_to_caption_host_ = true;
}
} }
} }
......
...@@ -65,8 +65,8 @@ class ChromeSpeechRecognitionClient ...@@ -65,8 +65,8 @@ class ChromeSpeechRecognitionClient
media::mojom::AudioDataS16Ptr ConvertToAudioDataS16( media::mojom::AudioDataS16Ptr ConvertToAudioDataS16(
scoped_refptr<media::AudioBuffer> buffer); scoped_refptr<media::AudioBuffer> buffer);
// Called as a response to sending a message to the browser. // Called as a response to sending a transcription to the browser.
void OnBrowserCallback(bool success); void OnTranscriptionCallback(bool success);
media::mojom::AudioDataS16Ptr ConvertToAudioDataS16( media::mojom::AudioDataS16Ptr ConvertToAudioDataS16(
std::unique_ptr<media::AudioBus> audio_bus, std::unique_ptr<media::AudioBus> audio_bus,
...@@ -116,9 +116,6 @@ class ChromeSpeechRecognitionClient ...@@ -116,9 +116,6 @@ class ChromeSpeechRecognitionClient
bool is_recognizer_bound_ = false; bool is_recognizer_bound_ = false;
// Whether or not the on ready message has been sent to the caption host.
bool on_ready_message_sent_to_caption_host_ = false;
// The temporary audio bus used to mix multichannel audio into a single // The temporary audio bus used to mix multichannel audio into a single
// channel. // channel.
std::unique_ptr<media::AudioBus> monaural_audio_bus_; std::unique_ptr<media::AudioBus> monaural_audio_bus_;
......
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