#ifdef UNSAFE_BUFFERS_BUILD
#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"
#include "services/screen_ai/public/test/fake_screen_ai_annotator.h"
#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
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(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
class TestPdfAccessibilityActionHandler
: public chrome_pdf::PdfAccessibilityActionHandler { … };
struct ImagePosition { … };
bool operator<(const ImagePosition& p1, const ImagePosition& p2) { … }
class TestPdfAccessibilityImageFetcher
: public chrome_pdf::PdfAccessibilityImageFetcher { … };
void WaitForThreadTasks() { … }
class TestPdfAccessibilityTree : public PdfAccessibilityTree { … };
}
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<
bool,
PdfOcrHelperTestBatchData>> { … };
TEST_P(PdfOcrHelperTest, PageBatching) { … }
TEST_P(PdfOcrHelperTest, UMAMetrics) { … }
TEST_P(PdfOcrHelperTest, EmptyOCRResults) { … }
TEST_P(PdfOcrHelperTest, OCRCompleteNotification) { … }
INSTANTIATE_TEST_SUITE_P(…);
class PdfOcrTest : public PdfAccessibilityTreeTest { … };
TEST_F(PdfOcrTest, CheckLiveRegionPoliteStatus) { … }
TEST_F(PdfOcrTest, CheckLiveRegionNotSetWhenInBackground) { … }
TEST_F(PdfOcrTest, FeatureNotificationOnInaccessiblePdf) { … }
TEST_F(PdfOcrTest, NoFeatureNotificationOnAccessiblePdf) { … }
class PdfOcrRotationTest : public PdfOcrTest,
public testing::WithParamInterface<int> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(PdfOcrRotationTest, TestTransformFromOnOcrDataReceived) { … }
#endif
}