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

Side by Side Diff: content/browser/renderer_host/input/input_router_impl_unittest.cc

Issue 660663002: Clear pending events upon main frame navigation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updates Created 6 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <math.h> 5 #include <math.h>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 } 280 }
281 281
282 bool TouchEventQueueEmpty() const { 282 bool TouchEventQueueEmpty() const {
283 return input_router()->touch_event_queue_.empty(); 283 return input_router()->touch_event_queue_.empty();
284 } 284 }
285 285
286 bool TouchEventTimeoutEnabled() const { 286 bool TouchEventTimeoutEnabled() const {
287 return input_router()->touch_event_queue_.IsAckTimeoutEnabled(); 287 return input_router()->touch_event_queue_.IsAckTimeoutEnabled();
288 } 288 }
289 289
290 void Flush() const { 290 void RequestFlushedNotification() const {
291 return input_router_->Flush(); 291 return input_router_->RequestFlushedNotification();
292 } 292 }
293 293
294 size_t GetAndResetDidFlushCount() { 294 size_t GetAndResetDidFlushCount() {
295 return client_->GetAndResetDidFlushCount(); 295 return client_->GetAndResetDidFlushCount();
296 } 296 }
297 297
298 bool HasPendingEvents() const { 298 bool HasPendingEvents() const {
299 return input_router_->HasPendingEvents(); 299 return input_router_->HasPendingEvents();
300 } 300 }
301 301
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); 806 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
807 EXPECT_EQ(WebInputEvent::TouchMove, 807 EXPECT_EQ(WebInputEvent::TouchMove,
808 ack_handler_->acked_touch_event().event.type); 808 ack_handler_->acked_touch_event().event.type);
809 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); 809 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
810 } 810 }
811 811
812 // Tests that the touch-queue is emptied after a page stops listening for touch 812 // Tests that the touch-queue is emptied after a page stops listening for touch
813 // events and the outstanding ack is received. 813 // events and the outstanding ack is received.
814 TEST_F(InputRouterImplTest, TouchEventQueueFlush) { 814 TEST_F(InputRouterImplTest, TouchEventQueueFlush) {
815 OnHasTouchEventHandlers(true); 815 OnHasTouchEventHandlers(true);
816 EXPECT_TRUE(client_->has_touch_handler());
817 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); 816 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
818 EXPECT_TRUE(TouchEventQueueEmpty()); 817 EXPECT_TRUE(TouchEventQueueEmpty());
819 818
820 EXPECT_TRUE(input_router_->ShouldForwardTouchEvent()); 819 EXPECT_TRUE(input_router_->ShouldForwardTouchEvent());
821 820
822 // Send a touch-press event. 821 // Send a touch-press event.
823 PressTouchPoint(1, 1); 822 PressTouchPoint(1, 1);
824 SendTouchEvent(); 823 SendTouchEvent();
825 MoveTouchPoint(0, 2, 2); 824 MoveTouchPoint(0, 2, 2);
826 MoveTouchPoint(0, 3, 3); 825 MoveTouchPoint(0, 3, 3);
827 EXPECT_FALSE(TouchEventQueueEmpty()); 826 EXPECT_FALSE(TouchEventQueueEmpty());
828 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 827 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
829 828
830 // The page stops listening for touch-events. Note that flushing is deferred 829 // The page stops listening for touch-events. Note that flushing is deferred
831 // until the outstanding ack is received. 830 // until the outstanding ack is received.
832 OnHasTouchEventHandlers(false); 831 OnHasTouchEventHandlers(false);
833 EXPECT_FALSE(client_->has_touch_handler());
834 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); 832 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
835 EXPECT_FALSE(TouchEventQueueEmpty()); 833 EXPECT_FALSE(TouchEventQueueEmpty());
836 EXPECT_TRUE(input_router_->ShouldForwardTouchEvent()); 834 EXPECT_TRUE(input_router_->ShouldForwardTouchEvent());
837 835
838 // After the ack, the touch-event queue should be empty, and none of the 836 // After the ack, the touch-event queue should be empty, and none of the
839 // flushed touch-events should have been sent to the renderer. 837 // flushed touch-events should have been sent to the renderer.
840 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); 838 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED);
841 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); 839 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
842 EXPECT_TRUE(TouchEventQueueEmpty()); 840 EXPECT_TRUE(TouchEventQueueEmpty());
843 EXPECT_FALSE(input_router_->ShouldForwardTouchEvent()); 841 EXPECT_FALSE(input_router_->ShouldForwardTouchEvent());
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
1544 SendInputEventACK(WebInputEvent::GestureTap, INPUT_EVENT_ACK_STATE_CONSUMED); 1542 SendInputEventACK(WebInputEvent::GestureTap, INPUT_EVENT_ACK_STATE_CONSUMED);
1545 EXPECT_EQ(0, client_->in_flight_event_count()); 1543 EXPECT_EQ(0, client_->in_flight_event_count());
1546 } 1544 }
1547 1545
1548 // Test that the router will call the client's |DidFlush| after all events have 1546 // Test that the router will call the client's |DidFlush| after all events have
1549 // been dispatched following a call to |Flush|. 1547 // been dispatched following a call to |Flush|.
1550 TEST_F(InputRouterImplTest, InputFlush) { 1548 TEST_F(InputRouterImplTest, InputFlush) {
1551 EXPECT_FALSE(HasPendingEvents()); 1549 EXPECT_FALSE(HasPendingEvents());
1552 1550
1553 // Flushing an empty router should immediately trigger DidFlush. 1551 // Flushing an empty router should immediately trigger DidFlush.
1554 Flush(); 1552 RequestFlushedNotification();
1555 EXPECT_EQ(1U, GetAndResetDidFlushCount()); 1553 EXPECT_EQ(1U, GetAndResetDidFlushCount());
1556 EXPECT_FALSE(HasPendingEvents()); 1554 EXPECT_FALSE(HasPendingEvents());
1557 1555
1558 // Queue a TouchStart. 1556 // Queue a TouchStart.
1559 OnHasTouchEventHandlers(true); 1557 OnHasTouchEventHandlers(true);
1560 PressTouchPoint(1, 1); 1558 PressTouchPoint(1, 1);
1561 SendTouchEvent(); 1559 SendTouchEvent();
1562 EXPECT_TRUE(HasPendingEvents()); 1560 EXPECT_TRUE(HasPendingEvents());
1563 1561
1564 // DidFlush should be called only after the event is ack'ed. 1562 // DidFlush should be called only after the event is ack'ed.
1565 Flush(); 1563 RequestFlushedNotification();
1566 EXPECT_EQ(0U, GetAndResetDidFlushCount()); 1564 EXPECT_EQ(0U, GetAndResetDidFlushCount());
1567 SendInputEventACK(WebInputEvent::TouchStart, 1565 SendInputEventACK(WebInputEvent::TouchStart,
1568 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1566 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1569 EXPECT_EQ(1U, GetAndResetDidFlushCount()); 1567 EXPECT_EQ(1U, GetAndResetDidFlushCount());
1570 1568
1571 // Ensure different types of enqueued events will prevent the DidFlush call 1569 // Ensure different types of enqueued events will prevent the DidFlush call
1572 // until all such events have been fully dispatched. 1570 // until all such events have been fully dispatched.
1573 MoveTouchPoint(0, 50, 50); 1571 MoveTouchPoint(0, 50, 50);
1574 SendTouchEvent(); 1572 SendTouchEvent();
1575 ASSERT_TRUE(HasPendingEvents()); 1573 ASSERT_TRUE(HasPendingEvents());
1576 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, 1574 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
1577 blink::WebGestureDeviceTouchscreen); 1575 blink::WebGestureDeviceTouchscreen);
1578 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate, 1576 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate,
1579 blink::WebGestureDeviceTouchscreen); 1577 blink::WebGestureDeviceTouchscreen);
1580 SimulateGestureEvent(WebInputEvent::GesturePinchBegin, 1578 SimulateGestureEvent(WebInputEvent::GesturePinchBegin,
1581 blink::WebGestureDeviceTouchscreen); 1579 blink::WebGestureDeviceTouchscreen);
1582 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate, 1580 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate,
1583 blink::WebGestureDeviceTouchscreen); 1581 blink::WebGestureDeviceTouchscreen);
1584 Flush(); 1582 RequestFlushedNotification();
1585 EXPECT_EQ(0U, GetAndResetDidFlushCount()); 1583 EXPECT_EQ(0U, GetAndResetDidFlushCount());
1586 1584
1587 // Repeated flush calls should have no effect. 1585 // Repeated flush calls should have no effect.
1588 Flush(); 1586 RequestFlushedNotification();
1589 EXPECT_EQ(0U, GetAndResetDidFlushCount()); 1587 EXPECT_EQ(0U, GetAndResetDidFlushCount());
1590 1588
1591 // There are still pending gestures. 1589 // There are still pending gestures.
1592 SendInputEventACK(WebInputEvent::TouchMove, 1590 SendInputEventACK(WebInputEvent::TouchMove,
1593 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1591 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1594 EXPECT_EQ(0U, GetAndResetDidFlushCount()); 1592 EXPECT_EQ(0U, GetAndResetDidFlushCount());
1595 EXPECT_TRUE(HasPendingEvents()); 1593 EXPECT_TRUE(HasPendingEvents());
1596 1594
1597 // One more gesture to go. 1595 // One more gesture to go.
1598 SendInputEventACK(WebInputEvent::GestureScrollUpdate, 1596 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
1900 1898
1901 client_overscroll = client_->GetAndResetOverscroll(); 1899 client_overscroll = client_->GetAndResetOverscroll();
1902 EXPECT_EQ(wheel_overscroll.accumulated_overscroll, 1900 EXPECT_EQ(wheel_overscroll.accumulated_overscroll,
1903 client_overscroll.accumulated_overscroll); 1901 client_overscroll.accumulated_overscroll);
1904 EXPECT_EQ(wheel_overscroll.latest_overscroll_delta, 1902 EXPECT_EQ(wheel_overscroll.latest_overscroll_delta,
1905 client_overscroll.latest_overscroll_delta); 1903 client_overscroll.latest_overscroll_delta);
1906 EXPECT_EQ(wheel_overscroll.current_fling_velocity, 1904 EXPECT_EQ(wheel_overscroll.current_fling_velocity,
1907 client_overscroll.current_fling_velocity); 1905 client_overscroll.current_fling_velocity);
1908 } 1906 }
1909 1907
1908 TEST_F(InputRouterImplTest, TouchFlushedOnDestruction) {
1909 // TODO(jdduke): Implement.
1910 }
1911
1910 } // namespace content 1912 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698