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/scoped_vector.h"
10 #include "base/memory/shared_memory.h"
11 #include "base/message_loop/message_loop.h"
12 #include "base/run_loop.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "base/test/simple_test_tick_clock.h"
15 #include "cc/output/begin_frame_args.h"
16 #include "cc/output/compositor_frame.h"
17 #include "cc/output/compositor_frame_metadata.h"
18 #include "cc/output/copy_output_request.h"
19 #include "cc/surfaces/surface.h"
20 #include "cc/surfaces/surface_manager.h"
21 #include "content/browser/browser_thread_impl.h"
22 #include "content/browser/compositor/resize_lock.h"
23 #include "content/browser/compositor/test/no_transport_image_transport_factory.h"
24 #include "content/browser/frame_host/render_widget_host_view_guest.h"
25 #include "content/browser/renderer_host/input/input_router.h"
26 #include "content/browser/renderer_host/input/web_input_event_util.h"
27 #include "content/browser/renderer_host/overscroll_controller.h"
28 #include "content/browser/renderer_host/overscroll_controller_delegate.h"
29 #include "content/browser/renderer_host/render_widget_host_delegate.h"
30 #include "content/browser/renderer_host/render_widget_host_impl.h"
31 #include "content/common/gpu/client/gl_helper.h"
32 #include "content/common/gpu/gpu_messages.h"
33 #include "content/common/host_shared_bitmap_manager.h"
34 #include "content/common/input/synthetic_web_input_event_builders.h"
35 #include "content/common/input_messages.h"
36 #include "content/common/view_messages.h"
37 #include "content/public/browser/render_widget_host_view.h"
38 #include "content/public/browser/render_widget_host_view_frame_subscriber.h"
39 #include "content/public/test/mock_render_process_host.h"
40 #include "content/public/test/test_browser_context.h"
41 #include "ipc/ipc_test_sink.h"
42 #include "testing/gmock/include/gmock/gmock.h"
43 #include "testing/gtest/include/gtest/gtest.h"
44 #include "ui/aura/client/aura_constants.h"
45 #include "ui/aura/client/screen_position_client.h"
46 #include "ui/aura/client/window_tree_client.h"
47 #include "ui/aura/env.h"
48 #include "ui/aura/layout_manager.h"
49 #include "ui/aura/test/aura_test_helper.h"
50 #include "ui/aura/test/aura_test_utils.h"
51 #include "ui/aura/test/test_cursor_client.h"
52 #include "ui/aura/test/test_screen.h"
53 #include "ui/aura/test/test_window_delegate.h"
54 #include "ui/aura/window.h"
55 #include "ui/aura/window_event_dispatcher.h"
56 #include "ui/aura/window_observer.h"
57 #include "ui/base/ui_base_types.h"
58 #include "ui/compositor/compositor.h"
59 #include "ui/compositor/layer_tree_owner.h"
60 #include "ui/compositor/test/draw_waiter_for_test.h"
61 #include "ui/events/blink/blink_event_util.h"
62 #include "ui/events/event.h"
63 #include "ui/events/event_utils.h"
64 #include "ui/events/gesture_detection/gesture_configuration.h"
65 #include "ui/events/keycodes/dom/dom_code.h"
66 #include "ui/events/keycodes/dom/keycode_converter.h"
67 #include "ui/events/test/event_generator.h"
68 #include "ui/wm/core/default_activation_client.h"
69 #include "ui/wm/core/default_screen_position_client.h"
70 #include "ui/wm/core/window_util.h"
74 using blink::WebGestureEvent
;
75 using blink::WebInputEvent
;
76 using blink::WebMouseEvent
;
77 using blink::WebMouseWheelEvent
;
78 using blink::WebTouchEvent
;
79 using blink::WebTouchPoint
;
84 class TestOverscrollDelegate
: public OverscrollControllerDelegate
{
86 explicit TestOverscrollDelegate(RenderWidgetHostView
* view
)
88 current_mode_(OVERSCROLL_NONE
),
89 completed_mode_(OVERSCROLL_NONE
),
93 ~TestOverscrollDelegate() override
{}
95 OverscrollMode
current_mode() const { return current_mode_
; }
96 OverscrollMode
completed_mode() const { return completed_mode_
; }
97 float delta_x() const { return delta_x_
; }
98 float delta_y() const { return delta_y_
; }
101 current_mode_
= OVERSCROLL_NONE
;
102 completed_mode_
= OVERSCROLL_NONE
;
103 delta_x_
= delta_y_
= 0.f
;
107 // Overridden from OverscrollControllerDelegate:
108 gfx::Rect
GetVisibleBounds() const override
{
109 return view_
->IsShowing() ? view_
->GetViewBounds() : gfx::Rect();
112 bool OnOverscrollUpdate(float delta_x
, float delta_y
) override
{
118 void OnOverscrollComplete(OverscrollMode overscroll_mode
) override
{
119 EXPECT_EQ(current_mode_
, overscroll_mode
);
120 completed_mode_
= overscroll_mode
;
121 current_mode_
= OVERSCROLL_NONE
;
124 void OnOverscrollModeChange(OverscrollMode old_mode
,
125 OverscrollMode new_mode
) override
{
126 EXPECT_EQ(current_mode_
, old_mode
);
127 current_mode_
= new_mode
;
128 delta_x_
= delta_y_
= 0.f
;
131 RenderWidgetHostView
* view_
;
132 OverscrollMode current_mode_
;
133 OverscrollMode completed_mode_
;
137 DISALLOW_COPY_AND_ASSIGN(TestOverscrollDelegate
);
140 class MockRenderWidgetHostDelegate
: public RenderWidgetHostDelegate
{
142 MockRenderWidgetHostDelegate() {}
143 ~MockRenderWidgetHostDelegate() override
{}
144 const NativeWebKeyboardEvent
* last_event() const { return last_event_
.get(); }
146 // RenderWidgetHostDelegate:
147 bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent
& event
,
148 bool* is_keyboard_shortcut
) override
{
149 last_event_
.reset(new NativeWebKeyboardEvent(event
));
152 void Cut() override
{}
153 void Copy() override
{}
154 void Paste() override
{}
155 void SelectAll() override
{}
158 scoped_ptr
<NativeWebKeyboardEvent
> last_event_
;
159 DISALLOW_COPY_AND_ASSIGN(MockRenderWidgetHostDelegate
);
162 // Simple observer that keeps track of changes to a window for tests.
163 class TestWindowObserver
: public aura::WindowObserver
{
165 explicit TestWindowObserver(aura::Window
* window_to_observe
)
166 : window_(window_to_observe
) {
167 window_
->AddObserver(this);
169 ~TestWindowObserver() override
{
171 window_
->RemoveObserver(this);
174 bool destroyed() const { return destroyed_
; }
176 // aura::WindowObserver overrides:
177 void OnWindowDestroyed(aura::Window
* window
) override
{
178 CHECK_EQ(window
, window_
);
184 // Window that we're observing, or NULL if it's been destroyed.
185 aura::Window
* window_
;
187 // Was |window_| destroyed?
190 DISALLOW_COPY_AND_ASSIGN(TestWindowObserver
);
193 class FakeFrameSubscriber
: public RenderWidgetHostViewFrameSubscriber
{
195 FakeFrameSubscriber(gfx::Size size
, base::Callback
<void(bool)> callback
)
196 : size_(size
), callback_(callback
) {}
198 bool ShouldCaptureFrame(const gfx::Rect
& damage_rect
,
199 base::TimeTicks present_time
,
200 scoped_refptr
<media::VideoFrame
>* storage
,
201 DeliverFrameCallback
* callback
) override
{
202 last_present_time_
= present_time
;
203 *storage
= media::VideoFrame::CreateFrame(media::PIXEL_FORMAT_YV12
, size_
,
204 gfx::Rect(size_
), size_
,
206 *callback
= base::Bind(&FakeFrameSubscriber::CallbackMethod
, callback_
);
210 base::TimeTicks
last_present_time() const { return last_present_time_
; }
212 static void CallbackMethod(base::Callback
<void(bool)> callback
,
213 base::TimeTicks present_time
,
215 callback
.Run(success
);
220 base::Callback
<void(bool)> callback_
;
221 base::TimeTicks last_present_time_
;
224 class FakeWindowEventDispatcher
: public aura::WindowEventDispatcher
{
226 FakeWindowEventDispatcher(aura::WindowTreeHost
* host
)
227 : WindowEventDispatcher(host
),
228 processed_touch_event_count_(0) {}
230 void ProcessedTouchEvent(uint32 unique_event_id
,
231 aura::Window
* window
,
232 ui::EventResult result
) override
{
233 WindowEventDispatcher::ProcessedTouchEvent(unique_event_id
, window
, result
);
234 processed_touch_event_count_
++;
237 size_t GetAndResetProcessedTouchEventCount() {
238 size_t count
= processed_touch_event_count_
;
239 processed_touch_event_count_
= 0;
244 size_t processed_touch_event_count_
;
247 class FakeRenderWidgetHostViewAura
: public RenderWidgetHostViewAura
{
249 FakeRenderWidgetHostViewAura(RenderWidgetHost
* widget
,
250 bool is_guest_view_hack
)
251 : RenderWidgetHostViewAura(widget
, is_guest_view_hack
),
252 has_resize_lock_(false) {}
254 void UseFakeDispatcher() {
255 dispatcher_
= new FakeWindowEventDispatcher(window()->GetHost());
256 scoped_ptr
<aura::WindowEventDispatcher
> dispatcher(dispatcher_
);
257 aura::test::SetHostDispatcher(window()->GetHost(), dispatcher
.Pass());
260 ~FakeRenderWidgetHostViewAura() override
{}
262 scoped_ptr
<ResizeLock
> DelegatedFrameHostCreateResizeLock(
263 bool defer_compositor_lock
) override
{
264 gfx::Size desired_size
= window()->bounds().size();
265 return scoped_ptr
<ResizeLock
>(
266 new FakeResizeLock(desired_size
, defer_compositor_lock
));
269 bool DelegatedFrameCanCreateResizeLock() const override
{ return true; }
271 void RunOnCompositingDidCommit() {
272 GetDelegatedFrameHost()->OnCompositingDidCommitForTesting(
273 window()->GetHost()->compositor());
276 void InterceptCopyOfOutput(scoped_ptr
<cc::CopyOutputRequest
> request
) {
277 last_copy_request_
= request
.Pass();
278 if (last_copy_request_
->has_texture_mailbox()) {
279 // Give the resulting texture a size.
280 GLHelper
* gl_helper
= ImageTransportFactory::GetInstance()->GetGLHelper();
281 GLuint texture
= gl_helper
->ConsumeMailboxToTexture(
282 last_copy_request_
->texture_mailbox().mailbox(),
283 last_copy_request_
->texture_mailbox().sync_point());
284 gl_helper
->ResizeTexture(texture
, window()->bounds().size());
285 gl_helper
->DeleteTexture(texture
);
289 cc::DelegatedFrameProvider
* frame_provider() const {
290 return GetDelegatedFrameHost()->FrameProviderForTesting();
293 cc::SurfaceId
surface_id() const {
294 return GetDelegatedFrameHost()->SurfaceIdForTesting();
297 bool HasFrameData() const {
298 return frame_provider() || !surface_id().is_null();
301 bool released_front_lock_active() const {
302 return GetDelegatedFrameHost()->ReleasedFrontLockActiveForTesting();
305 // A lock that doesn't actually do anything to the compositor, and does not
307 class FakeResizeLock
: public ResizeLock
{
309 FakeResizeLock(const gfx::Size new_size
, bool defer_compositor_lock
)
310 : ResizeLock(new_size
, defer_compositor_lock
) {}
313 const ui::MotionEventAura
& pointer_state_for_test() {
314 return pointer_state();
317 bool has_resize_lock_
;
318 gfx::Size last_frame_size_
;
319 scoped_ptr
<cc::CopyOutputRequest
> last_copy_request_
;
320 FakeWindowEventDispatcher
* dispatcher_
;
323 // A layout manager that always resizes a child to the root window size.
324 class FullscreenLayoutManager
: public aura::LayoutManager
{
326 explicit FullscreenLayoutManager(aura::Window
* owner
) : owner_(owner
) {}
327 ~FullscreenLayoutManager() override
{}
329 // Overridden from aura::LayoutManager:
330 void OnWindowResized() override
{
331 aura::Window::Windows::const_iterator i
;
332 for (i
= owner_
->children().begin(); i
!= owner_
->children().end(); ++i
) {
333 (*i
)->SetBounds(gfx::Rect());
336 void OnWindowAddedToLayout(aura::Window
* child
) override
{
337 child
->SetBounds(gfx::Rect());
339 void OnWillRemoveWindowFromLayout(aura::Window
* child
) override
{}
340 void OnWindowRemovedFromLayout(aura::Window
* child
) override
{}
341 void OnChildWindowVisibilityChanged(aura::Window
* child
,
342 bool visible
) override
{}
343 void SetChildBounds(aura::Window
* child
,
344 const gfx::Rect
& requested_bounds
) override
{
345 SetChildBoundsDirect(child
, gfx::Rect(owner_
->bounds().size()));
349 aura::Window
* owner_
;
350 DISALLOW_COPY_AND_ASSIGN(FullscreenLayoutManager
);
353 class MockWindowObserver
: public aura::WindowObserver
{
355 MOCK_METHOD2(OnDelegatedFrameDamage
, void(aura::Window
*, const gfx::Rect
&));
358 const WebInputEvent
* GetInputEventFromMessage(const IPC::Message
& message
) {
359 base::PickleIterator
iter(message
);
362 if (!iter
.ReadData(&data
, &data_length
))
364 return reinterpret_cast<const WebInputEvent
*>(data
);
369 class RenderWidgetHostViewAuraTest
: public testing::Test
{
371 RenderWidgetHostViewAuraTest()
372 : widget_host_uses_shutdown_to_destroy_(false),
373 is_guest_view_hack_(false),
374 browser_thread_for_ui_(BrowserThread::UI
, &message_loop_
) {}
376 void SetUpEnvironment() {
377 ImageTransportFactory::InitializeForUnitTests(
378 scoped_ptr
<ImageTransportFactory
>(
379 new NoTransportImageTransportFactory
));
380 aura_test_helper_
.reset(new aura::test::AuraTestHelper(&message_loop_
));
381 aura_test_helper_
->SetUp(
382 ImageTransportFactory::GetInstance()->GetContextFactory());
383 new wm::DefaultActivationClient(aura_test_helper_
->root_window());
385 browser_context_
.reset(new TestBrowserContext
);
386 process_host_
= new MockRenderProcessHost(browser_context_
.get());
387 process_host_
->Init();
389 sink_
= &process_host_
->sink();
391 parent_host_
= new RenderWidgetHostImpl(
392 &delegate_
, process_host_
, MSG_ROUTING_NONE
, false);
393 parent_view_
= new RenderWidgetHostViewAura(parent_host_
,
394 is_guest_view_hack_
);
395 parent_view_
->InitAsChild(NULL
);
396 aura::client::ParentWindowWithContext(parent_view_
->GetNativeView(),
397 aura_test_helper_
->root_window(),
400 widget_host_
= new RenderWidgetHostImpl(
401 &delegate_
, process_host_
, MSG_ROUTING_NONE
, false);
402 widget_host_
->Init();
403 view_
= new FakeRenderWidgetHostViewAura(widget_host_
, is_guest_view_hack_
);
406 void TearDownEnvironment() {
408 process_host_
= NULL
;
412 if (widget_host_uses_shutdown_to_destroy_
)
413 widget_host_
->Shutdown();
417 parent_view_
->Destroy();
420 browser_context_
.reset();
421 aura_test_helper_
->TearDown();
423 message_loop_
.DeleteSoon(FROM_HERE
, browser_context_
.release());
424 message_loop_
.RunUntilIdle();
425 ImageTransportFactory::Terminate();
428 void SetUp() override
{ SetUpEnvironment(); }
430 void TearDown() override
{ TearDownEnvironment(); }
432 void set_widget_host_uses_shutdown_to_destroy(bool use
) {
433 widget_host_uses_shutdown_to_destroy_
= use
;
436 void SimulateMemoryPressure(
437 base::MemoryPressureListener::MemoryPressureLevel level
) {
438 // Here should be base::MemoryPressureListener::NotifyMemoryPressure, but
439 // since the RendererFrameManager is installing a MemoryPressureListener
440 // which uses base::ObserverListThreadSafe, which furthermore remembers the
441 // message loop for the thread it was created in. Between tests, the
442 // RendererFrameManager singleton survives and and the MessageLoop gets
443 // destroyed. The correct fix would be to have base::ObserverListThreadSafe
445 // up the proper message loop every time (see crbug.com/443824.)
446 RendererFrameManager::GetInstance()->OnMemoryPressure(level
);
449 void SendInputEventACK(WebInputEvent::Type type
,
450 InputEventAckState ack_result
) {
451 DCHECK(!WebInputEvent::isTouchEventType(type
));
452 InputEventAck
ack(type
, ack_result
);
453 InputHostMsg_HandleInputEvent_ACK
response(0, ack
);
454 widget_host_
->OnMessageReceived(response
);
457 void SendTouchEventACK(WebInputEvent::Type type
,
458 InputEventAckState ack_result
,
460 DCHECK(WebInputEvent::isTouchEventType(type
));
461 InputEventAck
ack(type
, ack_result
, event_id
);
462 InputHostMsg_HandleInputEvent_ACK
response(0, ack
);
463 widget_host_
->OnMessageReceived(response
);
466 size_t GetSentMessageCountAndResetSink() {
467 size_t count
= sink_
->message_count();
468 sink_
->ClearMessages();
472 void AckLastSentInputEventIfNecessary(InputEventAckState ack_result
) {
473 if (!sink_
->message_count())
476 InputMsg_HandleInputEvent::Param params
;
477 if (!InputMsg_HandleInputEvent::Read(
478 sink_
->GetMessageAt(sink_
->message_count() - 1), ¶ms
)) {
482 if (!WebInputEventTraits::WillReceiveAckFromRenderer(
483 *base::get
<0>(params
)))
486 const blink::WebInputEvent
* event
= base::get
<0>(params
);
487 SendTouchEventACK(event
->type
, ack_result
,
488 WebInputEventTraits::GetUniqueTouchEventId(*event
));
491 const ui::MotionEventAura
& pointer_state() {
492 return view_
->pointer_state_for_test();
496 // If true, then calls RWH::Shutdown() instead of deleting RWH.
497 bool widget_host_uses_shutdown_to_destroy_
;
499 bool is_guest_view_hack_
;
501 base::MessageLoopForUI message_loop_
;
502 BrowserThreadImpl browser_thread_for_ui_
;
503 scoped_ptr
<aura::test::AuraTestHelper
> aura_test_helper_
;
504 scoped_ptr
<BrowserContext
> browser_context_
;
505 MockRenderWidgetHostDelegate delegate_
;
506 MockRenderProcessHost
* process_host_
;
508 // Tests should set these to NULL if they've already triggered their
510 RenderWidgetHostImpl
* parent_host_
;
511 RenderWidgetHostViewAura
* parent_view_
;
513 // Tests should set these to NULL if they've already triggered their
515 RenderWidgetHostImpl
* widget_host_
;
516 FakeRenderWidgetHostViewAura
* view_
;
518 IPC::TestSink
* sink_
;
521 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraTest
);
524 // Helper class to instantiate RenderWidgetHostViewGuest which is backed
525 // by an aura platform view.
526 class RenderWidgetHostViewGuestAuraTest
: public RenderWidgetHostViewAuraTest
{
528 RenderWidgetHostViewGuestAuraTest() {
529 // Use RWH::Shutdown to destroy RWH, instead of deleting.
530 // This will ensure that the RenderWidgetHostViewGuest is not leaked and
531 // is deleted properly upon RWH going away.
532 set_widget_host_uses_shutdown_to_destroy(true);
535 // We explicitly invoke SetUp to allow gesture debounce customization.
536 void SetUp() override
{
537 is_guest_view_hack_
= true;
539 RenderWidgetHostViewAuraTest::SetUp();
541 guest_view_weak_
= (new RenderWidgetHostViewGuest(
542 widget_host_
, NULL
, view_
->GetWeakPtr()))->GetWeakPtr();
545 void TearDown() override
{
546 // Internal override to do nothing, we clean up ourselves in the test body.
547 // This helps us test that |guest_view_weak_| does not leak.
551 base::WeakPtr
<RenderWidgetHostViewBase
> guest_view_weak_
;
555 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewGuestAuraTest
);
558 class RenderWidgetHostViewAuraOverscrollTest
559 : public RenderWidgetHostViewAuraTest
{
561 RenderWidgetHostViewAuraOverscrollTest() {}
563 // We explicitly invoke SetUp to allow gesture debounce customization.
564 void SetUp() override
{}
567 void SetUpOverscrollEnvironmentWithDebounce(int debounce_interval_in_ms
) {
568 SetUpOverscrollEnvironmentImpl(debounce_interval_in_ms
);
571 void SetUpOverscrollEnvironment() { SetUpOverscrollEnvironmentImpl(0); }
573 void SetUpOverscrollEnvironmentImpl(int debounce_interval_in_ms
) {
574 ui::GestureConfiguration::GetInstance()->set_scroll_debounce_interval_in_ms(
575 debounce_interval_in_ms
);
577 RenderWidgetHostViewAuraTest::SetUp();
579 view_
->SetOverscrollControllerEnabled(true);
580 overscroll_delegate_
.reset(new TestOverscrollDelegate(view_
));
581 view_
->overscroll_controller()->set_delegate(overscroll_delegate_
.get());
583 view_
->InitAsChild(NULL
);
584 view_
->SetBounds(gfx::Rect(0, 0, 400, 200));
587 sink_
->ClearMessages();
590 // TODO(jdduke): Simulate ui::Events, injecting through the view.
591 void SimulateMouseEvent(WebInputEvent::Type type
) {
592 widget_host_
->ForwardMouseEvent(SyntheticWebMouseEventBuilder::Build(type
));
595 void SimulateMouseEventWithLatencyInfo(WebInputEvent::Type type
,
596 const ui::LatencyInfo
& ui_latency
) {
597 widget_host_
->ForwardMouseEventWithLatencyInfo(
598 SyntheticWebMouseEventBuilder::Build(type
), ui_latency
);
601 void SimulateWheelEvent(float dX
, float dY
, int modifiers
, bool precise
) {
602 widget_host_
->ForwardWheelEvent(
603 SyntheticWebMouseWheelEventBuilder::Build(dX
, dY
, modifiers
, precise
));
606 void SimulateWheelEventWithLatencyInfo(float dX
,
610 const ui::LatencyInfo
& ui_latency
) {
611 widget_host_
->ForwardWheelEventWithLatencyInfo(
612 SyntheticWebMouseWheelEventBuilder::Build(dX
, dY
, modifiers
, precise
),
616 void SimulateMouseMove(int x
, int y
, int modifiers
) {
617 SimulateMouseEvent(WebInputEvent::MouseMove
, x
, y
, modifiers
, false);
620 void SimulateMouseEvent(WebInputEvent::Type type
,
625 WebMouseEvent event
=
626 SyntheticWebMouseEventBuilder::Build(type
, x
, y
, modifiers
);
628 event
.button
= WebMouseEvent::ButtonLeft
;
629 widget_host_
->ForwardMouseEvent(event
);
632 void SimulateWheelEventWithPhase(WebMouseWheelEvent::Phase phase
) {
633 widget_host_
->ForwardWheelEvent(
634 SyntheticWebMouseWheelEventBuilder::Build(phase
));
637 // Inject provided synthetic WebGestureEvent instance.
638 void SimulateGestureEventCore(const WebGestureEvent
& gesture_event
) {
639 widget_host_
->ForwardGestureEvent(gesture_event
);
642 void SimulateGestureEventCoreWithLatencyInfo(
643 const WebGestureEvent
& gesture_event
,
644 const ui::LatencyInfo
& ui_latency
) {
645 widget_host_
->ForwardGestureEventWithLatencyInfo(gesture_event
, ui_latency
);
648 // Inject simple synthetic WebGestureEvent instances.
649 void SimulateGestureEvent(WebInputEvent::Type type
,
650 blink::WebGestureDevice sourceDevice
) {
651 SimulateGestureEventCore(
652 SyntheticWebGestureEventBuilder::Build(type
, sourceDevice
));
655 void SimulateGestureEventWithLatencyInfo(WebInputEvent::Type type
,
656 blink::WebGestureDevice sourceDevice
,
657 const ui::LatencyInfo
& ui_latency
) {
658 SimulateGestureEventCoreWithLatencyInfo(
659 SyntheticWebGestureEventBuilder::Build(type
, sourceDevice
), ui_latency
);
662 void SimulateGestureScrollUpdateEvent(float dX
, float dY
, int modifiers
) {
663 SimulateGestureEventCore(SyntheticWebGestureEventBuilder::BuildScrollUpdate(
664 dX
, dY
, modifiers
, blink::WebGestureDeviceTouchscreen
));
667 void SimulateGesturePinchUpdateEvent(float scale
,
671 SimulateGestureEventCore(SyntheticWebGestureEventBuilder::BuildPinchUpdate(
676 blink::WebGestureDeviceTouchscreen
));
679 // Inject synthetic GestureFlingStart events.
680 void SimulateGestureFlingStartEvent(float velocityX
,
682 blink::WebGestureDevice sourceDevice
) {
683 SimulateGestureEventCore(SyntheticWebGestureEventBuilder::BuildFling(
684 velocityX
, velocityY
, sourceDevice
));
687 bool ScrollStateIsContentScrolling() const {
688 return scroll_state() == OverscrollController::STATE_CONTENT_SCROLLING
;
691 bool ScrollStateIsOverscrolling() const {
692 return scroll_state() == OverscrollController::STATE_OVERSCROLLING
;
695 bool ScrollStateIsUnknown() const {
696 return scroll_state() == OverscrollController::STATE_UNKNOWN
;
699 OverscrollController::ScrollState
scroll_state() const {
700 return view_
->overscroll_controller()->scroll_state_
;
703 OverscrollMode
overscroll_mode() const {
704 return view_
->overscroll_controller()->overscroll_mode_
;
707 float overscroll_delta_x() const {
708 return view_
->overscroll_controller()->overscroll_delta_x_
;
711 float overscroll_delta_y() const {
712 return view_
->overscroll_controller()->overscroll_delta_y_
;
715 TestOverscrollDelegate
* overscroll_delegate() {
716 return overscroll_delegate_
.get();
719 uint32
SendTouchEvent() {
720 uint32 touch_event_id
= touch_event_
.uniqueTouchEventId
;
721 widget_host_
->ForwardTouchEventWithLatencyInfo(touch_event_
,
723 touch_event_
.ResetPoints();
724 return touch_event_id
;
727 void PressTouchPoint(int x
, int y
) {
728 touch_event_
.PressPoint(x
, y
);
731 void MoveTouchPoint(int index
, int x
, int y
) {
732 touch_event_
.MovePoint(index
, x
, y
);
735 void ReleaseTouchPoint(int index
) {
736 touch_event_
.ReleasePoint(index
);
739 SyntheticWebTouchEvent touch_event_
;
741 scoped_ptr
<TestOverscrollDelegate
> overscroll_delegate_
;
744 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraOverscrollTest
);
747 class RenderWidgetHostViewAuraShutdownTest
748 : public RenderWidgetHostViewAuraTest
{
750 RenderWidgetHostViewAuraShutdownTest() {}
752 void TearDown() override
{
753 // No TearDownEnvironment here, we do this explicitly during the test.
757 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraShutdownTest
);
760 // Checks that a fullscreen view has the correct show-state and receives the
762 TEST_F(RenderWidgetHostViewAuraTest
, FocusFullscreen
) {
763 view_
->InitAsFullscreen(parent_view_
);
764 aura::Window
* window
= view_
->GetNativeView();
765 ASSERT_TRUE(window
!= NULL
);
766 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN
,
767 window
->GetProperty(aura::client::kShowStateKey
));
769 // Check that we requested and received the focus.
770 EXPECT_TRUE(window
->HasFocus());
772 // Check that we'll also say it's okay to activate the window when there's an
773 // ActivationClient defined.
774 EXPECT_TRUE(view_
->ShouldActivate());
777 // Checks that a popup is positioned correctly relative to its parent using
778 // screen coordinates.
779 TEST_F(RenderWidgetHostViewAuraTest
, PositionChildPopup
) {
780 wm::DefaultScreenPositionClient screen_position_client
;
782 aura::Window
* window
= parent_view_
->GetNativeView();
783 aura::Window
* root
= window
->GetRootWindow();
784 aura::client::SetScreenPositionClient(root
, &screen_position_client
);
786 parent_view_
->SetBounds(gfx::Rect(10, 10, 800, 600));
787 gfx::Rect bounds_in_screen
= parent_view_
->GetViewBounds();
788 int horiz
= bounds_in_screen
.width() / 4;
789 int vert
= bounds_in_screen
.height() / 4;
790 bounds_in_screen
.Inset(horiz
, vert
);
792 // Verify that when the popup is initialized for the first time, it correctly
793 // treats the input bounds as screen coordinates.
794 view_
->InitAsPopup(parent_view_
, bounds_in_screen
);
796 gfx::Rect final_bounds_in_screen
= view_
->GetViewBounds();
797 EXPECT_EQ(final_bounds_in_screen
.ToString(), bounds_in_screen
.ToString());
799 // Verify that directly setting the bounds via SetBounds() treats the input
800 // as screen coordinates.
801 bounds_in_screen
= gfx::Rect(60, 60, 100, 100);
802 view_
->SetBounds(bounds_in_screen
);
803 final_bounds_in_screen
= view_
->GetViewBounds();
804 EXPECT_EQ(final_bounds_in_screen
.ToString(), bounds_in_screen
.ToString());
806 // Verify that setting the size does not alter the origin.
807 gfx::Point original_origin
= window
->bounds().origin();
808 view_
->SetSize(gfx::Size(120, 120));
809 gfx::Point new_origin
= window
->bounds().origin();
810 EXPECT_EQ(original_origin
.ToString(), new_origin
.ToString());
812 aura::client::SetScreenPositionClient(root
, NULL
);
815 // Checks that moving parent sends new screen bounds.
816 TEST_F(RenderWidgetHostViewAuraTest
, ParentMovementUpdatesScreenRect
) {
817 view_
->InitAsChild(NULL
);
819 aura::Window
* root
= parent_view_
->GetNativeView()->GetRootWindow();
821 aura::test::TestWindowDelegate delegate1
, delegate2
;
822 scoped_ptr
<aura::Window
> parent1(new aura::Window(&delegate1
));
823 parent1
->Init(ui::LAYER_TEXTURED
);
825 scoped_ptr
<aura::Window
> parent2(new aura::Window(&delegate2
));
826 parent2
->Init(ui::LAYER_TEXTURED
);
829 root
->AddChild(parent1
.get());
830 parent1
->AddChild(parent2
.get());
831 parent2
->AddChild(view_
->GetNativeView());
833 root
->SetBounds(gfx::Rect(0, 0, 800, 600));
834 parent1
->SetBounds(gfx::Rect(1, 1, 300, 300));
835 parent2
->SetBounds(gfx::Rect(2, 2, 200, 200));
836 view_
->SetBounds(gfx::Rect(3, 3, 100, 100));
837 // view_ will be destroyed when parent is destroyed.
840 // Flush the state after initial setup is done.
841 widget_host_
->OnMessageReceived(
842 ViewHostMsg_UpdateScreenRects_ACK(widget_host_
->GetRoutingID()));
843 widget_host_
->OnMessageReceived(
844 ViewHostMsg_UpdateScreenRects_ACK(widget_host_
->GetRoutingID()));
845 sink_
->ClearMessages();
848 parent2
->SetBounds(gfx::Rect(20, 20, 200, 200));
849 ASSERT_EQ(1U, sink_
->message_count());
850 const IPC::Message
* msg
= sink_
->GetMessageAt(0);
851 ASSERT_EQ(ViewMsg_UpdateScreenRects::ID
, msg
->type());
852 ViewMsg_UpdateScreenRects::Param params
;
853 ViewMsg_UpdateScreenRects::Read(msg
, ¶ms
);
854 EXPECT_EQ(gfx::Rect(24, 24, 100, 100), base::get
<0>(params
));
855 EXPECT_EQ(gfx::Rect(1, 1, 300, 300), base::get
<1>(params
));
856 sink_
->ClearMessages();
857 widget_host_
->OnMessageReceived(
858 ViewHostMsg_UpdateScreenRects_ACK(widget_host_
->GetRoutingID()));
859 // There should not be any pending update.
860 EXPECT_EQ(0U, sink_
->message_count());
862 parent1
->SetBounds(gfx::Rect(10, 10, 300, 300));
863 ASSERT_EQ(1U, sink_
->message_count());
864 msg
= sink_
->GetMessageAt(0);
865 ASSERT_EQ(ViewMsg_UpdateScreenRects::ID
, msg
->type());
866 ViewMsg_UpdateScreenRects::Read(msg
, ¶ms
);
867 EXPECT_EQ(gfx::Rect(33, 33, 100, 100), base::get
<0>(params
));
868 EXPECT_EQ(gfx::Rect(10, 10, 300, 300), base::get
<1>(params
));
869 sink_
->ClearMessages();
870 widget_host_
->OnMessageReceived(
871 ViewHostMsg_UpdateScreenRects_ACK(widget_host_
->GetRoutingID()));
872 // There should not be any pending update.
873 EXPECT_EQ(0U, sink_
->message_count());
876 // Checks that a fullscreen view is destroyed when it loses the focus.
877 TEST_F(RenderWidgetHostViewAuraTest
, DestroyFullscreenOnBlur
) {
878 view_
->InitAsFullscreen(parent_view_
);
879 aura::Window
* window
= view_
->GetNativeView();
880 ASSERT_TRUE(window
!= NULL
);
881 ASSERT_TRUE(window
->HasFocus());
883 // After we create and focus another window, the RWHVA's window should be
885 TestWindowObserver
observer(window
);
886 aura::test::TestWindowDelegate delegate
;
887 scoped_ptr
<aura::Window
> sibling(new aura::Window(&delegate
));
888 sibling
->Init(ui::LAYER_TEXTURED
);
890 window
->parent()->AddChild(sibling
.get());
892 ASSERT_TRUE(sibling
->HasFocus());
893 ASSERT_TRUE(observer
.destroyed());
899 // Checks that a popup view is destroyed when a user clicks outside of the popup
900 // view and focus does not change. This is the case when the user clicks on the
901 // desktop background on Chrome OS.
902 TEST_F(RenderWidgetHostViewAuraTest
, DestroyPopupClickOutsidePopup
) {
903 parent_view_
->SetBounds(gfx::Rect(10, 10, 400, 400));
904 parent_view_
->Focus();
905 EXPECT_TRUE(parent_view_
->HasFocus());
907 view_
->InitAsPopup(parent_view_
, gfx::Rect(10, 10, 100, 100));
908 aura::Window
* window
= view_
->GetNativeView();
909 ASSERT_TRUE(window
!= NULL
);
911 gfx::Point click_point
;
912 EXPECT_FALSE(window
->GetBoundsInRootWindow().Contains(click_point
));
913 aura::Window
* parent_window
= parent_view_
->GetNativeView();
914 EXPECT_FALSE(parent_window
->GetBoundsInRootWindow().Contains(click_point
));
916 TestWindowObserver
observer(window
);
917 ui::test::EventGenerator
generator(window
->GetRootWindow(), click_point
);
918 generator
.ClickLeftButton();
919 ASSERT_TRUE(parent_view_
->HasFocus());
920 ASSERT_TRUE(observer
.destroyed());
926 // Checks that a popup view is destroyed when a user taps outside of the popup
927 // view and focus does not change. This is the case when the user taps the
928 // desktop background on Chrome OS.
929 TEST_F(RenderWidgetHostViewAuraTest
, DestroyPopupTapOutsidePopup
) {
930 parent_view_
->SetBounds(gfx::Rect(10, 10, 400, 400));
931 parent_view_
->Focus();
932 EXPECT_TRUE(parent_view_
->HasFocus());
934 view_
->InitAsPopup(parent_view_
, gfx::Rect(10, 10, 100, 100));
935 aura::Window
* window
= view_
->GetNativeView();
936 ASSERT_TRUE(window
!= NULL
);
938 gfx::Point tap_point
;
939 EXPECT_FALSE(window
->GetBoundsInRootWindow().Contains(tap_point
));
940 aura::Window
* parent_window
= parent_view_
->GetNativeView();
941 EXPECT_FALSE(parent_window
->GetBoundsInRootWindow().Contains(tap_point
));
943 TestWindowObserver
observer(window
);
944 ui::test::EventGenerator
generator(window
->GetRootWindow(), tap_point
);
945 generator
.GestureTapAt(tap_point
);
946 ASSERT_TRUE(parent_view_
->HasFocus());
947 ASSERT_TRUE(observer
.destroyed());
953 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
955 // On Desktop Linux, select boxes need mouse capture in order to work. Test that
956 // when a select box is opened via a mouse press that it retains mouse capture
957 // after the mouse is released.
958 TEST_F(RenderWidgetHostViewAuraTest
, PopupRetainsCaptureAfterMouseRelease
) {
959 parent_view_
->SetBounds(gfx::Rect(10, 10, 400, 400));
960 parent_view_
->Focus();
961 EXPECT_TRUE(parent_view_
->HasFocus());
963 ui::test::EventGenerator
generator(
964 parent_view_
->GetNativeView()->GetRootWindow(), gfx::Point(300, 300));
965 generator
.PressLeftButton();
967 view_
->SetPopupType(blink::WebPopupTypePage
);
968 view_
->InitAsPopup(parent_view_
, gfx::Rect(10, 10, 100, 100));
969 ASSERT_TRUE(view_
->NeedsMouseCapture());
970 aura::Window
* window
= view_
->GetNativeView();
971 EXPECT_TRUE(window
->HasCapture());
973 generator
.ReleaseLeftButton();
974 EXPECT_TRUE(window
->HasCapture());
978 // Test that select boxes close when their parent window loses focus (e.g. due
979 // to an alert or system modal dialog).
980 TEST_F(RenderWidgetHostViewAuraTest
, PopupClosesWhenParentLosesFocus
) {
981 parent_view_
->SetBounds(gfx::Rect(10, 10, 400, 400));
982 parent_view_
->Focus();
983 EXPECT_TRUE(parent_view_
->HasFocus());
985 view_
->SetPopupType(blink::WebPopupTypePage
);
986 view_
->InitAsPopup(parent_view_
, gfx::Rect(10, 10, 100, 100));
988 aura::Window
* popup_window
= view_
->GetNativeView();
989 TestWindowObserver
observer(popup_window
);
991 aura::test::TestWindowDelegate delegate
;
992 scoped_ptr
<aura::Window
> dialog_window(new aura::Window(&delegate
));
993 dialog_window
->Init(ui::LAYER_TEXTURED
);
994 aura::client::ParentWindowWithContext(
995 dialog_window
.get(), popup_window
, gfx::Rect());
996 dialog_window
->Show();
997 wm::ActivateWindow(dialog_window
.get());
998 dialog_window
->Focus();
1000 ASSERT_TRUE(wm::IsActiveWindow(dialog_window
.get()));
1001 EXPECT_TRUE(observer
.destroyed());
1003 widget_host_
= NULL
;
1007 // Checks that IME-composition-event state is maintained correctly.
1008 TEST_F(RenderWidgetHostViewAuraTest
, SetCompositionText
) {
1009 view_
->InitAsChild(NULL
);
1012 ui::CompositionText composition_text
;
1013 composition_text
.text
= base::ASCIIToUTF16("|a|b");
1016 composition_text
.underlines
.push_back(
1017 ui::CompositionUnderline(0, 3, 0xff000000, true, 0x78563412));
1019 // Non-focused segment, with different background color.
1020 composition_text
.underlines
.push_back(
1021 ui::CompositionUnderline(3, 4, 0xff000000, false, 0xefcdab90));
1023 const ui::CompositionUnderlines
& underlines
= composition_text
.underlines
;
1025 // Caret is at the end. (This emulates Japanese MSIME 2007 and later)
1026 composition_text
.selection
= gfx::Range(4);
1028 sink_
->ClearMessages();
1029 view_
->SetCompositionText(composition_text
);
1030 EXPECT_TRUE(view_
->has_composition_text_
);
1032 const IPC::Message
* msg
=
1033 sink_
->GetFirstMessageMatching(InputMsg_ImeSetComposition::ID
);
1034 ASSERT_TRUE(msg
!= NULL
);
1036 InputMsg_ImeSetComposition::Param params
;
1037 InputMsg_ImeSetComposition::Read(msg
, ¶ms
);
1039 EXPECT_EQ(composition_text
.text
, base::get
<0>(params
));
1041 ASSERT_EQ(underlines
.size(), base::get
<1>(params
).size());
1042 for (size_t i
= 0; i
< underlines
.size(); ++i
) {
1043 EXPECT_EQ(underlines
[i
].start_offset
,
1044 base::get
<1>(params
)[i
].startOffset
);
1045 EXPECT_EQ(underlines
[i
].end_offset
, base::get
<1>(params
)[i
].endOffset
);
1046 EXPECT_EQ(underlines
[i
].color
, base::get
<1>(params
)[i
].color
);
1047 EXPECT_EQ(underlines
[i
].thick
, base::get
<1>(params
)[i
].thick
);
1048 EXPECT_EQ(underlines
[i
].background_color
,
1049 base::get
<1>(params
)[i
].backgroundColor
);
1051 // highlighted range
1052 EXPECT_EQ(4, base::get
<2>(params
)) << "Should be the same to the caret pos";
1053 EXPECT_EQ(4, base::get
<3>(params
)) << "Should be the same to the caret pos";
1056 view_
->ImeCancelComposition();
1057 EXPECT_FALSE(view_
->has_composition_text_
);
1060 // Checks that sequence of IME-composition-event and mouse-event when mouse
1061 // clicking to cancel the composition.
1062 TEST_F(RenderWidgetHostViewAuraTest
, FinishCompositionByMouse
) {
1063 view_
->InitAsChild(NULL
);
1066 ui::CompositionText composition_text
;
1067 composition_text
.text
= base::ASCIIToUTF16("|a|b");
1070 composition_text
.underlines
.push_back(
1071 ui::CompositionUnderline(0, 3, 0xff000000, true, 0x78563412));
1073 // Non-focused segment, with different background color.
1074 composition_text
.underlines
.push_back(
1075 ui::CompositionUnderline(3, 4, 0xff000000, false, 0xefcdab90));
1077 // Caret is at the end. (This emulates Japanese MSIME 2007 and later)
1078 composition_text
.selection
= gfx::Range(4);
1080 view_
->SetCompositionText(composition_text
);
1081 EXPECT_TRUE(view_
->has_composition_text_
);
1082 sink_
->ClearMessages();
1084 // Simulates the mouse press.
1085 ui::MouseEvent
mouse_event(ui::ET_MOUSE_PRESSED
, gfx::Point(), gfx::Point(),
1086 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON
,
1088 view_
->OnMouseEvent(&mouse_event
);
1090 EXPECT_FALSE(view_
->has_composition_text_
);
1092 EXPECT_EQ(2U, sink_
->message_count());
1094 if (sink_
->message_count() == 2) {
1095 // Verify mouse event happens after the confirm-composition event.
1096 EXPECT_EQ(InputMsg_ImeConfirmComposition::ID
,
1097 sink_
->GetMessageAt(0)->type());
1098 EXPECT_EQ(InputMsg_HandleInputEvent::ID
,
1099 sink_
->GetMessageAt(1)->type());
1103 // Checks that touch-event state is maintained correctly.
1104 TEST_F(RenderWidgetHostViewAuraTest
, TouchEventState
) {
1105 view_
->InitAsChild(NULL
);
1107 GetSentMessageCountAndResetSink();
1109 // Start with no touch-event handler in the renderer.
1110 widget_host_
->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, false));
1112 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
,
1115 ui::EventTimeForNow());
1116 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
,
1119 ui::EventTimeForNow());
1120 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
,
1123 ui::EventTimeForNow());
1125 // The touch events should get forwarded from the view, but they should not
1126 // reach the renderer.
1127 view_
->OnTouchEvent(&press
);
1128 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1129 EXPECT_TRUE(press
.synchronous_handling_disabled());
1130 EXPECT_EQ(ui::MotionEvent::ACTION_DOWN
, pointer_state().GetAction());
1132 view_
->OnTouchEvent(&move
);
1133 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1134 EXPECT_TRUE(press
.synchronous_handling_disabled());
1135 EXPECT_EQ(ui::MotionEvent::ACTION_MOVE
, pointer_state().GetAction());
1136 EXPECT_EQ(1U, pointer_state().GetPointerCount());
1138 view_
->OnTouchEvent(&release
);
1139 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1140 EXPECT_TRUE(press
.synchronous_handling_disabled());
1141 EXPECT_EQ(0U, pointer_state().GetPointerCount());
1143 // Now install some touch-event handlers and do the same steps. The touch
1144 // events should now be consumed. However, the touch-event state should be
1145 // updated as before.
1146 widget_host_
->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
1148 view_
->OnTouchEvent(&press
);
1149 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1150 EXPECT_TRUE(press
.synchronous_handling_disabled());
1151 EXPECT_EQ(ui::MotionEvent::ACTION_DOWN
, pointer_state().GetAction());
1152 EXPECT_EQ(1U, pointer_state().GetPointerCount());
1154 view_
->OnTouchEvent(&move
);
1155 EXPECT_TRUE(move
.synchronous_handling_disabled());
1156 EXPECT_EQ(ui::MotionEvent::ACTION_MOVE
, pointer_state().GetAction());
1157 EXPECT_EQ(1U, pointer_state().GetPointerCount());
1158 view_
->OnTouchEvent(&release
);
1159 EXPECT_TRUE(release
.synchronous_handling_disabled());
1160 EXPECT_EQ(0U, pointer_state().GetPointerCount());
1162 // Now start a touch event, and remove the event-handlers before the release.
1163 view_
->OnTouchEvent(&press
);
1164 EXPECT_TRUE(press
.synchronous_handling_disabled());
1165 EXPECT_EQ(ui::MotionEvent::ACTION_DOWN
, pointer_state().GetAction());
1166 EXPECT_EQ(1U, pointer_state().GetPointerCount());
1168 widget_host_
->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, false));
1170 // Ack'ing the outstanding event should flush the pending touch queue.
1171 InputEventAck
ack(blink::WebInputEvent::TouchStart
,
1172 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS
,
1173 press
.unique_event_id());
1174 widget_host_
->OnMessageReceived(InputHostMsg_HandleInputEvent_ACK(0, ack
));
1175 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1177 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(20, 20), 0,
1178 base::Time::NowFromSystemTime() - base::Time());
1179 view_
->OnTouchEvent(&move2
);
1180 EXPECT_TRUE(press
.synchronous_handling_disabled());
1181 EXPECT_EQ(ui::MotionEvent::ACTION_MOVE
, pointer_state().GetAction());
1182 EXPECT_EQ(1U, pointer_state().GetPointerCount());
1184 ui::TouchEvent
release2(ui::ET_TOUCH_RELEASED
, gfx::Point(20, 20), 0,
1185 base::Time::NowFromSystemTime() - base::Time());
1186 view_
->OnTouchEvent(&release2
);
1187 EXPECT_TRUE(press
.synchronous_handling_disabled());
1188 EXPECT_EQ(0U, pointer_state().GetPointerCount());
1191 // Checks that touch-event state is maintained correctly for multiple touch
1193 TEST_F(RenderWidgetHostViewAuraTest
, MultiTouchPointsStates
) {
1194 view_
->InitAsFullscreen(parent_view_
);
1196 view_
->UseFakeDispatcher();
1197 GetSentMessageCountAndResetSink();
1199 ui::TouchEvent
press0(ui::ET_TOUCH_PRESSED
, gfx::Point(30, 30), 0,
1200 ui::EventTimeForNow());
1202 view_
->OnTouchEvent(&press0
);
1203 SendTouchEventACK(blink::WebInputEvent::TouchStart
,
1204 INPUT_EVENT_ACK_STATE_CONSUMED
,
1205 press0
.unique_event_id());
1206 EXPECT_EQ(ui::MotionEvent::ACTION_DOWN
, pointer_state().GetAction());
1207 EXPECT_EQ(1U, pointer_state().GetPointerCount());
1208 EXPECT_EQ(1U, view_
->dispatcher_
->GetAndResetProcessedTouchEventCount());
1210 ui::TouchEvent
move0(ui::ET_TOUCH_MOVED
, gfx::Point(20, 20), 0,
1211 ui::EventTimeForNow());
1213 view_
->OnTouchEvent(&move0
);
1214 SendTouchEventACK(blink::WebInputEvent::TouchMove
,
1215 INPUT_EVENT_ACK_STATE_CONSUMED
,
1216 move0
.unique_event_id());
1217 EXPECT_EQ(ui::MotionEvent::ACTION_MOVE
, pointer_state().GetAction());
1218 EXPECT_EQ(1U, pointer_state().GetPointerCount());
1219 EXPECT_EQ(1U, view_
->dispatcher_
->GetAndResetProcessedTouchEventCount());
1221 // For the second touchstart, only the state of the second touch point is
1222 // StatePressed, the state of the first touch point is StateStationary.
1223 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(10, 10), 1,
1224 ui::EventTimeForNow());
1226 view_
->OnTouchEvent(&press1
);
1227 SendTouchEventACK(blink::WebInputEvent::TouchStart
,
1228 INPUT_EVENT_ACK_STATE_CONSUMED
,
1229 press1
.unique_event_id());
1230 EXPECT_EQ(ui::MotionEvent::ACTION_POINTER_DOWN
, pointer_state().GetAction());
1231 EXPECT_EQ(1, pointer_state().GetActionIndex());
1232 EXPECT_EQ(2U, pointer_state().GetPointerCount());
1233 EXPECT_EQ(1U, view_
->dispatcher_
->GetAndResetProcessedTouchEventCount());
1235 // For the touchmove of second point, the state of the second touch point is
1236 // StateMoved, the state of the first touch point is StateStationary.
1237 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
, gfx::Point(30, 30), 1,
1238 ui::EventTimeForNow());
1240 view_
->OnTouchEvent(&move1
);
1241 SendTouchEventACK(blink::WebInputEvent::TouchMove
,
1242 INPUT_EVENT_ACK_STATE_CONSUMED
,
1243 move1
.unique_event_id());
1244 EXPECT_EQ(ui::MotionEvent::ACTION_MOVE
, pointer_state().GetAction());
1245 EXPECT_EQ(2U, pointer_state().GetPointerCount());
1246 EXPECT_EQ(1U, view_
->dispatcher_
->GetAndResetProcessedTouchEventCount());
1248 // For the touchmove of first point, the state of the first touch point is
1249 // StateMoved, the state of the second touch point is StateStationary.
1250 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(10, 10), 0,
1251 ui::EventTimeForNow());
1253 view_
->OnTouchEvent(&move2
);
1254 SendTouchEventACK(blink::WebInputEvent::TouchMove
,
1255 INPUT_EVENT_ACK_STATE_CONSUMED
,
1256 move2
.unique_event_id());
1257 EXPECT_EQ(ui::MotionEvent::ACTION_MOVE
, pointer_state().GetAction());
1258 EXPECT_EQ(2U, pointer_state().GetPointerCount());
1259 EXPECT_EQ(1U, view_
->dispatcher_
->GetAndResetProcessedTouchEventCount());
1261 ui::TouchEvent
cancel0(ui::ET_TOUCH_CANCELLED
, gfx::Point(10, 10), 0,
1262 ui::EventTimeForNow());
1264 // For the touchcancel, only the state of the current touch point is
1265 // StateCancelled, the state of the other touch point is StateStationary.
1266 view_
->OnTouchEvent(&cancel0
);
1267 EXPECT_EQ(1U, pointer_state().GetPointerCount());
1268 EXPECT_EQ(1U, view_
->dispatcher_
->GetAndResetProcessedTouchEventCount());
1270 ui::TouchEvent
cancel1(ui::ET_TOUCH_CANCELLED
, gfx::Point(30, 30), 1,
1271 ui::EventTimeForNow());
1273 view_
->OnTouchEvent(&cancel1
);
1274 EXPECT_EQ(1U, view_
->dispatcher_
->GetAndResetProcessedTouchEventCount());
1275 EXPECT_EQ(0U, pointer_state().GetPointerCount());
1278 // Checks that touch-events are queued properly when there is a touch-event
1279 // handler on the page.
1280 TEST_F(RenderWidgetHostViewAuraTest
, TouchEventSyncAsync
) {
1281 view_
->InitAsChild(NULL
);
1284 widget_host_
->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
1286 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
,
1289 ui::EventTimeForNow());
1290 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
,
1293 ui::EventTimeForNow());
1294 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
,
1297 ui::EventTimeForNow());
1299 view_
->OnTouchEvent(&press
);
1300 EXPECT_TRUE(press
.synchronous_handling_disabled());
1301 EXPECT_EQ(ui::MotionEvent::ACTION_DOWN
, pointer_state().GetAction());
1302 EXPECT_EQ(1U, pointer_state().GetPointerCount());
1304 view_
->OnTouchEvent(&move
);
1305 EXPECT_TRUE(move
.synchronous_handling_disabled());
1306 EXPECT_EQ(ui::MotionEvent::ACTION_MOVE
, pointer_state().GetAction());
1307 EXPECT_EQ(1U, pointer_state().GetPointerCount());
1309 // Send the same move event. Since the point hasn't moved, it won't affect the
1310 // queue. However, the view should consume the event.
1311 view_
->OnTouchEvent(&move
);
1312 EXPECT_TRUE(move
.synchronous_handling_disabled());
1313 EXPECT_EQ(ui::MotionEvent::ACTION_MOVE
, pointer_state().GetAction());
1314 EXPECT_EQ(1U, pointer_state().GetPointerCount());
1316 view_
->OnTouchEvent(&release
);
1317 EXPECT_TRUE(release
.synchronous_handling_disabled());
1318 EXPECT_EQ(0U, pointer_state().GetPointerCount());
1321 TEST_F(RenderWidgetHostViewAuraTest
, PhysicalBackingSizeWithScale
) {
1322 view_
->InitAsChild(NULL
);
1323 aura::client::ParentWindowWithContext(
1324 view_
->GetNativeView(),
1325 parent_view_
->GetNativeView()->GetRootWindow(),
1327 sink_
->ClearMessages();
1328 view_
->SetSize(gfx::Size(100, 100));
1329 EXPECT_EQ("100x100", view_
->GetPhysicalBackingSize().ToString());
1330 EXPECT_EQ(1u, sink_
->message_count());
1331 EXPECT_EQ(ViewMsg_Resize::ID
, sink_
->GetMessageAt(0)->type());
1333 const IPC::Message
* msg
= sink_
->GetMessageAt(0);
1334 EXPECT_EQ(ViewMsg_Resize::ID
, msg
->type());
1335 ViewMsg_Resize::Param params
;
1336 ViewMsg_Resize::Read(msg
, ¶ms
);
1337 EXPECT_EQ("100x100", base::get
<0>(params
).new_size
.ToString()); // dip size
1338 EXPECT_EQ("100x100",
1339 base::get
<0>(params
).physical_backing_size
.ToString()); // backing size
1342 widget_host_
->ResetSizeAndRepaintPendingFlags();
1343 sink_
->ClearMessages();
1345 aura_test_helper_
->test_screen()->SetDeviceScaleFactor(2.0f
);
1346 EXPECT_EQ("200x200", view_
->GetPhysicalBackingSize().ToString());
1347 // Extra ScreenInfoChanged message for |parent_view_|.
1348 EXPECT_EQ(1u, sink_
->message_count());
1350 const IPC::Message
* msg
= sink_
->GetMessageAt(0);
1351 EXPECT_EQ(ViewMsg_Resize::ID
, msg
->type());
1352 ViewMsg_Resize::Param params
;
1353 ViewMsg_Resize::Read(msg
, ¶ms
);
1354 EXPECT_EQ(2.0f
, base::get
<0>(params
).screen_info
.deviceScaleFactor
);
1355 EXPECT_EQ("100x100", base::get
<0>(params
).new_size
.ToString()); // dip size
1356 EXPECT_EQ("200x200",
1357 base::get
<0>(params
).physical_backing_size
.ToString()); // backing size
1360 widget_host_
->ResetSizeAndRepaintPendingFlags();
1361 sink_
->ClearMessages();
1363 aura_test_helper_
->test_screen()->SetDeviceScaleFactor(1.0f
);
1364 // Extra ScreenInfoChanged message for |parent_view_|.
1365 EXPECT_EQ(1u, sink_
->message_count());
1366 EXPECT_EQ("100x100", view_
->GetPhysicalBackingSize().ToString());
1368 const IPC::Message
* msg
= sink_
->GetMessageAt(0);
1369 EXPECT_EQ(ViewMsg_Resize::ID
, msg
->type());
1370 ViewMsg_Resize::Param params
;
1371 ViewMsg_Resize::Read(msg
, ¶ms
);
1372 EXPECT_EQ(1.0f
, base::get
<0>(params
).screen_info
.deviceScaleFactor
);
1373 EXPECT_EQ("100x100", base::get
<0>(params
).new_size
.ToString()); // dip size
1374 EXPECT_EQ("100x100",
1375 base::get
<0>(params
).physical_backing_size
.ToString()); // backing size
1379 // Checks that InputMsg_CursorVisibilityChange IPC messages are dispatched
1380 // to the renderer at the correct times.
1381 TEST_F(RenderWidgetHostViewAuraTest
, CursorVisibilityChange
) {
1382 view_
->InitAsChild(NULL
);
1383 aura::client::ParentWindowWithContext(
1384 view_
->GetNativeView(),
1385 parent_view_
->GetNativeView()->GetRootWindow(),
1387 view_
->SetSize(gfx::Size(100, 100));
1389 aura::test::TestCursorClient
cursor_client(
1390 parent_view_
->GetNativeView()->GetRootWindow());
1392 cursor_client
.AddObserver(view_
);
1394 // Expect a message the first time the cursor is shown.
1396 sink_
->ClearMessages();
1397 cursor_client
.ShowCursor();
1398 EXPECT_EQ(1u, sink_
->message_count());
1399 EXPECT_TRUE(sink_
->GetUniqueMessageMatching(
1400 InputMsg_CursorVisibilityChange::ID
));
1402 // No message expected if the renderer already knows the cursor is visible.
1403 sink_
->ClearMessages();
1404 cursor_client
.ShowCursor();
1405 EXPECT_EQ(0u, sink_
->message_count());
1407 // Hiding the cursor should send a message.
1408 sink_
->ClearMessages();
1409 cursor_client
.HideCursor();
1410 EXPECT_EQ(1u, sink_
->message_count());
1411 EXPECT_TRUE(sink_
->GetUniqueMessageMatching(
1412 InputMsg_CursorVisibilityChange::ID
));
1414 // No message expected if the renderer already knows the cursor is invisible.
1415 sink_
->ClearMessages();
1416 cursor_client
.HideCursor();
1417 EXPECT_EQ(0u, sink_
->message_count());
1419 // No messages should be sent while the view is invisible.
1421 sink_
->ClearMessages();
1422 cursor_client
.ShowCursor();
1423 EXPECT_EQ(0u, sink_
->message_count());
1424 cursor_client
.HideCursor();
1425 EXPECT_EQ(0u, sink_
->message_count());
1427 // Show the view. Since the cursor was invisible when the view was hidden,
1428 // no message should be sent.
1429 sink_
->ClearMessages();
1431 EXPECT_FALSE(sink_
->GetUniqueMessageMatching(
1432 InputMsg_CursorVisibilityChange::ID
));
1434 // No message expected if the renderer already knows the cursor is invisible.
1435 sink_
->ClearMessages();
1436 cursor_client
.HideCursor();
1437 EXPECT_EQ(0u, sink_
->message_count());
1439 // Showing the cursor should send a message.
1440 sink_
->ClearMessages();
1441 cursor_client
.ShowCursor();
1442 EXPECT_EQ(1u, sink_
->message_count());
1443 EXPECT_TRUE(sink_
->GetUniqueMessageMatching(
1444 InputMsg_CursorVisibilityChange::ID
));
1446 // No messages should be sent while the view is invisible.
1448 sink_
->ClearMessages();
1449 cursor_client
.HideCursor();
1450 EXPECT_EQ(0u, sink_
->message_count());
1452 // Show the view. Since the cursor was visible when the view was hidden,
1453 // a message is expected to be sent.
1454 sink_
->ClearMessages();
1456 EXPECT_TRUE(sink_
->GetUniqueMessageMatching(
1457 InputMsg_CursorVisibilityChange::ID
));
1459 cursor_client
.RemoveObserver(view_
);
1462 TEST_F(RenderWidgetHostViewAuraTest
, UpdateCursorIfOverSelf
) {
1463 view_
->InitAsChild(NULL
);
1464 aura::client::ParentWindowWithContext(
1465 view_
->GetNativeView(),
1466 parent_view_
->GetNativeView()->GetRootWindow(),
1469 // Note that all coordinates in this test are screen coordinates.
1470 view_
->SetBounds(gfx::Rect(60, 60, 100, 100));
1473 aura::test::TestCursorClient
cursor_client(
1474 parent_view_
->GetNativeView()->GetRootWindow());
1476 // Cursor is in the middle of the window.
1477 cursor_client
.reset_calls_to_set_cursor();
1478 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(110, 110));
1479 view_
->UpdateCursorIfOverSelf();
1480 EXPECT_EQ(1, cursor_client
.calls_to_set_cursor());
1482 // Cursor is near the top of the window.
1483 cursor_client
.reset_calls_to_set_cursor();
1484 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(80, 65));
1485 view_
->UpdateCursorIfOverSelf();
1486 EXPECT_EQ(1, cursor_client
.calls_to_set_cursor());
1488 // Cursor is near the bottom of the window.
1489 cursor_client
.reset_calls_to_set_cursor();
1490 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(159, 159));
1491 view_
->UpdateCursorIfOverSelf();
1492 EXPECT_EQ(1, cursor_client
.calls_to_set_cursor());
1494 // Cursor is above the window.
1495 cursor_client
.reset_calls_to_set_cursor();
1496 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(67, 59));
1497 view_
->UpdateCursorIfOverSelf();
1498 EXPECT_EQ(0, cursor_client
.calls_to_set_cursor());
1500 // Cursor is below the window.
1501 cursor_client
.reset_calls_to_set_cursor();
1502 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(161, 161));
1503 view_
->UpdateCursorIfOverSelf();
1504 EXPECT_EQ(0, cursor_client
.calls_to_set_cursor());
1507 scoped_ptr
<cc::CompositorFrame
> MakeDelegatedFrame(float scale_factor
,
1510 scoped_ptr
<cc::CompositorFrame
> frame(new cc::CompositorFrame
);
1511 frame
->metadata
.device_scale_factor
= scale_factor
;
1512 frame
->delegated_frame_data
.reset(new cc::DelegatedFrameData
);
1514 scoped_ptr
<cc::RenderPass
> pass
= cc::RenderPass::Create();
1516 cc::RenderPassId(1, 1), gfx::Rect(size
), damage
, gfx::Transform());
1517 frame
->delegated_frame_data
->render_pass_list
.push_back(pass
.Pass());
1518 return frame
.Pass();
1521 // Resizing in fullscreen mode should send the up-to-date screen info.
1522 // http://crbug.com/324350
1523 TEST_F(RenderWidgetHostViewAuraTest
, DISABLED_FullscreenResize
) {
1524 aura::Window
* root_window
= aura_test_helper_
->root_window();
1525 root_window
->SetLayoutManager(new FullscreenLayoutManager(root_window
));
1526 view_
->InitAsFullscreen(parent_view_
);
1528 widget_host_
->ResetSizeAndRepaintPendingFlags();
1529 sink_
->ClearMessages();
1531 // Call WasResized to flush the old screen info.
1532 view_
->GetRenderWidgetHost()->WasResized();
1534 // 0 is CreatingNew message.
1535 const IPC::Message
* msg
= sink_
->GetMessageAt(0);
1536 EXPECT_EQ(ViewMsg_Resize::ID
, msg
->type());
1537 ViewMsg_Resize::Param params
;
1538 ViewMsg_Resize::Read(msg
, ¶ms
);
1539 EXPECT_EQ("0,0 800x600",
1541 base::get
<0>(params
).screen_info
.availableRect
).ToString());
1542 EXPECT_EQ("800x600", base::get
<0>(params
).new_size
.ToString());
1543 // Resizes are blocked until we swapped a frame of the correct size, and
1544 // we've committed it.
1545 view_
->OnSwapCompositorFrame(
1548 1.f
, base::get
<0>(params
).new_size
,
1549 gfx::Rect(base::get
<0>(params
).new_size
)));
1550 ui::DrawWaiterForTest::WaitForCommit(
1551 root_window
->GetHost()->compositor());
1554 widget_host_
->ResetSizeAndRepaintPendingFlags();
1555 sink_
->ClearMessages();
1557 // Make sure the corrent screen size is set along in the resize
1558 // request when the screen size has changed.
1559 aura_test_helper_
->test_screen()->SetUIScale(0.5);
1560 EXPECT_EQ(1u, sink_
->message_count());
1562 const IPC::Message
* msg
= sink_
->GetMessageAt(0);
1563 EXPECT_EQ(ViewMsg_Resize::ID
, msg
->type());
1564 ViewMsg_Resize::Param params
;
1565 ViewMsg_Resize::Read(msg
, ¶ms
);
1566 EXPECT_EQ("0,0 1600x1200",
1568 base::get
<0>(params
).screen_info
.availableRect
).ToString());
1569 EXPECT_EQ("1600x1200", base::get
<0>(params
).new_size
.ToString());
1570 view_
->OnSwapCompositorFrame(
1573 1.f
, base::get
<0>(params
).new_size
,
1574 gfx::Rect(base::get
<0>(params
).new_size
)));
1575 ui::DrawWaiterForTest::WaitForCommit(
1576 root_window
->GetHost()->compositor());
1580 // Swapping a frame should notify the window.
1581 TEST_F(RenderWidgetHostViewAuraTest
, SwapNotifiesWindow
) {
1582 gfx::Size
view_size(100, 100);
1583 gfx::Rect
view_rect(view_size
);
1585 view_
->InitAsChild(NULL
);
1586 aura::client::ParentWindowWithContext(
1587 view_
->GetNativeView(),
1588 parent_view_
->GetNativeView()->GetRootWindow(),
1590 view_
->SetSize(view_size
);
1593 MockWindowObserver observer
;
1594 view_
->window_
->AddObserver(&observer
);
1596 // Delegated renderer path
1597 EXPECT_CALL(observer
, OnDelegatedFrameDamage(view_
->window_
, view_rect
));
1598 view_
->OnSwapCompositorFrame(
1599 0, MakeDelegatedFrame(1.f
, view_size
, view_rect
));
1600 testing::Mock::VerifyAndClearExpectations(&observer
);
1602 EXPECT_CALL(observer
, OnDelegatedFrameDamage(view_
->window_
,
1603 gfx::Rect(5, 5, 5, 5)));
1604 view_
->OnSwapCompositorFrame(
1605 0, MakeDelegatedFrame(1.f
, view_size
, gfx::Rect(5, 5, 5, 5)));
1606 testing::Mock::VerifyAndClearExpectations(&observer
);
1608 view_
->window_
->RemoveObserver(&observer
);
1611 // Recreating the layers for a window should cause Surface destruction to
1612 // depend on both layers.
1613 TEST_F(RenderWidgetHostViewAuraTest
, RecreateLayers
) {
1614 gfx::Size
view_size(100, 100);
1615 gfx::Rect
view_rect(view_size
);
1617 view_
->InitAsChild(NULL
);
1618 aura::client::ParentWindowWithContext(
1619 view_
->GetNativeView(), parent_view_
->GetNativeView()->GetRootWindow(),
1621 view_
->SetSize(view_size
);
1624 view_
->OnSwapCompositorFrame(0,
1625 MakeDelegatedFrame(1.f
, view_size
, view_rect
));
1626 scoped_ptr
<ui::LayerTreeOwner
> cloned_owner(
1627 wm::RecreateLayers(view_
->GetNativeView()));
1629 cc::SurfaceId id
= view_
->GetDelegatedFrameHost()->SurfaceIdForTesting();
1630 if (!id
.is_null()) {
1631 ImageTransportFactory
* factory
= ImageTransportFactory::GetInstance();
1632 cc::SurfaceManager
* manager
= factory
->GetSurfaceManager();
1633 cc::Surface
* surface
= manager
->GetSurfaceForId(id
);
1634 EXPECT_TRUE(surface
);
1635 // Should be a SurfaceSequence for both the original and new layers.
1636 EXPECT_EQ(2u, surface
->GetDestructionDependencyCount());
1640 TEST_F(RenderWidgetHostViewAuraTest
, Resize
) {
1641 gfx::Size
size1(100, 100);
1642 gfx::Size
size2(200, 200);
1643 gfx::Size
size3(300, 300);
1645 aura::Window
* root_window
= parent_view_
->GetNativeView()->GetRootWindow();
1646 view_
->InitAsChild(NULL
);
1647 aura::client::ParentWindowWithContext(
1648 view_
->GetNativeView(), root_window
, gfx::Rect(size1
));
1650 view_
->SetSize(size1
);
1651 view_
->OnSwapCompositorFrame(
1652 0, MakeDelegatedFrame(1.f
, size1
, gfx::Rect(size1
)));
1653 ui::DrawWaiterForTest::WaitForCommit(
1654 root_window
->GetHost()->compositor());
1655 ViewHostMsg_UpdateRect_Params update_params
;
1656 update_params
.view_size
= size1
;
1657 update_params
.flags
= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK
;
1658 widget_host_
->OnMessageReceived(
1659 ViewHostMsg_UpdateRect(widget_host_
->GetRoutingID(), update_params
));
1660 sink_
->ClearMessages();
1661 // Resize logic is idle (no pending resize, no pending commit).
1662 EXPECT_EQ(size1
.ToString(), view_
->GetRequestedRendererSize().ToString());
1664 // Resize renderer, should produce a Resize message
1665 view_
->SetSize(size2
);
1666 EXPECT_EQ(size2
.ToString(), view_
->GetRequestedRendererSize().ToString());
1667 EXPECT_EQ(1u, sink_
->message_count());
1669 const IPC::Message
* msg
= sink_
->GetMessageAt(0);
1670 EXPECT_EQ(ViewMsg_Resize::ID
, msg
->type());
1671 ViewMsg_Resize::Param params
;
1672 ViewMsg_Resize::Read(msg
, ¶ms
);
1673 EXPECT_EQ(size2
.ToString(), base::get
<0>(params
).new_size
.ToString());
1675 // Send resize ack to observe new Resize messages.
1676 update_params
.view_size
= size2
;
1677 widget_host_
->OnMessageReceived(
1678 ViewHostMsg_UpdateRect(widget_host_
->GetRoutingID(), update_params
));
1679 sink_
->ClearMessages();
1681 // Resize renderer again, before receiving a frame. Should not produce a
1683 view_
->SetSize(size3
);
1684 EXPECT_EQ(size2
.ToString(), view_
->GetRequestedRendererSize().ToString());
1685 EXPECT_EQ(0u, sink_
->message_count());
1687 // Receive a frame of the new size, should be skipped and not produce a Resize
1689 view_
->OnSwapCompositorFrame(
1690 0, MakeDelegatedFrame(1.f
, size3
, gfx::Rect(size3
)));
1691 // Expect the frame ack;
1692 EXPECT_EQ(1u, sink_
->message_count());
1693 EXPECT_EQ(ViewMsg_SwapCompositorFrameAck::ID
, sink_
->GetMessageAt(0)->type());
1694 sink_
->ClearMessages();
1695 EXPECT_EQ(size2
.ToString(), view_
->GetRequestedRendererSize().ToString());
1697 // Receive a frame of the correct size, should not be skipped and, and should
1698 // produce a Resize message after the commit.
1699 view_
->OnSwapCompositorFrame(
1700 0, MakeDelegatedFrame(1.f
, size2
, gfx::Rect(size2
)));
1701 cc::SurfaceId surface_id
= view_
->surface_id();
1702 if (surface_id
.is_null()) {
1703 // No frame ack yet.
1704 EXPECT_EQ(0u, sink_
->message_count());
1706 // Frame isn't desired size, so early ack.
1707 EXPECT_EQ(1u, sink_
->message_count());
1709 EXPECT_EQ(size2
.ToString(), view_
->GetRequestedRendererSize().ToString());
1711 // Wait for commit, then we should unlock the compositor and send a Resize
1712 // message (and a frame ack)
1713 ui::DrawWaiterForTest::WaitForCommit(
1714 root_window
->GetHost()->compositor());
1716 bool has_resize
= false;
1717 for (uint32 i
= 0; i
< sink_
->message_count(); ++i
) {
1718 const IPC::Message
* msg
= sink_
->GetMessageAt(i
);
1719 switch (msg
->type()) {
1720 case InputMsg_HandleInputEvent::ID
: {
1721 // On some platforms, the call to view_->Show() causes a posted task to
1723 // ui::WindowEventDispatcher::SynthesizeMouseMoveAfterChangeToWindow,
1724 // which the above WaitForCommit may cause to be picked up. Be robust
1725 // to this extra IPC coming in.
1726 InputMsg_HandleInputEvent::Param params
;
1727 InputMsg_HandleInputEvent::Read(msg
, ¶ms
);
1728 const blink::WebInputEvent
* event
= base::get
<0>(params
);
1729 EXPECT_EQ(blink::WebInputEvent::MouseMove
, event
->type
);
1732 case ViewMsg_SwapCompositorFrameAck::ID
:
1734 case ViewMsg_Resize::ID
: {
1735 EXPECT_FALSE(has_resize
);
1736 ViewMsg_Resize::Param params
;
1737 ViewMsg_Resize::Read(msg
, ¶ms
);
1738 EXPECT_EQ(size3
.ToString(), base::get
<0>(params
).new_size
.ToString());
1743 ADD_FAILURE() << "Unexpected message " << msg
->type();
1747 EXPECT_TRUE(has_resize
);
1748 update_params
.view_size
= size3
;
1749 widget_host_
->OnMessageReceived(
1750 ViewHostMsg_UpdateRect(widget_host_
->GetRoutingID(), update_params
));
1751 sink_
->ClearMessages();
1754 // Skipped frames should not drop their damage.
1755 TEST_F(RenderWidgetHostViewAuraTest
, SkippedDelegatedFrames
) {
1756 gfx::Rect
view_rect(100, 100);
1757 gfx::Size frame_size
= view_rect
.size();
1759 view_
->InitAsChild(NULL
);
1760 aura::client::ParentWindowWithContext(
1761 view_
->GetNativeView(),
1762 parent_view_
->GetNativeView()->GetRootWindow(),
1764 view_
->SetSize(view_rect
.size());
1766 MockWindowObserver observer
;
1767 view_
->window_
->AddObserver(&observer
);
1769 // A full frame of damage.
1770 EXPECT_CALL(observer
, OnDelegatedFrameDamage(view_
->window_
, view_rect
));
1771 view_
->OnSwapCompositorFrame(
1772 0, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1773 testing::Mock::VerifyAndClearExpectations(&observer
);
1774 view_
->RunOnCompositingDidCommit();
1776 // A partial damage frame.
1777 gfx::Rect
partial_view_rect(30, 30, 20, 20);
1778 EXPECT_CALL(observer
,
1779 OnDelegatedFrameDamage(view_
->window_
, partial_view_rect
));
1780 view_
->OnSwapCompositorFrame(
1781 0, MakeDelegatedFrame(1.f
, frame_size
, partial_view_rect
));
1782 testing::Mock::VerifyAndClearExpectations(&observer
);
1783 view_
->RunOnCompositingDidCommit();
1785 // Lock the compositor. Now we should drop frames.
1786 view_rect
= gfx::Rect(150, 150);
1787 view_
->SetSize(view_rect
.size());
1789 // This frame is dropped.
1790 gfx::Rect
dropped_damage_rect_1(10, 20, 30, 40);
1791 EXPECT_CALL(observer
, OnDelegatedFrameDamage(_
, _
)).Times(0);
1792 view_
->OnSwapCompositorFrame(
1793 0, MakeDelegatedFrame(1.f
, frame_size
, dropped_damage_rect_1
));
1794 testing::Mock::VerifyAndClearExpectations(&observer
);
1795 view_
->RunOnCompositingDidCommit();
1797 gfx::Rect
dropped_damage_rect_2(40, 50, 10, 20);
1798 EXPECT_CALL(observer
, OnDelegatedFrameDamage(_
, _
)).Times(0);
1799 view_
->OnSwapCompositorFrame(
1800 0, MakeDelegatedFrame(1.f
, frame_size
, dropped_damage_rect_2
));
1801 testing::Mock::VerifyAndClearExpectations(&observer
);
1802 view_
->RunOnCompositingDidCommit();
1804 // Unlock the compositor. This frame should damage everything.
1805 frame_size
= view_rect
.size();
1807 gfx::Rect
new_damage_rect(5, 6, 10, 10);
1808 EXPECT_CALL(observer
,
1809 OnDelegatedFrameDamage(view_
->window_
, view_rect
));
1810 view_
->OnSwapCompositorFrame(
1811 0, MakeDelegatedFrame(1.f
, frame_size
, new_damage_rect
));
1812 testing::Mock::VerifyAndClearExpectations(&observer
);
1813 view_
->RunOnCompositingDidCommit();
1815 // A partial damage frame, this should not be dropped.
1816 EXPECT_CALL(observer
,
1817 OnDelegatedFrameDamage(view_
->window_
, partial_view_rect
));
1818 view_
->OnSwapCompositorFrame(
1819 0, MakeDelegatedFrame(1.f
, frame_size
, partial_view_rect
));
1820 testing::Mock::VerifyAndClearExpectations(&observer
);
1821 view_
->RunOnCompositingDidCommit();
1824 // Resize to something empty.
1825 view_rect
= gfx::Rect(100, 0);
1826 view_
->SetSize(view_rect
.size());
1828 // We're never expecting empty frames, resize to something non-empty.
1829 view_rect
= gfx::Rect(100, 100);
1830 view_
->SetSize(view_rect
.size());
1832 // This frame should not be dropped.
1833 EXPECT_CALL(observer
, OnDelegatedFrameDamage(view_
->window_
, view_rect
));
1834 view_
->OnSwapCompositorFrame(
1835 0, MakeDelegatedFrame(1.f
, view_rect
.size(), view_rect
));
1836 testing::Mock::VerifyAndClearExpectations(&observer
);
1837 view_
->RunOnCompositingDidCommit();
1839 view_
->window_
->RemoveObserver(&observer
);
1842 TEST_F(RenderWidgetHostViewAuraTest
, OutputSurfaceIdChange
) {
1843 gfx::Rect
view_rect(100, 100);
1844 gfx::Size frame_size
= view_rect
.size();
1846 view_
->InitAsChild(NULL
);
1847 aura::client::ParentWindowWithContext(
1848 view_
->GetNativeView(),
1849 parent_view_
->GetNativeView()->GetRootWindow(),
1851 view_
->SetSize(view_rect
.size());
1853 MockWindowObserver observer
;
1854 view_
->window_
->AddObserver(&observer
);
1857 EXPECT_CALL(observer
, OnDelegatedFrameDamage(view_
->window_
, view_rect
));
1858 view_
->OnSwapCompositorFrame(
1859 0, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1860 testing::Mock::VerifyAndClearExpectations(&observer
);
1861 view_
->RunOnCompositingDidCommit();
1863 // Swap a frame with a different surface id.
1864 EXPECT_CALL(observer
, OnDelegatedFrameDamage(view_
->window_
, view_rect
));
1865 view_
->OnSwapCompositorFrame(
1866 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1867 testing::Mock::VerifyAndClearExpectations(&observer
);
1868 view_
->RunOnCompositingDidCommit();
1870 // Swap an empty frame, with a different surface id.
1871 view_
->OnSwapCompositorFrame(
1872 2, MakeDelegatedFrame(1.f
, gfx::Size(), gfx::Rect()));
1873 testing::Mock::VerifyAndClearExpectations(&observer
);
1874 view_
->RunOnCompositingDidCommit();
1876 // Swap another frame, with a different surface id.
1877 EXPECT_CALL(observer
, OnDelegatedFrameDamage(view_
->window_
, view_rect
));
1878 view_
->OnSwapCompositorFrame(3,
1879 MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1880 testing::Mock::VerifyAndClearExpectations(&observer
);
1881 view_
->RunOnCompositingDidCommit();
1883 view_
->window_
->RemoveObserver(&observer
);
1886 TEST_F(RenderWidgetHostViewAuraTest
, DiscardDelegatedFrames
) {
1887 view_
->InitAsChild(NULL
);
1889 size_t max_renderer_frames
=
1890 RendererFrameManager::GetInstance()->GetMaxNumberOfSavedFrames();
1891 ASSERT_LE(2u, max_renderer_frames
);
1892 size_t renderer_count
= max_renderer_frames
+ 1;
1893 gfx::Rect
view_rect(100, 100);
1894 gfx::Size frame_size
= view_rect
.size();
1895 DCHECK_EQ(0u, HostSharedBitmapManager::current()->AllocatedBitmapCount());
1897 scoped_ptr
<RenderWidgetHostImpl
* []> hosts(
1898 new RenderWidgetHostImpl
* [renderer_count
]);
1899 scoped_ptr
<FakeRenderWidgetHostViewAura
* []> views(
1900 new FakeRenderWidgetHostViewAura
* [renderer_count
]);
1902 // Create a bunch of renderers.
1903 for (size_t i
= 0; i
< renderer_count
; ++i
) {
1904 hosts
[i
] = new RenderWidgetHostImpl(
1905 &delegate_
, process_host_
, MSG_ROUTING_NONE
, false);
1907 views
[i
] = new FakeRenderWidgetHostViewAura(hosts
[i
], false);
1908 views
[i
]->InitAsChild(NULL
);
1909 aura::client::ParentWindowWithContext(
1910 views
[i
]->GetNativeView(),
1911 parent_view_
->GetNativeView()->GetRootWindow(),
1913 views
[i
]->SetSize(view_rect
.size());
1916 // Make each renderer visible, and swap a frame on it, then make it invisible.
1917 for (size_t i
= 0; i
< renderer_count
; ++i
) {
1919 views
[i
]->OnSwapCompositorFrame(
1920 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1921 EXPECT_TRUE(views
[i
]->HasFrameData());
1925 // There should be max_renderer_frames with a frame in it, and one without it.
1926 // Since the logic is LRU eviction, the first one should be without.
1927 EXPECT_FALSE(views
[0]->HasFrameData());
1928 for (size_t i
= 1; i
< renderer_count
; ++i
)
1929 EXPECT_TRUE(views
[i
]->HasFrameData());
1931 // LRU renderer is [0], make it visible, it shouldn't evict anything yet.
1933 EXPECT_FALSE(views
[0]->HasFrameData());
1934 EXPECT_TRUE(views
[1]->HasFrameData());
1935 // Since [0] doesn't have a frame, it should be waiting for the renderer to
1937 EXPECT_TRUE(views
[0]->released_front_lock_active());
1939 // Swap a frame on it, it should evict the next LRU [1].
1940 views
[0]->OnSwapCompositorFrame(
1941 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1942 EXPECT_TRUE(views
[0]->HasFrameData());
1943 EXPECT_FALSE(views
[1]->HasFrameData());
1944 // Now that [0] got a frame, it shouldn't be waiting any more.
1945 EXPECT_FALSE(views
[0]->released_front_lock_active());
1948 // LRU renderer is [1], still hidden. Swap a frame on it, it should evict
1949 // the next LRU [2].
1950 views
[1]->OnSwapCompositorFrame(
1951 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1952 EXPECT_TRUE(views
[0]->HasFrameData());
1953 EXPECT_TRUE(views
[1]->HasFrameData());
1954 EXPECT_FALSE(views
[2]->HasFrameData());
1955 for (size_t i
= 3; i
< renderer_count
; ++i
)
1956 EXPECT_TRUE(views
[i
]->HasFrameData());
1958 // Make all renderers but [0] visible and swap a frame on them, keep [0]
1959 // hidden, it becomes the LRU.
1960 for (size_t i
= 1; i
< renderer_count
; ++i
) {
1962 // The renderers who don't have a frame should be waiting. The ones that
1963 // have a frame should not.
1964 // In practice, [1] has a frame, but anything after has its frame evicted.
1965 EXPECT_EQ(!views
[i
]->HasFrameData(),
1966 views
[i
]->released_front_lock_active());
1967 views
[i
]->OnSwapCompositorFrame(
1968 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1969 // Now everyone has a frame.
1970 EXPECT_FALSE(views
[i
]->released_front_lock_active());
1971 EXPECT_TRUE(views
[i
]->HasFrameData());
1973 EXPECT_FALSE(views
[0]->HasFrameData());
1975 // Swap a frame on [0], it should be evicted immediately.
1976 views
[0]->OnSwapCompositorFrame(
1977 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1978 EXPECT_FALSE(views
[0]->HasFrameData());
1980 // Make [0] visible, and swap a frame on it. Nothing should be evicted
1981 // although we're above the limit.
1983 // We don't have a frame, wait.
1984 EXPECT_TRUE(views
[0]->released_front_lock_active());
1985 views
[0]->OnSwapCompositorFrame(
1986 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1987 EXPECT_FALSE(views
[0]->released_front_lock_active());
1988 for (size_t i
= 0; i
< renderer_count
; ++i
)
1989 EXPECT_TRUE(views
[i
]->HasFrameData());
1991 // Make [0] hidden, it should evict its frame.
1993 EXPECT_FALSE(views
[0]->HasFrameData());
1995 // Make [0] visible, don't give it a frame, it should be waiting.
1997 EXPECT_TRUE(views
[0]->released_front_lock_active());
1998 // Make [0] hidden, it should stop waiting.
2000 EXPECT_FALSE(views
[0]->released_front_lock_active());
2002 // Make [1] hidden, resize it. It should drop its frame.
2004 EXPECT_TRUE(views
[1]->HasFrameData());
2005 gfx::Size
size2(200, 200);
2006 views
[1]->SetSize(size2
);
2007 EXPECT_FALSE(views
[1]->HasFrameData());
2008 // Show it, it should block until we give it a frame.
2010 EXPECT_TRUE(views
[1]->released_front_lock_active());
2011 views
[1]->OnSwapCompositorFrame(
2012 1, MakeDelegatedFrame(1.f
, size2
, gfx::Rect(size2
)));
2013 EXPECT_FALSE(views
[1]->released_front_lock_active());
2015 for (size_t i
= 0; i
< renderer_count
- 1; ++i
)
2018 // Allocate enough bitmaps so that two frames (proportionally) would be
2019 // enough hit the handle limit.
2020 int handles_per_frame
= 5;
2021 RendererFrameManager::GetInstance()->set_max_handles(handles_per_frame
* 2);
2023 HostSharedBitmapManagerClient
bitmap_client(
2024 HostSharedBitmapManager::current());
2026 for (size_t i
= 0; i
< (renderer_count
- 1) * handles_per_frame
; i
++) {
2027 bitmap_client
.ChildAllocatedSharedBitmap(
2028 1, base::SharedMemory::NULLHandle(), base::GetCurrentProcessHandle(),
2029 cc::SharedBitmap::GenerateId());
2032 // Hiding this last bitmap should evict all but two frames.
2033 views
[renderer_count
- 1]->Hide();
2034 for (size_t i
= 0; i
< renderer_count
; ++i
) {
2035 if (i
+ 2 < renderer_count
)
2036 EXPECT_FALSE(views
[i
]->HasFrameData());
2038 EXPECT_TRUE(views
[i
]->HasFrameData());
2040 RendererFrameManager::GetInstance()->set_max_handles(
2041 base::SharedMemory::GetHandleLimit());
2043 for (size_t i
= 0; i
< renderer_count
; ++i
) {
2044 views
[i
]->Destroy();
2049 TEST_F(RenderWidgetHostViewAuraTest
, DiscardDelegatedFramesWithLocking
) {
2050 view_
->InitAsChild(NULL
);
2052 size_t max_renderer_frames
=
2053 RendererFrameManager::GetInstance()->GetMaxNumberOfSavedFrames();
2054 ASSERT_LE(2u, max_renderer_frames
);
2055 size_t renderer_count
= max_renderer_frames
+ 1;
2056 gfx::Rect
view_rect(100, 100);
2057 gfx::Size frame_size
= view_rect
.size();
2058 DCHECK_EQ(0u, HostSharedBitmapManager::current()->AllocatedBitmapCount());
2060 scoped_ptr
<RenderWidgetHostImpl
* []> hosts(
2061 new RenderWidgetHostImpl
* [renderer_count
]);
2062 scoped_ptr
<FakeRenderWidgetHostViewAura
* []> views(
2063 new FakeRenderWidgetHostViewAura
* [renderer_count
]);
2065 // Create a bunch of renderers.
2066 for (size_t i
= 0; i
< renderer_count
; ++i
) {
2067 hosts
[i
] = new RenderWidgetHostImpl(
2068 &delegate_
, process_host_
, MSG_ROUTING_NONE
, false);
2070 views
[i
] = new FakeRenderWidgetHostViewAura(hosts
[i
], false);
2071 views
[i
]->InitAsChild(NULL
);
2072 aura::client::ParentWindowWithContext(
2073 views
[i
]->GetNativeView(),
2074 parent_view_
->GetNativeView()->GetRootWindow(),
2076 views
[i
]->SetSize(view_rect
.size());
2079 // Make each renderer visible and swap a frame on it. No eviction should
2080 // occur because all frames are visible.
2081 for (size_t i
= 0; i
< renderer_count
; ++i
) {
2083 views
[i
]->OnSwapCompositorFrame(
2084 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
2085 EXPECT_TRUE(views
[i
]->HasFrameData());
2088 // If we hide [0], then [0] should be evicted.
2090 EXPECT_FALSE(views
[0]->HasFrameData());
2092 // If we lock [0] before hiding it, then [0] should not be evicted.
2094 views
[0]->OnSwapCompositorFrame(
2095 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
2096 EXPECT_TRUE(views
[0]->HasFrameData());
2097 views
[0]->GetDelegatedFrameHost()->LockResources();
2099 EXPECT_TRUE(views
[0]->HasFrameData());
2101 // If we unlock [0] now, then [0] should be evicted.
2102 views
[0]->GetDelegatedFrameHost()->UnlockResources();
2103 EXPECT_FALSE(views
[0]->HasFrameData());
2105 for (size_t i
= 0; i
< renderer_count
; ++i
) {
2106 views
[i
]->Destroy();
2111 // Test that changing the memory pressure should delete saved frames. This test
2112 // only applies to ChromeOS.
2113 TEST_F(RenderWidgetHostViewAuraTest
, DiscardDelegatedFramesWithMemoryPressure
) {
2114 view_
->InitAsChild(NULL
);
2116 // The test logic below relies on having max_renderer_frames > 2. By default,
2117 // this value is calculated from total physical memory and causes the test to
2118 // fail when run on hardware with < 256MB of RAM.
2119 const size_t kMaxRendererFrames
= 5;
2120 RendererFrameManager::GetInstance()->set_max_number_of_saved_frames(
2121 kMaxRendererFrames
);
2123 size_t renderer_count
= kMaxRendererFrames
;
2124 gfx::Rect
view_rect(100, 100);
2125 gfx::Size frame_size
= view_rect
.size();
2126 DCHECK_EQ(0u, HostSharedBitmapManager::current()->AllocatedBitmapCount());
2128 scoped_ptr
<RenderWidgetHostImpl
* []> hosts(
2129 new RenderWidgetHostImpl
* [renderer_count
]);
2130 scoped_ptr
<FakeRenderWidgetHostViewAura
* []> views(
2131 new FakeRenderWidgetHostViewAura
* [renderer_count
]);
2133 // Create a bunch of renderers.
2134 for (size_t i
= 0; i
< renderer_count
; ++i
) {
2135 hosts
[i
] = new RenderWidgetHostImpl(
2136 &delegate_
, process_host_
, MSG_ROUTING_NONE
, false);
2138 views
[i
] = new FakeRenderWidgetHostViewAura(hosts
[i
], false);
2139 views
[i
]->InitAsChild(NULL
);
2140 aura::client::ParentWindowWithContext(
2141 views
[i
]->GetNativeView(),
2142 parent_view_
->GetNativeView()->GetRootWindow(),
2144 views
[i
]->SetSize(view_rect
.size());
2147 // Make each renderer visible and swap a frame on it. No eviction should
2148 // occur because all frames are visible.
2149 for (size_t i
= 0; i
< renderer_count
; ++i
) {
2151 views
[i
]->OnSwapCompositorFrame(
2152 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
2153 EXPECT_TRUE(views
[i
]->HasFrameData());
2156 // If we hide one, it should not get evicted.
2158 message_loop_
.RunUntilIdle();
2159 EXPECT_TRUE(views
[0]->HasFrameData());
2160 // Using a lesser memory pressure event however, should evict.
2161 SimulateMemoryPressure(
2162 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE
);
2163 message_loop_
.RunUntilIdle();
2164 EXPECT_FALSE(views
[0]->HasFrameData());
2166 // Check the same for a higher pressure event.
2168 message_loop_
.RunUntilIdle();
2169 EXPECT_TRUE(views
[1]->HasFrameData());
2170 SimulateMemoryPressure(
2171 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL
);
2172 message_loop_
.RunUntilIdle();
2173 EXPECT_FALSE(views
[1]->HasFrameData());
2175 for (size_t i
= 0; i
< renderer_count
; ++i
) {
2176 views
[i
]->Destroy();
2181 TEST_F(RenderWidgetHostViewAuraTest
, SoftwareDPIChange
) {
2182 gfx::Rect
view_rect(100, 100);
2183 gfx::Size
frame_size(100, 100);
2185 view_
->InitAsChild(NULL
);
2186 aura::client::ParentWindowWithContext(
2187 view_
->GetNativeView(),
2188 parent_view_
->GetNativeView()->GetRootWindow(),
2190 view_
->SetSize(view_rect
.size());
2193 // With a 1x DPI UI and 1x DPI Renderer.
2194 view_
->OnSwapCompositorFrame(
2195 1, MakeDelegatedFrame(1.f
, frame_size
, gfx::Rect(frame_size
)));
2197 // Save the frame provider.
2198 scoped_refptr
<cc::DelegatedFrameProvider
> frame_provider
=
2199 view_
->frame_provider();
2200 cc::SurfaceId surface_id
= view_
->surface_id();
2202 // This frame will have the same number of physical pixels, but has a new
2204 view_
->OnSwapCompositorFrame(
2205 1, MakeDelegatedFrame(2.f
, frame_size
, gfx::Rect(frame_size
)));
2207 // When we get a new frame with the same frame size in physical pixels, but a
2208 // different scale, we should generate a new frame provider, as the final
2209 // result will need to be scaled differently to the screen.
2210 if (frame_provider
.get())
2211 EXPECT_NE(frame_provider
.get(), view_
->frame_provider());
2213 EXPECT_NE(surface_id
, view_
->surface_id());
2216 class RenderWidgetHostViewAuraCopyRequestTest
2217 : public RenderWidgetHostViewAuraShutdownTest
{
2219 RenderWidgetHostViewAuraCopyRequestTest()
2220 : callback_count_(0),
2222 frame_subscriber_(nullptr),
2223 tick_clock_(nullptr),
2224 view_rect_(100, 100) {}
2226 void CallbackMethod(bool result
) {
2229 quit_closure_
.Run();
2232 void RunLoopUntilCallback() {
2233 base::RunLoop run_loop
;
2234 quit_closure_
= run_loop
.QuitClosure();
2238 void InitializeView() {
2239 view_
->InitAsChild(NULL
);
2240 view_
->GetDelegatedFrameHost()->SetRequestCopyOfOutputCallbackForTesting(
2241 base::Bind(&FakeRenderWidgetHostViewAura::InterceptCopyOfOutput
,
2242 base::Unretained(view_
)));
2243 aura::client::ParentWindowWithContext(
2244 view_
->GetNativeView(), parent_view_
->GetNativeView()->GetRootWindow(),
2246 view_
->SetSize(view_rect_
.size());
2249 frame_subscriber_
= new FakeFrameSubscriber(
2251 base::Bind(&RenderWidgetHostViewAuraCopyRequestTest::CallbackMethod
,
2252 base::Unretained(this)));
2253 view_
->BeginFrameSubscription(make_scoped_ptr(frame_subscriber_
));
2254 ASSERT_EQ(0, callback_count_
);
2255 ASSERT_FALSE(view_
->last_copy_request_
);
2258 void InstallFakeTickClock() {
2259 // Create a fake tick clock and transfer ownership to the frame host.
2260 tick_clock_
= new base::SimpleTestTickClock();
2261 view_
->GetDelegatedFrameHost()->tick_clock_
= make_scoped_ptr(tick_clock_
);
2264 void OnSwapCompositorFrame() {
2265 view_
->OnSwapCompositorFrame(
2266 1, MakeDelegatedFrame(1.f
, view_rect_
.size(), view_rect_
));
2267 ASSERT_TRUE(view_
->last_copy_request_
);
2270 void ReleaseSwappedFrame() {
2271 scoped_ptr
<cc::CopyOutputRequest
> request
=
2272 view_
->last_copy_request_
.Pass();
2273 request
->SendTextureResult(view_rect_
.size(), request
->texture_mailbox(),
2274 scoped_ptr
<cc::SingleReleaseCallback
>());
2275 RunLoopUntilCallback();
2278 void OnSwapCompositorFrameAndRelease() {
2279 OnSwapCompositorFrame();
2280 ReleaseSwappedFrame();
2283 void RunOnCompositingDidCommitAndReleaseFrame() {
2284 view_
->RunOnCompositingDidCommit();
2285 ReleaseSwappedFrame();
2288 void OnUpdateVSyncParameters(base::TimeTicks timebase
,
2289 base::TimeDelta interval
) {
2290 view_
->GetDelegatedFrameHost()->OnUpdateVSyncParameters(timebase
, interval
);
2293 base::TimeTicks
vsync_timebase() {
2294 return view_
->GetDelegatedFrameHost()->vsync_timebase_
;
2297 base::TimeDelta
vsync_interval() {
2298 return view_
->GetDelegatedFrameHost()->vsync_interval_
;
2301 int callback_count_
;
2303 FakeFrameSubscriber
* frame_subscriber_
; // Owned by |view_|.
2304 base::SimpleTestTickClock
* tick_clock_
; // Owned by DelegatedFrameHost.
2305 const gfx::Rect view_rect_
;
2308 base::Closure quit_closure_
;
2310 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraCopyRequestTest
);
2313 // Tests that only one copy/readback request will be executed per one browser
2314 // composite operation, even when multiple render frame swaps occur in between
2315 // browser composites, and even if the frame subscriber desires more frames than
2316 // the number of browser composites.
2317 TEST_F(RenderWidgetHostViewAuraCopyRequestTest
, DedupeFrameSubscriberRequests
) {
2319 int expected_callback_count
= 0;
2321 // Normal case: A browser composite executes for each render frame swap.
2322 for (int i
= 0; i
< 3; ++i
) {
2323 // Renderer provides another frame and the Browser composites with the
2324 // frame, executing the copy request, and then the result is delivered.
2325 OnSwapCompositorFrame();
2326 RunOnCompositingDidCommitAndReleaseFrame();
2328 // The callback should be run with success status.
2329 ++expected_callback_count
;
2330 ASSERT_EQ(expected_callback_count
, callback_count_
);
2331 EXPECT_TRUE(result_
);
2334 // De-duping case: One browser composite executes per varied number of render
2336 for (int i
= 0; i
< 3; ++i
) {
2337 const int num_swaps
= 1 + i
% 3;
2339 // The renderer provides |num_swaps| frames.
2340 for (int j
= 0; j
< num_swaps
; ++j
) {
2341 OnSwapCompositorFrame();
2343 ++expected_callback_count
;
2344 ASSERT_EQ(expected_callback_count
, callback_count_
);
2345 EXPECT_FALSE(result_
); // The prior copy request was aborted.
2349 // Browser composites with the frame, executing the last copy request that
2350 // was made, and then the result is delivered.
2351 RunOnCompositingDidCommitAndReleaseFrame();
2353 // The final callback should be run with success status.
2354 ++expected_callback_count
;
2355 ASSERT_EQ(expected_callback_count
, callback_count_
);
2356 EXPECT_TRUE(result_
);
2359 // Destroy the RenderWidgetHostViewAura and ImageTransportFactory.
2360 TearDownEnvironment();
2363 TEST_F(RenderWidgetHostViewAuraCopyRequestTest
, DestroyedAfterCopyRequest
) {
2366 OnSwapCompositorFrame();
2367 EXPECT_EQ(0, callback_count_
);
2368 EXPECT_TRUE(view_
->last_copy_request_
);
2369 EXPECT_TRUE(view_
->last_copy_request_
->has_texture_mailbox());
2371 // Notify DelegatedFrameHost that the copy requests were moved to the
2372 // compositor thread by calling OnCompositingDidCommit().
2374 // Send back the mailbox included in the request. There's no release callback
2375 // since the mailbox came from the RWHVA originally.
2376 RunOnCompositingDidCommitAndReleaseFrame();
2378 // The callback should succeed.
2379 EXPECT_EQ(1, callback_count_
);
2380 EXPECT_TRUE(result_
);
2382 OnSwapCompositorFrame();
2383 EXPECT_EQ(1, callback_count_
);
2384 scoped_ptr
<cc::CopyOutputRequest
> request
= view_
->last_copy_request_
.Pass();
2386 // Destroy the RenderWidgetHostViewAura and ImageTransportFactory.
2387 TearDownEnvironment();
2389 // Send the result after-the-fact. It goes nowhere since DelegatedFrameHost
2390 // has been destroyed.
2391 request
->SendTextureResult(view_rect_
.size(), request
->texture_mailbox(),
2392 scoped_ptr
<cc::SingleReleaseCallback
>());
2394 // Because the copy request callback may be holding state within it, that
2395 // state must handle the RWHVA and ImageTransportFactory going away before the
2396 // callback is called. This test passes if it does not crash as a result of
2397 // these things being destroyed.
2398 EXPECT_EQ(2, callback_count_
);
2399 EXPECT_FALSE(result_
);
2402 TEST_F(RenderWidgetHostViewAuraCopyRequestTest
, PresentTime
) {
2404 InstallFakeTickClock();
2406 // Verify our initial state.
2407 EXPECT_EQ(base::TimeTicks(), frame_subscriber_
->last_present_time());
2408 EXPECT_EQ(base::TimeTicks(), tick_clock_
->NowTicks());
2410 // Start our fake clock from a non-zero, but not an even multiple of the
2411 // interval, value to differentiate it from our initialization state.
2412 const base::TimeDelta kDefaultInterval
=
2413 cc::BeginFrameArgs::DefaultInterval();
2414 tick_clock_
->Advance(kDefaultInterval
/ 3);
2416 // Swap the first frame without any vsync information.
2417 ASSERT_EQ(base::TimeTicks(), vsync_timebase());
2418 ASSERT_EQ(base::TimeDelta(), vsync_interval());
2420 // During this first call, there is no known vsync information, so while the
2421 // callback should succeed the present time is effectively just current time.
2422 OnSwapCompositorFrameAndRelease();
2423 EXPECT_EQ(tick_clock_
->NowTicks(), frame_subscriber_
->last_present_time());
2425 // Now initialize the vsync parameters with a null timebase, but a known vsync
2426 // interval; which should give us slightly better frame time estimates.
2427 OnUpdateVSyncParameters(base::TimeTicks(), kDefaultInterval
);
2428 ASSERT_EQ(base::TimeTicks(), vsync_timebase());
2429 ASSERT_EQ(kDefaultInterval
, vsync_interval());
2431 // Now that we have a vsync interval, the presentation time estimate should be
2432 // the nearest presentation interval, which is just kDefaultInterval since our
2433 // tick clock is initialized to a time before that.
2434 OnSwapCompositorFrameAndRelease();
2435 EXPECT_EQ(base::TimeTicks() + kDefaultInterval
,
2436 frame_subscriber_
->last_present_time());
2438 // Now initialize the vsync parameters with a valid timebase and a known vsync
2439 // interval; which should give us the best frame time estimates.
2440 const base::TimeTicks kBaseTime
= tick_clock_
->NowTicks();
2441 OnUpdateVSyncParameters(kBaseTime
, kDefaultInterval
);
2442 ASSERT_EQ(kBaseTime
, vsync_timebase());
2443 ASSERT_EQ(kDefaultInterval
, vsync_interval());
2445 // Now that we have a vsync interval and a timebase, the presentation time
2446 // should be based on the number of vsync intervals which have elapsed since
2447 // the vsync timebase. Advance time by a non integer number of intervals to
2449 const double kElapsedIntervals
= 2.5;
2450 tick_clock_
->Advance(kDefaultInterval
* kElapsedIntervals
);
2451 OnSwapCompositorFrameAndRelease();
2452 EXPECT_EQ(kBaseTime
+ kDefaultInterval
* std::ceil(kElapsedIntervals
),
2453 frame_subscriber_
->last_present_time());
2455 // Destroy the RenderWidgetHostViewAura and ImageTransportFactory.
2456 TearDownEnvironment();
2459 TEST_F(RenderWidgetHostViewAuraTest
, VisibleViewportTest
) {
2460 gfx::Rect
view_rect(100, 100);
2462 view_
->InitAsChild(NULL
);
2463 aura::client::ParentWindowWithContext(
2464 view_
->GetNativeView(),
2465 parent_view_
->GetNativeView()->GetRootWindow(),
2467 view_
->SetSize(view_rect
.size());
2470 // Defaults to full height of the view.
2471 EXPECT_EQ(100, view_
->GetVisibleViewportSize().height());
2473 widget_host_
->ResetSizeAndRepaintPendingFlags();
2474 sink_
->ClearMessages();
2475 view_
->SetInsets(gfx::Insets(0, 0, 40, 0));
2477 EXPECT_EQ(60, view_
->GetVisibleViewportSize().height());
2479 const IPC::Message
*message
= sink_
->GetFirstMessageMatching(
2480 ViewMsg_Resize::ID
);
2481 ASSERT_TRUE(message
!= NULL
);
2483 ViewMsg_Resize::Param params
;
2484 ViewMsg_Resize::Read(message
, ¶ms
);
2485 EXPECT_EQ(60, base::get
<0>(params
).visible_viewport_size
.height());
2488 // Ensures that touch event positions are never truncated to integers.
2489 TEST_F(RenderWidgetHostViewAuraTest
, TouchEventPositionsArentRounded
) {
2490 const float kX
= 30.58f
;
2491 const float kY
= 50.23f
;
2493 view_
->InitAsChild(NULL
);
2496 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
,
2497 gfx::PointF(kX
, kY
),
2499 ui::EventTimeForNow());
2501 view_
->OnTouchEvent(&press
);
2502 EXPECT_EQ(ui::MotionEvent::ACTION_DOWN
, pointer_state().GetAction());
2503 EXPECT_EQ(1U, pointer_state().GetPointerCount());
2504 EXPECT_EQ(kX
, pointer_state().GetX(0));
2505 EXPECT_EQ(kY
, pointer_state().GetY(0));
2508 // Tests that scroll ACKs are correctly handled by the overscroll-navigation
2510 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, WheelScrollEventOverscrolls
) {
2511 SetUpOverscrollEnvironment();
2513 // Simulate wheel events.
2514 SimulateWheelEvent(-5, 0, 0, true); // sent directly
2515 SimulateWheelEvent(-1, 1, 0, true); // enqueued
2516 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
2517 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
2518 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
2519 SimulateWheelEvent(-20, 6, 1, true); // enqueued, different modifiers
2520 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2521 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2523 // Receive ACK the first wheel event as not processed.
2524 SendInputEventACK(WebInputEvent::MouseWheel
,
2525 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2526 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2527 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2528 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2530 // Receive ACK for the second (coalesced) event as not processed. This will
2531 // start a back navigation. However, this will also cause the queued next
2532 // event to be sent to the renderer. But since overscroll navigation has
2533 // started, that event will also be included in the overscroll computation
2534 // instead of being sent to the renderer. So the result will be an overscroll
2535 // back navigation, and no event will be sent to the renderer.
2536 SendInputEventACK(WebInputEvent::MouseWheel
,
2537 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2538 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_mode());
2539 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_delegate()->current_mode());
2540 EXPECT_EQ(-81.f
, overscroll_delta_x());
2541 EXPECT_EQ(-31.f
, overscroll_delegate()->delta_x());
2542 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2543 EXPECT_EQ(0U, sink_
->message_count());
2545 // Send a mouse-move event. This should cancel the overscroll navigation.
2546 SimulateMouseMove(5, 10, 0);
2547 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2548 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2549 EXPECT_EQ(1U, sink_
->message_count());
2552 // Tests that if some scroll events are consumed towards the start, then
2553 // subsequent scrolls do not horizontal overscroll.
2554 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
2555 WheelScrollConsumedDoNotHorizOverscroll
) {
2556 SetUpOverscrollEnvironment();
2558 // Simulate wheel events.
2559 SimulateWheelEvent(-5, 0, 0, true); // sent directly
2560 SimulateWheelEvent(-1, -1, 0, true); // enqueued
2561 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
2562 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
2563 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
2564 SimulateWheelEvent(-20, 6, 1, true); // enqueued, different modifiers
2565 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2566 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2568 // Receive ACK the first wheel event as processed.
2569 SendInputEventACK(WebInputEvent::MouseWheel
, INPUT_EVENT_ACK_STATE_CONSUMED
);
2570 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2571 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2572 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2574 // Receive ACK for the second (coalesced) event as not processed. This should
2575 // not initiate overscroll, since the beginning of the scroll has been
2576 // consumed. The queued event with different modifiers should be sent to the
2578 SendInputEventACK(WebInputEvent::MouseWheel
,
2579 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2580 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2581 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2583 SendInputEventACK(WebInputEvent::MouseWheel
,
2584 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2585 EXPECT_EQ(0U, sink_
->message_count());
2586 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2588 // Indicate the end of the scrolling from the touchpad.
2589 SimulateGestureFlingStartEvent(-1200.f
, 0.f
, blink::WebGestureDeviceTouchpad
);
2590 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2592 // Start another scroll. This time, do not consume any scroll events.
2593 SimulateWheelEvent(0, -5, 0, true); // sent directly
2594 SimulateWheelEvent(0, -1, 0, true); // enqueued
2595 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
2596 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
2597 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
2598 SimulateWheelEvent(-20, 6, 1, true); // enqueued, different modifiers
2599 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2600 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2602 // Receive ACK for the first wheel and the subsequent coalesced event as not
2603 // processed. This should start a back-overscroll.
2604 SendInputEventACK(WebInputEvent::MouseWheel
,
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());
2609 SendInputEventACK(WebInputEvent::MouseWheel
,
2610 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2611 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_mode());
2614 // Tests that wheel-scrolling correctly turns overscroll on and off.
2615 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, WheelScrollOverscrollToggle
) {
2616 SetUpOverscrollEnvironment();
2618 // Send a wheel event. ACK the event as not processed. This should not
2619 // initiate an overscroll gesture since it doesn't cross the threshold yet.
2620 SimulateWheelEvent(10, 0, 0, true);
2621 SendInputEventACK(WebInputEvent::MouseWheel
,
2622 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2623 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2624 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2625 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2627 // Scroll some more so as to not overscroll.
2628 SimulateWheelEvent(10, 0, 0, true);
2629 SendInputEventACK(WebInputEvent::MouseWheel
,
2630 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2631 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2632 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2633 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2635 // Scroll some more to initiate an overscroll.
2636 SimulateWheelEvent(40, 0, 0, true);
2637 SendInputEventACK(WebInputEvent::MouseWheel
,
2638 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2639 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2640 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2641 EXPECT_EQ(60.f
, overscroll_delta_x());
2642 EXPECT_EQ(10.f
, overscroll_delegate()->delta_x());
2643 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2644 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2646 // Scroll in the reverse direction enough to abort the overscroll.
2647 SimulateWheelEvent(-20, 0, 0, true);
2648 EXPECT_EQ(0U, sink_
->message_count());
2649 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2650 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2652 // Continue to scroll in the reverse direction.
2653 SimulateWheelEvent(-20, 0, 0, true);
2654 SendInputEventACK(WebInputEvent::MouseWheel
,
2655 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2656 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2657 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2658 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2660 // Continue to scroll in the reverse direction enough to initiate overscroll
2661 // in that direction.
2662 SimulateWheelEvent(-55, 0, 0, true);
2663 EXPECT_EQ(1U, sink_
->message_count());
2664 SendInputEventACK(WebInputEvent::MouseWheel
,
2665 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2666 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_mode());
2667 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_delegate()->current_mode());
2668 EXPECT_EQ(-75.f
, overscroll_delta_x());
2669 EXPECT_EQ(-25.f
, overscroll_delegate()->delta_x());
2670 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2673 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
2674 ScrollEventsOverscrollWithFling
) {
2675 SetUpOverscrollEnvironment();
2677 // Send a wheel event. ACK the event as not processed. This should not
2678 // initiate an overscroll gesture since it doesn't cross the threshold yet.
2679 SimulateWheelEvent(10, 0, 0, true);
2680 SendInputEventACK(WebInputEvent::MouseWheel
,
2681 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2682 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2683 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2684 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2686 // Scroll some more so as to not overscroll.
2687 SimulateWheelEvent(20, 0, 0, true);
2688 EXPECT_EQ(1U, sink_
->message_count());
2689 SendInputEventACK(WebInputEvent::MouseWheel
,
2690 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2691 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2692 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2693 sink_
->ClearMessages();
2695 // Scroll some more to initiate an overscroll.
2696 SimulateWheelEvent(30, 0, 0, true);
2697 SendInputEventACK(WebInputEvent::MouseWheel
,
2698 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2699 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2700 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2701 EXPECT_EQ(60.f
, overscroll_delta_x());
2702 EXPECT_EQ(10.f
, overscroll_delegate()->delta_x());
2703 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2704 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2706 // Send a fling start, but with a small velocity, so that the overscroll is
2707 // aborted. The fling should proceed to the renderer, through the gesture
2709 SimulateGestureFlingStartEvent(0.f
, 0.1f
, blink::WebGestureDeviceTouchpad
);
2710 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2711 EXPECT_EQ(1U, sink_
->message_count());
2714 // Same as ScrollEventsOverscrollWithFling, but with zero velocity. Checks that
2715 // the zero-velocity fling does not reach the renderer.
2716 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
2717 ScrollEventsOverscrollWithZeroFling
) {
2718 SetUpOverscrollEnvironment();
2720 // Send a wheel event. ACK the event as not processed. This should not
2721 // initiate an overscroll gesture since it doesn't cross the threshold yet.
2722 SimulateWheelEvent(10, 0, 0, true);
2723 SendInputEventACK(WebInputEvent::MouseWheel
,
2724 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2725 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2726 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2727 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2729 // Scroll some more so as to not overscroll.
2730 SimulateWheelEvent(20, 0, 0, true);
2731 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2732 SendInputEventACK(WebInputEvent::MouseWheel
,
2733 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2734 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2735 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2737 // Scroll some more to initiate an overscroll.
2738 SimulateWheelEvent(30, 0, 0, true);
2739 SendInputEventACK(WebInputEvent::MouseWheel
,
2740 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2741 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2742 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2743 EXPECT_EQ(60.f
, overscroll_delta_x());
2744 EXPECT_EQ(10.f
, overscroll_delegate()->delta_x());
2745 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2746 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2748 // Send a fling start, but with a small velocity, so that the overscroll is
2749 // aborted. The fling should proceed to the renderer, through the gesture
2751 SimulateGestureFlingStartEvent(10.f
, 0.f
, blink::WebGestureDeviceTouchpad
);
2752 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2753 EXPECT_EQ(1U, sink_
->message_count());
2756 // Tests that a fling in the opposite direction of the overscroll cancels the
2757 // overscroll nav instead of completing it.
2758 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, ReverseFlingCancelsOverscroll
) {
2759 SetUpOverscrollEnvironment();
2762 // Start and end a gesture in the same direction without processing the
2763 // gesture events in the renderer. This should initiate and complete an
2764 // overscroll navigation.
2765 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2766 blink::WebGestureDeviceTouchscreen
);
2767 SimulateGestureScrollUpdateEvent(300, -5, 0);
2768 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2769 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2770 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2771 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2772 sink_
->ClearMessages();
2774 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
2775 blink::WebGestureDeviceTouchscreen
);
2776 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->completed_mode());
2777 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2778 EXPECT_EQ(1U, sink_
->message_count());
2782 // Start over, except instead of ending the gesture with ScrollEnd, end it
2783 // with a FlingStart, with velocity in the reverse direction. This should
2784 // initiate an overscroll navigation, but it should be cancelled because of
2785 // the fling in the opposite direction.
2786 overscroll_delegate()->Reset();
2787 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2788 blink::WebGestureDeviceTouchscreen
);
2789 SimulateGestureScrollUpdateEvent(-300, -5, 0);
2790 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2791 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2792 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_mode());
2793 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_delegate()->current_mode());
2794 sink_
->ClearMessages();
2796 SimulateGestureFlingStartEvent(100, 0, blink::WebGestureDeviceTouchscreen
);
2797 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->completed_mode());
2798 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2799 EXPECT_EQ(1U, sink_
->message_count());
2803 // Tests that touch-scroll events are handled correctly by the overscroll
2804 // controller. This also tests that the overscroll controller and the
2805 // gesture-event filter play nice with each other.
2806 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, GestureScrollOverscrolls
) {
2807 SetUpOverscrollEnvironment();
2809 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2810 blink::WebGestureDeviceTouchscreen
);
2811 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2812 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2813 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2815 // Send another gesture event and ACK as not being processed. This should
2816 // initiate the navigation gesture.
2817 SimulateGestureScrollUpdateEvent(55, -5, 0);
2818 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2819 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2820 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2821 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2822 EXPECT_EQ(55.f
, overscroll_delta_x());
2823 EXPECT_EQ(-5.f
, overscroll_delta_y());
2824 EXPECT_EQ(5.f
, overscroll_delegate()->delta_x());
2825 EXPECT_EQ(-5.f
, overscroll_delegate()->delta_y());
2826 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2828 // Send another gesture update event. This event should be consumed by the
2829 // controller, and not be forwarded to the renderer. The gesture-event filter
2830 // should not also receive this event.
2831 SimulateGestureScrollUpdateEvent(10, -5, 0);
2832 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2833 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2834 EXPECT_EQ(65.f
, overscroll_delta_x());
2835 EXPECT_EQ(-10.f
, overscroll_delta_y());
2836 EXPECT_EQ(15.f
, overscroll_delegate()->delta_x());
2837 EXPECT_EQ(-10.f
, overscroll_delegate()->delta_y());
2838 EXPECT_EQ(0U, sink_
->message_count());
2840 // Now send a scroll end. This should cancel the overscroll gesture, and send
2841 // the event to the renderer. The gesture-event filter should receive this
2843 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
2844 blink::WebGestureDeviceTouchscreen
);
2845 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2846 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2847 EXPECT_EQ(1U, sink_
->message_count());
2850 // Tests that if the page is scrolled because of a scroll-gesture, then that
2851 // particular scroll sequence never generates overscroll if the scroll direction
2853 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
2854 GestureScrollConsumedHorizontal
) {
2855 SetUpOverscrollEnvironment();
2857 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2858 blink::WebGestureDeviceTouchscreen
);
2859 SimulateGestureScrollUpdateEvent(10, 0, 0);
2861 // Start scrolling on content. ACK both events as being processed.
2862 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2863 INPUT_EVENT_ACK_STATE_CONSUMED
);
2864 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2865 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2866 sink_
->ClearMessages();
2868 // Send another gesture event and ACK as not being processed. This should
2869 // not initiate overscroll because the beginning of the scroll event did
2870 // scroll some content on the page. Since there was no overscroll, the event
2871 // should reach the renderer.
2872 SimulateGestureScrollUpdateEvent(55, 0, 0);
2873 EXPECT_EQ(1U, sink_
->message_count());
2874 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2875 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2876 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2879 // Tests that the overscroll controller plays nice with touch-scrolls and the
2880 // gesture event filter with debounce filtering turned on.
2881 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
2882 GestureScrollDebounceOverscrolls
) {
2883 SetUpOverscrollEnvironmentWithDebounce(100);
2885 // Start scrolling. Receive ACK as it being processed.
2886 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2887 blink::WebGestureDeviceTouchscreen
);
2888 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2890 // Send update events.
2891 SimulateGestureScrollUpdateEvent(25, 0, 0);
2892 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2894 // Quickly end and restart the scroll gesture. These two events should get
2896 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
2897 blink::WebGestureDeviceTouchscreen
);
2898 EXPECT_EQ(0U, sink_
->message_count());
2900 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2901 blink::WebGestureDeviceTouchscreen
);
2902 EXPECT_EQ(0U, sink_
->message_count());
2904 // Send another update event. This should get into the queue.
2905 SimulateGestureScrollUpdateEvent(30, 0, 0);
2906 EXPECT_EQ(0U, sink_
->message_count());
2908 // Receive an ACK for the first scroll-update event as not being processed.
2909 // This will contribute to the overscroll gesture, but not enough for the
2910 // overscroll controller to start consuming gesture events. This also cause
2911 // the queued gesture event to be forwarded to the renderer.
2912 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2913 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2914 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2915 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2916 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2918 // Send another update event. This should get into the queue.
2919 SimulateGestureScrollUpdateEvent(10, 0, 0);
2920 EXPECT_EQ(0U, sink_
->message_count());
2922 // Receive an ACK for the second scroll-update event as not being processed.
2923 // This will now initiate an overscroll. This will also cause the queued
2924 // gesture event to be released. But instead of going to the renderer, it will
2925 // be consumed by the overscroll controller.
2926 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2927 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2928 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2929 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2930 EXPECT_EQ(65.f
, overscroll_delta_x());
2931 EXPECT_EQ(15.f
, overscroll_delegate()->delta_x());
2932 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2933 EXPECT_EQ(0U, sink_
->message_count());
2936 // Tests that the gesture debounce timer plays nice with the overscroll
2938 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
2939 GestureScrollDebounceTimerOverscroll
) {
2940 SetUpOverscrollEnvironmentWithDebounce(10);
2942 // Start scrolling. Receive ACK as it being processed.
2943 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2944 blink::WebGestureDeviceTouchscreen
);
2945 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2947 // Send update events.
2948 SimulateGestureScrollUpdateEvent(55, 0, 0);
2949 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2951 // Send an end event. This should get in the debounce queue.
2952 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
2953 blink::WebGestureDeviceTouchscreen
);
2954 EXPECT_EQ(0U, sink_
->message_count());
2956 // Receive ACK for the scroll-update event.
2957 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2958 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2959 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2960 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2961 EXPECT_EQ(55.f
, overscroll_delta_x());
2962 EXPECT_EQ(5.f
, overscroll_delegate()->delta_x());
2963 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2964 EXPECT_EQ(0U, sink_
->message_count());
2966 // Let the timer for the debounce queue fire. That should release the queued
2967 // scroll-end event. Since overscroll has started, but there hasn't been
2968 // enough overscroll to complete the gesture, the overscroll controller
2969 // will reset the state. The scroll-end should therefore be dispatched to the
2970 // renderer, and the gesture-event-filter should await an ACK for it.
2971 base::MessageLoop::current()->PostDelayedTask(
2973 base::MessageLoop::QuitClosure(),
2974 base::TimeDelta::FromMilliseconds(15));
2975 base::MessageLoop::current()->Run();
2977 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2978 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2979 EXPECT_EQ(1U, sink_
->message_count());
2982 // Tests that when touch-events are dispatched to the renderer, the overscroll
2983 // gesture deals with them correctly.
2984 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, OverscrollWithTouchEvents
) {
2985 SetUpOverscrollEnvironmentWithDebounce(10);
2986 widget_host_
->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
2987 sink_
->ClearMessages();
2989 // The test sends an intermingled sequence of touch and gesture events.
2990 PressTouchPoint(0, 1);
2991 uint32 touch_press_event_id1
= SendTouchEvent();
2992 SendTouchEventACK(WebInputEvent::TouchStart
,
2993 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
, touch_press_event_id1
);
2994 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2996 MoveTouchPoint(0, 20, 5);
2997 uint32 touch_move_event_id1
= SendTouchEvent();
2998 SendTouchEventACK(WebInputEvent::TouchMove
,
2999 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
, touch_move_event_id1
);
3000 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3002 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3003 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3005 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
3006 blink::WebGestureDeviceTouchscreen
);
3007 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3008 SimulateGestureScrollUpdateEvent(20, 0, 0);
3009 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
3010 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3011 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3012 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3013 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3015 // Another touch move event should reach the renderer since overscroll hasn't
3016 // started yet. Note that touch events sent during the scroll period may
3017 // not require an ack (having been marked uncancelable).
3018 MoveTouchPoint(0, 65, 10);
3020 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3021 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3023 SimulateGestureScrollUpdateEvent(45, 0, 0);
3024 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
3025 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3026 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
3027 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
3028 EXPECT_EQ(65.f
, overscroll_delta_x());
3029 EXPECT_EQ(15.f
, overscroll_delegate()->delta_x());
3030 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
3031 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3033 // Send another touch event. The page should get the touch-move event, even
3034 // though overscroll has started.
3035 MoveTouchPoint(0, 55, 5);
3037 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
3038 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
3039 EXPECT_EQ(65.f
, overscroll_delta_x());
3040 EXPECT_EQ(15.f
, overscroll_delegate()->delta_x());
3041 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
3042 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3043 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3045 SimulateGestureScrollUpdateEvent(-10, 0, 0);
3046 EXPECT_EQ(0U, sink_
->message_count());
3047 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
3048 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
3049 EXPECT_EQ(55.f
, overscroll_delta_x());
3050 EXPECT_EQ(5.f
, overscroll_delegate()->delta_x());
3051 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
3053 PressTouchPoint(255, 5);
3055 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3056 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3058 SimulateGestureScrollUpdateEvent(200, 0, 0);
3059 EXPECT_EQ(0U, sink_
->message_count());
3060 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
3061 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
3062 EXPECT_EQ(255.f
, overscroll_delta_x());
3063 EXPECT_EQ(205.f
, overscroll_delegate()->delta_x());
3064 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
3066 // The touch-end/cancel event should always reach the renderer if the page has
3068 ReleaseTouchPoint(1);
3070 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3071 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3072 ReleaseTouchPoint(0);
3074 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3075 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3077 SimulateGestureEvent(blink::WebInputEvent::GestureScrollEnd
,
3078 blink::WebGestureDeviceTouchscreen
);
3079 base::MessageLoop::current()->PostDelayedTask(
3081 base::MessageLoop::QuitClosure(),
3082 base::TimeDelta::FromMilliseconds(10));
3083 base::MessageLoop::current()->Run();
3084 EXPECT_EQ(1U, sink_
->message_count());
3085 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3086 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3087 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->completed_mode());
3090 // Tests that touch-gesture end is dispatched to the renderer at the end of a
3091 // touch-gesture initiated overscroll.
3092 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
3093 TouchGestureEndDispatchedAfterOverscrollComplete
) {
3094 SetUpOverscrollEnvironmentWithDebounce(10);
3095 widget_host_
->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
3096 sink_
->ClearMessages();
3098 // Start scrolling. Receive ACK as it being processed.
3099 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
3100 blink::WebGestureDeviceTouchscreen
);
3101 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3102 // The scroll begin event will have received a synthetic ack from the input
3104 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3105 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3107 // Send update events.
3108 SimulateGestureScrollUpdateEvent(55, -5, 0);
3109 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3110 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3111 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3113 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
3114 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3115 EXPECT_EQ(0U, sink_
->message_count());
3116 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
3117 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
3118 EXPECT_EQ(55.f
, overscroll_delta_x());
3119 EXPECT_EQ(5.f
, overscroll_delegate()->delta_x());
3120 EXPECT_EQ(-5.f
, overscroll_delegate()->delta_y());
3123 SimulateGestureEvent(blink::WebInputEvent::GestureScrollEnd
,
3124 blink::WebGestureDeviceTouchscreen
);
3125 EXPECT_EQ(0U, sink_
->message_count());
3126 base::MessageLoop::current()->PostDelayedTask(
3128 base::MessageLoop::QuitClosure(),
3129 base::TimeDelta::FromMilliseconds(10));
3130 base::MessageLoop::current()->Run();
3131 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3132 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3133 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->completed_mode());
3134 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3136 // Start scrolling. Receive ACK as it being processed.
3137 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
3138 blink::WebGestureDeviceTouchscreen
);
3139 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3140 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3141 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3143 // Send update events.
3144 SimulateGestureScrollUpdateEvent(235, -5, 0);
3145 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3146 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3147 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3149 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
3150 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3151 EXPECT_EQ(0U, sink_
->message_count());
3152 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
3153 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
3154 EXPECT_EQ(235.f
, overscroll_delta_x());
3155 EXPECT_EQ(185.f
, overscroll_delegate()->delta_x());
3156 EXPECT_EQ(-5.f
, overscroll_delegate()->delta_y());
3159 SimulateGestureEvent(blink::WebInputEvent::GestureScrollEnd
,
3160 blink::WebGestureDeviceTouchscreen
);
3161 EXPECT_EQ(0U, sink_
->message_count());
3162 base::MessageLoop::current()->PostDelayedTask(
3164 base::MessageLoop::QuitClosure(),
3165 base::TimeDelta::FromMilliseconds(10));
3166 base::MessageLoop::current()->Run();
3167 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3168 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3169 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->completed_mode());
3170 EXPECT_EQ(1U, sink_
->message_count());
3173 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, OverscrollDirectionChange
) {
3174 SetUpOverscrollEnvironmentWithDebounce(100);
3176 // Start scrolling. Receive ACK as it being processed.
3177 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
3178 blink::WebGestureDeviceTouchscreen
);
3179 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3181 // Send update events and receive ack as not consumed.
3182 SimulateGestureScrollUpdateEvent(125, -5, 0);
3183 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3185 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
3186 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3187 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
3188 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
3189 EXPECT_EQ(0U, sink_
->message_count());
3191 // Send another update event, but in the reverse direction. The overscroll
3192 // controller will not consume the event, because it is not triggering
3194 SimulateGestureScrollUpdateEvent(-260, 0, 0);
3195 EXPECT_EQ(1U, sink_
->message_count());
3196 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3198 // Since the overscroll mode has been reset, the next scroll update events
3199 // should reach the renderer.
3200 SimulateGestureScrollUpdateEvent(-20, 0, 0);
3201 EXPECT_EQ(1U, sink_
->message_count());
3202 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3205 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
3206 OverscrollDirectionChangeMouseWheel
) {
3207 SetUpOverscrollEnvironment();
3209 // Send wheel event and receive ack as not consumed.
3210 SimulateWheelEvent(125, -5, 0, true);
3211 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3212 SendInputEventACK(WebInputEvent::MouseWheel
,
3213 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3214 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
3215 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
3216 EXPECT_EQ(0U, sink_
->message_count());
3218 // Send another wheel event, but in the reverse direction. The overscroll
3219 // controller will not consume the event, because it is not triggering
3221 SimulateWheelEvent(-260, 0, 0, true);
3222 EXPECT_EQ(1U, sink_
->message_count());
3223 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3225 // Since the overscroll mode has been reset, the next wheel event should reach
3227 SimulateWheelEvent(-20, 0, 0, true);
3228 EXPECT_EQ(1U, sink_
->message_count());
3229 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3232 // Tests that if a mouse-move event completes the overscroll gesture, future
3233 // move events do reach the renderer.
3234 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, OverscrollMouseMoveCompletion
) {
3235 SetUpOverscrollEnvironment();
3237 SimulateWheelEvent(5, 0, 0, true); // sent directly
3238 SimulateWheelEvent(-1, 0, 0, true); // enqueued
3239 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
3240 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
3241 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
3242 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3243 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3245 // Receive ACK the first wheel event as not processed.
3246 SendInputEventACK(WebInputEvent::MouseWheel
,
3247 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3248 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3249 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3250 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3252 // Receive ACK for the second (coalesced) event as not processed. This will
3253 // start an overcroll gesture.
3254 SendInputEventACK(WebInputEvent::MouseWheel
,
3255 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3256 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_mode());
3257 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_delegate()->current_mode());
3258 EXPECT_EQ(0U, sink_
->message_count());
3260 // Send a mouse-move event. This should cancel the overscroll navigation
3261 // (since the amount overscrolled is not above the threshold), and so the
3262 // mouse-move should reach the renderer.
3263 SimulateMouseMove(5, 10, 0);
3264 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3265 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->completed_mode());
3266 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3267 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3269 SendInputEventACK(WebInputEvent::MouseMove
,
3270 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3272 // Moving the mouse more should continue to send the events to the renderer.
3273 SimulateMouseMove(5, 10, 0);
3274 SendInputEventACK(WebInputEvent::MouseMove
,
3275 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3276 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3278 // Now try with gestures.
3279 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
3280 blink::WebGestureDeviceTouchscreen
);
3281 SimulateGestureScrollUpdateEvent(300, -5, 0);
3282 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
3283 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3284 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
3285 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
3286 sink_
->ClearMessages();
3288 // Overscroll gesture is in progress. Send a mouse-move now. This should
3289 // complete the gesture (because the amount overscrolled is above the
3291 SimulateMouseMove(5, 10, 0);
3292 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->completed_mode());
3293 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3294 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3295 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3296 SendInputEventACK(WebInputEvent::MouseMove
,
3297 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3299 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
3300 blink::WebGestureDeviceTouchscreen
);
3301 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3302 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3304 // Move mouse some more. The mouse-move events should reach the renderer.
3305 SimulateMouseMove(5, 10, 0);
3306 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3308 SendInputEventACK(WebInputEvent::MouseMove
,
3309 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3312 // Tests that if a page scrolled, then the overscroll controller's states are
3313 // reset after the end of the scroll.
3314 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
3315 OverscrollStateResetsAfterScroll
) {
3316 SetUpOverscrollEnvironment();
3318 SimulateWheelEvent(0, 5, 0, true); // sent directly
3319 SimulateWheelEvent(0, 30, 0, true); // enqueued
3320 SimulateWheelEvent(0, 40, 0, true); // coalesced into previous event
3321 SimulateWheelEvent(0, 10, 0, true); // coalesced into previous event
3322 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3323 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3325 // The first wheel event is consumed. Dispatches the queued wheel event.
3326 SendInputEventACK(WebInputEvent::MouseWheel
, INPUT_EVENT_ACK_STATE_CONSUMED
);
3327 EXPECT_TRUE(ScrollStateIsContentScrolling());
3328 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3330 // The second wheel event is consumed.
3331 SendInputEventACK(WebInputEvent::MouseWheel
, INPUT_EVENT_ACK_STATE_CONSUMED
);
3332 EXPECT_TRUE(ScrollStateIsContentScrolling());
3334 // Touchpad scroll can end with a zero-velocity fling. But it is not
3335 // dispatched, but it should still reset the overscroll controller state.
3336 SimulateGestureFlingStartEvent(0.f
, 0.f
, blink::WebGestureDeviceTouchpad
);
3337 EXPECT_TRUE(ScrollStateIsUnknown());
3338 EXPECT_EQ(0U, sink_
->message_count());
3340 // Dropped flings should neither propagate *nor* indicate that they were
3341 // consumed and have triggered a fling animation (as tracked by the router).
3342 EXPECT_FALSE(parent_host_
->input_router()->HasPendingEvents());
3344 SimulateWheelEvent(-5, 0, 0, true); // sent directly
3345 SimulateWheelEvent(-60, 0, 0, true); // enqueued
3346 SimulateWheelEvent(-100, 0, 0, true); // coalesced into previous event
3347 EXPECT_TRUE(ScrollStateIsUnknown());
3348 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3350 // The first wheel scroll did not scroll content. Overscroll should not start
3351 // yet, since enough hasn't been scrolled.
3352 SendInputEventACK(WebInputEvent::MouseWheel
,
3353 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3354 EXPECT_TRUE(ScrollStateIsUnknown());
3355 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3357 SendInputEventACK(WebInputEvent::MouseWheel
,
3358 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3359 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_mode());
3360 EXPECT_TRUE(ScrollStateIsOverscrolling());
3361 EXPECT_EQ(0U, sink_
->message_count());
3363 SimulateGestureFlingStartEvent(0.f
, 0.f
, blink::WebGestureDeviceTouchpad
);
3364 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3365 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_delegate()->completed_mode());
3366 EXPECT_TRUE(ScrollStateIsUnknown());
3367 EXPECT_EQ(0U, sink_
->message_count());
3368 EXPECT_FALSE(parent_host_
->input_router()->HasPendingEvents());
3371 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, OverscrollResetsOnBlur
) {
3372 SetUpOverscrollEnvironment();
3374 // Start an overscroll with gesture scroll. In the middle of the scroll, blur
3376 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
3377 blink::WebGestureDeviceTouchscreen
);
3378 SimulateGestureScrollUpdateEvent(300, -5, 0);
3379 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
3380 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3381 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
3382 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
3383 EXPECT_EQ(2U, GetSentMessageCountAndResetSink());
3385 view_
->OnWindowFocused(NULL
, view_
->GetNativeView());
3386 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3387 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3388 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->completed_mode());
3389 EXPECT_EQ(0.f
, overscroll_delegate()->delta_x());
3390 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
3391 sink_
->ClearMessages();
3393 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
3394 blink::WebGestureDeviceTouchscreen
);
3395 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3397 // Start a scroll gesture again. This should correctly start the overscroll
3398 // after the threshold.
3399 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
3400 blink::WebGestureDeviceTouchscreen
);
3401 SimulateGestureScrollUpdateEvent(300, -5, 0);
3402 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
3403 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3404 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
3405 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
3406 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->completed_mode());
3408 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
3409 blink::WebGestureDeviceTouchscreen
);
3410 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3411 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->completed_mode());
3412 EXPECT_EQ(3U, sink_
->message_count());
3415 // Tests that when view initiated shutdown happens (i.e. RWHView is deleted
3416 // before RWH), we clean up properly and don't leak the RWHVGuest.
3417 TEST_F(RenderWidgetHostViewGuestAuraTest
, GuestViewDoesNotLeak
) {
3418 view_
->InitAsChild(NULL
);
3419 TearDownEnvironment();
3420 ASSERT_FALSE(guest_view_weak_
.get());
3423 // Tests that invalid touch events are consumed and handled
3425 TEST_F(RenderWidgetHostViewAuraTest
,
3426 InvalidEventsHaveSyncHandlingDisabled
) {
3427 view_
->InitAsChild(NULL
);
3429 GetSentMessageCountAndResetSink();
3431 widget_host_
->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
3433 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(30, 30), 0,
3434 ui::EventTimeForNow());
3436 // Construct a move with a touch id which doesn't exist.
3437 ui::TouchEvent
invalid_move(ui::ET_TOUCH_MOVED
, gfx::Point(30, 30), 1,
3438 ui::EventTimeForNow());
3440 // Valid press is handled asynchronously.
3441 view_
->OnTouchEvent(&press
);
3442 EXPECT_TRUE(press
.synchronous_handling_disabled());
3443 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3444 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_CONSUMED
);
3446 // Invalid move is handled synchronously, but is consumed. It should not
3447 // be forwarded to the renderer.
3448 view_
->OnTouchEvent(&invalid_move
);
3449 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
3450 EXPECT_FALSE(invalid_move
.synchronous_handling_disabled());
3451 EXPECT_TRUE(invalid_move
.stopped_propagation());
3454 // Checks key event codes.
3455 TEST_F(RenderWidgetHostViewAuraTest
, KeyEvent
) {
3456 view_
->InitAsChild(NULL
);
3459 ui::KeyEvent
key_event(ui::ET_KEY_PRESSED
, ui::VKEY_A
, ui::DomCode::KEY_A
,
3461 view_
->OnKeyEvent(&key_event
);
3463 const NativeWebKeyboardEvent
* event
= delegate_
.last_event();
3464 EXPECT_NE(nullptr, event
);
3466 EXPECT_EQ(key_event
.key_code(), event
->windowsKeyCode
);
3467 EXPECT_EQ(ui::KeycodeConverter::DomCodeToNativeKeycode(key_event
.code()),
3468 event
->nativeKeyCode
);
3472 TEST_F(RenderWidgetHostViewAuraTest
, SetCanScrollForWebMouseWheelEvent
) {
3473 view_
->InitAsChild(NULL
);
3476 sink_
->ClearMessages();
3478 // Simulates the mouse wheel event with ctrl modifier applied.
3479 ui::MouseWheelEvent
event(gfx::Vector2d(1, 1), gfx::Point(), gfx::Point(),
3480 ui::EventTimeForNow(), ui::EF_CONTROL_DOWN
, 0);
3481 view_
->OnMouseEvent(&event
);
3483 const WebInputEvent
* input_event
=
3484 GetInputEventFromMessage(*sink_
->GetMessageAt(0));
3485 const WebMouseWheelEvent
* wheel_event
=
3486 static_cast<const WebMouseWheelEvent
*>(input_event
);
3487 // Check if the canScroll set to false when ctrl-scroll is generated from
3488 // mouse wheel event.
3489 EXPECT_FALSE(wheel_event
->canScroll
);
3490 sink_
->ClearMessages();
3492 // Ack'ing the outstanding event should flush the pending event queue.
3493 SendInputEventACK(blink::WebInputEvent::MouseWheel
,
3494 INPUT_EVENT_ACK_STATE_CONSUMED
);
3496 // Simulates the mouse wheel event with no modifier applied.
3497 event
= ui::MouseWheelEvent(gfx::Vector2d(1, 1), gfx::Point(), gfx::Point(),
3498 ui::EventTimeForNow(), ui::EF_NONE
, 0);
3500 view_
->OnMouseEvent(&event
);
3502 input_event
= GetInputEventFromMessage(*sink_
->GetMessageAt(0));
3503 wheel_event
= static_cast<const WebMouseWheelEvent
*>(input_event
);
3504 // Check if the canScroll set to true when no modifier is applied to the
3505 // mouse wheel event.
3506 EXPECT_TRUE(wheel_event
->canScroll
);
3507 sink_
->ClearMessages();
3509 SendInputEventACK(blink::WebInputEvent::MouseWheel
,
3510 INPUT_EVENT_ACK_STATE_CONSUMED
);
3512 // Simulates the scroll event with ctrl modifier applied.
3513 ui::ScrollEvent
scroll(ui::ET_SCROLL
, gfx::Point(2, 2), ui::EventTimeForNow(),
3514 ui::EF_CONTROL_DOWN
, 0, 5, 0, 5, 2);
3515 view_
->OnScrollEvent(&scroll
);
3517 input_event
= GetInputEventFromMessage(*sink_
->GetMessageAt(0));
3518 wheel_event
= static_cast<const WebMouseWheelEvent
*>(input_event
);
3519 // Check if the canScroll set to true when ctrl-touchpad-scroll is generated
3520 // from scroll event.
3521 EXPECT_TRUE(wheel_event
->canScroll
);
3524 // Ensures that the mapping from ui::TouchEvent to blink::WebTouchEvent doesn't
3525 // lose track of the number of acks required.
3526 TEST_F(RenderWidgetHostViewAuraTest
, CorrectNumberOfAcksAreDispatched
) {
3527 view_
->InitAsFullscreen(parent_view_
);
3529 view_
->UseFakeDispatcher();
3531 ui::TouchEvent
press1(
3532 ui::ET_TOUCH_PRESSED
, gfx::Point(30, 30), 0, ui::EventTimeForNow());
3534 view_
->OnTouchEvent(&press1
);
3535 SendTouchEventACK(blink::WebInputEvent::TouchStart
,
3536 INPUT_EVENT_ACK_STATE_CONSUMED
, press1
.unique_event_id());
3538 ui::TouchEvent
press2(
3539 ui::ET_TOUCH_PRESSED
, gfx::Point(20, 20), 1, ui::EventTimeForNow());
3540 view_
->OnTouchEvent(&press2
);
3541 SendTouchEventACK(blink::WebInputEvent::TouchStart
,
3542 INPUT_EVENT_ACK_STATE_CONSUMED
, press2
.unique_event_id());
3544 EXPECT_EQ(2U, view_
->dispatcher_
->GetAndResetProcessedTouchEventCount());
3547 // Tests that the scroll deltas stored within the overscroll controller get
3548 // reset at the end of the overscroll gesture even if the overscroll threshold
3549 // isn't surpassed and the overscroll mode stays OVERSCROLL_NONE.
3550 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, ScrollDeltasResetOnEnd
) {
3551 SetUpOverscrollEnvironment();
3552 // Wheel event scroll ending with mouse move.
3553 SimulateWheelEvent(-30, -10, 0, true); // sent directly
3554 SendInputEventACK(WebInputEvent::MouseWheel
,
3555 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3556 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3557 EXPECT_EQ(-30.f
, overscroll_delta_x());
3558 EXPECT_EQ(-10.f
, overscroll_delta_y());
3559 SimulateMouseMove(5, 10, 0);
3560 EXPECT_EQ(0.f
, overscroll_delta_x());
3561 EXPECT_EQ(0.f
, overscroll_delta_y());
3564 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
3565 blink::WebGestureDeviceTouchscreen
);
3566 SimulateGestureScrollUpdateEvent(-30, -5, 0);
3567 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
3568 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3569 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3570 EXPECT_EQ(-30.f
, overscroll_delta_x());
3571 EXPECT_EQ(-5.f
, overscroll_delta_y());
3572 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
3573 blink::WebGestureDeviceTouchscreen
);
3574 EXPECT_EQ(0.f
, overscroll_delta_x());
3575 EXPECT_EQ(0.f
, overscroll_delta_y());
3577 // Wheel event scroll ending with a fling.
3578 SimulateWheelEvent(5, 0, 0, true);
3579 SendInputEventACK(WebInputEvent::MouseWheel
,
3580 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3581 SimulateWheelEvent(10, -5, 0, true);
3582 SendInputEventACK(WebInputEvent::MouseWheel
,
3583 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3584 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3585 EXPECT_EQ(15.f
, overscroll_delta_x());
3586 EXPECT_EQ(-5.f
, overscroll_delta_y());
3587 SimulateGestureFlingStartEvent(0.f
, 0.1f
, blink::WebGestureDeviceTouchpad
);
3588 EXPECT_EQ(0.f
, overscroll_delta_x());
3589 EXPECT_EQ(0.f
, overscroll_delta_y());
3592 // Tests the RenderWidgetHostImpl sends the correct surface ID namespace to
3593 // the renderer process.
3594 TEST_F(RenderWidgetHostViewAuraTest
, SurfaceIdNamespaceInitialized
) {
3595 gfx::Size
size(5, 5);
3597 const IPC::Message
* msg
=
3598 sink_
->GetUniqueMessageMatching(ViewMsg_SetSurfaceIdNamespace::ID
);
3600 ViewMsg_SetSurfaceIdNamespace::Param params
;
3601 ViewMsg_SetSurfaceIdNamespace::Read(msg
, ¶ms
);
3602 view_
->InitAsChild(NULL
);
3604 view_
->SetSize(size
);
3605 view_
->OnSwapCompositorFrame(0,
3606 MakeDelegatedFrame(1.f
, size
, gfx::Rect(size
)));
3607 EXPECT_EQ(view_
->GetSurfaceIdNamespace(), base::get
<0>(params
));
3610 } // namespace content