chromium/components/pdf/renderer/pdf_accessibility_tree_browsertest.cc

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

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "components/pdf/renderer/pdf_accessibility_tree.h"

#include <map>
#include <memory>

#include "base/functional/callback.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "components/strings/grit/components_strings.h"
#include "content/public/common/content_switches.h"
#include "content/public/renderer/render_accessibility.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/test/render_view_test.h"
#include "pdf/accessibility_structs.h"
#include "pdf/pdf_accessibility_action_handler.h"
#include "pdf/pdf_accessibility_image_fetcher.h"
#include "pdf/pdf_features.h"
#include "third_party/blink/public/web/web_ax_object.h"
#include "third_party/blink/public/web/web_element.h"
#include "third_party/blink/public/web/web_local_frame.h"
#include "third_party/blink/public/web/web_settings.h"
#include "third_party/blink/public/web/web_view.h"
#include "ui/accessibility/ax_action_data.h"
#include "ui/accessibility/ax_enums.mojom.h"
#include "ui/accessibility/ax_event_generator.h"
#include "ui/accessibility/ax_mode.h"
#include "ui/accessibility/ax_node.h"
#include "ui/accessibility/ax_node_id_forward.h"
#include "ui/accessibility/ax_tree_id.h"
#include "ui/accessibility/ax_tree_manager.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/strings/grit/auto_image_annotation_strings.h"

#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
#include <tuple>

#include "base/containers/queue.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/screen_ai/public/mojom/screen_ai_service.mojom.h"  // nogncheck crbug.com/1125897
#include "services/screen_ai/public/test/fake_screen_ai_annotator.h"  // nogncheck crbug.com/40147906
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/accessibility/accessibility_features.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/accessibility/ax_tree_id.h"
#include "ui/accessibility/ax_tree_update.h"
#include "ui/gfx/geometry/transform.h"
#endif  // BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)

