chromium/pdf/pdfium/pdfium_engine_unittest.cc

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

#if defined(UNSAFE_BUFFERS_BUILD)
// TODO(crbug.com/40284755): Remove this and spanify to fix the errors.
#pragma allow_unsafe_buffers
#endif

#include "pdf/pdfium/pdfium_engine.h"

#include <stdint.h>

#include <utility>

#include "base/functional/callback.h"
#include "base/hash/md5.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/gmock_move_support.h"
#include "base/test/gtest_util.h"
#include "base/test/mock_callback.h"
#include "base/test/scoped_feature_list.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "pdf/document_attachment_info.h"
#include "pdf/document_layout.h"
#include "pdf/document_metadata.h"
#include "pdf/pdf_features.h"
#include "pdf/pdfium/pdfium_page.h"
#include "pdf/pdfium/pdfium_test_base.h"
#include "pdf/test/mouse_event_builder.h"
#include "pdf/test/test_client.h"
#include "pdf/test/test_document_loader.h"
#include "pdf/ui/thumbnail.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/input/web_input_event.h"
#include "third_party/blink/public/common/input/web_keyboard_event.h"
#include "third_party/blink/public/common/input/web_mouse_event.h"
#include "third_party/blink/public/common/input/web_pointer_properties.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"

namespace chrome_pdf {

namespace {

_;
InSequence;
Invoke;
IsEmpty;
NiceMock;
Not;
Return;
StrictMock;

MATCHER_P2(LayoutWithSize, width, height, "") {}

MATCHER_P(LayoutWithOptions, options, "") {}

blink::WebMouseEvent CreateLeftClickWebMouseEventAtPosition(
    const gfx::PointF& position) {}

blink::WebMouseEvent CreateLeftClickWebMouseUpEventAtPosition(
    const gfx::PointF& position) {}

blink::WebMouseEvent CreateRightClickWebMouseEventAtPosition(
    const gfx::PointF& position) {}

blink::WebMouseEvent CreateMoveWebMouseEventToPosition(
    const gfx::PointF& position) {}

class MockTestClient : public TestClient {};

}  // namespace

class PDFiumEngineTest : public PDFiumTestBase {};

TEST_P(PDFiumEngineTest, InitializeWithRectanglesMultiPagesPdf) {}

TEST_P(PDFiumEngineTest, InitializeWithRectanglesMultiPagesPdfInTwoUpView) {}

TEST_P(PDFiumEngineTest, AppendBlankPagesWithFewerPages) {}

TEST_P(PDFiumEngineTest, AppendBlankPagesWithMorePages) {}

TEST_P(PDFiumEngineTest, ProposeDocumentLayoutWithOverlap) {}

TEST_P(PDFiumEngineTest, ApplyDocumentLayoutBeforePluginSizeUpdated) {}

TEST_P(PDFiumEngineTest, ApplyDocumentLayoutAvoidsInfiniteLoop) {}

TEST_P(PDFiumEngineTest, GetDocumentAttachments) {}

TEST_P(PDFiumEngineTest, GetInvalidDocumentAttachment) {}

TEST_P(PDFiumEngineTest, GetDocumentAttachmentWithInvalidData) {}

TEST_P(PDFiumEngineTest, NoDocumentAttachmentInfo) {}

TEST_P(PDFiumEngineTest, GetDocumentMetadata) {}

TEST_P(PDFiumEngineTest, GetEmptyDocumentMetadata) {}

TEST_P(PDFiumEngineTest, GetLinearizedDocumentMetadata) {}

TEST_P(PDFiumEngineTest, GetBadPdfVersion) {}

TEST_P(PDFiumEngineTest, GetNamedDestination) {}

TEST_P(PDFiumEngineTest, PluginSizeUpdatedBeforeLoad) {}

TEST_P(PDFiumEngineTest, PluginSizeUpdatedDuringLoad) {}

TEST_P(PDFiumEngineTest, PluginSizeUpdatedAfterLoad) {}

TEST_P(PDFiumEngineTest, OnLeftMouseDownBeforePluginSizeUpdated) {}

TEST_P(PDFiumEngineTest, OnLeftMouseDownAfterPluginSizeUpdated) {}

TEST_P(PDFiumEngineTest, IncrementalLoadingFeatureDefault) {}

TEST_P(PDFiumEngineTest, IncrementalLoadingFeatureEnabled) {}

TEST_P(PDFiumEngineTest, IncrementalLoadingFeatureDisabled) {}

TEST_P(PDFiumEngineTest, RequestThumbnail) {}

TEST_P(PDFiumEngineTest, RequestThumbnailLinearized) {}

TEST_P(PDFiumEngineTest, HandleInputEventKeyDown) {}

TEST_P(PDFiumEngineTest, HandleInputEventRawKeyDown) {}

namespace {
#if BUILDFLAG(IS_WIN)
constexpr char kSelectTextExpectedText[] =
    "Hello, world!\r\nGoodbye, world!\r\nHello, world!\r\nGoodbye, world!";
#else
constexpr char kSelectTextExpectedText[] =;
#endif
}  // namespace

TEST_P(PDFiumEngineTest, SelectText) {}

TEST_P(PDFiumEngineTest, SelectTextBackwards) {}

TEST_P(PDFiumEngineTest, SelectTextWithCopyRestriction) {}

TEST_P(PDFiumEngineTest, SelectCroppedText) {}

TEST_P(PDFiumEngineTest, SelectTextWithDoubleClick) {}

TEST_P(PDFiumEngineTest, SelectTextWithTripleClick) {}

TEST_P(PDFiumEngineTest, SelectTextWithMouse) {}

#if BUILDFLAG(IS_MAC)
TEST_P(PDFiumEngineTest, CtrlLeftClickShouldNotSelectTextOnMac) {
  NiceMock<MockTestClient> client;
  std::unique_ptr<PDFiumEngine> engine =
      InitializeEngine(&client, FILE_PATH_LITERAL("hello_world2.pdf"));
  ASSERT_TRUE(engine);

  // Plugin size chosen so all pages of the document are visible.
  engine->PluginSizeUpdated({1024, 4096});

  EXPECT_THAT(engine->GetSelectedText(), IsEmpty());

  // In https://crbug.com/339681892, these are the events PDFiumEngine sees.
  constexpr gfx::PointF kStartPosition(50, 110);
  MouseEventBuilder builder;
  builder.CreateLeftClickAtPosition(kStartPosition)
      .SetModifiers(blink::WebInputEvent::Modifiers::kControlKey);
  EXPECT_FALSE(engine->HandleInputEvent(builder.Build()));

  constexpr gfx::PointF kEndPosition(100, 110);
  EXPECT_FALSE(engine->HandleInputEvent(
      CreateMoveWebMouseEventToPosition(kEndPosition)));

  EXPECT_EQ("", engine->GetSelectedText());
}
#else
TEST_P(PDFiumEngineTest, CtrlLeftClickSelectTextOnNonMac) {}
#endif  // BUILDFLAG(IS_MAC)

TEST_P(PDFiumEngineTest, SelectLinkAreaWithNoText) {}

TEST_P(PDFiumEngineTest, LinkNavigates) {}

// Test case for crbug.com/699000
TEST_P(PDFiumEngineTest, LinkDisabledInPrintPreview) {}

TEST_P(PDFiumEngineTest, SelectTextWithNonPrintableCharacter) {}

TEST_P(PDFiumEngineTest, RotateAfterSelectedText) {}

TEST_P(PDFiumEngineTest, MultiPagesPdfInTwoUpViewAfterSelectedText) {}

INSTANTIATE_TEST_SUITE_P();

PDFiumEngineDeathTest;

TEST_P(PDFiumEngineDeathTest, RequestThumbnailRedundant) {}

INSTANTIATE_TEST_SUITE_P();

class PDFiumEngineTabbingTest : public PDFiumTestBase {};

TEST_P(PDFiumEngineTabbingTest, LinkUnderCursor) {}

// Test case for crbug.com/1088296
TEST_P(PDFiumEngineTabbingTest, LinkUnderCursorAfterTabAndRightClick) {}

TEST_P(PDFiumEngineTabbingTest, TabbingSupportedAnnots) {}

TEST_P(PDFiumEngineTabbingTest, TabbingForward) {}

TEST_P(PDFiumEngineTabbingTest, TabbingBackward) {}

TEST_P(PDFiumEngineTabbingTest, TabbingWithModifiers) {}

TEST_P(PDFiumEngineTabbingTest, NoFocusableElementTabbing) {}

TEST_P(PDFiumEngineTabbingTest, RestoringDocumentFocus) {}

TEST_P(PDFiumEngineTabbingTest, RestoringAnnotFocus) {}

TEST_P(PDFiumEngineTabbingTest, VerifyFormFieldStatesOnTabbing) {}

TEST_P(PDFiumEngineTabbingTest, ClearSelectionOnFocusInFormTextArea) {}

TEST_P(PDFiumEngineTabbingTest, RetainSelectionOnFocusNotInFormTextArea) {}

class ScrollingTestClient : public TestClient {};

TEST_P(PDFiumEngineTabbingTest, MaintainViewportWhenFocusIsUpdated) {}

TEST_P(PDFiumEngineTabbingTest, ScrollFocusedAnnotationIntoView) {}

INSTANTIATE_TEST_SUITE_P();

class ReadOnlyTestClient : public TestClient {};

PDFiumEngineReadOnlyTest;

TEST_P(PDFiumEngineReadOnlyTest, KillFormFocus) {}

TEST_P(PDFiumEngineReadOnlyTest, UnselectText) {}

INSTANTIATE_TEST_SUITE_P();

}  // namespace chrome_pdf