#include <memory>
#include "base/memory/ptr_util.h"
#include "base/test/scoped_feature_list.h"
#include "base/values.h"
#include "components/manta/anchovy/anchovy_provider.h"
#include "components/manta/manta_status.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "ui/accessibility/accessibility_features.h"
#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include <cstring>
#include <optional>
#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/strings/stringprintf.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "net/base/net_errors.h"
#include "net/http/http_status_code.h"
#include "services/data_decoder/public/cpp/data_decoder.h"
#include "services/data_decoder/public/cpp/test_support/in_process_data_decoder.h"
#include "services/data_decoder/public/mojom/json_parser.mojom.h"
#include "services/image_annotation/annotator.h"
#include "services/image_annotation/image_annotation_metrics.h"
#include "services/image_annotation/public/mojom/image_annotation.mojom.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/public/mojom/url_loader.mojom-shared.h"
#include "services/network/test/test_url_loader_factory.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace image_annotation {
namespace {
Bucket;
ElementsAre;
Eq;
IsEmpty;
SizeIs;
UnorderedElementsAre;
MATCHER_P3(AnnotatorEq, type, score, text, "") { … }
constexpr char kTestServerUrl[] = …;
constexpr char kLangsServerUrl[] = …;
constexpr char kImage1Url[] = …;
constexpr char kImage2Url[] = …;
constexpr char kImage3Url[] = …;
constexpr char kTemplateRequest[] = …;
constexpr char kBatchRequest[] = …;
constexpr char kOcrSuccessResponse[] = …;
constexpr char kBatchResponse[] = …;
constexpr base::TimeDelta kThrottle = …;
constexpr int32_t kDescDim = …;
constexpr char kDescLang[] = …;
class TestImageProcessor : public mojom::ImageProcessor { … };
class TestServerURLLoaderFactory { … };
std::string ReformatJson(const std::string& in) { … }
void ReportResult(std::optional<mojom::AnnotateImageError>* const error,
std::vector<mojom::Annotation>* const annotations,
mojom::AnnotateImageResultPtr result) { … }
class TestAnnotatorClient : public Annotator::Client { … };
}
TEST(AnnotatorTest, OcrSuccessAndCache) { … }
TEST(AnnotatorTest, DescriptionSuccess) { … }
TEST(AnnotatorTest, DoubleOcrResult) { … }
TEST(AnnotatorTest, HttpError) { … }
TEST(AnnotatorTest, BackendError) { … }
TEST(AnnotatorTest, OcrBackendError) { … }
TEST(AnnotatorTest, DescriptionBackendError) { … }
TEST(AnnotatorTest, ServerError) { … }
TEST(AnnotatorTest, AdultError) { … }
TEST(AnnotatorTest, ProcessorFails) { … }
TEST(AnnotatorTest, ProcessorFailedPreviously) { … }
TEST(AnnotatorTest, ProcessorDies) { … }
TEST(AnnotatorTest, ConcurrentSameBatch) { … }
TEST(AnnotatorTest, ConcurrentSeparateBatches) { … }
TEST(AnnotatorTest, DuplicateWork) { … }
TEST(AnnotatorTest, DescPolicy) { … }
TEST(AnnotatorTest, DescLanguage) { … }
TEST(AnnotatorTest, LanguageFallback) { … }
TEST(AnnotatorTest, ApiKey) { … }
TEST(AnnotatorTest, ComputePreferredLanguage) { … }
TEST(AnnotatorTest, FetchServerLanguages) { … }
TEST(AnnotatorTest, ServerLanguagesMustContainEnglish) { … }
class FakeAnchovyProvider : public manta::AnchovyProvider { … };
void RunAnchovyAnnotatorTest(
std::unique_ptr<manta::AnchovyProvider> fake_provider,
std::vector<mojom::Annotation>* annotations) { … }
void SimpleAnchovySuccessTest(std::string str_type,
mojom::AnnotationType expected_type) { … }
TEST(AnnotatorTest, EmptyResultIfDictIsEmpty) { … }
TEST(AnnotatorTest, EmptyResultIfListIsEmpty) { … }
TEST(AnnotatorTest, AnchovySuccessMultiple) { … }
TEST(AnnotatorTest, AnchovySuccessOCR) { … }
TEST(AnnotatorTest, AnchovySuccessCaption) { … }
TEST(AnnotatorTest, AnchovySuccessLabel) { … }
TEST(AnnotatorTest, CrashIfNoText) { … }
TEST(AnnotatorTest, CrashIfNoAnchovyProvider) { … }
}