namespace pdf {

namespace {

const chrome_pdf::AccessibilityTextRunInfo kFirstTextRun =;
const chrome_pdf::AccessibilityTextRunInfo kSecondTextRun =;
const chrome_pdf::AccessibilityCharInfo kDummyCharsData[] =;
const chrome_pdf::AccessibilityTextRunInfo kFirstRunMultiLine =;
const chrome_pdf::AccessibilityTextRunInfo kSecondRunMultiLine =;
const chrome_pdf::AccessibilityTextRunInfo kThirdRunMultiLine =;
const chrome_pdf::AccessibilityTextRunInfo kFourthRunMultiLine =;

const char kChromiumTestUrl[] =;

Matches;
PrintToString;
UnorderedElementsAre;

// `MATCHER_P2` is copied from ui/accessibility/ax_event_generator_unittest.cc.
MATCHER_P2(HasEventAtNode,
           expected_event_type,
           expected_node_id,
           std::string(negation ? "does not have" : "has") + " " +
               PrintToString(expected_event_type) + " on " +
               PrintToString(expected_node_id)) {}

void CompareRect(const gfx::RectF& expected_rect,
                 const gfx::RectF& actual_rect) {}

constexpr uint32_t MakeARGB(unsigned int a,
                            unsigned int r,
                            unsigned int g,
                            unsigned int b) {}

void CheckRootAndStatusNodes(const ui::AXNode* root_node,
                             size_t num_child,
                             bool is_pdf_ocr_test,
                             bool is_ocr_completed,
                             bool create_empty_ocr_results) {}

#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
ui::AXTreeUpdate CreateMockOCRResult(const gfx::RectF& image_bounds,
                                     const gfx::RectF& text_bounds1,
                                     const gfx::RectF& text_bounds2) {}

uint32_t CalculateBatchCount(uint32_t page_count, uint32_t batch_size) {}
#endif  // BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)

// This class overrides PdfAccessibilityActionHandler to record received
// action data when tests make an accessibility action call.
class TestPdfAccessibilityActionHandler
    : public chrome_pdf::PdfAccessibilityActionHandler {};

struct ImagePosition {};

bool operator<(const ImagePosition& p1, const ImagePosition& p2) {}

// This class overrides PdfAccessibilityImageFetcher to return an image from
// previously stored images, instead of looking for it in the PDF.
class TestPdfAccessibilityImageFetcher
    : public chrome_pdf::PdfAccessibilityImageFetcher {};

// Waits for tasks posted to the thread's task runner to complete.
void WaitForThreadTasks() {}

class TestPdfAccessibilityTree : public PdfAccessibilityTree {};

}  // namespace

class PdfAccessibilityTreeTest : public content::RenderViewTest {};

TEST_F(PdfAccessibilityTreeTest, TestEmptyPDFPage) {}

TEST_F(PdfAccessibilityTreeTest, TestAccessibilityDisabledDuringPDFLoad) {}

TEST_F(PdfAccessibilityTreeTest, TestPdfAccessibilityTreeReload) {}

TEST_F(PdfAccessibilityTreeTest, TestPdfAccessibilityTreeCreation) {}

TEST_F(PdfAccessibilityTreeTest, TestOverlappingAnnots) {}

TEST_F(PdfAccessibilityTreeTest, TestHighlightCreation) {}

TEST_F(PdfAccessibilityTreeTest, TestTextFieldNodeCreation) {}

TEST_F(PdfAccessibilityTreeTest, TestButtonNodeCreation) {}

TEST_F(PdfAccessibilityTreeTest, TestListboxNodeCreation) {}

TEST_F(PdfAccessibilityTreeTest, TestComboboxNodeCreation) {}

TEST_F(PdfAccessibilityTreeTest, TestPreviousNextOnLine) {}

TEST_F(PdfAccessibilityTreeTest, TextRunsAndCharsMismatch) {}

TEST_F(PdfAccessibilityTreeTest, UnsortedLinkVector) {}

TEST_F(PdfAccessibilityTreeTest, OutOfBoundLink) {}

TEST_F(PdfAccessibilityTreeTest, UnsortedImageVector) {}

TEST_F(PdfAccessibilityTreeTest, OutOfBoundImage) {}

TEST_F(PdfAccessibilityTreeTest, UnsortedHighlightVector) {}

TEST_F(PdfAccessibilityTreeTest, OutOfBoundHighlight) {}

TEST_F(PdfAccessibilityTreeTest, TestActionDataConversion) {}

TEST_F(PdfAccessibilityTreeTest, TestScrollToGlobalPointDataConversion) {}

TEST_F(PdfAccessibilityTreeTest, TestClickActionDataConversion) {}

TEST_F(PdfAccessibilityTreeTest, TestEmptyPdfAxActions) {}

TEST_F(PdfAccessibilityTreeTest, TestZoomAndScaleChanges) {}

TEST_F(PdfAccessibilityTreeTest, TestSelectionActionDataConversion) {}

TEST_F(PdfAccessibilityTreeTest, TestShowContextMenuAction) {}

TEST_F(PdfAccessibilityTreeTest, StitchChildTreeAction) {}

#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
struct PdfOcrHelperTestBatchData {};

class PdfOcrHelperTest : public PdfAccessibilityTreeTest,
                         public testing::WithParamInterface<std::tuple<
                             /* is_ocr_helper_started_before_pdf_loads */ bool,
                             PdfOcrHelperTestBatchData>> {};

TEST_P(PdfOcrHelperTest, PageBatching) {}

TEST_P(PdfOcrHelperTest, UMAMetrics) {}

TEST_P(PdfOcrHelperTest, EmptyOCRResults) {}

TEST_P(PdfOcrHelperTest, OCRCompleteNotification) {}

// 5 = smaller than the batch size, 105 = larger than the batch size
// with fewer remaining pages in the first batch, 280 = greater than the
// batch size by a lot and no remaining pages in the first batch.
INSTANTIATE_TEST_SUITE_P();

// TODO(crbug.com/40267312): Add test for end result on a non-synthetic
// multi-page PDF.

class PdfOcrTest : public PdfAccessibilityTreeTest {};

TEST_F(PdfOcrTest, CheckLiveRegionPoliteStatus) {}

TEST_F(PdfOcrTest, CheckLiveRegionNotSetWhenInBackground) {}

TEST_F(PdfOcrTest, FeatureNotificationOnInaccessiblePdf) {}

TEST_F(PdfOcrTest, NoFeatureNotificationOnAccessiblePdf) {}

// Test param: image orientation.
class PdfOcrRotationTest : public PdfOcrTest,
                           public testing::WithParamInterface<int> {};

INSTANTIATE_TEST_SUITE_P();

TEST_P(PdfOcrRotationTest, TestTransformFromOnOcrDataReceived) {}
#endif  // BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)

}  // namespace pdf