This source file includes following definitions.
- sent_gesture_event_count_
- SetUp
- TearDown
- SendGestureEventImmediately
- OnGestureEventAck
- SendMouseEventImmediately
- SimulateGestureEvent
- SimulateGestureEvent
- SimulateGestureScrollUpdateEvent
- SimulateGesturePinchUpdateEvent
- SimulateGestureFlingStartEvent
- SendInputEventACK
- RunUntilIdle
- GetAndResetSentGestureEventCount
- GetAndResetAckedGestureEventCount
- last_acked_event
- DisableDebounce
- set_debounce_interval_time_ms
- set_synchronous_ack
- set_sync_followup_event
- GestureEventQueueSize
- GestureEventSecondFromLastQueueEvent
- GestureEventLastQueueEvent
- GestureEventDebouncingQueueSize
- GestureEventQueueEventAt
- ScrollingInProgress
- FlingInProgress
- WillIgnoreNextACK
- queue
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_P
- TEST_F
- TEST_F
- TEST_F
#include <vector>
#include "base/basictypes.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/time/time.h"
#include "content/browser/renderer_host/input/gesture_event_queue.h"
#include "content/browser/renderer_host/input/touchpad_tap_suppression_controller.h"
#include "content/common/input/synthetic_web_input_event_builders.h"
#include "content/port/common/input_event_ack_state.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/public/web/WebInputEvent.h"
using base::TimeDelta;
using blink::WebGestureEvent;
using blink::WebInputEvent;
namespace content {
class GestureEventQueueTest : public testing::Test,
public GestureEventQueueClient,
public TouchpadTapSuppressionControllerClient {
public:
GestureEventQueueTest()
: acked_gesture_event_count_(0),
sent_gesture_event_count_(0) {}
virtual ~GestureEventQueueTest() {}
virtual void SetUp() OVERRIDE {
queue_.reset(new GestureEventQueue(this, this));
}
virtual void TearDown() OVERRIDE {
RunUntilIdle();
queue_.reset();
}
virtual void SendGestureEventImmediately(
const GestureEventWithLatencyInfo& event) OVERRIDE {
++sent_gesture_event_count_;
if (sync_ack_result_) {
scoped_ptr<InputEventAckState> ack_result = sync_ack_result_.Pass();
SendInputEventACK(event.event.type, *ack_result);
}
}
virtual void OnGestureEventAck(
const GestureEventWithLatencyInfo& event,
InputEventAckState ack_result) OVERRIDE {
++acked_gesture_event_count_;
last_acked_event_ = event.event;
if (sync_followup_event_)
SimulateGestureEvent(*sync_followup_event_.Pass());
}
virtual void SendMouseEventImmediately(
const MouseEventWithLatencyInfo& event) OVERRIDE {
}
protected:
bool SimulateGestureEvent(const WebGestureEvent& gesture) {
GestureEventWithLatencyInfo gesture_with_latency(gesture,
ui::LatencyInfo());
if (queue()->ShouldForward(gesture_with_latency)) {
SendGestureEventImmediately(gesture_with_latency);
return true;
}
return false;
}
void SimulateGestureEvent(WebInputEvent::Type type,
WebGestureEvent::SourceDevice sourceDevice) {
SimulateGestureEvent(
SyntheticWebGestureEventBuilder::Build(type, sourceDevice));
}
void SimulateGestureScrollUpdateEvent(float dX, float dY, int modifiers) {
SimulateGestureEvent(
SyntheticWebGestureEventBuilder::BuildScrollUpdate(dX, dY, modifiers));
}
void SimulateGesturePinchUpdateEvent(float scale,
float anchorX,
float anchorY,
int modifiers) {
SimulateGestureEvent(
SyntheticWebGestureEventBuilder::BuildPinchUpdate(scale,
anchorX,
anchorY,
modifiers));
}
void SimulateGestureFlingStartEvent(
float velocityX,
float velocityY,
WebGestureEvent::SourceDevice sourceDevice) {
SimulateGestureEvent(
SyntheticWebGestureEventBuilder::BuildFling(velocityX,
velocityY,
sourceDevice));
}
void SendInputEventACK(WebInputEvent::Type type,
InputEventAckState ack) {
queue()->ProcessGestureAck(ack, type, ui::LatencyInfo());
}
void RunUntilIdle() {
base::MessageLoop::current()->RunUntilIdle();
}
size_t GetAndResetSentGestureEventCount() {
size_t count = sent_gesture_event_count_;
sent_gesture_event_count_ = 0;
return count;
}
size_t GetAndResetAckedGestureEventCount() {
size_t count = acked_gesture_event_count_;
acked_gesture_event_count_ = 0;
return count;
}
const WebGestureEvent& last_acked_event() const {
return last_acked_event_;
}
void DisableDebounce() {
queue()->set_debounce_enabled_for_testing(false);
}
void set_debounce_interval_time_ms(int ms) {
queue()->set_debounce_interval_time_ms_for_testing(ms);
}
void set_synchronous_ack(InputEventAckState ack_result) {
sync_ack_result_.reset(new InputEventAckState(ack_result));
}
void set_sync_followup_event(WebInputEvent::Type type,
WebGestureEvent::SourceDevice sourceDevice) {
sync_followup_event_.reset(new WebGestureEvent(
SyntheticWebGestureEventBuilder::Build(type, sourceDevice)));
}
unsigned GestureEventQueueSize() {
return queue()->coalesced_gesture_events_.size();
}
WebGestureEvent GestureEventSecondFromLastQueueEvent() {
return queue()->coalesced_gesture_events_.at(
GestureEventQueueSize() - 2).event;
}
WebGestureEvent GestureEventLastQueueEvent() {
return queue()->coalesced_gesture_events_.back().event;
}
unsigned GestureEventDebouncingQueueSize() {
return queue()->debouncing_deferral_queue_.size();
}
WebGestureEvent GestureEventQueueEventAt(int i) {
return queue()->coalesced_gesture_events_.at(i).event;
}
bool ScrollingInProgress() {
return queue()->scrolling_in_progress_;
}
bool FlingInProgress() {
return queue()->fling_in_progress_;
}
bool WillIgnoreNextACK() {
return queue()->ignore_next_ack_;
}
GestureEventQueue* queue() const {
return queue_.get();
}
private:
scoped_ptr<GestureEventQueue> queue_;
size_t acked_gesture_event_count_;
size_t sent_gesture_event_count_;
WebGestureEvent last_acked_event_;
scoped_ptr<InputEventAckState> sync_ack_result_;
scoped_ptr<WebGestureEvent> sync_followup_event_;
base::MessageLoopForUI message_loop_;
};
#if GTEST_HAS_PARAM_TEST
class GestureEventQueueWithSourceTest
: public GestureEventQueueTest,
public testing::WithParamInterface<WebGestureEvent::SourceDevice> {
};
#endif
TEST_F(GestureEventQueueTest, CoalescesScrollGestureEvents) {
DisableDebounce();
SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
WebGestureEvent::Touchscreen);
EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
SimulateGestureScrollUpdateEvent(8, -5, 0);
WebGestureEvent merged_event = GestureEventLastQueueEvent();
EXPECT_EQ(2U, GestureEventQueueSize());
EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
EXPECT_EQ(WebGestureEvent::Touchscreen, merged_event.sourceDevice);
SimulateGestureScrollUpdateEvent(8, -6, 0);
merged_event = GestureEventLastQueueEvent();
EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
EXPECT_EQ(0, merged_event.modifiers);
EXPECT_EQ(16, merged_event.data.scrollUpdate.deltaX);
EXPECT_EQ(-11, merged_event.data.scrollUpdate.deltaY);
EXPECT_EQ(WebGestureEvent::Touchscreen, merged_event.sourceDevice);
SimulateGestureScrollUpdateEvent(8, -7, 1);
merged_event = GestureEventLastQueueEvent();
EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
EXPECT_EQ(1, merged_event.modifiers);
EXPECT_EQ(WebGestureEvent::Touchscreen, merged_event.sourceDevice);
SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
WebGestureEvent::Touchscreen);
EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
SendInputEventACK(WebInputEvent::GestureScrollBegin,
INPUT_EVENT_ACK_STATE_CONSUMED);
RunUntilIdle();
EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
SendInputEventACK(WebInputEvent::GestureScrollUpdate,
INPUT_EVENT_ACK_STATE_CONSUMED);
RunUntilIdle();
EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
SendInputEventACK(WebInputEvent::GestureScrollUpdate,
INPUT_EVENT_ACK_STATE_CONSUMED);
RunUntilIdle();
EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
SendInputEventACK(WebInputEvent::GestureScrollEnd,
INPUT_EVENT_ACK_STATE_CONSUMED);
RunUntilIdle();
EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
}
TEST_F(GestureEventQueueTest,
DoesNotCoalesceScrollGestureEventsFromDifferentDevices) {
DisableDebounce();
SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
WebGestureEvent::Touchscreen);
EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
SimulateGestureScrollUpdateEvent(8, -5, 0);
EXPECT_EQ(2U, GestureEventQueueSize());
EXPECT_EQ(WebGestureEvent::Touchscreen,
GestureEventLastQueueEvent().sourceDevice);
SimulateGestureScrollUpdateEvent(8, -6, 0);
EXPECT_EQ(2U, GestureEventQueueSize());
EXPECT_EQ(WebGestureEvent::Touchscreen,
GestureEventLastQueueEvent().sourceDevice);
SimulateGestureEvent(WebInputEvent::GestureScrollUpdate,
WebGestureEvent::Touchpad);
EXPECT_EQ(3U, GestureEventQueueSize());
EXPECT_EQ(WebGestureEvent::Touchpad,
GestureEventLastQueueEvent().sourceDevice);
SimulateGestureEvent(WebInputEvent::GestureScrollUpdate,
WebGestureEvent::Touchpad);
EXPECT_EQ(3U, GestureEventQueueSize());
EXPECT_EQ(WebGestureEvent::Touchpad,
GestureEventLastQueueEvent().sourceDevice);
SimulateGestureScrollUpdateEvent(8, -7, 0);
EXPECT_EQ(4U, GestureEventQueueSize());
EXPECT_EQ(WebGestureEvent::Touchscreen,
GestureEventLastQueueEvent().sourceDevice);
}
TEST_F(GestureEventQueueTest, CoalescesScrollAndPinchEvents) {
DisableDebounce();
SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
WebGestureEvent::Touchscreen);
SimulateGestureEvent(WebInputEvent::GesturePinchBegin,
WebGestureEvent::Touchscreen);
SimulateGestureScrollUpdateEvent(8, -4, 1);
WebGestureEvent merged_event = GestureEventLastQueueEvent();
EXPECT_EQ(3U, GestureEventQueueSize());
EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
SimulateGesturePinchUpdateEvent(1.5, 60, 60, 1);
EXPECT_EQ(4U, GestureEventQueueSize());
merged_event = GestureEventLastQueueEvent();
EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
EXPECT_EQ(1.5, merged_event.data.pinchUpdate.scale);
EXPECT_EQ(1, merged_event.modifiers);
EXPECT_EQ(WebGestureEvent::Touchscreen, merged_event.sourceDevice);
merged_event = GestureEventSecondFromLastQueueEvent();
EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
EXPECT_EQ(8, merged_event.data.scrollUpdate.deltaX);
EXPECT_EQ(-4, merged_event.data.scrollUpdate.deltaY);
EXPECT_EQ(1, merged_event.modifiers);
EXPECT_EQ(WebGestureEvent::Touchscreen, merged_event.sourceDevice);
SimulateGestureScrollUpdateEvent(6, -3, 1);
EXPECT_EQ(4U, GestureEventQueueSize());
merged_event = GestureEventLastQueueEvent();
EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
EXPECT_EQ(1.5, merged_event.data.pinchUpdate.scale);
EXPECT_EQ(1, merged_event.modifiers);
EXPECT_EQ(WebGestureEvent::Touchscreen, merged_event.sourceDevice);
merged_event = GestureEventSecondFromLastQueueEvent();
EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
EXPECT_EQ(12, merged_event.data.scrollUpdate.deltaX);
EXPECT_EQ(-6, merged_event.data.scrollUpdate.deltaY);
EXPECT_EQ(1, merged_event.modifiers);
EXPECT_EQ(WebGestureEvent::Touchscreen, merged_event.sourceDevice);
SimulateGesturePinchUpdateEvent(2, 60, 60, 1);
EXPECT_EQ(4U, GestureEventQueueSize());
merged_event = GestureEventLastQueueEvent();
EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
EXPECT_EQ(3, merged_event.data.pinchUpdate.scale);
EXPECT_EQ(1, merged_event.modifiers);
EXPECT_EQ(WebGestureEvent::Touchscreen, merged_event.sourceDevice);
merged_event = GestureEventSecondFromLastQueueEvent();
EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
EXPECT_EQ(12, merged_event.data.scrollUpdate.deltaX);
EXPECT_EQ(-6, merged_event.data.scrollUpdate.deltaY);
EXPECT_EQ(1, merged_event.modifiers);
EXPECT_EQ(WebGestureEvent::Touchscreen, merged_event.sourceDevice);
SimulateGesturePinchUpdateEvent(2, 60, 60, 1);
EXPECT_EQ(4U, GestureEventQueueSize());
merged_event = GestureEventLastQueueEvent();
EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
EXPECT_EQ(6, merged_event.data.pinchUpdate.scale);
EXPECT_EQ(1, merged_event.modifiers);
EXPECT_EQ(WebGestureEvent::Touchscreen, merged_event.sourceDevice);
merged_event = GestureEventSecondFromLastQueueEvent();
EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
EXPECT_EQ(12, merged_event.data.scrollUpdate.deltaX);
EXPECT_EQ(-6, merged_event.data.scrollUpdate.deltaY);
EXPECT_EQ(1, merged_event.modifiers);
EXPECT_EQ(WebGestureEvent::Touchscreen, merged_event.sourceDevice);
EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
SendInputEventACK(WebInputEvent::GestureScrollBegin,
INPUT_EVENT_ACK_STATE_CONSUMED);
RunUntilIdle();
EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
SimulateGestureScrollUpdateEvent(6, -6, 1);
EXPECT_EQ(3U, GestureEventQueueSize());
merged_event = GestureEventLastQueueEvent();
EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
EXPECT_EQ(6, merged_event.data.pinchUpdate.scale);
EXPECT_EQ(1, merged_event.modifiers);
EXPECT_EQ(WebGestureEvent::Touchscreen, merged_event.sourceDevice);
merged_event = GestureEventSecondFromLastQueueEvent();
EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
EXPECT_EQ(13, merged_event.data.scrollUpdate.deltaX);
EXPECT_EQ(-7, merged_event.data.scrollUpdate.deltaY);
EXPECT_EQ(1, merged_event.modifiers);
EXPECT_EQ(WebGestureEvent::Touchscreen, merged_event.sourceDevice);
EXPECT_FALSE(WillIgnoreNextACK());
SendInputEventACK(WebInputEvent::GesturePinchBegin,
INPUT_EVENT_ACK_STATE_CONSUMED);
RunUntilIdle();
EXPECT_EQ(2U, GetAndResetSentGestureEventCount());
EXPECT_TRUE(WillIgnoreNextACK());
SimulateGestureScrollUpdateEvent(1, -1, 1);
EXPECT_EQ(3U, GestureEventQueueSize());
merged_event = GestureEventLastQueueEvent();
EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
EXPECT_EQ(1, merged_event.data.scrollUpdate.deltaX);
EXPECT_EQ(-1, merged_event.data.scrollUpdate.deltaY);
EXPECT_EQ(1, merged_event.modifiers);
EXPECT_EQ(WebGestureEvent::Touchscreen, merged_event.sourceDevice);
merged_event = GestureEventSecondFromLastQueueEvent();
EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
EXPECT_EQ(6, merged_event.data.pinchUpdate.scale);
EXPECT_EQ(1, merged_event.modifiers);
EXPECT_EQ(WebGestureEvent::Touchscreen, merged_event.sourceDevice);
SimulateGestureScrollUpdateEvent(2, -2, 1);
EXPECT_EQ(3U, GestureEventQueueSize());
merged_event = GestureEventLastQueueEvent();
EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
EXPECT_EQ(3, merged_event.data.scrollUpdate.deltaX);
EXPECT_EQ(-3, merged_event.data.scrollUpdate.deltaY);
EXPECT_EQ(1, merged_event.modifiers);
EXPECT_EQ(WebGestureEvent::Touchscreen, merged_event.sourceDevice);
merged_event = GestureEventSecondFromLastQueueEvent();
EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
EXPECT_EQ(6, merged_event.data.pinchUpdate.scale);
EXPECT_EQ(1, merged_event.modifiers);
EXPECT_EQ(WebGestureEvent::Touchscreen, merged_event.sourceDevice);
SimulateGesturePinchUpdateEvent(0.5, 60, 60, 1);
EXPECT_EQ(4U, GestureEventQueueSize());
merged_event = GestureEventLastQueueEvent();
EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
EXPECT_EQ(0.5, merged_event.data.pinchUpdate.scale);
EXPECT_EQ(1, merged_event.modifiers);
EXPECT_EQ(WebGestureEvent::Touchscreen, merged_event.sourceDevice);
merged_event = GestureEventSecondFromLastQueueEvent();
EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
EXPECT_EQ(3, merged_event.data.scrollUpdate.deltaX);
EXPECT_EQ(-3, merged_event.data.scrollUpdate.deltaY);
EXPECT_EQ(1, merged_event.modifiers);
EXPECT_EQ(WebGestureEvent::Touchscreen, merged_event.sourceDevice);
SendInputEventACK(WebInputEvent::GestureScrollUpdate,
INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(WebInputEvent::GestureScrollUpdate, last_acked_event().type);
RunUntilIdle();
EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
EXPECT_FALSE(WillIgnoreNextACK());
SimulateGestureScrollUpdateEvent(2, -2, 2);
EXPECT_EQ(4U, GestureEventQueueSize());
merged_event = GestureEventLastQueueEvent();
EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
EXPECT_EQ(2, merged_event.data.scrollUpdate.deltaX);
EXPECT_EQ(-2, merged_event.data.scrollUpdate.deltaY);
EXPECT_EQ(2, merged_event.modifiers);
EXPECT_EQ(WebGestureEvent::Touchscreen, merged_event.sourceDevice);
merged_event = GestureEventSecondFromLastQueueEvent();
EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
EXPECT_EQ(0.5, merged_event.data.pinchUpdate.scale);
EXPECT_EQ(1, merged_event.modifiers);
EXPECT_EQ(WebGestureEvent::Touchscreen, merged_event.sourceDevice);
SendInputEventACK(WebInputEvent::GesturePinchUpdate,
INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(WebInputEvent::GesturePinchUpdate, last_acked_event().type);
RunUntilIdle();
EXPECT_EQ(2U, GetAndResetSentGestureEventCount());
SendInputEventACK(WebInputEvent::GestureScrollUpdate,
INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(WebInputEvent::GestureScrollUpdate, last_acked_event().type);
RunUntilIdle();
EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
SendInputEventACK(WebInputEvent::GesturePinchUpdate,
INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(WebInputEvent::GesturePinchUpdate, last_acked_event().type);
RunUntilIdle();
EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
SendInputEventACK(WebInputEvent::GestureScrollUpdate,
INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(WebInputEvent::GestureScrollUpdate, last_acked_event().type);
RunUntilIdle();
EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
EXPECT_EQ(0U, GestureEventQueueSize());
}
TEST_F(GestureEventQueueTest, CoalescesMultiplePinchEventSequences) {
DisableDebounce();
SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
WebGestureEvent::Touchscreen);
SimulateGestureEvent(WebInputEvent::GesturePinchBegin,
WebGestureEvent::Touchscreen);
SimulateGestureScrollUpdateEvent(8, -4, 1);
WebGestureEvent merged_event = GestureEventLastQueueEvent();
size_t expected_events_in_queue = 3;
EXPECT_EQ(expected_events_in_queue, GestureEventQueueSize());
EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
SimulateGesturePinchUpdateEvent(1.5, 60, 60, 1);
EXPECT_EQ(++expected_events_in_queue, GestureEventQueueSize());
merged_event = GestureEventLastQueueEvent();
EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
EXPECT_EQ(1.5, merged_event.data.pinchUpdate.scale);
EXPECT_EQ(1, merged_event.modifiers);
merged_event = GestureEventSecondFromLastQueueEvent();
EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
EXPECT_EQ(8, merged_event.data.scrollUpdate.deltaX);
EXPECT_EQ(-4, merged_event.data.scrollUpdate.deltaY);
EXPECT_EQ(1, merged_event.modifiers);
SimulateGestureScrollUpdateEvent(6, -3, 1);
EXPECT_EQ(expected_events_in_queue, GestureEventQueueSize());
merged_event = GestureEventLastQueueEvent();
EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
EXPECT_EQ(1.5, merged_event.data.pinchUpdate.scale);
EXPECT_EQ(1, merged_event.modifiers);
merged_event = GestureEventSecondFromLastQueueEvent();
EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
EXPECT_EQ(12, merged_event.data.scrollUpdate.deltaX);
EXPECT_EQ(-6, merged_event.data.scrollUpdate.deltaY);
EXPECT_EQ(1, merged_event.modifiers);
SimulateGestureEvent(WebInputEvent::GesturePinchEnd,
WebGestureEvent::Touchscreen);
SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
WebGestureEvent::Touchscreen);
SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
WebGestureEvent::Touchscreen);
SimulateGestureEvent(WebInputEvent::GesturePinchBegin,
WebGestureEvent::Touchscreen);
SimulateGestureScrollUpdateEvent(8, -4, 1);
expected_events_in_queue += 5;
merged_event = GestureEventLastQueueEvent();
EXPECT_EQ(expected_events_in_queue, GestureEventQueueSize());
EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
SimulateGesturePinchUpdateEvent(1.5, 30, 30, 1);
EXPECT_EQ(++expected_events_in_queue, GestureEventQueueSize());
merged_event = GestureEventLastQueueEvent();
EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
EXPECT_EQ(1.5, merged_event.data.pinchUpdate.scale);
EXPECT_EQ(1, merged_event.modifiers);
merged_event = GestureEventSecondFromLastQueueEvent();
EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
EXPECT_EQ(8, merged_event.data.scrollUpdate.deltaX);
EXPECT_EQ(-4, merged_event.data.scrollUpdate.deltaY);
EXPECT_EQ(1, merged_event.modifiers);
SimulateGestureScrollUpdateEvent(6, -3, 1);
EXPECT_EQ(expected_events_in_queue, GestureEventQueueSize());
merged_event = GestureEventLastQueueEvent();
EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
EXPECT_EQ(1.5, merged_event.data.pinchUpdate.scale);
EXPECT_EQ(1, merged_event.modifiers);
merged_event = GestureEventSecondFromLastQueueEvent();
EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
EXPECT_EQ(12, merged_event.data.scrollUpdate.deltaX);
EXPECT_EQ(-6, merged_event.data.scrollUpdate.deltaY);
EXPECT_EQ(1, merged_event.modifiers);
}
TEST_F(GestureEventQueueTest, SimpleSyncAck) {
set_synchronous_ack(INPUT_EVENT_ACK_STATE_CONSUMED);
SimulateGestureEvent(WebInputEvent::GestureTapDown,
WebGestureEvent::Touchscreen);
EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
EXPECT_EQ(0U, GestureEventQueueSize());
EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
}
TEST_F(GestureEventQueueTest, SyncAckQueuesEvent) {
scoped_ptr<WebGestureEvent> queued_event;
set_synchronous_ack(INPUT_EVENT_ACK_STATE_CONSUMED);
set_sync_followup_event(WebInputEvent::GestureShowPress,
WebGestureEvent::Touchscreen);
SimulateGestureEvent(WebInputEvent::GestureTapDown,
WebGestureEvent::Touchscreen);
EXPECT_EQ(2U, GetAndResetSentGestureEventCount());
EXPECT_EQ(1U, GestureEventQueueSize());
EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
SendInputEventACK(WebInputEvent::GestureShowPress,
INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
EXPECT_EQ(0U, GestureEventQueueSize());
EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
}
TEST_F(GestureEventQueueTest, AsyncThenSyncAck) {
DisableDebounce();
SimulateGestureEvent(WebInputEvent::GestureTapDown,
WebGestureEvent::Touchscreen);
EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
EXPECT_EQ(1U, GestureEventQueueSize());
EXPECT_EQ(0U, GetAndResetAckedGestureEventCount());
SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
WebGestureEvent::Touchscreen);
set_synchronous_ack(INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
EXPECT_EQ(2U, GestureEventQueueSize());
EXPECT_EQ(0U, GetAndResetAckedGestureEventCount());
SendInputEventACK(WebInputEvent::GestureTapDown,
INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
EXPECT_EQ(0U, GestureEventQueueSize());
EXPECT_EQ(2U, GetAndResetAckedGestureEventCount());
}
TEST_F(GestureEventQueueTest, CoalescesScrollAndPinchEventWithSyncAck) {
DisableDebounce();
SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
WebGestureEvent::Touchscreen);
EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
SimulateGestureEvent(WebInputEvent::GesturePinchBegin,
WebGestureEvent::Touchscreen);
EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
SimulateGestureScrollUpdateEvent(8, -4, 1);
WebGestureEvent merged_event = GestureEventLastQueueEvent();
EXPECT_EQ(3U, GestureEventQueueSize());
EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
SimulateGesturePinchUpdateEvent(1.5, 60, 60, 1);
EXPECT_EQ(4U, GestureEventQueueSize());
SendInputEventACK(WebInputEvent::GestureScrollBegin,
INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
EXPECT_EQ(3U, GestureEventQueueSize());
set_synchronous_ack(INPUT_EVENT_ACK_STATE_CONSUMED);
SendInputEventACK(WebInputEvent::GesturePinchBegin,
INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(WebInputEvent::GestureScrollUpdate, last_acked_event().type);
EXPECT_EQ(1U, GestureEventQueueSize());
EXPECT_EQ(2U, GetAndResetSentGestureEventCount());
SendInputEventACK(WebInputEvent::GesturePinchUpdate,
INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(WebInputEvent::GesturePinchUpdate, last_acked_event().type);
EXPECT_EQ(0U, GestureEventQueueSize());
EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
}
#if GTEST_HAS_PARAM_TEST
TEST_P(GestureEventQueueWithSourceTest, GestureFlingCancelsFiltered) {
WebGestureEvent::SourceDevice source_device = GetParam();
DisableDebounce();
SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device);
EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
EXPECT_EQ(0U, GestureEventQueueSize());
SimulateGestureFlingStartEvent(0, -10, source_device);
EXPECT_TRUE(FlingInProgress());
SendInputEventACK(WebInputEvent::GestureFlingStart,
INPUT_EVENT_ACK_STATE_CONSUMED);
RunUntilIdle();
EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device);
EXPECT_FALSE(FlingInProgress());
EXPECT_EQ(2U, GetAndResetSentGestureEventCount());
SendInputEventACK(WebInputEvent::GestureFlingCancel,
INPUT_EVENT_ACK_STATE_CONSUMED);
RunUntilIdle();
EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
EXPECT_EQ(0U, GestureEventQueueSize());
SimulateGestureFlingStartEvent(0, -10, source_device);
EXPECT_TRUE(FlingInProgress());
SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device);
EXPECT_FALSE(FlingInProgress());
EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
EXPECT_EQ(2U, GestureEventQueueSize());
SendInputEventACK(WebInputEvent::GestureFlingStart,
INPUT_EVENT_ACK_STATE_CONSUMED);
RunUntilIdle();
EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
SendInputEventACK(WebInputEvent::GestureFlingCancel,
INPUT_EVENT_ACK_STATE_CONSUMED);
RunUntilIdle();
EXPECT_EQ(2U, GetAndResetAckedGestureEventCount());
EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
EXPECT_EQ(0U, GestureEventQueueSize());
SimulateGestureScrollUpdateEvent(8, -7, 0);
SimulateGestureFlingStartEvent(0, -10, source_device);
EXPECT_EQ(2U, GestureEventQueueSize());
EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
WebGestureEvent merged_event = GestureEventLastQueueEvent();
EXPECT_EQ(WebInputEvent::GestureFlingStart, merged_event.type);
EXPECT_TRUE(FlingInProgress());
EXPECT_EQ(2U, GestureEventQueueSize());
SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device);
merged_event =GestureEventLastQueueEvent();
EXPECT_EQ(WebInputEvent::GestureFlingCancel, merged_event.type);
EXPECT_FALSE(FlingInProgress());
EXPECT_EQ(3U, GestureEventQueueSize());
SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device);
EXPECT_FALSE(FlingInProgress());
EXPECT_EQ(3U, GestureEventQueueSize());
SimulateGestureFlingStartEvent(0, -10, source_device);
merged_event = GestureEventLastQueueEvent();
EXPECT_EQ(WebInputEvent::GestureFlingStart, merged_event.type);
EXPECT_TRUE(FlingInProgress());
EXPECT_EQ(4U, GestureEventQueueSize());
SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device);
merged_event = GestureEventLastQueueEvent();
EXPECT_EQ(WebInputEvent::GestureFlingCancel, merged_event.type);
EXPECT_FALSE(FlingInProgress());
EXPECT_EQ(5U, GestureEventQueueSize());
SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device);
merged_event = GestureEventLastQueueEvent();
EXPECT_EQ(WebInputEvent::GestureFlingCancel, merged_event.type);
EXPECT_FALSE(FlingInProgress());
EXPECT_EQ(5U, GestureEventQueueSize());
}
INSTANTIATE_TEST_CASE_P(AllSources,
GestureEventQueueWithSourceTest,
testing::Values(WebGestureEvent::Touchscreen,
WebGestureEvent::Touchpad));
#endif
TEST_F(GestureEventQueueTest, DebounceDefersFollowingGestureEvents) {
set_debounce_interval_time_ms(3);
SimulateGestureEvent(WebInputEvent::GestureScrollUpdate,
WebGestureEvent::Touchscreen);
EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
EXPECT_EQ(1U, GestureEventQueueSize());
EXPECT_EQ(0U, GestureEventDebouncingQueueSize());
EXPECT_TRUE(ScrollingInProgress());
SimulateGestureEvent(WebInputEvent::GestureScrollUpdate,
WebGestureEvent::Touchscreen);
EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
EXPECT_EQ(2U, GestureEventQueueSize());
EXPECT_EQ(0U, GestureEventDebouncingQueueSize());
EXPECT_TRUE(ScrollingInProgress());
SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
WebGestureEvent::Touchscreen);
EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
EXPECT_EQ(2U, GestureEventQueueSize());
EXPECT_EQ(1U, GestureEventDebouncingQueueSize());
SimulateGestureFlingStartEvent(0, 10, WebGestureEvent::Touchscreen);
EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
EXPECT_EQ(2U, GestureEventQueueSize());
EXPECT_EQ(2U, GestureEventDebouncingQueueSize());
SimulateGestureEvent(WebInputEvent::GestureTapDown,
WebGestureEvent::Touchscreen);
EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
EXPECT_EQ(2U, GestureEventQueueSize());
EXPECT_EQ(3U, GestureEventDebouncingQueueSize());
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE,
base::MessageLoop::QuitClosure(),
TimeDelta::FromMilliseconds(5));
base::MessageLoop::current()->Run();
EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
EXPECT_EQ(5U, GestureEventQueueSize());
EXPECT_EQ(0U, GestureEventDebouncingQueueSize());
EXPECT_FALSE(ScrollingInProgress());
WebInputEvent::Type expected[] = {
WebInputEvent::GestureScrollUpdate,
WebInputEvent::GestureScrollUpdate,
WebInputEvent::GestureScrollEnd,
WebInputEvent::GestureFlingStart};
for (unsigned i = 0; i < sizeof(expected) / sizeof(WebInputEvent::Type);
i++) {
WebGestureEvent merged_event = GestureEventQueueEventAt(i);
EXPECT_EQ(expected[i], merged_event.type);
}
}
TEST_F(GestureEventQueueTest, DebounceDropsDeferredEvents) {
set_debounce_interval_time_ms(3);
EXPECT_FALSE(ScrollingInProgress());
SimulateGestureEvent(WebInputEvent::GestureScrollUpdate,
WebGestureEvent::Touchscreen);
EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
EXPECT_EQ(1U, GestureEventQueueSize());
EXPECT_EQ(0U, GestureEventDebouncingQueueSize());
EXPECT_TRUE(ScrollingInProgress());
SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
WebGestureEvent::Touchscreen);
EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
EXPECT_EQ(1U, GestureEventQueueSize());
EXPECT_EQ(1U, GestureEventDebouncingQueueSize());
SimulateGestureEvent(WebInputEvent::GestureScrollUpdate,
WebGestureEvent::Touchscreen);
EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
EXPECT_EQ(2U, GestureEventQueueSize());
EXPECT_EQ(0U, GestureEventDebouncingQueueSize());
EXPECT_TRUE(ScrollingInProgress());
WebInputEvent::Type expected[] = {
WebInputEvent::GestureScrollUpdate,
WebInputEvent::GestureScrollUpdate};
for (unsigned i = 0; i < sizeof(expected) / sizeof(WebInputEvent::Type);
i++) {
WebGestureEvent merged_event = GestureEventQueueEventAt(i);
EXPECT_EQ(expected[i], merged_event.type);
}
}
TEST_F(GestureEventQueueTest, DropZeroVelocityFlings) {
WebGestureEvent gesture_event;
gesture_event.type = WebInputEvent::GestureFlingStart;
gesture_event.sourceDevice = WebGestureEvent::Touchpad;
gesture_event.data.flingStart.velocityX = 0.f;
gesture_event.data.flingStart.velocityY = 0.f;
ASSERT_EQ(0U, GetAndResetSentGestureEventCount());
ASSERT_EQ(0U, GestureEventQueueSize());
EXPECT_FALSE(SimulateGestureEvent(gesture_event));
EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
EXPECT_EQ(0U, GestureEventQueueSize());
}
}