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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_aura_unittest.cc

Issue 997283002: Coalesce async touch move events until the ack back from render (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/renderer_host/render_widget_host_view_aura.h" 5 #include "content/browser/renderer_host/render_widget_host_view_aura.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_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "base/memory/shared_memory.h" 10 #include "base/memory/shared_memory.h"
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 // which uses ObserverListThreadSafe, which furthermore remembers the 436 // which uses ObserverListThreadSafe, which furthermore remembers the
437 // message loop for the thread it was created in. Between tests, the 437 // message loop for the thread it was created in. Between tests, the
438 // RendererFrameManager singleton survives and and the MessageLoop gets 438 // RendererFrameManager singleton survives and and the MessageLoop gets
439 // destroyed. The correct fix would be to have ObserverListThreadSafe look 439 // destroyed. The correct fix would be to have ObserverListThreadSafe look
440 // up the proper message loop every time (see crbug.com/443824.) 440 // up the proper message loop every time (see crbug.com/443824.)
441 RendererFrameManager::GetInstance()->OnMemoryPressure(level); 441 RendererFrameManager::GetInstance()->OnMemoryPressure(level);
442 } 442 }
443 443
444 void SendInputEventACK(WebInputEvent::Type type, 444 void SendInputEventACK(WebInputEvent::Type type,
445 InputEventAckState ack_result) { 445 InputEventAckState ack_result) {
446 InputHostMsg_HandleInputEvent_ACK_Params ack; 446 DCHECK(!WebInputEvent::isTouchEventType(type));
447 ack.type = type; 447 InputEventAck ack(type, ack_result);
448 ack.state = ack_result;
449 InputHostMsg_HandleInputEvent_ACK response(0, ack); 448 InputHostMsg_HandleInputEvent_ACK response(0, ack);
450 widget_host_->OnMessageReceived(response); 449 widget_host_->OnMessageReceived(response);
451 } 450 }
451
452 void SendTouchEventACK(WebInputEvent::Type type, uint32 event_id,
453 InputEventAckState ack_result) {
454 DCHECK(WebInputEvent::isTouchEventType(type));
455 InputEventAck ack(type, ack_result, event_id);
456 InputHostMsg_HandleInputEvent_ACK response(0, ack);
457 widget_host_->OnMessageReceived(response);
458 }
452 459
453 size_t GetSentMessageCountAndResetSink() { 460 size_t GetSentMessageCountAndResetSink() {
454 size_t count = sink_->message_count(); 461 size_t count = sink_->message_count();
455 sink_->ClearMessages(); 462 sink_->ClearMessages();
456 return count; 463 return count;
457 } 464 }
458 465
459 void AckLastSentInputEventIfNecessary(InputEventAckState ack_result) { 466 void AckLastSentInputEventIfNecessary(InputEventAckState ack_result) {
460 if (!sink_->message_count()) 467 if (!sink_->message_count())
461 return; 468 return;
462 469
463 InputMsg_HandleInputEvent::Param params; 470 InputMsg_HandleInputEvent::Param params;
464 if (!InputMsg_HandleInputEvent::Read( 471 if (!InputMsg_HandleInputEvent::Read(
465 sink_->GetMessageAt(sink_->message_count() - 1), &params)) { 472 sink_->GetMessageAt(sink_->message_count() - 1), &params)) {
466 return; 473 return;
467 } 474 }
468 475
469 if (WebInputEventTraits::IgnoresAckDisposition(*get<0>(params))) 476 if (!WebInputEventTraits::WillReceiveAckFromRenderer(*get<0>(params)))
470 return; 477 return;
471 478
472 SendInputEventACK(get<0>(params)->type, ack_result); 479 SendTouchEventACK(get<0>(params)->type, LastSentEventID(), ack_result);
480 }
481
482 uint32 LastSentEventID() {
483 uint32 last_sent_event_id = 0;
jdduke (slow) 2015/05/12 16:07:11 Again, I don't think we should use this logic. Let
lanwei 2015/05/13 21:01:53 Done.
484 size_t count = sink_->message_count();
485 DCHECK_GT(count, 0U);
486 for (size_t i = 0; i < count; ++i) {
487 const WebInputEvent* input_event =
488 GetInputEventFromMessage(*sink_->GetMessageAt(i));
489 last_sent_event_id =
490 WebInputEventTraits::GetUniqueTouchEventId(*input_event);
491 }
492 return last_sent_event_id;
473 } 493 }
474 494
475 protected: 495 protected:
476 // If true, then calls RWH::Shutdown() instead of deleting RWH. 496 // If true, then calls RWH::Shutdown() instead of deleting RWH.
477 bool widget_host_uses_shutdown_to_destroy_; 497 bool widget_host_uses_shutdown_to_destroy_;
478 498
479 bool is_guest_view_hack_; 499 bool is_guest_view_hack_;
480 500
481 base::MessageLoopForUI message_loop_; 501 base::MessageLoopForUI message_loop_;
482 BrowserThreadImpl browser_thread_for_ui_; 502 BrowserThreadImpl browser_thread_for_ui_;
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
1095 view_->OnTouchEvent(&press); 1115 view_->OnTouchEvent(&press);
1096 EXPECT_TRUE(press.synchronous_handling_disabled()); 1116 EXPECT_TRUE(press.synchronous_handling_disabled());
1097 EXPECT_EQ(blink::WebInputEvent::TouchStart, view_->touch_event_->type); 1117 EXPECT_EQ(blink::WebInputEvent::TouchStart, view_->touch_event_->type);
1098 EXPECT_EQ(1U, view_->touch_event_->touchesLength); 1118 EXPECT_EQ(1U, view_->touch_event_->touchesLength);
1099 EXPECT_EQ(blink::WebTouchPoint::StatePressed, 1119 EXPECT_EQ(blink::WebTouchPoint::StatePressed,
1100 view_->touch_event_->touches[0].state); 1120 view_->touch_event_->touches[0].state);
1101 1121
1102 widget_host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, false)); 1122 widget_host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, false));
1103 1123
1104 // Ack'ing the outstanding event should flush the pending touch queue. 1124 // Ack'ing the outstanding event should flush the pending touch queue.
1105 InputHostMsg_HandleInputEvent_ACK_Params ack; 1125 InputEventAck ack(blink::WebInputEvent::TouchStart,
1106 ack.type = blink::WebInputEvent::TouchStart; 1126 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS,
1107 ack.state = INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS; 1127 press.unique_event_id());
1108 widget_host_->OnMessageReceived(InputHostMsg_HandleInputEvent_ACK(0, ack)); 1128 widget_host_->OnMessageReceived(InputHostMsg_HandleInputEvent_ACK(0, ack));
1109 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); 1129 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1110 1130
1111 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(20, 20), 0, 1131 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(20, 20), 0,
1112 base::Time::NowFromSystemTime() - base::Time()); 1132 base::Time::NowFromSystemTime() - base::Time());
1113 view_->OnTouchEvent(&move2); 1133 view_->OnTouchEvent(&move2);
1114 EXPECT_TRUE(press.synchronous_handling_disabled()); 1134 EXPECT_TRUE(press.synchronous_handling_disabled());
1115 EXPECT_EQ(blink::WebInputEvent::TouchMove, view_->touch_event_->type); 1135 EXPECT_EQ(blink::WebInputEvent::TouchMove, view_->touch_event_->type);
1116 EXPECT_EQ(1U, view_->touch_event_->touchesLength); 1136 EXPECT_EQ(1U, view_->touch_event_->touchesLength);
1117 EXPECT_EQ(blink::WebTouchPoint::StateMoved, 1137 EXPECT_EQ(blink::WebTouchPoint::StateMoved,
(...skipping 1654 matching lines...) Expand 10 before | Expand all | Expand 10 after
2772 } 2792 }
2773 2793
2774 // Tests that when touch-events are dispatched to the renderer, the overscroll 2794 // Tests that when touch-events are dispatched to the renderer, the overscroll
2775 // gesture deals with them correctly. 2795 // gesture deals with them correctly.
2776 TEST_F(RenderWidgetHostViewAuraOverscrollTest, OverscrollWithTouchEvents) { 2796 TEST_F(RenderWidgetHostViewAuraOverscrollTest, OverscrollWithTouchEvents) {
2777 SetUpOverscrollEnvironmentWithDebounce(10); 2797 SetUpOverscrollEnvironmentWithDebounce(10);
2778 widget_host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); 2798 widget_host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
2779 sink_->ClearMessages(); 2799 sink_->ClearMessages();
2780 2800
2781 // The test sends an intermingled sequence of touch and gesture events. 2801 // The test sends an intermingled sequence of touch and gesture events.
2782 PressTouchPoint(0, 1); 2802 PressTouchPoint(0, 1);
jdduke (slow) 2015/05/12 16:07:11 Looks like only 2 methods use the |PressTouchPoint
lanwei 2015/05/13 21:01:53 Done.
2783 SendInputEventACK(WebInputEvent::TouchStart, 2803 SendTouchEventACK(WebInputEvent::TouchStart, LastSentEventID(),
2784 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 2804 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2785 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 2805 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2786 2806
2787 MoveTouchPoint(0, 20, 5); 2807 MoveTouchPoint(0, 20, 5);
2808 SendTouchEventACK(WebInputEvent::TouchMove, LastSentEventID(),
2809 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2788 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 2810 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2789 SendInputEventACK(WebInputEvent::TouchMove,
2790 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2791 2811
2792 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); 2812 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2793 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); 2813 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2794 2814
2795 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, 2815 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2796 blink::WebGestureDeviceTouchscreen); 2816 blink::WebGestureDeviceTouchscreen);
2797 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 2817 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2798 SimulateGestureScrollUpdateEvent(20, 0, 0); 2818 SimulateGestureScrollUpdateEvent(20, 0, 0);
2799 SendInputEventACK(WebInputEvent::GestureScrollUpdate, 2819 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2800 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 2820 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
3305 // lose track of the number of acks required. 3325 // lose track of the number of acks required.
3306 TEST_F(RenderWidgetHostViewAuraTest, CorrectNumberOfAcksAreDispatched) { 3326 TEST_F(RenderWidgetHostViewAuraTest, CorrectNumberOfAcksAreDispatched) {
3307 view_->InitAsFullscreen(parent_view_); 3327 view_->InitAsFullscreen(parent_view_);
3308 view_->Show(); 3328 view_->Show();
3309 view_->UseFakeDispatcher(); 3329 view_->UseFakeDispatcher();
3310 3330
3311 ui::TouchEvent press1( 3331 ui::TouchEvent press1(
3312 ui::ET_TOUCH_PRESSED, gfx::Point(30, 30), 0, ui::EventTimeForNow()); 3332 ui::ET_TOUCH_PRESSED, gfx::Point(30, 30), 0, ui::EventTimeForNow());
3313 3333
3314 view_->OnTouchEvent(&press1); 3334 view_->OnTouchEvent(&press1);
3315 SendInputEventACK(blink::WebInputEvent::TouchStart, 3335 SendTouchEventACK(blink::WebInputEvent::TouchStart, press1.unique_event_id(),
3316 INPUT_EVENT_ACK_STATE_CONSUMED); 3336 INPUT_EVENT_ACK_STATE_CONSUMED);
3317 3337
3318 ui::TouchEvent press2( 3338 ui::TouchEvent press2(
3319 ui::ET_TOUCH_PRESSED, gfx::Point(20, 20), 1, ui::EventTimeForNow()); 3339 ui::ET_TOUCH_PRESSED, gfx::Point(20, 20), 1, ui::EventTimeForNow());
3320 view_->OnTouchEvent(&press2); 3340 view_->OnTouchEvent(&press2);
3321 SendInputEventACK(blink::WebInputEvent::TouchStart, 3341 SendTouchEventACK(blink::WebInputEvent::TouchStart, press2.unique_event_id(),
3322 INPUT_EVENT_ACK_STATE_CONSUMED); 3342 INPUT_EVENT_ACK_STATE_CONSUMED);
3323 3343
3324 EXPECT_EQ(2U, view_->dispatcher_->processed_touch_event_count()); 3344 EXPECT_EQ(2U, view_->dispatcher_->processed_touch_event_count());
3325 } 3345 }
3326 3346
3327 // Tests that the scroll deltas stored within the overscroll controller get 3347 // Tests that the scroll deltas stored within the overscroll controller get
3328 // reset at the end of the overscroll gesture even if the overscroll threshold 3348 // reset at the end of the overscroll gesture even if the overscroll threshold
3329 // isn't surpassed and the overscroll mode stays OVERSCROLL_NONE. 3349 // isn't surpassed and the overscroll mode stays OVERSCROLL_NONE.
3330 TEST_F(RenderWidgetHostViewAuraOverscrollTest, ScrollDeltasResetOnEnd) { 3350 TEST_F(RenderWidgetHostViewAuraOverscrollTest, ScrollDeltasResetOnEnd) {
3331 SetUpOverscrollEnvironment(); 3351 SetUpOverscrollEnvironment();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
3363 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 3383 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
3364 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); 3384 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
3365 EXPECT_EQ(15.f, overscroll_delta_x()); 3385 EXPECT_EQ(15.f, overscroll_delta_x());
3366 EXPECT_EQ(-5.f, overscroll_delta_y()); 3386 EXPECT_EQ(-5.f, overscroll_delta_y());
3367 SimulateGestureFlingStartEvent(0.f, 0.1f, blink::WebGestureDeviceTouchpad); 3387 SimulateGestureFlingStartEvent(0.f, 0.1f, blink::WebGestureDeviceTouchpad);
3368 EXPECT_EQ(0.f, overscroll_delta_x()); 3388 EXPECT_EQ(0.f, overscroll_delta_x());
3369 EXPECT_EQ(0.f, overscroll_delta_y()); 3389 EXPECT_EQ(0.f, overscroll_delta_y());
3370 } 3390 }
3371 3391
3372 } // namespace content 3392 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698