Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(886)

Unified Diff: content/browser/renderer_host/input/touch_event_queue_unittest.cc

Issue 132083006: Delegate touch handler registration logic to the TouchEventQueue (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/input/touch_event_queue_unittest.cc
diff --git a/content/browser/renderer_host/input/touch_event_queue_unittest.cc b/content/browser/renderer_host/input/touch_event_queue_unittest.cc
index 875b798546c9630d7aec244b9611e68fb6c17535..d6aeb419092decf6fda77e42e0f421e8a250c184 100644
--- a/content/browser/renderer_host/input/touch_event_queue_unittest.cc
+++ b/content/browser/renderer_host/input/touch_event_queue_unittest.cc
@@ -35,6 +35,7 @@ class TouchEventQueueTest : public testing::Test,
// testing::Test
virtual void SetUp() OVERRIDE {
queue_.reset(new TouchEventQueue(this));
+ queue_->OnHasTouchEventHandlers(true);
}
virtual void TearDown() OVERRIDE {
@@ -145,16 +146,14 @@ class TouchEventQueueTest : public testing::Test,
return queue_->IsPendingAckTouchStart();
}
- void Flush() {
- queue_->FlushQueue();
- }
-
- void SetEnableTouchForwarding(bool enabled) {
- queue_->no_touch_to_renderer_ = !enabled;
+ void OnHasTouchEventHandlers(bool has_handlers) {
+ queue_->OnHasTouchEventHandlers(has_handlers);
}
bool WillForwardTouchEvents() {
- return !queue_->no_touch_to_renderer_ && !queue_->HasTimeoutEvent();
+ return queue_->has_handlers_ &&
+ !queue_->scroll_in_progress_ &&
+ !queue_->HasTimeoutEvent();
}
bool IsTimeoutRunning() {
@@ -181,14 +180,6 @@ class TouchEventQueueTest : public testing::Test,
return last_acked_event_state_;
}
- void set_no_touch_to_renderer(bool no_touch) {
- queue_->no_touch_to_renderer_ = no_touch;
- }
-
- bool no_touch_to_renderer() const {
- return queue_->no_touch_to_renderer_;
- }
-
private:
void SendTouchEvent() {
SendTouchEvent(touch_event_);
@@ -237,8 +228,8 @@ TEST_F(TouchEventQueueTest, Basic) {
// Tests that the touch-queue is emptied if a page stops listening for touch
// events.
-TEST_F(TouchEventQueueTest, Flush) {
- Flush();
+TEST_F(TouchEventQueueTest, HasNoTouchHandlers) {
tdresser 2014/01/09 21:14:32 Test name isn't very descriptive. Perhaps QueueFlu
jdduke (slow) 2014/01/09 22:05:04 Done.
+ OnHasTouchEventHandlers(true);
EXPECT_EQ(0U, queued_event_count());
EXPECT_EQ(0U, GetAndResetSentEventCount());
@@ -267,12 +258,57 @@ TEST_F(TouchEventQueueTest, Flush) {
// Flush the queue. The touch-event queue should now be emptied, but none of
// the queued touch-events should be sent to the renderer.
- Flush();
+ OnHasTouchEventHandlers(false);
EXPECT_EQ(0U, queued_event_count());
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(31U, GetAndResetAckedEventCount());
}
+// Tests that if a touch sequence is interrupted by a no-touch-handler event,
+// the rest of the sequence will be ignored until a new touch sequence.
tdresser 2014/01/09 21:14:32 until a new touch sequence. -> until the next touc
jdduke (slow) 2014/01/09 22:05:04 Done.
+TEST_F(TouchEventQueueTest, HasNoTouchHandlersDuringTouchSequence) {
+ // Send a touch-press event.
+ PressTouchPoint(1, 1);
+ EXPECT_EQ(1U, GetAndResetSentEventCount());
+ EXPECT_EQ(1U, queued_event_count());
+
+ // Queue a touch-move event.
+ MoveTouchPoint(0, 5, 5);
+ EXPECT_EQ(2U, queued_event_count());
+ EXPECT_EQ(0U, GetAndResetAckedEventCount());
+ EXPECT_EQ(0U, GetAndResetSentEventCount());
+
+ // Touch handle deregistration should flush the queue.
+ OnHasTouchEventHandlers(false);
+ EXPECT_EQ(2U, GetAndResetAckedEventCount());
+ EXPECT_EQ(0U, queued_event_count());
+
+ // The ack should be ignored as the touch queue is now empty.
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
+ EXPECT_EQ(0U, GetAndResetAckedEventCount());
+ EXPECT_EQ(0U, queued_event_count());
+
+ // Events should be dropped while there is no touch handler.
+ MoveTouchPoint(0, 10, 10);
+ EXPECT_EQ(0U, queued_event_count());
+ EXPECT_EQ(1U, GetAndResetAckedEventCount());
+ EXPECT_EQ(0U, GetAndResetSentEventCount());
+
+ // Simulate touch handler registration in the middle of a touch sequence.
+ OnHasTouchEventHandlers(true);
+
+ // The touch end for the interrupted sequence should be dropped.
+ ReleaseTouchPoint(0);
+ EXPECT_EQ(0U, queued_event_count());
+ EXPECT_EQ(1U, GetAndResetAckedEventCount());
+ EXPECT_EQ(0U, GetAndResetSentEventCount());
+
+ // A new touch sequence should be forwarded properly.
+ PressTouchPoint(1, 1);
+ EXPECT_EQ(1U, queued_event_count());
+ EXPECT_EQ(1U, GetAndResetSentEventCount());
+}
+
// Tests that touch-events are coalesced properly in the queue.
TEST_F(TouchEventQueueTest, Coalesce) {
// Send a touch-press event.
@@ -393,7 +429,7 @@ TEST_F(TouchEventQueueTest, AckAfterQueueFlushed) {
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(1U, queued_event_count());
- Flush();
+ OnHasTouchEventHandlers(false);
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(0U, queued_event_count());
@@ -685,7 +721,7 @@ TEST_F(TouchEventQueueTest, ImmediateAckWithFollowupEvents) {
// Tests basic TouchEvent forwarding suppression.
TEST_F(TouchEventQueueTest, NoTouchBasic) {
// Disable TouchEvent forwarding.
- SetEnableTouchForwarding(false);
+ OnHasTouchEventHandlers(false);
MoveTouchPoint(0, 30, 5);
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
@@ -706,7 +742,7 @@ TEST_F(TouchEventQueueTest, NoTouchBasic) {
EXPECT_EQ(1U, GetAndResetAckedEventCount());
// Enable TouchEvent forwarding.
- SetEnableTouchForwarding(true);
+ OnHasTouchEventHandlers(true);
PressTouchPoint(80, 10);
EXPECT_EQ(1U, GetAndResetSentEventCount());
@@ -977,6 +1013,19 @@ TEST_F(TouchEventQueueTest, NoTouchTimeoutIfAckIsSynchronous) {
EXPECT_FALSE(IsTimeoutRunning());
}
+// Tests that the timeout is disabled if the touch handler disappears.
+TEST_F(TouchEventQueueTest, NoTouchTimeoutIfNoTouchHandler) {
+ SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs);
+
+ // Queue a TouchStart.
+ PressTouchPoint(0, 1);
+ ASSERT_TRUE(IsTimeoutRunning());
+
+ // Unload the touch handler.
+ OnHasTouchEventHandlers(false);
+ EXPECT_FALSE(IsTimeoutRunning());
+}
+
// Tests that a TouchCancel timeout plays nice when the timed out touch stream
// turns into a scroll gesture sequence.
TEST_F(TouchEventQueueTest, TouchTimeoutWithFollowupGesture) {

Powered by Google App Engine
This is Rietveld 408576698