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
));
153 scoped_ptr
<NativeWebKeyboardEvent
> last_event_
;
154 DISALLOW_COPY_AND_ASSIGN(MockRenderWidgetHostDelegate
);
157 // Simple observer that keeps track of changes to a window for tests.
158 class TestWindowObserver
: public aura::WindowObserver
{
160 explicit TestWindowObserver(aura::Window
* window_to_observe
)
161 : window_(window_to_observe
) {
162 window_
->AddObserver(this);
164 ~TestWindowObserver() override
{
166 window_
->RemoveObserver(this);
169 bool destroyed() const { return destroyed_
; }
171 // aura::WindowObserver overrides:
172 void OnWindowDestroyed(aura::Window
* window
) override
{
173 CHECK_EQ(window
, window_
);
179 // Window that we're observing, or NULL if it's been destroyed.
180 aura::Window
* window_
;
182 // Was |window_| destroyed?
185 DISALLOW_COPY_AND_ASSIGN(TestWindowObserver
);
188 class FakeFrameSubscriber
: public RenderWidgetHostViewFrameSubscriber
{
190 FakeFrameSubscriber(gfx::Size size
, base::Callback
<void(bool)> callback
)
191 : size_(size
), callback_(callback
) {}
193 bool ShouldCaptureFrame(const gfx::Rect
& damage_rect
,
194 base::TimeTicks present_time
,
195 scoped_refptr
<media::VideoFrame
>* storage
,
196 DeliverFrameCallback
* callback
) override
{
197 last_present_time_
= present_time
;
198 *storage
= media::VideoFrame::CreateFrame(media::VideoFrame::YV12
,
203 *callback
= base::Bind(&FakeFrameSubscriber::CallbackMethod
, callback_
);
207 base::TimeTicks
last_present_time() const { return last_present_time_
; }
209 static void CallbackMethod(base::Callback
<void(bool)> callback
,
210 base::TimeTicks present_time
,
212 callback
.Run(success
);
217 base::Callback
<void(bool)> callback_
;
218 base::TimeTicks last_present_time_
;
221 class FakeWindowEventDispatcher
: public aura::WindowEventDispatcher
{
223 FakeWindowEventDispatcher(aura::WindowTreeHost
* host
)
224 : WindowEventDispatcher(host
),
225 processed_touch_event_count_(0) {}
227 void ProcessedTouchEvent(uint32 unique_event_id
,
228 aura::Window
* window
,
229 ui::EventResult result
) override
{
230 WindowEventDispatcher::ProcessedTouchEvent(unique_event_id
, window
, result
);
231 processed_touch_event_count_
++;
234 size_t GetAndResetProcessedTouchEventCount() {
235 size_t count
= processed_touch_event_count_
;
236 processed_touch_event_count_
= 0;
241 size_t processed_touch_event_count_
;
244 class FakeRenderWidgetHostViewAura
: public RenderWidgetHostViewAura
{
246 FakeRenderWidgetHostViewAura(RenderWidgetHost
* widget
,
247 bool is_guest_view_hack
)
248 : RenderWidgetHostViewAura(widget
, is_guest_view_hack
),
249 has_resize_lock_(false) {}
251 void UseFakeDispatcher() {
252 dispatcher_
= new FakeWindowEventDispatcher(window()->GetHost());
253 scoped_ptr
<aura::WindowEventDispatcher
> dispatcher(dispatcher_
);
254 aura::test::SetHostDispatcher(window()->GetHost(), dispatcher
.Pass());
257 ~FakeRenderWidgetHostViewAura() override
{}
259 scoped_ptr
<ResizeLock
> DelegatedFrameHostCreateResizeLock(
260 bool defer_compositor_lock
) override
{
261 gfx::Size desired_size
= window()->bounds().size();
262 return scoped_ptr
<ResizeLock
>(
263 new FakeResizeLock(desired_size
, defer_compositor_lock
));
266 bool DelegatedFrameCanCreateResizeLock() const override
{ return true; }
268 void RunOnCompositingDidCommit() {
269 GetDelegatedFrameHost()->OnCompositingDidCommitForTesting(
270 window()->GetHost()->compositor());
273 void InterceptCopyOfOutput(scoped_ptr
<cc::CopyOutputRequest
> request
) {
274 last_copy_request_
= request
.Pass();
275 if (last_copy_request_
->has_texture_mailbox()) {
276 // Give the resulting texture a size.
277 GLHelper
* gl_helper
= ImageTransportFactory::GetInstance()->GetGLHelper();
278 GLuint texture
= gl_helper
->ConsumeMailboxToTexture(
279 last_copy_request_
->texture_mailbox().mailbox(),
280 last_copy_request_
->texture_mailbox().sync_point());
281 gl_helper
->ResizeTexture(texture
, window()->bounds().size());
282 gl_helper
->DeleteTexture(texture
);
286 cc::DelegatedFrameProvider
* frame_provider() const {
287 return GetDelegatedFrameHost()->FrameProviderForTesting();
290 cc::SurfaceId
surface_id() const {
291 return GetDelegatedFrameHost()->SurfaceIdForTesting();
294 bool HasFrameData() const {
295 return frame_provider() || !surface_id().is_null();
298 bool released_front_lock_active() const {
299 return GetDelegatedFrameHost()->ReleasedFrontLockActiveForTesting();
302 // A lock that doesn't actually do anything to the compositor, and does not
304 class FakeResizeLock
: public ResizeLock
{
306 FakeResizeLock(const gfx::Size new_size
, bool defer_compositor_lock
)
307 : ResizeLock(new_size
, defer_compositor_lock
) {}
310 void OnTouchEvent(ui::TouchEvent
* event
) override
{
311 RenderWidgetHostViewAura::OnTouchEvent(event
);
312 if (pointer_state().GetPointerCount() > 0) {
314 new blink::WebTouchEvent(ui::CreateWebTouchEventFromMotionEvent(
315 pointer_state(), event
->may_cause_scrolling())));
317 // Never create a WebTouchEvent with 0 touch points.
318 touch_event_
.reset();
322 bool has_resize_lock_
;
323 gfx::Size last_frame_size_
;
324 scoped_ptr
<cc::CopyOutputRequest
> last_copy_request_
;
325 // null if there are 0 active touch points.
326 scoped_ptr
<blink::WebTouchEvent
> touch_event_
;
327 FakeWindowEventDispatcher
* dispatcher_
;
330 // A layout manager that always resizes a child to the root window size.
331 class FullscreenLayoutManager
: public aura::LayoutManager
{
333 explicit FullscreenLayoutManager(aura::Window
* owner
) : owner_(owner
) {}
334 ~FullscreenLayoutManager() override
{}
336 // Overridden from aura::LayoutManager:
337 void OnWindowResized() override
{
338 aura::Window::Windows::const_iterator i
;
339 for (i
= owner_
->children().begin(); i
!= owner_
->children().end(); ++i
) {
340 (*i
)->SetBounds(gfx::Rect());
343 void OnWindowAddedToLayout(aura::Window
* child
) override
{
344 child
->SetBounds(gfx::Rect());
346 void OnWillRemoveWindowFromLayout(aura::Window
* child
) override
{}
347 void OnWindowRemovedFromLayout(aura::Window
* child
) override
{}
348 void OnChildWindowVisibilityChanged(aura::Window
* child
,
349 bool visible
) override
{}
350 void SetChildBounds(aura::Window
* child
,
351 const gfx::Rect
& requested_bounds
) override
{
352 SetChildBoundsDirect(child
, gfx::Rect(owner_
->bounds().size()));
356 aura::Window
* owner_
;
357 DISALLOW_COPY_AND_ASSIGN(FullscreenLayoutManager
);
360 class MockWindowObserver
: public aura::WindowObserver
{
362 MOCK_METHOD2(OnDelegatedFrameDamage
, void(aura::Window
*, const gfx::Rect
&));
365 const WebInputEvent
* GetInputEventFromMessage(const IPC::Message
& message
) {
366 base::PickleIterator
iter(message
);
369 if (!iter
.ReadData(&data
, &data_length
))
371 return reinterpret_cast<const WebInputEvent
*>(data
);
376 class RenderWidgetHostViewAuraTest
: public testing::Test
{
378 RenderWidgetHostViewAuraTest()
379 : widget_host_uses_shutdown_to_destroy_(false),
380 is_guest_view_hack_(false),
381 browser_thread_for_ui_(BrowserThread::UI
, &message_loop_
) {}
383 void SetUpEnvironment() {
384 ImageTransportFactory::InitializeForUnitTests(
385 scoped_ptr
<ImageTransportFactory
>(
386 new NoTransportImageTransportFactory
));
387 aura_test_helper_
.reset(new aura::test::AuraTestHelper(&message_loop_
));
388 aura_test_helper_
->SetUp(
389 ImageTransportFactory::GetInstance()->GetContextFactory());
390 new wm::DefaultActivationClient(aura_test_helper_
->root_window());
392 browser_context_
.reset(new TestBrowserContext
);
393 process_host_
= new MockRenderProcessHost(browser_context_
.get());
394 process_host_
->Init();
396 sink_
= &process_host_
->sink();
398 parent_host_
= new RenderWidgetHostImpl(
399 &delegate_
, process_host_
, MSG_ROUTING_NONE
, false);
400 parent_view_
= new RenderWidgetHostViewAura(parent_host_
,
401 is_guest_view_hack_
);
402 parent_view_
->InitAsChild(NULL
);
403 aura::client::ParentWindowWithContext(parent_view_
->GetNativeView(),
404 aura_test_helper_
->root_window(),
407 widget_host_
= new RenderWidgetHostImpl(
408 &delegate_
, process_host_
, MSG_ROUTING_NONE
, false);
409 widget_host_
->Init();
410 view_
= new FakeRenderWidgetHostViewAura(widget_host_
, is_guest_view_hack_
);
413 void TearDownEnvironment() {
415 process_host_
= NULL
;
419 if (widget_host_uses_shutdown_to_destroy_
)
420 widget_host_
->Shutdown();
424 parent_view_
->Destroy();
427 browser_context_
.reset();
428 aura_test_helper_
->TearDown();
430 message_loop_
.DeleteSoon(FROM_HERE
, browser_context_
.release());
431 message_loop_
.RunUntilIdle();
432 ImageTransportFactory::Terminate();
435 void SetUp() override
{ SetUpEnvironment(); }
437 void TearDown() override
{ TearDownEnvironment(); }
439 void set_widget_host_uses_shutdown_to_destroy(bool use
) {
440 widget_host_uses_shutdown_to_destroy_
= use
;
443 void SimulateMemoryPressure(
444 base::MemoryPressureListener::MemoryPressureLevel level
) {
445 // Here should be base::MemoryPressureListener::NotifyMemoryPressure, but
446 // since the RendererFrameManager is installing a MemoryPressureListener
447 // which uses base::ObserverListThreadSafe, which furthermore remembers the
448 // message loop for the thread it was created in. Between tests, the
449 // RendererFrameManager singleton survives and and the MessageLoop gets
450 // destroyed. The correct fix would be to have base::ObserverListThreadSafe
452 // up the proper message loop every time (see crbug.com/443824.)
453 RendererFrameManager::GetInstance()->OnMemoryPressure(level
);
456 void SendInputEventACK(WebInputEvent::Type type
,
457 InputEventAckState ack_result
) {
458 DCHECK(!WebInputEvent::isTouchEventType(type
));
459 InputEventAck
ack(type
, ack_result
);
460 InputHostMsg_HandleInputEvent_ACK
response(0, ack
);
461 widget_host_
->OnMessageReceived(response
);
464 void SendTouchEventACK(WebInputEvent::Type type
,
465 InputEventAckState ack_result
,
467 DCHECK(WebInputEvent::isTouchEventType(type
));
468 InputEventAck
ack(type
, ack_result
, event_id
);
469 InputHostMsg_HandleInputEvent_ACK
response(0, ack
);
470 widget_host_
->OnMessageReceived(response
);
473 size_t GetSentMessageCountAndResetSink() {
474 size_t count
= sink_
->message_count();
475 sink_
->ClearMessages();
479 void AckLastSentInputEventIfNecessary(InputEventAckState ack_result
) {
480 if (!sink_
->message_count())
483 InputMsg_HandleInputEvent::Param params
;
484 if (!InputMsg_HandleInputEvent::Read(
485 sink_
->GetMessageAt(sink_
->message_count() - 1), ¶ms
)) {
489 if (!WebInputEventTraits::WillReceiveAckFromRenderer(
490 *base::get
<0>(params
)))
493 const blink::WebInputEvent
* event
= base::get
<0>(params
);
494 SendTouchEventACK(event
->type
, ack_result
,
495 WebInputEventTraits::GetUniqueTouchEventId(*event
));
499 // If true, then calls RWH::Shutdown() instead of deleting RWH.
500 bool widget_host_uses_shutdown_to_destroy_
;
502 bool is_guest_view_hack_
;
504 base::MessageLoopForUI message_loop_
;
505 BrowserThreadImpl browser_thread_for_ui_
;
506 scoped_ptr
<aura::test::AuraTestHelper
> aura_test_helper_
;
507 scoped_ptr
<BrowserContext
> browser_context_
;
508 MockRenderWidgetHostDelegate delegate_
;
509 MockRenderProcessHost
* process_host_
;
511 // Tests should set these to NULL if they've already triggered their
513 RenderWidgetHostImpl
* parent_host_
;
514 RenderWidgetHostViewAura
* parent_view_
;
516 // Tests should set these to NULL if they've already triggered their
518 RenderWidgetHostImpl
* widget_host_
;
519 FakeRenderWidgetHostViewAura
* view_
;
521 IPC::TestSink
* sink_
;
524 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraTest
);
527 // Helper class to instantiate RenderWidgetHostViewGuest which is backed
528 // by an aura platform view.
529 class RenderWidgetHostViewGuestAuraTest
: public RenderWidgetHostViewAuraTest
{
531 RenderWidgetHostViewGuestAuraTest() {
532 // Use RWH::Shutdown to destroy RWH, instead of deleting.
533 // This will ensure that the RenderWidgetHostViewGuest is not leaked and
534 // is deleted properly upon RWH going away.
535 set_widget_host_uses_shutdown_to_destroy(true);
538 // We explicitly invoke SetUp to allow gesture debounce customization.
539 void SetUp() override
{
540 is_guest_view_hack_
= true;
542 RenderWidgetHostViewAuraTest::SetUp();
544 guest_view_weak_
= (new RenderWidgetHostViewGuest(
545 widget_host_
, NULL
, view_
->GetWeakPtr()))->GetWeakPtr();
548 void TearDown() override
{
549 // Internal override to do nothing, we clean up ourselves in the test body.
550 // This helps us test that |guest_view_weak_| does not leak.
554 base::WeakPtr
<RenderWidgetHostViewBase
> guest_view_weak_
;
558 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewGuestAuraTest
);
561 class RenderWidgetHostViewAuraOverscrollTest
562 : public RenderWidgetHostViewAuraTest
{
564 RenderWidgetHostViewAuraOverscrollTest() {}
566 // We explicitly invoke SetUp to allow gesture debounce customization.
567 void SetUp() override
{}
570 void SetUpOverscrollEnvironmentWithDebounce(int debounce_interval_in_ms
) {
571 SetUpOverscrollEnvironmentImpl(debounce_interval_in_ms
);
574 void SetUpOverscrollEnvironment() { SetUpOverscrollEnvironmentImpl(0); }
576 void SetUpOverscrollEnvironmentImpl(int debounce_interval_in_ms
) {
577 ui::GestureConfiguration::GetInstance()->set_scroll_debounce_interval_in_ms(
578 debounce_interval_in_ms
);
580 RenderWidgetHostViewAuraTest::SetUp();
582 view_
->SetOverscrollControllerEnabled(true);
583 overscroll_delegate_
.reset(new TestOverscrollDelegate(view_
));
584 view_
->overscroll_controller()->set_delegate(overscroll_delegate_
.get());
586 view_
->InitAsChild(NULL
);
587 view_
->SetBounds(gfx::Rect(0, 0, 400, 200));
590 sink_
->ClearMessages();
593 // TODO(jdduke): Simulate ui::Events, injecting through the view.
594 void SimulateMouseEvent(WebInputEvent::Type type
) {
595 widget_host_
->ForwardMouseEvent(SyntheticWebMouseEventBuilder::Build(type
));
598 void SimulateMouseEventWithLatencyInfo(WebInputEvent::Type type
,
599 const ui::LatencyInfo
& ui_latency
) {
600 widget_host_
->ForwardMouseEventWithLatencyInfo(
601 SyntheticWebMouseEventBuilder::Build(type
), ui_latency
);
604 void SimulateWheelEvent(float dX
, float dY
, int modifiers
, bool precise
) {
605 widget_host_
->ForwardWheelEvent(
606 SyntheticWebMouseWheelEventBuilder::Build(dX
, dY
, modifiers
, precise
));
609 void SimulateWheelEventWithLatencyInfo(float dX
,
613 const ui::LatencyInfo
& ui_latency
) {
614 widget_host_
->ForwardWheelEventWithLatencyInfo(
615 SyntheticWebMouseWheelEventBuilder::Build(dX
, dY
, modifiers
, precise
),
619 void SimulateMouseMove(int x
, int y
, int modifiers
) {
620 SimulateMouseEvent(WebInputEvent::MouseMove
, x
, y
, modifiers
, false);
623 void SimulateMouseEvent(WebInputEvent::Type type
,
628 WebMouseEvent event
=
629 SyntheticWebMouseEventBuilder::Build(type
, x
, y
, modifiers
);
631 event
.button
= WebMouseEvent::ButtonLeft
;
632 widget_host_
->ForwardMouseEvent(event
);
635 void SimulateWheelEventWithPhase(WebMouseWheelEvent::Phase phase
) {
636 widget_host_
->ForwardWheelEvent(
637 SyntheticWebMouseWheelEventBuilder::Build(phase
));
640 // Inject provided synthetic WebGestureEvent instance.
641 void SimulateGestureEventCore(const WebGestureEvent
& gesture_event
) {
642 widget_host_
->ForwardGestureEvent(gesture_event
);
645 void SimulateGestureEventCoreWithLatencyInfo(
646 const WebGestureEvent
& gesture_event
,
647 const ui::LatencyInfo
& ui_latency
) {
648 widget_host_
->ForwardGestureEventWithLatencyInfo(gesture_event
, ui_latency
);
651 // Inject simple synthetic WebGestureEvent instances.
652 void SimulateGestureEvent(WebInputEvent::Type type
,
653 blink::WebGestureDevice sourceDevice
) {
654 SimulateGestureEventCore(
655 SyntheticWebGestureEventBuilder::Build(type
, sourceDevice
));
658 void SimulateGestureEventWithLatencyInfo(WebInputEvent::Type type
,
659 blink::WebGestureDevice sourceDevice
,
660 const ui::LatencyInfo
& ui_latency
) {
661 SimulateGestureEventCoreWithLatencyInfo(
662 SyntheticWebGestureEventBuilder::Build(type
, sourceDevice
), ui_latency
);
665 void SimulateGestureScrollUpdateEvent(float dX
, float dY
, int modifiers
) {
666 SimulateGestureEventCore(SyntheticWebGestureEventBuilder::BuildScrollUpdate(
667 dX
, dY
, modifiers
, blink::WebGestureDeviceTouchscreen
));
670 void SimulateGesturePinchUpdateEvent(float scale
,
674 SimulateGestureEventCore(SyntheticWebGestureEventBuilder::BuildPinchUpdate(
679 blink::WebGestureDeviceTouchscreen
));
682 // Inject synthetic GestureFlingStart events.
683 void SimulateGestureFlingStartEvent(float velocityX
,
685 blink::WebGestureDevice sourceDevice
) {
686 SimulateGestureEventCore(SyntheticWebGestureEventBuilder::BuildFling(
687 velocityX
, velocityY
, sourceDevice
));
690 bool ScrollStateIsContentScrolling() const {
691 return scroll_state() == OverscrollController::STATE_CONTENT_SCROLLING
;
694 bool ScrollStateIsOverscrolling() const {
695 return scroll_state() == OverscrollController::STATE_OVERSCROLLING
;
698 bool ScrollStateIsUnknown() const {
699 return scroll_state() == OverscrollController::STATE_UNKNOWN
;
702 OverscrollController::ScrollState
scroll_state() const {
703 return view_
->overscroll_controller()->scroll_state_
;
706 OverscrollMode
overscroll_mode() const {
707 return view_
->overscroll_controller()->overscroll_mode_
;
710 float overscroll_delta_x() const {
711 return view_
->overscroll_controller()->overscroll_delta_x_
;
714 float overscroll_delta_y() const {
715 return view_
->overscroll_controller()->overscroll_delta_y_
;
718 TestOverscrollDelegate
* overscroll_delegate() {
719 return overscroll_delegate_
.get();
722 uint32
SendTouchEvent() {
723 uint32 touch_event_id
= touch_event_
.uniqueTouchEventId
;
724 widget_host_
->ForwardTouchEventWithLatencyInfo(touch_event_
,
726 touch_event_
.ResetPoints();
727 return touch_event_id
;
730 void PressTouchPoint(int x
, int y
) {
731 touch_event_
.PressPoint(x
, y
);
734 void MoveTouchPoint(int index
, int x
, int y
) {
735 touch_event_
.MovePoint(index
, x
, y
);
738 void ReleaseTouchPoint(int index
) {
739 touch_event_
.ReleasePoint(index
);
742 SyntheticWebTouchEvent touch_event_
;
744 scoped_ptr
<TestOverscrollDelegate
> overscroll_delegate_
;
747 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraOverscrollTest
);
750 class RenderWidgetHostViewAuraShutdownTest
751 : public RenderWidgetHostViewAuraTest
{
753 RenderWidgetHostViewAuraShutdownTest() {}
755 void TearDown() override
{
756 // No TearDownEnvironment here, we do this explicitly during the test.
760 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraShutdownTest
);
763 // Checks that a fullscreen view has the correct show-state and receives the
765 TEST_F(RenderWidgetHostViewAuraTest
, FocusFullscreen
) {
766 view_
->InitAsFullscreen(parent_view_
);
767 aura::Window
* window
= view_
->GetNativeView();
768 ASSERT_TRUE(window
!= NULL
);
769 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN
,
770 window
->GetProperty(aura::client::kShowStateKey
));
772 // Check that we requested and received the focus.
773 EXPECT_TRUE(window
->HasFocus());
775 // Check that we'll also say it's okay to activate the window when there's an
776 // ActivationClient defined.
777 EXPECT_TRUE(view_
->ShouldActivate());
780 // Checks that a popup is positioned correctly relative to its parent using
781 // screen coordinates.
782 TEST_F(RenderWidgetHostViewAuraTest
, PositionChildPopup
) {
783 wm::DefaultScreenPositionClient screen_position_client
;
785 aura::Window
* window
= parent_view_
->GetNativeView();
786 aura::Window
* root
= window
->GetRootWindow();
787 aura::client::SetScreenPositionClient(root
, &screen_position_client
);
789 parent_view_
->SetBounds(gfx::Rect(10, 10, 800, 600));
790 gfx::Rect bounds_in_screen
= parent_view_
->GetViewBounds();
791 int horiz
= bounds_in_screen
.width() / 4;
792 int vert
= bounds_in_screen
.height() / 4;
793 bounds_in_screen
.Inset(horiz
, vert
);
795 // Verify that when the popup is initialized for the first time, it correctly
796 // treats the input bounds as screen coordinates.
797 view_
->InitAsPopup(parent_view_
, bounds_in_screen
);
799 gfx::Rect final_bounds_in_screen
= view_
->GetViewBounds();
800 EXPECT_EQ(final_bounds_in_screen
.ToString(), bounds_in_screen
.ToString());
802 // Verify that directly setting the bounds via SetBounds() treats the input
803 // as screen coordinates.
804 bounds_in_screen
= gfx::Rect(60, 60, 100, 100);
805 view_
->SetBounds(bounds_in_screen
);
806 final_bounds_in_screen
= view_
->GetViewBounds();
807 EXPECT_EQ(final_bounds_in_screen
.ToString(), bounds_in_screen
.ToString());
809 // Verify that setting the size does not alter the origin.
810 gfx::Point original_origin
= window
->bounds().origin();
811 view_
->SetSize(gfx::Size(120, 120));
812 gfx::Point new_origin
= window
->bounds().origin();
813 EXPECT_EQ(original_origin
.ToString(), new_origin
.ToString());
815 aura::client::SetScreenPositionClient(root
, NULL
);
818 // Checks that moving parent sends new screen bounds.
819 TEST_F(RenderWidgetHostViewAuraTest
, ParentMovementUpdatesScreenRect
) {
820 view_
->InitAsChild(NULL
);
822 aura::Window
* root
= parent_view_
->GetNativeView()->GetRootWindow();
824 aura::test::TestWindowDelegate delegate1
, delegate2
;
825 scoped_ptr
<aura::Window
> parent1(new aura::Window(&delegate1
));
826 parent1
->Init(ui::LAYER_TEXTURED
);
828 scoped_ptr
<aura::Window
> parent2(new aura::Window(&delegate2
));
829 parent2
->Init(ui::LAYER_TEXTURED
);
832 root
->AddChild(parent1
.get());
833 parent1
->AddChild(parent2
.get());
834 parent2
->AddChild(view_
->GetNativeView());
836 root
->SetBounds(gfx::Rect(0, 0, 800, 600));
837 parent1
->SetBounds(gfx::Rect(1, 1, 300, 300));
838 parent2
->SetBounds(gfx::Rect(2, 2, 200, 200));
839 view_
->SetBounds(gfx::Rect(3, 3, 100, 100));
840 // view_ will be destroyed when parent is destroyed.
843 // Flush the state after initial setup is done.
844 widget_host_
->OnMessageReceived(
845 ViewHostMsg_UpdateScreenRects_ACK(widget_host_
->GetRoutingID()));
846 widget_host_
->OnMessageReceived(
847 ViewHostMsg_UpdateScreenRects_ACK(widget_host_
->GetRoutingID()));
848 sink_
->ClearMessages();
851 parent2
->SetBounds(gfx::Rect(20, 20, 200, 200));
852 ASSERT_EQ(1U, sink_
->message_count());
853 const IPC::Message
* msg
= sink_
->GetMessageAt(0);
854 ASSERT_EQ(ViewMsg_UpdateScreenRects::ID
, msg
->type());
855 ViewMsg_UpdateScreenRects::Param params
;
856 ViewMsg_UpdateScreenRects::Read(msg
, ¶ms
);
857 EXPECT_EQ(gfx::Rect(24, 24, 100, 100), base::get
<0>(params
));
858 EXPECT_EQ(gfx::Rect(1, 1, 300, 300), base::get
<1>(params
));
859 sink_
->ClearMessages();
860 widget_host_
->OnMessageReceived(
861 ViewHostMsg_UpdateScreenRects_ACK(widget_host_
->GetRoutingID()));
862 // There should not be any pending update.
863 EXPECT_EQ(0U, sink_
->message_count());
865 parent1
->SetBounds(gfx::Rect(10, 10, 300, 300));
866 ASSERT_EQ(1U, sink_
->message_count());
867 msg
= sink_
->GetMessageAt(0);
868 ASSERT_EQ(ViewMsg_UpdateScreenRects::ID
, msg
->type());
869 ViewMsg_UpdateScreenRects::Read(msg
, ¶ms
);
870 EXPECT_EQ(gfx::Rect(33, 33, 100, 100), base::get
<0>(params
));
871 EXPECT_EQ(gfx::Rect(10, 10, 300, 300), base::get
<1>(params
));
872 sink_
->ClearMessages();
873 widget_host_
->OnMessageReceived(
874 ViewHostMsg_UpdateScreenRects_ACK(widget_host_
->GetRoutingID()));
875 // There should not be any pending update.
876 EXPECT_EQ(0U, sink_
->message_count());
879 // Checks that a fullscreen view is destroyed when it loses the focus.
880 TEST_F(RenderWidgetHostViewAuraTest
, DestroyFullscreenOnBlur
) {
881 view_
->InitAsFullscreen(parent_view_
);
882 aura::Window
* window
= view_
->GetNativeView();
883 ASSERT_TRUE(window
!= NULL
);
884 ASSERT_TRUE(window
->HasFocus());
886 // After we create and focus another window, the RWHVA's window should be
888 TestWindowObserver
observer(window
);
889 aura::test::TestWindowDelegate delegate
;
890 scoped_ptr
<aura::Window
> sibling(new aura::Window(&delegate
));
891 sibling
->Init(ui::LAYER_TEXTURED
);
893 window
->parent()->AddChild(sibling
.get());
895 ASSERT_TRUE(sibling
->HasFocus());
896 ASSERT_TRUE(observer
.destroyed());
902 // Checks that a popup view is destroyed when a user clicks outside of the popup
903 // view and focus does not change. This is the case when the user clicks on the
904 // desktop background on Chrome OS.
905 TEST_F(RenderWidgetHostViewAuraTest
, DestroyPopupClickOutsidePopup
) {
906 parent_view_
->SetBounds(gfx::Rect(10, 10, 400, 400));
907 parent_view_
->Focus();
908 EXPECT_TRUE(parent_view_
->HasFocus());
910 view_
->InitAsPopup(parent_view_
, gfx::Rect(10, 10, 100, 100));
911 aura::Window
* window
= view_
->GetNativeView();
912 ASSERT_TRUE(window
!= NULL
);
914 gfx::Point click_point
;
915 EXPECT_FALSE(window
->GetBoundsInRootWindow().Contains(click_point
));
916 aura::Window
* parent_window
= parent_view_
->GetNativeView();
917 EXPECT_FALSE(parent_window
->GetBoundsInRootWindow().Contains(click_point
));
919 TestWindowObserver
observer(window
);
920 ui::test::EventGenerator
generator(window
->GetRootWindow(), click_point
);
921 generator
.ClickLeftButton();
922 ASSERT_TRUE(parent_view_
->HasFocus());
923 ASSERT_TRUE(observer
.destroyed());
929 // Checks that a popup view is destroyed when a user taps outside of the popup
930 // view and focus does not change. This is the case when the user taps the
931 // desktop background on Chrome OS.
932 TEST_F(RenderWidgetHostViewAuraTest
, DestroyPopupTapOutsidePopup
) {
933 parent_view_
->SetBounds(gfx::Rect(10, 10, 400, 400));
934 parent_view_
->Focus();
935 EXPECT_TRUE(parent_view_
->HasFocus());
937 view_
->InitAsPopup(parent_view_
, gfx::Rect(10, 10, 100, 100));
938 aura::Window
* window
= view_
->GetNativeView();
939 ASSERT_TRUE(window
!= NULL
);
941 gfx::Point tap_point
;
942 EXPECT_FALSE(window
->GetBoundsInRootWindow().Contains(tap_point
));
943 aura::Window
* parent_window
= parent_view_
->GetNativeView();
944 EXPECT_FALSE(parent_window
->GetBoundsInRootWindow().Contains(tap_point
));
946 TestWindowObserver
observer(window
);
947 ui::test::EventGenerator
generator(window
->GetRootWindow(), tap_point
);
948 generator
.GestureTapAt(tap_point
);
949 ASSERT_TRUE(parent_view_
->HasFocus());
950 ASSERT_TRUE(observer
.destroyed());
956 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
958 // On Desktop Linux, select boxes need mouse capture in order to work. Test that
959 // when a select box is opened via a mouse press that it retains mouse capture
960 // after the mouse is released.
961 TEST_F(RenderWidgetHostViewAuraTest
, PopupRetainsCaptureAfterMouseRelease
) {
962 parent_view_
->SetBounds(gfx::Rect(10, 10, 400, 400));
963 parent_view_
->Focus();
964 EXPECT_TRUE(parent_view_
->HasFocus());
966 ui::test::EventGenerator
generator(
967 parent_view_
->GetNativeView()->GetRootWindow(), gfx::Point(300, 300));
968 generator
.PressLeftButton();
970 view_
->SetPopupType(blink::WebPopupTypePage
);
971 view_
->InitAsPopup(parent_view_
, gfx::Rect(10, 10, 100, 100));
972 ASSERT_TRUE(view_
->NeedsMouseCapture());
973 aura::Window
* window
= view_
->GetNativeView();
974 EXPECT_TRUE(window
->HasCapture());
976 generator
.ReleaseLeftButton();
977 EXPECT_TRUE(window
->HasCapture());
981 // Test that select boxes close when their parent window loses focus (e.g. due
982 // to an alert or system modal dialog).
983 TEST_F(RenderWidgetHostViewAuraTest
, PopupClosesWhenParentLosesFocus
) {
984 parent_view_
->SetBounds(gfx::Rect(10, 10, 400, 400));
985 parent_view_
->Focus();
986 EXPECT_TRUE(parent_view_
->HasFocus());
988 view_
->SetPopupType(blink::WebPopupTypePage
);
989 view_
->InitAsPopup(parent_view_
, gfx::Rect(10, 10, 100, 100));
991 aura::Window
* popup_window
= view_
->GetNativeView();
992 TestWindowObserver
observer(popup_window
);
994 aura::test::TestWindowDelegate delegate
;
995 scoped_ptr
<aura::Window
> dialog_window(new aura::Window(&delegate
));
996 dialog_window
->Init(ui::LAYER_TEXTURED
);
997 aura::client::ParentWindowWithContext(
998 dialog_window
.get(), popup_window
, gfx::Rect());
999 dialog_window
->Show();
1000 wm::ActivateWindow(dialog_window
.get());
1001 dialog_window
->Focus();
1003 ASSERT_TRUE(wm::IsActiveWindow(dialog_window
.get()));
1004 EXPECT_TRUE(observer
.destroyed());
1006 widget_host_
= NULL
;
1010 // Checks that IME-composition-event state is maintained correctly.
1011 TEST_F(RenderWidgetHostViewAuraTest
, SetCompositionText
) {
1012 view_
->InitAsChild(NULL
);
1015 ui::CompositionText composition_text
;
1016 composition_text
.text
= base::ASCIIToUTF16("|a|b");
1019 composition_text
.underlines
.push_back(
1020 ui::CompositionUnderline(0, 3, 0xff000000, true, 0x78563412));
1022 // Non-focused segment, with different background color.
1023 composition_text
.underlines
.push_back(
1024 ui::CompositionUnderline(3, 4, 0xff000000, false, 0xefcdab90));
1026 const ui::CompositionUnderlines
& underlines
= composition_text
.underlines
;
1028 // Caret is at the end. (This emulates Japanese MSIME 2007 and later)
1029 composition_text
.selection
= gfx::Range(4);
1031 sink_
->ClearMessages();
1032 view_
->SetCompositionText(composition_text
);
1033 EXPECT_TRUE(view_
->has_composition_text_
);
1035 const IPC::Message
* msg
=
1036 sink_
->GetFirstMessageMatching(InputMsg_ImeSetComposition::ID
);
1037 ASSERT_TRUE(msg
!= NULL
);
1039 InputMsg_ImeSetComposition::Param params
;
1040 InputMsg_ImeSetComposition::Read(msg
, ¶ms
);
1042 EXPECT_EQ(composition_text
.text
, base::get
<0>(params
));
1044 ASSERT_EQ(underlines
.size(), base::get
<1>(params
).size());
1045 for (size_t i
= 0; i
< underlines
.size(); ++i
) {
1046 EXPECT_EQ(underlines
[i
].start_offset
,
1047 base::get
<1>(params
)[i
].startOffset
);
1048 EXPECT_EQ(underlines
[i
].end_offset
, base::get
<1>(params
)[i
].endOffset
);
1049 EXPECT_EQ(underlines
[i
].color
, base::get
<1>(params
)[i
].color
);
1050 EXPECT_EQ(underlines
[i
].thick
, base::get
<1>(params
)[i
].thick
);
1051 EXPECT_EQ(underlines
[i
].background_color
,
1052 base::get
<1>(params
)[i
].backgroundColor
);
1054 // highlighted range
1055 EXPECT_EQ(4, base::get
<2>(params
)) << "Should be the same to the caret pos";
1056 EXPECT_EQ(4, base::get
<3>(params
)) << "Should be the same to the caret pos";
1059 view_
->ImeCancelComposition();
1060 EXPECT_FALSE(view_
->has_composition_text_
);
1063 // Checks that sequence of IME-composition-event and mouse-event when mouse
1064 // clicking to cancel the composition.
1065 TEST_F(RenderWidgetHostViewAuraTest
, FinishCompositionByMouse
) {
1066 view_
->InitAsChild(NULL
);
1069 ui::CompositionText composition_text
;
1070 composition_text
.text
= base::ASCIIToUTF16("|a|b");
1073 composition_text
.underlines
.push_back(
1074 ui::CompositionUnderline(0, 3, 0xff000000, true, 0x78563412));
1076 // Non-focused segment, with different background color.
1077 composition_text
.underlines
.push_back(
1078 ui::CompositionUnderline(3, 4, 0xff000000, false, 0xefcdab90));
1080 // Caret is at the end. (This emulates Japanese MSIME 2007 and later)
1081 composition_text
.selection
= gfx::Range(4);
1083 view_
->SetCompositionText(composition_text
);
1084 EXPECT_TRUE(view_
->has_composition_text_
);
1085 sink_
->ClearMessages();
1087 // Simulates the mouse press.
1088 ui::MouseEvent
mouse_event(ui::ET_MOUSE_PRESSED
, gfx::Point(), gfx::Point(),
1089 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON
,
1091 view_
->OnMouseEvent(&mouse_event
);
1093 EXPECT_FALSE(view_
->has_composition_text_
);
1095 EXPECT_EQ(2U, sink_
->message_count());
1097 if (sink_
->message_count() == 2) {
1098 // Verify mouse event happens after the confirm-composition event.
1099 EXPECT_EQ(InputMsg_ImeConfirmComposition::ID
,
1100 sink_
->GetMessageAt(0)->type());
1101 EXPECT_EQ(InputMsg_HandleInputEvent::ID
,
1102 sink_
->GetMessageAt(1)->type());
1106 // Checks that touch-event state is maintained correctly.
1107 TEST_F(RenderWidgetHostViewAuraTest
, TouchEventState
) {
1108 view_
->InitAsChild(NULL
);
1110 GetSentMessageCountAndResetSink();
1112 // Start with no touch-event handler in the renderer.
1113 widget_host_
->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, false));
1115 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
,
1118 ui::EventTimeForNow());
1119 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
,
1122 ui::EventTimeForNow());
1123 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
,
1126 ui::EventTimeForNow());
1128 // The touch events should get forwared from the view, but they should not
1129 // reach the renderer.
1130 view_
->OnTouchEvent(&press
);
1131 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1132 EXPECT_TRUE(press
.synchronous_handling_disabled());
1133 EXPECT_EQ(blink::WebInputEvent::TouchStart
, view_
->touch_event_
->type
);
1134 EXPECT_TRUE(view_
->touch_event_
->cancelable
);
1135 EXPECT_EQ(1U, view_
->touch_event_
->touchesLength
);
1136 EXPECT_EQ(blink::WebTouchPoint::StatePressed
,
1137 view_
->touch_event_
->touches
[0].state
);
1139 view_
->OnTouchEvent(&move
);
1140 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1141 EXPECT_TRUE(press
.synchronous_handling_disabled());
1142 EXPECT_EQ(blink::WebInputEvent::TouchMove
, view_
->touch_event_
->type
);
1143 EXPECT_TRUE(view_
->touch_event_
->cancelable
);
1144 EXPECT_EQ(1U, view_
->touch_event_
->touchesLength
);
1145 EXPECT_EQ(blink::WebTouchPoint::StateMoved
,
1146 view_
->touch_event_
->touches
[0].state
);
1148 view_
->OnTouchEvent(&release
);
1149 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1150 EXPECT_TRUE(press
.synchronous_handling_disabled());
1151 EXPECT_EQ(nullptr, view_
->touch_event_
);
1153 // Now install some touch-event handlers and do the same steps. The touch
1154 // events should now be consumed. However, the touch-event state should be
1155 // updated as before.
1156 widget_host_
->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
1158 view_
->OnTouchEvent(&press
);
1159 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1160 EXPECT_TRUE(press
.synchronous_handling_disabled());
1161 EXPECT_EQ(blink::WebInputEvent::TouchStart
, view_
->touch_event_
->type
);
1162 EXPECT_TRUE(view_
->touch_event_
->cancelable
);
1163 EXPECT_EQ(1U, view_
->touch_event_
->touchesLength
);
1164 EXPECT_EQ(blink::WebTouchPoint::StatePressed
,
1165 view_
->touch_event_
->touches
[0].state
);
1167 view_
->OnTouchEvent(&move
);
1168 EXPECT_TRUE(move
.synchronous_handling_disabled());
1169 EXPECT_EQ(blink::WebInputEvent::TouchMove
, view_
->touch_event_
->type
);
1170 EXPECT_TRUE(view_
->touch_event_
->cancelable
);
1171 EXPECT_EQ(1U, view_
->touch_event_
->touchesLength
);
1172 EXPECT_EQ(blink::WebTouchPoint::StateMoved
,
1173 view_
->touch_event_
->touches
[0].state
);
1174 view_
->OnTouchEvent(&release
);
1175 EXPECT_TRUE(release
.synchronous_handling_disabled());
1176 EXPECT_EQ(nullptr, view_
->touch_event_
);
1178 // Now start a touch event, and remove the event-handlers before the release.
1179 view_
->OnTouchEvent(&press
);
1180 EXPECT_TRUE(press
.synchronous_handling_disabled());
1181 EXPECT_EQ(blink::WebInputEvent::TouchStart
, view_
->touch_event_
->type
);
1182 EXPECT_EQ(1U, view_
->touch_event_
->touchesLength
);
1183 EXPECT_EQ(blink::WebTouchPoint::StatePressed
,
1184 view_
->touch_event_
->touches
[0].state
);
1186 widget_host_
->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, false));
1188 // Ack'ing the outstanding event should flush the pending touch queue.
1189 InputEventAck
ack(blink::WebInputEvent::TouchStart
,
1190 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS
,
1191 press
.unique_event_id());
1192 widget_host_
->OnMessageReceived(InputHostMsg_HandleInputEvent_ACK(0, ack
));
1193 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1195 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(20, 20), 0,
1196 base::Time::NowFromSystemTime() - base::Time());
1197 view_
->OnTouchEvent(&move2
);
1198 EXPECT_TRUE(press
.synchronous_handling_disabled());
1199 EXPECT_EQ(blink::WebInputEvent::TouchMove
, view_
->touch_event_
->type
);
1200 EXPECT_EQ(1U, view_
->touch_event_
->touchesLength
);
1201 EXPECT_EQ(blink::WebTouchPoint::StateMoved
,
1202 view_
->touch_event_
->touches
[0].state
);
1204 ui::TouchEvent
release2(ui::ET_TOUCH_RELEASED
, gfx::Point(20, 20), 0,
1205 base::Time::NowFromSystemTime() - base::Time());
1206 view_
->OnTouchEvent(&release2
);
1207 EXPECT_TRUE(press
.synchronous_handling_disabled());
1208 EXPECT_EQ(nullptr, view_
->touch_event_
);
1211 // Checks that touch-event state is maintained correctly for multiple touch
1213 TEST_F(RenderWidgetHostViewAuraTest
, MultiTouchPointsStates
) {
1214 view_
->InitAsFullscreen(parent_view_
);
1216 view_
->UseFakeDispatcher();
1217 GetSentMessageCountAndResetSink();
1219 ui::TouchEvent
press0(ui::ET_TOUCH_PRESSED
, gfx::Point(30, 30), 0,
1220 ui::EventTimeForNow());
1222 view_
->OnTouchEvent(&press0
);
1223 SendTouchEventACK(blink::WebInputEvent::TouchStart
,
1224 INPUT_EVENT_ACK_STATE_CONSUMED
,
1225 press0
.unique_event_id());
1226 EXPECT_EQ(blink::WebInputEvent::TouchStart
, view_
->touch_event_
->type
);
1227 EXPECT_EQ(1U, view_
->touch_event_
->touchesLength
);
1228 EXPECT_EQ(1U, view_
->dispatcher_
->GetAndResetProcessedTouchEventCount());
1230 ui::TouchEvent
move0(ui::ET_TOUCH_MOVED
, gfx::Point(20, 20), 0,
1231 ui::EventTimeForNow());
1233 view_
->OnTouchEvent(&move0
);
1234 SendTouchEventACK(blink::WebInputEvent::TouchMove
,
1235 INPUT_EVENT_ACK_STATE_CONSUMED
,
1236 move0
.unique_event_id());
1237 EXPECT_EQ(blink::WebInputEvent::TouchMove
, view_
->touch_event_
->type
);
1238 EXPECT_EQ(1U, view_
->touch_event_
->touchesLength
);
1239 EXPECT_EQ(1U, view_
->dispatcher_
->GetAndResetProcessedTouchEventCount());
1241 // For the second touchstart, only the state of the second touch point is
1242 // StatePressed, the state of the first touch point is StateStationary.
1243 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(10, 10), 1,
1244 ui::EventTimeForNow());
1246 view_
->OnTouchEvent(&press1
);
1247 SendTouchEventACK(blink::WebInputEvent::TouchStart
,
1248 INPUT_EVENT_ACK_STATE_CONSUMED
,
1249 press1
.unique_event_id());
1250 EXPECT_EQ(blink::WebInputEvent::TouchStart
, view_
->touch_event_
->type
);
1251 EXPECT_EQ(2U, view_
->touch_event_
->touchesLength
);
1252 EXPECT_EQ(1U, view_
->dispatcher_
->GetAndResetProcessedTouchEventCount());
1254 // For the touchmove of second point, the state of the second touch point is
1255 // StateMoved, the state of the first touch point is StateStationary.
1256 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
, gfx::Point(30, 30), 1,
1257 ui::EventTimeForNow());
1259 view_
->OnTouchEvent(&move1
);
1260 SendTouchEventACK(blink::WebInputEvent::TouchMove
,
1261 INPUT_EVENT_ACK_STATE_CONSUMED
,
1262 move1
.unique_event_id());
1263 EXPECT_EQ(blink::WebInputEvent::TouchMove
, view_
->touch_event_
->type
);
1264 EXPECT_EQ(2U, view_
->touch_event_
->touchesLength
);
1265 EXPECT_EQ(1U, view_
->dispatcher_
->GetAndResetProcessedTouchEventCount());
1267 // For the touchmove of first point, the state of the first touch point is
1268 // StateMoved, the state of the second touch point is StateStationary.
1269 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(10, 10), 0,
1270 ui::EventTimeForNow());
1272 view_
->OnTouchEvent(&move2
);
1273 SendTouchEventACK(blink::WebInputEvent::TouchMove
,
1274 INPUT_EVENT_ACK_STATE_CONSUMED
,
1275 move2
.unique_event_id());
1276 EXPECT_EQ(blink::WebInputEvent::TouchMove
, view_
->touch_event_
->type
);
1277 EXPECT_EQ(2U, view_
->touch_event_
->touchesLength
);
1278 EXPECT_EQ(1U, view_
->dispatcher_
->GetAndResetProcessedTouchEventCount());
1280 ui::TouchEvent
cancel0(ui::ET_TOUCH_CANCELLED
, gfx::Point(10, 10), 0,
1281 ui::EventTimeForNow());
1283 // For the touchcancel, only the state of the current touch point is
1284 // StateCancelled, the state of the other touch point is StateStationary.
1285 view_
->OnTouchEvent(&cancel0
);
1286 EXPECT_EQ(blink::WebInputEvent::TouchCancel
, view_
-> touch_event_
->type
);
1287 EXPECT_EQ(1U, view_
->touch_event_
->touchesLength
);
1288 EXPECT_EQ(1U, view_
->dispatcher_
->GetAndResetProcessedTouchEventCount());
1290 ui::TouchEvent
cancel1(ui::ET_TOUCH_CANCELLED
, gfx::Point(30, 30), 1,
1291 ui::EventTimeForNow());
1293 view_
->OnTouchEvent(&cancel1
);
1294 EXPECT_EQ(1U, view_
->dispatcher_
->GetAndResetProcessedTouchEventCount());
1295 EXPECT_EQ(nullptr, view_
->touch_event_
);
1298 // Checks that touch-events are queued properly when there is a touch-event
1299 // handler on the page.
1300 TEST_F(RenderWidgetHostViewAuraTest
, TouchEventSyncAsync
) {
1301 view_
->InitAsChild(NULL
);
1304 widget_host_
->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
1306 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
,
1309 ui::EventTimeForNow());
1310 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
,
1313 ui::EventTimeForNow());
1314 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
,
1317 ui::EventTimeForNow());
1319 view_
->OnTouchEvent(&press
);
1320 EXPECT_TRUE(press
.synchronous_handling_disabled());
1321 EXPECT_EQ(blink::WebInputEvent::TouchStart
, view_
->touch_event_
->type
);
1322 EXPECT_EQ(1U, view_
->touch_event_
->touchesLength
);
1323 EXPECT_EQ(blink::WebTouchPoint::StatePressed
,
1324 view_
->touch_event_
->touches
[0].state
);
1326 view_
->OnTouchEvent(&move
);
1327 EXPECT_TRUE(move
.synchronous_handling_disabled());
1328 EXPECT_EQ(blink::WebInputEvent::TouchMove
, view_
->touch_event_
->type
);
1329 EXPECT_EQ(1U, view_
->touch_event_
->touchesLength
);
1330 EXPECT_EQ(blink::WebTouchPoint::StateMoved
,
1331 view_
->touch_event_
->touches
[0].state
);
1333 // Send the same move event. Since the point hasn't moved, it won't affect the
1334 // queue. However, the view should consume the event.
1335 view_
->OnTouchEvent(&move
);
1336 EXPECT_TRUE(move
.synchronous_handling_disabled());
1337 EXPECT_EQ(blink::WebInputEvent::TouchMove
, view_
->touch_event_
->type
);
1338 EXPECT_EQ(1U, view_
->touch_event_
->touchesLength
);
1339 EXPECT_EQ(blink::WebTouchPoint::StateMoved
,
1340 view_
->touch_event_
->touches
[0].state
);
1342 view_
->OnTouchEvent(&release
);
1343 EXPECT_TRUE(release
.synchronous_handling_disabled());
1344 EXPECT_EQ(nullptr, view_
->touch_event_
);
1347 TEST_F(RenderWidgetHostViewAuraTest
, PhysicalBackingSizeWithScale
) {
1348 view_
->InitAsChild(NULL
);
1349 aura::client::ParentWindowWithContext(
1350 view_
->GetNativeView(),
1351 parent_view_
->GetNativeView()->GetRootWindow(),
1353 sink_
->ClearMessages();
1354 view_
->SetSize(gfx::Size(100, 100));
1355 EXPECT_EQ("100x100", view_
->GetPhysicalBackingSize().ToString());
1356 EXPECT_EQ(1u, sink_
->message_count());
1357 EXPECT_EQ(ViewMsg_Resize::ID
, sink_
->GetMessageAt(0)->type());
1359 const IPC::Message
* msg
= sink_
->GetMessageAt(0);
1360 EXPECT_EQ(ViewMsg_Resize::ID
, msg
->type());
1361 ViewMsg_Resize::Param params
;
1362 ViewMsg_Resize::Read(msg
, ¶ms
);
1363 EXPECT_EQ("100x100", base::get
<0>(params
).new_size
.ToString()); // dip size
1364 EXPECT_EQ("100x100",
1365 base::get
<0>(params
).physical_backing_size
.ToString()); // backing size
1368 widget_host_
->ResetSizeAndRepaintPendingFlags();
1369 sink_
->ClearMessages();
1371 aura_test_helper_
->test_screen()->SetDeviceScaleFactor(2.0f
);
1372 EXPECT_EQ("200x200", view_
->GetPhysicalBackingSize().ToString());
1373 // Extra ScreenInfoChanged message for |parent_view_|.
1374 EXPECT_EQ(1u, sink_
->message_count());
1376 const IPC::Message
* msg
= sink_
->GetMessageAt(0);
1377 EXPECT_EQ(ViewMsg_Resize::ID
, msg
->type());
1378 ViewMsg_Resize::Param params
;
1379 ViewMsg_Resize::Read(msg
, ¶ms
);
1380 EXPECT_EQ(2.0f
, base::get
<0>(params
).screen_info
.deviceScaleFactor
);
1381 EXPECT_EQ("100x100", base::get
<0>(params
).new_size
.ToString()); // dip size
1382 EXPECT_EQ("200x200",
1383 base::get
<0>(params
).physical_backing_size
.ToString()); // backing size
1386 widget_host_
->ResetSizeAndRepaintPendingFlags();
1387 sink_
->ClearMessages();
1389 aura_test_helper_
->test_screen()->SetDeviceScaleFactor(1.0f
);
1390 // Extra ScreenInfoChanged message for |parent_view_|.
1391 EXPECT_EQ(1u, sink_
->message_count());
1392 EXPECT_EQ("100x100", view_
->GetPhysicalBackingSize().ToString());
1394 const IPC::Message
* msg
= sink_
->GetMessageAt(0);
1395 EXPECT_EQ(ViewMsg_Resize::ID
, msg
->type());
1396 ViewMsg_Resize::Param params
;
1397 ViewMsg_Resize::Read(msg
, ¶ms
);
1398 EXPECT_EQ(1.0f
, base::get
<0>(params
).screen_info
.deviceScaleFactor
);
1399 EXPECT_EQ("100x100", base::get
<0>(params
).new_size
.ToString()); // dip size
1400 EXPECT_EQ("100x100",
1401 base::get
<0>(params
).physical_backing_size
.ToString()); // backing size
1405 // Checks that InputMsg_CursorVisibilityChange IPC messages are dispatched
1406 // to the renderer at the correct times.
1407 TEST_F(RenderWidgetHostViewAuraTest
, CursorVisibilityChange
) {
1408 view_
->InitAsChild(NULL
);
1409 aura::client::ParentWindowWithContext(
1410 view_
->GetNativeView(),
1411 parent_view_
->GetNativeView()->GetRootWindow(),
1413 view_
->SetSize(gfx::Size(100, 100));
1415 aura::test::TestCursorClient
cursor_client(
1416 parent_view_
->GetNativeView()->GetRootWindow());
1418 cursor_client
.AddObserver(view_
);
1420 // Expect a message the first time the cursor is shown.
1422 sink_
->ClearMessages();
1423 cursor_client
.ShowCursor();
1424 EXPECT_EQ(1u, sink_
->message_count());
1425 EXPECT_TRUE(sink_
->GetUniqueMessageMatching(
1426 InputMsg_CursorVisibilityChange::ID
));
1428 // No message expected if the renderer already knows the cursor is visible.
1429 sink_
->ClearMessages();
1430 cursor_client
.ShowCursor();
1431 EXPECT_EQ(0u, sink_
->message_count());
1433 // Hiding the cursor should send a message.
1434 sink_
->ClearMessages();
1435 cursor_client
.HideCursor();
1436 EXPECT_EQ(1u, sink_
->message_count());
1437 EXPECT_TRUE(sink_
->GetUniqueMessageMatching(
1438 InputMsg_CursorVisibilityChange::ID
));
1440 // No message expected if the renderer already knows the cursor is invisible.
1441 sink_
->ClearMessages();
1442 cursor_client
.HideCursor();
1443 EXPECT_EQ(0u, sink_
->message_count());
1445 // No messages should be sent while the view is invisible.
1447 sink_
->ClearMessages();
1448 cursor_client
.ShowCursor();
1449 EXPECT_EQ(0u, sink_
->message_count());
1450 cursor_client
.HideCursor();
1451 EXPECT_EQ(0u, sink_
->message_count());
1453 // Show the view. Since the cursor was invisible when the view was hidden,
1454 // no message should be sent.
1455 sink_
->ClearMessages();
1457 EXPECT_FALSE(sink_
->GetUniqueMessageMatching(
1458 InputMsg_CursorVisibilityChange::ID
));
1460 // No message expected if the renderer already knows the cursor is invisible.
1461 sink_
->ClearMessages();
1462 cursor_client
.HideCursor();
1463 EXPECT_EQ(0u, sink_
->message_count());
1465 // Showing the cursor should send a message.
1466 sink_
->ClearMessages();
1467 cursor_client
.ShowCursor();
1468 EXPECT_EQ(1u, sink_
->message_count());
1469 EXPECT_TRUE(sink_
->GetUniqueMessageMatching(
1470 InputMsg_CursorVisibilityChange::ID
));
1472 // No messages should be sent while the view is invisible.
1474 sink_
->ClearMessages();
1475 cursor_client
.HideCursor();
1476 EXPECT_EQ(0u, sink_
->message_count());
1478 // Show the view. Since the cursor was visible when the view was hidden,
1479 // a message is expected to be sent.
1480 sink_
->ClearMessages();
1482 EXPECT_TRUE(sink_
->GetUniqueMessageMatching(
1483 InputMsg_CursorVisibilityChange::ID
));
1485 cursor_client
.RemoveObserver(view_
);
1488 TEST_F(RenderWidgetHostViewAuraTest
, UpdateCursorIfOverSelf
) {
1489 view_
->InitAsChild(NULL
);
1490 aura::client::ParentWindowWithContext(
1491 view_
->GetNativeView(),
1492 parent_view_
->GetNativeView()->GetRootWindow(),
1495 // Note that all coordinates in this test are screen coordinates.
1496 view_
->SetBounds(gfx::Rect(60, 60, 100, 100));
1499 aura::test::TestCursorClient
cursor_client(
1500 parent_view_
->GetNativeView()->GetRootWindow());
1502 // Cursor is in the middle of the window.
1503 cursor_client
.reset_calls_to_set_cursor();
1504 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(110, 110));
1505 view_
->UpdateCursorIfOverSelf();
1506 EXPECT_EQ(1, cursor_client
.calls_to_set_cursor());
1508 // Cursor is near the top of the window.
1509 cursor_client
.reset_calls_to_set_cursor();
1510 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(80, 65));
1511 view_
->UpdateCursorIfOverSelf();
1512 EXPECT_EQ(1, cursor_client
.calls_to_set_cursor());
1514 // Cursor is near the bottom of the window.
1515 cursor_client
.reset_calls_to_set_cursor();
1516 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(159, 159));
1517 view_
->UpdateCursorIfOverSelf();
1518 EXPECT_EQ(1, cursor_client
.calls_to_set_cursor());
1520 // Cursor is above the window.
1521 cursor_client
.reset_calls_to_set_cursor();
1522 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(67, 59));
1523 view_
->UpdateCursorIfOverSelf();
1524 EXPECT_EQ(0, cursor_client
.calls_to_set_cursor());
1526 // Cursor is below the window.
1527 cursor_client
.reset_calls_to_set_cursor();
1528 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(161, 161));
1529 view_
->UpdateCursorIfOverSelf();
1530 EXPECT_EQ(0, cursor_client
.calls_to_set_cursor());
1533 scoped_ptr
<cc::CompositorFrame
> MakeDelegatedFrame(float scale_factor
,
1536 scoped_ptr
<cc::CompositorFrame
> frame(new cc::CompositorFrame
);
1537 frame
->metadata
.device_scale_factor
= scale_factor
;
1538 frame
->delegated_frame_data
.reset(new cc::DelegatedFrameData
);
1540 scoped_ptr
<cc::RenderPass
> pass
= cc::RenderPass::Create();
1542 cc::RenderPassId(1, 1), gfx::Rect(size
), damage
, gfx::Transform());
1543 frame
->delegated_frame_data
->render_pass_list
.push_back(pass
.Pass());
1544 return frame
.Pass();
1547 // Resizing in fullscreen mode should send the up-to-date screen info.
1548 // http://crbug.com/324350
1549 TEST_F(RenderWidgetHostViewAuraTest
, DISABLED_FullscreenResize
) {
1550 aura::Window
* root_window
= aura_test_helper_
->root_window();
1551 root_window
->SetLayoutManager(new FullscreenLayoutManager(root_window
));
1552 view_
->InitAsFullscreen(parent_view_
);
1554 widget_host_
->ResetSizeAndRepaintPendingFlags();
1555 sink_
->ClearMessages();
1557 // Call WasResized to flush the old screen info.
1558 view_
->GetRenderWidgetHost()->WasResized();
1560 // 0 is CreatingNew message.
1561 const IPC::Message
* msg
= sink_
->GetMessageAt(0);
1562 EXPECT_EQ(ViewMsg_Resize::ID
, msg
->type());
1563 ViewMsg_Resize::Param params
;
1564 ViewMsg_Resize::Read(msg
, ¶ms
);
1565 EXPECT_EQ("0,0 800x600",
1567 base::get
<0>(params
).screen_info
.availableRect
).ToString());
1568 EXPECT_EQ("800x600", base::get
<0>(params
).new_size
.ToString());
1569 // Resizes are blocked until we swapped a frame of the correct size, and
1570 // we've committed it.
1571 view_
->OnSwapCompositorFrame(
1574 1.f
, base::get
<0>(params
).new_size
,
1575 gfx::Rect(base::get
<0>(params
).new_size
)));
1576 ui::DrawWaiterForTest::WaitForCommit(
1577 root_window
->GetHost()->compositor());
1580 widget_host_
->ResetSizeAndRepaintPendingFlags();
1581 sink_
->ClearMessages();
1583 // Make sure the corrent screen size is set along in the resize
1584 // request when the screen size has changed.
1585 aura_test_helper_
->test_screen()->SetUIScale(0.5);
1586 EXPECT_EQ(1u, sink_
->message_count());
1588 const IPC::Message
* msg
= sink_
->GetMessageAt(0);
1589 EXPECT_EQ(ViewMsg_Resize::ID
, msg
->type());
1590 ViewMsg_Resize::Param params
;
1591 ViewMsg_Resize::Read(msg
, ¶ms
);
1592 EXPECT_EQ("0,0 1600x1200",
1594 base::get
<0>(params
).screen_info
.availableRect
).ToString());
1595 EXPECT_EQ("1600x1200", base::get
<0>(params
).new_size
.ToString());
1596 view_
->OnSwapCompositorFrame(
1599 1.f
, base::get
<0>(params
).new_size
,
1600 gfx::Rect(base::get
<0>(params
).new_size
)));
1601 ui::DrawWaiterForTest::WaitForCommit(
1602 root_window
->GetHost()->compositor());
1606 // Swapping a frame should notify the window.
1607 TEST_F(RenderWidgetHostViewAuraTest
, SwapNotifiesWindow
) {
1608 gfx::Size
view_size(100, 100);
1609 gfx::Rect
view_rect(view_size
);
1611 view_
->InitAsChild(NULL
);
1612 aura::client::ParentWindowWithContext(
1613 view_
->GetNativeView(),
1614 parent_view_
->GetNativeView()->GetRootWindow(),
1616 view_
->SetSize(view_size
);
1619 MockWindowObserver observer
;
1620 view_
->window_
->AddObserver(&observer
);
1622 // Delegated renderer path
1623 EXPECT_CALL(observer
, OnDelegatedFrameDamage(view_
->window_
, view_rect
));
1624 view_
->OnSwapCompositorFrame(
1625 0, MakeDelegatedFrame(1.f
, view_size
, view_rect
));
1626 testing::Mock::VerifyAndClearExpectations(&observer
);
1628 EXPECT_CALL(observer
, OnDelegatedFrameDamage(view_
->window_
,
1629 gfx::Rect(5, 5, 5, 5)));
1630 view_
->OnSwapCompositorFrame(
1631 0, MakeDelegatedFrame(1.f
, view_size
, gfx::Rect(5, 5, 5, 5)));
1632 testing::Mock::VerifyAndClearExpectations(&observer
);
1634 view_
->window_
->RemoveObserver(&observer
);
1637 // Recreating the layers for a window should cause Surface destruction to
1638 // depend on both layers.
1639 TEST_F(RenderWidgetHostViewAuraTest
, RecreateLayers
) {
1640 gfx::Size
view_size(100, 100);
1641 gfx::Rect
view_rect(view_size
);
1643 view_
->InitAsChild(NULL
);
1644 aura::client::ParentWindowWithContext(
1645 view_
->GetNativeView(), parent_view_
->GetNativeView()->GetRootWindow(),
1647 view_
->SetSize(view_size
);
1650 view_
->OnSwapCompositorFrame(0,
1651 MakeDelegatedFrame(1.f
, view_size
, view_rect
));
1652 scoped_ptr
<ui::LayerTreeOwner
> cloned_owner(
1653 wm::RecreateLayers(view_
->GetNativeView()));
1655 cc::SurfaceId id
= view_
->GetDelegatedFrameHost()->SurfaceIdForTesting();
1656 if (!id
.is_null()) {
1657 ImageTransportFactory
* factory
= ImageTransportFactory::GetInstance();
1658 cc::SurfaceManager
* manager
= factory
->GetSurfaceManager();
1659 cc::Surface
* surface
= manager
->GetSurfaceForId(id
);
1660 EXPECT_TRUE(surface
);
1661 // Should be a SurfaceSequence for both the original and new layers.
1662 EXPECT_EQ(2u, surface
->GetDestructionDependencyCount());
1666 TEST_F(RenderWidgetHostViewAuraTest
, Resize
) {
1667 gfx::Size
size1(100, 100);
1668 gfx::Size
size2(200, 200);
1669 gfx::Size
size3(300, 300);
1671 aura::Window
* root_window
= parent_view_
->GetNativeView()->GetRootWindow();
1672 view_
->InitAsChild(NULL
);
1673 aura::client::ParentWindowWithContext(
1674 view_
->GetNativeView(), root_window
, gfx::Rect(size1
));
1676 view_
->SetSize(size1
);
1677 view_
->OnSwapCompositorFrame(
1678 0, MakeDelegatedFrame(1.f
, size1
, gfx::Rect(size1
)));
1679 ui::DrawWaiterForTest::WaitForCommit(
1680 root_window
->GetHost()->compositor());
1681 ViewHostMsg_UpdateRect_Params update_params
;
1682 update_params
.view_size
= size1
;
1683 update_params
.flags
= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK
;
1684 widget_host_
->OnMessageReceived(
1685 ViewHostMsg_UpdateRect(widget_host_
->GetRoutingID(), update_params
));
1686 sink_
->ClearMessages();
1687 // Resize logic is idle (no pending resize, no pending commit).
1688 EXPECT_EQ(size1
.ToString(), view_
->GetRequestedRendererSize().ToString());
1690 // Resize renderer, should produce a Resize message
1691 view_
->SetSize(size2
);
1692 EXPECT_EQ(size2
.ToString(), view_
->GetRequestedRendererSize().ToString());
1693 EXPECT_EQ(1u, sink_
->message_count());
1695 const IPC::Message
* msg
= sink_
->GetMessageAt(0);
1696 EXPECT_EQ(ViewMsg_Resize::ID
, msg
->type());
1697 ViewMsg_Resize::Param params
;
1698 ViewMsg_Resize::Read(msg
, ¶ms
);
1699 EXPECT_EQ(size2
.ToString(), base::get
<0>(params
).new_size
.ToString());
1701 // Send resize ack to observe new Resize messages.
1702 update_params
.view_size
= size2
;
1703 widget_host_
->OnMessageReceived(
1704 ViewHostMsg_UpdateRect(widget_host_
->GetRoutingID(), update_params
));
1705 sink_
->ClearMessages();
1707 // Resize renderer again, before receiving a frame. Should not produce a
1709 view_
->SetSize(size3
);
1710 EXPECT_EQ(size2
.ToString(), view_
->GetRequestedRendererSize().ToString());
1711 EXPECT_EQ(0u, sink_
->message_count());
1713 // Receive a frame of the new size, should be skipped and not produce a Resize
1715 view_
->OnSwapCompositorFrame(
1716 0, MakeDelegatedFrame(1.f
, size3
, gfx::Rect(size3
)));
1717 // Expect the frame ack;
1718 EXPECT_EQ(1u, sink_
->message_count());
1719 EXPECT_EQ(ViewMsg_SwapCompositorFrameAck::ID
, sink_
->GetMessageAt(0)->type());
1720 sink_
->ClearMessages();
1721 EXPECT_EQ(size2
.ToString(), view_
->GetRequestedRendererSize().ToString());
1723 // Receive a frame of the correct size, should not be skipped and, and should
1724 // produce a Resize message after the commit.
1725 view_
->OnSwapCompositorFrame(
1726 0, MakeDelegatedFrame(1.f
, size2
, gfx::Rect(size2
)));
1727 cc::SurfaceId surface_id
= view_
->surface_id();
1728 if (surface_id
.is_null()) {
1729 // No frame ack yet.
1730 EXPECT_EQ(0u, sink_
->message_count());
1732 // Frame isn't desired size, so early ack.
1733 EXPECT_EQ(1u, sink_
->message_count());
1735 EXPECT_EQ(size2
.ToString(), view_
->GetRequestedRendererSize().ToString());
1737 // Wait for commit, then we should unlock the compositor and send a Resize
1738 // message (and a frame ack)
1739 ui::DrawWaiterForTest::WaitForCommit(
1740 root_window
->GetHost()->compositor());
1742 bool has_resize
= false;
1743 for (uint32 i
= 0; i
< sink_
->message_count(); ++i
) {
1744 const IPC::Message
* msg
= sink_
->GetMessageAt(i
);
1745 switch (msg
->type()) {
1746 case InputMsg_HandleInputEvent::ID
: {
1747 // On some platforms, the call to view_->Show() causes a posted task to
1749 // ui::WindowEventDispatcher::SynthesizeMouseMoveAfterChangeToWindow,
1750 // which the above WaitForCommit may cause to be picked up. Be robust
1751 // to this extra IPC coming in.
1752 InputMsg_HandleInputEvent::Param params
;
1753 InputMsg_HandleInputEvent::Read(msg
, ¶ms
);
1754 const blink::WebInputEvent
* event
= base::get
<0>(params
);
1755 EXPECT_EQ(blink::WebInputEvent::MouseMove
, event
->type
);
1758 case ViewMsg_SwapCompositorFrameAck::ID
:
1760 case ViewMsg_Resize::ID
: {
1761 EXPECT_FALSE(has_resize
);
1762 ViewMsg_Resize::Param params
;
1763 ViewMsg_Resize::Read(msg
, ¶ms
);
1764 EXPECT_EQ(size3
.ToString(), base::get
<0>(params
).new_size
.ToString());
1769 ADD_FAILURE() << "Unexpected message " << msg
->type();
1773 EXPECT_TRUE(has_resize
);
1774 update_params
.view_size
= size3
;
1775 widget_host_
->OnMessageReceived(
1776 ViewHostMsg_UpdateRect(widget_host_
->GetRoutingID(), update_params
));
1777 sink_
->ClearMessages();
1780 // Skipped frames should not drop their damage.
1781 TEST_F(RenderWidgetHostViewAuraTest
, SkippedDelegatedFrames
) {
1782 gfx::Rect
view_rect(100, 100);
1783 gfx::Size frame_size
= view_rect
.size();
1785 view_
->InitAsChild(NULL
);
1786 aura::client::ParentWindowWithContext(
1787 view_
->GetNativeView(),
1788 parent_view_
->GetNativeView()->GetRootWindow(),
1790 view_
->SetSize(view_rect
.size());
1792 MockWindowObserver observer
;
1793 view_
->window_
->AddObserver(&observer
);
1795 // A full frame of damage.
1796 EXPECT_CALL(observer
, OnDelegatedFrameDamage(view_
->window_
, view_rect
));
1797 view_
->OnSwapCompositorFrame(
1798 0, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1799 testing::Mock::VerifyAndClearExpectations(&observer
);
1800 view_
->RunOnCompositingDidCommit();
1802 // A partial damage frame.
1803 gfx::Rect
partial_view_rect(30, 30, 20, 20);
1804 EXPECT_CALL(observer
,
1805 OnDelegatedFrameDamage(view_
->window_
, partial_view_rect
));
1806 view_
->OnSwapCompositorFrame(
1807 0, MakeDelegatedFrame(1.f
, frame_size
, partial_view_rect
));
1808 testing::Mock::VerifyAndClearExpectations(&observer
);
1809 view_
->RunOnCompositingDidCommit();
1811 // Lock the compositor. Now we should drop frames.
1812 view_rect
= gfx::Rect(150, 150);
1813 view_
->SetSize(view_rect
.size());
1815 // This frame is dropped.
1816 gfx::Rect
dropped_damage_rect_1(10, 20, 30, 40);
1817 EXPECT_CALL(observer
, OnDelegatedFrameDamage(_
, _
)).Times(0);
1818 view_
->OnSwapCompositorFrame(
1819 0, MakeDelegatedFrame(1.f
, frame_size
, dropped_damage_rect_1
));
1820 testing::Mock::VerifyAndClearExpectations(&observer
);
1821 view_
->RunOnCompositingDidCommit();
1823 gfx::Rect
dropped_damage_rect_2(40, 50, 10, 20);
1824 EXPECT_CALL(observer
, OnDelegatedFrameDamage(_
, _
)).Times(0);
1825 view_
->OnSwapCompositorFrame(
1826 0, MakeDelegatedFrame(1.f
, frame_size
, dropped_damage_rect_2
));
1827 testing::Mock::VerifyAndClearExpectations(&observer
);
1828 view_
->RunOnCompositingDidCommit();
1830 // Unlock the compositor. This frame should damage everything.
1831 frame_size
= view_rect
.size();
1833 gfx::Rect
new_damage_rect(5, 6, 10, 10);
1834 EXPECT_CALL(observer
,
1835 OnDelegatedFrameDamage(view_
->window_
, view_rect
));
1836 view_
->OnSwapCompositorFrame(
1837 0, MakeDelegatedFrame(1.f
, frame_size
, new_damage_rect
));
1838 testing::Mock::VerifyAndClearExpectations(&observer
);
1839 view_
->RunOnCompositingDidCommit();
1841 // A partial damage frame, this should not be dropped.
1842 EXPECT_CALL(observer
,
1843 OnDelegatedFrameDamage(view_
->window_
, partial_view_rect
));
1844 view_
->OnSwapCompositorFrame(
1845 0, MakeDelegatedFrame(1.f
, frame_size
, partial_view_rect
));
1846 testing::Mock::VerifyAndClearExpectations(&observer
);
1847 view_
->RunOnCompositingDidCommit();
1850 // Resize to something empty.
1851 view_rect
= gfx::Rect(100, 0);
1852 view_
->SetSize(view_rect
.size());
1854 // We're never expecting empty frames, resize to something non-empty.
1855 view_rect
= gfx::Rect(100, 100);
1856 view_
->SetSize(view_rect
.size());
1858 // This frame should not be dropped.
1859 EXPECT_CALL(observer
, OnDelegatedFrameDamage(view_
->window_
, view_rect
));
1860 view_
->OnSwapCompositorFrame(
1861 0, MakeDelegatedFrame(1.f
, view_rect
.size(), view_rect
));
1862 testing::Mock::VerifyAndClearExpectations(&observer
);
1863 view_
->RunOnCompositingDidCommit();
1865 view_
->window_
->RemoveObserver(&observer
);
1868 TEST_F(RenderWidgetHostViewAuraTest
, OutputSurfaceIdChange
) {
1869 gfx::Rect
view_rect(100, 100);
1870 gfx::Size frame_size
= view_rect
.size();
1872 view_
->InitAsChild(NULL
);
1873 aura::client::ParentWindowWithContext(
1874 view_
->GetNativeView(),
1875 parent_view_
->GetNativeView()->GetRootWindow(),
1877 view_
->SetSize(view_rect
.size());
1879 MockWindowObserver observer
;
1880 view_
->window_
->AddObserver(&observer
);
1883 EXPECT_CALL(observer
, OnDelegatedFrameDamage(view_
->window_
, view_rect
));
1884 view_
->OnSwapCompositorFrame(
1885 0, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1886 testing::Mock::VerifyAndClearExpectations(&observer
);
1887 view_
->RunOnCompositingDidCommit();
1889 // Swap a frame with a different surface id.
1890 EXPECT_CALL(observer
, OnDelegatedFrameDamage(view_
->window_
, view_rect
));
1891 view_
->OnSwapCompositorFrame(
1892 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1893 testing::Mock::VerifyAndClearExpectations(&observer
);
1894 view_
->RunOnCompositingDidCommit();
1896 // Swap an empty frame, with a different surface id.
1897 view_
->OnSwapCompositorFrame(
1898 2, MakeDelegatedFrame(1.f
, gfx::Size(), gfx::Rect()));
1899 testing::Mock::VerifyAndClearExpectations(&observer
);
1900 view_
->RunOnCompositingDidCommit();
1902 // Swap another frame, with a different surface id.
1903 EXPECT_CALL(observer
, OnDelegatedFrameDamage(view_
->window_
, view_rect
));
1904 view_
->OnSwapCompositorFrame(3,
1905 MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1906 testing::Mock::VerifyAndClearExpectations(&observer
);
1907 view_
->RunOnCompositingDidCommit();
1909 view_
->window_
->RemoveObserver(&observer
);
1912 TEST_F(RenderWidgetHostViewAuraTest
, DiscardDelegatedFrames
) {
1913 view_
->InitAsChild(NULL
);
1915 size_t max_renderer_frames
=
1916 RendererFrameManager::GetInstance()->GetMaxNumberOfSavedFrames();
1917 ASSERT_LE(2u, max_renderer_frames
);
1918 size_t renderer_count
= max_renderer_frames
+ 1;
1919 gfx::Rect
view_rect(100, 100);
1920 gfx::Size frame_size
= view_rect
.size();
1921 DCHECK_EQ(0u, HostSharedBitmapManager::current()->AllocatedBitmapCount());
1923 scoped_ptr
<RenderWidgetHostImpl
* []> hosts(
1924 new RenderWidgetHostImpl
* [renderer_count
]);
1925 scoped_ptr
<FakeRenderWidgetHostViewAura
* []> views(
1926 new FakeRenderWidgetHostViewAura
* [renderer_count
]);
1928 // Create a bunch of renderers.
1929 for (size_t i
= 0; i
< renderer_count
; ++i
) {
1930 hosts
[i
] = new RenderWidgetHostImpl(
1931 &delegate_
, process_host_
, MSG_ROUTING_NONE
, false);
1933 views
[i
] = new FakeRenderWidgetHostViewAura(hosts
[i
], false);
1934 views
[i
]->InitAsChild(NULL
);
1935 aura::client::ParentWindowWithContext(
1936 views
[i
]->GetNativeView(),
1937 parent_view_
->GetNativeView()->GetRootWindow(),
1939 views
[i
]->SetSize(view_rect
.size());
1942 // Make each renderer visible, and swap a frame on it, then make it invisible.
1943 for (size_t i
= 0; i
< renderer_count
; ++i
) {
1945 views
[i
]->OnSwapCompositorFrame(
1946 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1947 EXPECT_TRUE(views
[i
]->HasFrameData());
1951 // There should be max_renderer_frames with a frame in it, and one without it.
1952 // Since the logic is LRU eviction, the first one should be without.
1953 EXPECT_FALSE(views
[0]->HasFrameData());
1954 for (size_t i
= 1; i
< renderer_count
; ++i
)
1955 EXPECT_TRUE(views
[i
]->HasFrameData());
1957 // LRU renderer is [0], make it visible, it shouldn't evict anything yet.
1959 EXPECT_FALSE(views
[0]->HasFrameData());
1960 EXPECT_TRUE(views
[1]->HasFrameData());
1961 // Since [0] doesn't have a frame, it should be waiting for the renderer to
1963 EXPECT_TRUE(views
[0]->released_front_lock_active());
1965 // Swap a frame on it, it should evict the next LRU [1].
1966 views
[0]->OnSwapCompositorFrame(
1967 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1968 EXPECT_TRUE(views
[0]->HasFrameData());
1969 EXPECT_FALSE(views
[1]->HasFrameData());
1970 // Now that [0] got a frame, it shouldn't be waiting any more.
1971 EXPECT_FALSE(views
[0]->released_front_lock_active());
1974 // LRU renderer is [1], still hidden. Swap a frame on it, it should evict
1975 // the next LRU [2].
1976 views
[1]->OnSwapCompositorFrame(
1977 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1978 EXPECT_TRUE(views
[0]->HasFrameData());
1979 EXPECT_TRUE(views
[1]->HasFrameData());
1980 EXPECT_FALSE(views
[2]->HasFrameData());
1981 for (size_t i
= 3; i
< renderer_count
; ++i
)
1982 EXPECT_TRUE(views
[i
]->HasFrameData());
1984 // Make all renderers but [0] visible and swap a frame on them, keep [0]
1985 // hidden, it becomes the LRU.
1986 for (size_t i
= 1; i
< renderer_count
; ++i
) {
1988 // The renderers who don't have a frame should be waiting. The ones that
1989 // have a frame should not.
1990 // In practice, [1] has a frame, but anything after has its frame evicted.
1991 EXPECT_EQ(!views
[i
]->HasFrameData(),
1992 views
[i
]->released_front_lock_active());
1993 views
[i
]->OnSwapCompositorFrame(
1994 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1995 // Now everyone has a frame.
1996 EXPECT_FALSE(views
[i
]->released_front_lock_active());
1997 EXPECT_TRUE(views
[i
]->HasFrameData());
1999 EXPECT_FALSE(views
[0]->HasFrameData());
2001 // Swap a frame on [0], it should be evicted immediately.
2002 views
[0]->OnSwapCompositorFrame(
2003 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
2004 EXPECT_FALSE(views
[0]->HasFrameData());
2006 // Make [0] visible, and swap a frame on it. Nothing should be evicted
2007 // although we're above the limit.
2009 // We don't have a frame, wait.
2010 EXPECT_TRUE(views
[0]->released_front_lock_active());
2011 views
[0]->OnSwapCompositorFrame(
2012 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
2013 EXPECT_FALSE(views
[0]->released_front_lock_active());
2014 for (size_t i
= 0; i
< renderer_count
; ++i
)
2015 EXPECT_TRUE(views
[i
]->HasFrameData());
2017 // Make [0] hidden, it should evict its frame.
2019 EXPECT_FALSE(views
[0]->HasFrameData());
2021 // Make [0] visible, don't give it a frame, it should be waiting.
2023 EXPECT_TRUE(views
[0]->released_front_lock_active());
2024 // Make [0] hidden, it should stop waiting.
2026 EXPECT_FALSE(views
[0]->released_front_lock_active());
2028 // Make [1] hidden, resize it. It should drop its frame.
2030 EXPECT_TRUE(views
[1]->HasFrameData());
2031 gfx::Size
size2(200, 200);
2032 views
[1]->SetSize(size2
);
2033 EXPECT_FALSE(views
[1]->HasFrameData());
2034 // Show it, it should block until we give it a frame.
2036 EXPECT_TRUE(views
[1]->released_front_lock_active());
2037 views
[1]->OnSwapCompositorFrame(
2038 1, MakeDelegatedFrame(1.f
, size2
, gfx::Rect(size2
)));
2039 EXPECT_FALSE(views
[1]->released_front_lock_active());
2041 for (size_t i
= 0; i
< renderer_count
- 1; ++i
)
2044 // Allocate enough bitmaps so that two frames (proportionally) would be
2045 // enough hit the handle limit.
2046 int handles_per_frame
= 5;
2047 RendererFrameManager::GetInstance()->set_max_handles(handles_per_frame
* 2);
2049 HostSharedBitmapManagerClient
bitmap_client(
2050 HostSharedBitmapManager::current());
2052 for (size_t i
= 0; i
< (renderer_count
- 1) * handles_per_frame
; i
++) {
2053 bitmap_client
.ChildAllocatedSharedBitmap(
2054 1, base::SharedMemory::NULLHandle(), base::GetCurrentProcessHandle(),
2055 cc::SharedBitmap::GenerateId());
2058 // Hiding this last bitmap should evict all but two frames.
2059 views
[renderer_count
- 1]->Hide();
2060 for (size_t i
= 0; i
< renderer_count
; ++i
) {
2061 if (i
+ 2 < renderer_count
)
2062 EXPECT_FALSE(views
[i
]->HasFrameData());
2064 EXPECT_TRUE(views
[i
]->HasFrameData());
2066 RendererFrameManager::GetInstance()->set_max_handles(
2067 base::SharedMemory::GetHandleLimit());
2069 for (size_t i
= 0; i
< renderer_count
; ++i
) {
2070 views
[i
]->Destroy();
2075 TEST_F(RenderWidgetHostViewAuraTest
, DiscardDelegatedFramesWithLocking
) {
2076 view_
->InitAsChild(NULL
);
2078 size_t max_renderer_frames
=
2079 RendererFrameManager::GetInstance()->GetMaxNumberOfSavedFrames();
2080 ASSERT_LE(2u, max_renderer_frames
);
2081 size_t renderer_count
= max_renderer_frames
+ 1;
2082 gfx::Rect
view_rect(100, 100);
2083 gfx::Size frame_size
= view_rect
.size();
2084 DCHECK_EQ(0u, HostSharedBitmapManager::current()->AllocatedBitmapCount());
2086 scoped_ptr
<RenderWidgetHostImpl
* []> hosts(
2087 new RenderWidgetHostImpl
* [renderer_count
]);
2088 scoped_ptr
<FakeRenderWidgetHostViewAura
* []> views(
2089 new FakeRenderWidgetHostViewAura
* [renderer_count
]);
2091 // Create a bunch of renderers.
2092 for (size_t i
= 0; i
< renderer_count
; ++i
) {
2093 hosts
[i
] = new RenderWidgetHostImpl(
2094 &delegate_
, process_host_
, MSG_ROUTING_NONE
, false);
2096 views
[i
] = new FakeRenderWidgetHostViewAura(hosts
[i
], false);
2097 views
[i
]->InitAsChild(NULL
);
2098 aura::client::ParentWindowWithContext(
2099 views
[i
]->GetNativeView(),
2100 parent_view_
->GetNativeView()->GetRootWindow(),
2102 views
[i
]->SetSize(view_rect
.size());
2105 // Make each renderer visible and swap a frame on it. No eviction should
2106 // occur because all frames are visible.
2107 for (size_t i
= 0; i
< renderer_count
; ++i
) {
2109 views
[i
]->OnSwapCompositorFrame(
2110 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
2111 EXPECT_TRUE(views
[i
]->HasFrameData());
2114 // If we hide [0], then [0] should be evicted.
2116 EXPECT_FALSE(views
[0]->HasFrameData());
2118 // If we lock [0] before hiding it, then [0] should not be evicted.
2120 views
[0]->OnSwapCompositorFrame(
2121 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
2122 EXPECT_TRUE(views
[0]->HasFrameData());
2123 views
[0]->GetDelegatedFrameHost()->LockResources();
2125 EXPECT_TRUE(views
[0]->HasFrameData());
2127 // If we unlock [0] now, then [0] should be evicted.
2128 views
[0]->GetDelegatedFrameHost()->UnlockResources();
2129 EXPECT_FALSE(views
[0]->HasFrameData());
2131 for (size_t i
= 0; i
< renderer_count
; ++i
) {
2132 views
[i
]->Destroy();
2137 // Test that changing the memory pressure should delete saved frames. This test
2138 // only applies to ChromeOS.
2139 TEST_F(RenderWidgetHostViewAuraTest
, DiscardDelegatedFramesWithMemoryPressure
) {
2140 view_
->InitAsChild(NULL
);
2142 // The test logic below relies on having max_renderer_frames > 2. By default,
2143 // this value is calculated from total physical memory and causes the test to
2144 // fail when run on hardware with < 256MB of RAM.
2145 const size_t kMaxRendererFrames
= 5;
2146 RendererFrameManager::GetInstance()->set_max_number_of_saved_frames(
2147 kMaxRendererFrames
);
2149 size_t renderer_count
= kMaxRendererFrames
;
2150 gfx::Rect
view_rect(100, 100);
2151 gfx::Size frame_size
= view_rect
.size();
2152 DCHECK_EQ(0u, HostSharedBitmapManager::current()->AllocatedBitmapCount());
2154 scoped_ptr
<RenderWidgetHostImpl
* []> hosts(
2155 new RenderWidgetHostImpl
* [renderer_count
]);
2156 scoped_ptr
<FakeRenderWidgetHostViewAura
* []> views(
2157 new FakeRenderWidgetHostViewAura
* [renderer_count
]);
2159 // Create a bunch of renderers.
2160 for (size_t i
= 0; i
< renderer_count
; ++i
) {
2161 hosts
[i
] = new RenderWidgetHostImpl(
2162 &delegate_
, process_host_
, MSG_ROUTING_NONE
, false);
2164 views
[i
] = new FakeRenderWidgetHostViewAura(hosts
[i
], false);
2165 views
[i
]->InitAsChild(NULL
);
2166 aura::client::ParentWindowWithContext(
2167 views
[i
]->GetNativeView(),
2168 parent_view_
->GetNativeView()->GetRootWindow(),
2170 views
[i
]->SetSize(view_rect
.size());
2173 // Make each renderer visible and swap a frame on it. No eviction should
2174 // occur because all frames are visible.
2175 for (size_t i
= 0; i
< renderer_count
; ++i
) {
2177 views
[i
]->OnSwapCompositorFrame(
2178 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
2179 EXPECT_TRUE(views
[i
]->HasFrameData());
2182 // If we hide one, it should not get evicted.
2184 message_loop_
.RunUntilIdle();
2185 EXPECT_TRUE(views
[0]->HasFrameData());
2186 // Using a lesser memory pressure event however, should evict.
2187 SimulateMemoryPressure(
2188 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE
);
2189 message_loop_
.RunUntilIdle();
2190 EXPECT_FALSE(views
[0]->HasFrameData());
2192 // Check the same for a higher pressure event.
2194 message_loop_
.RunUntilIdle();
2195 EXPECT_TRUE(views
[1]->HasFrameData());
2196 SimulateMemoryPressure(
2197 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL
);
2198 message_loop_
.RunUntilIdle();
2199 EXPECT_FALSE(views
[1]->HasFrameData());
2201 for (size_t i
= 0; i
< renderer_count
; ++i
) {
2202 views
[i
]->Destroy();
2207 TEST_F(RenderWidgetHostViewAuraTest
, SoftwareDPIChange
) {
2208 gfx::Rect
view_rect(100, 100);
2209 gfx::Size
frame_size(100, 100);
2211 view_
->InitAsChild(NULL
);
2212 aura::client::ParentWindowWithContext(
2213 view_
->GetNativeView(),
2214 parent_view_
->GetNativeView()->GetRootWindow(),
2216 view_
->SetSize(view_rect
.size());
2219 // With a 1x DPI UI and 1x DPI Renderer.
2220 view_
->OnSwapCompositorFrame(
2221 1, MakeDelegatedFrame(1.f
, frame_size
, gfx::Rect(frame_size
)));
2223 // Save the frame provider.
2224 scoped_refptr
<cc::DelegatedFrameProvider
> frame_provider
=
2225 view_
->frame_provider();
2226 cc::SurfaceId surface_id
= view_
->surface_id();
2228 // This frame will have the same number of physical pixels, but has a new
2230 view_
->OnSwapCompositorFrame(
2231 1, MakeDelegatedFrame(2.f
, frame_size
, gfx::Rect(frame_size
)));
2233 // When we get a new frame with the same frame size in physical pixels, but a
2234 // different scale, we should generate a new frame provider, as the final
2235 // result will need to be scaled differently to the screen.
2236 if (frame_provider
.get())
2237 EXPECT_NE(frame_provider
.get(), view_
->frame_provider());
2239 EXPECT_NE(surface_id
, view_
->surface_id());
2242 class RenderWidgetHostViewAuraCopyRequestTest
2243 : public RenderWidgetHostViewAuraShutdownTest
{
2245 RenderWidgetHostViewAuraCopyRequestTest()
2246 : callback_count_(0),
2248 frame_subscriber_(nullptr),
2249 tick_clock_(nullptr),
2250 view_rect_(100, 100) {}
2252 void CallbackMethod(bool result
) {
2255 quit_closure_
.Run();
2258 void RunLoopUntilCallback() {
2259 base::RunLoop run_loop
;
2260 quit_closure_
= run_loop
.QuitClosure();
2264 void InitializeView() {
2265 view_
->InitAsChild(NULL
);
2266 view_
->GetDelegatedFrameHost()->SetRequestCopyOfOutputCallbackForTesting(
2267 base::Bind(&FakeRenderWidgetHostViewAura::InterceptCopyOfOutput
,
2268 base::Unretained(view_
)));
2269 aura::client::ParentWindowWithContext(
2270 view_
->GetNativeView(), parent_view_
->GetNativeView()->GetRootWindow(),
2272 view_
->SetSize(view_rect_
.size());
2275 frame_subscriber_
= new FakeFrameSubscriber(
2277 base::Bind(&RenderWidgetHostViewAuraCopyRequestTest::CallbackMethod
,
2278 base::Unretained(this)));
2279 view_
->BeginFrameSubscription(make_scoped_ptr(frame_subscriber_
));
2280 ASSERT_EQ(0, callback_count_
);
2281 ASSERT_FALSE(view_
->last_copy_request_
);
2284 void InstallFakeTickClock() {
2285 // Create a fake tick clock and transfer ownership to the frame host.
2286 tick_clock_
= new base::SimpleTestTickClock();
2287 view_
->GetDelegatedFrameHost()->tick_clock_
= make_scoped_ptr(tick_clock_
);
2290 void OnSwapCompositorFrame() {
2291 view_
->OnSwapCompositorFrame(
2292 1, MakeDelegatedFrame(1.f
, view_rect_
.size(), view_rect_
));
2293 ASSERT_TRUE(view_
->last_copy_request_
);
2296 void ReleaseSwappedFrame() {
2297 scoped_ptr
<cc::CopyOutputRequest
> request
=
2298 view_
->last_copy_request_
.Pass();
2299 request
->SendTextureResult(view_rect_
.size(), request
->texture_mailbox(),
2300 scoped_ptr
<cc::SingleReleaseCallback
>());
2301 RunLoopUntilCallback();
2304 void OnSwapCompositorFrameAndRelease() {
2305 OnSwapCompositorFrame();
2306 ReleaseSwappedFrame();
2309 void RunOnCompositingDidCommitAndReleaseFrame() {
2310 view_
->RunOnCompositingDidCommit();
2311 ReleaseSwappedFrame();
2314 void OnUpdateVSyncParameters(base::TimeTicks timebase
,
2315 base::TimeDelta interval
) {
2316 view_
->GetDelegatedFrameHost()->OnUpdateVSyncParameters(timebase
, interval
);
2319 base::TimeTicks
vsync_timebase() {
2320 return view_
->GetDelegatedFrameHost()->vsync_timebase_
;
2323 base::TimeDelta
vsync_interval() {
2324 return view_
->GetDelegatedFrameHost()->vsync_interval_
;
2327 int callback_count_
;
2329 FakeFrameSubscriber
* frame_subscriber_
; // Owned by |view_|.
2330 base::SimpleTestTickClock
* tick_clock_
; // Owned by DelegatedFrameHost.
2331 const gfx::Rect view_rect_
;
2334 base::Closure quit_closure_
;
2336 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraCopyRequestTest
);
2339 // Tests that only one copy/readback request will be executed per one browser
2340 // composite operation, even when multiple render frame swaps occur in between
2341 // browser composites, and even if the frame subscriber desires more frames than
2342 // the number of browser composites.
2343 TEST_F(RenderWidgetHostViewAuraCopyRequestTest
, DedupeFrameSubscriberRequests
) {
2345 int expected_callback_count
= 0;
2347 // Normal case: A browser composite executes for each render frame swap.
2348 for (int i
= 0; i
< 3; ++i
) {
2349 // Renderer provides another frame and the Browser composites with the
2350 // frame, executing the copy request, and then the result is delivered.
2351 OnSwapCompositorFrame();
2352 RunOnCompositingDidCommitAndReleaseFrame();
2354 // The callback should be run with success status.
2355 ++expected_callback_count
;
2356 ASSERT_EQ(expected_callback_count
, callback_count_
);
2357 EXPECT_TRUE(result_
);
2360 // De-duping case: One browser composite executes per varied number of render
2362 for (int i
= 0; i
< 3; ++i
) {
2363 const int num_swaps
= 1 + i
% 3;
2365 // The renderer provides |num_swaps| frames.
2366 for (int j
= 0; j
< num_swaps
; ++j
) {
2367 OnSwapCompositorFrame();
2369 ++expected_callback_count
;
2370 ASSERT_EQ(expected_callback_count
, callback_count_
);
2371 EXPECT_FALSE(result_
); // The prior copy request was aborted.
2375 // Browser composites with the frame, executing the last copy request that
2376 // was made, and then the result is delivered.
2377 RunOnCompositingDidCommitAndReleaseFrame();
2379 // The final callback should be run with success status.
2380 ++expected_callback_count
;
2381 ASSERT_EQ(expected_callback_count
, callback_count_
);
2382 EXPECT_TRUE(result_
);
2385 // Destroy the RenderWidgetHostViewAura and ImageTransportFactory.
2386 TearDownEnvironment();
2389 TEST_F(RenderWidgetHostViewAuraCopyRequestTest
, DestroyedAfterCopyRequest
) {
2392 OnSwapCompositorFrame();
2393 EXPECT_EQ(0, callback_count_
);
2394 EXPECT_TRUE(view_
->last_copy_request_
);
2395 EXPECT_TRUE(view_
->last_copy_request_
->has_texture_mailbox());
2397 // Notify DelegatedFrameHost that the copy requests were moved to the
2398 // compositor thread by calling OnCompositingDidCommit().
2400 // Send back the mailbox included in the request. There's no release callback
2401 // since the mailbox came from the RWHVA originally.
2402 RunOnCompositingDidCommitAndReleaseFrame();
2404 // The callback should succeed.
2405 EXPECT_EQ(1, callback_count_
);
2406 EXPECT_TRUE(result_
);
2408 OnSwapCompositorFrame();
2409 EXPECT_EQ(1, callback_count_
);
2410 scoped_ptr
<cc::CopyOutputRequest
> request
= view_
->last_copy_request_
.Pass();
2412 // Destroy the RenderWidgetHostViewAura and ImageTransportFactory.
2413 TearDownEnvironment();
2415 // Send the result after-the-fact. It goes nowhere since DelegatedFrameHost
2416 // has been destroyed.
2417 request
->SendTextureResult(view_rect_
.size(), request
->texture_mailbox(),
2418 scoped_ptr
<cc::SingleReleaseCallback
>());
2420 // Because the copy request callback may be holding state within it, that
2421 // state must handle the RWHVA and ImageTransportFactory going away before the
2422 // callback is called. This test passes if it does not crash as a result of
2423 // these things being destroyed.
2424 EXPECT_EQ(2, callback_count_
);
2425 EXPECT_FALSE(result_
);
2428 TEST_F(RenderWidgetHostViewAuraCopyRequestTest
, PresentTime
) {
2430 InstallFakeTickClock();
2432 // Verify our initial state.
2433 EXPECT_EQ(base::TimeTicks(), frame_subscriber_
->last_present_time());
2434 EXPECT_EQ(base::TimeTicks(), tick_clock_
->NowTicks());
2436 // Start our fake clock from a non-zero, but not an even multiple of the
2437 // interval, value to differentiate it from our initialization state.
2438 const base::TimeDelta kDefaultInterval
=
2439 cc::BeginFrameArgs::DefaultInterval();
2440 tick_clock_
->Advance(kDefaultInterval
/ 3);
2442 // Swap the first frame without any vsync information.
2443 ASSERT_EQ(base::TimeTicks(), vsync_timebase());
2444 ASSERT_EQ(base::TimeDelta(), vsync_interval());
2446 // During this first call, there is no known vsync information, so while the
2447 // callback should succeed the present time is effectively just current time.
2448 OnSwapCompositorFrameAndRelease();
2449 EXPECT_EQ(tick_clock_
->NowTicks(), frame_subscriber_
->last_present_time());
2451 // Now initialize the vsync parameters with a null timebase, but a known vsync
2452 // interval; which should give us slightly better frame time estimates.
2453 OnUpdateVSyncParameters(base::TimeTicks(), kDefaultInterval
);
2454 ASSERT_EQ(base::TimeTicks(), vsync_timebase());
2455 ASSERT_EQ(kDefaultInterval
, vsync_interval());
2457 // Now that we have a vsync interval, the presentation time estimate should be
2458 // the nearest presentation interval, which is just kDefaultInterval since our
2459 // tick clock is initialized to a time before that.
2460 OnSwapCompositorFrameAndRelease();
2461 EXPECT_EQ(base::TimeTicks() + kDefaultInterval
,
2462 frame_subscriber_
->last_present_time());
2464 // Now initialize the vsync parameters with a valid timebase and a known vsync
2465 // interval; which should give us the best frame time estimates.
2466 const base::TimeTicks kBaseTime
= tick_clock_
->NowTicks();
2467 OnUpdateVSyncParameters(kBaseTime
, kDefaultInterval
);
2468 ASSERT_EQ(kBaseTime
, vsync_timebase());
2469 ASSERT_EQ(kDefaultInterval
, vsync_interval());
2471 // Now that we have a vsync interval and a timebase, the presentation time
2472 // should be based on the number of vsync intervals which have elapsed since
2473 // the vsync timebase. Advance time by a non integer number of intervals to
2475 const double kElapsedIntervals
= 2.5;
2476 tick_clock_
->Advance(kDefaultInterval
* kElapsedIntervals
);
2477 OnSwapCompositorFrameAndRelease();
2478 EXPECT_EQ(kBaseTime
+ kDefaultInterval
* std::ceil(kElapsedIntervals
),
2479 frame_subscriber_
->last_present_time());
2481 // Destroy the RenderWidgetHostViewAura and ImageTransportFactory.
2482 TearDownEnvironment();
2485 TEST_F(RenderWidgetHostViewAuraTest
, VisibleViewportTest
) {
2486 gfx::Rect
view_rect(100, 100);
2488 view_
->InitAsChild(NULL
);
2489 aura::client::ParentWindowWithContext(
2490 view_
->GetNativeView(),
2491 parent_view_
->GetNativeView()->GetRootWindow(),
2493 view_
->SetSize(view_rect
.size());
2496 // Defaults to full height of the view.
2497 EXPECT_EQ(100, view_
->GetVisibleViewportSize().height());
2499 widget_host_
->ResetSizeAndRepaintPendingFlags();
2500 sink_
->ClearMessages();
2501 view_
->SetInsets(gfx::Insets(0, 0, 40, 0));
2503 EXPECT_EQ(60, view_
->GetVisibleViewportSize().height());
2505 const IPC::Message
*message
= sink_
->GetFirstMessageMatching(
2506 ViewMsg_Resize::ID
);
2507 ASSERT_TRUE(message
!= NULL
);
2509 ViewMsg_Resize::Param params
;
2510 ViewMsg_Resize::Read(message
, ¶ms
);
2511 EXPECT_EQ(60, base::get
<0>(params
).visible_viewport_size
.height());
2514 // Ensures that touch event positions are never truncated to integers.
2515 TEST_F(RenderWidgetHostViewAuraTest
, TouchEventPositionsArentRounded
) {
2516 const float kX
= 30.58f
;
2517 const float kY
= 50.23f
;
2519 view_
->InitAsChild(NULL
);
2522 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
,
2523 gfx::PointF(kX
, kY
),
2525 ui::EventTimeForNow());
2527 view_
->OnTouchEvent(&press
);
2528 EXPECT_EQ(blink::WebInputEvent::TouchStart
, view_
->touch_event_
->type
);
2529 EXPECT_TRUE(view_
->touch_event_
->cancelable
);
2530 EXPECT_EQ(1U, view_
->touch_event_
->touchesLength
);
2531 EXPECT_EQ(blink::WebTouchPoint::StatePressed
,
2532 view_
->touch_event_
->touches
[0].state
);
2533 EXPECT_EQ(kX
, view_
->touch_event_
->touches
[0].screenPosition
.x
);
2534 EXPECT_EQ(kX
, view_
->touch_event_
->touches
[0].position
.x
);
2535 EXPECT_EQ(kY
, view_
->touch_event_
->touches
[0].screenPosition
.y
);
2536 EXPECT_EQ(kY
, view_
->touch_event_
->touches
[0].position
.y
);
2539 // Tests that scroll ACKs are correctly handled by the overscroll-navigation
2541 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, WheelScrollEventOverscrolls
) {
2542 SetUpOverscrollEnvironment();
2544 // Simulate wheel events.
2545 SimulateWheelEvent(-5, 0, 0, true); // sent directly
2546 SimulateWheelEvent(-1, 1, 0, true); // enqueued
2547 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
2548 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
2549 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
2550 SimulateWheelEvent(-20, 6, 1, true); // enqueued, different modifiers
2551 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2552 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2554 // Receive ACK the first wheel event as not processed.
2555 SendInputEventACK(WebInputEvent::MouseWheel
,
2556 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2557 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2558 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2559 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2561 // Receive ACK for the second (coalesced) event as not processed. This will
2562 // start a back navigation. However, this will also cause the queued next
2563 // event to be sent to the renderer. But since overscroll navigation has
2564 // started, that event will also be included in the overscroll computation
2565 // instead of being sent to the renderer. So the result will be an overscroll
2566 // back navigation, and no event will be sent to the renderer.
2567 SendInputEventACK(WebInputEvent::MouseWheel
,
2568 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2569 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_mode());
2570 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_delegate()->current_mode());
2571 EXPECT_EQ(-81.f
, overscroll_delta_x());
2572 EXPECT_EQ(-31.f
, overscroll_delegate()->delta_x());
2573 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2574 EXPECT_EQ(0U, sink_
->message_count());
2576 // Send a mouse-move event. This should cancel the overscroll navigation.
2577 SimulateMouseMove(5, 10, 0);
2578 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2579 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2580 EXPECT_EQ(1U, sink_
->message_count());
2583 // Tests that if some scroll events are consumed towards the start, then
2584 // subsequent scrolls do not horizontal overscroll.
2585 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
2586 WheelScrollConsumedDoNotHorizOverscroll
) {
2587 SetUpOverscrollEnvironment();
2589 // Simulate wheel events.
2590 SimulateWheelEvent(-5, 0, 0, true); // sent directly
2591 SimulateWheelEvent(-1, -1, 0, true); // enqueued
2592 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
2593 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
2594 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
2595 SimulateWheelEvent(-20, 6, 1, true); // enqueued, different modifiers
2596 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2597 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2599 // Receive ACK the first wheel event as processed.
2600 SendInputEventACK(WebInputEvent::MouseWheel
, INPUT_EVENT_ACK_STATE_CONSUMED
);
2601 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2602 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2603 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2605 // Receive ACK for the second (coalesced) event as not processed. This should
2606 // not initiate overscroll, since the beginning of the scroll has been
2607 // consumed. The queued event with different modifiers should be sent to the
2609 SendInputEventACK(WebInputEvent::MouseWheel
,
2610 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2611 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2612 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2614 SendInputEventACK(WebInputEvent::MouseWheel
,
2615 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2616 EXPECT_EQ(0U, sink_
->message_count());
2617 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2619 // Indicate the end of the scrolling from the touchpad.
2620 SimulateGestureFlingStartEvent(-1200.f
, 0.f
, blink::WebGestureDeviceTouchpad
);
2621 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2623 // Start another scroll. This time, do not consume any scroll events.
2624 SimulateWheelEvent(0, -5, 0, true); // sent directly
2625 SimulateWheelEvent(0, -1, 0, true); // enqueued
2626 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
2627 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
2628 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
2629 SimulateWheelEvent(-20, 6, 1, true); // enqueued, different modifiers
2630 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2631 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2633 // Receive ACK for the first wheel and the subsequent coalesced event as not
2634 // processed. This should start a back-overscroll.
2635 SendInputEventACK(WebInputEvent::MouseWheel
,
2636 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2637 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2638 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2639 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2640 SendInputEventACK(WebInputEvent::MouseWheel
,
2641 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2642 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_mode());
2645 // Tests that wheel-scrolling correctly turns overscroll on and off.
2646 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, WheelScrollOverscrollToggle
) {
2647 SetUpOverscrollEnvironment();
2649 // Send a wheel event. ACK the event as not processed. This should not
2650 // initiate an overscroll gesture since it doesn't cross the threshold yet.
2651 SimulateWheelEvent(10, 0, 0, true);
2652 SendInputEventACK(WebInputEvent::MouseWheel
,
2653 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2654 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2655 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2656 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2658 // Scroll some more so as to not overscroll.
2659 SimulateWheelEvent(10, 0, 0, true);
2660 SendInputEventACK(WebInputEvent::MouseWheel
,
2661 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2662 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2663 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2664 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2666 // Scroll some more to initiate an overscroll.
2667 SimulateWheelEvent(40, 0, 0, true);
2668 SendInputEventACK(WebInputEvent::MouseWheel
,
2669 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2670 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2671 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2672 EXPECT_EQ(60.f
, overscroll_delta_x());
2673 EXPECT_EQ(10.f
, overscroll_delegate()->delta_x());
2674 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2675 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2677 // Scroll in the reverse direction enough to abort the overscroll.
2678 SimulateWheelEvent(-20, 0, 0, true);
2679 EXPECT_EQ(0U, sink_
->message_count());
2680 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2681 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2683 // Continue to scroll in the reverse direction.
2684 SimulateWheelEvent(-20, 0, 0, true);
2685 SendInputEventACK(WebInputEvent::MouseWheel
,
2686 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2687 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2688 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2689 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2691 // Continue to scroll in the reverse direction enough to initiate overscroll
2692 // in that direction.
2693 SimulateWheelEvent(-55, 0, 0, true);
2694 EXPECT_EQ(1U, sink_
->message_count());
2695 SendInputEventACK(WebInputEvent::MouseWheel
,
2696 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2697 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_mode());
2698 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_delegate()->current_mode());
2699 EXPECT_EQ(-75.f
, overscroll_delta_x());
2700 EXPECT_EQ(-25.f
, overscroll_delegate()->delta_x());
2701 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2704 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
2705 ScrollEventsOverscrollWithFling
) {
2706 SetUpOverscrollEnvironment();
2708 // Send a wheel event. ACK the event as not processed. This should not
2709 // initiate an overscroll gesture since it doesn't cross the threshold yet.
2710 SimulateWheelEvent(10, 0, 0, true);
2711 SendInputEventACK(WebInputEvent::MouseWheel
,
2712 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2713 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2714 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2715 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2717 // Scroll some more so as to not overscroll.
2718 SimulateWheelEvent(20, 0, 0, true);
2719 EXPECT_EQ(1U, sink_
->message_count());
2720 SendInputEventACK(WebInputEvent::MouseWheel
,
2721 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2722 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2723 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2724 sink_
->ClearMessages();
2726 // Scroll some more to initiate an overscroll.
2727 SimulateWheelEvent(30, 0, 0, true);
2728 SendInputEventACK(WebInputEvent::MouseWheel
,
2729 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2730 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2731 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2732 EXPECT_EQ(60.f
, overscroll_delta_x());
2733 EXPECT_EQ(10.f
, overscroll_delegate()->delta_x());
2734 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2735 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2737 // Send a fling start, but with a small velocity, so that the overscroll is
2738 // aborted. The fling should proceed to the renderer, through the gesture
2740 SimulateGestureFlingStartEvent(0.f
, 0.1f
, blink::WebGestureDeviceTouchpad
);
2741 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2742 EXPECT_EQ(1U, sink_
->message_count());
2745 // Same as ScrollEventsOverscrollWithFling, but with zero velocity. Checks that
2746 // the zero-velocity fling does not reach the renderer.
2747 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
2748 ScrollEventsOverscrollWithZeroFling
) {
2749 SetUpOverscrollEnvironment();
2751 // Send a wheel event. ACK the event as not processed. This should not
2752 // initiate an overscroll gesture since it doesn't cross the threshold yet.
2753 SimulateWheelEvent(10, 0, 0, true);
2754 SendInputEventACK(WebInputEvent::MouseWheel
,
2755 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2756 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2757 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2758 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2760 // Scroll some more so as to not overscroll.
2761 SimulateWheelEvent(20, 0, 0, true);
2762 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2763 SendInputEventACK(WebInputEvent::MouseWheel
,
2764 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2765 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2766 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2768 // Scroll some more to initiate an overscroll.
2769 SimulateWheelEvent(30, 0, 0, true);
2770 SendInputEventACK(WebInputEvent::MouseWheel
,
2771 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2772 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2773 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2774 EXPECT_EQ(60.f
, overscroll_delta_x());
2775 EXPECT_EQ(10.f
, overscroll_delegate()->delta_x());
2776 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2777 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2779 // Send a fling start, but with a small velocity, so that the overscroll is
2780 // aborted. The fling should proceed to the renderer, through the gesture
2782 SimulateGestureFlingStartEvent(10.f
, 0.f
, blink::WebGestureDeviceTouchpad
);
2783 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2784 EXPECT_EQ(1U, sink_
->message_count());
2787 // Tests that a fling in the opposite direction of the overscroll cancels the
2788 // overscroll nav instead of completing it.
2789 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, ReverseFlingCancelsOverscroll
) {
2790 SetUpOverscrollEnvironment();
2793 // Start and end a gesture in the same direction without processing the
2794 // gesture events in the renderer. This should initiate and complete an
2795 // overscroll navigation.
2796 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2797 blink::WebGestureDeviceTouchscreen
);
2798 SimulateGestureScrollUpdateEvent(300, -5, 0);
2799 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2800 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2801 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2802 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2803 sink_
->ClearMessages();
2805 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
2806 blink::WebGestureDeviceTouchscreen
);
2807 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->completed_mode());
2808 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2809 EXPECT_EQ(1U, sink_
->message_count());
2813 // Start over, except instead of ending the gesture with ScrollEnd, end it
2814 // with a FlingStart, with velocity in the reverse direction. This should
2815 // initiate an overscroll navigation, but it should be cancelled because of
2816 // the fling in the opposite direction.
2817 overscroll_delegate()->Reset();
2818 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2819 blink::WebGestureDeviceTouchscreen
);
2820 SimulateGestureScrollUpdateEvent(-300, -5, 0);
2821 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2822 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2823 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_mode());
2824 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_delegate()->current_mode());
2825 sink_
->ClearMessages();
2827 SimulateGestureFlingStartEvent(100, 0, blink::WebGestureDeviceTouchscreen
);
2828 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->completed_mode());
2829 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2830 EXPECT_EQ(1U, sink_
->message_count());
2834 // Tests that touch-scroll events are handled correctly by the overscroll
2835 // controller. This also tests that the overscroll controller and the
2836 // gesture-event filter play nice with each other.
2837 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, GestureScrollOverscrolls
) {
2838 SetUpOverscrollEnvironment();
2840 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2841 blink::WebGestureDeviceTouchscreen
);
2842 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2843 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2844 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2846 // Send another gesture event and ACK as not being processed. This should
2847 // initiate the navigation gesture.
2848 SimulateGestureScrollUpdateEvent(55, -5, 0);
2849 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2850 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2851 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2852 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2853 EXPECT_EQ(55.f
, overscroll_delta_x());
2854 EXPECT_EQ(-5.f
, overscroll_delta_y());
2855 EXPECT_EQ(5.f
, overscroll_delegate()->delta_x());
2856 EXPECT_EQ(-5.f
, overscroll_delegate()->delta_y());
2857 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2859 // Send another gesture update event. This event should be consumed by the
2860 // controller, and not be forwarded to the renderer. The gesture-event filter
2861 // should not also receive this event.
2862 SimulateGestureScrollUpdateEvent(10, -5, 0);
2863 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2864 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2865 EXPECT_EQ(65.f
, overscroll_delta_x());
2866 EXPECT_EQ(-10.f
, overscroll_delta_y());
2867 EXPECT_EQ(15.f
, overscroll_delegate()->delta_x());
2868 EXPECT_EQ(-10.f
, overscroll_delegate()->delta_y());
2869 EXPECT_EQ(0U, sink_
->message_count());
2871 // Now send a scroll end. This should cancel the overscroll gesture, and send
2872 // the event to the renderer. The gesture-event filter should receive this
2874 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
2875 blink::WebGestureDeviceTouchscreen
);
2876 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2877 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2878 EXPECT_EQ(1U, sink_
->message_count());
2881 // Tests that if the page is scrolled because of a scroll-gesture, then that
2882 // particular scroll sequence never generates overscroll if the scroll direction
2884 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
2885 GestureScrollConsumedHorizontal
) {
2886 SetUpOverscrollEnvironment();
2888 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2889 blink::WebGestureDeviceTouchscreen
);
2890 SimulateGestureScrollUpdateEvent(10, 0, 0);
2892 // Start scrolling on content. ACK both events as being processed.
2893 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2894 INPUT_EVENT_ACK_STATE_CONSUMED
);
2895 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2896 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2897 sink_
->ClearMessages();
2899 // Send another gesture event and ACK as not being processed. This should
2900 // not initiate overscroll because the beginning of the scroll event did
2901 // scroll some content on the page. Since there was no overscroll, the event
2902 // should reach the renderer.
2903 SimulateGestureScrollUpdateEvent(55, 0, 0);
2904 EXPECT_EQ(1U, sink_
->message_count());
2905 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2906 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2907 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2910 // Tests that the overscroll controller plays nice with touch-scrolls and the
2911 // gesture event filter with debounce filtering turned on.
2912 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
2913 GestureScrollDebounceOverscrolls
) {
2914 SetUpOverscrollEnvironmentWithDebounce(100);
2916 // Start scrolling. Receive ACK as it being processed.
2917 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2918 blink::WebGestureDeviceTouchscreen
);
2919 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2921 // Send update events.
2922 SimulateGestureScrollUpdateEvent(25, 0, 0);
2923 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2925 // Quickly end and restart the scroll gesture. These two events should get
2927 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
2928 blink::WebGestureDeviceTouchscreen
);
2929 EXPECT_EQ(0U, sink_
->message_count());
2931 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2932 blink::WebGestureDeviceTouchscreen
);
2933 EXPECT_EQ(0U, sink_
->message_count());
2935 // Send another update event. This should get into the queue.
2936 SimulateGestureScrollUpdateEvent(30, 0, 0);
2937 EXPECT_EQ(0U, sink_
->message_count());
2939 // Receive an ACK for the first scroll-update event as not being processed.
2940 // This will contribute to the overscroll gesture, but not enough for the
2941 // overscroll controller to start consuming gesture events. This also cause
2942 // the queued gesture event to be forwarded to the renderer.
2943 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2944 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2945 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2946 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2947 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2949 // Send another update event. This should get into the queue.
2950 SimulateGestureScrollUpdateEvent(10, 0, 0);
2951 EXPECT_EQ(0U, sink_
->message_count());
2953 // Receive an ACK for the second scroll-update event as not being processed.
2954 // This will now initiate an overscroll. This will also cause the queued
2955 // gesture event to be released. But instead of going to the renderer, it will
2956 // be consumed by the overscroll controller.
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(65.f
, overscroll_delta_x());
2962 EXPECT_EQ(15.f
, overscroll_delegate()->delta_x());
2963 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2964 EXPECT_EQ(0U, sink_
->message_count());
2967 // Tests that the gesture debounce timer plays nice with the overscroll
2969 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
2970 GestureScrollDebounceTimerOverscroll
) {
2971 SetUpOverscrollEnvironmentWithDebounce(10);
2973 // Start scrolling. Receive ACK as it being processed.
2974 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2975 blink::WebGestureDeviceTouchscreen
);
2976 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2978 // Send update events.
2979 SimulateGestureScrollUpdateEvent(55, 0, 0);
2980 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2982 // Send an end event. This should get in the debounce queue.
2983 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
2984 blink::WebGestureDeviceTouchscreen
);
2985 EXPECT_EQ(0U, sink_
->message_count());
2987 // Receive ACK for the scroll-update event.
2988 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2989 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2990 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2991 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2992 EXPECT_EQ(55.f
, overscroll_delta_x());
2993 EXPECT_EQ(5.f
, overscroll_delegate()->delta_x());
2994 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2995 EXPECT_EQ(0U, sink_
->message_count());
2997 // Let the timer for the debounce queue fire. That should release the queued
2998 // scroll-end event. Since overscroll has started, but there hasn't been
2999 // enough overscroll to complete the gesture, the overscroll controller
3000 // will reset the state. The scroll-end should therefore be dispatched to the
3001 // renderer, and the gesture-event-filter should await an ACK for it.
3002 base::MessageLoop::current()->PostDelayedTask(
3004 base::MessageLoop::QuitClosure(),
3005 base::TimeDelta::FromMilliseconds(15));
3006 base::MessageLoop::current()->Run();
3008 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3009 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3010 EXPECT_EQ(1U, sink_
->message_count());
3013 // Tests that when touch-events are dispatched to the renderer, the overscroll
3014 // gesture deals with them correctly.
3015 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, OverscrollWithTouchEvents
) {
3016 SetUpOverscrollEnvironmentWithDebounce(10);
3017 widget_host_
->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
3018 sink_
->ClearMessages();
3020 // The test sends an intermingled sequence of touch and gesture events.
3021 PressTouchPoint(0, 1);
3022 uint32 touch_press_event_id1
= SendTouchEvent();
3023 SendTouchEventACK(WebInputEvent::TouchStart
,
3024 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
, touch_press_event_id1
);
3025 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3027 MoveTouchPoint(0, 20, 5);
3028 uint32 touch_move_event_id1
= SendTouchEvent();
3029 SendTouchEventACK(WebInputEvent::TouchMove
,
3030 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
, touch_move_event_id1
);
3031 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3033 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3034 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3036 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
3037 blink::WebGestureDeviceTouchscreen
);
3038 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3039 SimulateGestureScrollUpdateEvent(20, 0, 0);
3040 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
3041 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3042 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3043 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3044 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3046 // Another touch move event should reach the renderer since overscroll hasn't
3047 // started yet. Note that touch events sent during the scroll period may
3048 // not require an ack (having been marked uncancelable).
3049 MoveTouchPoint(0, 65, 10);
3051 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3052 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3054 SimulateGestureScrollUpdateEvent(45, 0, 0);
3055 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
3056 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3057 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
3058 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
3059 EXPECT_EQ(65.f
, overscroll_delta_x());
3060 EXPECT_EQ(15.f
, overscroll_delegate()->delta_x());
3061 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
3062 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3064 // Send another touch event. The page should get the touch-move event, even
3065 // though overscroll has started.
3066 MoveTouchPoint(0, 55, 5);
3068 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
3069 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
3070 EXPECT_EQ(65.f
, overscroll_delta_x());
3071 EXPECT_EQ(15.f
, overscroll_delegate()->delta_x());
3072 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
3073 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3074 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3076 SimulateGestureScrollUpdateEvent(-10, 0, 0);
3077 EXPECT_EQ(0U, sink_
->message_count());
3078 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
3079 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
3080 EXPECT_EQ(55.f
, overscroll_delta_x());
3081 EXPECT_EQ(5.f
, overscroll_delegate()->delta_x());
3082 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
3084 PressTouchPoint(255, 5);
3086 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3087 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3089 SimulateGestureScrollUpdateEvent(200, 0, 0);
3090 EXPECT_EQ(0U, sink_
->message_count());
3091 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
3092 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
3093 EXPECT_EQ(255.f
, overscroll_delta_x());
3094 EXPECT_EQ(205.f
, overscroll_delegate()->delta_x());
3095 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
3097 // The touch-end/cancel event should always reach the renderer if the page has
3099 ReleaseTouchPoint(1);
3101 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3102 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3103 ReleaseTouchPoint(0);
3105 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3106 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3108 SimulateGestureEvent(blink::WebInputEvent::GestureScrollEnd
,
3109 blink::WebGestureDeviceTouchscreen
);
3110 base::MessageLoop::current()->PostDelayedTask(
3112 base::MessageLoop::QuitClosure(),
3113 base::TimeDelta::FromMilliseconds(10));
3114 base::MessageLoop::current()->Run();
3115 EXPECT_EQ(1U, sink_
->message_count());
3116 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3117 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3118 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->completed_mode());
3121 // Tests that touch-gesture end is dispatched to the renderer at the end of a
3122 // touch-gesture initiated overscroll.
3123 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
3124 TouchGestureEndDispatchedAfterOverscrollComplete
) {
3125 SetUpOverscrollEnvironmentWithDebounce(10);
3126 widget_host_
->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
3127 sink_
->ClearMessages();
3129 // Start scrolling. Receive ACK as it being processed.
3130 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
3131 blink::WebGestureDeviceTouchscreen
);
3132 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3133 // The scroll begin event will have received a synthetic ack from the input
3135 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3136 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3138 // Send update events.
3139 SimulateGestureScrollUpdateEvent(55, -5, 0);
3140 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3141 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3142 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3144 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
3145 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3146 EXPECT_EQ(0U, sink_
->message_count());
3147 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
3148 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
3149 EXPECT_EQ(55.f
, overscroll_delta_x());
3150 EXPECT_EQ(5.f
, overscroll_delegate()->delta_x());
3151 EXPECT_EQ(-5.f
, overscroll_delegate()->delta_y());
3154 SimulateGestureEvent(blink::WebInputEvent::GestureScrollEnd
,
3155 blink::WebGestureDeviceTouchscreen
);
3156 EXPECT_EQ(0U, sink_
->message_count());
3157 base::MessageLoop::current()->PostDelayedTask(
3159 base::MessageLoop::QuitClosure(),
3160 base::TimeDelta::FromMilliseconds(10));
3161 base::MessageLoop::current()->Run();
3162 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3163 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3164 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->completed_mode());
3165 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3167 // Start scrolling. Receive ACK as it being processed.
3168 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
3169 blink::WebGestureDeviceTouchscreen
);
3170 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3171 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3172 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3174 // Send update events.
3175 SimulateGestureScrollUpdateEvent(235, -5, 0);
3176 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3177 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3178 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3180 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
3181 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3182 EXPECT_EQ(0U, sink_
->message_count());
3183 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
3184 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
3185 EXPECT_EQ(235.f
, overscroll_delta_x());
3186 EXPECT_EQ(185.f
, overscroll_delegate()->delta_x());
3187 EXPECT_EQ(-5.f
, overscroll_delegate()->delta_y());
3190 SimulateGestureEvent(blink::WebInputEvent::GestureScrollEnd
,
3191 blink::WebGestureDeviceTouchscreen
);
3192 EXPECT_EQ(0U, sink_
->message_count());
3193 base::MessageLoop::current()->PostDelayedTask(
3195 base::MessageLoop::QuitClosure(),
3196 base::TimeDelta::FromMilliseconds(10));
3197 base::MessageLoop::current()->Run();
3198 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3199 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3200 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->completed_mode());
3201 EXPECT_EQ(1U, sink_
->message_count());
3204 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, OverscrollDirectionChange
) {
3205 SetUpOverscrollEnvironmentWithDebounce(100);
3207 // Start scrolling. Receive ACK as it being processed.
3208 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
3209 blink::WebGestureDeviceTouchscreen
);
3210 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3212 // Send update events and receive ack as not consumed.
3213 SimulateGestureScrollUpdateEvent(125, -5, 0);
3214 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3216 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
3217 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3218 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
3219 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
3220 EXPECT_EQ(0U, sink_
->message_count());
3222 // Send another update event, but in the reverse direction. The overscroll
3223 // controller will not consume the event, because it is not triggering
3225 SimulateGestureScrollUpdateEvent(-260, 0, 0);
3226 EXPECT_EQ(1U, sink_
->message_count());
3227 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3229 // Since the overscroll mode has been reset, the next scroll update events
3230 // should reach the renderer.
3231 SimulateGestureScrollUpdateEvent(-20, 0, 0);
3232 EXPECT_EQ(1U, sink_
->message_count());
3233 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3236 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
3237 OverscrollDirectionChangeMouseWheel
) {
3238 SetUpOverscrollEnvironment();
3240 // Send wheel event and receive ack as not consumed.
3241 SimulateWheelEvent(125, -5, 0, true);
3242 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3243 SendInputEventACK(WebInputEvent::MouseWheel
,
3244 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3245 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
3246 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
3247 EXPECT_EQ(0U, sink_
->message_count());
3249 // Send another wheel event, but in the reverse direction. The overscroll
3250 // controller will not consume the event, because it is not triggering
3252 SimulateWheelEvent(-260, 0, 0, true);
3253 EXPECT_EQ(1U, sink_
->message_count());
3254 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3256 // Since the overscroll mode has been reset, the next wheel event should reach
3258 SimulateWheelEvent(-20, 0, 0, true);
3259 EXPECT_EQ(1U, sink_
->message_count());
3260 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3263 // Tests that if a mouse-move event completes the overscroll gesture, future
3264 // move events do reach the renderer.
3265 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, OverscrollMouseMoveCompletion
) {
3266 SetUpOverscrollEnvironment();
3268 SimulateWheelEvent(5, 0, 0, true); // sent directly
3269 SimulateWheelEvent(-1, 0, 0, true); // enqueued
3270 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
3271 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
3272 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
3273 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3274 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3276 // Receive ACK the first wheel event as not processed.
3277 SendInputEventACK(WebInputEvent::MouseWheel
,
3278 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3279 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3280 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3281 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3283 // Receive ACK for the second (coalesced) event as not processed. This will
3284 // start an overcroll gesture.
3285 SendInputEventACK(WebInputEvent::MouseWheel
,
3286 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3287 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_mode());
3288 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_delegate()->current_mode());
3289 EXPECT_EQ(0U, sink_
->message_count());
3291 // Send a mouse-move event. This should cancel the overscroll navigation
3292 // (since the amount overscrolled is not above the threshold), and so the
3293 // mouse-move should reach the renderer.
3294 SimulateMouseMove(5, 10, 0);
3295 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3296 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->completed_mode());
3297 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3298 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3300 SendInputEventACK(WebInputEvent::MouseMove
,
3301 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3303 // Moving the mouse more should continue to send the events to the renderer.
3304 SimulateMouseMove(5, 10, 0);
3305 SendInputEventACK(WebInputEvent::MouseMove
,
3306 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3307 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3309 // Now try with gestures.
3310 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
3311 blink::WebGestureDeviceTouchscreen
);
3312 SimulateGestureScrollUpdateEvent(300, -5, 0);
3313 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
3314 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3315 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
3316 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
3317 sink_
->ClearMessages();
3319 // Overscroll gesture is in progress. Send a mouse-move now. This should
3320 // complete the gesture (because the amount overscrolled is above the
3322 SimulateMouseMove(5, 10, 0);
3323 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->completed_mode());
3324 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3325 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3326 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3327 SendInputEventACK(WebInputEvent::MouseMove
,
3328 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3330 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
3331 blink::WebGestureDeviceTouchscreen
);
3332 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3333 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3335 // Move mouse some more. The mouse-move events should reach the renderer.
3336 SimulateMouseMove(5, 10, 0);
3337 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3339 SendInputEventACK(WebInputEvent::MouseMove
,
3340 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3343 // Tests that if a page scrolled, then the overscroll controller's states are
3344 // reset after the end of the scroll.
3345 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
3346 OverscrollStateResetsAfterScroll
) {
3347 SetUpOverscrollEnvironment();
3349 SimulateWheelEvent(0, 5, 0, true); // sent directly
3350 SimulateWheelEvent(0, 30, 0, true); // enqueued
3351 SimulateWheelEvent(0, 40, 0, true); // coalesced into previous event
3352 SimulateWheelEvent(0, 10, 0, true); // coalesced into previous event
3353 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3354 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3356 // The first wheel event is consumed. Dispatches the queued wheel event.
3357 SendInputEventACK(WebInputEvent::MouseWheel
, INPUT_EVENT_ACK_STATE_CONSUMED
);
3358 EXPECT_TRUE(ScrollStateIsContentScrolling());
3359 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3361 // The second wheel event is consumed.
3362 SendInputEventACK(WebInputEvent::MouseWheel
, INPUT_EVENT_ACK_STATE_CONSUMED
);
3363 EXPECT_TRUE(ScrollStateIsContentScrolling());
3365 // Touchpad scroll can end with a zero-velocity fling. But it is not
3366 // dispatched, but it should still reset the overscroll controller state.
3367 SimulateGestureFlingStartEvent(0.f
, 0.f
, blink::WebGestureDeviceTouchpad
);
3368 EXPECT_TRUE(ScrollStateIsUnknown());
3369 EXPECT_EQ(0U, sink_
->message_count());
3371 // Dropped flings should neither propagate *nor* indicate that they were
3372 // consumed and have triggered a fling animation (as tracked by the router).
3373 EXPECT_FALSE(parent_host_
->input_router()->HasPendingEvents());
3375 SimulateWheelEvent(-5, 0, 0, true); // sent directly
3376 SimulateWheelEvent(-60, 0, 0, true); // enqueued
3377 SimulateWheelEvent(-100, 0, 0, true); // coalesced into previous event
3378 EXPECT_TRUE(ScrollStateIsUnknown());
3379 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3381 // The first wheel scroll did not scroll content. Overscroll should not start
3382 // yet, since enough hasn't been scrolled.
3383 SendInputEventACK(WebInputEvent::MouseWheel
,
3384 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3385 EXPECT_TRUE(ScrollStateIsUnknown());
3386 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3388 SendInputEventACK(WebInputEvent::MouseWheel
,
3389 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3390 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_mode());
3391 EXPECT_TRUE(ScrollStateIsOverscrolling());
3392 EXPECT_EQ(0U, sink_
->message_count());
3394 SimulateGestureFlingStartEvent(0.f
, 0.f
, blink::WebGestureDeviceTouchpad
);
3395 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3396 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_delegate()->completed_mode());
3397 EXPECT_TRUE(ScrollStateIsUnknown());
3398 EXPECT_EQ(0U, sink_
->message_count());
3399 EXPECT_FALSE(parent_host_
->input_router()->HasPendingEvents());
3402 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, OverscrollResetsOnBlur
) {
3403 SetUpOverscrollEnvironment();
3405 // Start an overscroll with gesture scroll. In the middle of the scroll, blur
3407 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
3408 blink::WebGestureDeviceTouchscreen
);
3409 SimulateGestureScrollUpdateEvent(300, -5, 0);
3410 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
3411 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3412 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
3413 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
3414 EXPECT_EQ(2U, GetSentMessageCountAndResetSink());
3416 view_
->OnWindowFocused(NULL
, view_
->GetNativeView());
3417 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3418 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3419 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->completed_mode());
3420 EXPECT_EQ(0.f
, overscroll_delegate()->delta_x());
3421 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
3422 sink_
->ClearMessages();
3424 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
3425 blink::WebGestureDeviceTouchscreen
);
3426 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3428 // Start a scroll gesture again. This should correctly start the overscroll
3429 // after the threshold.
3430 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
3431 blink::WebGestureDeviceTouchscreen
);
3432 SimulateGestureScrollUpdateEvent(300, -5, 0);
3433 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
3434 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3435 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
3436 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
3437 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->completed_mode());
3439 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
3440 blink::WebGestureDeviceTouchscreen
);
3441 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3442 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->completed_mode());
3443 EXPECT_EQ(3U, sink_
->message_count());
3446 // Tests that when view initiated shutdown happens (i.e. RWHView is deleted
3447 // before RWH), we clean up properly and don't leak the RWHVGuest.
3448 TEST_F(RenderWidgetHostViewGuestAuraTest
, GuestViewDoesNotLeak
) {
3449 view_
->InitAsChild(NULL
);
3450 TearDownEnvironment();
3451 ASSERT_FALSE(guest_view_weak_
.get());
3454 // Tests that invalid touch events are consumed and handled
3456 TEST_F(RenderWidgetHostViewAuraTest
,
3457 InvalidEventsHaveSyncHandlingDisabled
) {
3458 view_
->InitAsChild(NULL
);
3460 GetSentMessageCountAndResetSink();
3462 widget_host_
->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
3464 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(30, 30), 0,
3465 ui::EventTimeForNow());
3467 // Construct a move with a touch id which doesn't exist.
3468 ui::TouchEvent
invalid_move(ui::ET_TOUCH_MOVED
, gfx::Point(30, 30), 1,
3469 ui::EventTimeForNow());
3471 // Valid press is handled asynchronously.
3472 view_
->OnTouchEvent(&press
);
3473 EXPECT_TRUE(press
.synchronous_handling_disabled());
3474 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3475 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_CONSUMED
);
3477 // Invalid move is handled synchronously, but is consumed. It should not
3478 // be forwarded to the renderer.
3479 view_
->OnTouchEvent(&invalid_move
);
3480 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
3481 EXPECT_FALSE(invalid_move
.synchronous_handling_disabled());
3482 EXPECT_TRUE(invalid_move
.stopped_propagation());
3485 // Checks key event codes.
3486 TEST_F(RenderWidgetHostViewAuraTest
, KeyEvent
) {
3487 view_
->InitAsChild(NULL
);
3490 ui::KeyEvent
key_event(ui::ET_KEY_PRESSED
, ui::VKEY_A
, ui::DomCode::KEY_A
,
3492 view_
->OnKeyEvent(&key_event
);
3494 const NativeWebKeyboardEvent
* event
= delegate_
.last_event();
3495 EXPECT_NE(nullptr, event
);
3497 EXPECT_EQ(key_event
.key_code(), event
->windowsKeyCode
);
3498 EXPECT_EQ(ui::KeycodeConverter::DomCodeToNativeKeycode(key_event
.code()),
3499 event
->nativeKeyCode
);
3503 TEST_F(RenderWidgetHostViewAuraTest
, SetCanScrollForWebMouseWheelEvent
) {
3504 view_
->InitAsChild(NULL
);
3507 sink_
->ClearMessages();
3509 // Simulates the mouse wheel event with ctrl modifier applied.
3510 ui::MouseWheelEvent
event(gfx::Vector2d(1, 1), gfx::Point(), gfx::Point(),
3511 ui::EventTimeForNow(), ui::EF_CONTROL_DOWN
, 0);
3512 view_
->OnMouseEvent(&event
);
3514 const WebInputEvent
* input_event
=
3515 GetInputEventFromMessage(*sink_
->GetMessageAt(0));
3516 const WebMouseWheelEvent
* wheel_event
=
3517 static_cast<const WebMouseWheelEvent
*>(input_event
);
3518 // Check if the canScroll set to false when ctrl-scroll is generated from
3519 // mouse wheel event.
3520 EXPECT_FALSE(wheel_event
->canScroll
);
3521 sink_
->ClearMessages();
3523 // Ack'ing the outstanding event should flush the pending event queue.
3524 SendInputEventACK(blink::WebInputEvent::MouseWheel
,
3525 INPUT_EVENT_ACK_STATE_CONSUMED
);
3527 // Simulates the mouse wheel event with no modifier applied.
3528 event
= ui::MouseWheelEvent(gfx::Vector2d(1, 1), gfx::Point(), gfx::Point(),
3529 ui::EventTimeForNow(), ui::EF_NONE
, 0);
3531 view_
->OnMouseEvent(&event
);
3533 input_event
= GetInputEventFromMessage(*sink_
->GetMessageAt(0));
3534 wheel_event
= static_cast<const WebMouseWheelEvent
*>(input_event
);
3535 // Check if the canScroll set to true when no modifier is applied to the
3536 // mouse wheel event.
3537 EXPECT_TRUE(wheel_event
->canScroll
);
3538 sink_
->ClearMessages();
3540 SendInputEventACK(blink::WebInputEvent::MouseWheel
,
3541 INPUT_EVENT_ACK_STATE_CONSUMED
);
3543 // Simulates the scroll event with ctrl modifier applied.
3544 ui::ScrollEvent
scroll(ui::ET_SCROLL
, gfx::Point(2, 2), ui::EventTimeForNow(),
3545 ui::EF_CONTROL_DOWN
, 0, 5, 0, 5, 2);
3546 view_
->OnScrollEvent(&scroll
);
3548 input_event
= GetInputEventFromMessage(*sink_
->GetMessageAt(0));
3549 wheel_event
= static_cast<const WebMouseWheelEvent
*>(input_event
);
3550 // Check if the canScroll set to true when ctrl-touchpad-scroll is generated
3551 // from scroll event.
3552 EXPECT_TRUE(wheel_event
->canScroll
);
3555 // Ensures that the mapping from ui::TouchEvent to blink::WebTouchEvent doesn't
3556 // lose track of the number of acks required.
3557 TEST_F(RenderWidgetHostViewAuraTest
, CorrectNumberOfAcksAreDispatched
) {
3558 view_
->InitAsFullscreen(parent_view_
);
3560 view_
->UseFakeDispatcher();
3562 ui::TouchEvent
press1(
3563 ui::ET_TOUCH_PRESSED
, gfx::Point(30, 30), 0, ui::EventTimeForNow());
3565 view_
->OnTouchEvent(&press1
);
3566 SendTouchEventACK(blink::WebInputEvent::TouchStart
,
3567 INPUT_EVENT_ACK_STATE_CONSUMED
, press1
.unique_event_id());
3569 ui::TouchEvent
press2(
3570 ui::ET_TOUCH_PRESSED
, gfx::Point(20, 20), 1, ui::EventTimeForNow());
3571 view_
->OnTouchEvent(&press2
);
3572 SendTouchEventACK(blink::WebInputEvent::TouchStart
,
3573 INPUT_EVENT_ACK_STATE_CONSUMED
, press2
.unique_event_id());
3575 EXPECT_EQ(2U, view_
->dispatcher_
->GetAndResetProcessedTouchEventCount());
3578 // Tests that the scroll deltas stored within the overscroll controller get
3579 // reset at the end of the overscroll gesture even if the overscroll threshold
3580 // isn't surpassed and the overscroll mode stays OVERSCROLL_NONE.
3581 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, ScrollDeltasResetOnEnd
) {
3582 SetUpOverscrollEnvironment();
3583 // Wheel event scroll ending with mouse move.
3584 SimulateWheelEvent(-30, -10, 0, true); // sent directly
3585 SendInputEventACK(WebInputEvent::MouseWheel
,
3586 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3587 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3588 EXPECT_EQ(-30.f
, overscroll_delta_x());
3589 EXPECT_EQ(-10.f
, overscroll_delta_y());
3590 SimulateMouseMove(5, 10, 0);
3591 EXPECT_EQ(0.f
, overscroll_delta_x());
3592 EXPECT_EQ(0.f
, overscroll_delta_y());
3595 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
3596 blink::WebGestureDeviceTouchscreen
);
3597 SimulateGestureScrollUpdateEvent(-30, -5, 0);
3598 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
3599 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3600 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3601 EXPECT_EQ(-30.f
, overscroll_delta_x());
3602 EXPECT_EQ(-5.f
, overscroll_delta_y());
3603 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
3604 blink::WebGestureDeviceTouchscreen
);
3605 EXPECT_EQ(0.f
, overscroll_delta_x());
3606 EXPECT_EQ(0.f
, overscroll_delta_y());
3608 // Wheel event scroll ending with a fling.
3609 SimulateWheelEvent(5, 0, 0, true);
3610 SendInputEventACK(WebInputEvent::MouseWheel
,
3611 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3612 SimulateWheelEvent(10, -5, 0, true);
3613 SendInputEventACK(WebInputEvent::MouseWheel
,
3614 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3615 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3616 EXPECT_EQ(15.f
, overscroll_delta_x());
3617 EXPECT_EQ(-5.f
, overscroll_delta_y());
3618 SimulateGestureFlingStartEvent(0.f
, 0.1f
, blink::WebGestureDeviceTouchpad
);
3619 EXPECT_EQ(0.f
, overscroll_delta_x());
3620 EXPECT_EQ(0.f
, overscroll_delta_y());
3623 // Tests the RenderWidgetHostImpl sends the correct surface ID namespace to
3624 // the renderer process.
3625 TEST_F(RenderWidgetHostViewAuraTest
, SurfaceIdNamespaceInitialized
) {
3626 gfx::Size
size(5, 5);
3628 const IPC::Message
* msg
=
3629 sink_
->GetUniqueMessageMatching(ViewMsg_SetSurfaceIdNamespace::ID
);
3631 ViewMsg_SetSurfaceIdNamespace::Param params
;
3632 ViewMsg_SetSurfaceIdNamespace::Read(msg
, ¶ms
);
3633 view_
->InitAsChild(NULL
);
3635 view_
->SetSize(size
);
3636 view_
->OnSwapCompositorFrame(0,
3637 MakeDelegatedFrame(1.f
, size
, gfx::Rect(size
)));
3638 EXPECT_EQ(view_
->GetSurfaceIdNamespace(), base::get
<0>(params
));
3641 } // namespace content