1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
pdf / input_utils_unittest.cc [blame]
// 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