Skip to content

Commit

Permalink
[pdf] Migrate SelectionChanged() tests
Browse files Browse the repository at this point in the history
Migrates tests exercising PdfViewPluginBase's SelectionChanged() method.

Bug: 1323307
Change-Id: Idb07492c76e2063a8203968680ed7839e7f5a426
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3696190
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: K. Moon <kmoon@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1012749}
  • Loading branch information
kmoon-work authored and Chromium LUCI CQ committed Jun 9, 2022
1 parent 99e49bb commit 6ec3253
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 62 deletions.
62 changes: 0 additions & 62 deletions pdf/pdf_view_plugin_base_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "base/memory/weak_ptr.h"
#include "base/test/values_test_util.h"
#include "base/values.h"
#include "pdf/accessibility_structs.h"
#include "pdf/pdf_engine.h"
#include "pdf/ppapi_migration/url_loader.h"
#include "pdf/test/test_pdfium_engine.h"
Expand All @@ -31,7 +30,6 @@ namespace {

using ::testing::NiceMock;
using ::testing::Return;
using ::testing::SaveArg;

// TODO(crbug.com/1302059): Overhaul this when PdfViewPluginBase merges with
// PdfViewWebPlugin.
Expand Down Expand Up @@ -236,64 +234,4 @@ TEST_F(PdfViewPluginBaseWithEngineTest, SetCaretPositionScaled) {
fake_plugin_.SetCaretPosition({4.0f, 3.0f});
}

TEST_F(PdfViewPluginBaseWithEngineTest, SelectionChanged) {
auto* engine = static_cast<TestPDFiumEngine*>(fake_plugin_.engine());
fake_plugin_.EnableAccessibility();
fake_plugin_.DocumentLoadComplete();
fake_plugin_.UpdateGeometryOnPluginRectChanged({300, 56, 20, 5}, 1.0f);
EXPECT_CALL(*engine, ApplyDocumentLayout)
.WillRepeatedly(Return(gfx::Size(16, 9)));
SendDefaultViewportMessage();

AccessibilityViewportInfo viewport_info;
EXPECT_CALL(fake_plugin_,
NotifySelectionChanged(gfx::PointF(-8.0f, -20.0f), 40,
gfx::PointF(52.0f, 60.0f), 80));
EXPECT_CALL(fake_plugin_, SetAccessibilityViewportInfo)
.WillOnce(SaveArg<0>(&viewport_info));
fake_plugin_.SelectionChanged({-10, -20, 30, 40}, {50, 60, 70, 80});

EXPECT_EQ(gfx::Point(), viewport_info.scroll);
}

TEST_F(PdfViewPluginBaseWithEngineTest, SelectionChangedNegativeOrigin) {
auto* engine = static_cast<TestPDFiumEngine*>(fake_plugin_.engine());
fake_plugin_.EnableAccessibility();
fake_plugin_.DocumentLoadComplete();
fake_plugin_.UpdateGeometryOnPluginRectChanged({-300, -56, 20, 5}, 1.0f);
EXPECT_CALL(*engine, ApplyDocumentLayout)
.WillRepeatedly(Return(gfx::Size(16, 9)));
SendDefaultViewportMessage();

AccessibilityViewportInfo viewport_info;
EXPECT_CALL(fake_plugin_,
NotifySelectionChanged(gfx::PointF(-8.0f, -20.0f), 40,
gfx::PointF(52.0f, 60.0f), 80));
EXPECT_CALL(fake_plugin_, SetAccessibilityViewportInfo)
.WillOnce(SaveArg<0>(&viewport_info));
fake_plugin_.SelectionChanged({-10, -20, 30, 40}, {50, 60, 70, 80});

EXPECT_EQ(gfx::Point(), viewport_info.scroll);
}

TEST_F(PdfViewPluginBaseWithEngineTest, SelectionChangedScaled) {
auto* engine = static_cast<TestPDFiumEngine*>(fake_plugin_.engine());
fake_plugin_.EnableAccessibility();
fake_plugin_.DocumentLoadComplete();
fake_plugin_.UpdateGeometryOnPluginRectChanged({600, 112, 40, 10}, 2.0f);
EXPECT_CALL(*engine, ApplyDocumentLayout)
.WillRepeatedly(Return(gfx::Size(16, 9)));
SendDefaultViewportMessage();

AccessibilityViewportInfo viewport_info;
EXPECT_CALL(fake_plugin_,
NotifySelectionChanged(gfx::PointF(-8.0f, -20.0f), 40,
gfx::PointF(52.0f, 60.0f), 80));
EXPECT_CALL(fake_plugin_, SetAccessibilityViewportInfo)
.WillOnce(SaveArg<0>(&viewport_info));
fake_plugin_.SelectionChanged({-20, -40, 60, 80}, {100, 120, 140, 160});

EXPECT_EQ(gfx::Point(), viewport_info.scroll);
}

} // namespace chrome_pdf
52 changes: 52 additions & 0 deletions pdf/pdf_view_web_plugin_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ using ::testing::MockFunction;
using ::testing::NiceMock;
using ::testing::Pointwise;
using ::testing::Return;
using ::testing::SaveArg;
using ::testing::SizeIs;

