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

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

Issue 291003002: Move OverscrollController to RenderWidgetHostViewAura (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 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/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
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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 public: 264 public:
199 FakeResizeLock(const gfx::Size new_size, bool defer_compositor_lock) 265 FakeResizeLock(const gfx::Size new_size, bool defer_compositor_lock)
200 : ResizeLock(new_size, defer_compositor_lock) {} 266 : ResizeLock(new_size, defer_compositor_lock) {}
201 }; 267 };
202 268
203 bool has_resize_lock_; 269 bool has_resize_lock_;
204 gfx::Size last_frame_size_; 270 gfx::Size last_frame_size_;
205 scoped_ptr<cc::CopyOutputRequest> last_copy_request_; 271 scoped_ptr<cc::CopyOutputRequest> last_copy_request_;
206 }; 272 };
207 273
274 // A layout manager that always resizes a child to the root window size.
275 class FullscreenLayoutManager : public aura::LayoutManager {
276 public:
277 explicit FullscreenLayoutManager(aura::Window* owner) : owner_(owner) {}
278 virtual ~FullscreenLayoutManager() {}
279
280 // Overridden from aura::LayoutManager:
281 virtual void OnWindowResized() OVERRIDE {
282 aura::Window::Windows::const_iterator i;
283 for (i = owner_->children().begin(); i != owner_->children().end(); ++i) {
284 (*i)->SetBounds(gfx::Rect());
285 }
286 }
287 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE {
288 child->SetBounds(gfx::Rect());
289 }
290 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {}
291 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {}
292 virtual void OnChildWindowVisibilityChanged(aura::Window* child,
293 bool visible) OVERRIDE {}
294 virtual void SetChildBounds(aura::Window* child,
295 const gfx::Rect& requested_bounds) OVERRIDE {
296 SetChildBoundsDirect(child, gfx::Rect(owner_->bounds().size()));
297 }
298
299 private:
300 aura::Window* owner_;
301 DISALLOW_COPY_AND_ASSIGN(FullscreenLayoutManager);
302 };
303
304 class MockWindowObserver : public aura::WindowObserver {
305 public:
306 MOCK_METHOD2(OnWindowPaintScheduled, void(aura::Window*, const gfx::Rect&));
307 };
308
309 } // namespace
310
208 class RenderWidgetHostViewAuraTest : public testing::Test { 311 class RenderWidgetHostViewAuraTest : public testing::Test {
209 public: 312 public:
210 RenderWidgetHostViewAuraTest() 313 RenderWidgetHostViewAuraTest()
211 : browser_thread_for_ui_(BrowserThread::UI, &message_loop_) {} 314 : browser_thread_for_ui_(BrowserThread::UI, &message_loop_) {}
212 315
213 void SetUpEnvironment() { 316 void SetUpEnvironment() {
214 ImageTransportFactory::InitializeForUnitTests( 317 ImageTransportFactory::InitializeForUnitTests(
215 scoped_ptr<ui::ContextFactory>(new ui::InProcessContextFactory)); 318 scoped_ptr<ui::ContextFactory>(new ui::InProcessContextFactory));
216 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); 319 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_));
217 aura_test_helper_->SetUp(); 320 aura_test_helper_->SetUp();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 // destruction. 378 // destruction.
276 RenderWidgetHostImpl* widget_host_; 379 RenderWidgetHostImpl* widget_host_;
277 FakeRenderWidgetHostViewAura* view_; 380 FakeRenderWidgetHostViewAura* view_;
278 381
279 IPC::TestSink* sink_; 382 IPC::TestSink* sink_;
280 383
281 private: 384 private:
282 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraTest); 385 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraTest);
283 }; 386 };
284 387
388 class RenderWidgetHostViewAuraOverscrollTest
389 : public RenderWidgetHostViewAuraTest {
390 public:
391 RenderWidgetHostViewAuraOverscrollTest() {}
392
393 // We explicitly invoke SetUp to allow gesture debounce customization.
394 virtual void SetUp() {}
395
396 protected:
397 void SetUpOverscrollEnvironmentWithDebounce(int debounce_interval_in_ms) {
398 SetUpOverscrollEnvironmentImpl(debounce_interval_in_ms);
399 }
400
401 void SetUpOverscrollEnvironment() { SetUpOverscrollEnvironmentImpl(0); }
402
403 void SetUpOverscrollEnvironmentImpl(int debounce_interval_in_ms) {
404 ui::GestureConfiguration::set_scroll_debounce_interval_in_ms(
405 debounce_interval_in_ms);
406
407 RenderWidgetHostViewAuraTest::SetUp();
408
409 view_->SetOverscrollControllerEnabled(true);
410 overscroll_delegate_.reset(new TestOverscrollDelegate(view_));
411 view_->overscroll_controller()->set_delegate(overscroll_delegate_.get());
412
413 view_->InitAsChild(NULL);
414 aura::client::ParentWindowWithContext(
415 view_->GetNativeView(),
416 parent_view_->GetNativeView()->GetRootWindow(),
417 gfx::Rect());
418 view_->SetBounds(gfx::Rect(0, 0, 400, 200));
419 view_->Show();
420
421 sink_->ClearMessages();
422 }
423
424 // TODO(jdduke): Simulate ui::Events, injecting through the view.
425 void SimulateMouseEvent(WebInputEvent::Type type) {
426 widget_host_->ForwardMouseEvent(SyntheticWebMouseEventBuilder::Build(type));
427 }
428
429 void SimulateMouseEventWithLatencyInfo(WebInputEvent::Type type,
430 const ui::LatencyInfo& ui_latency) {
431 widget_host_->ForwardMouseEventWithLatencyInfo(
432 SyntheticWebMouseEventBuilder::Build(type), ui_latency);
433 }
434
435 void SimulateWheelEvent(float dX, float dY, int modifiers, bool precise) {
436 widget_host_->ForwardWheelEvent(
437 SyntheticWebMouseWheelEventBuilder::Build(dX, dY, modifiers, precise));
438 }
439
440 void SimulateWheelEventWithLatencyInfo(float dX,
441 float dY,
442 int modifiers,
443 bool precise,
444 const ui::LatencyInfo& ui_latency) {
445 widget_host_->ForwardWheelEventWithLatencyInfo(
446 SyntheticWebMouseWheelEventBuilder::Build(dX, dY, modifiers, precise),
447 ui_latency);
448 }
449
450 void SimulateMouseMove(int x, int y, int modifiers) {
451 SimulateMouseEvent(WebInputEvent::MouseMove, x, y, modifiers, false);
452 }
453
454 void SimulateMouseEvent(WebInputEvent::Type type,
455 int x,
456 int y,
457 int modifiers,
458 bool pressed) {
459 WebMouseEvent event =
460 SyntheticWebMouseEventBuilder::Build(type, x, y, modifiers);
461 if (pressed)
462 event.button = WebMouseEvent::ButtonLeft;
463 widget_host_->ForwardMouseEvent(event);
464 }
465
466 void SimulateWheelEventWithPhase(WebMouseWheelEvent::Phase phase) {
467 widget_host_->ForwardWheelEvent(
468 SyntheticWebMouseWheelEventBuilder::Build(phase));
469 }
470
471 // Inject provided synthetic WebGestureEvent instance.
472 void SimulateGestureEventCore(const WebGestureEvent& gesture_event) {
473 widget_host_->ForwardGestureEvent(gesture_event);
474 }
475
476 void SimulateGestureEventCoreWithLatencyInfo(
477 const WebGestureEvent& gesture_event,
478 const ui::LatencyInfo& ui_latency) {
479 widget_host_->ForwardGestureEventWithLatencyInfo(gesture_event, ui_latency);
480 }
481
482 // Inject simple synthetic WebGestureEvent instances.
483 void SimulateGestureEvent(WebInputEvent::Type type,
484 WebGestureEvent::SourceDevice sourceDevice) {
485 SimulateGestureEventCore(
486 SyntheticWebGestureEventBuilder::Build(type, sourceDevice));
487 }
488
489 void SimulateGestureEventWithLatencyInfo(
490 WebInputEvent::Type type,
491 WebGestureEvent::SourceDevice sourceDevice,
492 const ui::LatencyInfo& ui_latency) {
493 SimulateGestureEventCoreWithLatencyInfo(
494 SyntheticWebGestureEventBuilder::Build(type, sourceDevice), ui_latency);
495 }
496
497 void SimulateGestureScrollUpdateEvent(float dX, float dY, int modifiers) {
498 SimulateGestureEventCore(
499 SyntheticWebGestureEventBuilder::BuildScrollUpdate(dX, dY, modifiers));
500 }
501
502 void SimulateGesturePinchUpdateEvent(float scale,
503 float anchorX,
504 float anchorY,
505 int modifiers) {
506 SimulateGestureEventCore(SyntheticWebGestureEventBuilder::BuildPinchUpdate(
507 scale, anchorX, anchorY, modifiers, WebGestureEvent::Touchscreen));
508 }
509
510 // Inject synthetic GestureFlingStart events.
511 void SimulateGestureFlingStartEvent(
512 float velocityX,
513 float velocityY,
514 WebGestureEvent::SourceDevice sourceDevice) {
515 SimulateGestureEventCore(SyntheticWebGestureEventBuilder::BuildFling(
516 velocityX, velocityY, sourceDevice));
517 }
518
519 void SendInputEventACK(WebInputEvent::Type type,
520 InputEventAckState ack_result) {
521 InputHostMsg_HandleInputEvent_ACK_Params ack;
522 ack.type = type;
523 ack.state = ack_result;
524 InputHostMsg_HandleInputEvent_ACK response(0, ack);
525 widget_host_->OnMessageReceived(response);
526 }
527
528 bool ScrollStateIsContentScrolling() const {
529 return scroll_state() == OverscrollController::STATE_CONTENT_SCROLLING;
530 }
531
532 bool ScrollStateIsOverscrolling() const {
533 return scroll_state() == OverscrollController::STATE_OVERSCROLLING;
534 }
535
536 bool ScrollStateIsUnknown() const {
537 return scroll_state() == OverscrollController::STATE_UNKNOWN;
538 }
539
540 OverscrollController::ScrollState scroll_state() const {
541 return view_->overscroll_controller()->scroll_state_;
542 }
543
544 OverscrollMode overscroll_mode() const {
545 return view_->overscroll_controller()->overscroll_mode_;
546 }
547
548 float overscroll_delta_x() const {
549 return view_->overscroll_controller()->overscroll_delta_x_;
550 }
551
552 float overscroll_delta_y() const {
553 return view_->overscroll_controller()->overscroll_delta_y_;
554 }
555
556 TestOverscrollDelegate* overscroll_delegate() {
557 return overscroll_delegate_.get();
558 }
559
560 void SendTouchEvent() {
561 widget_host_->ForwardTouchEventWithLatencyInfo(touch_event_,
562 ui::LatencyInfo());
563 touch_event_.ResetPoints();
564 }
565
566 void PressTouchPoint(int x, int y) {
567 touch_event_.PressPoint(x, y);
568 SendTouchEvent();
569 }
570
571 void MoveTouchPoint(int index, int x, int y) {
572 touch_event_.MovePoint(index, x, y);
573 SendTouchEvent();
574 }
575
576 void ReleaseTouchPoint(int index) {
577 touch_event_.ReleasePoint(index);
578 SendTouchEvent();
579 }
580
581 SyntheticWebTouchEvent touch_event_;
582
583 scoped_ptr<TestOverscrollDelegate> overscroll_delegate_;
584
585 private:
586 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraOverscrollTest);
587 };
588
285 class RenderWidgetHostViewAuraShutdownTest 589 class RenderWidgetHostViewAuraShutdownTest
286 : public RenderWidgetHostViewAuraTest { 590 : public RenderWidgetHostViewAuraTest {
287 public: 591 public:
288 RenderWidgetHostViewAuraShutdownTest() {} 592 RenderWidgetHostViewAuraShutdownTest() {}
289 593
290 virtual void TearDown() OVERRIDE { 594 virtual void TearDown() OVERRIDE {
291 // No TearDownEnvironment here, we do this explicitly during the test. 595 // No TearDownEnvironment here, we do this explicitly during the test.
292 } 596 }
293 597
294 private: 598 private:
295 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraShutdownTest); 599 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraShutdownTest);
296 }; 600 };
297 601
298 // A layout manager that always resizes a child to the root window size.
299 class FullscreenLayoutManager : public aura::LayoutManager {
300 public:
301 explicit FullscreenLayoutManager(aura::Window* owner)
302 : owner_(owner) {}
303 virtual ~FullscreenLayoutManager() {}
304
305 // Overridden from aura::LayoutManager:
306 virtual void OnWindowResized() OVERRIDE {
307 aura::Window::Windows::const_iterator i;
308 for (i = owner_->children().begin(); i != owner_->children().end(); ++i) {
309 (*i)->SetBounds(gfx::Rect());
310 }
311 }
312 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE {
313 child->SetBounds(gfx::Rect());
314 }
315 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {
316 }
317 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {
318 }
319 virtual void OnChildWindowVisibilityChanged(aura::Window* child,
320 bool visible) OVERRIDE {
321 }
322 virtual void SetChildBounds(aura::Window* child,
323 const gfx::Rect& requested_bounds) OVERRIDE {
324 SetChildBoundsDirect(child, gfx::Rect(owner_->bounds().size()));
325 }
326
327 private:
328 aura::Window* owner_;
329 DISALLOW_COPY_AND_ASSIGN(FullscreenLayoutManager);
330 };
331
332 class MockWindowObserver : public aura::WindowObserver {
333 public:
334 MOCK_METHOD2(OnWindowPaintScheduled, void(aura::Window*, const gfx::Rect&));
335 };
336
337 } // namespace
338
339 // Checks that a fullscreen view has the correct show-state and receives the 602 // Checks that a fullscreen view has the correct show-state and receives the
340 // focus. 603 // focus.
341 TEST_F(RenderWidgetHostViewAuraTest, FocusFullscreen) { 604 TEST_F(RenderWidgetHostViewAuraTest, FocusFullscreen) {
342 view_->InitAsFullscreen(parent_view_); 605 view_->InitAsFullscreen(parent_view_);
343 aura::Window* window = view_->GetNativeView(); 606 aura::Window* window = view_->GetNativeView();
344 ASSERT_TRUE(window != NULL); 607 ASSERT_TRUE(window != NULL);
345 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, 608 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN,
346 window->GetProperty(aura::client::kShowStateKey)); 609 window->GetProperty(aura::client::kShowStateKey));
347 610
348 // Check that we requested and received the focus. 611 // Check that we requested and received the focus.
(...skipping 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after
1413 1676
1414 const IPC::Message *message = sink_->GetFirstMessageMatching( 1677 const IPC::Message *message = sink_->GetFirstMessageMatching(
1415 ViewMsg_Resize::ID); 1678 ViewMsg_Resize::ID);
1416 ASSERT_TRUE(message != NULL); 1679 ASSERT_TRUE(message != NULL);
1417 1680
1418 ViewMsg_Resize::Param params; 1681 ViewMsg_Resize::Param params;
1419 ViewMsg_Resize::Read(message, &params); 1682 ViewMsg_Resize::Read(message, &params);
1420 EXPECT_EQ(60, params.a.visible_viewport_size.height()); 1683 EXPECT_EQ(60, params.a.visible_viewport_size.height());
1421 } 1684 }
1422 1685
1686 // Tests that scroll ACKs are correctly handled by the overscroll-navigation
1687 // controller.
1688 TEST_F(RenderWidgetHostViewAuraOverscrollTest, WheelScrollEventOverscrolls) {
1689 SetUpOverscrollEnvironment();
1690
1691 // Simulate wheel events.
1692 SimulateWheelEvent(-5, 0, 0, true); // sent directly
1693 SimulateWheelEvent(-1, 1, 0, true); // enqueued
1694 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
1695 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
1696 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
1697 SimulateWheelEvent(-20, 6, 1, true); // enqueued, different modifiers
1698 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
1699 EXPECT_EQ(1U, sink_->message_count());
1700 sink_->ClearMessages();
1701
1702 // Receive ACK the first wheel event as not processed.
1703 SendInputEventACK(WebInputEvent::MouseWheel,
1704 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1705 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
1706 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
1707 EXPECT_EQ(1U, sink_->message_count());
1708 sink_->ClearMessages();
1709
1710 // Receive ACK for the second (coalesced) event as not processed. This will
1711 // start a back navigation. However, this will also cause the queued next
1712 // event to be sent to the renderer. But since overscroll navigation has
1713 // started, that event will also be included in the overscroll computation
1714 // instead of being sent to the renderer. So the result will be an overscroll
1715 // back navigation, and no event will be sent to the renderer.
1716 SendInputEventACK(WebInputEvent::MouseWheel,
1717 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1718 EXPECT_EQ(OVERSCROLL_WEST, overscroll_mode());
1719 EXPECT_EQ(OVERSCROLL_WEST, overscroll_delegate()->current_mode());
1720 EXPECT_EQ(-81.f, overscroll_delta_x());
1721 EXPECT_EQ(-31.f, overscroll_delegate()->delta_x());
1722 EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
1723 EXPECT_EQ(0U, sink_->message_count());
1724
1725 // Send a mouse-move event. This should cancel the overscroll navigation.
1726 SimulateMouseMove(5, 10, 0);
1727 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
1728 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
1729 EXPECT_EQ(1U, sink_->message_count());
1730 }
1731
1732 // Tests that if some scroll events are consumed towards the start, then
1733 // subsequent scrolls do not horizontal overscroll.
1734 TEST_F(RenderWidgetHostViewAuraOverscrollTest,
1735 WheelScrollConsumedDoNotHorizOverscroll) {
1736 SetUpOverscrollEnvironment();
1737
1738 // Simulate wheel events.
1739 SimulateWheelEvent(-5, 0, 0, true); // sent directly
1740 SimulateWheelEvent(-1, -1, 0, true); // enqueued
1741 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
1742 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
1743 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
1744 SimulateWheelEvent(-20, 6, 1, true); // enqueued, different modifiers
1745 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
1746 EXPECT_EQ(1U, sink_->message_count());
1747 sink_->ClearMessages();
1748
1749 // Receive ACK the first wheel event as processed.
1750 SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED);
1751 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
1752 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
1753 EXPECT_EQ(1U, sink_->message_count());
1754 sink_->ClearMessages();
1755
1756 // Receive ACK for the second (coalesced) event as not processed. This should
1757 // not initiate overscroll, since the beginning of the scroll has been
1758 // consumed. The queued event with different modifiers should be sent to the
1759 // renderer.
1760 SendInputEventACK(WebInputEvent::MouseWheel,
1761 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1762 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
1763 EXPECT_EQ(1U, sink_->message_count());
1764
1765 sink_->ClearMessages();
1766 SendInputEventACK(WebInputEvent::MouseWheel,
1767 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1768 EXPECT_EQ(0U, sink_->message_count());
1769 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
1770
1771 // Indicate the end of the scrolling from the touchpad.
1772 SimulateGestureFlingStartEvent(-1200.f, 0.f, WebGestureEvent::Touchpad);
1773 EXPECT_EQ(1U, sink_->message_count());
1774
1775 // Start another scroll. This time, do not consume any scroll events.
1776 sink_->ClearMessages();
1777 SimulateWheelEvent(0, -5, 0, true); // sent directly
1778 SimulateWheelEvent(0, -1, 0, true); // enqueued
1779 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
1780 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
1781 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
1782 SimulateWheelEvent(-20, 6, 1, true); // enqueued, different modifiers
1783 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
1784 EXPECT_EQ(1U, sink_->message_count());
1785 sink_->ClearMessages();
1786
1787 // Receive ACK for the first wheel and the subsequent coalesced event as not
1788 // processed. This should start a back-overscroll.
1789 SendInputEventACK(WebInputEvent::MouseWheel,
1790 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1791 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
1792 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
1793 EXPECT_EQ(1U, sink_->message_count());
1794 sink_->ClearMessages();
1795 SendInputEventACK(WebInputEvent::MouseWheel,
1796 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1797 EXPECT_EQ(OVERSCROLL_WEST, overscroll_mode());
1798 }
1799
1800 // Tests that wheel-scrolling correctly turns overscroll on and off.
1801 TEST_F(RenderWidgetHostViewAuraOverscrollTest, WheelScrollOverscrollToggle) {
1802 SetUpOverscrollEnvironment();
1803
1804 // Send a wheel event. ACK the event as not processed. This should not
1805 // initiate an overscroll gesture since it doesn't cross the threshold yet.
1806 SimulateWheelEvent(10, 0, 0, true);
1807 EXPECT_EQ(1U, sink_->message_count());
1808 SendInputEventACK(WebInputEvent::MouseWheel,
1809 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1810 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
1811 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
1812 sink_->ClearMessages();
1813
1814 // Scroll some more so as to not overscroll.
1815 SimulateWheelEvent(10, 0, 0, true);
1816 EXPECT_EQ(1U, sink_->message_count());
1817 SendInputEventACK(WebInputEvent::MouseWheel,
1818 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1819 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
1820 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
1821 sink_->ClearMessages();
1822
1823 // Scroll some more to initiate an overscroll.
1824 SimulateWheelEvent(40, 0, 0, true);
1825 EXPECT_EQ(1U, sink_->message_count());
1826 SendInputEventACK(WebInputEvent::MouseWheel,
1827 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1828 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
1829 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
1830 EXPECT_EQ(60.f, overscroll_delta_x());
1831 EXPECT_EQ(10.f, overscroll_delegate()->delta_x());
1832 EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
1833 sink_->ClearMessages();
1834
1835 // Scroll in the reverse direction enough to abort the overscroll.
1836 SimulateWheelEvent(-20, 0, 0, true);
1837 EXPECT_EQ(0U, sink_->message_count());
1838 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
1839 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
1840
1841 // Continue to scroll in the reverse direction.
1842 SimulateWheelEvent(-20, 0, 0, true);
1843 EXPECT_EQ(1U, sink_->message_count());
1844 SendInputEventACK(WebInputEvent::MouseWheel,
1845 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1846 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
1847 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
1848 sink_->ClearMessages();
1849
1850 // Continue to scroll in the reverse direction enough to initiate overscroll
1851 // in that direction.
1852 SimulateWheelEvent(-55, 0, 0, true);
1853 EXPECT_EQ(1U, sink_->message_count());
1854 SendInputEventACK(WebInputEvent::MouseWheel,
1855 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1856 EXPECT_EQ(OVERSCROLL_WEST, overscroll_mode());
1857 EXPECT_EQ(OVERSCROLL_WEST, overscroll_delegate()->current_mode());
1858 EXPECT_EQ(-75.f, overscroll_delta_x());
1859 EXPECT_EQ(-25.f, overscroll_delegate()->delta_x());
1860 EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
1861 }
1862
1863 TEST_F(RenderWidgetHostViewAuraOverscrollTest,
1864 ScrollEventsOverscrollWithFling) {
1865 SetUpOverscrollEnvironment();
1866
1867 // Send a wheel event. ACK the event as not processed. This should not
1868 // initiate an overscroll gesture since it doesn't cross the threshold yet.
1869 SimulateWheelEvent(10, 0, 0, true);
1870 EXPECT_EQ(1U, sink_->message_count());
1871 SendInputEventACK(WebInputEvent::MouseWheel,
1872 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1873 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
1874 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
1875 sink_->ClearMessages();
1876
1877 // Scroll some more so as to not overscroll.
1878 SimulateWheelEvent(20, 0, 0, true);
1879 EXPECT_EQ(1U, sink_->message_count());
1880 SendInputEventACK(WebInputEvent::MouseWheel,
1881 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1882 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
1883 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
1884 sink_->ClearMessages();
1885
1886 // Scroll some more to initiate an overscroll.
1887 SimulateWheelEvent(30, 0, 0, true);
1888 EXPECT_EQ(1U, sink_->message_count());
1889 SendInputEventACK(WebInputEvent::MouseWheel,
1890 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1891 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
1892 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
1893 EXPECT_EQ(60.f, overscroll_delta_x());
1894 EXPECT_EQ(10.f, overscroll_delegate()->delta_x());
1895 EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
1896 sink_->ClearMessages();
1897
1898 // Send a fling start, but with a small velocity, so that the overscroll is
1899 // aborted. The fling should proceed to the renderer, through the gesture
1900 // event filter.
1901 SimulateGestureFlingStartEvent(0.f, 0.1f, WebGestureEvent::Touchpad);
1902 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
1903 EXPECT_EQ(1U, sink_->message_count());
1904 }
1905
1906 // Same as ScrollEventsOverscrollWithFling, but with zero velocity. Checks that
1907 // the zero-velocity fling does not reach the renderer.
1908 TEST_F(RenderWidgetHostViewAuraOverscrollTest,
1909 ScrollEventsOverscrollWithZeroFling) {
1910 SetUpOverscrollEnvironment();
1911
1912 // Send a wheel event. ACK the event as not processed. This should not
1913 // initiate an overscroll gesture since it doesn't cross the threshold yet.
1914 SimulateWheelEvent(10, 0, 0, true);
1915 EXPECT_EQ(1U, sink_->message_count());
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 sink_->ClearMessages();
1921
1922 // Scroll some more so as to not overscroll.
1923 SimulateWheelEvent(20, 0, 0, true);
1924 EXPECT_EQ(1U, sink_->message_count());
1925 SendInputEventACK(WebInputEvent::MouseWheel,
1926 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1927 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
1928 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
1929 sink_->ClearMessages();
1930
1931 // Scroll some more to initiate an overscroll.
1932 SimulateWheelEvent(30, 0, 0, true);
1933 EXPECT_EQ(1U, sink_->message_count());
1934 SendInputEventACK(WebInputEvent::MouseWheel,
1935 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1936 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
1937 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
1938 EXPECT_EQ(60.f, overscroll_delta_x());
1939 EXPECT_EQ(10.f, overscroll_delegate()->delta_x());
1940 EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
1941 sink_->ClearMessages();
1942
1943 // Send a fling start, but with a small velocity, so that the overscroll is
1944 // aborted. The fling should proceed to the renderer, through the gesture
1945 // event filter.
1946 SimulateGestureFlingStartEvent(10.f, 0.f, WebGestureEvent::Touchpad);
1947 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
1948 EXPECT_EQ(1U, sink_->message_count());
1949 }
1950
1951 // Tests that a fling in the opposite direction of the overscroll cancels the
1952 // overscroll nav instead of completing it.
1953 TEST_F(RenderWidgetHostViewAuraOverscrollTest, ReverseFlingCancelsOverscroll) {
1954 SetUpOverscrollEnvironment();
1955
1956 {
1957 // Start and end a gesture in the same direction without processing the
1958 // gesture events in the renderer. This should initiate and complete an
1959 // overscroll navigation.
1960 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
1961 WebGestureEvent::Touchscreen);
1962 SimulateGestureScrollUpdateEvent(300, -5, 0);
1963 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
1964 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1965 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
1966 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
1967 sink_->ClearMessages();
1968
1969 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
1970 WebGestureEvent::Touchscreen);
1971 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->completed_mode());
1972 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
1973 EXPECT_EQ(1U, sink_->message_count());
1974 }
1975
1976 {
1977 // Start over, except instead of ending the gesture with ScrollEnd, end it
1978 // with a FlingStart, with velocity in the reverse direction. This should
1979 // initiate an overscroll navigation, but it should be cancelled because of
1980 // the fling in the opposite direction.
1981 overscroll_delegate()->Reset();
1982 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
1983 WebGestureEvent::Touchscreen);
1984 SimulateGestureScrollUpdateEvent(-300, -5, 0);
1985 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
1986 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1987 EXPECT_EQ(OVERSCROLL_WEST, overscroll_mode());
1988 EXPECT_EQ(OVERSCROLL_WEST, overscroll_delegate()->current_mode());
1989 sink_->ClearMessages();
1990
1991 SimulateGestureFlingStartEvent(100, 0, WebGestureEvent::Touchscreen);
1992 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->completed_mode());
1993 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
1994 EXPECT_EQ(1U, sink_->message_count());
1995 }
1996 }
1997
1998 // Tests that touch-scroll events are handled correctly by the overscroll
1999 // controller. This also tests that the overscroll controller and the
2000 // gesture-event filter play nice with each other.
2001 TEST_F(RenderWidgetHostViewAuraOverscrollTest, GestureScrollOverscrolls) {
2002 SetUpOverscrollEnvironment();
2003
2004 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2005 WebGestureEvent::Touchscreen);
2006 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2007 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2008 EXPECT_EQ(1U, sink_->message_count());
2009 sink_->ClearMessages();
2010
2011 // Send another gesture event and ACK as not being processed. This should
2012 // initiate the navigation gesture.
2013 SimulateGestureScrollUpdateEvent(55, -5, 0);
2014 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2015 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2016 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2017 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2018 EXPECT_EQ(55.f, overscroll_delta_x());
2019 EXPECT_EQ(-5.f, overscroll_delta_y());
2020 EXPECT_EQ(5.f, overscroll_delegate()->delta_x());
2021 EXPECT_EQ(-5.f, overscroll_delegate()->delta_y());
2022 EXPECT_EQ(1U, sink_->message_count());
2023 sink_->ClearMessages();
2024
2025 // Send another gesture update event. This event should be consumed by the
2026 // controller, and not be forwarded to the renderer. The gesture-event filter
2027 // should not also receive this event.
2028 SimulateGestureScrollUpdateEvent(10, -5, 0);
2029 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2030 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2031 EXPECT_EQ(65.f, overscroll_delta_x());
2032 EXPECT_EQ(-10.f, overscroll_delta_y());
2033 EXPECT_EQ(15.f, overscroll_delegate()->delta_x());
2034 EXPECT_EQ(-10.f, overscroll_delegate()->delta_y());
2035 EXPECT_EQ(0U, sink_->message_count());
2036
2037 // Now send a scroll end. This should cancel the overscroll gesture, and send
2038 // the event to the renderer. The gesture-event filter should receive this
2039 // event.
2040 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
2041 WebGestureEvent::Touchscreen);
2042 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2043 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2044 EXPECT_EQ(1U, sink_->message_count());
2045 }
2046
2047 // Tests that if the page is scrolled because of a scroll-gesture, then that
2048 // particular scroll sequence never generates overscroll if the scroll direction
2049 // is horizontal.
2050 TEST_F(RenderWidgetHostViewAuraOverscrollTest,
2051 GestureScrollConsumedHorizontal) {
2052 SetUpOverscrollEnvironment();
2053
2054 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2055 WebGestureEvent::Touchscreen);
2056 SimulateGestureScrollUpdateEvent(10, 0, 0);
2057
2058 // Start scrolling on content. ACK both events as being processed.
2059 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2060 INPUT_EVENT_ACK_STATE_CONSUMED);
2061 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2062 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2063 sink_->ClearMessages();
2064
2065 // Send another gesture event and ACK as not being processed. This should
2066 // not initiate overscroll because the beginning of the scroll event did
2067 // scroll some content on the page. Since there was no overscroll, the event
2068 // should reach the renderer.
2069 SimulateGestureScrollUpdateEvent(55, 0, 0);
2070 EXPECT_EQ(1U, sink_->message_count());
2071 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2072 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2073 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2074 }
2075
2076 // Tests that the overscroll controller plays nice with touch-scrolls and the
2077 // gesture event filter with debounce filtering turned on.
2078 TEST_F(RenderWidgetHostViewAuraOverscrollTest,
2079 GestureScrollDebounceOverscrolls) {
2080 SetUpOverscrollEnvironmentWithDebounce(100);
2081
2082 // Start scrolling. Receive ACK as it being processed.
2083 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2084 WebGestureEvent::Touchscreen);
2085 EXPECT_EQ(1U, sink_->message_count());
2086 sink_->ClearMessages();
2087
2088 // Send update events.
2089 SimulateGestureScrollUpdateEvent(25, 0, 0);
2090 EXPECT_EQ(1U, sink_->message_count());
2091 sink_->ClearMessages();
2092
2093 // Quickly end and restart the scroll gesture. These two events should get
2094 // discarded.
2095 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
2096 WebGestureEvent::Touchscreen);
2097 EXPECT_EQ(0U, sink_->message_count());
2098
2099 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2100 WebGestureEvent::Touchscreen);
2101 EXPECT_EQ(0U, sink_->message_count());
2102
2103 // Send another update event. This should get into the queue.
2104 SimulateGestureScrollUpdateEvent(30, 0, 0);
2105 EXPECT_EQ(0U, sink_->message_count());
2106
2107 // Receive an ACK for the first scroll-update event as not being processed.
2108 // This will contribute to the overscroll gesture, but not enough for the
2109 // overscroll controller to start consuming gesture events. This also cause
2110 // the queued gesture event to be forwarded to the renderer.
2111 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2112 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2113 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2114 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2115 EXPECT_EQ(1U, sink_->message_count());
2116 sink_->ClearMessages();
2117
2118 // Send another update event. This should get into the queue.
2119 SimulateGestureScrollUpdateEvent(10, 0, 0);
2120 EXPECT_EQ(0U, sink_->message_count());
2121
2122 // Receive an ACK for the second scroll-update event as not being processed.
2123 // This will now initiate an overscroll. This will also cause the queued
2124 // gesture event to be released. But instead of going to the renderer, it will
2125 // be consumed by the overscroll controller.
2126 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2127 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2128 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2129 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2130 EXPECT_EQ(65.f, overscroll_delta_x());
2131 EXPECT_EQ(15.f, overscroll_delegate()->delta_x());
2132 EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
2133 EXPECT_EQ(0U, sink_->message_count());
2134 }
2135
2136 // Tests that the gesture debounce timer plays nice with the overscroll
2137 // controller.
2138 TEST_F(RenderWidgetHostViewAuraOverscrollTest,
2139 GestureScrollDebounceTimerOverscroll) {
2140 SetUpOverscrollEnvironmentWithDebounce(10);
2141
2142 // Start scrolling. Receive ACK as it being processed.
2143 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2144 WebGestureEvent::Touchscreen);
2145 EXPECT_EQ(1U, sink_->message_count());
2146 sink_->ClearMessages();
2147
2148 // Send update events.
2149 SimulateGestureScrollUpdateEvent(55, 0, 0);
2150 EXPECT_EQ(1U, sink_->message_count());
2151 sink_->ClearMessages();
2152
2153 // Send an end event. This should get in the debounce queue.
2154 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
2155 WebGestureEvent::Touchscreen);
2156 EXPECT_EQ(0U, sink_->message_count());
2157
2158 // Receive ACK for the scroll-update event.
2159 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2160 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2161 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2162 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2163 EXPECT_EQ(55.f, overscroll_delta_x());
2164 EXPECT_EQ(5.f, overscroll_delegate()->delta_x());
2165 EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
2166 EXPECT_EQ(0U, sink_->message_count());
2167
2168 // Let the timer for the debounce queue fire. That should release the queued
2169 // scroll-end event. Since overscroll has started, but there hasn't been
2170 // enough overscroll to complete the gesture, the overscroll controller
2171 // will reset the state. The scroll-end should therefore be dispatched to the
2172 // renderer, and the gesture-event-filter should await an ACK for it.
2173 base::MessageLoop::current()->PostDelayedTask(
2174 FROM_HERE,
2175 base::MessageLoop::QuitClosure(),
2176 base::TimeDelta::FromMilliseconds(15));
2177 base::MessageLoop::current()->Run();
2178
2179 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2180 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2181 EXPECT_EQ(1U, sink_->message_count());
2182 }
2183
2184 // Tests that when touch-events are dispatched to the renderer, the overscroll
2185 // gesture deals with them correctly.
2186 TEST_F(RenderWidgetHostViewAuraOverscrollTest, OverscrollWithTouchEvents) {
2187 SetUpOverscrollEnvironmentWithDebounce(10);
2188 widget_host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
2189 sink_->ClearMessages();
2190
2191 // The test sends an intermingled sequence of touch and gesture events.
2192
2193 PressTouchPoint(0, 1);
2194 EXPECT_EQ(1U, sink_->message_count());
2195 SendInputEventACK(WebInputEvent::TouchStart,
2196 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2197 sink_->ClearMessages();
2198
2199 MoveTouchPoint(0, 20, 5);
2200 EXPECT_EQ(1U, sink_->message_count());
2201 sink_->ClearMessages();
2202 SendInputEventACK(WebInputEvent::TouchMove,
2203 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2204
2205 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2206 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2207
2208 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2209 WebGestureEvent::Touchscreen);
2210 SimulateGestureScrollUpdateEvent(20, 0, 0);
2211 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2212 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2213 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2214 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2215 sink_->ClearMessages();
2216
2217 // Another touch move event should reach the renderer since overscroll hasn't
2218 // started yet.
2219 MoveTouchPoint(0, 65, 10);
2220 EXPECT_EQ(1U, sink_->message_count());
2221 sink_->ClearMessages();
2222
2223 SendInputEventACK(WebInputEvent::TouchMove,
2224 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2225 SimulateGestureScrollUpdateEvent(45, 0, 0);
2226 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2227 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2228 EXPECT_EQ(1U, sink_->message_count());
2229 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2230 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2231 EXPECT_EQ(65.f, overscroll_delta_x());
2232 EXPECT_EQ(15.f, overscroll_delegate()->delta_x());
2233 EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
2234 sink_->ClearMessages();
2235
2236 // Send another touch event. The page should get the touch-move event, even
2237 // though overscroll has started.
2238 MoveTouchPoint(0, 55, 5);
2239 EXPECT_EQ(1U, sink_->message_count());
2240 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2241 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2242 EXPECT_EQ(65.f, overscroll_delta_x());
2243 EXPECT_EQ(15.f, overscroll_delegate()->delta_x());
2244 EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
2245
2246 SendInputEventACK(WebInputEvent::TouchMove,
2247 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2248 sink_->ClearMessages();
2249
2250 SimulateGestureScrollUpdateEvent(-10, 0, 0);
2251 EXPECT_EQ(0U, sink_->message_count());
2252 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2253 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2254 EXPECT_EQ(55.f, overscroll_delta_x());
2255 EXPECT_EQ(5.f, overscroll_delegate()->delta_x());
2256 EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
2257
2258 MoveTouchPoint(0, 255, 5);
2259 EXPECT_EQ(1U, sink_->message_count());
2260 sink_->ClearMessages();
2261 SendInputEventACK(WebInputEvent::TouchMove,
2262 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2263
2264 SimulateGestureScrollUpdateEvent(200, 0, 0);
2265 EXPECT_EQ(0U, sink_->message_count());
2266 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2267 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2268 EXPECT_EQ(255.f, overscroll_delta_x());
2269 EXPECT_EQ(205.f, overscroll_delegate()->delta_x());
2270 EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
2271
2272 // The touch-end/cancel event should always reach the renderer if the page has
2273 // touch handlers.
2274 ReleaseTouchPoint(0);
2275 EXPECT_EQ(1U, sink_->message_count());
2276 sink_->ClearMessages();
2277
2278 SendInputEventACK(WebInputEvent::TouchEnd,
2279 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2280 EXPECT_EQ(0U, sink_->message_count());
2281
2282 SimulateGestureEvent(blink::WebInputEvent::GestureScrollEnd,
2283 WebGestureEvent::Touchscreen);
2284 base::MessageLoop::current()->PostDelayedTask(
2285 FROM_HERE,
2286 base::MessageLoop::QuitClosure(),
2287 base::TimeDelta::FromMilliseconds(10));
2288 base::MessageLoop::current()->Run();
2289 EXPECT_EQ(1U, sink_->message_count());
2290 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2291 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2292 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->completed_mode());
2293 }
2294
2295 // Tests that touch-gesture end is dispatched to the renderer at the end of a
2296 // touch-gesture initiated overscroll.
2297 TEST_F(RenderWidgetHostViewAuraOverscrollTest,
2298 TouchGestureEndDispatchedAfterOverscrollComplete) {
2299 SetUpOverscrollEnvironmentWithDebounce(10);
2300 widget_host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
2301 sink_->ClearMessages();
2302
2303 // Start scrolling. Receive ACK as it being processed.
2304 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2305 WebGestureEvent::Touchscreen);
2306 EXPECT_EQ(1U, sink_->message_count());
2307 sink_->ClearMessages();
2308 // The scroll begin event will have received a synthetic ack from the input
2309 // router.
2310 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2311 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2312
2313 // Send update events.
2314 SimulateGestureScrollUpdateEvent(55, -5, 0);
2315 EXPECT_EQ(1U, sink_->message_count());
2316 sink_->ClearMessages();
2317 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2318 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2319
2320 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2321 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2322 EXPECT_EQ(0U, sink_->message_count());
2323 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2324 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2325 EXPECT_EQ(55.f, overscroll_delta_x());
2326 EXPECT_EQ(5.f, overscroll_delegate()->delta_x());
2327 EXPECT_EQ(-5.f, overscroll_delegate()->delta_y());
2328
2329 // Send end event.
2330 SimulateGestureEvent(blink::WebInputEvent::GestureScrollEnd,
2331 WebGestureEvent::Touchscreen);
2332 EXPECT_EQ(0U, sink_->message_count());
2333 base::MessageLoop::current()->PostDelayedTask(
2334 FROM_HERE,
2335 base::MessageLoop::QuitClosure(),
2336 base::TimeDelta::FromMilliseconds(10));
2337 base::MessageLoop::current()->Run();
2338 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2339 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2340 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->completed_mode());
2341 EXPECT_EQ(1U, sink_->message_count());
2342 SendInputEventACK(WebInputEvent::GestureScrollEnd,
2343 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2344 sink_->ClearMessages();
2345
2346 // Start scrolling. Receive ACK as it being processed.
2347 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2348 WebGestureEvent::Touchscreen);
2349 EXPECT_EQ(1U, sink_->message_count());
2350 sink_->ClearMessages();
2351 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2352 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2353
2354 // Send update events.
2355 SimulateGestureScrollUpdateEvent(235, -5, 0);
2356 EXPECT_EQ(1U, sink_->message_count());
2357 sink_->ClearMessages();
2358 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2359 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2360
2361 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2362 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2363 EXPECT_EQ(0U, sink_->message_count());
2364 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2365 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2366 EXPECT_EQ(235.f, overscroll_delta_x());
2367 EXPECT_EQ(185.f, overscroll_delegate()->delta_x());
2368 EXPECT_EQ(-5.f, overscroll_delegate()->delta_y());
2369
2370 // Send end event.
2371 SimulateGestureEvent(blink::WebInputEvent::GestureScrollEnd,
2372 WebGestureEvent::Touchscreen);
2373 EXPECT_EQ(0U, sink_->message_count());
2374 base::MessageLoop::current()->PostDelayedTask(
2375 FROM_HERE,
2376 base::MessageLoop::QuitClosure(),
2377 base::TimeDelta::FromMilliseconds(10));
2378 base::MessageLoop::current()->Run();
2379 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2380 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2381 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->completed_mode());
2382 EXPECT_EQ(1U, sink_->message_count());
2383 }
2384
2385 TEST_F(RenderWidgetHostViewAuraOverscrollTest, OverscrollDirectionChange) {
2386 SetUpOverscrollEnvironmentWithDebounce(100);
2387
2388 // Start scrolling. Receive ACK as it being processed.
2389 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2390 WebGestureEvent::Touchscreen);
2391 EXPECT_EQ(1U, sink_->message_count());
2392 sink_->ClearMessages();
2393
2394 // Send update events and receive ack as not consumed.
2395 SimulateGestureScrollUpdateEvent(125, -5, 0);
2396 EXPECT_EQ(1U, sink_->message_count());
2397 sink_->ClearMessages();
2398
2399 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2400 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2401 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2402 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2403 EXPECT_EQ(0U, sink_->message_count());
2404
2405 // Send another update event, but in the reverse direction. The overscroll
2406 // controller will consume the event, and reset the overscroll mode.
2407 SimulateGestureScrollUpdateEvent(-260, 0, 0);
2408 EXPECT_EQ(0U, sink_->message_count());
2409 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2410
2411 // Since the overscroll mode has been reset, the next scroll update events
2412 // should reach the renderer.
2413 SimulateGestureScrollUpdateEvent(-20, 0, 0);
2414 EXPECT_EQ(1U, sink_->message_count());
2415 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2416 }
2417
2418 // Tests that if a mouse-move event completes the overscroll gesture, future
2419 // move events do reach the renderer.
2420 TEST_F(RenderWidgetHostViewAuraOverscrollTest, OverscrollMouseMoveCompletion) {
2421 SetUpOverscrollEnvironment();
2422
2423 SimulateWheelEvent(5, 0, 0, true); // sent directly
2424 SimulateWheelEvent(-1, 0, 0, true); // enqueued
2425 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
2426 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
2427 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
2428 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2429 EXPECT_EQ(1U, sink_->message_count());
2430 sink_->ClearMessages();
2431
2432 // Receive ACK the first wheel event as not processed.
2433 SendInputEventACK(WebInputEvent::MouseWheel,
2434 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2435 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2436 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2437 EXPECT_EQ(1U, sink_->message_count());
2438 sink_->ClearMessages();
2439
2440 // Receive ACK for the second (coalesced) event as not processed. This will
2441 // start an overcroll gesture.
2442 SendInputEventACK(WebInputEvent::MouseWheel,
2443 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2444 EXPECT_EQ(OVERSCROLL_WEST, overscroll_mode());
2445 EXPECT_EQ(OVERSCROLL_WEST, overscroll_delegate()->current_mode());
2446 EXPECT_EQ(0U, sink_->message_count());
2447
2448 // Send a mouse-move event. This should cancel the overscroll navigation
2449 // (since the amount overscrolled is not above the threshold), and so the
2450 // mouse-move should reach the renderer.
2451 SimulateMouseMove(5, 10, 0);
2452 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2453 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->completed_mode());
2454 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2455 EXPECT_EQ(1U, sink_->message_count());
2456 sink_->ClearMessages();
2457
2458 SendInputEventACK(WebInputEvent::MouseMove,
2459 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2460
2461 // Moving the mouse more should continue to send the events to the renderer.
2462 SimulateMouseMove(5, 10, 0);
2463 SendInputEventACK(WebInputEvent::MouseMove,
2464 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2465 EXPECT_EQ(1U, sink_->message_count());
2466 sink_->ClearMessages();
2467
2468 // Now try with gestures.
2469 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2470 WebGestureEvent::Touchscreen);
2471 SimulateGestureScrollUpdateEvent(300, -5, 0);
2472 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2473 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2474 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2475 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2476 sink_->ClearMessages();
2477
2478 // Overscroll gesture is in progress. Send a mouse-move now. This should
2479 // complete the gesture (because the amount overscrolled is above the
2480 // threshold).
2481 SimulateMouseMove(5, 10, 0);
2482 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->completed_mode());
2483 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2484 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2485 EXPECT_EQ(1U, sink_->message_count());
2486 sink_->ClearMessages();
2487 SendInputEventACK(WebInputEvent::MouseMove,
2488 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2489
2490 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
2491 WebGestureEvent::Touchscreen);
2492 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2493 EXPECT_EQ(1U, sink_->message_count());
2494 sink_->ClearMessages();
2495
2496 // Move mouse some more. The mouse-move events should reach the renderer.
2497 SimulateMouseMove(5, 10, 0);
2498 EXPECT_EQ(1U, sink_->message_count());
2499
2500 SendInputEventACK(WebInputEvent::MouseMove,
2501 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2502 sink_->ClearMessages();
2503 }
2504
2505 // Tests that if a page scrolled, then the overscroll controller's states are
2506 // reset after the end of the scroll.
2507 TEST_F(RenderWidgetHostViewAuraOverscrollTest,
2508 OverscrollStateResetsAfterScroll) {
2509 SetUpOverscrollEnvironment();
2510
2511 SimulateWheelEvent(0, 5, 0, true); // sent directly
2512 SimulateWheelEvent(0, 30, 0, true); // enqueued
2513 SimulateWheelEvent(0, 40, 0, true); // coalesced into previous event
2514 SimulateWheelEvent(0, 10, 0, true); // coalesced into previous event
2515 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2516 EXPECT_EQ(1U, sink_->message_count());
2517 sink_->ClearMessages();
2518
2519 // The first wheel event is consumed. Dispatches the queued wheel event.
2520 SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED);
2521 EXPECT_TRUE(ScrollStateIsContentScrolling());
2522 EXPECT_EQ(1U, sink_->message_count());
2523 sink_->ClearMessages();
2524
2525 // The second wheel event is consumed.
2526 SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED);
2527 EXPECT_TRUE(ScrollStateIsContentScrolling());
2528
2529 // Touchpad scroll can end with a zero-velocity fling. But it is not
2530 // dispatched, but it should still reset the overscroll controller state.
2531 SimulateGestureFlingStartEvent(0.f, 0.f, WebGestureEvent::Touchpad);
2532 EXPECT_TRUE(ScrollStateIsUnknown());
2533 EXPECT_EQ(0U, sink_->message_count());
2534
2535 SimulateWheelEvent(-5, 0, 0, true); // sent directly
2536 SimulateWheelEvent(-60, 0, 0, true); // enqueued
2537 SimulateWheelEvent(-100, 0, 0, true); // coalesced into previous event
2538 EXPECT_EQ(1U, sink_->message_count());
2539 EXPECT_TRUE(ScrollStateIsUnknown());
2540 sink_->ClearMessages();
2541
2542 // The first wheel scroll did not scroll content. Overscroll should not start
2543 // yet, since enough hasn't been scrolled.
2544 SendInputEventACK(WebInputEvent::MouseWheel,
2545 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2546 EXPECT_TRUE(ScrollStateIsUnknown());
2547 EXPECT_EQ(1U, sink_->message_count());
2548 sink_->ClearMessages();
2549
2550 SendInputEventACK(WebInputEvent::MouseWheel,
2551 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2552 EXPECT_EQ(OVERSCROLL_WEST, overscroll_mode());
2553 EXPECT_TRUE(ScrollStateIsOverscrolling());
2554 EXPECT_EQ(0U, sink_->message_count());
2555
2556 SimulateGestureFlingStartEvent(0.f, 0.f, WebGestureEvent::Touchpad);
2557 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2558 EXPECT_EQ(OVERSCROLL_WEST, overscroll_delegate()->completed_mode());
2559 EXPECT_TRUE(ScrollStateIsUnknown());
2560 EXPECT_EQ(0U, sink_->message_count());
2561 sink_->ClearMessages();
2562 }
2563
2564 TEST_F(RenderWidgetHostViewAuraOverscrollTest, OverscrollResetsOnBlur) {
2565 SetUpOverscrollEnvironment();
2566
2567 // Start an overscroll with gesture scroll. In the middle of the scroll, blur
2568 // the host.
2569 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2570 WebGestureEvent::Touchscreen);
2571 SimulateGestureScrollUpdateEvent(300, -5, 0);
2572 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2573 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2574 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2575 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2576 EXPECT_EQ(2U, sink_->message_count());
2577
2578 view_->OnWindowFocused(NULL, view_->GetAttachedWindow());
2579 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2580 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2581 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->completed_mode());
2582 EXPECT_EQ(0.f, overscroll_delegate()->delta_x());
2583 EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
2584 sink_->ClearMessages();
2585
2586 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
2587 WebGestureEvent::Touchscreen);
2588 EXPECT_EQ(1U, sink_->message_count());
2589 sink_->ClearMessages();
2590
2591 // Start a scroll gesture again. This should correctly start the overscroll
2592 // after the threshold.
2593 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2594 WebGestureEvent::Touchscreen);
2595 SimulateGestureScrollUpdateEvent(300, -5, 0);
2596 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2597 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2598 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2599 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2600 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->completed_mode());
2601
2602 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
2603 WebGestureEvent::Touchscreen);
2604 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2605 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->completed_mode());
2606 EXPECT_EQ(3U, sink_->message_count());
2607 }
2608
1423 } // namespace content 2609 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698