chromium/components/input/mouse_wheel_event_queue_unittest.cc

// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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)

}  // namespace

class MouseWheelEventQueueTest : public testing::Test,
                                 public MouseWheelEventQueueClient {};

// Tests that mouse wheel events are queued properly.
TEST_F(MouseWheelEventQueueTest, Basic) {}

TEST_F(MouseWheelEventQueueTest, GestureSending) {}

TEST_F(MouseWheelEventQueueTest, GestureSendingPrecisePixels) {}

TEST_F(MouseWheelEventQueueTest, GestureSendingWithPhaseInformation) {}

TEST_F(MouseWheelEventQueueTest,
       GestureSendingWithPhaseInformationPrecisePixels) {}

// Tests that a Wheel event with synthetic momentumn_phase == PhaseEnded that is
// generated by the fling controller properly populates
// scroll_end.data.scroll_end.generated_by_fling_controller.
#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 /* high_precision */,
                 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 /* high_precision */,
                 WebMouseWheelEvent::kPhaseNone,
                 WebMouseWheelEvent::kPhaseEnded, true /*has_synthetic_phase*/);
  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  // BUILDFLAG(IS_CHROMEOS_ASH)

TEST_F(MouseWheelEventQueueTest, GestureSendingInterrupted) {}

TEST_F(MouseWheelEventQueueTest, GestureRailScrolling) {}

TEST_F(MouseWheelEventQueueTest, WheelScrollLatching) {}

#if BUILDFLAG(IS_MAC)
TEST_F(MouseWheelEventQueueTest, DoNotSwapXYForShiftScroll) {
  // Send an event with shift modifier, zero value for delta X, and no direction
  // for |rails_mode|. Do not swap the scroll direction.
  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());

  // Receive an ACK for the mouse wheel event.
  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
}  // namespace input