// `kCanvasSize` needs to be big enough to hold plugin's snapshots during
Expand Down Expand Up @@ -1481,6 +1482,57 @@ TEST_F(PdfViewWebPluginImeTest, ImeCommitTextForPluginEmpty) {
TestImeCommitTextForPlugin(text);
}

TEST_F(PdfViewWebPluginTest, SelectionChanged) {
plugin_->EnableAccessibility();
plugin_->DocumentLoadComplete();
UpdatePluginGeometryWithoutWaiting(1.0f, {300, 56, 20, 5});
SetDocumentDimensions({16, 9});

AccessibilityViewportInfo viewport_info;
EXPECT_CALL(pdf_service_, SelectionChanged(gfx::PointF(-8.0f, -20.0f), 40,
gfx::PointF(52.0f, 60.0f), 80));
EXPECT_CALL(*accessibility_data_handler_ptr_, SetAccessibilityViewportInfo)
.WillOnce(SaveArg<0>(&viewport_info));
plugin_->SelectionChanged({-10, -20, 30, 40}, {50, 60, 70, 80});

EXPECT_EQ(gfx::Point(), viewport_info.scroll);
pdf_receiver_.FlushForTesting();
}

TEST_F(PdfViewWebPluginTest, SelectionChangedNegativeOrigin) {
plugin_->EnableAccessibility();
plugin_->DocumentLoadComplete();
UpdatePluginGeometryWithoutWaiting(1.0f, {-300, -56, 20, 5});
SetDocumentDimensions({16, 9});

AccessibilityViewportInfo viewport_info;
EXPECT_CALL(pdf_service_, SelectionChanged(gfx::PointF(-8.0f, -20.0f), 40,
gfx::PointF(52.0f, 60.0f), 80));
EXPECT_CALL(*accessibility_data_handler_ptr_, SetAccessibilityViewportInfo)
.WillOnce(SaveArg<0>(&viewport_info));
plugin_->SelectionChanged({-10, -20, 30, 40}, {50, 60, 70, 80});

EXPECT_EQ(gfx::Point(), viewport_info.scroll);
pdf_receiver_.FlushForTesting();
}

TEST_F(PdfViewWebPluginTest, SelectionChangedScaled) {
plugin_->EnableAccessibility();
plugin_->DocumentLoadComplete();
UpdatePluginGeometryWithoutWaiting(2.0f, {600, 112, 40, 10});
SetDocumentDimensions({16, 9});

AccessibilityViewportInfo viewport_info;
EXPECT_CALL(pdf_service_, SelectionChanged(gfx::PointF(-8.0f, -20.0f), 40,
gfx::PointF(52.0f, 60.0f), 80));
EXPECT_CALL(*accessibility_data_handler_ptr_, SetAccessibilityViewportInfo)
.WillOnce(SaveArg<0>(&viewport_info));
plugin_->SelectionChanged({-20, -40, 60, 80}, {100, 120, 140, 160});

EXPECT_EQ(gfx::Point(), viewport_info.scroll);
pdf_receiver_.FlushForTesting();
}

TEST_F(PdfViewWebPluginTest, ChangeTextSelection) {
ASSERT_FALSE(plugin_->HasSelection());
ASSERT_TRUE(plugin_->SelectionAsText().IsEmpty());
Expand Down

0 comments on commit 6ec3253

Please sign in to comment.