#include "components/input/mouse_wheel_event_queue.h"
#include <stddef.h>
#include <memory>
#include <utility>
#include "base/location.h"
#include "base/run_loop.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/task_environment.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "components/input/timeout_monitor.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/input/synthetic_web_input_event_builders.h"
#include "third_party/blink/public/common/input/web_input_event.h"
#include "ui/events/base_event_utils.h"
WebGestureEvent;
WebInputEvent;
WebMouseWheelEvent;
namespace input {
namespace {
const float kWheelScrollX = …;
const float kWheelScrollY = …;
const float kWheelScrollGlobalX = …;
const float kWheelScrollGlobalY = …;
#define EXPECT_GESTURE_SCROLL_BEGIN_IMPL(event) …
#define EXPECT_GESTURE_SCROLL_BEGIN(event) …
#define EXPECT_GESTURE_SCROLL_BEGIN_WITH_PHASE(event) …
#define EXPECT_SYNTHETIC_GESTURE_SCROLL_BEGIN(event) …
#define EXPECT_INERTIAL_GESTURE_SCROLL_BEGIN(event) …
#define EXPECT_SYNTHETIC_INERTIAL_GESTURE_SCROLL_BEGIN(event) …
#define EXPECT_GESTURE_SCROLL_UPDATE_IMPL(event) …
#define EXPECT_GESTURE_SCROLL_UPDATE(event) …
#define EXPECT_GESTURE_SCROLL_UPDATE_WITH_PHASE(event) …
#define EXPECT_INERTIAL_GESTURE_SCROLL_UPDATE(event) …
#define EXPECT_GESTURE_SCROLL_END_IMPL(event) …
#define EXPECT_GESTURE_SCROLL_END(event) …
#define EXPECT_GESTURE_SCROLL_END_WITH_PHASE(event) …
#define EXPECT_SYNTHETIC_GESTURE_SCROLL_END(event) …
#define EXPECT_INERTIAL_GESTURE_SCROLL_END(event) …
#if BUILDFLAG(IS_CHROMEOS_ASH)
#define EXPECT_SYNTHETIC_INERTIAL_GESTURE_SCROLL_END …
#endif
#define EXPECT_MOUSE_WHEEL(event) …
}
class MouseWheelEventQueueTest : public testing::Test,
public MouseWheelEventQueueClient { … };
TEST_F(MouseWheelEventQueueTest, Basic) { … }
TEST_F(MouseWheelEventQueueTest, GestureSending) { … }
TEST_F(MouseWheelEventQueueTest, GestureSendingPrecisePixels) { … }
TEST_F(MouseWheelEventQueueTest, GestureSendingWithPhaseInformation) { … }
TEST_F(MouseWheelEventQueueTest,
GestureSendingWithPhaseInformationPrecisePixels) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(MouseWheelEventQueueTest, WheelEndWithMomentumPhaseEndedInformation) {
const ui::ScrollGranularity scroll_units =
ui::ScrollGranularity::kScrollByPrecisePixel;
SendMouseWheel(kWheelScrollX, kWheelScrollY, kWheelScrollGlobalX,
kWheelScrollGlobalY, 1, 1, 0, true ,
WebMouseWheelEvent::kPhaseBegan,
WebMouseWheelEvent::kPhaseNone);
EXPECT_EQ(0U, queued_event_count());
EXPECT_TRUE(event_in_flight());
EXPECT_EQ(1U, GetAndResetSentEventCount());
SendMouseWheelEventAck(blink::mojom::InputEventResultState::kNotConsumed);
EXPECT_GESTURE_SCROLL_BEGIN_WITH_PHASE(sent_gesture_event(0));
EXPECT_GESTURE_SCROLL_UPDATE_WITH_PHASE(sent_gesture_event(1));
EXPECT_EQ(2U, GetAndResetSentEventCount());
SendMouseWheel(kWheelScrollX, kWheelScrollY, kWheelScrollGlobalX,
kWheelScrollGlobalY, 0, 0, 0, true ,
WebMouseWheelEvent::kPhaseNone,
WebMouseWheelEvent::kPhaseEnded, true );
EXPECT_EQ(0U, queued_event_count());
EXPECT_TRUE(event_in_flight());
EXPECT_EQ(1U, GetAndResetSentEventCount());
SendMouseWheelEventAck(blink::mojom::InputEventResultState::kNotConsumed);
EXPECT_EQ(1U, all_sent_events().size());
EXPECT_SYNTHETIC_INERTIAL_GESTURE_SCROLL_END(sent_gesture_event(0));
EXPECT_EQ(1U, GetAndResetSentEventCount());
}
#endif
TEST_F(MouseWheelEventQueueTest, GestureSendingInterrupted) { … }
TEST_F(MouseWheelEventQueueTest, GestureRailScrolling) { … }
TEST_F(MouseWheelEventQueueTest, WheelScrollLatching) { … }
#if BUILDFLAG(IS_MAC)
TEST_F(MouseWheelEventQueueTest, DoNotSwapXYForShiftScroll) {
SendMouseWheel(kWheelScrollX, kWheelScrollY, kWheelScrollGlobalX,
kWheelScrollGlobalY, 0.0, 1.0, WebInputEvent::kShiftKey, false,
WebMouseWheelEvent::kPhaseBegan,
WebMouseWheelEvent::kPhaseNone, WebInputEvent::kRailsModeFree);
EXPECT_EQ(0U, queued_event_count());
EXPECT_TRUE(event_in_flight());
EXPECT_EQ(1U, GetAndResetSentEventCount());
SendMouseWheelEventAck(blink::mojom::InputEventResultState::kNotConsumed);
EXPECT_EQ(0U, queued_event_count());
EXPECT_FALSE(event_in_flight());
EXPECT_EQ(WebInputEvent::Type::kMouseWheel, acked_event().GetType());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
EXPECT_EQ(2U, all_sent_events().size());
EXPECT_EQ(0U, sent_gesture_event(1)->data.scroll_update.delta_x);
EXPECT_EQ(1U, sent_gesture_event(1)->data.scroll_update.delta_y);
EXPECT_EQ(2U, GetAndResetSentEventCount());
}
#endif
}