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

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

Powered by Google App Engine
This is Rietveld 408576698