Move event handling code out of TestPDFiumEngine.
Instead, put the (mouse) event handling code in a class derived from TestPDFiumEngine, and only use the derived engine in tests that care about mouse events. This way, different tests that tests different aspects of event handling do not have to all pile their code into a single TestPDFiumEngine class. Change-Id: I76587204e51ae071f9e9d6a4aff0702e3f90dc79 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3188667 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Hui Yingst <nigi@chromium.org> Cr-Commit-Position: refs/heads/main@{#925855}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
81d7127406
commit
765599cdef
@ -18,6 +18,7 @@
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "third_party/blink/public/common/input/web_coalesced_input_event.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/blink/public/common/input/web_pointer_properties.h"
|
||||
#include "third_party/blink/public/platform/web_string.h"
|
||||
#include "third_party/blink/public/platform/web_text_input_type.h"
|
||||
@ -253,7 +254,7 @@ class PdfViewWebPluginTest : public PdfViewWebPluginWithoutInitializeTest {
|
||||
auto wrapper =
|
||||
std::make_unique<NiceMock<FakeContainerWrapper>>(plugin_.get());
|
||||
wrapper_ptr_ = wrapper.get();
|
||||
auto engine = std::make_unique<TestPDFiumEngine>(plugin_.get());
|
||||
auto engine = CreateEngine();
|
||||
engine_ptr_ = engine.get();
|
||||
EXPECT_TRUE(
|
||||
plugin_->InitializeForTesting(std::move(wrapper), std::move(engine)));
|
||||
@ -265,6 +266,11 @@ class PdfViewWebPluginTest : public PdfViewWebPluginWithoutInitializeTest {
|
||||
PdfViewWebPluginWithoutInitializeTest::TearDown();
|
||||
}
|
||||
|
||||
// Allow derived test classes to create their own custom TestPDFiumEngine.
|
||||
virtual std::unique_ptr<TestPDFiumEngine> CreateEngine() {
|
||||
return std::make_unique<TestPDFiumEngine>(plugin_.get());
|
||||
}
|
||||
|
||||
void UpdatePluginGeometry(float device_scale, const gfx::Rect& window_rect) {
|
||||
// The plugin container's device scale must be set before calling
|
||||
// UpdateGeometry().
|
||||
@ -479,7 +485,45 @@ INSTANTIATE_TEST_SUITE_P(All,
|
||||
PdfViewWebPluginTestUseZoomForDSF,
|
||||
testing::Bool());
|
||||
|
||||
TEST_F(PdfViewWebPluginTest, HandleInputEventWithUseZoomForDSFEnabled) {
|
||||
class PdfViewWebPluginMouseEventsTest : public PdfViewWebPluginTest {
|
||||
public:
|
||||
class TestPDFiumEngineForMouseEvents : public TestPDFiumEngine {
|
||||
public:
|
||||
explicit TestPDFiumEngineForMouseEvents(PDFEngine::Client* client)
|
||||
: TestPDFiumEngine(client) {}
|
||||
|
||||
// TestPDFiumEngine:
|
||||
bool HandleInputEvent(const blink::WebInputEvent& event) override {
|
||||
// Since blink::WebInputEvent is an abstract class, we cannot use equal
|
||||
// matcher to verify its value. Here we test with blink::WebMouseEvent
|
||||
// specifically.
|
||||
if (!blink::WebInputEvent::IsMouseEventType(event.GetType()))
|
||||
return false;
|
||||
|
||||
scaled_mouse_event_ = std::make_unique<blink::WebMouseEvent>();
|
||||
*scaled_mouse_event_ = static_cast<const blink::WebMouseEvent&>(event);
|
||||
return true;
|
||||
}
|
||||
|
||||
const blink::WebMouseEvent* GetScaledMouseEvent() const {
|
||||
return scaled_mouse_event_.get();
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<blink::WebMouseEvent> scaled_mouse_event_;
|
||||
};
|
||||
|
||||
std::unique_ptr<TestPDFiumEngine> CreateEngine() override {
|
||||
return std::make_unique<TestPDFiumEngineForMouseEvents>(plugin_.get());
|
||||
}
|
||||
|
||||
TestPDFiumEngineForMouseEvents* engine() {
|
||||
return static_cast<TestPDFiumEngineForMouseEvents*>(engine_ptr_);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(PdfViewWebPluginMouseEventsTest,
|
||||
HandleInputEventWithUseZoomForDSFEnabled) {
|
||||
// Test when using zoom for DSF is enabled.
|
||||
EXPECT_CALL(*client_ptr_, IsUseZoomForDSFEnabled)
|
||||
.WillRepeatedly(Return(true));
|
||||
@ -492,12 +536,13 @@ TEST_F(PdfViewWebPluginTest, HandleInputEventWithUseZoomForDSFEnabled) {
|
||||
ui::LatencyInfo()),
|
||||
&dummy_cursor);
|
||||
|
||||
ASSERT_TRUE(engine_ptr_->GetScaledMouseEvent());
|
||||
EXPECT_EQ(gfx::PointF(-10.0f, 0.0f),
|
||||
engine_ptr_->GetScaledMouseEvent()->PositionInWidget());
|
||||
const blink::WebMouseEvent* event = engine()->GetScaledMouseEvent();
|
||||
ASSERT_TRUE(event);
|
||||
EXPECT_EQ(gfx::PointF(-10.0f, 0.0f), event->PositionInWidget());
|
||||
}
|
||||
|
||||
TEST_F(PdfViewWebPluginTest, HandleInputEventWithUseZoomForDSFDisabled) {
|
||||
TEST_F(PdfViewWebPluginMouseEventsTest,
|
||||
HandleInputEventWithUseZoomForDSFDisabled) {
|
||||
// Test when using zoom for DSF is disabled.
|
||||
EXPECT_CALL(*client_ptr_, IsUseZoomForDSFEnabled)
|
||||
.WillRepeatedly(Return(false));
|
||||
@ -510,9 +555,9 @@ TEST_F(PdfViewWebPluginTest, HandleInputEventWithUseZoomForDSFDisabled) {
|
||||
ui::LatencyInfo()),
|
||||
&dummy_cursor);
|
||||
|
||||
ASSERT_TRUE(engine_ptr_->GetScaledMouseEvent());
|
||||
EXPECT_EQ(gfx::PointF(-20.0f, 0.0f),
|
||||
engine_ptr_->GetScaledMouseEvent()->PositionInWidget());
|
||||
const blink::WebMouseEvent* event = engine()->GetScaledMouseEvent();
|
||||
ASSERT_TRUE(event);
|
||||
EXPECT_EQ(gfx::PointF(-20.0f, 0.0f), event->PositionInWidget());
|
||||
}
|
||||
|
||||
TEST_F(PdfViewWebPluginTest, ChangeTextSelection) {
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <memory>
|
||||
#include <iterator>
|
||||
#include <vector>
|
||||
|
||||
#include "base/check_op.h"
|
||||
@ -18,8 +18,6 @@
|
||||
#include "pdf/pdf_engine.h"
|
||||
#include "pdf/pdfium/pdfium_engine.h"
|
||||
#include "pdf/pdfium/pdfium_form_filler.h"
|
||||
#include "third_party/blink/public/common/input/web_input_event.h"
|
||||
#include "third_party/blink/public/common/input/web_mouse_event.h"
|
||||
|
||||
namespace chrome_pdf {
|
||||
|
||||
@ -34,18 +32,6 @@ TestPDFiumEngine::TestPDFiumEngine(PDFEngine::Client* client)
|
||||
|
||||
TestPDFiumEngine::~TestPDFiumEngine() = default;
|
||||
|
||||
bool TestPDFiumEngine::HandleInputEvent(const blink::WebInputEvent& event) {
|
||||
// Since blink::WebInputEvent is an abstract class, we cannot use equal
|
||||
// matcher to verify its value. Here we test with blink::WebMouseEvent
|
||||
// specifically.
|
||||
if (!blink::WebInputEvent::IsMouseEventType(event.GetType()))
|
||||
return false;
|
||||
|
||||
scaled_mouse_event_ = std::make_unique<blink::WebMouseEvent>();
|
||||
*scaled_mouse_event_ = static_cast<const blink::WebMouseEvent&>(event);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TestPDFiumEngine::HasPermission(DocumentPermission permission) const {
|
||||
return base::Contains(permissions_, permission);
|
||||
}
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "base/containers/flat_set.h"
|
||||
@ -17,11 +16,6 @@
|
||||
#include "pdf/pdf_engine.h"
|
||||
#include "pdf/pdfium/pdfium_engine.h"
|
||||
#include "testing/gmock/include/gmock/gmock.h"
|
||||
#include "third_party/blink/public/common/input/web_mouse_event.h"
|
||||
|
||||
namespace blink {
|
||||
class WebInputEvent;
|
||||
} // namespace blink
|
||||
|
||||
namespace chrome_pdf {
|
||||
|
||||
@ -48,9 +42,6 @@ class TestPDFiumEngine : public PDFiumEngine {
|
||||
(const DocumentLayout::Options&),
|
||||
(override));
|
||||
|
||||
// Sets a scaled mouse event for testing.
|
||||
bool HandleInputEvent(const blink::WebInputEvent& event) override;
|
||||
|
||||
bool HasPermission(DocumentPermission permission) const override;
|
||||
|
||||
const std::vector<DocumentAttachmentInfo>& GetDocumentAttachmentInfoList()
|
||||
@ -69,10 +60,6 @@ class TestPDFiumEngine : public PDFiumEngine {
|
||||
|
||||
std::vector<uint8_t> GetSaveData() override;
|
||||
|
||||
const blink::WebMouseEvent* GetScaledMouseEvent() const {
|
||||
return scaled_mouse_event_.get();
|
||||
}
|
||||
|
||||
void SetPermissions(const std::vector<DocumentPermission>& permissions);
|
||||
|
||||
protected:
|
||||
@ -87,8 +74,6 @@ class TestPDFiumEngine : public PDFiumEngine {
|
||||
|
||||
DocumentMetadata metadata_;
|
||||
|
||||
std::unique_ptr<blink::WebMouseEvent> scaled_mouse_event_;
|
||||
|
||||
base::flat_set<DocumentPermission> permissions_;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user