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

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: 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/input/gesture_event_queue.h"
19 #include "content/browser/renderer_host/input/input_router_impl.h"
20 #include "content/browser/renderer_host/overscroll_controller.h"
21 #include "content/browser/renderer_host/overscroll_controller_delegate.h"
18 #include "content/browser/renderer_host/render_widget_host_delegate.h" 22 #include "content/browser/renderer_host/render_widget_host_delegate.h"
19 #include "content/browser/renderer_host/render_widget_host_impl.h" 23 #include "content/browser/renderer_host/render_widget_host_impl.h"
20 #include "content/common/gpu/client/gl_helper.h" 24 #include "content/common/gpu/client/gl_helper.h"
21 #include "content/common/gpu/gpu_messages.h" 25 #include "content/common/gpu/gpu_messages.h"
22 #include "content/common/host_shared_bitmap_manager.h" 26 #include "content/common/host_shared_bitmap_manager.h"
27 #include "content/common/input/synthetic_web_input_event_builders.h"
23 #include "content/common/input_messages.h" 28 #include "content/common/input_messages.h"
24 #include "content/common/view_messages.h" 29 #include "content/common/view_messages.h"
25 #include "content/public/browser/render_widget_host_view.h" 30 #include "content/public/browser/render_widget_host_view.h"
26 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" 31 #include "content/public/browser/render_widget_host_view_frame_subscriber.h"
27 #include "content/public/test/mock_render_process_host.h" 32 #include "content/public/test/mock_render_process_host.h"
28 #include "content/public/test/test_browser_context.h" 33 #include "content/public/test/test_browser_context.h"
29 #include "ipc/ipc_test_sink.h" 34 #include "ipc/ipc_test_sink.h"
30 #include "testing/gmock/include/gmock/gmock.h" 35 #include "testing/gmock/include/gmock/gmock.h"
31 #include "testing/gtest/include/gtest/gtest.h" 36 #include "testing/gtest/include/gtest/gtest.h"
32 #include "ui/aura/client/aura_constants.h" 37 #include "ui/aura/client/aura_constants.h"
33 #include "ui/aura/client/screen_position_client.h" 38 #include "ui/aura/client/screen_position_client.h"
34 #include "ui/aura/client/window_tree_client.h" 39 #include "ui/aura/client/window_tree_client.h"
35 #include "ui/aura/env.h" 40 #include "ui/aura/env.h"
36 #include "ui/aura/layout_manager.h" 41 #include "ui/aura/layout_manager.h"
37 #include "ui/aura/test/aura_test_helper.h" 42 #include "ui/aura/test/aura_test_helper.h"
38 #include "ui/aura/test/event_generator.h" 43 #include "ui/aura/test/event_generator.h"
39 #include "ui/aura/test/test_cursor_client.h" 44 #include "ui/aura/test/test_cursor_client.h"
40 #include "ui/aura/test/test_screen.h" 45 #include "ui/aura/test/test_screen.h"
41 #include "ui/aura/test/test_window_delegate.h" 46 #include "ui/aura/test/test_window_delegate.h"
42 #include "ui/aura/window.h" 47 #include "ui/aura/window.h"
43 #include "ui/aura/window_event_dispatcher.h" 48 #include "ui/aura/window_event_dispatcher.h"
44 #include "ui/aura/window_observer.h" 49 #include "ui/aura/window_observer.h"
45 #include "ui/base/ui_base_types.h" 50 #include "ui/base/ui_base_types.h"
46 #include "ui/compositor/compositor.h" 51 #include "ui/compositor/compositor.h"
47 #include "ui/compositor/test/draw_waiter_for_test.h" 52 #include "ui/compositor/test/draw_waiter_for_test.h"
48 #include "ui/compositor/test/in_process_context_factory.h" 53 #include "ui/compositor/test/in_process_context_factory.h"
49 #include "ui/events/event.h" 54 #include "ui/events/event.h"
50 #include "ui/events/event_utils.h" 55 #include "ui/events/event_utils.h"
56 #include "ui/events/gestures/gesture_configuration.h"
51 #include "ui/wm/core/default_activation_client.h" 57 #include "ui/wm/core/default_activation_client.h"
52 58
53 using testing::_; 59 using testing::_;
54 60
61 using blink::WebGestureEvent;
62 using blink::WebInputEvent;
63 using blink::WebMouseEvent;
64 using blink::WebMouseWheelEvent;
65 using blink::WebTouchEvent;
66 using blink::WebTouchPoint;
67
55 namespace content { 68 namespace content {
56 namespace { 69 namespace {
57 70
58 // Simple screen position client to test coordinate system conversion. 71 // Simple screen position client to test coordinate system conversion.
59 class TestScreenPositionClient 72 class TestScreenPositionClient
60 : public aura::client::ScreenPositionClient { 73 : public aura::client::ScreenPositionClient {
61 public: 74 public:
62 TestScreenPositionClient() {} 75 TestScreenPositionClient() {}
63 virtual ~TestScreenPositionClient() {} 76 virtual ~TestScreenPositionClient() {}
64 77
(...skipping 12 matching lines...) Expand all
77 gfx::Point* point) OVERRIDE { 90 gfx::Point* point) OVERRIDE {
78 ConvertPointToScreen(window, point); 91 ConvertPointToScreen(window, point);
79 } 92 }
80 93
81 virtual void SetBounds(aura::Window* window, 94 virtual void SetBounds(aura::Window* window,
82 const gfx::Rect& bounds, 95 const gfx::Rect& bounds,
83 const gfx::Display& display) OVERRIDE { 96 const gfx::Display& display) OVERRIDE {
84 } 97 }
85 }; 98 };
86 99
100 class TestOverscrollDelegate : public OverscrollControllerDelegate {
101 public:
102 explicit TestOverscrollDelegate(RenderWidgetHostView* view)
103 : view_(view),
104 current_mode_(OVERSCROLL_NONE),
105 completed_mode_(OVERSCROLL_NONE),
106 delta_x_(0.f),
107 delta_y_(0.f) {}
108
109 virtual ~TestOverscrollDelegate() {}
110
111 OverscrollMode current_mode() const { return current_mode_; }
112 OverscrollMode completed_mode() const { return completed_mode_; }
113 float delta_x() const { return delta_x_; }
114 float delta_y() const { return delta_y_; }
115
116 void Reset() {
117 current_mode_ = OVERSCROLL_NONE;
118 completed_mode_ = OVERSCROLL_NONE;
119 delta_x_ = delta_y_ = 0.f;
120 }
121
122 private:
123 // Overridden from OverscrollControllerDelegate:
124 virtual gfx::Rect GetVisibleBounds() const OVERRIDE {
125 return view_->IsShowing() ? view_->GetViewBounds() : gfx::Rect();
126 }
127
128 virtual void OnOverscrollUpdate(float delta_x, float delta_y) OVERRIDE {
129 delta_x_ = delta_x;
130 delta_y_ = delta_y;
131 }
132
133 virtual void OnOverscrollComplete(OverscrollMode overscroll_mode) OVERRIDE {
134 EXPECT_EQ(current_mode_, overscroll_mode);
135 completed_mode_ = overscroll_mode;
136 current_mode_ = OVERSCROLL_NONE;
137 }
138
139 virtual void OnOverscrollModeChange(OverscrollMode old_mode,
140 OverscrollMode new_mode) OVERRIDE {
141 EXPECT_EQ(current_mode_, old_mode);
142 current_mode_ = new_mode;
143 delta_x_ = delta_y_ = 0.f;
144 }
145
146 RenderWidgetHostView* view_;
147 OverscrollMode current_mode_;
148 OverscrollMode completed_mode_;
149 float delta_x_;
150 float delta_y_;
151
152 DISALLOW_COPY_AND_ASSIGN(TestOverscrollDelegate);
153 };
154
87 class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate { 155 class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate {
88 public: 156 public:
89 MockRenderWidgetHostDelegate() {} 157 MockRenderWidgetHostDelegate() {}
90 virtual ~MockRenderWidgetHostDelegate() {} 158 virtual ~MockRenderWidgetHostDelegate() {}
91 }; 159 };
92 160
93 // Simple observer that keeps track of changes to a window for tests. 161 // Simple observer that keeps track of changes to a window for tests.
94 class TestWindowObserver : public aura::WindowObserver { 162 class TestWindowObserver : public aura::WindowObserver {
95 public: 163 public:
96 explicit TestWindowObserver(aura::Window* window_to_observe) 164 explicit TestWindowObserver(aura::Window* window_to_observe)
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 public: 266 public:
199 FakeResizeLock(const gfx::Size new_size, bool defer_compositor_lock) 267 FakeResizeLock(const gfx::Size new_size, bool defer_compositor_lock)
200 : ResizeLock(new_size, defer_compositor_lock) {} 268 : ResizeLock(new_size, defer_compositor_lock) {}
201 }; 269 };
202 270
203 bool has_resize_lock_; 271 bool has_resize_lock_;
204 gfx::Size last_frame_size_; 272 gfx::Size last_frame_size_;
205 scoped_ptr<cc::CopyOutputRequest> last_copy_request_; 273 scoped_ptr<cc::CopyOutputRequest> last_copy_request_;
206 }; 274 };
207 275
276 // A layout manager that always resizes a child to the root window size.
277 class FullscreenLayoutManager : public aura::LayoutManager {
278 public:
279 explicit FullscreenLayoutManager(aura::Window* owner) : owner_(owner) {}
280 virtual ~FullscreenLayoutManager() {}
281
282 // Overridden from aura::LayoutManager:
283 virtual void OnWindowResized() OVERRIDE {
284 aura::Window::Windows::const_iterator i;
285 for (i = owner_->children().begin(); i != owner_->children().end(); ++i) {
286 (*i)->SetBounds(gfx::Rect());
287 }
288 }
289 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE {
290 child->SetBounds(gfx::Rect());
291 }
292 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {}
293 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {}
294 virtual void OnChildWindowVisibilityChanged(aura::Window* child,
295 bool visible) OVERRIDE {}
296 virtual void SetChildBounds(aura::Window* child,
297 const gfx::Rect& requested_bounds) OVERRIDE {
298 SetChildBoundsDirect(child, gfx::Rect(owner_->bounds().size()));
299 }
300
301 private:
302 aura::Window* owner_;
303 DISALLOW_COPY_AND_ASSIGN(FullscreenLayoutManager);
304 };
305
306 class MockWindowObserver : public aura::WindowObserver {
307 public:
308 MOCK_METHOD2(OnWindowPaintScheduled, void(aura::Window*, const gfx::Rect&));
309 };
310
311 } // namespace
312
208 class RenderWidgetHostViewAuraTest : public testing::Test { 313 class RenderWidgetHostViewAuraTest : public testing::Test {
209 public: 314 public:
210 RenderWidgetHostViewAuraTest() 315 RenderWidgetHostViewAuraTest()
211 : browser_thread_for_ui_(BrowserThread::UI, &message_loop_) {} 316 : browser_thread_for_ui_(BrowserThread::UI, &message_loop_) {}
212 317
213 void SetUpEnvironment() { 318 void SetUpEnvironment() {
214 ImageTransportFactory::InitializeForUnitTests( 319 ImageTransportFactory::InitializeForUnitTests(
215 scoped_ptr<ui::ContextFactory>(new ui::InProcessContextFactory)); 320 scoped_ptr<ui::ContextFactory>(new ui::InProcessContextFactory));
216 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); 321 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_));
217 aura_test_helper_->SetUp(); 322 aura_test_helper_->SetUp();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 // destruction. 380 // destruction.
276 RenderWidgetHostImpl* widget_host_; 381 RenderWidgetHostImpl* widget_host_;
277 FakeRenderWidgetHostViewAura* view_; 382 FakeRenderWidgetHostViewAura* view_;
278 383
279 IPC::TestSink* sink_; 384 IPC::TestSink* sink_;
280 385
281 private: 386 private:
282 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraTest); 387 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraTest);
283 }; 388 };
284 389
390 class RenderWidgetHostViewAuraOverscrollTest
391 : public RenderWidgetHostViewAuraTest {
392 public:
393 RenderWidgetHostViewAuraOverscrollTest() {}
394
395 // We explicitly invoke SetUp to allow gesture debounce customization.
396 virtual void SetUp() {}
397
398 protected:
399 void SetUpOverscrollEnvironmentWithDebounce(int debounce_interval_in_ms) {
400 SetUpOverscrollEnvironmentImpl(debounce_interval_in_ms);
401 }
402
403 void SetUpOverscrollEnvironment() { SetUpOverscrollEnvironmentImpl(0); }
404
405 void SetUpOverscrollEnvironmentImpl(int debounce_interval_in_ms) {
406 ui::GestureConfiguration::set_scroll_debounce_interval_in_ms(
407 debounce_interval_in_ms);
408
409 RenderWidgetHostViewAuraTest::SetUp();
410
411 view_->SetOverscrollControllerEnabled(true);
412 overscroll_delegate_.reset(new TestOverscrollDelegate(view_));
413 view_->overscroll_controller()->set_delegate(overscroll_delegate_.get());
414
415 view_->InitAsChild(NULL);
416 aura::client::ParentWindowWithContext(
417 view_->GetNativeView(),
418 parent_view_->GetNativeView()->GetRootWindow(),
419 gfx::Rect());
420 view_->SetBounds(gfx::Rect(0, 0, 400, 200));
421 view_->Show();
422
423 sink_->ClearMessages();
424 }
425
426 // TODO(jdduke): Simulate ui::Events, injecting through the view.
427 void SimulateMouseEvent(WebInputEvent::Type type) {
428 widget_host_->ForwardMouseEvent(SyntheticWebMouseEventBuilder::Build(type));
429 }
430
431 void SimulateMouseEventWithLatencyInfo(WebInputEvent::Type type,
432 const ui::LatencyInfo& ui_latency) {
433 widget_host_->ForwardMouseEventWithLatencyInfo(
434 SyntheticWebMouseEventBuilder::Build(type), ui_latency);
435 }
436
437 void SimulateWheelEvent(float dX, float dY, int modifiers, bool precise) {
438 widget_host_->ForwardWheelEvent(
439 SyntheticWebMouseWheelEventBuilder::Build(dX, dY, modifiers, precise));
440 }
441
442 void SimulateWheelEventWithLatencyInfo(float dX,
443 float dY,
444 int modifiers,
445 bool precise,
446 const ui::LatencyInfo& ui_latency) {
447 widget_host_->ForwardWheelEventWithLatencyInfo(
448 SyntheticWebMouseWheelEventBuilder::Build(dX, dY, modifiers, precise),
449 ui_latency);
450 }
451
452 void SimulateMouseMove(int x, int y, int modifiers) {
453 SimulateMouseEvent(WebInputEvent::MouseMove, x, y, modifiers, false);
454 }
455
456 void SimulateMouseEvent(WebInputEvent::Type type,
457 int x,
458 int y,
459 int modifiers,
460 bool pressed) {
461 WebMouseEvent event =
462 SyntheticWebMouseEventBuilder::Build(type, x, y, modifiers);
463 if (pressed)
464 event.button = WebMouseEvent::ButtonLeft;
465 widget_host_->ForwardMouseEvent(event);
466 }
467
468 void SimulateWheelEventWithPhase(WebMouseWheelEvent::Phase phase) {
469 widget_host_->ForwardWheelEvent(
470 SyntheticWebMouseWheelEventBuilder::Build(phase));
471 }
472
473 // Inject provided synthetic WebGestureEvent instance.
474 void SimulateGestureEventCore(const WebGestureEvent& gesture_event) {
475 widget_host_->ForwardGestureEvent(gesture_event);
476 }
477
478 void SimulateGestureEventCoreWithLatencyInfo(
479 const WebGestureEvent& gesture_event,
480 const ui::LatencyInfo& ui_latency) {
481 widget_host_->ForwardGestureEventWithLatencyInfo(gesture_event, ui_latency);
482 }
483
484 // Inject simple synthetic WebGestureEvent instances.
485 void SimulateGestureEvent(WebInputEvent::Type type,
486 WebGestureEvent::SourceDevice sourceDevice) {
487 SimulateGestureEventCore(
488 SyntheticWebGestureEventBuilder::Build(type, sourceDevice));
489 }
490
491 void SimulateGestureEventWithLatencyInfo(
492 WebInputEvent::Type type,
493 WebGestureEvent::SourceDevice sourceDevice,
494 const ui::LatencyInfo& ui_latency) {
495 SimulateGestureEventCoreWithLatencyInfo(
496 SyntheticWebGestureEventBuilder::Build(type, sourceDevice), ui_latency);
497 }
498
499 void SimulateGestureScrollUpdateEvent(float dX, float dY, int modifiers) {
500 SimulateGestureEventCore(
501 SyntheticWebGestureEventBuilder::BuildScrollUpdate(dX, dY, modifiers));
502 }
503
504 void SimulateGesturePinchUpdateEvent(float scale,
505 float anchorX,
506 float anchorY,
507 int modifiers) {
508 SimulateGestureEventCore(SyntheticWebGestureEventBuilder::BuildPinchUpdate(
509 scale, anchorX, anchorY, modifiers, WebGestureEvent::Touchscreen));
510 }
511
512 // Inject synthetic GestureFlingStart events.
513 void SimulateGestureFlingStartEvent(
514 float velocityX,
515 float velocityY,
516 WebGestureEvent::SourceDevice sourceDevice) {
517 SimulateGestureEventCore(SyntheticWebGestureEventBuilder::BuildFling(
518 velocityX, velocityY, sourceDevice));
519 }
520
521 void SendInputEventACK(WebInputEvent::Type type,
522 InputEventAckState ack_result) {
523 InputHostMsg_HandleInputEvent_ACK response(
524 0, type, ack_result, ui::LatencyInfo());
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 sink_->ClearMessages();
2196 SendInputEventACK(WebInputEvent::TouchStart,
2197 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
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(OVERSCROLL_EAST, overscroll_mode());
2229 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2230 EXPECT_EQ(65.f, overscroll_delta_x());
2231 EXPECT_EQ(15.f, overscroll_delegate()->delta_x());
2232 EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
2233 sink_->ClearMessages();
2234
2235 // Send another touch event. The page should get the touch-move event, even
2236 // though overscroll has started.
2237 MoveTouchPoint(0, 55, 5);
2238 EXPECT_EQ(1U, sink_->message_count());
2239 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2240 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2241 EXPECT_EQ(65.f, overscroll_delta_x());
2242 EXPECT_EQ(15.f, overscroll_delegate()->delta_x());
2243 EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
2244
2245 SendInputEventACK(WebInputEvent::TouchMove,
2246 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2247 sink_->ClearMessages();
2248
2249 SimulateGestureScrollUpdateEvent(-10, 0, 0);
2250 EXPECT_EQ(0U, sink_->message_count());
2251 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2252 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2253 EXPECT_EQ(55.f, overscroll_delta_x());
2254 EXPECT_EQ(5.f, overscroll_delegate()->delta_x());
2255 EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
2256
2257 MoveTouchPoint(0, 255, 5);
2258 EXPECT_EQ(1U, sink_->message_count());
2259 sink_->ClearMessages();
2260 SendInputEventACK(WebInputEvent::TouchMove,
2261 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2262
2263 SimulateGestureScrollUpdateEvent(200, 0, 0);
2264 EXPECT_EQ(0U, sink_->message_count());
2265 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2266 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2267 EXPECT_EQ(255.f, overscroll_delta_x());
2268 EXPECT_EQ(205.f, overscroll_delegate()->delta_x());
2269 EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
2270
2271 // The touch-end/cancel event should always reach the renderer if the page has
2272 // touch handlers.
2273 ReleaseTouchPoint(0);
2274 EXPECT_EQ(1U, sink_->message_count());
2275 sink_->ClearMessages();
2276
2277 SendInputEventACK(WebInputEvent::TouchEnd,
2278 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2279 EXPECT_EQ(0U, sink_->message_count());
2280
2281 SimulateGestureEvent(blink::WebInputEvent::GestureScrollEnd,
2282 WebGestureEvent::Touchscreen);
2283 base::MessageLoop::current()->PostDelayedTask(
2284 FROM_HERE,
2285 base::MessageLoop::QuitClosure(),
2286 base::TimeDelta::FromMilliseconds(10));
2287 base::MessageLoop::current()->Run();
2288 EXPECT_EQ(1U, sink_->message_count());
2289 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2290 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2291 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->completed_mode());
2292 }
2293
2294 // Tests that touch-gesture end is dispatched to the renderer at the end of a
2295 // touch-gesture initiated overscroll.
2296 TEST_F(RenderWidgetHostViewAuraOverscrollTest,
2297 TouchGestureEndDispatchedAfterOverscrollComplete) {
2298 SetUpOverscrollEnvironmentWithDebounce(10);
2299 widget_host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
2300 sink_->ClearMessages();
2301
2302 // Start scrolling. Receive ACK as it being processed.
2303 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2304 WebGestureEvent::Touchscreen);
2305 EXPECT_EQ(1U, sink_->message_count());
2306 sink_->ClearMessages();
2307 // The scroll begin event will have received a synthetic ack from the input
2308 // router.
2309 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2310 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2311
2312 // Send update events.
2313 SimulateGestureScrollUpdateEvent(55, -5, 0);
2314 EXPECT_EQ(1U, sink_->message_count());
2315 sink_->ClearMessages();
2316 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2317 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2318
2319 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2320 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2321 EXPECT_EQ(0U, sink_->message_count());
2322 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2323 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2324 EXPECT_EQ(55.f, overscroll_delta_x());
2325 EXPECT_EQ(5.f, overscroll_delegate()->delta_x());
2326 EXPECT_EQ(-5.f, overscroll_delegate()->delta_y());
2327
2328 // Send end event.
2329 SimulateGestureEvent(blink::WebInputEvent::GestureScrollEnd,
2330 WebGestureEvent::Touchscreen);
2331 EXPECT_EQ(0U, sink_->message_count());
2332 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2333 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2334 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->completed_mode());
2335 base::MessageLoop::current()->PostDelayedTask(
2336 FROM_HERE,
2337 base::MessageLoop::QuitClosure(),
2338 base::TimeDelta::FromMilliseconds(10));
2339 base::MessageLoop::current()->Run();
2340 EXPECT_EQ(1U, sink_->message_count());
2341 sink_->ClearMessages();
2342
2343 // Start scrolling. Receive ACK as it being processed.
2344 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2345 WebGestureEvent::Touchscreen);
2346 EXPECT_EQ(1U, sink_->message_count());
2347 sink_->ClearMessages();
2348 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2349 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2350
2351 // Send update events.
2352 SimulateGestureScrollUpdateEvent(235, -5, 0);
2353 EXPECT_EQ(1U, sink_->message_count());
2354 sink_->ClearMessages();
2355 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2356 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2357
2358 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2359 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2360 EXPECT_EQ(0U, sink_->message_count());
2361 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2362 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2363 EXPECT_EQ(235.f, overscroll_delta_x());
2364 EXPECT_EQ(185.f, overscroll_delegate()->delta_x());
2365 EXPECT_EQ(-5.f, overscroll_delegate()->delta_y());
2366
2367 // Send end event.
2368 SimulateGestureEvent(blink::WebInputEvent::GestureScrollEnd,
2369 WebGestureEvent::Touchscreen);
2370 EXPECT_EQ(0U, sink_->message_count());
2371 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2372 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2373 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->completed_mode());
2374
2375 base::MessageLoop::current()->PostDelayedTask(
2376 FROM_HERE,
2377 base::MessageLoop::QuitClosure(),
2378 base::TimeDelta::FromMilliseconds(10));
2379 base::MessageLoop::current()->Run();
2380 EXPECT_EQ(1U, sink_->message_count());
2381 }
2382
2383 TEST_F(RenderWidgetHostViewAuraOverscrollTest, OverscrollDirectionChange) {
2384 SetUpOverscrollEnvironmentWithDebounce(100);
2385
2386 // Start scrolling. Receive ACK as it being processed.
2387 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2388 WebGestureEvent::Touchscreen);
2389 EXPECT_EQ(1U, sink_->message_count());
2390 sink_->ClearMessages();
2391
2392 // Send update events and receive ack as not consumed.
2393 SimulateGestureScrollUpdateEvent(125, -5, 0);
2394 EXPECT_EQ(1U, sink_->message_count());
2395 sink_->ClearMessages();
2396
2397 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2398 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2399 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2400 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2401 EXPECT_EQ(0U, sink_->message_count());
2402
2403 // Send another update event, but in the reverse direction. The overscroll
2404 // controller will consume the event, and reset the overscroll mode.
2405 SimulateGestureScrollUpdateEvent(-260, 0, 0);
2406 EXPECT_EQ(0U, sink_->message_count());
2407 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2408
2409 // Since the overscroll mode has been reset, the next scroll update events
2410 // should reach the renderer.
2411 SimulateGestureScrollUpdateEvent(-20, 0, 0);
2412 EXPECT_EQ(1U, sink_->message_count());
2413 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2414 }
2415
2416 // Tests that if a mouse-move event completes the overscroll gesture, future
2417 // move events do reach the renderer.
2418 TEST_F(RenderWidgetHostViewAuraOverscrollTest, OverscrollMouseMoveCompletion) {
2419 SetUpOverscrollEnvironment();
2420
2421 SimulateWheelEvent(5, 0, 0, true); // sent directly
2422 SimulateWheelEvent(-1, 0, 0, true); // enqueued
2423 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
2424 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
2425 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
2426 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2427 EXPECT_EQ(1U, sink_->message_count());
2428 sink_->ClearMessages();
2429
2430 // Receive ACK the first wheel event as not processed.
2431 SendInputEventACK(WebInputEvent::MouseWheel,
2432 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2433 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2434 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2435 EXPECT_EQ(1U, sink_->message_count());
2436 sink_->ClearMessages();
2437
2438 // Receive ACK for the second (coalesced) event as not processed. This will
2439 // start an overcroll gesture.
2440 SendInputEventACK(WebInputEvent::MouseWheel,
2441 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2442 EXPECT_EQ(OVERSCROLL_WEST, overscroll_mode());
2443 EXPECT_EQ(OVERSCROLL_WEST, overscroll_delegate()->current_mode());
2444 EXPECT_EQ(0U, sink_->message_count());
2445
2446 // Send a mouse-move event. This should cancel the overscroll navigation
2447 // (since the amount overscrolled is not above the threshold), and so the
2448 // mouse-move should reach the renderer.
2449 SimulateMouseMove(5, 10, 0);
2450 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2451 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->completed_mode());
2452 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2453 EXPECT_EQ(1U, sink_->message_count());
2454 sink_->ClearMessages();
2455
2456 SendInputEventACK(WebInputEvent::MouseMove,
2457 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2458
2459 // Moving the mouse more should continue to send the events to the renderer.
2460 SimulateMouseMove(5, 10, 0);
2461 SendInputEventACK(WebInputEvent::MouseMove,
2462 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2463 EXPECT_EQ(1U, sink_->message_count());
2464 sink_->ClearMessages();
2465
2466 // Now try with gestures.
2467 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2468 WebGestureEvent::Touchscreen);
2469 SimulateGestureScrollUpdateEvent(300, -5, 0);
2470 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2471 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2472 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2473 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2474 sink_->ClearMessages();
2475
2476 // Overscroll gesture is in progress. Send a mouse-move now. This should
2477 // complete the gesture (because the amount overscrolled is above the
2478 // threshold).
2479 SimulateMouseMove(5, 10, 0);
2480 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->completed_mode());
2481 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2482 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2483 EXPECT_EQ(1U, sink_->message_count());
2484 sink_->ClearMessages();
2485 SendInputEventACK(WebInputEvent::MouseMove,
2486 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2487
2488 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
2489 WebGestureEvent::Touchscreen);
2490 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2491 EXPECT_EQ(1U, sink_->message_count());
2492 sink_->ClearMessages();
2493
2494 // Move mouse some more. The mouse-move events should reach the renderer.
2495 SimulateMouseMove(5, 10, 0);
2496 EXPECT_EQ(1U, sink_->message_count());
2497
2498 SendInputEventACK(WebInputEvent::MouseMove,
2499 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2500 sink_->ClearMessages();
2501 }
2502
2503 // Tests that if a page scrolled, then the overscroll controller's states are
2504 // reset after the end of the scroll.
2505 TEST_F(RenderWidgetHostViewAuraOverscrollTest,
2506 OverscrollStateResetsAfterScroll) {
2507 SetUpOverscrollEnvironment();
2508
2509 SimulateWheelEvent(0, 5, 0, true); // sent directly
2510 SimulateWheelEvent(0, 30, 0, true); // enqueued
2511 SimulateWheelEvent(0, 40, 0, true); // coalesced into previous event
2512 SimulateWheelEvent(0, 10, 0, true); // coalesced into previous event
2513 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2514 EXPECT_EQ(1U, sink_->message_count());
2515 sink_->ClearMessages();
2516
2517 // The first wheel event is consumed. Dispatches the queued wheel event.
2518 SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED);
2519 EXPECT_TRUE(ScrollStateIsContentScrolling());
2520 EXPECT_EQ(1U, sink_->message_count());
2521 sink_->ClearMessages();
2522
2523 // The second wheel event is consumed.
2524 SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED);
2525 EXPECT_TRUE(ScrollStateIsContentScrolling());
2526
2527 // Touchpad scroll can end with a zero-velocity fling. But it is not
2528 // dispatched, but it should still reset the overscroll controller state.
2529 SimulateGestureFlingStartEvent(0.f, 0.f, WebGestureEvent::Touchpad);
2530 EXPECT_TRUE(ScrollStateIsUnknown());
2531 EXPECT_EQ(0U, sink_->message_count());
2532
2533 SimulateWheelEvent(-5, 0, 0, true); // sent directly
2534 SimulateWheelEvent(-60, 0, 0, true); // enqueued
2535 SimulateWheelEvent(-100, 0, 0, true); // coalesced into previous event
2536 EXPECT_EQ(1U, sink_->message_count());
2537 EXPECT_TRUE(ScrollStateIsUnknown());
2538 sink_->ClearMessages();
2539
2540 // The first wheel scroll did not scroll content. Overscroll should not start
2541 // yet, since enough hasn't been scrolled.
2542 SendInputEventACK(WebInputEvent::MouseWheel,
2543 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2544 EXPECT_TRUE(ScrollStateIsUnknown());
2545 EXPECT_EQ(1U, sink_->message_count());
2546 sink_->ClearMessages();
2547
2548 SendInputEventACK(WebInputEvent::MouseWheel,
2549 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2550 EXPECT_EQ(OVERSCROLL_WEST, overscroll_mode());
2551 EXPECT_TRUE(ScrollStateIsOverscrolling());
2552 EXPECT_EQ(0U, sink_->message_count());
2553
2554 SimulateGestureFlingStartEvent(0.f, 0.f, WebGestureEvent::Touchpad);
2555 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2556 EXPECT_EQ(OVERSCROLL_WEST, overscroll_delegate()->completed_mode());
2557 EXPECT_TRUE(ScrollStateIsUnknown());
2558 EXPECT_EQ(0U, sink_->message_count());
2559 sink_->ClearMessages();
2560 }
2561
2562 TEST_F(RenderWidgetHostViewAuraOverscrollTest, OverscrollResetsOnBlur) {
2563 SetUpOverscrollEnvironment();
2564
2565 // Start an overscroll with gesture scroll. In the middle of the scroll, blur
2566 // the host.
2567 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2568 WebGestureEvent::Touchscreen);
2569 SimulateGestureScrollUpdateEvent(300, -5, 0);
2570 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2571 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2572 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2573 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2574 EXPECT_EQ(2U, sink_->message_count());
2575
2576 view_->OnWindowFocused(NULL, view_->GetAttachedWindow());
2577 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2578 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2579 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->completed_mode());
2580 EXPECT_EQ(0.f, overscroll_delegate()->delta_x());
2581 EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
2582 sink_->ClearMessages();
2583
2584 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
2585 WebGestureEvent::Touchscreen);
2586 EXPECT_EQ(1U, sink_->message_count());
2587 sink_->ClearMessages();
2588
2589 // Start a scroll gesture again. This should correctly start the overscroll
2590 // after the threshold.
2591 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2592 WebGestureEvent::Touchscreen);
2593 SimulateGestureScrollUpdateEvent(300, -5, 0);
2594 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2595 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2596 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2597 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2598 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->completed_mode());
2599
2600 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
2601 WebGestureEvent::Touchscreen);
2602 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2603 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->completed_mode());
2604 EXPECT_EQ(3U, sink_->message_count());
2605 }
2606
1423 } // namespace content 2607 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698