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/shared_memory.h" | 9 #include "base/memory/shared_memory.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "cc/output/compositor_frame.h" | 13 #include "cc/output/compositor_frame.h" |
14 #include "cc/output/compositor_frame_metadata.h" | 14 #include "cc/output/compositor_frame_metadata.h" |
15 #include "cc/output/copy_output_request.h" | 15 #include "cc/output/copy_output_request.h" |
16 #include "content/browser/browser_thread_impl.h" | 16 #include "content/browser/browser_thread_impl.h" |
17 #include "content/browser/compositor/resize_lock.h" | 17 #include "content/browser/compositor/resize_lock.h" |
| 18 #include "content/browser/renderer_host/overscroll_controller.h" |
| 19 #include "content/browser/renderer_host/overscroll_controller_delegate.h" |
18 #include "content/browser/renderer_host/render_widget_host_delegate.h" | 20 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
19 #include "content/browser/renderer_host/render_widget_host_impl.h" | 21 #include "content/browser/renderer_host/render_widget_host_impl.h" |
20 #include "content/common/gpu/client/gl_helper.h" | 22 #include "content/common/gpu/client/gl_helper.h" |
21 #include "content/common/gpu/gpu_messages.h" | 23 #include "content/common/gpu/gpu_messages.h" |
22 #include "content/common/host_shared_bitmap_manager.h" | 24 #include "content/common/host_shared_bitmap_manager.h" |
| 25 #include "content/common/input/synthetic_web_input_event_builders.h" |
23 #include "content/common/input_messages.h" | 26 #include "content/common/input_messages.h" |
24 #include "content/common/view_messages.h" | 27 #include "content/common/view_messages.h" |
25 #include "content/public/browser/render_widget_host_view.h" | 28 #include "content/public/browser/render_widget_host_view.h" |
26 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" | 29 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" |
27 #include "content/public/test/mock_render_process_host.h" | 30 #include "content/public/test/mock_render_process_host.h" |
28 #include "content/public/test/test_browser_context.h" | 31 #include "content/public/test/test_browser_context.h" |
29 #include "ipc/ipc_test_sink.h" | 32 #include "ipc/ipc_test_sink.h" |
30 #include "testing/gmock/include/gmock/gmock.h" | 33 #include "testing/gmock/include/gmock/gmock.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
32 #include "ui/aura/client/aura_constants.h" | 35 #include "ui/aura/client/aura_constants.h" |
33 #include "ui/aura/client/screen_position_client.h" | 36 #include "ui/aura/client/screen_position_client.h" |
34 #include "ui/aura/client/window_tree_client.h" | 37 #include "ui/aura/client/window_tree_client.h" |
35 #include "ui/aura/env.h" | 38 #include "ui/aura/env.h" |
36 #include "ui/aura/layout_manager.h" | 39 #include "ui/aura/layout_manager.h" |
37 #include "ui/aura/test/aura_test_helper.h" | 40 #include "ui/aura/test/aura_test_helper.h" |
38 #include "ui/aura/test/event_generator.h" | 41 #include "ui/aura/test/event_generator.h" |
39 #include "ui/aura/test/test_cursor_client.h" | 42 #include "ui/aura/test/test_cursor_client.h" |
40 #include "ui/aura/test/test_screen.h" | 43 #include "ui/aura/test/test_screen.h" |
41 #include "ui/aura/test/test_window_delegate.h" | 44 #include "ui/aura/test/test_window_delegate.h" |
42 #include "ui/aura/window.h" | 45 #include "ui/aura/window.h" |
43 #include "ui/aura/window_event_dispatcher.h" | 46 #include "ui/aura/window_event_dispatcher.h" |
44 #include "ui/aura/window_observer.h" | 47 #include "ui/aura/window_observer.h" |
45 #include "ui/base/ui_base_types.h" | 48 #include "ui/base/ui_base_types.h" |
46 #include "ui/compositor/compositor.h" | 49 #include "ui/compositor/compositor.h" |
47 #include "ui/compositor/test/draw_waiter_for_test.h" | 50 #include "ui/compositor/test/draw_waiter_for_test.h" |
48 #include "ui/compositor/test/in_process_context_factory.h" | 51 #include "ui/compositor/test/in_process_context_factory.h" |
49 #include "ui/events/event.h" | 52 #include "ui/events/event.h" |
50 #include "ui/events/event_utils.h" | 53 #include "ui/events/event_utils.h" |
| 54 #include "ui/events/gestures/gesture_configuration.h" |
51 #include "ui/wm/core/default_activation_client.h" | 55 #include "ui/wm/core/default_activation_client.h" |
52 | 56 |
53 using testing::_; | 57 using testing::_; |
54 | 58 |
| 59 using blink::WebGestureEvent; |
| 60 using blink::WebInputEvent; |
| 61 using blink::WebMouseEvent; |
| 62 using blink::WebMouseWheelEvent; |
| 63 using blink::WebTouchEvent; |
| 64 using blink::WebTouchPoint; |
| 65 |
55 namespace content { | 66 namespace content { |
56 namespace { | 67 namespace { |
57 | 68 |
58 // Simple screen position client to test coordinate system conversion. | 69 // Simple screen position client to test coordinate system conversion. |
59 class TestScreenPositionClient | 70 class TestScreenPositionClient |
60 : public aura::client::ScreenPositionClient { | 71 : public aura::client::ScreenPositionClient { |
61 public: | 72 public: |
62 TestScreenPositionClient() {} | 73 TestScreenPositionClient() {} |
63 virtual ~TestScreenPositionClient() {} | 74 virtual ~TestScreenPositionClient() {} |
64 | 75 |
(...skipping 12 matching lines...) Expand all Loading... |
77 gfx::Point* point) OVERRIDE { | 88 gfx::Point* point) OVERRIDE { |
78 ConvertPointToScreen(window, point); | 89 ConvertPointToScreen(window, point); |
79 } | 90 } |
80 | 91 |
81 virtual void SetBounds(aura::Window* window, | 92 virtual void SetBounds(aura::Window* window, |
82 const gfx::Rect& bounds, | 93 const gfx::Rect& bounds, |
83 const gfx::Display& display) OVERRIDE { | 94 const gfx::Display& display) OVERRIDE { |
84 } | 95 } |
85 }; | 96 }; |
86 | 97 |
| 98 class TestOverscrollDelegate : public OverscrollControllerDelegate { |
| 99 public: |
| 100 explicit TestOverscrollDelegate(RenderWidgetHostView* view) |
| 101 : view_(view), |
| 102 current_mode_(OVERSCROLL_NONE), |
| 103 completed_mode_(OVERSCROLL_NONE), |
| 104 delta_x_(0.f), |
| 105 delta_y_(0.f) {} |
| 106 |
| 107 virtual ~TestOverscrollDelegate() {} |
| 108 |
| 109 OverscrollMode current_mode() const { return current_mode_; } |
| 110 OverscrollMode completed_mode() const { return completed_mode_; } |
| 111 float delta_x() const { return delta_x_; } |
| 112 float delta_y() const { return delta_y_; } |
| 113 |
| 114 void Reset() { |
| 115 current_mode_ = OVERSCROLL_NONE; |
| 116 completed_mode_ = OVERSCROLL_NONE; |
| 117 delta_x_ = delta_y_ = 0.f; |
| 118 } |
| 119 |
| 120 private: |
| 121 // Overridden from OverscrollControllerDelegate: |
| 122 virtual gfx::Rect GetVisibleBounds() const OVERRIDE { |
| 123 return view_->IsShowing() ? view_->GetViewBounds() : gfx::Rect(); |
| 124 } |
| 125 |
| 126 virtual void OnOverscrollUpdate(float delta_x, float delta_y) OVERRIDE { |
| 127 delta_x_ = delta_x; |
| 128 delta_y_ = delta_y; |
| 129 } |
| 130 |
| 131 virtual void OnOverscrollComplete(OverscrollMode overscroll_mode) OVERRIDE { |
| 132 EXPECT_EQ(current_mode_, overscroll_mode); |
| 133 completed_mode_ = overscroll_mode; |
| 134 current_mode_ = OVERSCROLL_NONE; |
| 135 } |
| 136 |
| 137 virtual void OnOverscrollModeChange(OverscrollMode old_mode, |
| 138 OverscrollMode new_mode) OVERRIDE { |
| 139 EXPECT_EQ(current_mode_, old_mode); |
| 140 current_mode_ = new_mode; |
| 141 delta_x_ = delta_y_ = 0.f; |
| 142 } |
| 143 |
| 144 RenderWidgetHostView* view_; |
| 145 OverscrollMode current_mode_; |
| 146 OverscrollMode completed_mode_; |
| 147 float delta_x_; |
| 148 float delta_y_; |
| 149 |
| 150 DISALLOW_COPY_AND_ASSIGN(TestOverscrollDelegate); |
| 151 }; |
| 152 |
87 class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate { | 153 class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate { |
88 public: | 154 public: |
89 MockRenderWidgetHostDelegate() {} | 155 MockRenderWidgetHostDelegate() {} |
90 virtual ~MockRenderWidgetHostDelegate() {} | 156 virtual ~MockRenderWidgetHostDelegate() {} |
91 }; | 157 }; |
92 | 158 |
93 // Simple observer that keeps track of changes to a window for tests. | 159 // Simple observer that keeps track of changes to a window for tests. |
94 class TestWindowObserver : public aura::WindowObserver { | 160 class TestWindowObserver : public aura::WindowObserver { |
95 public: | 161 public: |
96 explicit TestWindowObserver(aura::Window* window_to_observe) | 162 explicit TestWindowObserver(aura::Window* window_to_observe) |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 public: | 262 public: |
197 FakeResizeLock(const gfx::Size new_size, bool defer_compositor_lock) | 263 FakeResizeLock(const gfx::Size new_size, bool defer_compositor_lock) |
198 : ResizeLock(new_size, defer_compositor_lock) {} | 264 : ResizeLock(new_size, defer_compositor_lock) {} |
199 }; | 265 }; |
200 | 266 |
201 bool has_resize_lock_; | 267 bool has_resize_lock_; |
202 gfx::Size last_frame_size_; | 268 gfx::Size last_frame_size_; |
203 scoped_ptr<cc::CopyOutputRequest> last_copy_request_; | 269 scoped_ptr<cc::CopyOutputRequest> last_copy_request_; |
204 }; | 270 }; |
205 | 271 |
| 272 // A layout manager that always resizes a child to the root window size. |
| 273 class FullscreenLayoutManager : public aura::LayoutManager { |
| 274 public: |
| 275 explicit FullscreenLayoutManager(aura::Window* owner) : owner_(owner) {} |
| 276 virtual ~FullscreenLayoutManager() {} |
| 277 |
| 278 // Overridden from aura::LayoutManager: |
| 279 virtual void OnWindowResized() OVERRIDE { |
| 280 aura::Window::Windows::const_iterator i; |
| 281 for (i = owner_->children().begin(); i != owner_->children().end(); ++i) { |
| 282 (*i)->SetBounds(gfx::Rect()); |
| 283 } |
| 284 } |
| 285 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { |
| 286 child->SetBounds(gfx::Rect()); |
| 287 } |
| 288 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {} |
| 289 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {} |
| 290 virtual void OnChildWindowVisibilityChanged(aura::Window* child, |
| 291 bool visible) OVERRIDE {} |
| 292 virtual void SetChildBounds(aura::Window* child, |
| 293 const gfx::Rect& requested_bounds) OVERRIDE { |
| 294 SetChildBoundsDirect(child, gfx::Rect(owner_->bounds().size())); |
| 295 } |
| 296 |
| 297 private: |
| 298 aura::Window* owner_; |
| 299 DISALLOW_COPY_AND_ASSIGN(FullscreenLayoutManager); |
| 300 }; |
| 301 |
| 302 class MockWindowObserver : public aura::WindowObserver { |
| 303 public: |
| 304 MOCK_METHOD2(OnWindowPaintScheduled, void(aura::Window*, const gfx::Rect&)); |
| 305 }; |
| 306 |
| 307 } // namespace |
| 308 |
206 class RenderWidgetHostViewAuraTest : public testing::Test { | 309 class RenderWidgetHostViewAuraTest : public testing::Test { |
207 public: | 310 public: |
208 RenderWidgetHostViewAuraTest() | 311 RenderWidgetHostViewAuraTest() |
209 : browser_thread_for_ui_(BrowserThread::UI, &message_loop_) {} | 312 : browser_thread_for_ui_(BrowserThread::UI, &message_loop_) {} |
210 | 313 |
211 void SetUpEnvironment() { | 314 void SetUpEnvironment() { |
212 ui::ContextFactory* context_factory = new ui::InProcessContextFactory; | 315 ui::ContextFactory* context_factory = new ui::InProcessContextFactory; |
213 ImageTransportFactory::InitializeForUnitTests( | 316 ImageTransportFactory::InitializeForUnitTests( |
214 scoped_ptr<ui::ContextFactory>(context_factory)); | 317 scoped_ptr<ui::ContextFactory>(context_factory)); |
215 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); | 318 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 // destruction. | 377 // destruction. |
275 RenderWidgetHostImpl* widget_host_; | 378 RenderWidgetHostImpl* widget_host_; |
276 FakeRenderWidgetHostViewAura* view_; | 379 FakeRenderWidgetHostViewAura* view_; |
277 | 380 |
278 IPC::TestSink* sink_; | 381 IPC::TestSink* sink_; |
279 | 382 |
280 private: | 383 private: |
281 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraTest); | 384 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraTest); |
282 }; | 385 }; |
283 | 386 |
| 387 class RenderWidgetHostViewAuraOverscrollTest |
| 388 : public RenderWidgetHostViewAuraTest { |
| 389 public: |
| 390 RenderWidgetHostViewAuraOverscrollTest() {} |
| 391 |
| 392 // We explicitly invoke SetUp to allow gesture debounce customization. |
| 393 virtual void SetUp() {} |
| 394 |
| 395 protected: |
| 396 void SetUpOverscrollEnvironmentWithDebounce(int debounce_interval_in_ms) { |
| 397 SetUpOverscrollEnvironmentImpl(debounce_interval_in_ms); |
| 398 } |
| 399 |
| 400 void SetUpOverscrollEnvironment() { SetUpOverscrollEnvironmentImpl(0); } |
| 401 |
| 402 void SetUpOverscrollEnvironmentImpl(int debounce_interval_in_ms) { |
| 403 ui::GestureConfiguration::set_scroll_debounce_interval_in_ms( |
| 404 debounce_interval_in_ms); |
| 405 |
| 406 RenderWidgetHostViewAuraTest::SetUp(); |
| 407 |
| 408 view_->SetOverscrollControllerEnabled(true); |
| 409 overscroll_delegate_.reset(new TestOverscrollDelegate(view_)); |
| 410 view_->overscroll_controller()->set_delegate(overscroll_delegate_.get()); |
| 411 |
| 412 view_->InitAsChild(NULL); |
| 413 view_->SetBounds(gfx::Rect(0, 0, 400, 200)); |
| 414 view_->Show(); |
| 415 |
| 416 sink_->ClearMessages(); |
| 417 } |
| 418 |
| 419 // TODO(jdduke): Simulate ui::Events, injecting through the view. |
| 420 void SimulateMouseEvent(WebInputEvent::Type type) { |
| 421 widget_host_->ForwardMouseEvent(SyntheticWebMouseEventBuilder::Build(type)); |
| 422 } |
| 423 |
| 424 void SimulateMouseEventWithLatencyInfo(WebInputEvent::Type type, |
| 425 const ui::LatencyInfo& ui_latency) { |
| 426 widget_host_->ForwardMouseEventWithLatencyInfo( |
| 427 SyntheticWebMouseEventBuilder::Build(type), ui_latency); |
| 428 } |
| 429 |
| 430 void SimulateWheelEvent(float dX, float dY, int modifiers, bool precise) { |
| 431 widget_host_->ForwardWheelEvent( |
| 432 SyntheticWebMouseWheelEventBuilder::Build(dX, dY, modifiers, precise)); |
| 433 } |
| 434 |
| 435 void SimulateWheelEventWithLatencyInfo(float dX, |
| 436 float dY, |
| 437 int modifiers, |
| 438 bool precise, |
| 439 const ui::LatencyInfo& ui_latency) { |
| 440 widget_host_->ForwardWheelEventWithLatencyInfo( |
| 441 SyntheticWebMouseWheelEventBuilder::Build(dX, dY, modifiers, precise), |
| 442 ui_latency); |
| 443 } |
| 444 |
| 445 void SimulateMouseMove(int x, int y, int modifiers) { |
| 446 SimulateMouseEvent(WebInputEvent::MouseMove, x, y, modifiers, false); |
| 447 } |
| 448 |
| 449 void SimulateMouseEvent(WebInputEvent::Type type, |
| 450 int x, |
| 451 int y, |
| 452 int modifiers, |
| 453 bool pressed) { |
| 454 WebMouseEvent event = |
| 455 SyntheticWebMouseEventBuilder::Build(type, x, y, modifiers); |
| 456 if (pressed) |
| 457 event.button = WebMouseEvent::ButtonLeft; |
| 458 widget_host_->ForwardMouseEvent(event); |
| 459 } |
| 460 |
| 461 void SimulateWheelEventWithPhase(WebMouseWheelEvent::Phase phase) { |
| 462 widget_host_->ForwardWheelEvent( |
| 463 SyntheticWebMouseWheelEventBuilder::Build(phase)); |
| 464 } |
| 465 |
| 466 // Inject provided synthetic WebGestureEvent instance. |
| 467 void SimulateGestureEventCore(const WebGestureEvent& gesture_event) { |
| 468 widget_host_->ForwardGestureEvent(gesture_event); |
| 469 } |
| 470 |
| 471 void SimulateGestureEventCoreWithLatencyInfo( |
| 472 const WebGestureEvent& gesture_event, |
| 473 const ui::LatencyInfo& ui_latency) { |
| 474 widget_host_->ForwardGestureEventWithLatencyInfo(gesture_event, ui_latency); |
| 475 } |
| 476 |
| 477 // Inject simple synthetic WebGestureEvent instances. |
| 478 void SimulateGestureEvent(WebInputEvent::Type type, |
| 479 WebGestureEvent::SourceDevice sourceDevice) { |
| 480 SimulateGestureEventCore( |
| 481 SyntheticWebGestureEventBuilder::Build(type, sourceDevice)); |
| 482 } |
| 483 |
| 484 void SimulateGestureEventWithLatencyInfo( |
| 485 WebInputEvent::Type type, |
| 486 WebGestureEvent::SourceDevice sourceDevice, |
| 487 const ui::LatencyInfo& ui_latency) { |
| 488 SimulateGestureEventCoreWithLatencyInfo( |
| 489 SyntheticWebGestureEventBuilder::Build(type, sourceDevice), ui_latency); |
| 490 } |
| 491 |
| 492 void SimulateGestureScrollUpdateEvent(float dX, float dY, int modifiers) { |
| 493 SimulateGestureEventCore( |
| 494 SyntheticWebGestureEventBuilder::BuildScrollUpdate(dX, dY, modifiers)); |
| 495 } |
| 496 |
| 497 void SimulateGesturePinchUpdateEvent(float scale, |
| 498 float anchorX, |
| 499 float anchorY, |
| 500 int modifiers) { |
| 501 SimulateGestureEventCore(SyntheticWebGestureEventBuilder::BuildPinchUpdate( |
| 502 scale, anchorX, anchorY, modifiers, WebGestureEvent::Touchscreen)); |
| 503 } |
| 504 |
| 505 // Inject synthetic GestureFlingStart events. |
| 506 void SimulateGestureFlingStartEvent( |
| 507 float velocityX, |
| 508 float velocityY, |
| 509 WebGestureEvent::SourceDevice sourceDevice) { |
| 510 SimulateGestureEventCore(SyntheticWebGestureEventBuilder::BuildFling( |
| 511 velocityX, velocityY, sourceDevice)); |
| 512 } |
| 513 |
| 514 void SendInputEventACK(WebInputEvent::Type type, |
| 515 InputEventAckState ack_result) { |
| 516 InputHostMsg_HandleInputEvent_ACK_Params ack; |
| 517 ack.type = type; |
| 518 ack.state = ack_result; |
| 519 InputHostMsg_HandleInputEvent_ACK response(0, ack); |
| 520 widget_host_->OnMessageReceived(response); |
| 521 } |
| 522 |
| 523 bool ScrollStateIsContentScrolling() const { |
| 524 return scroll_state() == OverscrollController::STATE_CONTENT_SCROLLING; |
| 525 } |
| 526 |
| 527 bool ScrollStateIsOverscrolling() const { |
| 528 return scroll_state() == OverscrollController::STATE_OVERSCROLLING; |
| 529 } |
| 530 |
| 531 bool ScrollStateIsUnknown() const { |
| 532 return scroll_state() == OverscrollController::STATE_UNKNOWN; |
| 533 } |
| 534 |
| 535 OverscrollController::ScrollState scroll_state() const { |
| 536 return view_->overscroll_controller()->scroll_state_; |
| 537 } |
| 538 |
| 539 OverscrollMode overscroll_mode() const { |
| 540 return view_->overscroll_controller()->overscroll_mode_; |
| 541 } |
| 542 |
| 543 float overscroll_delta_x() const { |
| 544 return view_->overscroll_controller()->overscroll_delta_x_; |
| 545 } |
| 546 |
| 547 float overscroll_delta_y() const { |
| 548 return view_->overscroll_controller()->overscroll_delta_y_; |
| 549 } |
| 550 |
| 551 TestOverscrollDelegate* overscroll_delegate() { |
| 552 return overscroll_delegate_.get(); |
| 553 } |
| 554 |
| 555 void SendTouchEvent() { |
| 556 widget_host_->ForwardTouchEventWithLatencyInfo(touch_event_, |
| 557 ui::LatencyInfo()); |
| 558 touch_event_.ResetPoints(); |
| 559 } |
| 560 |
| 561 void PressTouchPoint(int x, int y) { |
| 562 touch_event_.PressPoint(x, y); |
| 563 SendTouchEvent(); |
| 564 } |
| 565 |
| 566 void MoveTouchPoint(int index, int x, int y) { |
| 567 touch_event_.MovePoint(index, x, y); |
| 568 SendTouchEvent(); |
| 569 } |
| 570 |
| 571 void ReleaseTouchPoint(int index) { |
| 572 touch_event_.ReleasePoint(index); |
| 573 SendTouchEvent(); |
| 574 } |
| 575 |
| 576 size_t GetSentMessageCountAndResetSink() { |
| 577 size_t count = sink_->message_count(); |
| 578 sink_->ClearMessages(); |
| 579 return count; |
| 580 } |
| 581 |
| 582 void AckLastSentInputEventIfNecessary(InputEventAckState ack_result) { |
| 583 if (!sink_->message_count()) |
| 584 return; |
| 585 |
| 586 InputMsg_HandleInputEvent::Param params; |
| 587 if (!InputMsg_HandleInputEvent::Read( |
| 588 sink_->GetMessageAt(sink_->message_count() - 1), ¶ms)) { |
| 589 return; |
| 590 } |
| 591 |
| 592 if (WebInputEventTraits::IgnoresAckDisposition(*params.a)) |
| 593 return; |
| 594 |
| 595 SendInputEventACK(params.a->type, ack_result); |
| 596 } |
| 597 |
| 598 SyntheticWebTouchEvent touch_event_; |
| 599 |
| 600 scoped_ptr<TestOverscrollDelegate> overscroll_delegate_; |
| 601 |
| 602 private: |
| 603 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraOverscrollTest); |
| 604 }; |
| 605 |
284 class RenderWidgetHostViewAuraShutdownTest | 606 class RenderWidgetHostViewAuraShutdownTest |
285 : public RenderWidgetHostViewAuraTest { | 607 : public RenderWidgetHostViewAuraTest { |
286 public: | 608 public: |
287 RenderWidgetHostViewAuraShutdownTest() {} | 609 RenderWidgetHostViewAuraShutdownTest() {} |
288 | 610 |
289 virtual void TearDown() OVERRIDE { | 611 virtual void TearDown() OVERRIDE { |
290 // No TearDownEnvironment here, we do this explicitly during the test. | 612 // No TearDownEnvironment here, we do this explicitly during the test. |
291 } | 613 } |
292 | 614 |
293 private: | 615 private: |
294 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraShutdownTest); | 616 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraShutdownTest); |
295 }; | 617 }; |
296 | 618 |
297 // A layout manager that always resizes a child to the root window size. | |
298 class FullscreenLayoutManager : public aura::LayoutManager { | |
299 public: | |
300 explicit FullscreenLayoutManager(aura::Window* owner) | |
301 : owner_(owner) {} | |
302 virtual ~FullscreenLayoutManager() {} | |
303 | |
304 // Overridden from aura::LayoutManager: | |
305 virtual void OnWindowResized() OVERRIDE { | |
306 aura::Window::Windows::const_iterator i; | |
307 for (i = owner_->children().begin(); i != owner_->children().end(); ++i) { | |
308 (*i)->SetBounds(gfx::Rect()); | |
309 } | |
310 } | |
311 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { | |
312 child->SetBounds(gfx::Rect()); | |
313 } | |
314 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE { | |
315 } | |
316 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE { | |
317 } | |
318 virtual void OnChildWindowVisibilityChanged(aura::Window* child, | |
319 bool visible) OVERRIDE { | |
320 } | |
321 virtual void SetChildBounds(aura::Window* child, | |
322 const gfx::Rect& requested_bounds) OVERRIDE { | |
323 SetChildBoundsDirect(child, gfx::Rect(owner_->bounds().size())); | |
324 } | |
325 | |
326 private: | |
327 aura::Window* owner_; | |
328 DISALLOW_COPY_AND_ASSIGN(FullscreenLayoutManager); | |
329 }; | |
330 | |
331 class MockWindowObserver : public aura::WindowObserver { | |
332 public: | |
333 MOCK_METHOD2(OnWindowPaintScheduled, void(aura::Window*, const gfx::Rect&)); | |
334 }; | |
335 | |
336 } // namespace | |
337 | |
338 // Checks that a fullscreen view has the correct show-state and receives the | 619 // Checks that a fullscreen view has the correct show-state and receives the |
339 // focus. | 620 // focus. |
340 TEST_F(RenderWidgetHostViewAuraTest, FocusFullscreen) { | 621 TEST_F(RenderWidgetHostViewAuraTest, FocusFullscreen) { |
341 view_->InitAsFullscreen(parent_view_); | 622 view_->InitAsFullscreen(parent_view_); |
342 aura::Window* window = view_->GetNativeView(); | 623 aura::Window* window = view_->GetNativeView(); |
343 ASSERT_TRUE(window != NULL); | 624 ASSERT_TRUE(window != NULL); |
344 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, | 625 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, |
345 window->GetProperty(aura::client::kShowStateKey)); | 626 window->GetProperty(aura::client::kShowStateKey)); |
346 | 627 |
347 // Check that we requested and received the focus. | 628 // Check that we requested and received the focus. |
(...skipping 1164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1512 | 1793 |
1513 const IPC::Message *message = sink_->GetFirstMessageMatching( | 1794 const IPC::Message *message = sink_->GetFirstMessageMatching( |
1514 ViewMsg_Resize::ID); | 1795 ViewMsg_Resize::ID); |
1515 ASSERT_TRUE(message != NULL); | 1796 ASSERT_TRUE(message != NULL); |
1516 | 1797 |
1517 ViewMsg_Resize::Param params; | 1798 ViewMsg_Resize::Param params; |
1518 ViewMsg_Resize::Read(message, ¶ms); | 1799 ViewMsg_Resize::Read(message, ¶ms); |
1519 EXPECT_EQ(60, params.a.visible_viewport_size.height()); | 1800 EXPECT_EQ(60, params.a.visible_viewport_size.height()); |
1520 } | 1801 } |
1521 | 1802 |
| 1803 // Tests that scroll ACKs are correctly handled by the overscroll-navigation |
| 1804 // controller. |
| 1805 TEST_F(RenderWidgetHostViewAuraOverscrollTest, WheelScrollEventOverscrolls) { |
| 1806 SetUpOverscrollEnvironment(); |
| 1807 |
| 1808 // Simulate wheel events. |
| 1809 SimulateWheelEvent(-5, 0, 0, true); // sent directly |
| 1810 SimulateWheelEvent(-1, 1, 0, true); // enqueued |
| 1811 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event |
| 1812 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event |
| 1813 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event |
| 1814 SimulateWheelEvent(-20, 6, 1, true); // enqueued, different modifiers |
| 1815 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 1816 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1817 |
| 1818 // Receive ACK the first wheel event as not processed. |
| 1819 SendInputEventACK(WebInputEvent::MouseWheel, |
| 1820 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1821 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 1822 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 1823 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1824 |
| 1825 // Receive ACK for the second (coalesced) event as not processed. This will |
| 1826 // start a back navigation. However, this will also cause the queued next |
| 1827 // event to be sent to the renderer. But since overscroll navigation has |
| 1828 // started, that event will also be included in the overscroll computation |
| 1829 // instead of being sent to the renderer. So the result will be an overscroll |
| 1830 // back navigation, and no event will be sent to the renderer. |
| 1831 SendInputEventACK(WebInputEvent::MouseWheel, |
| 1832 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1833 EXPECT_EQ(OVERSCROLL_WEST, overscroll_mode()); |
| 1834 EXPECT_EQ(OVERSCROLL_WEST, overscroll_delegate()->current_mode()); |
| 1835 EXPECT_EQ(-81.f, overscroll_delta_x()); |
| 1836 EXPECT_EQ(-31.f, overscroll_delegate()->delta_x()); |
| 1837 EXPECT_EQ(0.f, overscroll_delegate()->delta_y()); |
| 1838 EXPECT_EQ(0U, sink_->message_count()); |
| 1839 |
| 1840 // Send a mouse-move event. This should cancel the overscroll navigation. |
| 1841 SimulateMouseMove(5, 10, 0); |
| 1842 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 1843 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 1844 EXPECT_EQ(1U, sink_->message_count()); |
| 1845 } |
| 1846 |
| 1847 // Tests that if some scroll events are consumed towards the start, then |
| 1848 // subsequent scrolls do not horizontal overscroll. |
| 1849 TEST_F(RenderWidgetHostViewAuraOverscrollTest, |
| 1850 WheelScrollConsumedDoNotHorizOverscroll) { |
| 1851 SetUpOverscrollEnvironment(); |
| 1852 |
| 1853 // Simulate wheel events. |
| 1854 SimulateWheelEvent(-5, 0, 0, true); // sent directly |
| 1855 SimulateWheelEvent(-1, -1, 0, true); // enqueued |
| 1856 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event |
| 1857 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event |
| 1858 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event |
| 1859 SimulateWheelEvent(-20, 6, 1, true); // enqueued, different modifiers |
| 1860 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 1861 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1862 |
| 1863 // Receive ACK the first wheel event as processed. |
| 1864 SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1865 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 1866 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 1867 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1868 |
| 1869 // Receive ACK for the second (coalesced) event as not processed. This should |
| 1870 // not initiate overscroll, since the beginning of the scroll has been |
| 1871 // consumed. The queued event with different modifiers should be sent to the |
| 1872 // renderer. |
| 1873 SendInputEventACK(WebInputEvent::MouseWheel, |
| 1874 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1875 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 1876 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1877 |
| 1878 SendInputEventACK(WebInputEvent::MouseWheel, |
| 1879 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1880 EXPECT_EQ(0U, sink_->message_count()); |
| 1881 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 1882 |
| 1883 // Indicate the end of the scrolling from the touchpad. |
| 1884 SimulateGestureFlingStartEvent(-1200.f, 0.f, WebGestureEvent::Touchpad); |
| 1885 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1886 |
| 1887 // Start another scroll. This time, do not consume any scroll events. |
| 1888 SimulateWheelEvent(0, -5, 0, true); // sent directly |
| 1889 SimulateWheelEvent(0, -1, 0, true); // enqueued |
| 1890 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event |
| 1891 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event |
| 1892 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event |
| 1893 SimulateWheelEvent(-20, 6, 1, true); // enqueued, different modifiers |
| 1894 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 1895 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1896 |
| 1897 // Receive ACK for the first wheel and the subsequent coalesced event as not |
| 1898 // processed. This should start a back-overscroll. |
| 1899 SendInputEventACK(WebInputEvent::MouseWheel, |
| 1900 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1901 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 1902 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 1903 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1904 SendInputEventACK(WebInputEvent::MouseWheel, |
| 1905 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1906 EXPECT_EQ(OVERSCROLL_WEST, overscroll_mode()); |
| 1907 } |
| 1908 |
| 1909 // Tests that wheel-scrolling correctly turns overscroll on and off. |
| 1910 TEST_F(RenderWidgetHostViewAuraOverscrollTest, WheelScrollOverscrollToggle) { |
| 1911 SetUpOverscrollEnvironment(); |
| 1912 |
| 1913 // Send a wheel event. ACK the event as not processed. This should not |
| 1914 // initiate an overscroll gesture since it doesn't cross the threshold yet. |
| 1915 SimulateWheelEvent(10, 0, 0, true); |
| 1916 SendInputEventACK(WebInputEvent::MouseWheel, |
| 1917 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1918 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 1919 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 1920 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1921 |
| 1922 // Scroll some more so as to not overscroll. |
| 1923 SimulateWheelEvent(10, 0, 0, true); |
| 1924 SendInputEventACK(WebInputEvent::MouseWheel, |
| 1925 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1926 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 1927 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 1928 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1929 |
| 1930 // Scroll some more to initiate an overscroll. |
| 1931 SimulateWheelEvent(40, 0, 0, true); |
| 1932 SendInputEventACK(WebInputEvent::MouseWheel, |
| 1933 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1934 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode()); |
| 1935 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode()); |
| 1936 EXPECT_EQ(60.f, overscroll_delta_x()); |
| 1937 EXPECT_EQ(10.f, overscroll_delegate()->delta_x()); |
| 1938 EXPECT_EQ(0.f, overscroll_delegate()->delta_y()); |
| 1939 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1940 |
| 1941 // Scroll in the reverse direction enough to abort the overscroll. |
| 1942 SimulateWheelEvent(-20, 0, 0, true); |
| 1943 EXPECT_EQ(0U, sink_->message_count()); |
| 1944 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 1945 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 1946 |
| 1947 // Continue to scroll in the reverse direction. |
| 1948 SimulateWheelEvent(-20, 0, 0, true); |
| 1949 SendInputEventACK(WebInputEvent::MouseWheel, |
| 1950 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1951 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 1952 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 1953 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1954 |
| 1955 // Continue to scroll in the reverse direction enough to initiate overscroll |
| 1956 // in that direction. |
| 1957 SimulateWheelEvent(-55, 0, 0, true); |
| 1958 EXPECT_EQ(1U, sink_->message_count()); |
| 1959 SendInputEventACK(WebInputEvent::MouseWheel, |
| 1960 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1961 EXPECT_EQ(OVERSCROLL_WEST, overscroll_mode()); |
| 1962 EXPECT_EQ(OVERSCROLL_WEST, overscroll_delegate()->current_mode()); |
| 1963 EXPECT_EQ(-75.f, overscroll_delta_x()); |
| 1964 EXPECT_EQ(-25.f, overscroll_delegate()->delta_x()); |
| 1965 EXPECT_EQ(0.f, overscroll_delegate()->delta_y()); |
| 1966 } |
| 1967 |
| 1968 TEST_F(RenderWidgetHostViewAuraOverscrollTest, |
| 1969 ScrollEventsOverscrollWithFling) { |
| 1970 SetUpOverscrollEnvironment(); |
| 1971 |
| 1972 // Send a wheel event. ACK the event as not processed. This should not |
| 1973 // initiate an overscroll gesture since it doesn't cross the threshold yet. |
| 1974 SimulateWheelEvent(10, 0, 0, true); |
| 1975 SendInputEventACK(WebInputEvent::MouseWheel, |
| 1976 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1977 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 1978 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 1979 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1980 |
| 1981 // Scroll some more so as to not overscroll. |
| 1982 SimulateWheelEvent(20, 0, 0, true); |
| 1983 EXPECT_EQ(1U, sink_->message_count()); |
| 1984 SendInputEventACK(WebInputEvent::MouseWheel, |
| 1985 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1986 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 1987 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 1988 sink_->ClearMessages(); |
| 1989 |
| 1990 // Scroll some more to initiate an overscroll. |
| 1991 SimulateWheelEvent(30, 0, 0, true); |
| 1992 SendInputEventACK(WebInputEvent::MouseWheel, |
| 1993 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1994 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode()); |
| 1995 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode()); |
| 1996 EXPECT_EQ(60.f, overscroll_delta_x()); |
| 1997 EXPECT_EQ(10.f, overscroll_delegate()->delta_x()); |
| 1998 EXPECT_EQ(0.f, overscroll_delegate()->delta_y()); |
| 1999 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2000 |
| 2001 // Send a fling start, but with a small velocity, so that the overscroll is |
| 2002 // aborted. The fling should proceed to the renderer, through the gesture |
| 2003 // event filter. |
| 2004 SimulateGestureFlingStartEvent(0.f, 0.1f, WebGestureEvent::Touchpad); |
| 2005 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 2006 EXPECT_EQ(1U, sink_->message_count()); |
| 2007 } |
| 2008 |
| 2009 // Same as ScrollEventsOverscrollWithFling, but with zero velocity. Checks that |
| 2010 // the zero-velocity fling does not reach the renderer. |
| 2011 TEST_F(RenderWidgetHostViewAuraOverscrollTest, |
| 2012 ScrollEventsOverscrollWithZeroFling) { |
| 2013 SetUpOverscrollEnvironment(); |
| 2014 |
| 2015 // Send a wheel event. ACK the event as not processed. This should not |
| 2016 // initiate an overscroll gesture since it doesn't cross the threshold yet. |
| 2017 SimulateWheelEvent(10, 0, 0, true); |
| 2018 SendInputEventACK(WebInputEvent::MouseWheel, |
| 2019 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2020 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 2021 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 2022 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2023 |
| 2024 // Scroll some more so as to not overscroll. |
| 2025 SimulateWheelEvent(20, 0, 0, true); |
| 2026 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2027 SendInputEventACK(WebInputEvent::MouseWheel, |
| 2028 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2029 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 2030 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 2031 |
| 2032 // Scroll some more to initiate an overscroll. |
| 2033 SimulateWheelEvent(30, 0, 0, true); |
| 2034 SendInputEventACK(WebInputEvent::MouseWheel, |
| 2035 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2036 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode()); |
| 2037 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode()); |
| 2038 EXPECT_EQ(60.f, overscroll_delta_x()); |
| 2039 EXPECT_EQ(10.f, overscroll_delegate()->delta_x()); |
| 2040 EXPECT_EQ(0.f, overscroll_delegate()->delta_y()); |
| 2041 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2042 |
| 2043 // Send a fling start, but with a small velocity, so that the overscroll is |
| 2044 // aborted. The fling should proceed to the renderer, through the gesture |
| 2045 // event filter. |
| 2046 SimulateGestureFlingStartEvent(10.f, 0.f, WebGestureEvent::Touchpad); |
| 2047 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 2048 EXPECT_EQ(1U, sink_->message_count()); |
| 2049 } |
| 2050 |
| 2051 // Tests that a fling in the opposite direction of the overscroll cancels the |
| 2052 // overscroll nav instead of completing it. |
| 2053 TEST_F(RenderWidgetHostViewAuraOverscrollTest, ReverseFlingCancelsOverscroll) { |
| 2054 SetUpOverscrollEnvironment(); |
| 2055 |
| 2056 { |
| 2057 // Start and end a gesture in the same direction without processing the |
| 2058 // gesture events in the renderer. This should initiate and complete an |
| 2059 // overscroll navigation. |
| 2060 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 2061 WebGestureEvent::Touchscreen); |
| 2062 SimulateGestureScrollUpdateEvent(300, -5, 0); |
| 2063 SendInputEventACK(WebInputEvent::GestureScrollUpdate, |
| 2064 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2065 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode()); |
| 2066 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode()); |
| 2067 sink_->ClearMessages(); |
| 2068 |
| 2069 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, |
| 2070 WebGestureEvent::Touchscreen); |
| 2071 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->completed_mode()); |
| 2072 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 2073 EXPECT_EQ(1U, sink_->message_count()); |
| 2074 } |
| 2075 |
| 2076 { |
| 2077 // Start over, except instead of ending the gesture with ScrollEnd, end it |
| 2078 // with a FlingStart, with velocity in the reverse direction. This should |
| 2079 // initiate an overscroll navigation, but it should be cancelled because of |
| 2080 // the fling in the opposite direction. |
| 2081 overscroll_delegate()->Reset(); |
| 2082 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 2083 WebGestureEvent::Touchscreen); |
| 2084 SimulateGestureScrollUpdateEvent(-300, -5, 0); |
| 2085 SendInputEventACK(WebInputEvent::GestureScrollUpdate, |
| 2086 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2087 EXPECT_EQ(OVERSCROLL_WEST, overscroll_mode()); |
| 2088 EXPECT_EQ(OVERSCROLL_WEST, overscroll_delegate()->current_mode()); |
| 2089 sink_->ClearMessages(); |
| 2090 |
| 2091 SimulateGestureFlingStartEvent(100, 0, WebGestureEvent::Touchscreen); |
| 2092 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->completed_mode()); |
| 2093 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 2094 EXPECT_EQ(1U, sink_->message_count()); |
| 2095 } |
| 2096 } |
| 2097 |
| 2098 // Tests that touch-scroll events are handled correctly by the overscroll |
| 2099 // controller. This also tests that the overscroll controller and the |
| 2100 // gesture-event filter play nice with each other. |
| 2101 TEST_F(RenderWidgetHostViewAuraOverscrollTest, GestureScrollOverscrolls) { |
| 2102 SetUpOverscrollEnvironment(); |
| 2103 |
| 2104 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 2105 WebGestureEvent::Touchscreen); |
| 2106 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 2107 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 2108 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2109 |
| 2110 // Send another gesture event and ACK as not being processed. This should |
| 2111 // initiate the navigation gesture. |
| 2112 SimulateGestureScrollUpdateEvent(55, -5, 0); |
| 2113 SendInputEventACK(WebInputEvent::GestureScrollUpdate, |
| 2114 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2115 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode()); |
| 2116 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode()); |
| 2117 EXPECT_EQ(55.f, overscroll_delta_x()); |
| 2118 EXPECT_EQ(-5.f, overscroll_delta_y()); |
| 2119 EXPECT_EQ(5.f, overscroll_delegate()->delta_x()); |
| 2120 EXPECT_EQ(-5.f, overscroll_delegate()->delta_y()); |
| 2121 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2122 |
| 2123 // Send another gesture update event. This event should be consumed by the |
| 2124 // controller, and not be forwarded to the renderer. The gesture-event filter |
| 2125 // should not also receive this event. |
| 2126 SimulateGestureScrollUpdateEvent(10, -5, 0); |
| 2127 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode()); |
| 2128 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode()); |
| 2129 EXPECT_EQ(65.f, overscroll_delta_x()); |
| 2130 EXPECT_EQ(-10.f, overscroll_delta_y()); |
| 2131 EXPECT_EQ(15.f, overscroll_delegate()->delta_x()); |
| 2132 EXPECT_EQ(-10.f, overscroll_delegate()->delta_y()); |
| 2133 EXPECT_EQ(0U, sink_->message_count()); |
| 2134 |
| 2135 // Now send a scroll end. This should cancel the overscroll gesture, and send |
| 2136 // the event to the renderer. The gesture-event filter should receive this |
| 2137 // event. |
| 2138 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, |
| 2139 WebGestureEvent::Touchscreen); |
| 2140 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 2141 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 2142 EXPECT_EQ(1U, sink_->message_count()); |
| 2143 } |
| 2144 |
| 2145 // Tests that if the page is scrolled because of a scroll-gesture, then that |
| 2146 // particular scroll sequence never generates overscroll if the scroll direction |
| 2147 // is horizontal. |
| 2148 TEST_F(RenderWidgetHostViewAuraOverscrollTest, |
| 2149 GestureScrollConsumedHorizontal) { |
| 2150 SetUpOverscrollEnvironment(); |
| 2151 |
| 2152 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 2153 WebGestureEvent::Touchscreen); |
| 2154 SimulateGestureScrollUpdateEvent(10, 0, 0); |
| 2155 |
| 2156 // Start scrolling on content. ACK both events as being processed. |
| 2157 SendInputEventACK(WebInputEvent::GestureScrollUpdate, |
| 2158 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2159 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 2160 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 2161 sink_->ClearMessages(); |
| 2162 |
| 2163 // Send another gesture event and ACK as not being processed. This should |
| 2164 // not initiate overscroll because the beginning of the scroll event did |
| 2165 // scroll some content on the page. Since there was no overscroll, the event |
| 2166 // should reach the renderer. |
| 2167 SimulateGestureScrollUpdateEvent(55, 0, 0); |
| 2168 EXPECT_EQ(1U, sink_->message_count()); |
| 2169 SendInputEventACK(WebInputEvent::GestureScrollUpdate, |
| 2170 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2171 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 2172 } |
| 2173 |
| 2174 // Tests that the overscroll controller plays nice with touch-scrolls and the |
| 2175 // gesture event filter with debounce filtering turned on. |
| 2176 TEST_F(RenderWidgetHostViewAuraOverscrollTest, |
| 2177 GestureScrollDebounceOverscrolls) { |
| 2178 SetUpOverscrollEnvironmentWithDebounce(100); |
| 2179 |
| 2180 // Start scrolling. Receive ACK as it being processed. |
| 2181 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 2182 WebGestureEvent::Touchscreen); |
| 2183 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2184 |
| 2185 // Send update events. |
| 2186 SimulateGestureScrollUpdateEvent(25, 0, 0); |
| 2187 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2188 |
| 2189 // Quickly end and restart the scroll gesture. These two events should get |
| 2190 // discarded. |
| 2191 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, |
| 2192 WebGestureEvent::Touchscreen); |
| 2193 EXPECT_EQ(0U, sink_->message_count()); |
| 2194 |
| 2195 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 2196 WebGestureEvent::Touchscreen); |
| 2197 EXPECT_EQ(0U, sink_->message_count()); |
| 2198 |
| 2199 // Send another update event. This should get into the queue. |
| 2200 SimulateGestureScrollUpdateEvent(30, 0, 0); |
| 2201 EXPECT_EQ(0U, sink_->message_count()); |
| 2202 |
| 2203 // Receive an ACK for the first scroll-update event as not being processed. |
| 2204 // This will contribute to the overscroll gesture, but not enough for the |
| 2205 // overscroll controller to start consuming gesture events. This also cause |
| 2206 // the queued gesture event to be forwarded to the renderer. |
| 2207 SendInputEventACK(WebInputEvent::GestureScrollUpdate, |
| 2208 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2209 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 2210 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 2211 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2212 |
| 2213 // Send another update event. This should get into the queue. |
| 2214 SimulateGestureScrollUpdateEvent(10, 0, 0); |
| 2215 EXPECT_EQ(0U, sink_->message_count()); |
| 2216 |
| 2217 // Receive an ACK for the second scroll-update event as not being processed. |
| 2218 // This will now initiate an overscroll. This will also cause the queued |
| 2219 // gesture event to be released. But instead of going to the renderer, it will |
| 2220 // be consumed by the overscroll controller. |
| 2221 SendInputEventACK(WebInputEvent::GestureScrollUpdate, |
| 2222 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2223 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode()); |
| 2224 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode()); |
| 2225 EXPECT_EQ(65.f, overscroll_delta_x()); |
| 2226 EXPECT_EQ(15.f, overscroll_delegate()->delta_x()); |
| 2227 EXPECT_EQ(0.f, overscroll_delegate()->delta_y()); |
| 2228 EXPECT_EQ(0U, sink_->message_count()); |
| 2229 } |
| 2230 |
| 2231 // Tests that the gesture debounce timer plays nice with the overscroll |
| 2232 // controller. |
| 2233 TEST_F(RenderWidgetHostViewAuraOverscrollTest, |
| 2234 GestureScrollDebounceTimerOverscroll) { |
| 2235 SetUpOverscrollEnvironmentWithDebounce(10); |
| 2236 |
| 2237 // Start scrolling. Receive ACK as it being processed. |
| 2238 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 2239 WebGestureEvent::Touchscreen); |
| 2240 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2241 |
| 2242 // Send update events. |
| 2243 SimulateGestureScrollUpdateEvent(55, 0, 0); |
| 2244 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2245 |
| 2246 // Send an end event. This should get in the debounce queue. |
| 2247 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, |
| 2248 WebGestureEvent::Touchscreen); |
| 2249 EXPECT_EQ(0U, sink_->message_count()); |
| 2250 |
| 2251 // Receive ACK for the scroll-update event. |
| 2252 SendInputEventACK(WebInputEvent::GestureScrollUpdate, |
| 2253 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2254 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode()); |
| 2255 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode()); |
| 2256 EXPECT_EQ(55.f, overscroll_delta_x()); |
| 2257 EXPECT_EQ(5.f, overscroll_delegate()->delta_x()); |
| 2258 EXPECT_EQ(0.f, overscroll_delegate()->delta_y()); |
| 2259 EXPECT_EQ(0U, sink_->message_count()); |
| 2260 |
| 2261 // Let the timer for the debounce queue fire. That should release the queued |
| 2262 // scroll-end event. Since overscroll has started, but there hasn't been |
| 2263 // enough overscroll to complete the gesture, the overscroll controller |
| 2264 // will reset the state. The scroll-end should therefore be dispatched to the |
| 2265 // renderer, and the gesture-event-filter should await an ACK for it. |
| 2266 base::MessageLoop::current()->PostDelayedTask( |
| 2267 FROM_HERE, |
| 2268 base::MessageLoop::QuitClosure(), |
| 2269 base::TimeDelta::FromMilliseconds(15)); |
| 2270 base::MessageLoop::current()->Run(); |
| 2271 |
| 2272 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 2273 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 2274 EXPECT_EQ(1U, sink_->message_count()); |
| 2275 } |
| 2276 |
| 2277 // Tests that when touch-events are dispatched to the renderer, the overscroll |
| 2278 // gesture deals with them correctly. |
| 2279 TEST_F(RenderWidgetHostViewAuraOverscrollTest, OverscrollWithTouchEvents) { |
| 2280 SetUpOverscrollEnvironmentWithDebounce(10); |
| 2281 widget_host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); |
| 2282 sink_->ClearMessages(); |
| 2283 |
| 2284 // The test sends an intermingled sequence of touch and gesture events. |
| 2285 PressTouchPoint(0, 1); |
| 2286 SendInputEventACK(WebInputEvent::TouchStart, |
| 2287 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2288 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2289 |
| 2290 MoveTouchPoint(0, 20, 5); |
| 2291 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2292 SendInputEventACK(WebInputEvent::TouchMove, |
| 2293 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2294 |
| 2295 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 2296 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 2297 |
| 2298 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 2299 WebGestureEvent::Touchscreen); |
| 2300 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2301 SimulateGestureScrollUpdateEvent(20, 0, 0); |
| 2302 SendInputEventACK(WebInputEvent::GestureScrollUpdate, |
| 2303 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2304 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2305 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 2306 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 2307 |
| 2308 // Another touch move event should reach the renderer since overscroll hasn't |
| 2309 // started yet. Note that touch events sent during the scroll period may |
| 2310 // not require an ack (having been marked uncancelable). |
| 2311 MoveTouchPoint(0, 65, 10); |
| 2312 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2313 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2314 |
| 2315 SimulateGestureScrollUpdateEvent(45, 0, 0); |
| 2316 SendInputEventACK(WebInputEvent::GestureScrollUpdate, |
| 2317 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2318 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode()); |
| 2319 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode()); |
| 2320 EXPECT_EQ(65.f, overscroll_delta_x()); |
| 2321 EXPECT_EQ(15.f, overscroll_delegate()->delta_x()); |
| 2322 EXPECT_EQ(0.f, overscroll_delegate()->delta_y()); |
| 2323 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2324 |
| 2325 // Send another touch event. The page should get the touch-move event, even |
| 2326 // though overscroll has started. |
| 2327 MoveTouchPoint(0, 55, 5); |
| 2328 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode()); |
| 2329 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode()); |
| 2330 EXPECT_EQ(65.f, overscroll_delta_x()); |
| 2331 EXPECT_EQ(15.f, overscroll_delegate()->delta_x()); |
| 2332 EXPECT_EQ(0.f, overscroll_delegate()->delta_y()); |
| 2333 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2334 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2335 |
| 2336 SimulateGestureScrollUpdateEvent(-10, 0, 0); |
| 2337 EXPECT_EQ(0U, sink_->message_count()); |
| 2338 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode()); |
| 2339 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode()); |
| 2340 EXPECT_EQ(55.f, overscroll_delta_x()); |
| 2341 EXPECT_EQ(5.f, overscroll_delegate()->delta_x()); |
| 2342 EXPECT_EQ(0.f, overscroll_delegate()->delta_y()); |
| 2343 |
| 2344 PressTouchPoint(255, 5); |
| 2345 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2346 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2347 |
| 2348 SimulateGestureScrollUpdateEvent(200, 0, 0); |
| 2349 EXPECT_EQ(0U, sink_->message_count()); |
| 2350 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode()); |
| 2351 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode()); |
| 2352 EXPECT_EQ(255.f, overscroll_delta_x()); |
| 2353 EXPECT_EQ(205.f, overscroll_delegate()->delta_x()); |
| 2354 EXPECT_EQ(0.f, overscroll_delegate()->delta_y()); |
| 2355 |
| 2356 // The touch-end/cancel event should always reach the renderer if the page has |
| 2357 // touch handlers. |
| 2358 ReleaseTouchPoint(1); |
| 2359 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2360 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2361 ReleaseTouchPoint(0); |
| 2362 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2363 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2364 |
| 2365 SimulateGestureEvent(blink::WebInputEvent::GestureScrollEnd, |
| 2366 WebGestureEvent::Touchscreen); |
| 2367 base::MessageLoop::current()->PostDelayedTask( |
| 2368 FROM_HERE, |
| 2369 base::MessageLoop::QuitClosure(), |
| 2370 base::TimeDelta::FromMilliseconds(10)); |
| 2371 base::MessageLoop::current()->Run(); |
| 2372 EXPECT_EQ(1U, sink_->message_count()); |
| 2373 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 2374 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 2375 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->completed_mode()); |
| 2376 } |
| 2377 |
| 2378 // Tests that touch-gesture end is dispatched to the renderer at the end of a |
| 2379 // touch-gesture initiated overscroll. |
| 2380 TEST_F(RenderWidgetHostViewAuraOverscrollTest, |
| 2381 TouchGestureEndDispatchedAfterOverscrollComplete) { |
| 2382 SetUpOverscrollEnvironmentWithDebounce(10); |
| 2383 widget_host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); |
| 2384 sink_->ClearMessages(); |
| 2385 |
| 2386 // Start scrolling. Receive ACK as it being processed. |
| 2387 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 2388 WebGestureEvent::Touchscreen); |
| 2389 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2390 // The scroll begin event will have received a synthetic ack from the input |
| 2391 // router. |
| 2392 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 2393 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 2394 |
| 2395 // Send update events. |
| 2396 SimulateGestureScrollUpdateEvent(55, -5, 0); |
| 2397 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2398 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 2399 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 2400 |
| 2401 SendInputEventACK(WebInputEvent::GestureScrollUpdate, |
| 2402 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2403 EXPECT_EQ(0U, sink_->message_count()); |
| 2404 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode()); |
| 2405 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode()); |
| 2406 EXPECT_EQ(55.f, overscroll_delta_x()); |
| 2407 EXPECT_EQ(5.f, overscroll_delegate()->delta_x()); |
| 2408 EXPECT_EQ(-5.f, overscroll_delegate()->delta_y()); |
| 2409 |
| 2410 // Send end event. |
| 2411 SimulateGestureEvent(blink::WebInputEvent::GestureScrollEnd, |
| 2412 WebGestureEvent::Touchscreen); |
| 2413 EXPECT_EQ(0U, sink_->message_count()); |
| 2414 base::MessageLoop::current()->PostDelayedTask( |
| 2415 FROM_HERE, |
| 2416 base::MessageLoop::QuitClosure(), |
| 2417 base::TimeDelta::FromMilliseconds(10)); |
| 2418 base::MessageLoop::current()->Run(); |
| 2419 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 2420 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 2421 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->completed_mode()); |
| 2422 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2423 |
| 2424 // Start scrolling. Receive ACK as it being processed. |
| 2425 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 2426 WebGestureEvent::Touchscreen); |
| 2427 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2428 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 2429 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 2430 |
| 2431 // Send update events. |
| 2432 SimulateGestureScrollUpdateEvent(235, -5, 0); |
| 2433 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2434 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 2435 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 2436 |
| 2437 SendInputEventACK(WebInputEvent::GestureScrollUpdate, |
| 2438 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2439 EXPECT_EQ(0U, sink_->message_count()); |
| 2440 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode()); |
| 2441 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode()); |
| 2442 EXPECT_EQ(235.f, overscroll_delta_x()); |
| 2443 EXPECT_EQ(185.f, overscroll_delegate()->delta_x()); |
| 2444 EXPECT_EQ(-5.f, overscroll_delegate()->delta_y()); |
| 2445 |
| 2446 // Send end event. |
| 2447 SimulateGestureEvent(blink::WebInputEvent::GestureScrollEnd, |
| 2448 WebGestureEvent::Touchscreen); |
| 2449 EXPECT_EQ(0U, sink_->message_count()); |
| 2450 base::MessageLoop::current()->PostDelayedTask( |
| 2451 FROM_HERE, |
| 2452 base::MessageLoop::QuitClosure(), |
| 2453 base::TimeDelta::FromMilliseconds(10)); |
| 2454 base::MessageLoop::current()->Run(); |
| 2455 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 2456 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 2457 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->completed_mode()); |
| 2458 EXPECT_EQ(1U, sink_->message_count()); |
| 2459 } |
| 2460 |
| 2461 TEST_F(RenderWidgetHostViewAuraOverscrollTest, OverscrollDirectionChange) { |
| 2462 SetUpOverscrollEnvironmentWithDebounce(100); |
| 2463 |
| 2464 // Start scrolling. Receive ACK as it being processed. |
| 2465 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 2466 WebGestureEvent::Touchscreen); |
| 2467 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2468 |
| 2469 // Send update events and receive ack as not consumed. |
| 2470 SimulateGestureScrollUpdateEvent(125, -5, 0); |
| 2471 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2472 |
| 2473 SendInputEventACK(WebInputEvent::GestureScrollUpdate, |
| 2474 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2475 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode()); |
| 2476 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode()); |
| 2477 EXPECT_EQ(0U, sink_->message_count()); |
| 2478 |
| 2479 // Send another update event, but in the reverse direction. The overscroll |
| 2480 // controller will consume the event, and reset the overscroll mode. |
| 2481 SimulateGestureScrollUpdateEvent(-260, 0, 0); |
| 2482 EXPECT_EQ(0U, sink_->message_count()); |
| 2483 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 2484 |
| 2485 // Since the overscroll mode has been reset, the next scroll update events |
| 2486 // should reach the renderer. |
| 2487 SimulateGestureScrollUpdateEvent(-20, 0, 0); |
| 2488 EXPECT_EQ(1U, sink_->message_count()); |
| 2489 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 2490 } |
| 2491 |
| 2492 // Tests that if a mouse-move event completes the overscroll gesture, future |
| 2493 // move events do reach the renderer. |
| 2494 TEST_F(RenderWidgetHostViewAuraOverscrollTest, OverscrollMouseMoveCompletion) { |
| 2495 SetUpOverscrollEnvironment(); |
| 2496 |
| 2497 SimulateWheelEvent(5, 0, 0, true); // sent directly |
| 2498 SimulateWheelEvent(-1, 0, 0, true); // enqueued |
| 2499 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event |
| 2500 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event |
| 2501 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event |
| 2502 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 2503 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2504 |
| 2505 // Receive ACK the first wheel event as not processed. |
| 2506 SendInputEventACK(WebInputEvent::MouseWheel, |
| 2507 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2508 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 2509 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 2510 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2511 |
| 2512 // Receive ACK for the second (coalesced) event as not processed. This will |
| 2513 // start an overcroll gesture. |
| 2514 SendInputEventACK(WebInputEvent::MouseWheel, |
| 2515 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2516 EXPECT_EQ(OVERSCROLL_WEST, overscroll_mode()); |
| 2517 EXPECT_EQ(OVERSCROLL_WEST, overscroll_delegate()->current_mode()); |
| 2518 EXPECT_EQ(0U, sink_->message_count()); |
| 2519 |
| 2520 // Send a mouse-move event. This should cancel the overscroll navigation |
| 2521 // (since the amount overscrolled is not above the threshold), and so the |
| 2522 // mouse-move should reach the renderer. |
| 2523 SimulateMouseMove(5, 10, 0); |
| 2524 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 2525 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->completed_mode()); |
| 2526 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 2527 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2528 |
| 2529 SendInputEventACK(WebInputEvent::MouseMove, |
| 2530 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2531 |
| 2532 // Moving the mouse more should continue to send the events to the renderer. |
| 2533 SimulateMouseMove(5, 10, 0); |
| 2534 SendInputEventACK(WebInputEvent::MouseMove, |
| 2535 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2536 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2537 |
| 2538 // Now try with gestures. |
| 2539 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 2540 WebGestureEvent::Touchscreen); |
| 2541 SimulateGestureScrollUpdateEvent(300, -5, 0); |
| 2542 SendInputEventACK(WebInputEvent::GestureScrollUpdate, |
| 2543 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2544 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode()); |
| 2545 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode()); |
| 2546 sink_->ClearMessages(); |
| 2547 |
| 2548 // Overscroll gesture is in progress. Send a mouse-move now. This should |
| 2549 // complete the gesture (because the amount overscrolled is above the |
| 2550 // threshold). |
| 2551 SimulateMouseMove(5, 10, 0); |
| 2552 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->completed_mode()); |
| 2553 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 2554 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 2555 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2556 SendInputEventACK(WebInputEvent::MouseMove, |
| 2557 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2558 |
| 2559 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, |
| 2560 WebGestureEvent::Touchscreen); |
| 2561 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 2562 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2563 |
| 2564 // Move mouse some more. The mouse-move events should reach the renderer. |
| 2565 SimulateMouseMove(5, 10, 0); |
| 2566 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2567 |
| 2568 SendInputEventACK(WebInputEvent::MouseMove, |
| 2569 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2570 } |
| 2571 |
| 2572 // Tests that if a page scrolled, then the overscroll controller's states are |
| 2573 // reset after the end of the scroll. |
| 2574 TEST_F(RenderWidgetHostViewAuraOverscrollTest, |
| 2575 OverscrollStateResetsAfterScroll) { |
| 2576 SetUpOverscrollEnvironment(); |
| 2577 |
| 2578 SimulateWheelEvent(0, 5, 0, true); // sent directly |
| 2579 SimulateWheelEvent(0, 30, 0, true); // enqueued |
| 2580 SimulateWheelEvent(0, 40, 0, true); // coalesced into previous event |
| 2581 SimulateWheelEvent(0, 10, 0, true); // coalesced into previous event |
| 2582 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 2583 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2584 |
| 2585 // The first wheel event is consumed. Dispatches the queued wheel event. |
| 2586 SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2587 EXPECT_TRUE(ScrollStateIsContentScrolling()); |
| 2588 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2589 |
| 2590 // The second wheel event is consumed. |
| 2591 SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2592 EXPECT_TRUE(ScrollStateIsContentScrolling()); |
| 2593 |
| 2594 // Touchpad scroll can end with a zero-velocity fling. But it is not |
| 2595 // dispatched, but it should still reset the overscroll controller state. |
| 2596 SimulateGestureFlingStartEvent(0.f, 0.f, WebGestureEvent::Touchpad); |
| 2597 EXPECT_TRUE(ScrollStateIsUnknown()); |
| 2598 EXPECT_EQ(0U, sink_->message_count()); |
| 2599 |
| 2600 SimulateWheelEvent(-5, 0, 0, true); // sent directly |
| 2601 SimulateWheelEvent(-60, 0, 0, true); // enqueued |
| 2602 SimulateWheelEvent(-100, 0, 0, true); // coalesced into previous event |
| 2603 EXPECT_TRUE(ScrollStateIsUnknown()); |
| 2604 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2605 |
| 2606 // The first wheel scroll did not scroll content. Overscroll should not start |
| 2607 // yet, since enough hasn't been scrolled. |
| 2608 SendInputEventACK(WebInputEvent::MouseWheel, |
| 2609 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2610 EXPECT_TRUE(ScrollStateIsUnknown()); |
| 2611 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2612 |
| 2613 SendInputEventACK(WebInputEvent::MouseWheel, |
| 2614 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2615 EXPECT_EQ(OVERSCROLL_WEST, overscroll_mode()); |
| 2616 EXPECT_TRUE(ScrollStateIsOverscrolling()); |
| 2617 EXPECT_EQ(0U, sink_->message_count()); |
| 2618 |
| 2619 SimulateGestureFlingStartEvent(0.f, 0.f, WebGestureEvent::Touchpad); |
| 2620 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 2621 EXPECT_EQ(OVERSCROLL_WEST, overscroll_delegate()->completed_mode()); |
| 2622 EXPECT_TRUE(ScrollStateIsUnknown()); |
| 2623 EXPECT_EQ(0U, sink_->message_count()); |
| 2624 } |
| 2625 |
| 2626 TEST_F(RenderWidgetHostViewAuraOverscrollTest, OverscrollResetsOnBlur) { |
| 2627 SetUpOverscrollEnvironment(); |
| 2628 |
| 2629 // Start an overscroll with gesture scroll. In the middle of the scroll, blur |
| 2630 // the host. |
| 2631 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 2632 WebGestureEvent::Touchscreen); |
| 2633 SimulateGestureScrollUpdateEvent(300, -5, 0); |
| 2634 SendInputEventACK(WebInputEvent::GestureScrollUpdate, |
| 2635 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2636 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode()); |
| 2637 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode()); |
| 2638 EXPECT_EQ(2U, GetSentMessageCountAndResetSink()); |
| 2639 |
| 2640 view_->OnWindowFocused(NULL, view_->GetAttachedWindow()); |
| 2641 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 2642 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 2643 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->completed_mode()); |
| 2644 EXPECT_EQ(0.f, overscroll_delegate()->delta_x()); |
| 2645 EXPECT_EQ(0.f, overscroll_delegate()->delta_y()); |
| 2646 sink_->ClearMessages(); |
| 2647 |
| 2648 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, |
| 2649 WebGestureEvent::Touchscreen); |
| 2650 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2651 |
| 2652 // Start a scroll gesture again. This should correctly start the overscroll |
| 2653 // after the threshold. |
| 2654 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 2655 WebGestureEvent::Touchscreen); |
| 2656 SimulateGestureScrollUpdateEvent(300, -5, 0); |
| 2657 SendInputEventACK(WebInputEvent::GestureScrollUpdate, |
| 2658 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2659 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode()); |
| 2660 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode()); |
| 2661 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->completed_mode()); |
| 2662 |
| 2663 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, |
| 2664 WebGestureEvent::Touchscreen); |
| 2665 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 2666 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->completed_mode()); |
| 2667 EXPECT_EQ(3U, sink_->message_count()); |
| 2668 } |
| 2669 |
1522 } // namespace content | 2670 } // namespace content |
OLD | NEW |