#include "chrome/browser/accessibility/live_caption/live_caption_speech_recognition_host_browsertest.h"
#include <string>
#include <vector>
#include "chrome/browser/accessibility/live_caption/live_caption_controller_factory.h"
#include "chrome/browser/accessibility/live_caption/live_caption_speech_recognition_host.h"
#include "chrome/browser/accessibility/live_caption/live_caption_test_util.h"
#include "chrome/browser/accessibility/live_translate_controller_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/live_caption/caption_bubble_controller.h"
#include "components/live_caption/live_caption_controller.h"
#include "components/live_caption/live_translate_controller.h"
#include "components/live_caption/pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/sync_preferences/pref_service_syncable.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "media/mojo/mojom/speech_recognition.mojom.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
namespace {
FullscreenEventsWaiter::FullscreenEventsWaiter(
content::WebContents* web_contents)
: … { … }
FullscreenEventsWaiter::~FullscreenEventsWaiter() = default;
void FullscreenEventsWaiter::MediaEffectivelyFullscreenChanged(bool value) { … }
void FullscreenEventsWaiter::Wait() { … }
}
namespace captions {
MockLiveTranslateController::MockLiveTranslateController(
PrefService* profile_prefs,
content::BrowserContext* browser_context)
: … { … }
MockLiveTranslateController::~MockLiveTranslateController() = default;
void MockLiveTranslateController::GetTranslation(
const std::string& result,
std::string source_language,
std::string target_language,
OnTranslateEventCallback callback) { … }
std::vector<std::string> MockLiveTranslateController::GetTranslationRequests() { … }
LiveCaptionSpeechRecognitionHostTest::LiveCaptionSpeechRecognitionHostTest() =
default;
LiveCaptionSpeechRecognitionHostTest::~LiveCaptionSpeechRecognitionHostTest() =
default;
std::unique_ptr<KeyedService>
LiveCaptionSpeechRecognitionHostTest::SetLiveTranslateController(
content::BrowserContext* context) { … }
void LiveCaptionSpeechRecognitionHostTest::SetUp() { … }
void LiveCaptionSpeechRecognitionHostTest::SetUpOnMainThread() { … }
void LiveCaptionSpeechRecognitionHostTest::
CreateLiveCaptionSpeechRecognitionHost(
content::RenderFrameHost* frame_host) { … }
void LiveCaptionSpeechRecognitionHostTest::OnSpeechRecognitionRecognitionEvent(
content::RenderFrameHost* frame_host,
std::string text,
bool expected_success,
bool is_final) { … }
void LiveCaptionSpeechRecognitionHostTest::OnLanguageIdentificationEvent(
content::RenderFrameHost* frame_host,
const std::string& language,
const media::mojom::ConfidenceLevel confidence_level,
const media::mojom::AsrSwitchResult asr_switch_result) { … }
void LiveCaptionSpeechRecognitionHostTest::OnSpeechRecognitionError(
content::RenderFrameHost* frame_host) { … }
bool LiveCaptionSpeechRecognitionHostTest::HasBubbleController() { … }
void LiveCaptionSpeechRecognitionHostTest::ExpectIsWidgetVisible(bool visible) { … }
std::vector<std::string>
LiveCaptionSpeechRecognitionHostTest::GetTranslationRequests() { … }
void LiveCaptionSpeechRecognitionHostTest::DispatchTranscriptionCallback(
bool expected_success,
bool success) { … }
IN_PROC_BROWSER_TEST_F(LiveCaptionSpeechRecognitionHostTest,
DISABLED_DestroysWithoutCrashing) { … }
IN_PROC_BROWSER_TEST_F(LiveCaptionSpeechRecognitionHostTest,
OnSpeechRecognitionRecognitionEvent) { … }
IN_PROC_BROWSER_TEST_F(LiveCaptionSpeechRecognitionHostTest,
OnLanguageIdentificationEvent) { … }
IN_PROC_BROWSER_TEST_F(LiveCaptionSpeechRecognitionHostTest,
OnSpeechRecognitionError) { … }
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_CHROMEOS)
IN_PROC_BROWSER_TEST_F(LiveCaptionSpeechRecognitionHostTest,
MediaEffectivelyFullscreenChanged) {
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
content::RenderFrameHost* frame_host = web_contents->GetPrimaryMainFrame();
CreateLiveCaptionSpeechRecognitionHost(frame_host);
EXPECT_TRUE(content::NavigateToURL(
web_contents, embedded_test_server()->GetURL("/media/fullscreen.html")));
SetLiveCaptionEnabled(true);
EXPECT_TRUE(HasBubbleController());
FullscreenEventsWaiter waiter(web_contents);
EXPECT_TRUE(content::ExecJs(web_contents, "makeFullscreen('small_video')"));
waiter.Wait();
EXPECT_TRUE(HasBubbleController());
EXPECT_TRUE(content::ExecJs(web_contents, "exitFullscreen()"));
waiter.Wait();
EXPECT_TRUE(HasBubbleController());
}
#endif
IN_PROC_BROWSER_TEST_F(LiveCaptionSpeechRecognitionHostTest, LiveTranslate) { … }
IN_PROC_BROWSER_TEST_F(LiveCaptionSpeechRecognitionHostTest, TranslationCache) { … }
IN_PROC_BROWSER_TEST_F(LiveCaptionSpeechRecognitionHostTest,
IdeographicTranslationCache) { … }
}