Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 InputEventAck ack(type, ack_result); |
| 447 ack.type = type; | 447 if (WebInputEvent::isTouchEventType(type)) |
| 448 ack.state = ack_result; | 448 ack.unique_touch_event_id = last_sent_event_id_; |
| 449 InputHostMsg_HandleInputEvent_ACK response(0, ack); | 449 InputHostMsg_HandleInputEvent_ACK response(0, ack); |
| 450 widget_host_->OnMessageReceived(response); | 450 widget_host_->OnMessageReceived(response); |
| 451 } | 451 } |
| 452 | 452 |
| 453 size_t GetSentMessageCountAndResetSink() { | 453 size_t GetSentMessageCountAndResetSink() { |
| 454 size_t count = sink_->message_count(); | 454 size_t count = sink_->message_count(); |
| 455 sink_->ClearMessages(); | 455 sink_->ClearMessages(); |
| 456 return count; | 456 return count; |
| 457 } | 457 } |
| 458 | 458 |
| 459 void AckLastSentInputEventIfNecessary(InputEventAckState ack_result) { | 459 void AckLastSentInputEventIfNecessary(InputEventAckState ack_result) { |
| 460 if (!sink_->message_count()) | 460 if (!sink_->message_count()) |
| 461 return; | 461 return; |
| 462 | 462 |
| 463 InputMsg_HandleInputEvent::Param params; | 463 InputMsg_HandleInputEvent::Param params; |
| 464 if (!InputMsg_HandleInputEvent::Read( | 464 if (!InputMsg_HandleInputEvent::Read( |
| 465 sink_->GetMessageAt(sink_->message_count() - 1), ¶ms)) { | 465 sink_->GetMessageAt(sink_->message_count() - 1), ¶ms)) { |
| 466 return; | 466 return; |
| 467 } | 467 } |
| 468 | 468 |
| 469 if (WebInputEventTraits::IgnoresAckDisposition(*get<0>(params))) | 469 if (!WebInputEventTraits::WillReceiveAckFromRenderer(*get<0>(params))) |
| 470 return; | 470 return; |
| 471 | 471 |
| 472 SetLastSentEventIDFromSentEvent(); | |
| 472 SendInputEventACK(get<0>(params)->type, ack_result); | 473 SendInputEventACK(get<0>(params)->type, ack_result); |
| 473 } | 474 } |
| 474 | 475 |
| 476 void SetLastSentEventID(uint32 event_id) { last_sent_event_id_ = event_id; } | |
|
jdduke (slow)
2015/05/07 21:11:16
Instead of setting the id and trying to guess it,
| |
| 477 | |
| 478 void SetLastSentEventIDFromSentEvent() { | |
| 479 size_t count = sink_->message_count(); | |
| 480 for (size_t i = 0; i < count; ++i) { | |
| 481 const WebInputEvent* input_event = | |
| 482 GetInputEventFromMessage(*sink_->GetMessageAt(i)); | |
| 483 last_sent_event_id_ = | |
| 484 WebInputEventTraits::GetUniqueTouchEventId(*input_event); | |
| 485 } | |
| 486 } | |
| 487 | |
| 475 protected: | 488 protected: |
| 476 // If true, then calls RWH::Shutdown() instead of deleting RWH. | 489 // If true, then calls RWH::Shutdown() instead of deleting RWH. |
| 477 bool widget_host_uses_shutdown_to_destroy_; | 490 bool widget_host_uses_shutdown_to_destroy_; |
| 478 | 491 |
| 479 bool is_guest_view_hack_; | 492 bool is_guest_view_hack_; |
| 480 | 493 |
| 481 base::MessageLoopForUI message_loop_; | 494 base::MessageLoopForUI message_loop_; |
| 482 BrowserThreadImpl browser_thread_for_ui_; | 495 BrowserThreadImpl browser_thread_for_ui_; |
| 483 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; | 496 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; |
| 484 scoped_ptr<BrowserContext> browser_context_; | 497 scoped_ptr<BrowserContext> browser_context_; |
| 485 MockRenderWidgetHostDelegate delegate_; | 498 MockRenderWidgetHostDelegate delegate_; |
| 486 MockRenderProcessHost* process_host_; | 499 MockRenderProcessHost* process_host_; |
| 487 | 500 |
| 488 // Tests should set these to NULL if they've already triggered their | 501 // Tests should set these to NULL if they've already triggered their |
| 489 // destruction. | 502 // destruction. |
| 490 RenderWidgetHostImpl* parent_host_; | 503 RenderWidgetHostImpl* parent_host_; |
| 491 RenderWidgetHostViewAura* parent_view_; | 504 RenderWidgetHostViewAura* parent_view_; |
| 492 | 505 |
| 493 // Tests should set these to NULL if they've already triggered their | 506 // Tests should set these to NULL if they've already triggered their |
| 494 // destruction. | 507 // destruction. |
| 495 RenderWidgetHostImpl* widget_host_; | 508 RenderWidgetHostImpl* widget_host_; |
| 496 FakeRenderWidgetHostViewAura* view_; | 509 FakeRenderWidgetHostViewAura* view_; |
| 497 | 510 |
| 498 IPC::TestSink* sink_; | 511 IPC::TestSink* sink_; |
| 499 | 512 |
| 513 uint32 last_sent_event_id_; | |
| 514 | |
| 500 private: | 515 private: |
| 501 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraTest); | 516 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraTest); |
| 502 }; | 517 }; |
| 503 | 518 |
| 504 // Helper class to instantiate RenderWidgetHostViewGuest which is backed | 519 // Helper class to instantiate RenderWidgetHostViewGuest which is backed |
| 505 // by an aura platform view. | 520 // by an aura platform view. |
| 506 class RenderWidgetHostViewGuestAuraTest : public RenderWidgetHostViewAuraTest { | 521 class RenderWidgetHostViewGuestAuraTest : public RenderWidgetHostViewAuraTest { |
| 507 public: | 522 public: |
| 508 RenderWidgetHostViewGuestAuraTest() { | 523 RenderWidgetHostViewGuestAuraTest() { |
| 509 // Use RWH::Shutdown to destroy RWH, instead of deleting. | 524 // Use RWH::Shutdown to destroy RWH, instead of deleting. |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1095 view_->OnTouchEvent(&press); | 1110 view_->OnTouchEvent(&press); |
| 1096 EXPECT_TRUE(press.synchronous_handling_disabled()); | 1111 EXPECT_TRUE(press.synchronous_handling_disabled()); |
| 1097 EXPECT_EQ(blink::WebInputEvent::TouchStart, view_->touch_event_->type); | 1112 EXPECT_EQ(blink::WebInputEvent::TouchStart, view_->touch_event_->type); |
| 1098 EXPECT_EQ(1U, view_->touch_event_->touchesLength); | 1113 EXPECT_EQ(1U, view_->touch_event_->touchesLength); |
| 1099 EXPECT_EQ(blink::WebTouchPoint::StatePressed, | 1114 EXPECT_EQ(blink::WebTouchPoint::StatePressed, |
| 1100 view_->touch_event_->touches[0].state); | 1115 view_->touch_event_->touches[0].state); |
| 1101 | 1116 |
| 1102 widget_host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, false)); | 1117 widget_host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, false)); |
| 1103 | 1118 |
| 1104 // Ack'ing the outstanding event should flush the pending touch queue. | 1119 // Ack'ing the outstanding event should flush the pending touch queue. |
| 1105 InputHostMsg_HandleInputEvent_ACK_Params ack; | 1120 InputEventAck ack(blink::WebInputEvent::TouchStart, |
| 1106 ack.type = blink::WebInputEvent::TouchStart; | 1121 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
| 1107 ack.state = INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS; | 1122 ack.unique_touch_event_id = press.unique_event_id(); |
| 1108 widget_host_->OnMessageReceived(InputHostMsg_HandleInputEvent_ACK(0, ack)); | 1123 widget_host_->OnMessageReceived(InputHostMsg_HandleInputEvent_ACK(0, ack)); |
| 1109 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 1124 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1110 | 1125 |
| 1111 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(20, 20), 0, | 1126 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(20, 20), 0, |
| 1112 base::Time::NowFromSystemTime() - base::Time()); | 1127 base::Time::NowFromSystemTime() - base::Time()); |
| 1113 view_->OnTouchEvent(&move2); | 1128 view_->OnTouchEvent(&move2); |
| 1114 EXPECT_TRUE(press.synchronous_handling_disabled()); | 1129 EXPECT_TRUE(press.synchronous_handling_disabled()); |
| 1115 EXPECT_EQ(blink::WebInputEvent::TouchMove, view_->touch_event_->type); | 1130 EXPECT_EQ(blink::WebInputEvent::TouchMove, view_->touch_event_->type); |
| 1116 EXPECT_EQ(1U, view_->touch_event_->touchesLength); | 1131 EXPECT_EQ(1U, view_->touch_event_->touchesLength); |
| 1117 EXPECT_EQ(blink::WebTouchPoint::StateMoved, | 1132 EXPECT_EQ(blink::WebTouchPoint::StateMoved, |
| (...skipping 1655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2773 | 2788 |
| 2774 // Tests that when touch-events are dispatched to the renderer, the overscroll | 2789 // Tests that when touch-events are dispatched to the renderer, the overscroll |
| 2775 // gesture deals with them correctly. | 2790 // gesture deals with them correctly. |
| 2776 TEST_F(RenderWidgetHostViewAuraOverscrollTest, OverscrollWithTouchEvents) { | 2791 TEST_F(RenderWidgetHostViewAuraOverscrollTest, OverscrollWithTouchEvents) { |
| 2777 SetUpOverscrollEnvironmentWithDebounce(10); | 2792 SetUpOverscrollEnvironmentWithDebounce(10); |
| 2778 widget_host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); | 2793 widget_host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); |
| 2779 sink_->ClearMessages(); | 2794 sink_->ClearMessages(); |
| 2780 | 2795 |
| 2781 // The test sends an intermingled sequence of touch and gesture events. | 2796 // The test sends an intermingled sequence of touch and gesture events. |
| 2782 PressTouchPoint(0, 1); | 2797 PressTouchPoint(0, 1); |
| 2798 SetLastSentEventIDFromSentEvent(); | |
| 2783 SendInputEventACK(WebInputEvent::TouchStart, | 2799 SendInputEventACK(WebInputEvent::TouchStart, |
| 2784 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 2800 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2785 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 2801 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2786 | 2802 |
| 2787 MoveTouchPoint(0, 20, 5); | 2803 MoveTouchPoint(0, 20, 5); |
| 2804 SetLastSentEventIDFromSentEvent(); | |
| 2788 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 2805 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2789 SendInputEventACK(WebInputEvent::TouchMove, | 2806 SendInputEventACK(WebInputEvent::TouchMove, |
| 2790 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 2807 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2791 | 2808 |
| 2792 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); | 2809 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 2793 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); | 2810 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 2794 | 2811 |
| 2795 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | 2812 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 2796 blink::WebGestureDeviceTouchscreen); | 2813 blink::WebGestureDeviceTouchscreen); |
| 2797 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 2814 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3305 // lose track of the number of acks required. | 3322 // lose track of the number of acks required. |
| 3306 TEST_F(RenderWidgetHostViewAuraTest, CorrectNumberOfAcksAreDispatched) { | 3323 TEST_F(RenderWidgetHostViewAuraTest, CorrectNumberOfAcksAreDispatched) { |
| 3307 view_->InitAsFullscreen(parent_view_); | 3324 view_->InitAsFullscreen(parent_view_); |
| 3308 view_->Show(); | 3325 view_->Show(); |
| 3309 view_->UseFakeDispatcher(); | 3326 view_->UseFakeDispatcher(); |
| 3310 | 3327 |
| 3311 ui::TouchEvent press1( | 3328 ui::TouchEvent press1( |
| 3312 ui::ET_TOUCH_PRESSED, gfx::Point(30, 30), 0, ui::EventTimeForNow()); | 3329 ui::ET_TOUCH_PRESSED, gfx::Point(30, 30), 0, ui::EventTimeForNow()); |
| 3313 | 3330 |
| 3314 view_->OnTouchEvent(&press1); | 3331 view_->OnTouchEvent(&press1); |
| 3332 SetLastSentEventID(press1.unique_event_id()); | |
| 3315 SendInputEventACK(blink::WebInputEvent::TouchStart, | 3333 SendInputEventACK(blink::WebInputEvent::TouchStart, |
| 3316 INPUT_EVENT_ACK_STATE_CONSUMED); | 3334 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 3317 | 3335 |
| 3318 ui::TouchEvent press2( | 3336 ui::TouchEvent press2( |
| 3319 ui::ET_TOUCH_PRESSED, gfx::Point(20, 20), 1, ui::EventTimeForNow()); | 3337 ui::ET_TOUCH_PRESSED, gfx::Point(20, 20), 1, ui::EventTimeForNow()); |
| 3320 view_->OnTouchEvent(&press2); | 3338 view_->OnTouchEvent(&press2); |
| 3339 SetLastSentEventID(press2.unique_event_id()); | |
| 3321 SendInputEventACK(blink::WebInputEvent::TouchStart, | 3340 SendInputEventACK(blink::WebInputEvent::TouchStart, |
| 3322 INPUT_EVENT_ACK_STATE_CONSUMED); | 3341 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 3323 | 3342 |
| 3324 EXPECT_EQ(2U, view_->dispatcher_->processed_touch_event_count()); | 3343 EXPECT_EQ(2U, view_->dispatcher_->processed_touch_event_count()); |
| 3325 } | 3344 } |
| 3326 | 3345 |
| 3327 // Tests that the scroll deltas stored within the overscroll controller get | 3346 // 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 | 3347 // reset at the end of the overscroll gesture even if the overscroll threshold |
| 3329 // isn't surpassed and the overscroll mode stays OVERSCROLL_NONE. | 3348 // isn't surpassed and the overscroll mode stays OVERSCROLL_NONE. |
| 3330 TEST_F(RenderWidgetHostViewAuraOverscrollTest, ScrollDeltasResetOnEnd) { | 3349 TEST_F(RenderWidgetHostViewAuraOverscrollTest, ScrollDeltasResetOnEnd) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3363 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 3382 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 3364 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); | 3383 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 3365 EXPECT_EQ(15.f, overscroll_delta_x()); | 3384 EXPECT_EQ(15.f, overscroll_delta_x()); |
| 3366 EXPECT_EQ(-5.f, overscroll_delta_y()); | 3385 EXPECT_EQ(-5.f, overscroll_delta_y()); |
| 3367 SimulateGestureFlingStartEvent(0.f, 0.1f, blink::WebGestureDeviceTouchpad); | 3386 SimulateGestureFlingStartEvent(0.f, 0.1f, blink::WebGestureDeviceTouchpad); |
| 3368 EXPECT_EQ(0.f, overscroll_delta_x()); | 3387 EXPECT_EQ(0.f, overscroll_delta_x()); |
| 3369 EXPECT_EQ(0.f, overscroll_delta_y()); | 3388 EXPECT_EQ(0.f, overscroll_delta_y()); |
| 3370 } | 3389 } |
| 3371 | 3390 |
| 3372 } // namespace content | 3391 } // namespace content |
| OLD | NEW |