chromium/chrome/browser/screen_ai/optical_character_recognizer_browsertest.cc

// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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 {

// Load image from test data directory.
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) {}

// bool: PDF OCR service enabled.
// bool: ScreenAI library available.
OpticalCharacterRecognizerTestParams;

struct OpticalCharacterRecognizerTestParamsToString {};

#if BUILDFLAG(ENABLE_SCREEN_AI_BROWSERTESTS) && !BUILDFLAG(USE_FAKE_SCREEN_AI)

// Computes string match based on the edit distance of the two strings.
// Returns 0 for totally different strings and 1 for totally matching. See
// `StringMatchTest` for some examples.
double StringMatch(std::string_view expected, std::string_view extracted) {}

#endif  // BUILDFLAG(ENABLE_SCREEN_AI_BROWSERTESTS) &&
        // !BUILDFLAG(USE_FAKE_SCREEN_AI)

}  // namespace

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) {}

// The image used in this test is very simple to reduce the possibility of
// failure due to library changes.
// If this test fails after updating the library, there is a high probability
// that the new library has some sort of incompatibility with Chromium.
IN_PROC_BROWSER_TEST_P(OpticalCharacterRecognizerTest, PerformOCR_Simple) {}

// TODO(362478055): Fix this flaky test.
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) {}

// Param: Test name.
class OpticalCharacterRecognizerResultsTest
    : public InProcessBrowserTest,
      public ::testing::WithParamInterface<const char*> {};

// If this test fails after updating the library, the failure can be related to
// minor changes in recognition results of the library. The failed cases can be
// checked and if the new result is acceptable. For each test case, the last
// line in the .txt file is the minimum acceptable match and it can be updated.
IN_PROC_BROWSER_TEST_P(OpticalCharacterRecognizerResultsTest, PerformOCR) {}

INSTANTIATE_TEST_SUITE_P();

#endif  // BUILDFLAG(ENABLE_SCREEN_AI_BROWSERTESTS) && !
        // BUILDFLAG(USE_FAKE_SCREEN_AI)
}  // namespace screen_ai