Add unit tests for chrome_pdf::NormalizeMouseEvent()
Add tests to make sure the function works as intended. Update MouseEventBuilder::Build() to handle middle click events to support the new test cases. Change-Id: I24f108dd407be111b6228fa89d0b7e41bf70a046 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5528796 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Andy Phan <andyphan@chromium.org> Cr-Commit-Position: refs/heads/main@{#1299639}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
7c68a71865
commit
9ef6882af4
@ -350,6 +350,7 @@ if (enable_pdf) {
|
||||
sources = [
|
||||
"document_layout_unittest.cc",
|
||||
"draw_utils/coordinates_unittest.cc",
|
||||
"input_utils_unittest.cc",
|
||||
"page_orientation_unittest.cc",
|
||||
"paint_manager_unittest.cc",
|
||||
"parsed_params_unittest.cc",
|
||||
|
104
pdf/input_utils_unittest.cc
Normal file
104
pdf/input_utils_unittest.cc
Normal file
@ -0,0 +1,104 @@
|
||||
// Copyright 2024 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "pdf/input_utils.h"
|
||||
|
||||
#include "build/build_config.h"
|
||||
#include "pdf/test/mouse_event_builder.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_mouse_event.h"
|
||||
#include "third_party/blink/public/common/input/web_pointer_properties.h"
|
||||
|
||||
namespace chrome_pdf {
|
||||
|
||||
namespace {
|
||||
|
||||
void CheckNormalizeMouseEventIsNoOp(const blink::WebMouseEvent& event) {
|
||||
blink::WebMouseEvent normalized_event = NormalizeMouseEvent(event);
|
||||
EXPECT_EQ(event.button, normalized_event.button);
|
||||
EXPECT_EQ(event.GetModifiers(), normalized_event.GetModifiers());
|
||||
EXPECT_EQ(event.GetType(), normalized_event.GetType());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(InputUtilsTest, NormalizeMouseEventLeftMouseDown) {
|
||||
CheckNormalizeMouseEventIsNoOp(
|
||||
MouseEventBuilder()
|
||||
.SetType(blink::WebInputEvent::Type::kMouseDown)
|
||||
.SetButton(blink::WebPointerProperties::Button::kLeft)
|
||||
.Build());
|
||||
}
|
||||
|
||||
TEST(InputUtilsTest, NormalizeMouseEventMiddleMouseDown) {
|
||||
CheckNormalizeMouseEventIsNoOp(
|
||||
MouseEventBuilder()
|
||||
.SetType(blink::WebInputEvent::Type::kMouseDown)
|
||||
.SetButton(blink::WebPointerProperties::Button::kMiddle)
|
||||
.Build());
|
||||
}
|
||||
|
||||
TEST(InputUtilsTest, NormalizeMouseEventRightMouseDown) {
|
||||
CheckNormalizeMouseEventIsNoOp(
|
||||
MouseEventBuilder()
|
||||
.SetType(blink::WebInputEvent::Type::kMouseDown)
|
||||
.SetButton(blink::WebPointerProperties::Button::kRight)
|
||||
.Build());
|
||||
}
|
||||
|
||||
TEST(InputUtilsTest, NormalizeMouseEventLeftMouseUp) {
|
||||
CheckNormalizeMouseEventIsNoOp(
|
||||
MouseEventBuilder()
|
||||
.SetType(blink::WebInputEvent::Type::kMouseUp)
|
||||
.SetButton(blink::WebPointerProperties::Button::kLeft)
|
||||
.Build());
|
||||
}
|
||||
|
||||
TEST(InputUtilsTest, NormalizeMouseEventMiddleMouseUp) {
|
||||
CheckNormalizeMouseEventIsNoOp(
|
||||
MouseEventBuilder()
|
||||
.SetType(blink::WebInputEvent::Type::kMouseUp)
|
||||
.SetButton(blink::WebPointerProperties::Button::kMiddle)
|
||||
.Build());
|
||||
}
|
||||
|
||||
TEST(InputUtilsTest, NormalizeMouseEventRightMouseUp) {
|
||||
CheckNormalizeMouseEventIsNoOp(
|
||||
MouseEventBuilder()
|
||||
.SetType(blink::WebInputEvent::Type::kMouseUp)
|
||||
.SetButton(blink::WebPointerProperties::Button::kRight)
|
||||
.Build());
|
||||
}
|
||||
|
||||
TEST(InputUtilsTest, NormalizeMouseEventCtrlLeftMouseDown) {
|
||||
blink::WebMouseEvent event =
|
||||
MouseEventBuilder()
|
||||
.SetType(blink::WebInputEvent::Type::kMouseDown)
|
||||
.SetButton(blink::WebPointerProperties::Button::kLeft)
|
||||
.SetModifiers(blink::WebInputEvent::Modifiers::kControlKey)
|
||||
.Build();
|
||||
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
blink::WebMouseEvent normalized_event = NormalizeMouseEvent(event);
|
||||
EXPECT_EQ(blink::WebPointerProperties::Button::kRight,
|
||||
normalized_event.button);
|
||||
EXPECT_EQ(blink::WebInputEvent::Modifiers::kRightButtonDown,
|
||||
normalized_event.GetModifiers());
|
||||
EXPECT_EQ(event.GetType(), normalized_event.GetType());
|
||||
#else
|
||||
CheckNormalizeMouseEventIsNoOp(event);
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(InputUtilsTest, NormalizeMouseEventCtrlLefttMouseUp) {
|
||||
CheckNormalizeMouseEventIsNoOp(
|
||||
MouseEventBuilder()
|
||||
.SetType(blink::WebInputEvent::Type::kMouseUp)
|
||||
.SetButton(blink::WebPointerProperties::Button::kLeft)
|
||||
.SetModifiers(blink::WebInputEvent::Modifiers::kControlKey)
|
||||
.Build());
|
||||
}
|
||||
|
||||
} // namespace chrome_pdf
|
@ -25,6 +25,9 @@ blink::WebMouseEvent MouseEventBuilder::Build() const {
|
||||
case blink::WebPointerProperties::Button::kLeft:
|
||||
actual_modifiers |= blink::WebInputEvent::Modifiers::kLeftButtonDown;
|
||||
break;
|
||||
case blink::WebPointerProperties::Button::kMiddle:
|
||||
actual_modifiers |= blink::WebInputEvent::Modifiers::kMiddleButtonDown;
|
||||
break;
|
||||
case blink::WebPointerProperties::Button::kRight:
|
||||
actual_modifiers |= blink::WebInputEvent::Modifiers::kRightButtonDown;
|
||||
break;
|
||||
|
Reference in New Issue
Block a user