Skip to content

Commit

Permalink
[Live Caption] Tests for non-web prototype.
Browse files Browse the repository at this point in the history
This CL adds tests for new "non-web" audio source live caption
functionality. The two CLs are kept separate to emphasize that this CL's
broad footprint is trivial and for testing purposes only.

We migrate to "for testing" helpers because adding more friend classes
would violate layering (e.g. ::ash friends in ::content-level classes).

Bug: b:253114860
Change-Id: Ib288aa8b6e5790565bc776e7e81d385eb4cc4dec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4050680
Reviewed-by: Andrew Moylan <amoylan@chromium.org>
Reviewed-by: Abigail Klein <abigailbklein@google.com>
Reviewed-by: Katie Dektar <katie@chromium.org>
Commit-Queue: Michael Martis <martis@chromium.org>
Reviewed-by: Evan Liu <evliu@google.com>
Cr-Commit-Position: refs/heads/main@{#1084819}
  • Loading branch information
martis-chromium authored and Chromium LUCI CQ committed Dec 19, 2022
1 parent 007f799 commit 1fca20b
Show file tree
Hide file tree
Showing 15 changed files with 418 additions and 24 deletions.
Expand Up @@ -73,7 +73,8 @@ class LiveCaptionControllerTest : public LiveCaptionBrowserTest {
}

CaptionBubbleController* GetBubbleControllerForProfile(Profile* profile) {
return GetControllerForProfile(profile)->caption_bubble_controller_.get();
return GetControllerForProfile(profile)
->caption_bubble_controller_for_testing();
}

CaptionBubbleContextBrowser* GetCaptionBubbleContextBrowser() {
Expand Down Expand Up @@ -123,8 +124,8 @@ class LiveCaptionControllerTest : public LiveCaptionBrowserTest {
}

bool HasBubbleControllerOnProfile(Profile* profile) {
return GetControllerForProfile(profile)->caption_bubble_controller_ !=
nullptr;
return GetControllerForProfile(profile)
->caption_bubble_controller_for_testing() != nullptr;
}

void ExpectIsWidgetVisible(bool visible) {
Expand Down
Expand Up @@ -112,14 +112,14 @@ class LiveCaptionSpeechRecognitionHostTest : public LiveCaptionBrowserTest {

bool HasBubbleController() {
return LiveCaptionControllerFactory::GetForProfile(browser()->profile())
->caption_bubble_controller_.get() != nullptr;
->caption_bubble_controller_for_testing() != nullptr;
}

void ExpectIsWidgetVisible(bool visible) {
#if defined(TOOLKIT_VIEWS)
CaptionBubbleController* bubble_controller =
LiveCaptionControllerFactory::GetForProfile(browser()->profile())
->caption_bubble_controller_.get();
->caption_bubble_controller_for_testing();
EXPECT_EQ(visible, bubble_controller->IsWidgetVisibleForTesting());
#endif
}
Expand Down
Expand Up @@ -62,14 +62,14 @@ class LiveCaptionUnavailabilityNotifierTest : public LiveCaptionBrowserTest {

bool HasBubbleController() {
return LiveCaptionControllerFactory::GetForProfile(browser()->profile())
->caption_bubble_controller_.get() != nullptr;
->caption_bubble_controller_for_testing() != nullptr;
}

void ExpectIsWidgetVisible(bool visible) {
#if defined(TOOLKIT_VIEWS)
CaptionBubbleController* bubble_controller =
LiveCaptionControllerFactory::GetForProfile(browser()->profile())
->caption_bubble_controller_.get();
->caption_bubble_controller_for_testing();
EXPECT_EQ(visible, bubble_controller->IsWidgetVisibleForTesting());
#endif
}
Expand Down
Expand Up @@ -100,6 +100,13 @@ void SystemLiveCaptionService::SpeechRecognitionAvailabilityChanged(
prefs::GetLiveCaptionLanguageCode(profile_->GetPrefs()),
/*is_server_based=*/false,
media::mojom::RecognizerClientType::kLiveCaption));

// Inject a fake audio system in tests.
if (!create_audio_system_for_testing_.is_null()) {
client_->set_audio_system_for_testing( // IN-TEST
create_audio_system_for_testing_.Run());
}

return;
}

Expand Down
15 changes: 15 additions & 0 deletions chrome/browser/ash/accessibility/system_live_caption_service.h
Expand Up @@ -27,6 +27,10 @@ namespace captions {
class LiveCaptionController;
} // namespace captions

namespace media {
class AudioSystem;
} // namespace media

namespace ash {

// Responsible for running the live captioning model on audio from non-web (e.g.
Expand Down Expand Up @@ -71,6 +75,13 @@ class SystemLiveCaptionService
bool is_speech_recognition_available) override;
void SpeechRecognitionLanguageChanged(const std::string& language) override;

void set_audio_system_factory_for_testing(
base::RepeatingCallback<std::unique_ptr<media::AudioSystem>()>
create_audio_system_for_testing) {
create_audio_system_for_testing_ =
std::move(create_audio_system_for_testing);
}

private:
// Stops and destructs audio stream recognizing client.
void StopRecognizing();
Expand All @@ -85,6 +96,10 @@ class SystemLiveCaptionService
mojo::Receiver<media::mojom::SpeechRecognitionBrowserObserver>
browser_observer_receiver_{this};

// Used to inject a fake audio system into our client in tests.
base::RepeatingCallback<std::unique_ptr<media::AudioSystem>()>
create_audio_system_for_testing_;

base::WeakPtrFactory<SystemLiveCaptionService> weak_ptr_factory_{this};
};

Expand Down

0 comments on commit 1fca20b

Please sign in to comment.