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
3 // found in the LICENSE file.
5 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
7 #include "base/basictypes.h"
8 #include "base/command_line.h"
9 #include "base/memory/shared_memory.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "cc/output/compositor_frame.h"
14 #include "cc/output/compositor_frame_metadata.h"
15 #include "cc/output/copy_output_request.h"
16 #include "cc/surfaces/surface.h"
17 #include "cc/surfaces/surface_manager.h"
18 #include "content/browser/browser_thread_impl.h"
19 #include "content/browser/compositor/resize_lock.h"
20 #include "content/browser/compositor/test/no_transport_image_transport_factory.h"
21 #include "content/browser/frame_host/render_widget_host_view_guest.h"
22 #include "content/browser/renderer_host/input/web_input_event_util.h"
23 #include "content/browser/renderer_host/overscroll_controller.h"
24 #include "content/browser/renderer_host/overscroll_controller_delegate.h"
25 #include "content/browser/renderer_host/render_widget_host_delegate.h"
26 #include "content/browser/renderer_host/render_widget_host_impl.h"
27 #include "content/common/gpu/client/gl_helper.h"
28 #include "content/common/gpu/gpu_messages.h"
29 #include "content/common/host_shared_bitmap_manager.h"
30 #include "content/common/input/synthetic_web_input_event_builders.h"
31 #include "content/common/input_messages.h"
32 #include "content/common/view_messages.h"
33 #include "content/public/browser/render_widget_host_view.h"
34 #include "content/public/browser/render_widget_host_view_frame_subscriber.h"
35 #include "content/public/test/mock_render_process_host.h"
36 #include "content/public/test/test_browser_context.h"
37 #include "ipc/ipc_test_sink.h"
38 #include "testing/gmock/include/gmock/gmock.h"
39 #include "testing/gtest/include/gtest/gtest.h"
40 #include "ui/aura/client/aura_constants.h"
41 #include "ui/aura/client/screen_position_client.h"
42 #include "ui/aura/client/window_tree_client.h"
43 #include "ui/aura/env.h"
44 #include "ui/aura/layout_manager.h"
45 #include "ui/aura/test/aura_test_helper.h"
46 #include "ui/aura/test/aura_test_utils.h"
47 #include "ui/aura/test/test_cursor_client.h"
48 #include "ui/aura/test/test_screen.h"
49 #include "ui/aura/test/test_window_delegate.h"
50 #include "ui/aura/window.h"
51 #include "ui/aura/window_event_dispatcher.h"
52 #include "ui/aura/window_observer.h"
53 #include "ui/base/ui_base_types.h"
54 #include "ui/compositor/compositor.h"
55 #include "ui/compositor/layer_tree_owner.h"
56 #include "ui/compositor/test/draw_waiter_for_test.h"
57 #include "ui/events/blink/blink_event_util.h"
58 #include "ui/events/event.h"
59 #include "ui/events/event_utils.h"
60 #include "ui/events/gesture_detection/gesture_configuration.h"
61 #include "ui/events/keycodes/dom3/dom_code.h"
62 #include "ui/events/keycodes/dom4/keycode_converter.h"
63 #include "ui/events/test/event_generator.h"
64 #include "ui/wm/core/default_activation_client.h"
65 #include "ui/wm/core/default_screen_position_client.h"
66 #include "ui/wm/core/window_util.h"
70 using blink::WebGestureEvent
;
71 using blink::WebInputEvent
;
72 using blink::WebMouseEvent
;
73 using blink::WebMouseWheelEvent
;
74 using blink::WebTouchEvent
;
75 using blink::WebTouchPoint
;
80 class TestOverscrollDelegate
: public OverscrollControllerDelegate
{
82 explicit TestOverscrollDelegate(RenderWidgetHostView
* view
)
84 current_mode_(OVERSCROLL_NONE
),
85 completed_mode_(OVERSCROLL_NONE
),
89 ~TestOverscrollDelegate() override
{}
91 OverscrollMode
current_mode() const { return current_mode_
; }
92 OverscrollMode
completed_mode() const { return completed_mode_
; }
93 float delta_x() const { return delta_x_
; }
94 float delta_y() const { return delta_y_
; }
97 current_mode_
= OVERSCROLL_NONE
;
98 completed_mode_
= OVERSCROLL_NONE
;
99 delta_x_
= delta_y_
= 0.f
;
103 // Overridden from OverscrollControllerDelegate:
104 gfx::Rect
GetVisibleBounds() const override
{
105 return view_
->IsShowing() ? view_
->GetViewBounds() : gfx::Rect();
108 bool OnOverscrollUpdate(float delta_x
, float delta_y
) override
{
114 void OnOverscrollComplete(OverscrollMode overscroll_mode
) override
{
115 EXPECT_EQ(current_mode_
, overscroll_mode
);
116 completed_mode_
= overscroll_mode
;
117 current_mode_
= OVERSCROLL_NONE
;
120 void OnOverscrollModeChange(OverscrollMode old_mode
,
121 OverscrollMode new_mode
) override
{
122 EXPECT_EQ(current_mode_
, old_mode
);
123 current_mode_
= new_mode
;
124 delta_x_
= delta_y_
= 0.f
;
127 RenderWidgetHostView
* view_
;
128 OverscrollMode current_mode_
;
129 OverscrollMode completed_mode_
;
133 DISALLOW_COPY_AND_ASSIGN(TestOverscrollDelegate
);
136 class MockRenderWidgetHostDelegate
: public RenderWidgetHostDelegate
{
138 MockRenderWidgetHostDelegate() {}
139 ~MockRenderWidgetHostDelegate() override
{}
140 const NativeWebKeyboardEvent
* last_event() const { return last_event_
.get(); }
142 // RenderWidgetHostDelegate:
143 bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent
& event
,
144 bool* is_keyboard_shortcut
) override
{
145 last_event_
.reset(new NativeWebKeyboardEvent(event
));
149 scoped_ptr
<NativeWebKeyboardEvent
> last_event_
;
150 DISALLOW_COPY_AND_ASSIGN(MockRenderWidgetHostDelegate
);
153 // Simple observer that keeps track of changes to a window for tests.
154 class TestWindowObserver
: public aura::WindowObserver
{
156 explicit TestWindowObserver(aura::Window
* window_to_observe
)
157 : window_(window_to_observe
) {
158 window_
->AddObserver(this);
160 ~TestWindowObserver() override
{
162 window_
->RemoveObserver(this);
165 bool destroyed() const { return destroyed_
; }
167 // aura::WindowObserver overrides:
168 void OnWindowDestroyed(aura::Window
* window
) override
{
169 CHECK_EQ(window
, window_
);
175 // Window that we're observing, or NULL if it's been destroyed.
176 aura::Window
* window_
;
178 // Was |window_| destroyed?
181 DISALLOW_COPY_AND_ASSIGN(TestWindowObserver
);
184 class FakeFrameSubscriber
: public RenderWidgetHostViewFrameSubscriber
{
186 FakeFrameSubscriber(gfx::Size size
, base::Callback
<void(bool)> callback
)
187 : size_(size
), callback_(callback
) {}
189 bool ShouldCaptureFrame(const gfx::Rect
& damage_rect
,
190 base::TimeTicks present_time
,
191 scoped_refptr
<media::VideoFrame
>* storage
,
192 DeliverFrameCallback
* callback
) override
{
193 *storage
= media::VideoFrame::CreateFrame(media::VideoFrame::YV12
,
198 *callback
= base::Bind(&FakeFrameSubscriber::CallbackMethod
, callback_
);
202 static void CallbackMethod(base::Callback
<void(bool)> callback
,
203 base::TimeTicks timestamp
,
205 callback
.Run(success
);
210 base::Callback
<void(bool)> callback_
;
213 class FakeWindowEventDispatcher
: public aura::WindowEventDispatcher
{
215 FakeWindowEventDispatcher(aura::WindowTreeHost
* host
)
216 : WindowEventDispatcher(host
),
217 processed_touch_event_count_(0) {}
219 void ProcessedTouchEvent(aura::Window
* window
,
220 ui::EventResult result
) override
{
221 WindowEventDispatcher::ProcessedTouchEvent(window
, result
);
222 processed_touch_event_count_
++;
225 size_t processed_touch_event_count() {
226 return processed_touch_event_count_
;
230 size_t processed_touch_event_count_
;
233 class FakeRenderWidgetHostViewAura
: public RenderWidgetHostViewAura
{
235 FakeRenderWidgetHostViewAura(RenderWidgetHost
* widget
,
236 bool is_guest_view_hack
)
237 : RenderWidgetHostViewAura(widget
, is_guest_view_hack
),
238 has_resize_lock_(false) {}
240 void UseFakeDispatcher() {
241 dispatcher_
= new FakeWindowEventDispatcher(window()->GetHost());
242 scoped_ptr
<aura::WindowEventDispatcher
> dispatcher(dispatcher_
);
243 aura::test::SetHostDispatcher(window()->GetHost(), dispatcher
.Pass());
246 ~FakeRenderWidgetHostViewAura() override
{}
248 scoped_ptr
<ResizeLock
> DelegatedFrameHostCreateResizeLock(
249 bool defer_compositor_lock
) override
{
250 gfx::Size desired_size
= window()->bounds().size();
251 return scoped_ptr
<ResizeLock
>(
252 new FakeResizeLock(desired_size
, defer_compositor_lock
));
255 bool DelegatedFrameCanCreateResizeLock() const override
{ return true; }
257 void RunOnCompositingDidCommit() {
258 GetDelegatedFrameHost()->OnCompositingDidCommitForTesting(
259 window()->GetHost()->compositor());
262 void InterceptCopyOfOutput(scoped_ptr
<cc::CopyOutputRequest
> request
) {
263 last_copy_request_
= request
.Pass();
264 if (last_copy_request_
->has_texture_mailbox()) {
265 // Give the resulting texture a size.
266 GLHelper
* gl_helper
= ImageTransportFactory::GetInstance()->GetGLHelper();
267 GLuint texture
= gl_helper
->ConsumeMailboxToTexture(
268 last_copy_request_
->texture_mailbox().mailbox(),
269 last_copy_request_
->texture_mailbox().sync_point());
270 gl_helper
->ResizeTexture(texture
, window()->bounds().size());
271 gl_helper
->DeleteTexture(texture
);
275 cc::DelegatedFrameProvider
* frame_provider() const {
276 return GetDelegatedFrameHost()->FrameProviderForTesting();
279 cc::SurfaceId
surface_id() const {
280 return GetDelegatedFrameHost()->SurfaceIdForTesting();
283 bool HasFrameData() const {
284 return frame_provider() || !surface_id().is_null();
287 bool released_front_lock_active() const {
288 return GetDelegatedFrameHost()->ReleasedFrontLockActiveForTesting();
291 // A lock that doesn't actually do anything to the compositor, and does not
293 class FakeResizeLock
: public ResizeLock
{
295 FakeResizeLock(const gfx::Size new_size
, bool defer_compositor_lock
)
296 : ResizeLock(new_size
, defer_compositor_lock
) {}
299 void OnTouchEvent(ui::TouchEvent
* event
) override
{
300 RenderWidgetHostViewAura::OnTouchEvent(event
);
301 if (pointer_state().GetPointerCount() > 0) {
303 new blink::WebTouchEvent(ui::CreateWebTouchEventFromMotionEvent(
304 pointer_state(), event
->may_cause_scrolling())));
306 // Never create a WebTouchEvent with 0 touch points.
307 touch_event_
.reset();
311 bool has_resize_lock_
;
312 gfx::Size last_frame_size_
;
313 scoped_ptr
<cc::CopyOutputRequest
> last_copy_request_
;
314 // null if there are 0 active touch points.
315 scoped_ptr
<blink::WebTouchEvent
> touch_event_
;
316 FakeWindowEventDispatcher
* dispatcher_
;
319 // A layout manager that always resizes a child to the root window size.
320 class FullscreenLayoutManager
: public aura::LayoutManager
{
322 explicit FullscreenLayoutManager(aura::Window
* owner
) : owner_(owner
) {}
323 ~FullscreenLayoutManager() override
{}
325 // Overridden from aura::LayoutManager:
326 void OnWindowResized() override
{
327 aura::Window::Windows::const_iterator i
;
328 for (i
= owner_
->children().begin(); i
!= owner_
->children().end(); ++i
) {
329 (*i
)->SetBounds(gfx::Rect());
332 void OnWindowAddedToLayout(aura::Window
* child
) override
{
333 child
->SetBounds(gfx::Rect());
335 void OnWillRemoveWindowFromLayout(aura::Window
* child
) override
{}
336 void OnWindowRemovedFromLayout(aura::Window
* child
) override
{}
337 void OnChildWindowVisibilityChanged(aura::Window
* child
,
338 bool visible
) override
{}
339 void SetChildBounds(aura::Window
* child
,
340 const gfx::Rect
& requested_bounds
) override
{
341 SetChildBoundsDirect(child
, gfx::Rect(owner_
->bounds().size()));
345 aura::Window
* owner_
;
346 DISALLOW_COPY_AND_ASSIGN(FullscreenLayoutManager
);
349 class MockWindowObserver
: public aura::WindowObserver
{
351 MOCK_METHOD2(OnDelegatedFrameDamage
, void(aura::Window
*, const gfx::Rect
&));
354 const WebInputEvent
* GetInputEventFromMessage(const IPC::Message
& message
) {
355 PickleIterator
iter(message
);
358 if (!iter
.ReadData(&data
, &data_length
))
360 return reinterpret_cast<const WebInputEvent
*>(data
);
365 class RenderWidgetHostViewAuraTest
: public testing::Test
{
367 RenderWidgetHostViewAuraTest()
368 : widget_host_uses_shutdown_to_destroy_(false),
369 is_guest_view_hack_(false),
370 browser_thread_for_ui_(BrowserThread::UI
, &message_loop_
) {}
372 void SetUpEnvironment() {
373 ImageTransportFactory::InitializeForUnitTests(
374 scoped_ptr
<ImageTransportFactory
>(
375 new NoTransportImageTransportFactory
));
376 aura_test_helper_
.reset(new aura::test::AuraTestHelper(&message_loop_
));
377 aura_test_helper_
->SetUp(
378 ImageTransportFactory::GetInstance()->GetContextFactory());
379 new wm::DefaultActivationClient(aura_test_helper_
->root_window());
381 browser_context_
.reset(new TestBrowserContext
);
382 process_host_
= new MockRenderProcessHost(browser_context_
.get());
384 sink_
= &process_host_
->sink();
386 parent_host_
= new RenderWidgetHostImpl(
387 &delegate_
, process_host_
, MSG_ROUTING_NONE
, false);
388 parent_view_
= new RenderWidgetHostViewAura(parent_host_
,
389 is_guest_view_hack_
);
390 parent_view_
->InitAsChild(NULL
);
391 aura::client::ParentWindowWithContext(parent_view_
->GetNativeView(),
392 aura_test_helper_
->root_window(),
395 widget_host_
= new RenderWidgetHostImpl(
396 &delegate_
, process_host_
, MSG_ROUTING_NONE
, false);
397 widget_host_
->Init();
398 view_
= new FakeRenderWidgetHostViewAura(widget_host_
, is_guest_view_hack_
);
401 void TearDownEnvironment() {
403 process_host_
= NULL
;
407 if (widget_host_uses_shutdown_to_destroy_
)
408 widget_host_
->Shutdown();
412 parent_view_
->Destroy();
415 browser_context_
.reset();
416 aura_test_helper_
->TearDown();
418 message_loop_
.DeleteSoon(FROM_HERE
, browser_context_
.release());
419 message_loop_
.RunUntilIdle();
420 ImageTransportFactory::Terminate();
423 void SetUp() override
{ SetUpEnvironment(); }
425 void TearDown() override
{ TearDownEnvironment(); }
427 void set_widget_host_uses_shutdown_to_destroy(bool use
) {
428 widget_host_uses_shutdown_to_destroy_
= use
;
431 void SimulateMemoryPressure(
432 base::MemoryPressureListener::MemoryPressureLevel level
) {
433 // Here should be base::MemoryPressureListener::NotifyMemoryPressure, but
434 // since the RendererFrameManager is installing a MemoryPressureListener
435 // which uses ObserverListThreadSafe, which furthermore remembers the
436 // message loop for the thread it was created in. Between tests, the
437 // RendererFrameManager singleton survives and and the MessageLoop gets
438 // destroyed. The correct fix would be to have ObserverListThreadSafe look
439 // up the proper message loop every time (see crbug.com/443824.)
440 RendererFrameManager::GetInstance()->OnMemoryPressure(level
);
443 void SendInputEventACK(WebInputEvent::Type type
,
444 InputEventAckState ack_result
) {
445 InputHostMsg_HandleInputEvent_ACK_Params ack
;
447 ack
.state
= ack_result
;
448 InputHostMsg_HandleInputEvent_ACK
response(0, ack
);
449 widget_host_
->OnMessageReceived(response
);
452 size_t GetSentMessageCountAndResetSink() {
453 size_t count
= sink_
->message_count();
454 sink_
->ClearMessages();
458 void AckLastSentInputEventIfNecessary(InputEventAckState ack_result
) {
459 if (!sink_
->message_count())
462 InputMsg_HandleInputEvent::Param params
;
463 if (!InputMsg_HandleInputEvent::Read(
464 sink_
->GetMessageAt(sink_
->message_count() - 1), ¶ms
)) {
468 if (WebInputEventTraits::IgnoresAckDisposition(*get
<0>(params
)))
471 SendInputEventACK(get
<0>(params
)->type
, ack_result
);
475 // If true, then calls RWH::Shutdown() instead of deleting RWH.
476 bool widget_host_uses_shutdown_to_destroy_
;
478 bool is_guest_view_hack_
;
480 base::MessageLoopForUI message_loop_
;
481 BrowserThreadImpl browser_thread_for_ui_
;
482 scoped_ptr
<aura::test::AuraTestHelper
> aura_test_helper_
;
483 scoped_ptr
<BrowserContext
> browser_context_
;
484 MockRenderWidgetHostDelegate delegate_
;
485 MockRenderProcessHost
* process_host_
;
487 // Tests should set these to NULL if they've already triggered their
489 RenderWidgetHostImpl
* parent_host_
;
490 RenderWidgetHostViewAura
* parent_view_
;
492 // Tests should set these to NULL if they've already triggered their
494 RenderWidgetHostImpl
* widget_host_
;
495 FakeRenderWidgetHostViewAura
* view_
;
497 IPC::TestSink
* sink_
;
500 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraTest
);
503 // Helper class to instantiate RenderWidgetHostViewGuest which is backed
504 // by an aura platform view.
505 class RenderWidgetHostViewGuestAuraTest
: public RenderWidgetHostViewAuraTest
{
507 RenderWidgetHostViewGuestAuraTest() {
508 // Use RWH::Shutdown to destroy RWH, instead of deleting.
509 // This will ensure that the RenderWidgetHostViewGuest is not leaked and
510 // is deleted properly upon RWH going away.
511 set_widget_host_uses_shutdown_to_destroy(true);
514 // We explicitly invoke SetUp to allow gesture debounce customization.
515 void SetUp() override
{
516 is_guest_view_hack_
= true;
518 RenderWidgetHostViewAuraTest::SetUp();
520 guest_view_weak_
= (new RenderWidgetHostViewGuest(
521 widget_host_
, NULL
, view_
->GetWeakPtr()))->GetWeakPtr();
524 void TearDown() override
{
525 // Internal override to do nothing, we clean up ourselves in the test body.
526 // This helps us test that |guest_view_weak_| does not leak.
530 base::WeakPtr
<RenderWidgetHostViewBase
> guest_view_weak_
;
534 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewGuestAuraTest
);
537 class RenderWidgetHostViewAuraOverscrollTest
538 : public RenderWidgetHostViewAuraTest
{
540 RenderWidgetHostViewAuraOverscrollTest() {}
542 // We explicitly invoke SetUp to allow gesture debounce customization.
543 void SetUp() override
{}
546 void SetUpOverscrollEnvironmentWithDebounce(int debounce_interval_in_ms
) {
547 SetUpOverscrollEnvironmentImpl(debounce_interval_in_ms
);
550 void SetUpOverscrollEnvironment() { SetUpOverscrollEnvironmentImpl(0); }
552 void SetUpOverscrollEnvironmentImpl(int debounce_interval_in_ms
) {
553 ui::GestureConfiguration::GetInstance()->set_scroll_debounce_interval_in_ms(
554 debounce_interval_in_ms
);
556 RenderWidgetHostViewAuraTest::SetUp();
558 view_
->SetOverscrollControllerEnabled(true);
559 overscroll_delegate_
.reset(new TestOverscrollDelegate(view_
));
560 view_
->overscroll_controller()->set_delegate(overscroll_delegate_
.get());
562 view_
->InitAsChild(NULL
);
563 view_
->SetBounds(gfx::Rect(0, 0, 400, 200));
566 sink_
->ClearMessages();
569 // TODO(jdduke): Simulate ui::Events, injecting through the view.
570 void SimulateMouseEvent(WebInputEvent::Type type
) {
571 widget_host_
->ForwardMouseEvent(SyntheticWebMouseEventBuilder::Build(type
));
574 void SimulateMouseEventWithLatencyInfo(WebInputEvent::Type type
,
575 const ui::LatencyInfo
& ui_latency
) {
576 widget_host_
->ForwardMouseEventWithLatencyInfo(
577 SyntheticWebMouseEventBuilder::Build(type
), ui_latency
);
580 void SimulateWheelEvent(float dX
, float dY
, int modifiers
, bool precise
) {
581 widget_host_
->ForwardWheelEvent(
582 SyntheticWebMouseWheelEventBuilder::Build(dX
, dY
, modifiers
, precise
));
585 void SimulateWheelEventWithLatencyInfo(float dX
,
589 const ui::LatencyInfo
& ui_latency
) {
590 widget_host_
->ForwardWheelEventWithLatencyInfo(
591 SyntheticWebMouseWheelEventBuilder::Build(dX
, dY
, modifiers
, precise
),
595 void SimulateMouseMove(int x
, int y
, int modifiers
) {
596 SimulateMouseEvent(WebInputEvent::MouseMove
, x
, y
, modifiers
, false);
599 void SimulateMouseEvent(WebInputEvent::Type type
,
604 WebMouseEvent event
=
605 SyntheticWebMouseEventBuilder::Build(type
, x
, y
, modifiers
);
607 event
.button
= WebMouseEvent::ButtonLeft
;
608 widget_host_
->ForwardMouseEvent(event
);
611 void SimulateWheelEventWithPhase(WebMouseWheelEvent::Phase phase
) {
612 widget_host_
->ForwardWheelEvent(
613 SyntheticWebMouseWheelEventBuilder::Build(phase
));
616 // Inject provided synthetic WebGestureEvent instance.
617 void SimulateGestureEventCore(const WebGestureEvent
& gesture_event
) {
618 widget_host_
->ForwardGestureEvent(gesture_event
);
621 void SimulateGestureEventCoreWithLatencyInfo(
622 const WebGestureEvent
& gesture_event
,
623 const ui::LatencyInfo
& ui_latency
) {
624 widget_host_
->ForwardGestureEventWithLatencyInfo(gesture_event
, ui_latency
);
627 // Inject simple synthetic WebGestureEvent instances.
628 void SimulateGestureEvent(WebInputEvent::Type type
,
629 blink::WebGestureDevice sourceDevice
) {
630 SimulateGestureEventCore(
631 SyntheticWebGestureEventBuilder::Build(type
, sourceDevice
));
634 void SimulateGestureEventWithLatencyInfo(WebInputEvent::Type type
,
635 blink::WebGestureDevice sourceDevice
,
636 const ui::LatencyInfo
& ui_latency
) {
637 SimulateGestureEventCoreWithLatencyInfo(
638 SyntheticWebGestureEventBuilder::Build(type
, sourceDevice
), ui_latency
);
641 void SimulateGestureScrollUpdateEvent(float dX
, float dY
, int modifiers
) {
642 SimulateGestureEventCore(SyntheticWebGestureEventBuilder::BuildScrollUpdate(
643 dX
, dY
, modifiers
, blink::WebGestureDeviceTouchscreen
));
646 void SimulateGesturePinchUpdateEvent(float scale
,
650 SimulateGestureEventCore(SyntheticWebGestureEventBuilder::BuildPinchUpdate(
655 blink::WebGestureDeviceTouchscreen
));
658 // Inject synthetic GestureFlingStart events.
659 void SimulateGestureFlingStartEvent(float velocityX
,
661 blink::WebGestureDevice sourceDevice
) {
662 SimulateGestureEventCore(SyntheticWebGestureEventBuilder::BuildFling(
663 velocityX
, velocityY
, sourceDevice
));
666 bool ScrollStateIsContentScrolling() const {
667 return scroll_state() == OverscrollController::STATE_CONTENT_SCROLLING
;
670 bool ScrollStateIsOverscrolling() const {
671 return scroll_state() == OverscrollController::STATE_OVERSCROLLING
;
674 bool ScrollStateIsUnknown() const {
675 return scroll_state() == OverscrollController::STATE_UNKNOWN
;
678 OverscrollController::ScrollState
scroll_state() const {
679 return view_
->overscroll_controller()->scroll_state_
;
682 OverscrollMode
overscroll_mode() const {
683 return view_
->overscroll_controller()->overscroll_mode_
;
686 float overscroll_delta_x() const {
687 return view_
->overscroll_controller()->overscroll_delta_x_
;
690 float overscroll_delta_y() const {
691 return view_
->overscroll_controller()->overscroll_delta_y_
;
694 TestOverscrollDelegate
* overscroll_delegate() {
695 return overscroll_delegate_
.get();
698 void SendTouchEvent() {
699 widget_host_
->ForwardTouchEventWithLatencyInfo(touch_event_
,
701 touch_event_
.ResetPoints();
704 void PressTouchPoint(int x
, int y
) {
705 touch_event_
.PressPoint(x
, y
);
709 void MoveTouchPoint(int index
, int x
, int y
) {
710 touch_event_
.MovePoint(index
, x
, y
);
714 void ReleaseTouchPoint(int index
) {
715 touch_event_
.ReleasePoint(index
);
719 SyntheticWebTouchEvent touch_event_
;
721 scoped_ptr
<TestOverscrollDelegate
> overscroll_delegate_
;
724 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraOverscrollTest
);
727 class RenderWidgetHostViewAuraShutdownTest
728 : public RenderWidgetHostViewAuraTest
{
730 RenderWidgetHostViewAuraShutdownTest() {}
732 void TearDown() override
{
733 // No TearDownEnvironment here, we do this explicitly during the test.
737 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraShutdownTest
);
740 // Checks that a fullscreen view has the correct show-state and receives the
742 TEST_F(RenderWidgetHostViewAuraTest
, FocusFullscreen
) {
743 view_
->InitAsFullscreen(parent_view_
);
744 aura::Window
* window
= view_
->GetNativeView();
745 ASSERT_TRUE(window
!= NULL
);
746 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN
,
747 window
->GetProperty(aura::client::kShowStateKey
));
749 // Check that we requested and received the focus.
750 EXPECT_TRUE(window
->HasFocus());
752 // Check that we'll also say it's okay to activate the window when there's an
753 // ActivationClient defined.
754 EXPECT_TRUE(view_
->ShouldActivate());
757 // Checks that a popup is positioned correctly relative to its parent using
758 // screen coordinates.
759 TEST_F(RenderWidgetHostViewAuraTest
, PositionChildPopup
) {
760 wm::DefaultScreenPositionClient screen_position_client
;
762 aura::Window
* window
= parent_view_
->GetNativeView();
763 aura::Window
* root
= window
->GetRootWindow();
764 aura::client::SetScreenPositionClient(root
, &screen_position_client
);
766 parent_view_
->SetBounds(gfx::Rect(10, 10, 800, 600));
767 gfx::Rect bounds_in_screen
= parent_view_
->GetViewBounds();
768 int horiz
= bounds_in_screen
.width() / 4;
769 int vert
= bounds_in_screen
.height() / 4;
770 bounds_in_screen
.Inset(horiz
, vert
);
772 // Verify that when the popup is initialized for the first time, it correctly
773 // treats the input bounds as screen coordinates.
774 view_
->InitAsPopup(parent_view_
, bounds_in_screen
);
776 gfx::Rect final_bounds_in_screen
= view_
->GetViewBounds();
777 EXPECT_EQ(final_bounds_in_screen
.ToString(), bounds_in_screen
.ToString());
779 // Verify that directly setting the bounds via SetBounds() treats the input
780 // as screen coordinates.
781 bounds_in_screen
= gfx::Rect(60, 60, 100, 100);
782 view_
->SetBounds(bounds_in_screen
);
783 final_bounds_in_screen
= view_
->GetViewBounds();
784 EXPECT_EQ(final_bounds_in_screen
.ToString(), bounds_in_screen
.ToString());
786 // Verify that setting the size does not alter the origin.
787 gfx::Point original_origin
= window
->bounds().origin();
788 view_
->SetSize(gfx::Size(120, 120));
789 gfx::Point new_origin
= window
->bounds().origin();
790 EXPECT_EQ(original_origin
.ToString(), new_origin
.ToString());
792 aura::client::SetScreenPositionClient(root
, NULL
);
795 // Checks that a fullscreen view is destroyed when it loses the focus.
796 TEST_F(RenderWidgetHostViewAuraTest
, DestroyFullscreenOnBlur
) {
797 view_
->InitAsFullscreen(parent_view_
);
798 aura::Window
* window
= view_
->GetNativeView();
799 ASSERT_TRUE(window
!= NULL
);
800 ASSERT_TRUE(window
->HasFocus());
802 // After we create and focus another window, the RWHVA's window should be
804 TestWindowObserver
observer(window
);
805 aura::test::TestWindowDelegate delegate
;
806 scoped_ptr
<aura::Window
> sibling(new aura::Window(&delegate
));
807 sibling
->Init(aura::WINDOW_LAYER_TEXTURED
);
809 window
->parent()->AddChild(sibling
.get());
811 ASSERT_TRUE(sibling
->HasFocus());
812 ASSERT_TRUE(observer
.destroyed());
818 // Checks that a popup view is destroyed when a user clicks outside of the popup
819 // view and focus does not change. This is the case when the user clicks on the
820 // desktop background on Chrome OS.
821 TEST_F(RenderWidgetHostViewAuraTest
, DestroyPopupClickOutsidePopup
) {
822 parent_view_
->SetBounds(gfx::Rect(10, 10, 400, 400));
823 parent_view_
->Focus();
824 EXPECT_TRUE(parent_view_
->HasFocus());
826 view_
->InitAsPopup(parent_view_
, gfx::Rect(10, 10, 100, 100));
827 aura::Window
* window
= view_
->GetNativeView();
828 ASSERT_TRUE(window
!= NULL
);
830 gfx::Point click_point
;
831 EXPECT_FALSE(window
->GetBoundsInRootWindow().Contains(click_point
));
832 aura::Window
* parent_window
= parent_view_
->GetNativeView();
833 EXPECT_FALSE(parent_window
->GetBoundsInRootWindow().Contains(click_point
));
835 TestWindowObserver
observer(window
);
836 ui::test::EventGenerator
generator(window
->GetRootWindow(), click_point
);
837 generator
.ClickLeftButton();
838 ASSERT_TRUE(parent_view_
->HasFocus());
839 ASSERT_TRUE(observer
.destroyed());
845 // Checks that a popup view is destroyed when a user taps outside of the popup
846 // view and focus does not change. This is the case when the user taps the
847 // desktop background on Chrome OS.
848 TEST_F(RenderWidgetHostViewAuraTest
, DestroyPopupTapOutsidePopup
) {
849 parent_view_
->SetBounds(gfx::Rect(10, 10, 400, 400));
850 parent_view_
->Focus();
851 EXPECT_TRUE(parent_view_
->HasFocus());
853 view_
->InitAsPopup(parent_view_
, gfx::Rect(10, 10, 100, 100));
854 aura::Window
* window
= view_
->GetNativeView();
855 ASSERT_TRUE(window
!= NULL
);
857 gfx::Point tap_point
;
858 EXPECT_FALSE(window
->GetBoundsInRootWindow().Contains(tap_point
));
859 aura::Window
* parent_window
= parent_view_
->GetNativeView();
860 EXPECT_FALSE(parent_window
->GetBoundsInRootWindow().Contains(tap_point
));
862 TestWindowObserver
observer(window
);
863 ui::test::EventGenerator
generator(window
->GetRootWindow(), tap_point
);
864 generator
.GestureTapAt(tap_point
);
865 ASSERT_TRUE(parent_view_
->HasFocus());
866 ASSERT_TRUE(observer
.destroyed());
872 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
874 // On Desktop Linux, select boxes need mouse capture in order to work. Test that
875 // when a select box is opened via a mouse press that it retains mouse capture
876 // after the mouse is released.
877 TEST_F(RenderWidgetHostViewAuraTest
, PopupRetainsCaptureAfterMouseRelease
) {
878 parent_view_
->SetBounds(gfx::Rect(10, 10, 400, 400));
879 parent_view_
->Focus();
880 EXPECT_TRUE(parent_view_
->HasFocus());
882 ui::test::EventGenerator
generator(
883 parent_view_
->GetNativeView()->GetRootWindow(), gfx::Point(300, 300));
884 generator
.PressLeftButton();
886 view_
->SetPopupType(blink::WebPopupTypeSelect
);
887 view_
->InitAsPopup(parent_view_
, gfx::Rect(10, 10, 100, 100));
888 ASSERT_TRUE(view_
->NeedsMouseCapture());
889 aura::Window
* window
= view_
->GetNativeView();
890 EXPECT_TRUE(window
->HasCapture());
892 generator
.ReleaseLeftButton();
893 EXPECT_TRUE(window
->HasCapture());
897 // Test that select boxes close when their parent window loses focus (e.g. due
898 // to an alert or system modal dialog).
899 TEST_F(RenderWidgetHostViewAuraTest
, PopupClosesWhenParentLosesFocus
) {
900 parent_view_
->SetBounds(gfx::Rect(10, 10, 400, 400));
901 parent_view_
->Focus();
902 EXPECT_TRUE(parent_view_
->HasFocus());
904 view_
->SetPopupType(blink::WebPopupTypeSelect
);
905 view_
->InitAsPopup(parent_view_
, gfx::Rect(10, 10, 100, 100));
907 aura::Window
* popup_window
= view_
->GetNativeView();
908 TestWindowObserver
observer(popup_window
);
910 aura::test::TestWindowDelegate delegate
;
911 scoped_ptr
<aura::Window
> dialog_window(new aura::Window(&delegate
));
912 dialog_window
->Init(aura::WINDOW_LAYER_TEXTURED
);
913 aura::client::ParentWindowWithContext(
914 dialog_window
.get(), popup_window
, gfx::Rect());
915 dialog_window
->Show();
916 wm::ActivateWindow(dialog_window
.get());
917 dialog_window
->Focus();
919 ASSERT_TRUE(wm::IsActiveWindow(dialog_window
.get()));
920 EXPECT_TRUE(observer
.destroyed());
926 // Checks that IME-composition-event state is maintained correctly.
927 TEST_F(RenderWidgetHostViewAuraTest
, SetCompositionText
) {
928 view_
->InitAsChild(NULL
);
931 ui::CompositionText composition_text
;
932 composition_text
.text
= base::ASCIIToUTF16("|a|b");
935 composition_text
.underlines
.push_back(
936 ui::CompositionUnderline(0, 3, 0xff000000, true, 0x78563412));
938 // Non-focused segment, with different background color.
939 composition_text
.underlines
.push_back(
940 ui::CompositionUnderline(3, 4, 0xff000000, false, 0xefcdab90));
942 const ui::CompositionUnderlines
& underlines
= composition_text
.underlines
;
944 // Caret is at the end. (This emulates Japanese MSIME 2007 and later)
945 composition_text
.selection
= gfx::Range(4);
947 sink_
->ClearMessages();
948 view_
->SetCompositionText(composition_text
);
949 EXPECT_TRUE(view_
->has_composition_text_
);
951 const IPC::Message
* msg
=
952 sink_
->GetFirstMessageMatching(InputMsg_ImeSetComposition::ID
);
953 ASSERT_TRUE(msg
!= NULL
);
955 InputMsg_ImeSetComposition::Param params
;
956 InputMsg_ImeSetComposition::Read(msg
, ¶ms
);
958 EXPECT_EQ(composition_text
.text
, get
<0>(params
));
960 ASSERT_EQ(underlines
.size(), get
<1>(params
).size());
961 for (size_t i
= 0; i
< underlines
.size(); ++i
) {
962 EXPECT_EQ(underlines
[i
].start_offset
, get
<1>(params
)[i
].startOffset
);
963 EXPECT_EQ(underlines
[i
].end_offset
, get
<1>(params
)[i
].endOffset
);
964 EXPECT_EQ(underlines
[i
].color
, get
<1>(params
)[i
].color
);
965 EXPECT_EQ(underlines
[i
].thick
, get
<1>(params
)[i
].thick
);
966 EXPECT_EQ(underlines
[i
].background_color
,
967 get
<1>(params
)[i
].backgroundColor
);
970 EXPECT_EQ(4, get
<2>(params
)) << "Should be the same to the caret pos";
971 EXPECT_EQ(4, get
<3>(params
)) << "Should be the same to the caret pos";
974 view_
->ImeCancelComposition();
975 EXPECT_FALSE(view_
->has_composition_text_
);
978 // Checks that sequence of IME-composition-event and mouse-event when mouse
979 // clicking to cancel the composition.
980 TEST_F(RenderWidgetHostViewAuraTest
, FinishCompositionByMouse
) {
981 view_
->InitAsChild(NULL
);
984 ui::CompositionText composition_text
;
985 composition_text
.text
= base::ASCIIToUTF16("|a|b");
988 composition_text
.underlines
.push_back(
989 ui::CompositionUnderline(0, 3, 0xff000000, true, 0x78563412));
991 // Non-focused segment, with different background color.
992 composition_text
.underlines
.push_back(
993 ui::CompositionUnderline(3, 4, 0xff000000, false, 0xefcdab90));
995 // Caret is at the end. (This emulates Japanese MSIME 2007 and later)
996 composition_text
.selection
= gfx::Range(4);
998 view_
->SetCompositionText(composition_text
);
999 EXPECT_TRUE(view_
->has_composition_text_
);
1000 sink_
->ClearMessages();
1002 // Simulates the mouse press.
1003 ui::MouseEvent
mouse_event(ui::ET_MOUSE_PRESSED
, gfx::Point(), gfx::Point(),
1004 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON
,
1006 view_
->OnMouseEvent(&mouse_event
);
1008 EXPECT_FALSE(view_
->has_composition_text_
);
1010 EXPECT_EQ(2U, sink_
->message_count());
1012 if (sink_
->message_count() == 2) {
1013 // Verify mouse event happens after the confirm-composition event.
1014 EXPECT_EQ(InputMsg_ImeConfirmComposition::ID
,
1015 sink_
->GetMessageAt(0)->type());
1016 EXPECT_EQ(InputMsg_HandleInputEvent::ID
,
1017 sink_
->GetMessageAt(1)->type());
1021 // Checks that touch-event state is maintained correctly.
1022 TEST_F(RenderWidgetHostViewAuraTest
, TouchEventState
) {
1023 view_
->InitAsChild(NULL
);
1025 GetSentMessageCountAndResetSink();
1027 // Start with no touch-event handler in the renderer.
1028 widget_host_
->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, false));
1030 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
,
1033 ui::EventTimeForNow());
1034 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
,
1037 ui::EventTimeForNow());
1038 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
,
1041 ui::EventTimeForNow());
1043 // The touch events should get forwared from the view, but they should not
1044 // reach the renderer.
1045 view_
->OnTouchEvent(&press
);
1046 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1047 EXPECT_TRUE(press
.synchronous_handling_disabled());
1048 EXPECT_EQ(blink::WebInputEvent::TouchStart
, view_
->touch_event_
->type
);
1049 EXPECT_TRUE(view_
->touch_event_
->cancelable
);
1050 EXPECT_EQ(1U, view_
->touch_event_
->touchesLength
);
1051 EXPECT_EQ(blink::WebTouchPoint::StatePressed
,
1052 view_
->touch_event_
->touches
[0].state
);
1054 view_
->OnTouchEvent(&move
);
1055 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1056 EXPECT_TRUE(press
.synchronous_handling_disabled());
1057 EXPECT_EQ(blink::WebInputEvent::TouchMove
, view_
->touch_event_
->type
);
1058 EXPECT_TRUE(view_
->touch_event_
->cancelable
);
1059 EXPECT_EQ(1U, view_
->touch_event_
->touchesLength
);
1060 EXPECT_EQ(blink::WebTouchPoint::StateMoved
,
1061 view_
->touch_event_
->touches
[0].state
);
1063 view_
->OnTouchEvent(&release
);
1064 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1065 EXPECT_TRUE(press
.synchronous_handling_disabled());
1066 EXPECT_EQ(nullptr, view_
->touch_event_
);
1068 // Now install some touch-event handlers and do the same steps. The touch
1069 // events should now be consumed. However, the touch-event state should be
1070 // updated as before.
1071 widget_host_
->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
1073 view_
->OnTouchEvent(&press
);
1074 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1075 EXPECT_TRUE(press
.synchronous_handling_disabled());
1076 EXPECT_EQ(blink::WebInputEvent::TouchStart
, view_
->touch_event_
->type
);
1077 EXPECT_TRUE(view_
->touch_event_
->cancelable
);
1078 EXPECT_EQ(1U, view_
->touch_event_
->touchesLength
);
1079 EXPECT_EQ(blink::WebTouchPoint::StatePressed
,
1080 view_
->touch_event_
->touches
[0].state
);
1082 view_
->OnTouchEvent(&move
);
1083 EXPECT_TRUE(move
.synchronous_handling_disabled());
1084 EXPECT_EQ(blink::WebInputEvent::TouchMove
, view_
->touch_event_
->type
);
1085 EXPECT_TRUE(view_
->touch_event_
->cancelable
);
1086 EXPECT_EQ(1U, view_
->touch_event_
->touchesLength
);
1087 EXPECT_EQ(blink::WebTouchPoint::StateMoved
,
1088 view_
->touch_event_
->touches
[0].state
);
1089 view_
->OnTouchEvent(&release
);
1090 EXPECT_TRUE(release
.synchronous_handling_disabled());
1091 EXPECT_EQ(nullptr, view_
->touch_event_
);
1093 // Now start a touch event, and remove the event-handlers before the release.
1094 view_
->OnTouchEvent(&press
);
1095 EXPECT_TRUE(press
.synchronous_handling_disabled());
1096 EXPECT_EQ(blink::WebInputEvent::TouchStart
, view_
->touch_event_
->type
);
1097 EXPECT_EQ(1U, view_
->touch_event_
->touchesLength
);
1098 EXPECT_EQ(blink::WebTouchPoint::StatePressed
,
1099 view_
->touch_event_
->touches
[0].state
);
1101 widget_host_
->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, false));
1103 // Ack'ing the outstanding event should flush the pending touch queue.
1104 InputHostMsg_HandleInputEvent_ACK_Params ack
;
1105 ack
.type
= blink::WebInputEvent::TouchStart
;
1106 ack
.state
= INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS
;
1107 widget_host_
->OnMessageReceived(InputHostMsg_HandleInputEvent_ACK(0, ack
));
1108 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1110 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(20, 20), 0,
1111 base::Time::NowFromSystemTime() - base::Time());
1112 view_
->OnTouchEvent(&move2
);
1113 EXPECT_TRUE(press
.synchronous_handling_disabled());
1114 EXPECT_EQ(blink::WebInputEvent::TouchMove
, view_
->touch_event_
->type
);
1115 EXPECT_EQ(1U, view_
->touch_event_
->touchesLength
);
1116 EXPECT_EQ(blink::WebTouchPoint::StateMoved
,
1117 view_
->touch_event_
->touches
[0].state
);
1119 ui::TouchEvent
release2(ui::ET_TOUCH_RELEASED
, gfx::Point(20, 20), 0,
1120 base::Time::NowFromSystemTime() - base::Time());
1121 view_
->OnTouchEvent(&release2
);
1122 EXPECT_TRUE(press
.synchronous_handling_disabled());
1123 EXPECT_EQ(nullptr, view_
->touch_event_
);
1126 // Checks that touch-events are queued properly when there is a touch-event
1127 // handler on the page.
1128 TEST_F(RenderWidgetHostViewAuraTest
, TouchEventSyncAsync
) {
1129 view_
->InitAsChild(NULL
);
1132 widget_host_
->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
1134 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
,
1137 ui::EventTimeForNow());
1138 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
,
1141 ui::EventTimeForNow());
1142 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
,
1145 ui::EventTimeForNow());
1147 view_
->OnTouchEvent(&press
);
1148 EXPECT_TRUE(press
.synchronous_handling_disabled());
1149 EXPECT_EQ(blink::WebInputEvent::TouchStart
, view_
->touch_event_
->type
);
1150 EXPECT_EQ(1U, view_
->touch_event_
->touchesLength
);
1151 EXPECT_EQ(blink::WebTouchPoint::StatePressed
,
1152 view_
->touch_event_
->touches
[0].state
);
1154 view_
->OnTouchEvent(&move
);
1155 EXPECT_TRUE(move
.synchronous_handling_disabled());
1156 EXPECT_EQ(blink::WebInputEvent::TouchMove
, view_
->touch_event_
->type
);
1157 EXPECT_EQ(1U, view_
->touch_event_
->touchesLength
);
1158 EXPECT_EQ(blink::WebTouchPoint::StateMoved
,
1159 view_
->touch_event_
->touches
[0].state
);
1161 // Send the same move event. Since the point hasn't moved, it won't affect the
1162 // queue. However, the view should consume the event.
1163 view_
->OnTouchEvent(&move
);
1164 EXPECT_TRUE(move
.synchronous_handling_disabled());
1165 EXPECT_EQ(blink::WebInputEvent::TouchMove
, view_
->touch_event_
->type
);
1166 EXPECT_EQ(1U, view_
->touch_event_
->touchesLength
);
1167 EXPECT_EQ(blink::WebTouchPoint::StateMoved
,
1168 view_
->touch_event_
->touches
[0].state
);
1170 view_
->OnTouchEvent(&release
);
1171 EXPECT_TRUE(release
.synchronous_handling_disabled());
1172 EXPECT_EQ(nullptr, view_
->touch_event_
);
1175 TEST_F(RenderWidgetHostViewAuraTest
, PhysicalBackingSizeWithScale
) {
1176 view_
->InitAsChild(NULL
);
1177 aura::client::ParentWindowWithContext(
1178 view_
->GetNativeView(),
1179 parent_view_
->GetNativeView()->GetRootWindow(),
1181 sink_
->ClearMessages();
1182 view_
->SetSize(gfx::Size(100, 100));
1183 EXPECT_EQ("100x100", view_
->GetPhysicalBackingSize().ToString());
1184 EXPECT_EQ(1u, sink_
->message_count());
1185 EXPECT_EQ(ViewMsg_Resize::ID
, sink_
->GetMessageAt(0)->type());
1187 const IPC::Message
* msg
= sink_
->GetMessageAt(0);
1188 EXPECT_EQ(ViewMsg_Resize::ID
, msg
->type());
1189 ViewMsg_Resize::Param params
;
1190 ViewMsg_Resize::Read(msg
, ¶ms
);
1191 EXPECT_EQ("100x100", get
<0>(params
).new_size
.ToString()); // dip size
1192 EXPECT_EQ("100x100",
1193 get
<0>(params
).physical_backing_size
.ToString()); // backing size
1196 widget_host_
->ResetSizeAndRepaintPendingFlags();
1197 sink_
->ClearMessages();
1199 aura_test_helper_
->test_screen()->SetDeviceScaleFactor(2.0f
);
1200 EXPECT_EQ("200x200", view_
->GetPhysicalBackingSize().ToString());
1201 // Extra ScreenInfoChanged message for |parent_view_|.
1202 EXPECT_EQ(1u, sink_
->message_count());
1204 const IPC::Message
* msg
= sink_
->GetMessageAt(0);
1205 EXPECT_EQ(ViewMsg_Resize::ID
, msg
->type());
1206 ViewMsg_Resize::Param params
;
1207 ViewMsg_Resize::Read(msg
, ¶ms
);
1208 EXPECT_EQ(2.0f
, get
<0>(params
).screen_info
.deviceScaleFactor
);
1209 EXPECT_EQ("100x100", get
<0>(params
).new_size
.ToString()); // dip size
1210 EXPECT_EQ("200x200",
1211 get
<0>(params
).physical_backing_size
.ToString()); // backing size
1214 widget_host_
->ResetSizeAndRepaintPendingFlags();
1215 sink_
->ClearMessages();
1217 aura_test_helper_
->test_screen()->SetDeviceScaleFactor(1.0f
);
1218 // Extra ScreenInfoChanged message for |parent_view_|.
1219 EXPECT_EQ(1u, sink_
->message_count());
1220 EXPECT_EQ("100x100", view_
->GetPhysicalBackingSize().ToString());
1222 const IPC::Message
* msg
= sink_
->GetMessageAt(0);
1223 EXPECT_EQ(ViewMsg_Resize::ID
, msg
->type());
1224 ViewMsg_Resize::Param params
;
1225 ViewMsg_Resize::Read(msg
, ¶ms
);
1226 EXPECT_EQ(1.0f
, get
<0>(params
).screen_info
.deviceScaleFactor
);
1227 EXPECT_EQ("100x100", get
<0>(params
).new_size
.ToString()); // dip size
1228 EXPECT_EQ("100x100",
1229 get
<0>(params
).physical_backing_size
.ToString()); // backing size
1233 // Checks that InputMsg_CursorVisibilityChange IPC messages are dispatched
1234 // to the renderer at the correct times.
1235 TEST_F(RenderWidgetHostViewAuraTest
, CursorVisibilityChange
) {
1236 view_
->InitAsChild(NULL
);
1237 aura::client::ParentWindowWithContext(
1238 view_
->GetNativeView(),
1239 parent_view_
->GetNativeView()->GetRootWindow(),
1241 view_
->SetSize(gfx::Size(100, 100));
1243 aura::test::TestCursorClient
cursor_client(
1244 parent_view_
->GetNativeView()->GetRootWindow());
1246 cursor_client
.AddObserver(view_
);
1248 // Expect a message the first time the cursor is shown.
1250 sink_
->ClearMessages();
1251 cursor_client
.ShowCursor();
1252 EXPECT_EQ(1u, sink_
->message_count());
1253 EXPECT_TRUE(sink_
->GetUniqueMessageMatching(
1254 InputMsg_CursorVisibilityChange::ID
));
1256 // No message expected if the renderer already knows the cursor is visible.
1257 sink_
->ClearMessages();
1258 cursor_client
.ShowCursor();
1259 EXPECT_EQ(0u, sink_
->message_count());
1261 // Hiding the cursor should send a message.
1262 sink_
->ClearMessages();
1263 cursor_client
.HideCursor();
1264 EXPECT_EQ(1u, sink_
->message_count());
1265 EXPECT_TRUE(sink_
->GetUniqueMessageMatching(
1266 InputMsg_CursorVisibilityChange::ID
));
1268 // No message expected if the renderer already knows the cursor is invisible.
1269 sink_
->ClearMessages();
1270 cursor_client
.HideCursor();
1271 EXPECT_EQ(0u, sink_
->message_count());
1273 // No messages should be sent while the view is invisible.
1275 sink_
->ClearMessages();
1276 cursor_client
.ShowCursor();
1277 EXPECT_EQ(0u, sink_
->message_count());
1278 cursor_client
.HideCursor();
1279 EXPECT_EQ(0u, sink_
->message_count());
1281 // Show the view. Since the cursor was invisible when the view was hidden,
1282 // no message should be sent.
1283 sink_
->ClearMessages();
1285 EXPECT_FALSE(sink_
->GetUniqueMessageMatching(
1286 InputMsg_CursorVisibilityChange::ID
));
1288 // No message expected if the renderer already knows the cursor is invisible.
1289 sink_
->ClearMessages();
1290 cursor_client
.HideCursor();
1291 EXPECT_EQ(0u, sink_
->message_count());
1293 // Showing the cursor should send a message.
1294 sink_
->ClearMessages();
1295 cursor_client
.ShowCursor();
1296 EXPECT_EQ(1u, sink_
->message_count());
1297 EXPECT_TRUE(sink_
->GetUniqueMessageMatching(
1298 InputMsg_CursorVisibilityChange::ID
));
1300 // No messages should be sent while the view is invisible.
1302 sink_
->ClearMessages();
1303 cursor_client
.HideCursor();
1304 EXPECT_EQ(0u, sink_
->message_count());
1306 // Show the view. Since the cursor was visible when the view was hidden,
1307 // a message is expected to be sent.
1308 sink_
->ClearMessages();
1310 EXPECT_TRUE(sink_
->GetUniqueMessageMatching(
1311 InputMsg_CursorVisibilityChange::ID
));
1313 cursor_client
.RemoveObserver(view_
);
1316 TEST_F(RenderWidgetHostViewAuraTest
, UpdateCursorIfOverSelf
) {
1317 view_
->InitAsChild(NULL
);
1318 aura::client::ParentWindowWithContext(
1319 view_
->GetNativeView(),
1320 parent_view_
->GetNativeView()->GetRootWindow(),
1323 // Note that all coordinates in this test are screen coordinates.
1324 view_
->SetBounds(gfx::Rect(60, 60, 100, 100));
1327 aura::test::TestCursorClient
cursor_client(
1328 parent_view_
->GetNativeView()->GetRootWindow());
1330 // Cursor is in the middle of the window.
1331 cursor_client
.reset_calls_to_set_cursor();
1332 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(110, 110));
1333 view_
->UpdateCursorIfOverSelf();
1334 EXPECT_EQ(1, cursor_client
.calls_to_set_cursor());
1336 // Cursor is near the top of the window.
1337 cursor_client
.reset_calls_to_set_cursor();
1338 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(80, 65));
1339 view_
->UpdateCursorIfOverSelf();
1340 EXPECT_EQ(1, cursor_client
.calls_to_set_cursor());
1342 // Cursor is near the bottom of the window.
1343 cursor_client
.reset_calls_to_set_cursor();
1344 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(159, 159));
1345 view_
->UpdateCursorIfOverSelf();
1346 EXPECT_EQ(1, cursor_client
.calls_to_set_cursor());
1348 // Cursor is above the window.
1349 cursor_client
.reset_calls_to_set_cursor();
1350 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(67, 59));
1351 view_
->UpdateCursorIfOverSelf();
1352 EXPECT_EQ(0, cursor_client
.calls_to_set_cursor());
1354 // Cursor is below the window.
1355 cursor_client
.reset_calls_to_set_cursor();
1356 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(161, 161));
1357 view_
->UpdateCursorIfOverSelf();
1358 EXPECT_EQ(0, cursor_client
.calls_to_set_cursor());
1361 scoped_ptr
<cc::CompositorFrame
> MakeDelegatedFrame(float scale_factor
,
1364 scoped_ptr
<cc::CompositorFrame
> frame(new cc::CompositorFrame
);
1365 frame
->metadata
.device_scale_factor
= scale_factor
;
1366 frame
->delegated_frame_data
.reset(new cc::DelegatedFrameData
);
1368 scoped_ptr
<cc::RenderPass
> pass
= cc::RenderPass::Create();
1370 cc::RenderPassId(1, 1), gfx::Rect(size
), damage
, gfx::Transform());
1371 frame
->delegated_frame_data
->render_pass_list
.push_back(pass
.Pass());
1372 return frame
.Pass();
1375 // Resizing in fullscreen mode should send the up-to-date screen info.
1376 // http://crbug.com/324350
1377 TEST_F(RenderWidgetHostViewAuraTest
, DISABLED_FullscreenResize
) {
1378 aura::Window
* root_window
= aura_test_helper_
->root_window();
1379 root_window
->SetLayoutManager(new FullscreenLayoutManager(root_window
));
1380 view_
->InitAsFullscreen(parent_view_
);
1382 widget_host_
->ResetSizeAndRepaintPendingFlags();
1383 sink_
->ClearMessages();
1385 // Call WasResized to flush the old screen info.
1386 view_
->GetRenderWidgetHost()->WasResized();
1388 // 0 is CreatingNew message.
1389 const IPC::Message
* msg
= sink_
->GetMessageAt(0);
1390 EXPECT_EQ(ViewMsg_Resize::ID
, msg
->type());
1391 ViewMsg_Resize::Param params
;
1392 ViewMsg_Resize::Read(msg
, ¶ms
);
1393 EXPECT_EQ("0,0 800x600",
1394 gfx::Rect(get
<0>(params
).screen_info
.availableRect
).ToString());
1395 EXPECT_EQ("800x600", get
<0>(params
).new_size
.ToString());
1396 // Resizes are blocked until we swapped a frame of the correct size, and
1397 // we've committed it.
1398 view_
->OnSwapCompositorFrame(
1401 1.f
, get
<0>(params
).new_size
, gfx::Rect(get
<0>(params
).new_size
)));
1402 ui::DrawWaiterForTest::WaitForCommit(
1403 root_window
->GetHost()->compositor());
1406 widget_host_
->ResetSizeAndRepaintPendingFlags();
1407 sink_
->ClearMessages();
1409 // Make sure the corrent screen size is set along in the resize
1410 // request when the screen size has changed.
1411 aura_test_helper_
->test_screen()->SetUIScale(0.5);
1412 EXPECT_EQ(1u, sink_
->message_count());
1414 const IPC::Message
* msg
= sink_
->GetMessageAt(0);
1415 EXPECT_EQ(ViewMsg_Resize::ID
, msg
->type());
1416 ViewMsg_Resize::Param params
;
1417 ViewMsg_Resize::Read(msg
, ¶ms
);
1418 EXPECT_EQ("0,0 1600x1200",
1419 gfx::Rect(get
<0>(params
).screen_info
.availableRect
).ToString());
1420 EXPECT_EQ("1600x1200", get
<0>(params
).new_size
.ToString());
1421 view_
->OnSwapCompositorFrame(
1424 1.f
, get
<0>(params
).new_size
, gfx::Rect(get
<0>(params
).new_size
)));
1425 ui::DrawWaiterForTest::WaitForCommit(
1426 root_window
->GetHost()->compositor());
1430 // Swapping a frame should notify the window.
1431 TEST_F(RenderWidgetHostViewAuraTest
, SwapNotifiesWindow
) {
1432 gfx::Size
view_size(100, 100);
1433 gfx::Rect
view_rect(view_size
);
1435 view_
->InitAsChild(NULL
);
1436 aura::client::ParentWindowWithContext(
1437 view_
->GetNativeView(),
1438 parent_view_
->GetNativeView()->GetRootWindow(),
1440 view_
->SetSize(view_size
);
1443 MockWindowObserver observer
;
1444 view_
->window_
->AddObserver(&observer
);
1446 // Delegated renderer path
1447 EXPECT_CALL(observer
, OnDelegatedFrameDamage(view_
->window_
, view_rect
));
1448 view_
->OnSwapCompositorFrame(
1449 0, MakeDelegatedFrame(1.f
, view_size
, view_rect
));
1450 testing::Mock::VerifyAndClearExpectations(&observer
);
1452 EXPECT_CALL(observer
, OnDelegatedFrameDamage(view_
->window_
,
1453 gfx::Rect(5, 5, 5, 5)));
1454 view_
->OnSwapCompositorFrame(
1455 0, MakeDelegatedFrame(1.f
, view_size
, gfx::Rect(5, 5, 5, 5)));
1456 testing::Mock::VerifyAndClearExpectations(&observer
);
1458 view_
->window_
->RemoveObserver(&observer
);
1461 // Recreating the layers for a window should cause Surface destruction to
1462 // depend on both layers.
1463 TEST_F(RenderWidgetHostViewAuraTest
, RecreateLayers
) {
1464 gfx::Size
view_size(100, 100);
1465 gfx::Rect
view_rect(view_size
);
1467 view_
->InitAsChild(NULL
);
1468 aura::client::ParentWindowWithContext(
1469 view_
->GetNativeView(), parent_view_
->GetNativeView()->GetRootWindow(),
1471 view_
->SetSize(view_size
);
1474 view_
->OnSwapCompositorFrame(0,
1475 MakeDelegatedFrame(1.f
, view_size
, view_rect
));
1476 scoped_ptr
<ui::LayerTreeOwner
> cloned_owner(
1477 wm::RecreateLayers(view_
->GetNativeView()));
1479 cc::SurfaceId id
= view_
->GetDelegatedFrameHost()->SurfaceIdForTesting();
1480 if (!id
.is_null()) {
1481 ImageTransportFactory
* factory
= ImageTransportFactory::GetInstance();
1482 cc::SurfaceManager
* manager
= factory
->GetSurfaceManager();
1483 cc::Surface
* surface
= manager
->GetSurfaceForId(id
);
1484 EXPECT_TRUE(surface
);
1485 // Should be a SurfaceSequence for both the original and new layers.
1486 EXPECT_EQ(2u, surface
->GetDestructionDependencyCount());
1490 TEST_F(RenderWidgetHostViewAuraTest
, Resize
) {
1491 gfx::Size
size1(100, 100);
1492 gfx::Size
size2(200, 200);
1493 gfx::Size
size3(300, 300);
1495 aura::Window
* root_window
= parent_view_
->GetNativeView()->GetRootWindow();
1496 view_
->InitAsChild(NULL
);
1497 aura::client::ParentWindowWithContext(
1498 view_
->GetNativeView(), root_window
, gfx::Rect(size1
));
1500 view_
->SetSize(size1
);
1501 view_
->OnSwapCompositorFrame(
1502 0, MakeDelegatedFrame(1.f
, size1
, gfx::Rect(size1
)));
1503 ui::DrawWaiterForTest::WaitForCommit(
1504 root_window
->GetHost()->compositor());
1505 ViewHostMsg_UpdateRect_Params update_params
;
1506 update_params
.view_size
= size1
;
1507 update_params
.flags
= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK
;
1508 widget_host_
->OnMessageReceived(
1509 ViewHostMsg_UpdateRect(widget_host_
->GetRoutingID(), update_params
));
1510 sink_
->ClearMessages();
1511 // Resize logic is idle (no pending resize, no pending commit).
1512 EXPECT_EQ(size1
.ToString(), view_
->GetRequestedRendererSize().ToString());
1514 // Resize renderer, should produce a Resize message
1515 view_
->SetSize(size2
);
1516 EXPECT_EQ(size2
.ToString(), view_
->GetRequestedRendererSize().ToString());
1517 EXPECT_EQ(1u, sink_
->message_count());
1519 const IPC::Message
* msg
= sink_
->GetMessageAt(0);
1520 EXPECT_EQ(ViewMsg_Resize::ID
, msg
->type());
1521 ViewMsg_Resize::Param params
;
1522 ViewMsg_Resize::Read(msg
, ¶ms
);
1523 EXPECT_EQ(size2
.ToString(), get
<0>(params
).new_size
.ToString());
1525 // Send resize ack to observe new Resize messages.
1526 update_params
.view_size
= size2
;
1527 widget_host_
->OnMessageReceived(
1528 ViewHostMsg_UpdateRect(widget_host_
->GetRoutingID(), update_params
));
1529 sink_
->ClearMessages();
1531 // Resize renderer again, before receiving a frame. Should not produce a
1533 view_
->SetSize(size3
);
1534 EXPECT_EQ(size2
.ToString(), view_
->GetRequestedRendererSize().ToString());
1535 EXPECT_EQ(0u, sink_
->message_count());
1537 // Receive a frame of the new size, should be skipped and not produce a Resize
1539 view_
->OnSwapCompositorFrame(
1540 0, MakeDelegatedFrame(1.f
, size3
, gfx::Rect(size3
)));
1541 // Expect the frame ack;
1542 EXPECT_EQ(1u, sink_
->message_count());
1543 EXPECT_EQ(ViewMsg_SwapCompositorFrameAck::ID
, sink_
->GetMessageAt(0)->type());
1544 sink_
->ClearMessages();
1545 EXPECT_EQ(size2
.ToString(), view_
->GetRequestedRendererSize().ToString());
1547 // Receive a frame of the correct size, should not be skipped and, and should
1548 // produce a Resize message after the commit.
1549 view_
->OnSwapCompositorFrame(
1550 0, MakeDelegatedFrame(1.f
, size2
, gfx::Rect(size2
)));
1551 cc::SurfaceId surface_id
= view_
->surface_id();
1552 if (surface_id
.is_null()) {
1553 // No frame ack yet.
1554 EXPECT_EQ(0u, sink_
->message_count());
1556 // Frame isn't desired size, so early ack.
1557 EXPECT_EQ(1u, sink_
->message_count());
1559 EXPECT_EQ(size2
.ToString(), view_
->GetRequestedRendererSize().ToString());
1561 // Wait for commit, then we should unlock the compositor and send a Resize
1562 // message (and a frame ack)
1563 ui::DrawWaiterForTest::WaitForCommit(
1564 root_window
->GetHost()->compositor());
1566 bool has_resize
= false;
1567 for (uint32 i
= 0; i
< sink_
->message_count(); ++i
) {
1568 const IPC::Message
* msg
= sink_
->GetMessageAt(i
);
1569 switch (msg
->type()) {
1570 case InputMsg_HandleInputEvent::ID
: {
1571 // On some platforms, the call to view_->Show() causes a posted task to
1573 // ui::WindowEventDispatcher::SynthesizeMouseMoveAfterChangeToWindow,
1574 // which the above WaitForCommit may cause to be picked up. Be robust
1575 // to this extra IPC coming in.
1576 InputMsg_HandleInputEvent::Param params
;
1577 InputMsg_HandleInputEvent::Read(msg
, ¶ms
);
1578 const blink::WebInputEvent
* event
= get
<0>(params
);
1579 EXPECT_EQ(blink::WebInputEvent::MouseMove
, event
->type
);
1582 case ViewMsg_SwapCompositorFrameAck::ID
:
1584 case ViewMsg_Resize::ID
: {
1585 EXPECT_FALSE(has_resize
);
1586 ViewMsg_Resize::Param params
;
1587 ViewMsg_Resize::Read(msg
, ¶ms
);
1588 EXPECT_EQ(size3
.ToString(), get
<0>(params
).new_size
.ToString());
1593 ADD_FAILURE() << "Unexpected message " << msg
->type();
1597 EXPECT_TRUE(has_resize
);
1598 update_params
.view_size
= size3
;
1599 widget_host_
->OnMessageReceived(
1600 ViewHostMsg_UpdateRect(widget_host_
->GetRoutingID(), update_params
));
1601 sink_
->ClearMessages();
1604 // Skipped frames should not drop their damage.
1605 TEST_F(RenderWidgetHostViewAuraTest
, SkippedDelegatedFrames
) {
1606 gfx::Rect
view_rect(100, 100);
1607 gfx::Size frame_size
= view_rect
.size();
1609 view_
->InitAsChild(NULL
);
1610 aura::client::ParentWindowWithContext(
1611 view_
->GetNativeView(),
1612 parent_view_
->GetNativeView()->GetRootWindow(),
1614 view_
->SetSize(view_rect
.size());
1616 MockWindowObserver observer
;
1617 view_
->window_
->AddObserver(&observer
);
1619 // A full frame of damage.
1620 EXPECT_CALL(observer
, OnDelegatedFrameDamage(view_
->window_
, view_rect
));
1621 view_
->OnSwapCompositorFrame(
1622 0, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1623 testing::Mock::VerifyAndClearExpectations(&observer
);
1624 view_
->RunOnCompositingDidCommit();
1626 // A partial damage frame.
1627 gfx::Rect
partial_view_rect(30, 30, 20, 20);
1628 EXPECT_CALL(observer
,
1629 OnDelegatedFrameDamage(view_
->window_
, partial_view_rect
));
1630 view_
->OnSwapCompositorFrame(
1631 0, MakeDelegatedFrame(1.f
, frame_size
, partial_view_rect
));
1632 testing::Mock::VerifyAndClearExpectations(&observer
);
1633 view_
->RunOnCompositingDidCommit();
1635 // Lock the compositor. Now we should drop frames.
1636 view_rect
= gfx::Rect(150, 150);
1637 view_
->SetSize(view_rect
.size());
1639 // This frame is dropped.
1640 gfx::Rect
dropped_damage_rect_1(10, 20, 30, 40);
1641 EXPECT_CALL(observer
, OnDelegatedFrameDamage(_
, _
)).Times(0);
1642 view_
->OnSwapCompositorFrame(
1643 0, MakeDelegatedFrame(1.f
, frame_size
, dropped_damage_rect_1
));
1644 testing::Mock::VerifyAndClearExpectations(&observer
);
1645 view_
->RunOnCompositingDidCommit();
1647 gfx::Rect
dropped_damage_rect_2(40, 50, 10, 20);
1648 EXPECT_CALL(observer
, OnDelegatedFrameDamage(_
, _
)).Times(0);
1649 view_
->OnSwapCompositorFrame(
1650 0, MakeDelegatedFrame(1.f
, frame_size
, dropped_damage_rect_2
));
1651 testing::Mock::VerifyAndClearExpectations(&observer
);
1652 view_
->RunOnCompositingDidCommit();
1654 // Unlock the compositor. This frame should damage everything.
1655 frame_size
= view_rect
.size();
1657 gfx::Rect
new_damage_rect(5, 6, 10, 10);
1658 EXPECT_CALL(observer
,
1659 OnDelegatedFrameDamage(view_
->window_
, view_rect
));
1660 view_
->OnSwapCompositorFrame(
1661 0, MakeDelegatedFrame(1.f
, frame_size
, new_damage_rect
));
1662 testing::Mock::VerifyAndClearExpectations(&observer
);
1663 view_
->RunOnCompositingDidCommit();
1665 // A partial damage frame, this should not be dropped.
1666 EXPECT_CALL(observer
,
1667 OnDelegatedFrameDamage(view_
->window_
, partial_view_rect
));
1668 view_
->OnSwapCompositorFrame(
1669 0, MakeDelegatedFrame(1.f
, frame_size
, partial_view_rect
));
1670 testing::Mock::VerifyAndClearExpectations(&observer
);
1671 view_
->RunOnCompositingDidCommit();
1674 // Resize to something empty.
1675 view_rect
= gfx::Rect(100, 0);
1676 view_
->SetSize(view_rect
.size());
1678 // We're never expecting empty frames, resize to something non-empty.
1679 view_rect
= gfx::Rect(100, 100);
1680 view_
->SetSize(view_rect
.size());
1682 // This frame should not be dropped.
1683 EXPECT_CALL(observer
, OnDelegatedFrameDamage(view_
->window_
, view_rect
));
1684 view_
->OnSwapCompositorFrame(
1685 0, MakeDelegatedFrame(1.f
, view_rect
.size(), view_rect
));
1686 testing::Mock::VerifyAndClearExpectations(&observer
);
1687 view_
->RunOnCompositingDidCommit();
1689 view_
->window_
->RemoveObserver(&observer
);
1692 TEST_F(RenderWidgetHostViewAuraTest
, OutputSurfaceIdChange
) {
1693 gfx::Rect
view_rect(100, 100);
1694 gfx::Size frame_size
= view_rect
.size();
1696 view_
->InitAsChild(NULL
);
1697 aura::client::ParentWindowWithContext(
1698 view_
->GetNativeView(),
1699 parent_view_
->GetNativeView()->GetRootWindow(),
1701 view_
->SetSize(view_rect
.size());
1703 MockWindowObserver observer
;
1704 view_
->window_
->AddObserver(&observer
);
1707 EXPECT_CALL(observer
, OnDelegatedFrameDamage(view_
->window_
, view_rect
));
1708 view_
->OnSwapCompositorFrame(
1709 0, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1710 testing::Mock::VerifyAndClearExpectations(&observer
);
1711 view_
->RunOnCompositingDidCommit();
1713 // Swap a frame with a different surface id.
1714 EXPECT_CALL(observer
, OnDelegatedFrameDamage(view_
->window_
, view_rect
));
1715 view_
->OnSwapCompositorFrame(
1716 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1717 testing::Mock::VerifyAndClearExpectations(&observer
);
1718 view_
->RunOnCompositingDidCommit();
1720 // Swap an empty frame, with a different surface id.
1721 view_
->OnSwapCompositorFrame(
1722 2, MakeDelegatedFrame(1.f
, gfx::Size(), gfx::Rect()));
1723 testing::Mock::VerifyAndClearExpectations(&observer
);
1724 view_
->RunOnCompositingDidCommit();
1726 // Swap another frame, with a different surface id.
1727 EXPECT_CALL(observer
, OnDelegatedFrameDamage(view_
->window_
, view_rect
));
1728 view_
->OnSwapCompositorFrame(3,
1729 MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1730 testing::Mock::VerifyAndClearExpectations(&observer
);
1731 view_
->RunOnCompositingDidCommit();
1733 view_
->window_
->RemoveObserver(&observer
);
1736 TEST_F(RenderWidgetHostViewAuraTest
, DiscardDelegatedFrames
) {
1737 size_t max_renderer_frames
=
1738 RendererFrameManager::GetInstance()->GetMaxNumberOfSavedFrames();
1739 ASSERT_LE(2u, max_renderer_frames
);
1740 size_t renderer_count
= max_renderer_frames
+ 1;
1741 gfx::Rect
view_rect(100, 100);
1742 gfx::Size frame_size
= view_rect
.size();
1743 DCHECK_EQ(0u, HostSharedBitmapManager::current()->AllocatedBitmapCount());
1745 scoped_ptr
<RenderWidgetHostImpl
* []> hosts(
1746 new RenderWidgetHostImpl
* [renderer_count
]);
1747 scoped_ptr
<FakeRenderWidgetHostViewAura
* []> views(
1748 new FakeRenderWidgetHostViewAura
* [renderer_count
]);
1750 // Create a bunch of renderers.
1751 for (size_t i
= 0; i
< renderer_count
; ++i
) {
1752 hosts
[i
] = new RenderWidgetHostImpl(
1753 &delegate_
, process_host_
, MSG_ROUTING_NONE
, false);
1755 views
[i
] = new FakeRenderWidgetHostViewAura(hosts
[i
], false);
1756 views
[i
]->InitAsChild(NULL
);
1757 aura::client::ParentWindowWithContext(
1758 views
[i
]->GetNativeView(),
1759 parent_view_
->GetNativeView()->GetRootWindow(),
1761 views
[i
]->SetSize(view_rect
.size());
1764 // Make each renderer visible, and swap a frame on it, then make it invisible.
1765 for (size_t i
= 0; i
< renderer_count
; ++i
) {
1767 views
[i
]->OnSwapCompositorFrame(
1768 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1769 EXPECT_TRUE(views
[i
]->HasFrameData());
1773 // There should be max_renderer_frames with a frame in it, and one without it.
1774 // Since the logic is LRU eviction, the first one should be without.
1775 EXPECT_FALSE(views
[0]->HasFrameData());
1776 for (size_t i
= 1; i
< renderer_count
; ++i
)
1777 EXPECT_TRUE(views
[i
]->HasFrameData());
1779 // LRU renderer is [0], make it visible, it shouldn't evict anything yet.
1781 EXPECT_FALSE(views
[0]->HasFrameData());
1782 EXPECT_TRUE(views
[1]->HasFrameData());
1783 // Since [0] doesn't have a frame, it should be waiting for the renderer to
1785 EXPECT_TRUE(views
[0]->released_front_lock_active());
1787 // Swap a frame on it, it should evict the next LRU [1].
1788 views
[0]->OnSwapCompositorFrame(
1789 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1790 EXPECT_TRUE(views
[0]->HasFrameData());
1791 EXPECT_FALSE(views
[1]->HasFrameData());
1792 // Now that [0] got a frame, it shouldn't be waiting any more.
1793 EXPECT_FALSE(views
[0]->released_front_lock_active());
1796 // LRU renderer is [1], still hidden. Swap a frame on it, it should evict
1797 // the next LRU [2].
1798 views
[1]->OnSwapCompositorFrame(
1799 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1800 EXPECT_TRUE(views
[0]->HasFrameData());
1801 EXPECT_TRUE(views
[1]->HasFrameData());
1802 EXPECT_FALSE(views
[2]->HasFrameData());
1803 for (size_t i
= 3; i
< renderer_count
; ++i
)
1804 EXPECT_TRUE(views
[i
]->HasFrameData());
1806 // Make all renderers but [0] visible and swap a frame on them, keep [0]
1807 // hidden, it becomes the LRU.
1808 for (size_t i
= 1; i
< renderer_count
; ++i
) {
1810 // The renderers who don't have a frame should be waiting. The ones that
1811 // have a frame should not.
1812 // In practice, [1] has a frame, but anything after has its frame evicted.
1813 EXPECT_EQ(!views
[i
]->HasFrameData(),
1814 views
[i
]->released_front_lock_active());
1815 views
[i
]->OnSwapCompositorFrame(
1816 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1817 // Now everyone has a frame.
1818 EXPECT_FALSE(views
[i
]->released_front_lock_active());
1819 EXPECT_TRUE(views
[i
]->HasFrameData());
1821 EXPECT_FALSE(views
[0]->HasFrameData());
1823 // Swap a frame on [0], it should be evicted immediately.
1824 views
[0]->OnSwapCompositorFrame(
1825 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1826 EXPECT_FALSE(views
[0]->HasFrameData());
1828 // Make [0] visible, and swap a frame on it. Nothing should be evicted
1829 // although we're above the limit.
1831 // We don't have a frame, wait.
1832 EXPECT_TRUE(views
[0]->released_front_lock_active());
1833 views
[0]->OnSwapCompositorFrame(
1834 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1835 EXPECT_FALSE(views
[0]->released_front_lock_active());
1836 for (size_t i
= 0; i
< renderer_count
; ++i
)
1837 EXPECT_TRUE(views
[i
]->HasFrameData());
1839 // Make [0] hidden, it should evict its frame.
1841 EXPECT_FALSE(views
[0]->HasFrameData());
1843 // Make [0] visible, don't give it a frame, it should be waiting.
1845 EXPECT_TRUE(views
[0]->released_front_lock_active());
1846 // Make [0] hidden, it should stop waiting.
1848 EXPECT_FALSE(views
[0]->released_front_lock_active());
1850 // Make [1] hidden, resize it. It should drop its frame.
1852 EXPECT_TRUE(views
[1]->HasFrameData());
1853 gfx::Size
size2(200, 200);
1854 views
[1]->SetSize(size2
);
1855 EXPECT_FALSE(views
[1]->HasFrameData());
1856 // Show it, it should block until we give it a frame.
1858 EXPECT_TRUE(views
[1]->released_front_lock_active());
1859 views
[1]->OnSwapCompositorFrame(
1860 1, MakeDelegatedFrame(1.f
, size2
, gfx::Rect(size2
)));
1861 EXPECT_FALSE(views
[1]->released_front_lock_active());
1863 for (size_t i
= 0; i
< renderer_count
- 1; ++i
)
1866 // Allocate enough bitmaps so that two frames (proportionally) would be
1867 // enough hit the handle limit.
1868 int handles_per_frame
= 5;
1869 RendererFrameManager::GetInstance()->set_max_handles(handles_per_frame
* 2);
1871 HostSharedBitmapManagerClient
bitmap_client(
1872 HostSharedBitmapManager::current());
1874 for (size_t i
= 0; i
< (renderer_count
- 1) * handles_per_frame
; i
++) {
1875 bitmap_client
.ChildAllocatedSharedBitmap(
1876 1, base::SharedMemory::NULLHandle(), base::GetCurrentProcessHandle(),
1877 cc::SharedBitmap::GenerateId());
1880 // Hiding this last bitmap should evict all but two frames.
1881 views
[renderer_count
- 1]->Hide();
1882 for (size_t i
= 0; i
< renderer_count
; ++i
) {
1883 if (i
+ 2 < renderer_count
)
1884 EXPECT_FALSE(views
[i
]->HasFrameData());
1886 EXPECT_TRUE(views
[i
]->HasFrameData());
1888 RendererFrameManager::GetInstance()->set_max_handles(
1889 base::SharedMemory::GetHandleLimit());
1891 for (size_t i
= 0; i
< renderer_count
; ++i
) {
1892 views
[i
]->Destroy();
1897 TEST_F(RenderWidgetHostViewAuraTest
, DiscardDelegatedFramesWithLocking
) {
1898 size_t max_renderer_frames
=
1899 RendererFrameManager::GetInstance()->GetMaxNumberOfSavedFrames();
1900 ASSERT_LE(2u, max_renderer_frames
);
1901 size_t renderer_count
= max_renderer_frames
+ 1;
1902 gfx::Rect
view_rect(100, 100);
1903 gfx::Size frame_size
= view_rect
.size();
1904 DCHECK_EQ(0u, HostSharedBitmapManager::current()->AllocatedBitmapCount());
1906 scoped_ptr
<RenderWidgetHostImpl
* []> hosts(
1907 new RenderWidgetHostImpl
* [renderer_count
]);
1908 scoped_ptr
<FakeRenderWidgetHostViewAura
* []> views(
1909 new FakeRenderWidgetHostViewAura
* [renderer_count
]);
1911 // Create a bunch of renderers.
1912 for (size_t i
= 0; i
< renderer_count
; ++i
) {
1913 hosts
[i
] = new RenderWidgetHostImpl(
1914 &delegate_
, process_host_
, MSG_ROUTING_NONE
, false);
1916 views
[i
] = new FakeRenderWidgetHostViewAura(hosts
[i
], false);
1917 views
[i
]->InitAsChild(NULL
);
1918 aura::client::ParentWindowWithContext(
1919 views
[i
]->GetNativeView(),
1920 parent_view_
->GetNativeView()->GetRootWindow(),
1922 views
[i
]->SetSize(view_rect
.size());
1925 // Make each renderer visible and swap a frame on it. No eviction should
1926 // occur because all frames are visible.
1927 for (size_t i
= 0; i
< renderer_count
; ++i
) {
1929 views
[i
]->OnSwapCompositorFrame(
1930 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1931 EXPECT_TRUE(views
[i
]->HasFrameData());
1934 // If we hide [0], then [0] should be evicted.
1936 EXPECT_FALSE(views
[0]->HasFrameData());
1938 // If we lock [0] before hiding it, then [0] should not be evicted.
1940 views
[0]->OnSwapCompositorFrame(
1941 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1942 EXPECT_TRUE(views
[0]->HasFrameData());
1943 views
[0]->GetDelegatedFrameHost()->LockResources();
1945 EXPECT_TRUE(views
[0]->HasFrameData());
1947 // If we unlock [0] now, then [0] should be evicted.
1948 views
[0]->GetDelegatedFrameHost()->UnlockResources();
1949 EXPECT_FALSE(views
[0]->HasFrameData());
1951 for (size_t i
= 0; i
< renderer_count
; ++i
) {
1952 views
[i
]->Destroy();
1957 // Test that changing the memory pressure should delete saved frames. This test
1958 // only applies to ChromeOS.
1959 TEST_F(RenderWidgetHostViewAuraTest
, DiscardDelegatedFramesWithMemoryPressure
) {
1960 size_t max_renderer_frames
=
1961 RendererFrameManager::GetInstance()->GetMaxNumberOfSavedFrames();
1962 ASSERT_LE(2u, max_renderer_frames
);
1963 size_t renderer_count
= max_renderer_frames
;
1964 gfx::Rect
view_rect(100, 100);
1965 gfx::Size frame_size
= view_rect
.size();
1966 DCHECK_EQ(0u, HostSharedBitmapManager::current()->AllocatedBitmapCount());
1968 scoped_ptr
<RenderWidgetHostImpl
* []> hosts(
1969 new RenderWidgetHostImpl
* [renderer_count
]);
1970 scoped_ptr
<FakeRenderWidgetHostViewAura
* []> views(
1971 new FakeRenderWidgetHostViewAura
* [renderer_count
]);
1973 // Create a bunch of renderers.
1974 for (size_t i
= 0; i
< renderer_count
; ++i
) {
1975 hosts
[i
] = new RenderWidgetHostImpl(
1976 &delegate_
, process_host_
, MSG_ROUTING_NONE
, false);
1978 views
[i
] = new FakeRenderWidgetHostViewAura(hosts
[i
], false);
1979 views
[i
]->InitAsChild(NULL
);
1980 aura::client::ParentWindowWithContext(
1981 views
[i
]->GetNativeView(),
1982 parent_view_
->GetNativeView()->GetRootWindow(),
1984 views
[i
]->SetSize(view_rect
.size());
1987 // Make each renderer visible and swap a frame on it. No eviction should
1988 // occur because all frames are visible.
1989 for (size_t i
= 0; i
< renderer_count
; ++i
) {
1991 views
[i
]->OnSwapCompositorFrame(
1992 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1993 EXPECT_TRUE(views
[i
]->HasFrameData());
1996 // If we hide one, it should not get evicted.
1998 message_loop_
.RunUntilIdle();
1999 EXPECT_TRUE(views
[0]->HasFrameData());
2000 // Using a lesser memory pressure event however, should evict.
2001 SimulateMemoryPressure(
2002 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE
);
2003 message_loop_
.RunUntilIdle();
2004 EXPECT_FALSE(views
[0]->HasFrameData());
2006 // Check the same for a higher pressure event.
2008 message_loop_
.RunUntilIdle();
2009 EXPECT_TRUE(views
[1]->HasFrameData());
2010 SimulateMemoryPressure(
2011 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL
);
2012 message_loop_
.RunUntilIdle();
2013 EXPECT_FALSE(views
[1]->HasFrameData());
2015 for (size_t i
= 0; i
< renderer_count
; ++i
) {
2016 views
[i
]->Destroy();
2021 TEST_F(RenderWidgetHostViewAuraTest
, SoftwareDPIChange
) {
2022 gfx::Rect
view_rect(100, 100);
2023 gfx::Size
frame_size(100, 100);
2025 view_
->InitAsChild(NULL
);
2026 aura::client::ParentWindowWithContext(
2027 view_
->GetNativeView(),
2028 parent_view_
->GetNativeView()->GetRootWindow(),
2030 view_
->SetSize(view_rect
.size());
2033 // With a 1x DPI UI and 1x DPI Renderer.
2034 view_
->OnSwapCompositorFrame(
2035 1, MakeDelegatedFrame(1.f
, frame_size
, gfx::Rect(frame_size
)));
2037 // Save the frame provider.
2038 scoped_refptr
<cc::DelegatedFrameProvider
> frame_provider
=
2039 view_
->frame_provider();
2040 cc::SurfaceId surface_id
= view_
->surface_id();
2042 // This frame will have the same number of physical pixels, but has a new
2044 view_
->OnSwapCompositorFrame(
2045 1, MakeDelegatedFrame(2.f
, frame_size
, gfx::Rect(frame_size
)));
2047 // When we get a new frame with the same frame size in physical pixels, but a
2048 // different scale, we should generate a new frame provider, as the final
2049 // result will need to be scaled differently to the screen.
2050 if (frame_provider
.get())
2051 EXPECT_NE(frame_provider
.get(), view_
->frame_provider());
2053 EXPECT_NE(surface_id
, view_
->surface_id());
2056 class RenderWidgetHostViewAuraCopyRequestTest
2057 : public RenderWidgetHostViewAuraShutdownTest
{
2059 RenderWidgetHostViewAuraCopyRequestTest()
2060 : callback_count_(0), result_(false) {}
2062 void CallbackMethod(const base::Closure
& quit_closure
, bool result
) {
2068 int callback_count_
;
2072 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraCopyRequestTest
);
2075 TEST_F(RenderWidgetHostViewAuraCopyRequestTest
, DestroyedAfterCopyRequest
) {
2076 base::RunLoop run_loop
;
2078 gfx::Rect
view_rect(100, 100);
2079 scoped_ptr
<cc::CopyOutputRequest
> request
;
2081 view_
->InitAsChild(NULL
);
2082 view_
->GetDelegatedFrameHost()->SetRequestCopyOfOutputCallbackForTesting(
2083 base::Bind(&FakeRenderWidgetHostViewAura::InterceptCopyOfOutput
,
2084 base::Unretained(view_
)));
2085 aura::client::ParentWindowWithContext(
2086 view_
->GetNativeView(),
2087 parent_view_
->GetNativeView()->GetRootWindow(),
2089 view_
->SetSize(view_rect
.size());
2092 scoped_ptr
<FakeFrameSubscriber
> frame_subscriber(new FakeFrameSubscriber(
2094 base::Bind(&RenderWidgetHostViewAuraCopyRequestTest::CallbackMethod
,
2095 base::Unretained(this),
2096 run_loop
.QuitClosure())));
2098 EXPECT_EQ(0, callback_count_
);
2099 EXPECT_FALSE(view_
->last_copy_request_
);
2101 view_
->BeginFrameSubscription(frame_subscriber
.Pass());
2102 view_
->OnSwapCompositorFrame(
2103 1, MakeDelegatedFrame(1.f
, view_rect
.size(), gfx::Rect(view_rect
)));
2105 EXPECT_EQ(0, callback_count_
);
2106 EXPECT_TRUE(view_
->last_copy_request_
);
2107 EXPECT_TRUE(view_
->last_copy_request_
->has_texture_mailbox());
2108 request
= view_
->last_copy_request_
.Pass();
2110 // Send back the mailbox included in the request. There's no release callback
2111 // since the mailbox came from the RWHVA originally.
2112 request
->SendTextureResult(view_rect
.size(),
2113 request
->texture_mailbox(),
2114 scoped_ptr
<cc::SingleReleaseCallback
>());
2116 // This runs until the callback happens.
2119 // The callback should succeed.
2120 EXPECT_EQ(1, callback_count_
);
2121 EXPECT_TRUE(result_
);
2123 view_
->OnSwapCompositorFrame(
2124 1, MakeDelegatedFrame(1.f
, view_rect
.size(), gfx::Rect(view_rect
)));
2126 EXPECT_EQ(1, callback_count_
);
2127 request
= view_
->last_copy_request_
.Pass();
2129 // Destroy the RenderWidgetHostViewAura and ImageTransportFactory.
2130 TearDownEnvironment();
2132 // Send back the mailbox included in the request. There's no release callback
2133 // since the mailbox came from the RWHVA originally.
2134 request
->SendTextureResult(view_rect
.size(),
2135 request
->texture_mailbox(),
2136 scoped_ptr
<cc::SingleReleaseCallback
>());
2138 // Because the copy request callback may be holding state within it, that
2139 // state must handle the RWHVA and ImageTransportFactory going away before the
2140 // callback is called. This test passes if it does not crash as a result of
2141 // these things being destroyed.
2142 EXPECT_EQ(2, callback_count_
);
2143 EXPECT_FALSE(result_
);
2146 TEST_F(RenderWidgetHostViewAuraTest
, VisibleViewportTest
) {
2147 gfx::Rect
view_rect(100, 100);
2149 view_
->InitAsChild(NULL
);
2150 aura::client::ParentWindowWithContext(
2151 view_
->GetNativeView(),
2152 parent_view_
->GetNativeView()->GetRootWindow(),
2154 view_
->SetSize(view_rect
.size());
2157 // Defaults to full height of the view.
2158 EXPECT_EQ(100, view_
->GetVisibleViewportSize().height());
2160 widget_host_
->ResetSizeAndRepaintPendingFlags();
2161 sink_
->ClearMessages();
2162 view_
->SetInsets(gfx::Insets(0, 0, 40, 0));
2164 EXPECT_EQ(60, view_
->GetVisibleViewportSize().height());
2166 const IPC::Message
*message
= sink_
->GetFirstMessageMatching(
2167 ViewMsg_Resize::ID
);
2168 ASSERT_TRUE(message
!= NULL
);
2170 ViewMsg_Resize::Param params
;
2171 ViewMsg_Resize::Read(message
, ¶ms
);
2172 EXPECT_EQ(60, get
<0>(params
).visible_viewport_size
.height());
2175 // Ensures that touch event positions are never truncated to integers.
2176 TEST_F(RenderWidgetHostViewAuraTest
, TouchEventPositionsArentRounded
) {
2177 const float kX
= 30.58f
;
2178 const float kY
= 50.23f
;
2180 view_
->InitAsChild(NULL
);
2183 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
,
2184 gfx::PointF(kX
, kY
),
2186 ui::EventTimeForNow());
2188 view_
->OnTouchEvent(&press
);
2189 EXPECT_EQ(blink::WebInputEvent::TouchStart
, view_
->touch_event_
->type
);
2190 EXPECT_TRUE(view_
->touch_event_
->cancelable
);
2191 EXPECT_EQ(1U, view_
->touch_event_
->touchesLength
);
2192 EXPECT_EQ(blink::WebTouchPoint::StatePressed
,
2193 view_
->touch_event_
->touches
[0].state
);
2194 EXPECT_EQ(kX
, view_
->touch_event_
->touches
[0].screenPosition
.x
);
2195 EXPECT_EQ(kX
, view_
->touch_event_
->touches
[0].position
.x
);
2196 EXPECT_EQ(kY
, view_
->touch_event_
->touches
[0].screenPosition
.y
);
2197 EXPECT_EQ(kY
, view_
->touch_event_
->touches
[0].position
.y
);
2200 // Tests that scroll ACKs are correctly handled by the overscroll-navigation
2202 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, WheelScrollEventOverscrolls
) {
2203 SetUpOverscrollEnvironment();
2205 // Simulate wheel events.
2206 SimulateWheelEvent(-5, 0, 0, true); // sent directly
2207 SimulateWheelEvent(-1, 1, 0, true); // enqueued
2208 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
2209 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
2210 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
2211 SimulateWheelEvent(-20, 6, 1, true); // enqueued, different modifiers
2212 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2213 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2215 // Receive ACK the first wheel event as not processed.
2216 SendInputEventACK(WebInputEvent::MouseWheel
,
2217 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2218 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2219 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2220 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2222 // Receive ACK for the second (coalesced) event as not processed. This will
2223 // start a back navigation. However, this will also cause the queued next
2224 // event to be sent to the renderer. But since overscroll navigation has
2225 // started, that event will also be included in the overscroll computation
2226 // instead of being sent to the renderer. So the result will be an overscroll
2227 // back navigation, and no event will be sent to the renderer.
2228 SendInputEventACK(WebInputEvent::MouseWheel
,
2229 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2230 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_mode());
2231 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_delegate()->current_mode());
2232 EXPECT_EQ(-81.f
, overscroll_delta_x());
2233 EXPECT_EQ(-31.f
, overscroll_delegate()->delta_x());
2234 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2235 EXPECT_EQ(0U, sink_
->message_count());
2237 // Send a mouse-move event. This should cancel the overscroll navigation.
2238 SimulateMouseMove(5, 10, 0);
2239 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2240 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2241 EXPECT_EQ(1U, sink_
->message_count());
2244 // Tests that if some scroll events are consumed towards the start, then
2245 // subsequent scrolls do not horizontal overscroll.
2246 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
2247 WheelScrollConsumedDoNotHorizOverscroll
) {
2248 SetUpOverscrollEnvironment();
2250 // Simulate wheel events.
2251 SimulateWheelEvent(-5, 0, 0, true); // sent directly
2252 SimulateWheelEvent(-1, -1, 0, true); // enqueued
2253 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
2254 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
2255 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
2256 SimulateWheelEvent(-20, 6, 1, true); // enqueued, different modifiers
2257 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2258 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2260 // Receive ACK the first wheel event as processed.
2261 SendInputEventACK(WebInputEvent::MouseWheel
, INPUT_EVENT_ACK_STATE_CONSUMED
);
2262 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2263 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2264 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2266 // Receive ACK for the second (coalesced) event as not processed. This should
2267 // not initiate overscroll, since the beginning of the scroll has been
2268 // consumed. The queued event with different modifiers should be sent to the
2270 SendInputEventACK(WebInputEvent::MouseWheel
,
2271 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2272 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2273 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2275 SendInputEventACK(WebInputEvent::MouseWheel
,
2276 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2277 EXPECT_EQ(0U, sink_
->message_count());
2278 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2280 // Indicate the end of the scrolling from the touchpad.
2281 SimulateGestureFlingStartEvent(-1200.f
, 0.f
, blink::WebGestureDeviceTouchpad
);
2282 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2284 // Start another scroll. This time, do not consume any scroll events.
2285 SimulateWheelEvent(0, -5, 0, true); // sent directly
2286 SimulateWheelEvent(0, -1, 0, true); // enqueued
2287 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
2288 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
2289 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
2290 SimulateWheelEvent(-20, 6, 1, true); // enqueued, different modifiers
2291 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2292 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2294 // Receive ACK for the first wheel and the subsequent coalesced event as not
2295 // processed. This should start a back-overscroll.
2296 SendInputEventACK(WebInputEvent::MouseWheel
,
2297 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2298 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2299 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2300 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2301 SendInputEventACK(WebInputEvent::MouseWheel
,
2302 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2303 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_mode());
2306 // Tests that wheel-scrolling correctly turns overscroll on and off.
2307 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, WheelScrollOverscrollToggle
) {
2308 SetUpOverscrollEnvironment();
2310 // Send a wheel event. ACK the event as not processed. This should not
2311 // initiate an overscroll gesture since it doesn't cross the threshold yet.
2312 SimulateWheelEvent(10, 0, 0, true);
2313 SendInputEventACK(WebInputEvent::MouseWheel
,
2314 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2315 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2316 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2317 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2319 // Scroll some more so as to not overscroll.
2320 SimulateWheelEvent(10, 0, 0, true);
2321 SendInputEventACK(WebInputEvent::MouseWheel
,
2322 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2323 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2324 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2325 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2327 // Scroll some more to initiate an overscroll.
2328 SimulateWheelEvent(40, 0, 0, true);
2329 SendInputEventACK(WebInputEvent::MouseWheel
,
2330 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2331 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2332 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2333 EXPECT_EQ(60.f
, overscroll_delta_x());
2334 EXPECT_EQ(10.f
, overscroll_delegate()->delta_x());
2335 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2336 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2338 // Scroll in the reverse direction enough to abort the overscroll.
2339 SimulateWheelEvent(-20, 0, 0, true);
2340 EXPECT_EQ(0U, sink_
->message_count());
2341 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2342 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2344 // Continue to scroll in the reverse direction.
2345 SimulateWheelEvent(-20, 0, 0, true);
2346 SendInputEventACK(WebInputEvent::MouseWheel
,
2347 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2348 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2349 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2350 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2352 // Continue to scroll in the reverse direction enough to initiate overscroll
2353 // in that direction.
2354 SimulateWheelEvent(-55, 0, 0, true);
2355 EXPECT_EQ(1U, sink_
->message_count());
2356 SendInputEventACK(WebInputEvent::MouseWheel
,
2357 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2358 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_mode());
2359 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_delegate()->current_mode());
2360 EXPECT_EQ(-75.f
, overscroll_delta_x());
2361 EXPECT_EQ(-25.f
, overscroll_delegate()->delta_x());
2362 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2365 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
2366 ScrollEventsOverscrollWithFling
) {
2367 SetUpOverscrollEnvironment();
2369 // Send a wheel event. ACK the event as not processed. This should not
2370 // initiate an overscroll gesture since it doesn't cross the threshold yet.
2371 SimulateWheelEvent(10, 0, 0, true);
2372 SendInputEventACK(WebInputEvent::MouseWheel
,
2373 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2374 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2375 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2376 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2378 // Scroll some more so as to not overscroll.
2379 SimulateWheelEvent(20, 0, 0, true);
2380 EXPECT_EQ(1U, sink_
->message_count());
2381 SendInputEventACK(WebInputEvent::MouseWheel
,
2382 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2383 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2384 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2385 sink_
->ClearMessages();
2387 // Scroll some more to initiate an overscroll.
2388 SimulateWheelEvent(30, 0, 0, true);
2389 SendInputEventACK(WebInputEvent::MouseWheel
,
2390 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2391 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2392 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2393 EXPECT_EQ(60.f
, overscroll_delta_x());
2394 EXPECT_EQ(10.f
, overscroll_delegate()->delta_x());
2395 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2396 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2398 // Send a fling start, but with a small velocity, so that the overscroll is
2399 // aborted. The fling should proceed to the renderer, through the gesture
2401 SimulateGestureFlingStartEvent(0.f
, 0.1f
, blink::WebGestureDeviceTouchpad
);
2402 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2403 EXPECT_EQ(1U, sink_
->message_count());
2406 // Same as ScrollEventsOverscrollWithFling, but with zero velocity. Checks that
2407 // the zero-velocity fling does not reach the renderer.
2408 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
2409 ScrollEventsOverscrollWithZeroFling
) {
2410 SetUpOverscrollEnvironment();
2412 // Send a wheel event. ACK the event as not processed. This should not
2413 // initiate an overscroll gesture since it doesn't cross the threshold yet.
2414 SimulateWheelEvent(10, 0, 0, true);
2415 SendInputEventACK(WebInputEvent::MouseWheel
,
2416 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2417 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2418 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2419 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2421 // Scroll some more so as to not overscroll.
2422 SimulateWheelEvent(20, 0, 0, true);
2423 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2424 SendInputEventACK(WebInputEvent::MouseWheel
,
2425 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2426 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2427 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2429 // Scroll some more to initiate an overscroll.
2430 SimulateWheelEvent(30, 0, 0, true);
2431 SendInputEventACK(WebInputEvent::MouseWheel
,
2432 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2433 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2434 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2435 EXPECT_EQ(60.f
, overscroll_delta_x());
2436 EXPECT_EQ(10.f
, overscroll_delegate()->delta_x());
2437 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2438 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2440 // Send a fling start, but with a small velocity, so that the overscroll is
2441 // aborted. The fling should proceed to the renderer, through the gesture
2443 SimulateGestureFlingStartEvent(10.f
, 0.f
, blink::WebGestureDeviceTouchpad
);
2444 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2445 EXPECT_EQ(1U, sink_
->message_count());
2448 // Tests that a fling in the opposite direction of the overscroll cancels the
2449 // overscroll nav instead of completing it.
2450 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, ReverseFlingCancelsOverscroll
) {
2451 SetUpOverscrollEnvironment();
2454 // Start and end a gesture in the same direction without processing the
2455 // gesture events in the renderer. This should initiate and complete an
2456 // overscroll navigation.
2457 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2458 blink::WebGestureDeviceTouchscreen
);
2459 SimulateGestureScrollUpdateEvent(300, -5, 0);
2460 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2461 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2462 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2463 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2464 sink_
->ClearMessages();
2466 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
2467 blink::WebGestureDeviceTouchscreen
);
2468 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->completed_mode());
2469 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2470 EXPECT_EQ(1U, sink_
->message_count());
2474 // Start over, except instead of ending the gesture with ScrollEnd, end it
2475 // with a FlingStart, with velocity in the reverse direction. This should
2476 // initiate an overscroll navigation, but it should be cancelled because of
2477 // the fling in the opposite direction.
2478 overscroll_delegate()->Reset();
2479 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2480 blink::WebGestureDeviceTouchscreen
);
2481 SimulateGestureScrollUpdateEvent(-300, -5, 0);
2482 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2483 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2484 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_mode());
2485 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_delegate()->current_mode());
2486 sink_
->ClearMessages();
2488 SimulateGestureFlingStartEvent(100, 0, blink::WebGestureDeviceTouchscreen
);
2489 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->completed_mode());
2490 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2491 EXPECT_EQ(1U, sink_
->message_count());
2495 // Tests that touch-scroll events are handled correctly by the overscroll
2496 // controller. This also tests that the overscroll controller and the
2497 // gesture-event filter play nice with each other.
2498 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, GestureScrollOverscrolls
) {
2499 SetUpOverscrollEnvironment();
2501 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2502 blink::WebGestureDeviceTouchscreen
);
2503 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2504 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2505 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2507 // Send another gesture event and ACK as not being processed. This should
2508 // initiate the navigation gesture.
2509 SimulateGestureScrollUpdateEvent(55, -5, 0);
2510 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2511 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2512 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2513 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2514 EXPECT_EQ(55.f
, overscroll_delta_x());
2515 EXPECT_EQ(-5.f
, overscroll_delta_y());
2516 EXPECT_EQ(5.f
, overscroll_delegate()->delta_x());
2517 EXPECT_EQ(-5.f
, overscroll_delegate()->delta_y());
2518 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2520 // Send another gesture update event. This event should be consumed by the
2521 // controller, and not be forwarded to the renderer. The gesture-event filter
2522 // should not also receive this event.
2523 SimulateGestureScrollUpdateEvent(10, -5, 0);
2524 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2525 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2526 EXPECT_EQ(65.f
, overscroll_delta_x());
2527 EXPECT_EQ(-10.f
, overscroll_delta_y());
2528 EXPECT_EQ(15.f
, overscroll_delegate()->delta_x());
2529 EXPECT_EQ(-10.f
, overscroll_delegate()->delta_y());
2530 EXPECT_EQ(0U, sink_
->message_count());
2532 // Now send a scroll end. This should cancel the overscroll gesture, and send
2533 // the event to the renderer. The gesture-event filter should receive this
2535 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
2536 blink::WebGestureDeviceTouchscreen
);
2537 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2538 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2539 EXPECT_EQ(1U, sink_
->message_count());
2542 // Tests that if the page is scrolled because of a scroll-gesture, then that
2543 // particular scroll sequence never generates overscroll if the scroll direction
2545 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
2546 GestureScrollConsumedHorizontal
) {
2547 SetUpOverscrollEnvironment();
2549 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2550 blink::WebGestureDeviceTouchscreen
);
2551 SimulateGestureScrollUpdateEvent(10, 0, 0);
2553 // Start scrolling on content. ACK both events as being processed.
2554 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2555 INPUT_EVENT_ACK_STATE_CONSUMED
);
2556 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2557 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2558 sink_
->ClearMessages();
2560 // Send another gesture event and ACK as not being processed. This should
2561 // not initiate overscroll because the beginning of the scroll event did
2562 // scroll some content on the page. Since there was no overscroll, the event
2563 // should reach the renderer.
2564 SimulateGestureScrollUpdateEvent(55, 0, 0);
2565 EXPECT_EQ(1U, sink_
->message_count());
2566 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2567 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2568 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2571 // Tests that the overscroll controller plays nice with touch-scrolls and the
2572 // gesture event filter with debounce filtering turned on.
2573 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
2574 GestureScrollDebounceOverscrolls
) {
2575 SetUpOverscrollEnvironmentWithDebounce(100);
2577 // Start scrolling. Receive ACK as it being processed.
2578 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2579 blink::WebGestureDeviceTouchscreen
);
2580 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2582 // Send update events.
2583 SimulateGestureScrollUpdateEvent(25, 0, 0);
2584 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2586 // Quickly end and restart the scroll gesture. These two events should get
2588 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
2589 blink::WebGestureDeviceTouchscreen
);
2590 EXPECT_EQ(0U, sink_
->message_count());
2592 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2593 blink::WebGestureDeviceTouchscreen
);
2594 EXPECT_EQ(0U, sink_
->message_count());
2596 // Send another update event. This should get into the queue.
2597 SimulateGestureScrollUpdateEvent(30, 0, 0);
2598 EXPECT_EQ(0U, sink_
->message_count());
2600 // Receive an ACK for the first scroll-update event as not being processed.
2601 // This will contribute to the overscroll gesture, but not enough for the
2602 // overscroll controller to start consuming gesture events. This also cause
2603 // the queued gesture event to be forwarded to the renderer.
2604 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2605 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2606 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2607 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2608 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2610 // Send another update event. This should get into the queue.
2611 SimulateGestureScrollUpdateEvent(10, 0, 0);
2612 EXPECT_EQ(0U, sink_
->message_count());
2614 // Receive an ACK for the second scroll-update event as not being processed.
2615 // This will now initiate an overscroll. This will also cause the queued
2616 // gesture event to be released. But instead of going to the renderer, it will
2617 // be consumed by the overscroll controller.
2618 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2619 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2620 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2621 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2622 EXPECT_EQ(65.f
, overscroll_delta_x());
2623 EXPECT_EQ(15.f
, overscroll_delegate()->delta_x());
2624 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2625 EXPECT_EQ(0U, sink_
->message_count());
2628 // Tests that the gesture debounce timer plays nice with the overscroll
2630 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
2631 GestureScrollDebounceTimerOverscroll
) {
2632 SetUpOverscrollEnvironmentWithDebounce(10);
2634 // Start scrolling. Receive ACK as it being processed.
2635 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2636 blink::WebGestureDeviceTouchscreen
);
2637 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2639 // Send update events.
2640 SimulateGestureScrollUpdateEvent(55, 0, 0);
2641 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2643 // Send an end event. This should get in the debounce queue.
2644 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
2645 blink::WebGestureDeviceTouchscreen
);
2646 EXPECT_EQ(0U, sink_
->message_count());
2648 // Receive ACK for the scroll-update event.
2649 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2650 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2651 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2652 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2653 EXPECT_EQ(55.f
, overscroll_delta_x());
2654 EXPECT_EQ(5.f
, overscroll_delegate()->delta_x());
2655 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2656 EXPECT_EQ(0U, sink_
->message_count());
2658 // Let the timer for the debounce queue fire. That should release the queued
2659 // scroll-end event. Since overscroll has started, but there hasn't been
2660 // enough overscroll to complete the gesture, the overscroll controller
2661 // will reset the state. The scroll-end should therefore be dispatched to the
2662 // renderer, and the gesture-event-filter should await an ACK for it.
2663 base::MessageLoop::current()->PostDelayedTask(
2665 base::MessageLoop::QuitClosure(),
2666 base::TimeDelta::FromMilliseconds(15));
2667 base::MessageLoop::current()->Run();
2669 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2670 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2671 EXPECT_EQ(1U, sink_
->message_count());
2674 // Tests that when touch-events are dispatched to the renderer, the overscroll
2675 // gesture deals with them correctly.
2676 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, OverscrollWithTouchEvents
) {
2677 SetUpOverscrollEnvironmentWithDebounce(10);
2678 widget_host_
->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
2679 sink_
->ClearMessages();
2681 // The test sends an intermingled sequence of touch and gesture events.
2682 PressTouchPoint(0, 1);
2683 SendInputEventACK(WebInputEvent::TouchStart
,
2684 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2685 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2687 MoveTouchPoint(0, 20, 5);
2688 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2689 SendInputEventACK(WebInputEvent::TouchMove
,
2690 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2692 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2693 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2695 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2696 blink::WebGestureDeviceTouchscreen
);
2697 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2698 SimulateGestureScrollUpdateEvent(20, 0, 0);
2699 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2700 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2701 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2702 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2703 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2705 // Another touch move event should reach the renderer since overscroll hasn't
2706 // started yet. Note that touch events sent during the scroll period may
2707 // not require an ack (having been marked uncancelable).
2708 MoveTouchPoint(0, 65, 10);
2709 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2710 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2712 SimulateGestureScrollUpdateEvent(45, 0, 0);
2713 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2714 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2715 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2716 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2717 EXPECT_EQ(65.f
, overscroll_delta_x());
2718 EXPECT_EQ(15.f
, overscroll_delegate()->delta_x());
2719 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2720 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2722 // Send another touch event. The page should get the touch-move event, even
2723 // though overscroll has started.
2724 MoveTouchPoint(0, 55, 5);
2725 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2726 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2727 EXPECT_EQ(65.f
, overscroll_delta_x());
2728 EXPECT_EQ(15.f
, overscroll_delegate()->delta_x());
2729 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2730 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2731 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2733 SimulateGestureScrollUpdateEvent(-10, 0, 0);
2734 EXPECT_EQ(0U, sink_
->message_count());
2735 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2736 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2737 EXPECT_EQ(55.f
, overscroll_delta_x());
2738 EXPECT_EQ(5.f
, overscroll_delegate()->delta_x());
2739 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2741 PressTouchPoint(255, 5);
2742 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2743 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2745 SimulateGestureScrollUpdateEvent(200, 0, 0);
2746 EXPECT_EQ(0U, sink_
->message_count());
2747 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2748 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2749 EXPECT_EQ(255.f
, overscroll_delta_x());
2750 EXPECT_EQ(205.f
, overscroll_delegate()->delta_x());
2751 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2753 // The touch-end/cancel event should always reach the renderer if the page has
2755 ReleaseTouchPoint(1);
2756 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2757 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2758 ReleaseTouchPoint(0);
2759 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2760 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2762 SimulateGestureEvent(blink::WebInputEvent::GestureScrollEnd
,
2763 blink::WebGestureDeviceTouchscreen
);
2764 base::MessageLoop::current()->PostDelayedTask(
2766 base::MessageLoop::QuitClosure(),
2767 base::TimeDelta::FromMilliseconds(10));
2768 base::MessageLoop::current()->Run();
2769 EXPECT_EQ(1U, sink_
->message_count());
2770 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2771 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2772 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->completed_mode());
2775 // Tests that touch-gesture end is dispatched to the renderer at the end of a
2776 // touch-gesture initiated overscroll.
2777 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
2778 TouchGestureEndDispatchedAfterOverscrollComplete
) {
2779 SetUpOverscrollEnvironmentWithDebounce(10);
2780 widget_host_
->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
2781 sink_
->ClearMessages();
2783 // Start scrolling. Receive ACK as it being processed.
2784 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2785 blink::WebGestureDeviceTouchscreen
);
2786 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2787 // The scroll begin event will have received a synthetic ack from the input
2789 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2790 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2792 // Send update events.
2793 SimulateGestureScrollUpdateEvent(55, -5, 0);
2794 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2795 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2796 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2798 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2799 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2800 EXPECT_EQ(0U, sink_
->message_count());
2801 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2802 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2803 EXPECT_EQ(55.f
, overscroll_delta_x());
2804 EXPECT_EQ(5.f
, overscroll_delegate()->delta_x());
2805 EXPECT_EQ(-5.f
, overscroll_delegate()->delta_y());
2808 SimulateGestureEvent(blink::WebInputEvent::GestureScrollEnd
,
2809 blink::WebGestureDeviceTouchscreen
);
2810 EXPECT_EQ(0U, sink_
->message_count());
2811 base::MessageLoop::current()->PostDelayedTask(
2813 base::MessageLoop::QuitClosure(),
2814 base::TimeDelta::FromMilliseconds(10));
2815 base::MessageLoop::current()->Run();
2816 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2817 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2818 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->completed_mode());
2819 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2821 // Start scrolling. Receive ACK as it being processed.
2822 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2823 blink::WebGestureDeviceTouchscreen
);
2824 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2825 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2826 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2828 // Send update events.
2829 SimulateGestureScrollUpdateEvent(235, -5, 0);
2830 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2831 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2832 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2834 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2835 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2836 EXPECT_EQ(0U, sink_
->message_count());
2837 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2838 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2839 EXPECT_EQ(235.f
, overscroll_delta_x());
2840 EXPECT_EQ(185.f
, overscroll_delegate()->delta_x());
2841 EXPECT_EQ(-5.f
, overscroll_delegate()->delta_y());
2844 SimulateGestureEvent(blink::WebInputEvent::GestureScrollEnd
,
2845 blink::WebGestureDeviceTouchscreen
);
2846 EXPECT_EQ(0U, sink_
->message_count());
2847 base::MessageLoop::current()->PostDelayedTask(
2849 base::MessageLoop::QuitClosure(),
2850 base::TimeDelta::FromMilliseconds(10));
2851 base::MessageLoop::current()->Run();
2852 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2853 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2854 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->completed_mode());
2855 EXPECT_EQ(1U, sink_
->message_count());
2858 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, OverscrollDirectionChange
) {
2859 SetUpOverscrollEnvironmentWithDebounce(100);
2861 // Start scrolling. Receive ACK as it being processed.
2862 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2863 blink::WebGestureDeviceTouchscreen
);
2864 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2866 // Send update events and receive ack as not consumed.
2867 SimulateGestureScrollUpdateEvent(125, -5, 0);
2868 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2870 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2871 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2872 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2873 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2874 EXPECT_EQ(0U, sink_
->message_count());
2876 // Send another update event, but in the reverse direction. The overscroll
2877 // controller will not consume the event, because it is not triggering
2879 SimulateGestureScrollUpdateEvent(-260, 0, 0);
2880 EXPECT_EQ(1U, sink_
->message_count());
2881 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2883 // Since the overscroll mode has been reset, the next scroll update events
2884 // should reach the renderer.
2885 SimulateGestureScrollUpdateEvent(-20, 0, 0);
2886 EXPECT_EQ(1U, sink_
->message_count());
2887 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2890 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
2891 OverscrollDirectionChangeMouseWheel
) {
2892 SetUpOverscrollEnvironment();
2894 // Send wheel event and receive ack as not consumed.
2895 SimulateWheelEvent(125, -5, 0, true);
2896 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2897 SendInputEventACK(WebInputEvent::MouseWheel
,
2898 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2899 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2900 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2901 EXPECT_EQ(0U, sink_
->message_count());
2903 // Send another wheel event, but in the reverse direction. The overscroll
2904 // controller will not consume the event, because it is not triggering
2906 SimulateWheelEvent(-260, 0, 0, true);
2907 EXPECT_EQ(1U, sink_
->message_count());
2908 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2910 // Since the overscroll mode has been reset, the next wheel event should reach
2912 SimulateWheelEvent(-20, 0, 0, true);
2913 EXPECT_EQ(1U, sink_
->message_count());
2914 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2917 // Tests that if a mouse-move event completes the overscroll gesture, future
2918 // move events do reach the renderer.
2919 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, OverscrollMouseMoveCompletion
) {
2920 SetUpOverscrollEnvironment();
2922 SimulateWheelEvent(5, 0, 0, true); // sent directly
2923 SimulateWheelEvent(-1, 0, 0, true); // enqueued
2924 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
2925 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
2926 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
2927 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2928 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2930 // Receive ACK the first wheel event as not processed.
2931 SendInputEventACK(WebInputEvent::MouseWheel
,
2932 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2933 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2934 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2935 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2937 // Receive ACK for the second (coalesced) event as not processed. This will
2938 // start an overcroll gesture.
2939 SendInputEventACK(WebInputEvent::MouseWheel
,
2940 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2941 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_mode());
2942 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_delegate()->current_mode());
2943 EXPECT_EQ(0U, sink_
->message_count());
2945 // Send a mouse-move event. This should cancel the overscroll navigation
2946 // (since the amount overscrolled is not above the threshold), and so the
2947 // mouse-move should reach the renderer.
2948 SimulateMouseMove(5, 10, 0);
2949 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2950 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->completed_mode());
2951 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2952 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2954 SendInputEventACK(WebInputEvent::MouseMove
,
2955 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2957 // Moving the mouse more should continue to send the events to the renderer.
2958 SimulateMouseMove(5, 10, 0);
2959 SendInputEventACK(WebInputEvent::MouseMove
,
2960 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2961 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2963 // Now try with gestures.
2964 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2965 blink::WebGestureDeviceTouchscreen
);
2966 SimulateGestureScrollUpdateEvent(300, -5, 0);
2967 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2968 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2969 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2970 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2971 sink_
->ClearMessages();
2973 // Overscroll gesture is in progress. Send a mouse-move now. This should
2974 // complete the gesture (because the amount overscrolled is above the
2976 SimulateMouseMove(5, 10, 0);
2977 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->completed_mode());
2978 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2979 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2980 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2981 SendInputEventACK(WebInputEvent::MouseMove
,
2982 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2984 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
2985 blink::WebGestureDeviceTouchscreen
);
2986 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2987 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2989 // Move mouse some more. The mouse-move events should reach the renderer.
2990 SimulateMouseMove(5, 10, 0);
2991 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2993 SendInputEventACK(WebInputEvent::MouseMove
,
2994 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2997 // Tests that if a page scrolled, then the overscroll controller's states are
2998 // reset after the end of the scroll.
2999 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
3000 OverscrollStateResetsAfterScroll
) {
3001 SetUpOverscrollEnvironment();
3003 SimulateWheelEvent(0, 5, 0, true); // sent directly
3004 SimulateWheelEvent(0, 30, 0, true); // enqueued
3005 SimulateWheelEvent(0, 40, 0, true); // coalesced into previous event
3006 SimulateWheelEvent(0, 10, 0, true); // coalesced into previous event
3007 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3008 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3010 // The first wheel event is consumed. Dispatches the queued wheel event.
3011 SendInputEventACK(WebInputEvent::MouseWheel
, INPUT_EVENT_ACK_STATE_CONSUMED
);
3012 EXPECT_TRUE(ScrollStateIsContentScrolling());
3013 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3015 // The second wheel event is consumed.
3016 SendInputEventACK(WebInputEvent::MouseWheel
, INPUT_EVENT_ACK_STATE_CONSUMED
);
3017 EXPECT_TRUE(ScrollStateIsContentScrolling());
3019 // Touchpad scroll can end with a zero-velocity fling. But it is not
3020 // dispatched, but it should still reset the overscroll controller state.
3021 SimulateGestureFlingStartEvent(0.f
, 0.f
, blink::WebGestureDeviceTouchpad
);
3022 EXPECT_TRUE(ScrollStateIsUnknown());
3023 EXPECT_EQ(0U, sink_
->message_count());
3025 SimulateWheelEvent(-5, 0, 0, true); // sent directly
3026 SimulateWheelEvent(-60, 0, 0, true); // enqueued
3027 SimulateWheelEvent(-100, 0, 0, true); // coalesced into previous event
3028 EXPECT_TRUE(ScrollStateIsUnknown());
3029 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3031 // The first wheel scroll did not scroll content. Overscroll should not start
3032 // yet, since enough hasn't been scrolled.
3033 SendInputEventACK(WebInputEvent::MouseWheel
,
3034 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3035 EXPECT_TRUE(ScrollStateIsUnknown());
3036 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3038 SendInputEventACK(WebInputEvent::MouseWheel
,
3039 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3040 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_mode());
3041 EXPECT_TRUE(ScrollStateIsOverscrolling());
3042 EXPECT_EQ(0U, sink_
->message_count());
3044 SimulateGestureFlingStartEvent(0.f
, 0.f
, blink::WebGestureDeviceTouchpad
);
3045 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3046 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_delegate()->completed_mode());
3047 EXPECT_TRUE(ScrollStateIsUnknown());
3048 EXPECT_EQ(0U, sink_
->message_count());
3051 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, OverscrollResetsOnBlur
) {
3052 SetUpOverscrollEnvironment();
3054 // Start an overscroll with gesture scroll. In the middle of the scroll, blur
3056 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
3057 blink::WebGestureDeviceTouchscreen
);
3058 SimulateGestureScrollUpdateEvent(300, -5, 0);
3059 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
3060 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3061 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
3062 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
3063 EXPECT_EQ(2U, GetSentMessageCountAndResetSink());
3065 view_
->OnWindowFocused(NULL
, view_
->GetAttachedWindow());
3066 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3067 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3068 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->completed_mode());
3069 EXPECT_EQ(0.f
, overscroll_delegate()->delta_x());
3070 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
3071 sink_
->ClearMessages();
3073 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
3074 blink::WebGestureDeviceTouchscreen
);
3075 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3077 // Start a scroll gesture again. This should correctly start the overscroll
3078 // after the threshold.
3079 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
3080 blink::WebGestureDeviceTouchscreen
);
3081 SimulateGestureScrollUpdateEvent(300, -5, 0);
3082 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
3083 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3084 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
3085 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
3086 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->completed_mode());
3088 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
3089 blink::WebGestureDeviceTouchscreen
);
3090 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3091 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->completed_mode());
3092 EXPECT_EQ(3U, sink_
->message_count());
3095 // Tests that when view initiated shutdown happens (i.e. RWHView is deleted
3096 // before RWH), we clean up properly and don't leak the RWHVGuest.
3097 TEST_F(RenderWidgetHostViewGuestAuraTest
, GuestViewDoesNotLeak
) {
3098 TearDownEnvironment();
3099 ASSERT_FALSE(guest_view_weak_
.get());
3102 // Tests that invalid touch events are consumed and handled
3104 TEST_F(RenderWidgetHostViewAuraTest
,
3105 InvalidEventsHaveSyncHandlingDisabled
) {
3106 view_
->InitAsChild(NULL
);
3108 GetSentMessageCountAndResetSink();
3110 widget_host_
->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
3112 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(30, 30), 0,
3113 ui::EventTimeForNow());
3115 // Construct a move with a touch id which doesn't exist.
3116 ui::TouchEvent
invalid_move(ui::ET_TOUCH_MOVED
, gfx::Point(30, 30), 1,
3117 ui::EventTimeForNow());
3119 // Valid press is handled asynchronously.
3120 view_
->OnTouchEvent(&press
);
3121 EXPECT_TRUE(press
.synchronous_handling_disabled());
3122 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3123 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_CONSUMED
);
3125 // Invalid move is handled synchronously, but is consumed. It should not
3126 // be forwarded to the renderer.
3127 view_
->OnTouchEvent(&invalid_move
);
3128 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
3129 EXPECT_FALSE(invalid_move
.synchronous_handling_disabled());
3130 EXPECT_TRUE(invalid_move
.stopped_propagation());
3133 // Checks key event codes.
3134 TEST_F(RenderWidgetHostViewAuraTest
, KeyEvent
) {
3135 view_
->InitAsChild(NULL
);
3138 ui::KeyEvent
key_event(ui::ET_KEY_PRESSED
, ui::VKEY_A
, ui::DomCode::KEY_A
,
3140 view_
->OnKeyEvent(&key_event
);
3142 const NativeWebKeyboardEvent
* event
= delegate_
.last_event();
3143 EXPECT_NE(nullptr, event
);
3145 EXPECT_EQ(key_event
.key_code(), event
->windowsKeyCode
);
3146 EXPECT_EQ(ui::KeycodeConverter::DomCodeToNativeKeycode(key_event
.code()),
3147 event
->nativeKeyCode
);
3151 TEST_F(RenderWidgetHostViewAuraTest
, SetCanScrollForWebMouseWheelEvent
) {
3152 view_
->InitAsChild(NULL
);
3155 sink_
->ClearMessages();
3157 // Simulates the mouse wheel event with ctrl modifier applied.
3158 ui::MouseWheelEvent
event(gfx::Vector2d(1, 1), gfx::Point(), gfx::Point(),
3159 ui::EventTimeForNow(), ui::EF_CONTROL_DOWN
, 0);
3160 view_
->OnMouseEvent(&event
);
3162 const WebInputEvent
* input_event
=
3163 GetInputEventFromMessage(*sink_
->GetMessageAt(0));
3164 const WebMouseWheelEvent
* wheel_event
=
3165 static_cast<const WebMouseWheelEvent
*>(input_event
);
3166 // Check if the canScroll set to false when ctrl-scroll is generated from
3167 // mouse wheel event.
3168 EXPECT_FALSE(wheel_event
->canScroll
);
3169 sink_
->ClearMessages();
3171 // Ack'ing the outstanding event should flush the pending event queue.
3172 SendInputEventACK(blink::WebInputEvent::MouseWheel
,
3173 INPUT_EVENT_ACK_STATE_CONSUMED
);
3175 // Simulates the mouse wheel event with no modifier applied.
3176 event
= ui::MouseWheelEvent(gfx::Vector2d(1, 1), gfx::Point(), gfx::Point(),
3177 ui::EventTimeForNow(), ui::EF_NONE
, 0);
3179 view_
->OnMouseEvent(&event
);
3181 input_event
= GetInputEventFromMessage(*sink_
->GetMessageAt(0));
3182 wheel_event
= static_cast<const WebMouseWheelEvent
*>(input_event
);
3183 // Check if the canScroll set to true when no modifier is applied to the
3184 // mouse wheel event.
3185 EXPECT_TRUE(wheel_event
->canScroll
);
3186 sink_
->ClearMessages();
3188 SendInputEventACK(blink::WebInputEvent::MouseWheel
,
3189 INPUT_EVENT_ACK_STATE_CONSUMED
);
3191 // Simulates the scroll event with ctrl modifier applied.
3192 ui::ScrollEvent
scroll(ui::ET_SCROLL
, gfx::Point(2, 2), ui::EventTimeForNow(),
3193 ui::EF_CONTROL_DOWN
, 0, 5, 0, 5, 2);
3194 view_
->OnScrollEvent(&scroll
);
3196 input_event
= GetInputEventFromMessage(*sink_
->GetMessageAt(0));
3197 wheel_event
= static_cast<const WebMouseWheelEvent
*>(input_event
);
3198 // Check if the canScroll set to true when ctrl-touchpad-scroll is generated
3199 // from scroll event.
3200 EXPECT_TRUE(wheel_event
->canScroll
);
3203 // Ensures that the mapping from ui::TouchEvent to blink::WebTouchEvent doesn't
3204 // lose track of the number of acks required.
3205 TEST_F(RenderWidgetHostViewAuraTest
, CorrectNumberOfAcksAreDispatched
) {
3206 view_
->InitAsFullscreen(parent_view_
);
3208 view_
->UseFakeDispatcher();
3210 ui::TouchEvent
press1(
3211 ui::ET_TOUCH_PRESSED
, gfx::Point(30, 30), 0, ui::EventTimeForNow());
3213 view_
->OnTouchEvent(&press1
);
3214 SendInputEventACK(blink::WebInputEvent::TouchStart
,
3215 INPUT_EVENT_ACK_STATE_CONSUMED
);
3217 ui::TouchEvent
press2(
3218 ui::ET_TOUCH_PRESSED
, gfx::Point(20, 20), 1, ui::EventTimeForNow());
3219 view_
->OnTouchEvent(&press2
);
3220 SendInputEventACK(blink::WebInputEvent::TouchStart
,
3221 INPUT_EVENT_ACK_STATE_CONSUMED
);
3223 EXPECT_EQ(2U, view_
->dispatcher_
->processed_touch_event_count());
3226 } // namespace content