0

[unseasoned-pdf] Add PdfViewPluginBase::HandleInputEvent() test

Adds a minimal unit test for PdfViewPluginBase::HandleInputEvent().

Bug: 1191817
Change-Id: I98c131242d1d0ebce1fb4889d890f7b307ee17a0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3373134
Commit-Queue: K. Moon <kmoon@chromium.org>
Auto-Submit: K. Moon <kmoon@chromium.org>
Reviewed-by: Hui Yingst <nigi@chromium.org>
Commit-Queue: Hui Yingst <nigi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#956572}
This commit is contained in:
K. Moon
2022-01-07 18:04:41 +00:00
committed by Chromium LUCI CQ
parent dfe741e94a
commit 59f3b67233
4 changed files with 34 additions and 27 deletions

@ -567,8 +567,6 @@ void PdfViewPluginBase::SetLinkUnderCursor(
NotifyLinkUnderCursor();
}
// TODO(crbug.com/1191817): Add tests for input events. Unit testing should be
// feasible now that the Pepper dependency is removed for input events.
bool PdfViewPluginBase::HandleInputEvent(const blink::WebInputEvent& event) {
// Ignore user input in read-only mode.
if (engine()->IsReadOnly())

@ -31,7 +31,10 @@
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "third_party/blink/public/common/input/web_input_event.h"
#include "third_party/blink/public/common/input/web_mouse_event.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/size.h"
namespace chrome_pdf {
@ -160,6 +163,7 @@ class FakePdfViewPluginBase : public PdfViewPluginBase {
using PdfViewPluginBase::accessibility_state;
using PdfViewPluginBase::engine;
using PdfViewPluginBase::full_frame;
using PdfViewPluginBase::HandleInputEvent;
using PdfViewPluginBase::HandleMessage;
using PdfViewPluginBase::LoadUrl;
using PdfViewPluginBase::SetZoom;
@ -780,6 +784,25 @@ TEST_F(PdfViewPluginBaseTest, DocumentHasUnsupportedFeatureWithoutFullFrame) {
fake_plugin_.GetNotifiedBrowserAboutUnsupportedFeatureForTesting());
}
TEST_F(PdfViewPluginBaseWithEngineTest, HandleInputEvent) {
auto* engine = static_cast<TestPDFiumEngine*>(fake_plugin_.engine());
EXPECT_CALL(*engine, HandleInputEvent)
.WillRepeatedly([](const blink::WebInputEvent& event) {
const auto& mouse_event =
static_cast<const blink::WebMouseEvent&>(event);
EXPECT_EQ(blink::WebInputEvent::Type::kMouseDown,
mouse_event.GetType());
EXPECT_EQ(gfx::PointF(10.0f, 20.0f), mouse_event.PositionInWidget());
return true;
});
blink::WebMouseEvent mouse_event;
mouse_event.SetType(blink::WebInputEvent::Type::kMouseDown);
mouse_event.SetPositionInWidget(10.0f, 20.0f);
EXPECT_TRUE(fake_plugin_.HandleInputEvent(mouse_event));
}
TEST_F(PdfViewPluginBaseTest, EnteredEditMode) {
EXPECT_CALL(fake_plugin_, SetPluginCanSave(true));
fake_plugin_.EnteredEditMode();

@ -721,28 +721,8 @@ TEST_F(PdfViewWebPluginMouseEventsTest,
class PdfViewWebPluginImeTest : public PdfViewWebPluginTest {
public:
class TestPDFiumEngineForIme : public TestPDFiumEngine {
public:
explicit TestPDFiumEngineForIme(PDFEngine::Client* client)
: TestPDFiumEngine(client) {}
// TestPDFiumEngine:
MOCK_METHOD(bool,
HandleInputEvent,
(const blink::WebInputEvent&),
(override));
};
std::unique_ptr<TestPDFiumEngine> CreateEngine() override {
return std::make_unique<NiceMock<TestPDFiumEngineForIme>>(plugin_.get());
}
TestPDFiumEngineForIme* engine() {
return static_cast<TestPDFiumEngineForIme*>(engine_ptr_);
}
void TestImeSetCompositionForPlugin(const blink::WebString& text) {
EXPECT_CALL(*engine(), HandleInputEvent).Times(0);
EXPECT_CALL(*engine_ptr_, HandleInputEvent).Times(0);
plugin_->ImeSetCompositionForPlugin(text, std::vector<ui::ImeTextSpan>(),
gfx::Range(),
/*selection_start=*/0,
@ -756,12 +736,12 @@ class PdfViewWebPluginImeTest : public PdfViewWebPluginTest {
if (expected_text16.size()) {
for (const auto& c : expected_text16) {
base::StringPiece16 expected_key(&c, 1);
EXPECT_CALL(*engine(),
EXPECT_CALL(*engine_ptr_,
HandleInputEvent(IsExpectedImeKeyEvent(expected_key)))
.WillOnce(Return(true));
}
} else {
EXPECT_CALL(*engine(), HandleInputEvent).Times(0);
EXPECT_CALL(*engine_ptr_, HandleInputEvent).Times(0);
}
plugin_->ImeFinishComposingTextForPlugin(false);
}
@ -772,11 +752,12 @@ class PdfViewWebPluginImeTest : public PdfViewWebPluginTest {
if (expected_text16.size()) {
for (const auto& c : expected_text16) {
base::StringPiece16 event(&c, 1);
EXPECT_CALL(*engine(), HandleInputEvent(IsExpectedImeKeyEvent(event)))
EXPECT_CALL(*engine_ptr_,
HandleInputEvent(IsExpectedImeKeyEvent(event)))
.WillOnce(Return(true));
}
} else {
EXPECT_CALL(*engine(), HandleInputEvent).Times(0);
EXPECT_CALL(*engine_ptr_, HandleInputEvent).Times(0);
}
plugin_->ImeCommitTextForPlugin(text, std::vector<ui::ImeTextSpan>(),
gfx::Range(),

@ -42,6 +42,11 @@ class TestPDFiumEngine : public PDFiumEngine {
MOCK_METHOD(void, ScrolledToXPosition, (int), (override));
MOCK_METHOD(void, ScrolledToYPosition, (int), (override));
MOCK_METHOD(bool,
HandleInputEvent,
(const blink::WebInputEvent&),
(override));
MOCK_METHOD(void, ZoomUpdated, (double), (override));
MOCK_METHOD(gfx::Size,