Lei Zhang | 9ef6882 | 2024-05-11 00:47:56 | [diff] [blame] | 1 | // Copyright 2024 The Chromium Authors |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include"pdf/input_utils.h" |
| 6 | |
| 7 | #include"build/build_config.h" |
| 8 | #include"pdf/test/mouse_event_builder.h" |
| 9 | #include"testing/gtest/include/gtest/gtest.h" |
| 10 | #include"third_party/blink/public/common/input/web_input_event.h" |
| 11 | #include"third_party/blink/public/common/input/web_mouse_event.h" |
| 12 | #include"third_party/blink/public/common/input/web_pointer_properties.h" |
| 13 | |
| 14 | namespace chrome_pdf{ |
| 15 | |
| 16 | namespace{ |
| 17 | |
| 18 | voidCheckNormalizeMouseEventIsNoOp(const blink::WebMouseEvent& event){ |
| 19 | blink::WebMouseEvent normalized_event=NormalizeMouseEvent(event); |
| 20 | EXPECT_EQ(event.button, normalized_event.button); |
| 21 | EXPECT_EQ(event.GetModifiers(), normalized_event.GetModifiers()); |
| 22 | EXPECT_EQ(event.GetType(), normalized_event.GetType()); |
| 23 | } |
| 24 | |
| 25 | }// namespace |
| 26 | |
| 27 | TEST(InputUtilsTest,NormalizeMouseEventLeftMouseDown){ |
| 28 | CheckNormalizeMouseEventIsNoOp( |
| 29 | MouseEventBuilder() |
| 30 | .SetType(blink::WebInputEvent::Type::kMouseDown) |
| 31 | .SetButton(blink::WebPointerProperties::Button::kLeft) |
| 32 | .Build()); |
| 33 | } |
| 34 | |
| 35 | TEST(InputUtilsTest,NormalizeMouseEventMiddleMouseDown){ |
| 36 | CheckNormalizeMouseEventIsNoOp( |
| 37 | MouseEventBuilder() |
| 38 | .SetType(blink::WebInputEvent::Type::kMouseDown) |
| 39 | .SetButton(blink::WebPointerProperties::Button::kMiddle) |
| 40 | .Build()); |
| 41 | } |
| 42 | |
| 43 | TEST(InputUtilsTest,NormalizeMouseEventRightMouseDown){ |
| 44 | CheckNormalizeMouseEventIsNoOp( |
| 45 | MouseEventBuilder() |
| 46 | .SetType(blink::WebInputEvent::Type::kMouseDown) |
| 47 | .SetButton(blink::WebPointerProperties::Button::kRight) |
| 48 | .Build()); |
| 49 | } |
| 50 | |
| 51 | TEST(InputUtilsTest,NormalizeMouseEventLeftMouseUp){ |
| 52 | CheckNormalizeMouseEventIsNoOp( |
| 53 | MouseEventBuilder() |
| 54 | .SetType(blink::WebInputEvent::Type::kMouseUp) |
| 55 | .SetButton(blink::WebPointerProperties::Button::kLeft) |
| 56 | .Build()); |
| 57 | } |
| 58 | |
| 59 | TEST(InputUtilsTest,NormalizeMouseEventMiddleMouseUp){ |
| 60 | CheckNormalizeMouseEventIsNoOp( |
| 61 | MouseEventBuilder() |
| 62 | .SetType(blink::WebInputEvent::Type::kMouseUp) |
| 63 | .SetButton(blink::WebPointerProperties::Button::kMiddle) |
| 64 | .Build()); |
| 65 | } |
| 66 | |
| 67 | TEST(InputUtilsTest,NormalizeMouseEventRightMouseUp){ |
| 68 | CheckNormalizeMouseEventIsNoOp( |
| 69 | MouseEventBuilder() |
| 70 | .SetType(blink::WebInputEvent::Type::kMouseUp) |
| 71 | .SetButton(blink::WebPointerProperties::Button::kRight) |
| 72 | .Build()); |
| 73 | } |
| 74 | |
| 75 | TEST(InputUtilsTest,NormalizeMouseEventCtrlLeftMouseDown){ |
| 76 | blink::WebMouseEvent event= |
| 77 | MouseEventBuilder() |
| 78 | .SetType(blink::WebInputEvent::Type::kMouseDown) |
| 79 | .SetButton(blink::WebPointerProperties::Button::kLeft) |
| 80 | .SetModifiers(blink::WebInputEvent::Modifiers::kControlKey) |
| 81 | .Build(); |
| 82 | |
| 83 | #if BUILDFLAG(IS_MAC) |
| 84 | blink::WebMouseEvent normalized_event=NormalizeMouseEvent(event); |
| 85 | EXPECT_EQ(blink::WebPointerProperties::Button::kRight, |
| 86 | normalized_event.button); |
| 87 | EXPECT_EQ(blink::WebInputEvent::Modifiers::kRightButtonDown, |
| 88 | normalized_event.GetModifiers()); |
| 89 | EXPECT_EQ(event.GetType(), normalized_event.GetType()); |
| 90 | #else |
| 91 | CheckNormalizeMouseEventIsNoOp(event); |
| 92 | #endif |
| 93 | } |
| 94 | |
| 95 | TEST(InputUtilsTest,NormalizeMouseEventCtrlLefttMouseUp){ |
| 96 | CheckNormalizeMouseEventIsNoOp( |
| 97 | MouseEventBuilder() |
| 98 | .SetType(blink::WebInputEvent::Type::kMouseUp) |
| 99 | .SetButton(blink::WebPointerProperties::Button::kLeft) |
| 100 | .SetModifiers(blink::WebInputEvent::Modifiers::kControlKey) |
| 101 | .Build()); |
| 102 | } |
| 103 | |
| 104 | }// namespace chrome_pdf |