#include "chrome/browser/screen_ai/public/optical_character_recognizer.h"
#include "base/files/file_util.h"
#include "base/notreached.h"
#include "base/path_service.h"
#include "base/scoped_observation.h"
#include "base/strings/stringprintf.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/test_future.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/screen_ai/screen_ai_install_state.h"
#include "chrome/browser/screen_ai/screen_ai_service_router.h"
#include "chrome/browser/screen_ai/screen_ai_service_router_factory.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "components/metrics/content/subprocess_metrics_provider.h"
#include "content/public/test/browser_test.h"
#include "services/screen_ai/buildflags/buildflags.h"
#include "services/screen_ai/public/cpp/utilities.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/accessibility/accessibility_features.h"
#include "ui/accessibility/ax_features.mojom-features.h"
#include "ui/gfx/codec/png_codec.h"
namespace {
SkBitmap LoadImageFromTestFile(
const base::FilePath& relative_path_from_chrome_data) { … }
void WaitForStatus(scoped_refptr<screen_ai::OpticalCharacterRecognizer> ocr,
base::OnceCallback<void(void)> callback,
int remaining_tries) { … }
void WaitForDisconnecting(screen_ai::ScreenAIServiceRouter* router,
base::OnceCallback<void()> callback,
int remaining_tries) { … }
OpticalCharacterRecognizerTestParams;
struct OpticalCharacterRecognizerTestParamsToString { … };
#if BUILDFLAG(ENABLE_SCREEN_AI_BROWSERTESTS) && !BUILDFLAG(USE_FAKE_SCREEN_AI)
double StringMatch(std::string_view expected, std::string_view extracted) { … }
#endif
}
namespace screen_ai {
class OpticalCharacterRecognizerTest
: public InProcessBrowserTest,
public ScreenAIInstallState::Observer,
public ::testing::WithParamInterface<
OpticalCharacterRecognizerTestParams> { … };
IN_PROC_BROWSER_TEST_P(OpticalCharacterRecognizerTest, Create) { … }
IN_PROC_BROWSER_TEST_P(OpticalCharacterRecognizerTest,
CreateWithStatusCallback) { … }
IN_PROC_BROWSER_TEST_P(OpticalCharacterRecognizerTest, PerformOCR_Empty) { … }
IN_PROC_BROWSER_TEST_P(OpticalCharacterRecognizerTest, PerformOCR_Simple) { … }
IN_PROC_BROWSER_TEST_P(OpticalCharacterRecognizerTest,
DISABLED_PerformOCR_AfterServiceRevive) { … }
IN_PROC_BROWSER_TEST_P(OpticalCharacterRecognizerTest,
PerformOCR_AfterDisconnect) { … }
INSTANTIATE_TEST_SUITE_P(…);
#if BUILDFLAG(ENABLE_SCREEN_AI_BROWSERTESTS) && !BUILDFLAG(USE_FAKE_SCREEN_AI)
TEST(OpticalCharacterRecognizer, StringMatchTest) { … }
class OpticalCharacterRecognizerResultsTest
: public InProcessBrowserTest,
public ::testing::WithParamInterface<const char*> { … };
IN_PROC_BROWSER_TEST_P(OpticalCharacterRecognizerResultsTest, PerformOCR) { … }
INSTANTIATE_TEST_SUITE_P(…);
#endif
}