1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
7 #include "base/basictypes.h"
8 #include "base/command_line.h"
9 #include "base/memory/shared_memory.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "base/test/simple_test_tick_clock.h"
14 #include "cc/output/begin_frame_args.h"
15 #include "cc/output/compositor_frame.h"
16 #include "cc/output/compositor_frame_metadata.h"
17 #include "cc/output/copy_output_request.h"
18 #include "cc/surfaces/surface.h"
19 #include "cc/surfaces/surface_manager.h"
20 #include "content/browser/browser_thread_impl.h"
21 #include "content/browser/compositor/resize_lock.h"
22 #include "content/browser/compositor/test/no_transport_image_transport_factory.h"
23 #include "content/browser/frame_host/render_widget_host_view_guest.h"
24 #include "content/browser/gpu/gpu_surface_tracker.h"
25 #include "content/browser/renderer_host/input/input_router.h"
26 #include "content/browser/renderer_host/input/web_input_event_util.h"
27 #include "content/browser/renderer_host/overscroll_controller.h"
28 #include "content/browser/renderer_host/overscroll_controller_delegate.h"
29 #include "content/browser/renderer_host/render_widget_host_delegate.h"
30 #include "content/browser/renderer_host/render_widget_host_impl.h"
31 #include "content/common/gpu/client/gl_helper.h"
32 #include "content/common/gpu/gpu_messages.h"
33 #include "content/common/host_shared_bitmap_manager.h"
34 #include "content/common/input/synthetic_web_input_event_builders.h"
35 #include "content/common/input_messages.h"
36 #include "content/common/view_messages.h"
37 #include "content/public/browser/render_widget_host_view.h"
38 #include "content/public/browser/render_widget_host_view_frame_subscriber.h"
39 #include "content/public/test/mock_render_process_host.h"
40 #include "content/public/test/test_browser_context.h"
41 #include "ipc/ipc_test_sink.h"
42 #include "testing/gmock/include/gmock/gmock.h"
43 #include "testing/gtest/include/gtest/gtest.h"
44 #include "ui/aura/client/aura_constants.h"
45 #include "ui/aura/client/screen_position_client.h"
46 #include "ui/aura/client/window_tree_client.h"
47 #include "ui/aura/env.h"
48 #include "ui/aura/layout_manager.h"
49 #include "ui/aura/test/aura_test_helper.h"
50 #include "ui/aura/test/aura_test_utils.h"
51 #include "ui/aura/test/test_cursor_client.h"
52 #include "ui/aura/test/test_screen.h"
53 #include "ui/aura/test/test_window_delegate.h"
54 #include "ui/aura/window.h"
55 #include "ui/aura/window_event_dispatcher.h"
56 #include "ui/aura/window_observer.h"
57 #include "ui/base/ui_base_types.h"
58 #include "ui/compositor/compositor.h"
59 #include "ui/compositor/layer_tree_owner.h"
60 #include "ui/compositor/test/draw_waiter_for_test.h"
61 #include "ui/events/blink/blink_event_util.h"
62 #include "ui/events/event.h"
63 #include "ui/events/event_utils.h"
64 #include "ui/events/gesture_detection/gesture_configuration.h"
65 #include "ui/events/keycodes/dom/dom_code.h"
66 #include "ui/events/keycodes/dom/keycode_converter.h"
67 #include "ui/events/test/event_generator.h"
68 #include "ui/wm/core/default_activation_client.h"
69 #include "ui/wm/core/default_screen_position_client.h"
70 #include "ui/wm/core/window_util.h"
74 using blink::WebGestureEvent
;
75 using blink::WebInputEvent
;
76 using blink::WebMouseEvent
;
77 using blink::WebMouseWheelEvent
;
78 using blink::WebTouchEvent
;
79 using blink::WebTouchPoint
;
84 class TestOverscrollDelegate
: public OverscrollControllerDelegate
{
86 explicit TestOverscrollDelegate(RenderWidgetHostView
* view
)
88 current_mode_(OVERSCROLL_NONE
),
89 completed_mode_(OVERSCROLL_NONE
),
93 ~TestOverscrollDelegate() override
{}
95 OverscrollMode
current_mode() const { return current_mode_
; }
96 OverscrollMode
completed_mode() const { return completed_mode_
; }
97 float delta_x() const { return delta_x_
; }
98 float delta_y() const { return delta_y_
; }
101 current_mode_
= OVERSCROLL_NONE
;
102 completed_mode_
= OVERSCROLL_NONE
;
103 delta_x_
= delta_y_
= 0.f
;
107 // Overridden from OverscrollControllerDelegate:
108 gfx::Rect
GetVisibleBounds() const override
{
109 return view_
->IsShowing() ? view_
->GetViewBounds() : gfx::Rect();
112 bool OnOverscrollUpdate(float delta_x
, float delta_y
) override
{
118 void OnOverscrollComplete(OverscrollMode overscroll_mode
) override
{
119 EXPECT_EQ(current_mode_
, overscroll_mode
);
120 completed_mode_
= overscroll_mode
;
121 current_mode_
= OVERSCROLL_NONE
;
124 void OnOverscrollModeChange(OverscrollMode old_mode
,
125 OverscrollMode new_mode
) override
{
126 EXPECT_EQ(current_mode_
, old_mode
);
127 current_mode_
= new_mode
;
128 delta_x_
= delta_y_
= 0.f
;
131 RenderWidgetHostView
* view_
;
132 OverscrollMode current_mode_
;
133 OverscrollMode completed_mode_
;
137 DISALLOW_COPY_AND_ASSIGN(TestOverscrollDelegate
);
140 class MockRenderWidgetHostDelegate
: public RenderWidgetHostDelegate
{
142 MockRenderWidgetHostDelegate() {}
143 ~MockRenderWidgetHostDelegate() override
{}
144 const NativeWebKeyboardEvent
* last_event() const { return last_event_
.get(); }
146 // RenderWidgetHostDelegate:
147 bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent
& event
,
148 bool* is_keyboard_shortcut
) override
{
149 last_event_
.reset(new NativeWebKeyboardEvent(event
));
152 void Cut() override
{}
153 void Copy() override
{}
154 void Paste() override
{}
155 void SelectAll() override
{}
158 scoped_ptr
<NativeWebKeyboardEvent
> last_event_
;
159 DISALLOW_COPY_AND_ASSIGN(MockRenderWidgetHostDelegate
);
162 // Simple observer that keeps track of changes to a window for tests.
163 class TestWindowObserver
: public aura::WindowObserver
{
165 explicit TestWindowObserver(aura::Window
* window_to_observe
)
166 : window_(window_to_observe
) {
167 window_
->AddObserver(this);
169 ~TestWindowObserver() override
{
171 window_
->RemoveObserver(this);
174 bool destroyed() const { return destroyed_
; }
176 // aura::WindowObserver overrides:
177 void OnWindowDestroyed(aura::Window
* window
) override
{
178 CHECK_EQ(window
, window_
);
184 // Window that we're observing, or NULL if it's been destroyed.
185 aura::Window
* window_
;
187 // Was |window_| destroyed?
190 DISALLOW_COPY_AND_ASSIGN(TestWindowObserver
);
193 class FakeFrameSubscriber
: public RenderWidgetHostViewFrameSubscriber
{
195 FakeFrameSubscriber(gfx::Size size
, base::Callback
<void(bool)> callback
)
196 : size_(size
), callback_(callback
) {}
198 bool ShouldCaptureFrame(const gfx::Rect
& damage_rect
,
199 base::TimeTicks present_time
,
200 scoped_refptr
<media::VideoFrame
>* storage
,
201 DeliverFrameCallback
* callback
) override
{
202 last_present_time_
= present_time
;
203 *storage
= media::VideoFrame::CreateFrame(media::PIXEL_FORMAT_YV12
, size_
,
204 gfx::Rect(size_
), size_
,
206 *callback
= base::Bind(&FakeFrameSubscriber::CallbackMethod
, callback_
);
210 base::TimeTicks
last_present_time() const { return last_present_time_
; }
212 static void CallbackMethod(base::Callback
<void(bool)> callback
,
213 base::TimeTicks present_time
,
215 callback
.Run(success
);
220 base::Callback
<void(bool)> callback_
;
221 base::TimeTicks last_present_time_
;
224 class FakeWindowEventDispatcher
: public aura::WindowEventDispatcher
{
226 FakeWindowEventDispatcher(aura::WindowTreeHost
* host
)
227 : WindowEventDispatcher(host
),
228 processed_touch_event_count_(0) {}
230 void ProcessedTouchEvent(uint32 unique_event_id
,
231 aura::Window
* window
,
232 ui::EventResult result
) override
{
233 WindowEventDispatcher::ProcessedTouchEvent(unique_event_id
, window
, result
);
234 processed_touch_event_count_
++;
237 size_t GetAndResetProcessedTouchEventCount() {
238 size_t count
= processed_touch_event_count_
;
239 processed_touch_event_count_
= 0;
244 size_t processed_touch_event_count_
;
247 class FakeRenderWidgetHostViewAura
: public RenderWidgetHostViewAura
{
249 FakeRenderWidgetHostViewAura(RenderWidgetHost
* widget
,
250 bool is_guest_view_hack
)
251 : RenderWidgetHostViewAura(widget
, is_guest_view_hack
),
252 has_resize_lock_(false) {}
254 void UseFakeDispatcher() {
255 dispatcher_
= new FakeWindowEventDispatcher(window()->GetHost());
256 scoped_ptr
<aura::WindowEventDispatcher
> dispatcher(dispatcher_
);
257 aura::test::SetHostDispatcher(window()->GetHost(), dispatcher
.Pass());
260 ~FakeRenderWidgetHostViewAura() override
{}
262 scoped_ptr
<ResizeLock
> DelegatedFrameHostCreateResizeLock(
263 bool defer_compositor_lock
) override
{
264 gfx::Size desired_size
= window()->bounds().size();
265 return scoped_ptr
<ResizeLock
>(
266 new FakeResizeLock(desired_size
, defer_compositor_lock
));
269 bool DelegatedFrameCanCreateResizeLock() const override
{ return true; }
271 void RunOnCompositingDidCommit() {
272 GetDelegatedFrameHost()->OnCompositingDidCommitForTesting(
273 window()->GetHost()->compositor());
276 void InterceptCopyOfOutput(scoped_ptr
<cc::CopyOutputRequest
> request
) {
277 last_copy_request_
= request
.Pass();
278 if (last_copy_request_
->has_texture_mailbox()) {
279 // Give the resulting texture a size.
280 GLHelper
* gl_helper
= ImageTransportFactory::GetInstance()->GetGLHelper();
281 GLuint texture
= gl_helper
->ConsumeMailboxToTexture(
282 last_copy_request_
->texture_mailbox().mailbox(),
283 last_copy_request_
->texture_mailbox().sync_point());
284 gl_helper
->ResizeTexture(texture
, window()->bounds().size());
285 gl_helper
->DeleteTexture(texture
);
289 cc::DelegatedFrameProvider
* frame_provider() const {
290 return GetDelegatedFrameHost()->FrameProviderForTesting();
293 cc::SurfaceId
surface_id() const {
294 return GetDelegatedFrameHost()->SurfaceIdForTesting();
297 bool HasFrameData() const {
298 return frame_provider() || !surface_id().is_null();
301 bool released_front_lock_active() const {
302 return GetDelegatedFrameHost()->ReleasedFrontLockActiveForTesting();
305 // A lock that doesn't actually do anything to the compositor, and does not
307 class FakeResizeLock
: public ResizeLock
{
309 FakeResizeLock(const gfx::Size new_size
, bool defer_compositor_lock
)
310 : ResizeLock(new_size
, defer_compositor_lock
) {}
313 const ui::MotionEventAura
& pointer_state_for_test() {
314 return pointer_state();
317 bool has_resize_lock_
;
318 gfx::Size last_frame_size_
;
319 scoped_ptr
<cc::CopyOutputRequest
> last_copy_request_
;
320 FakeWindowEventDispatcher
* dispatcher_
;
323 // A layout manager that always resizes a child to the root window size.
324 class FullscreenLayoutManager
: public aura::LayoutManager
{
326 explicit FullscreenLayoutManager(aura::Window
* owner
) : owner_(owner
) {}
327 ~FullscreenLayoutManager() override
{}
329 // Overridden from aura::LayoutManager:
330 void OnWindowResized() override
{
331 aura::Window::Windows::const_iterator i
;
332 for (i
= owner_
->children().begin(); i
!= owner_
->children().end(); ++i
) {
333 (*i
)->SetBounds(gfx::Rect());
336 void OnWindowAddedToLayout(aura::Window
* child
) override
{
337 child
->SetBounds(gfx::Rect());
339 void OnWillRemoveWindowFromLayout(aura::Window
* child
) override
{}
340 void OnWindowRemovedFromLayout(aura::Window
* child
) override
{}
341 void OnChildWindowVisibilityChanged(aura::Window
* child
,
342 bool visible
) override
{}
343 void SetChildBounds(aura::Window
* child
,
344 const gfx::Rect
& requested_bounds
) override
{
345 SetChildBoundsDirect(child
, gfx::Rect(owner_
->bounds().size()));
349 aura::Window
* owner_
;
350 DISALLOW_COPY_AND_ASSIGN(FullscreenLayoutManager
);
353 class MockWindowObserver
: public aura::WindowObserver
{
355 MOCK_METHOD2(OnDelegatedFrameDamage
, void(aura::Window
*, const gfx::Rect
&));
358 const WebInputEvent
* GetInputEventFromMessage(const IPC::Message
& message
) {
359 base::PickleIterator
iter(message
);
362 if (!iter
.ReadData(&data
, &data_length
))
364 return reinterpret_cast<const WebInputEvent
*>(data
);
369 class RenderWidgetHostViewAuraTest
: public testing::Test
{
371 RenderWidgetHostViewAuraTest()
372 : widget_host_uses_shutdown_to_destroy_(false),
373 is_guest_view_hack_(false),
374 browser_thread_for_ui_(BrowserThread::UI
, &message_loop_
) {}
376 void SetUpEnvironment() {
377 ImageTransportFactory::InitializeForUnitTests(
378 scoped_ptr
<ImageTransportFactory
>(
379 new NoTransportImageTransportFactory
));
380 aura_test_helper_
.reset(new aura::test::AuraTestHelper(&message_loop_
));
381 aura_test_helper_
->SetUp(
382 ImageTransportFactory::GetInstance()->GetContextFactory());
383 new wm::DefaultActivationClient(aura_test_helper_
->root_window());
385 browser_context_
.reset(new TestBrowserContext
);
386 process_host_
= new MockRenderProcessHost(browser_context_
.get());
387 process_host_
->Init();
389 sink_
= &process_host_
->sink();
391 int32 routing_id
= process_host_
->GetNextRoutingID();
392 int32 surface_id
= GpuSurfaceTracker::Get()->AddSurfaceForRenderer(
393 process_host_
->GetID(), routing_id
);
394 parent_host_
= new RenderWidgetHostImpl(&delegate_
, process_host_
,
395 routing_id
, surface_id
, false);
396 parent_view_
= new RenderWidgetHostViewAura(parent_host_
,
397 is_guest_view_hack_
);
398 parent_view_
->InitAsChild(NULL
);
399 aura::client::ParentWindowWithContext(parent_view_
->GetNativeView(),
400 aura_test_helper_
->root_window(),
403 routing_id
= process_host_
->GetNextRoutingID();
404 surface_id
= GpuSurfaceTracker::Get()->AddSurfaceForRenderer(
405 process_host_
->GetID(), routing_id
);
406 widget_host_
= new RenderWidgetHostImpl(&delegate_
, process_host_
,
407 routing_id
, surface_id
, false);
408 widget_host_
->Init();
409 view_
= new FakeRenderWidgetHostViewAura(widget_host_
, is_guest_view_hack_
);
412 void TearDownEnvironment() {
414 process_host_
= NULL
;
418 if (widget_host_uses_shutdown_to_destroy_
)
419 widget_host_
->Shutdown();
423 parent_view_
->Destroy();
426 browser_context_
.reset();
427 aura_test_helper_
->TearDown();
429 message_loop_
.DeleteSoon(FROM_HERE
, browser_context_
.release());
430 message_loop_
.RunUntilIdle();
431 ImageTransportFactory::Terminate();
434 void SetUp() override
{ SetUpEnvironment(); }
436 void TearDown() override
{ TearDownEnvironment(); }
438 void set_widget_host_uses_shutdown_to_destroy(bool use
) {
439 widget_host_uses_shutdown_to_destroy_
= use
;
442 void SimulateMemoryPressure(
443 base::MemoryPressureListener::MemoryPressureLevel level
) {
444 // Here should be base::MemoryPressureListener::NotifyMemoryPressure, but
445 // since the RendererFrameManager is installing a MemoryPressureListener
446 // which uses base::ObserverListThreadSafe, which furthermore remembers the
447 // message loop for the thread it was created in. Between tests, the
448 // RendererFrameManager singleton survives and and the MessageLoop gets
449 // destroyed. The correct fix would be to have base::ObserverListThreadSafe
451 // up the proper message loop every time (see crbug.com/443824.)
452 RendererFrameManager::GetInstance()->OnMemoryPressure(level
);
455 void SendInputEventACK(WebInputEvent::Type type
,
456 InputEventAckState ack_result
) {
457 DCHECK(!WebInputEvent::isTouchEventType(type
));
458 InputEventAck
ack(type
, ack_result
);
459 InputHostMsg_HandleInputEvent_ACK
response(0, ack
);
460 widget_host_
->OnMessageReceived(response
);
463 void SendTouchEventACK(WebInputEvent::Type type
,
464 InputEventAckState ack_result
,
466 DCHECK(WebInputEvent::isTouchEventType(type
));
467 InputEventAck
ack(type
, ack_result
, event_id
);
468 InputHostMsg_HandleInputEvent_ACK
response(0, ack
);
469 widget_host_
->OnMessageReceived(response
);
472 size_t GetSentMessageCountAndResetSink() {
473 size_t count
= sink_
->message_count();
474 sink_
->ClearMessages();
478 void AckLastSentInputEventIfNecessary(InputEventAckState ack_result
) {
479 if (!sink_
->message_count())
482 InputMsg_HandleInputEvent::Param params
;
483 if (!InputMsg_HandleInputEvent::Read(
484 sink_
->GetMessageAt(sink_
->message_count() - 1), ¶ms
)) {
488 if (!WebInputEventTraits::WillReceiveAckFromRenderer(
489 *base::get
<0>(params
)))
492 const blink::WebInputEvent
* event
= base::get
<0>(params
);
493 SendTouchEventACK(event
->type
, ack_result
,
494 WebInputEventTraits::GetUniqueTouchEventId(*event
));
497 const ui::MotionEventAura
& pointer_state() {
498 return view_
->pointer_state_for_test();
502 // If true, then calls RWH::Shutdown() instead of deleting RWH.
503 bool widget_host_uses_shutdown_to_destroy_
;
505 bool is_guest_view_hack_
;
507 base::MessageLoopForUI message_loop_
;
508 BrowserThreadImpl browser_thread_for_ui_
;
509 scoped_ptr
<aura::test::AuraTestHelper
> aura_test_helper_
;
510 scoped_ptr
<BrowserContext
> browser_context_
;
511 MockRenderWidgetHostDelegate delegate_
;
512 MockRenderProcessHost
* process_host_
;
514 // Tests should set these to NULL if they've already triggered their
516 RenderWidgetHostImpl
* parent_host_
;
517 RenderWidgetHostViewAura
* parent_view_
;
519 // Tests should set these to NULL if they've already triggered their
521 RenderWidgetHostImpl
* widget_host_
;
522 FakeRenderWidgetHostViewAura
* view_
;
524 IPC::TestSink
* sink_
;
527 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraTest
);
530 // Helper class to instantiate RenderWidgetHostViewGuest which is backed
531 // by an aura platform view.
532 class RenderWidgetHostViewGuestAuraTest
: public RenderWidgetHostViewAuraTest
{
534 RenderWidgetHostViewGuestAuraTest() {
535 // Use RWH::Shutdown to destroy RWH, instead of deleting.
536 // This will ensure that the RenderWidgetHostViewGuest is not leaked and
537 // is deleted properly upon RWH going away.
538 set_widget_host_uses_shutdown_to_destroy(true);
541 // We explicitly invoke SetUp to allow gesture debounce customization.
542 void SetUp() override
{
543 is_guest_view_hack_
= true;
545 RenderWidgetHostViewAuraTest::SetUp();
547 guest_view_weak_
= (new RenderWidgetHostViewGuest(
548 widget_host_
, NULL
, view_
->GetWeakPtr()))->GetWeakPtr();
551 void TearDown() override
{
552 // Internal override to do nothing, we clean up ourselves in the test body.
553 // This helps us test that |guest_view_weak_| does not leak.
557 base::WeakPtr
<RenderWidgetHostViewBase
> guest_view_weak_
;
561 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewGuestAuraTest
);
564 class RenderWidgetHostViewAuraOverscrollTest
565 : public RenderWidgetHostViewAuraTest
{
567 RenderWidgetHostViewAuraOverscrollTest() {}
569 // We explicitly invoke SetUp to allow gesture debounce customization.
570 void SetUp() override
{}
573 void SetUpOverscrollEnvironmentWithDebounce(int debounce_interval_in_ms
) {
574 SetUpOverscrollEnvironmentImpl(debounce_interval_in_ms
);
577 void SetUpOverscrollEnvironment() { SetUpOverscrollEnvironmentImpl(0); }
579 void SetUpOverscrollEnvironmentImpl(int debounce_interval_in_ms
) {
580 ui::GestureConfiguration::GetInstance()->set_scroll_debounce_interval_in_ms(
581 debounce_interval_in_ms
);
583 RenderWidgetHostViewAuraTest::SetUp();
585 view_
->SetOverscrollControllerEnabled(true);
586 overscroll_delegate_
.reset(new TestOverscrollDelegate(view_
));
587 view_
->overscroll_controller()->set_delegate(overscroll_delegate_
.get());
589 view_
->InitAsChild(NULL
);
590 view_
->SetBounds(gfx::Rect(0, 0, 400, 200));
593 sink_
->ClearMessages();
596 // TODO(jdduke): Simulate ui::Events, injecting through the view.
597 void SimulateMouseEvent(WebInputEvent::Type type
) {
598 widget_host_
->ForwardMouseEvent(SyntheticWebMouseEventBuilder::Build(type
));
601 void SimulateMouseEventWithLatencyInfo(WebInputEvent::Type type
,
602 const ui::LatencyInfo
& ui_latency
) {
603 widget_host_
->ForwardMouseEventWithLatencyInfo(
604 SyntheticWebMouseEventBuilder::Build(type
), ui_latency
);
607 void SimulateWheelEvent(float dX
, float dY
, int modifiers
, bool precise
) {
608 widget_host_
->ForwardWheelEvent(
609 SyntheticWebMouseWheelEventBuilder::Build(dX
, dY
, modifiers
, precise
));
612 void SimulateWheelEventWithLatencyInfo(float dX
,
616 const ui::LatencyInfo
& ui_latency
) {
617 widget_host_
->ForwardWheelEventWithLatencyInfo(
618 SyntheticWebMouseWheelEventBuilder::Build(dX
, dY
, modifiers
, precise
),
622 void SimulateMouseMove(int x
, int y
, int modifiers
) {
623 SimulateMouseEvent(WebInputEvent::MouseMove
, x
, y
, modifiers
, false);
626 void SimulateMouseEvent(WebInputEvent::Type type
,
631 WebMouseEvent event
=
632 SyntheticWebMouseEventBuilder::Build(type
, x
, y
, modifiers
);
634 event
.button
= WebMouseEvent::ButtonLeft
;
635 widget_host_
->ForwardMouseEvent(event
);
638 void SimulateWheelEventWithPhase(WebMouseWheelEvent::Phase phase
) {
639 widget_host_
->ForwardWheelEvent(
640 SyntheticWebMouseWheelEventBuilder::Build(phase
));
643 // Inject provided synthetic WebGestureEvent instance.
644 void SimulateGestureEventCore(const WebGestureEvent
& gesture_event
) {
645 widget_host_
->ForwardGestureEvent(gesture_event
);
648 void SimulateGestureEventCoreWithLatencyInfo(
649 const WebGestureEvent
& gesture_event
,
650 const ui::LatencyInfo
& ui_latency
) {
651 widget_host_
->ForwardGestureEventWithLatencyInfo(gesture_event
, ui_latency
);
654 // Inject simple synthetic WebGestureEvent instances.
655 void SimulateGestureEvent(WebInputEvent::Type type
,
656 blink::WebGestureDevice sourceDevice
) {
657 SimulateGestureEventCore(
658 SyntheticWebGestureEventBuilder::Build(type
, sourceDevice
));
661 void SimulateGestureEventWithLatencyInfo(WebInputEvent::Type type
,
662 blink::WebGestureDevice sourceDevice
,
663 const ui::LatencyInfo
& ui_latency
) {
664 SimulateGestureEventCoreWithLatencyInfo(
665 SyntheticWebGestureEventBuilder::Build(type
, sourceDevice
), ui_latency
);
668 void SimulateGestureScrollUpdateEvent(float dX
, float dY
, int modifiers
) {
669 SimulateGestureEventCore(SyntheticWebGestureEventBuilder::BuildScrollUpdate(
670 dX
, dY
, modifiers
, blink::WebGestureDeviceTouchscreen
));
673 void SimulateGesturePinchUpdateEvent(float scale
,
677 SimulateGestureEventCore(SyntheticWebGestureEventBuilder::BuildPinchUpdate(
682 blink::WebGestureDeviceTouchscreen
));
685 // Inject synthetic GestureFlingStart events.
686 void SimulateGestureFlingStartEvent(float velocityX
,
688 blink::WebGestureDevice sourceDevice
) {
689 SimulateGestureEventCore(SyntheticWebGestureEventBuilder::BuildFling(
690 velocityX
, velocityY
, sourceDevice
));
693 bool ScrollStateIsContentScrolling() const {
694 return scroll_state() == OverscrollController::STATE_CONTENT_SCROLLING
;
697 bool ScrollStateIsOverscrolling() const {
698 return scroll_state() == OverscrollController::STATE_OVERSCROLLING
;
701 bool ScrollStateIsUnknown() const {
702 return scroll_state() == OverscrollController::STATE_UNKNOWN
;
705 OverscrollController::ScrollState
scroll_state() const {
706 return view_
->overscroll_controller()->scroll_state_
;
709 OverscrollMode
overscroll_mode() const {
710 return view_
->overscroll_controller()->overscroll_mode_
;
713 float overscroll_delta_x() const {
714 return view_
->overscroll_controller()->overscroll_delta_x_
;
717 float overscroll_delta_y() const {
718 return view_
->overscroll_controller()->overscroll_delta_y_
;
721 TestOverscrollDelegate
* overscroll_delegate() {
722 return overscroll_delegate_
.get();
725 uint32
SendTouchEvent() {
726 uint32 touch_event_id
= touch_event_
.uniqueTouchEventId
;
727 widget_host_
->ForwardTouchEventWithLatencyInfo(touch_event_
,
729 touch_event_
.ResetPoints();
730 return touch_event_id
;
733 void PressTouchPoint(int x
, int y
) {
734 touch_event_
.PressPoint(x
, y
);
737 void MoveTouchPoint(int index
, int x
, int y
) {
738 touch_event_
.MovePoint(index
, x
, y
);
741 void ReleaseTouchPoint(int index
) {
742 touch_event_
.ReleasePoint(index
);
745 SyntheticWebTouchEvent touch_event_
;
747 scoped_ptr
<TestOverscrollDelegate
> overscroll_delegate_
;
750 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraOverscrollTest
);
753 class RenderWidgetHostViewAuraShutdownTest
754 : public RenderWidgetHostViewAuraTest
{
756 RenderWidgetHostViewAuraShutdownTest() {}
758 void TearDown() override
{
759 // No TearDownEnvironment here, we do this explicitly during the test.
763 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraShutdownTest
);
766 // Checks that a fullscreen view has the correct show-state and receives the
768 TEST_F(RenderWidgetHostViewAuraTest
, FocusFullscreen
) {
769 view_
->InitAsFullscreen(parent_view_
);
770 aura::Window
* window
= view_
->GetNativeView();
771 ASSERT_TRUE(window
!= NULL
);
772 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN
,
773 window
->GetProperty(aura::client::kShowStateKey
));
775 // Check that we requested and received the focus.
776 EXPECT_TRUE(window
->HasFocus());
778 // Check that we'll also say it's okay to activate the window when there's an
779 // ActivationClient defined.
780 EXPECT_TRUE(view_
->ShouldActivate());
783 // Checks that a popup is positioned correctly relative to its parent using
784 // screen coordinates.
785 TEST_F(RenderWidgetHostViewAuraTest
, PositionChildPopup
) {
786 wm::DefaultScreenPositionClient screen_position_client
;
788 aura::Window
* window
= parent_view_
->GetNativeView();
789 aura::Window
* root
= window
->GetRootWindow();
790 aura::client::SetScreenPositionClient(root
, &screen_position_client
);
792 parent_view_
->SetBounds(gfx::Rect(10, 10, 800, 600));
793 gfx::Rect bounds_in_screen
= parent_view_
->GetViewBounds();
794 int horiz
= bounds_in_screen
.width() / 4;
795 int vert
= bounds_in_screen
.height() / 4;
796 bounds_in_screen
.Inset(horiz
, vert
);
798 // Verify that when the popup is initialized for the first time, it correctly
799 // treats the input bounds as screen coordinates.
800 view_
->InitAsPopup(parent_view_
, bounds_in_screen
);
802 gfx::Rect final_bounds_in_screen
= view_
->GetViewBounds();
803 EXPECT_EQ(final_bounds_in_screen
.ToString(), bounds_in_screen
.ToString());
805 // Verify that directly setting the bounds via SetBounds() treats the input
806 // as screen coordinates.
807 bounds_in_screen
= gfx::Rect(60, 60, 100, 100);
808 view_
->SetBounds(bounds_in_screen
);
809 final_bounds_in_screen
= view_
->GetViewBounds();
810 EXPECT_EQ(final_bounds_in_screen
.ToString(), bounds_in_screen
.ToString());
812 // Verify that setting the size does not alter the origin.
813 gfx::Point original_origin
= window
->bounds().origin();
814 view_
->SetSize(gfx::Size(120, 120));
815 gfx::Point new_origin
= window
->bounds().origin();
816 EXPECT_EQ(original_origin
.ToString(), new_origin
.ToString());
818 aura::client::SetScreenPositionClient(root
, NULL
);
821 // Checks that moving parent sends new screen bounds.
822 TEST_F(RenderWidgetHostViewAuraTest
, ParentMovementUpdatesScreenRect
) {
823 view_
->InitAsChild(NULL
);
825 aura::Window
* root
= parent_view_
->GetNativeView()->GetRootWindow();
827 aura::test::TestWindowDelegate delegate1
, delegate2
;
828 scoped_ptr
<aura::Window
> parent1(new aura::Window(&delegate1
));
829 parent1
->Init(ui::LAYER_TEXTURED
);
831 scoped_ptr
<aura::Window
> parent2(new aura::Window(&delegate2
));
832 parent2
->Init(ui::LAYER_TEXTURED
);
835 root
->AddChild(parent1
.get());
836 parent1
->AddChild(parent2
.get());
837 parent2
->AddChild(view_
->GetNativeView());
839 root
->SetBounds(gfx::Rect(0, 0, 800, 600));
840 parent1
->SetBounds(gfx::Rect(1, 1, 300, 300));
841 parent2
->SetBounds(gfx::Rect(2, 2, 200, 200));
842 view_
->SetBounds(gfx::Rect(3, 3, 100, 100));
843 // view_ will be destroyed when parent is destroyed.
846 // Flush the state after initial setup is done.
847 widget_host_
->OnMessageReceived(
848 ViewHostMsg_UpdateScreenRects_ACK(widget_host_
->GetRoutingID()));
849 widget_host_
->OnMessageReceived(
850 ViewHostMsg_UpdateScreenRects_ACK(widget_host_
->GetRoutingID()));
851 sink_
->ClearMessages();
854 parent2
->SetBounds(gfx::Rect(20, 20, 200, 200));
855 ASSERT_EQ(1U, sink_
->message_count());
856 const IPC::Message
* msg
= sink_
->GetMessageAt(0);
857 ASSERT_EQ(ViewMsg_UpdateScreenRects::ID
, msg
->type());
858 ViewMsg_UpdateScreenRects::Param params
;
859 ViewMsg_UpdateScreenRects::Read(msg
, ¶ms
);
860 EXPECT_EQ(gfx::Rect(24, 24, 100, 100), base::get
<0>(params
));
861 EXPECT_EQ(gfx::Rect(1, 1, 300, 300), base::get
<1>(params
));
862 sink_
->ClearMessages();
863 widget_host_
->OnMessageReceived(
864 ViewHostMsg_UpdateScreenRects_ACK(widget_host_
->GetRoutingID()));
865 // There should not be any pending update.
866 EXPECT_EQ(0U, sink_
->message_count());
868 parent1
->SetBounds(gfx::Rect(10, 10, 300, 300));
869 ASSERT_EQ(1U, sink_
->message_count());
870 msg
= sink_
->GetMessageAt(0);
871 ASSERT_EQ(ViewMsg_UpdateScreenRects::ID
, msg
->type());
872 ViewMsg_UpdateScreenRects::Read(msg
, ¶ms
);
873 EXPECT_EQ(gfx::Rect(33, 33, 100, 100), base::get
<0>(params
));
874 EXPECT_EQ(gfx::Rect(10, 10, 300, 300), base::get
<1>(params
));
875 sink_
->ClearMessages();
876 widget_host_
->OnMessageReceived(
877 ViewHostMsg_UpdateScreenRects_ACK(widget_host_
->GetRoutingID()));
878 // There should not be any pending update.
879 EXPECT_EQ(0U, sink_
->message_count());
882 // Checks that a fullscreen view is destroyed when it loses the focus.
883 TEST_F(RenderWidgetHostViewAuraTest
, DestroyFullscreenOnBlur
) {
884 view_
->InitAsFullscreen(parent_view_
);
885 aura::Window
* window
= view_
->GetNativeView();
886 ASSERT_TRUE(window
!= NULL
);
887 ASSERT_TRUE(window
->HasFocus());
889 // After we create and focus another window, the RWHVA's window should be
891 TestWindowObserver
observer(window
);
892 aura::test::TestWindowDelegate delegate
;
893 scoped_ptr
<aura::Window
> sibling(new aura::Window(&delegate
));
894 sibling
->Init(ui::LAYER_TEXTURED
);
896 window
->parent()->AddChild(sibling
.get());
898 ASSERT_TRUE(sibling
->HasFocus());
899 ASSERT_TRUE(observer
.destroyed());
905 // Checks that a popup view is destroyed when a user clicks outside of the popup
906 // view and focus does not change. This is the case when the user clicks on the
907 // desktop background on Chrome OS.
908 TEST_F(RenderWidgetHostViewAuraTest
, DestroyPopupClickOutsidePopup
) {
909 parent_view_
->SetBounds(gfx::Rect(10, 10, 400, 400));
910 parent_view_
->Focus();
911 EXPECT_TRUE(parent_view_
->HasFocus());
913 view_
->InitAsPopup(parent_view_
, gfx::Rect(10, 10, 100, 100));
914 aura::Window
* window
= view_
->GetNativeView();
915 ASSERT_TRUE(window
!= NULL
);
917 gfx::Point click_point
;
918 EXPECT_FALSE(window
->GetBoundsInRootWindow().Contains(click_point
));
919 aura::Window
* parent_window
= parent_view_
->GetNativeView();
920 EXPECT_FALSE(parent_window
->GetBoundsInRootWindow().Contains(click_point
));
922 TestWindowObserver
observer(window
);
923 ui::test::EventGenerator
generator(window
->GetRootWindow(), click_point
);
924 generator
.ClickLeftButton();
925 ASSERT_TRUE(parent_view_
->HasFocus());
926 ASSERT_TRUE(observer
.destroyed());
932 // Checks that a popup view is destroyed when a user taps outside of the popup
933 // view and focus does not change. This is the case when the user taps the
934 // desktop background on Chrome OS.
935 TEST_F(RenderWidgetHostViewAuraTest
, DestroyPopupTapOutsidePopup
) {
936 parent_view_
->SetBounds(gfx::Rect(10, 10, 400, 400));
937 parent_view_
->Focus();
938 EXPECT_TRUE(parent_view_
->HasFocus());
940 view_
->InitAsPopup(parent_view_
, gfx::Rect(10, 10, 100, 100));
941 aura::Window
* window
= view_
->GetNativeView();
942 ASSERT_TRUE(window
!= NULL
);
944 gfx::Point tap_point
;
945 EXPECT_FALSE(window
->GetBoundsInRootWindow().Contains(tap_point
));
946 aura::Window
* parent_window
= parent_view_
->GetNativeView();
947 EXPECT_FALSE(parent_window
->GetBoundsInRootWindow().Contains(tap_point
));
949 TestWindowObserver
observer(window
);
950 ui::test::EventGenerator
generator(window
->GetRootWindow(), tap_point
);
951 generator
.GestureTapAt(tap_point
);
952 ASSERT_TRUE(parent_view_
->HasFocus());
953 ASSERT_TRUE(observer
.destroyed());
959 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
961 // On Desktop Linux, select boxes need mouse capture in order to work. Test that
962 // when a select box is opened via a mouse press that it retains mouse capture
963 // after the mouse is released.
964 TEST_F(RenderWidgetHostViewAuraTest
, PopupRetainsCaptureAfterMouseRelease
) {
965 parent_view_
->SetBounds(gfx::Rect(10, 10, 400, 400));
966 parent_view_
->Focus();
967 EXPECT_TRUE(parent_view_
->HasFocus());
969 ui::test::EventGenerator
generator(
970 parent_view_
->GetNativeView()->GetRootWindow(), gfx::Point(300, 300));
971 generator
.PressLeftButton();
973 view_
->SetPopupType(blink::WebPopupTypePage
);
974 view_
->InitAsPopup(parent_view_
, gfx::Rect(10, 10, 100, 100));
975 ASSERT_TRUE(view_
->NeedsMouseCapture());
976 aura::Window
* window
= view_
->GetNativeView();
977 EXPECT_TRUE(window
->HasCapture());
979 generator
.ReleaseLeftButton();
980 EXPECT_TRUE(window
->HasCapture());
984 // Test that select boxes close when their parent window loses focus (e.g. due
985 // to an alert or system modal dialog).
986 TEST_F(RenderWidgetHostViewAuraTest
, PopupClosesWhenParentLosesFocus
) {
987 parent_view_
->SetBounds(gfx::Rect(10, 10, 400, 400));
988 parent_view_
->Focus();
989 EXPECT_TRUE(parent_view_
->HasFocus());
991 view_
->SetPopupType(blink::WebPopupTypePage
);
992 view_
->InitAsPopup(parent_view_
, gfx::Rect(10, 10, 100, 100));
994 aura::Window
* popup_window
= view_
->GetNativeView();
995 TestWindowObserver
observer(popup_window
);
997 aura::test::TestWindowDelegate delegate
;
998 scoped_ptr
<aura::Window
> dialog_window(new aura::Window(&delegate
));
999 dialog_window
->Init(ui::LAYER_TEXTURED
);
1000 aura::client::ParentWindowWithContext(
1001 dialog_window
.get(), popup_window
, gfx::Rect());
1002 dialog_window
->Show();
1003 wm::ActivateWindow(dialog_window
.get());
1004 dialog_window
->Focus();
1006 ASSERT_TRUE(wm::IsActiveWindow(dialog_window
.get()));
1007 EXPECT_TRUE(observer
.destroyed());
1009 widget_host_
= NULL
;
1013 // Checks that IME-composition-event state is maintained correctly.
1014 TEST_F(RenderWidgetHostViewAuraTest
, SetCompositionText
) {
1015 view_
->InitAsChild(NULL
);
1018 ui::CompositionText composition_text
;
1019 composition_text
.text
= base::ASCIIToUTF16("|a|b");
1022 composition_text
.underlines
.push_back(
1023 ui::CompositionUnderline(0, 3, 0xff000000, true, 0x78563412));
1025 // Non-focused segment, with different background color.
1026 composition_text
.underlines
.push_back(
1027 ui::CompositionUnderline(3, 4, 0xff000000, false, 0xefcdab90));
1029 const ui::CompositionUnderlines
& underlines
= composition_text
.underlines
;
1031 // Caret is at the end. (This emulates Japanese MSIME 2007 and later)
1032 composition_text
.selection
= gfx::Range(4);
1034 sink_
->ClearMessages();
1035 view_
->SetCompositionText(composition_text
);
1036 EXPECT_TRUE(view_
->has_composition_text_
);
1038 const IPC::Message
* msg
=
1039 sink_
->GetFirstMessageMatching(InputMsg_ImeSetComposition::ID
);
1040 ASSERT_TRUE(msg
!= NULL
);
1042 InputMsg_ImeSetComposition::Param params
;
1043 InputMsg_ImeSetComposition::Read(msg
, ¶ms
);
1045 EXPECT_EQ(composition_text
.text
, base::get
<0>(params
));
1047 ASSERT_EQ(underlines
.size(), base::get
<1>(params
).size());
1048 for (size_t i
= 0; i
< underlines
.size(); ++i
) {
1049 EXPECT_EQ(underlines
[i
].start_offset
,
1050 base::get
<1>(params
)[i
].startOffset
);
1051 EXPECT_EQ(underlines
[i
].end_offset
, base::get
<1>(params
)[i
].endOffset
);
1052 EXPECT_EQ(underlines
[i
].color
, base::get
<1>(params
)[i
].color
);
1053 EXPECT_EQ(underlines
[i
].thick
, base::get
<1>(params
)[i
].thick
);
1054 EXPECT_EQ(underlines
[i
].background_color
,
1055 base::get
<1>(params
)[i
].backgroundColor
);
1057 // highlighted range
1058 EXPECT_EQ(4, base::get
<2>(params
)) << "Should be the same to the caret pos";
1059 EXPECT_EQ(4, base::get
<3>(params
)) << "Should be the same to the caret pos";
1062 view_
->ImeCancelComposition();
1063 EXPECT_FALSE(view_
->has_composition_text_
);
1066 // Checks that sequence of IME-composition-event and mouse-event when mouse
1067 // clicking to cancel the composition.
1068 TEST_F(RenderWidgetHostViewAuraTest
, FinishCompositionByMouse
) {
1069 view_
->InitAsChild(NULL
);
1072 ui::CompositionText composition_text
;
1073 composition_text
.text
= base::ASCIIToUTF16("|a|b");
1076 composition_text
.underlines
.push_back(
1077 ui::CompositionUnderline(0, 3, 0xff000000, true, 0x78563412));
1079 // Non-focused segment, with different background color.
1080 composition_text
.underlines
.push_back(
1081 ui::CompositionUnderline(3, 4, 0xff000000, false, 0xefcdab90));
1083 // Caret is at the end. (This emulates Japanese MSIME 2007 and later)
1084 composition_text
.selection
= gfx::Range(4);
1086 view_
->SetCompositionText(composition_text
);
1087 EXPECT_TRUE(view_
->has_composition_text_
);
1088 sink_
->ClearMessages();
1090 // Simulates the mouse press.
1091 ui::MouseEvent
mouse_event(ui::ET_MOUSE_PRESSED
, gfx::Point(), gfx::Point(),
1092 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON
,
1094 view_
->OnMouseEvent(&mouse_event
);
1096 EXPECT_FALSE(view_
->has_composition_text_
);
1098 EXPECT_EQ(2U, sink_
->message_count());
1100 if (sink_
->message_count() == 2) {
1101 // Verify mouse event happens after the confirm-composition event.
1102 EXPECT_EQ(InputMsg_ImeConfirmComposition::ID
,
1103 sink_
->GetMessageAt(0)->type());
1104 EXPECT_EQ(InputMsg_HandleInputEvent::ID
,
1105 sink_
->GetMessageAt(1)->type());
1109 // Checks that touch-event state is maintained correctly.
1110 TEST_F(RenderWidgetHostViewAuraTest
, TouchEventState
) {
1111 view_
->InitAsChild(NULL
);
1113 GetSentMessageCountAndResetSink();
1115 // Start with no touch-event handler in the renderer.
1116 widget_host_
->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, false));
1118 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
,
1121 ui::EventTimeForNow());
1122 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
,
1125 ui::EventTimeForNow());
1126 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
,
1129 ui::EventTimeForNow());
1131 // The touch events should get forwarded from the view, but they should not
1132 // reach the renderer.
1133 view_
->OnTouchEvent(&press
);
1134 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1135 EXPECT_TRUE(press
.synchronous_handling_disabled());
1136 EXPECT_EQ(ui::MotionEvent::ACTION_DOWN
, pointer_state().GetAction());
1138 view_
->OnTouchEvent(&move
);
1139 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1140 EXPECT_TRUE(press
.synchronous_handling_disabled());
1141 EXPECT_EQ(ui::MotionEvent::ACTION_MOVE
, pointer_state().GetAction());
1142 EXPECT_EQ(1U, pointer_state().GetPointerCount());
1144 view_
->OnTouchEvent(&release
);
1145 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1146 EXPECT_TRUE(press
.synchronous_handling_disabled());
1147 EXPECT_EQ(0U, pointer_state().GetPointerCount());
1149 // Now install some touch-event handlers and do the same steps. The touch
1150 // events should now be consumed. However, the touch-event state should be
1151 // updated as before.
1152 widget_host_
->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
1154 view_
->OnTouchEvent(&press
);
1155 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1156 EXPECT_TRUE(press
.synchronous_handling_disabled());
1157 EXPECT_EQ(ui::MotionEvent::ACTION_DOWN
, pointer_state().GetAction());
1158 EXPECT_EQ(1U, pointer_state().GetPointerCount());
1160 view_
->OnTouchEvent(&move
);
1161 EXPECT_TRUE(move
.synchronous_handling_disabled());
1162 EXPECT_EQ(ui::MotionEvent::ACTION_MOVE
, pointer_state().GetAction());
1163 EXPECT_EQ(1U, pointer_state().GetPointerCount());
1164 view_
->OnTouchEvent(&release
);
1165 EXPECT_TRUE(release
.synchronous_handling_disabled());
1166 EXPECT_EQ(0U, pointer_state().GetPointerCount());
1168 // Now start a touch event, and remove the event-handlers before the release.
1169 view_
->OnTouchEvent(&press
);
1170 EXPECT_TRUE(press
.synchronous_handling_disabled());
1171 EXPECT_EQ(ui::MotionEvent::ACTION_DOWN
, pointer_state().GetAction());
1172 EXPECT_EQ(1U, pointer_state().GetPointerCount());
1174 widget_host_
->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, false));
1176 // Ack'ing the outstanding event should flush the pending touch queue.
1177 InputEventAck
ack(blink::WebInputEvent::TouchStart
,
1178 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS
,
1179 press
.unique_event_id());
1180 widget_host_
->OnMessageReceived(InputHostMsg_HandleInputEvent_ACK(0, ack
));
1181 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1183 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(20, 20), 0,
1184 base::Time::NowFromSystemTime() - base::Time());
1185 view_
->OnTouchEvent(&move2
);
1186 EXPECT_TRUE(press
.synchronous_handling_disabled());
1187 EXPECT_EQ(ui::MotionEvent::ACTION_MOVE
, pointer_state().GetAction());
1188 EXPECT_EQ(1U, pointer_state().GetPointerCount());
1190 ui::TouchEvent
release2(ui::ET_TOUCH_RELEASED
, gfx::Point(20, 20), 0,
1191 base::Time::NowFromSystemTime() - base::Time());
1192 view_
->OnTouchEvent(&release2
);
1193 EXPECT_TRUE(press
.synchronous_handling_disabled());
1194 EXPECT_EQ(0U, pointer_state().GetPointerCount());
1197 // Checks that touch-event state is maintained correctly for multiple touch
1199 TEST_F(RenderWidgetHostViewAuraTest
, MultiTouchPointsStates
) {
1200 view_
->InitAsFullscreen(parent_view_
);
1202 view_
->UseFakeDispatcher();
1203 GetSentMessageCountAndResetSink();
1205 ui::TouchEvent
press0(ui::ET_TOUCH_PRESSED
, gfx::Point(30, 30), 0,
1206 ui::EventTimeForNow());
1208 view_
->OnTouchEvent(&press0
);
1209 SendTouchEventACK(blink::WebInputEvent::TouchStart
,
1210 INPUT_EVENT_ACK_STATE_CONSUMED
,
1211 press0
.unique_event_id());
1212 EXPECT_EQ(ui::MotionEvent::ACTION_DOWN
, pointer_state().GetAction());
1213 EXPECT_EQ(1U, pointer_state().GetPointerCount());
1214 EXPECT_EQ(1U, view_
->dispatcher_
->GetAndResetProcessedTouchEventCount());
1216 ui::TouchEvent
move0(ui::ET_TOUCH_MOVED
, gfx::Point(20, 20), 0,
1217 ui::EventTimeForNow());
1219 view_
->OnTouchEvent(&move0
);
1220 SendTouchEventACK(blink::WebInputEvent::TouchMove
,
1221 INPUT_EVENT_ACK_STATE_CONSUMED
,
1222 move0
.unique_event_id());
1223 EXPECT_EQ(ui::MotionEvent::ACTION_MOVE
, pointer_state().GetAction());
1224 EXPECT_EQ(1U, pointer_state().GetPointerCount());
1225 EXPECT_EQ(1U, view_
->dispatcher_
->GetAndResetProcessedTouchEventCount());
1227 // For the second touchstart, only the state of the second touch point is
1228 // StatePressed, the state of the first touch point is StateStationary.
1229 ui::TouchEvent
press1(ui::ET_TOUCH_PRESSED
, gfx::Point(10, 10), 1,
1230 ui::EventTimeForNow());
1232 view_
->OnTouchEvent(&press1
);
1233 SendTouchEventACK(blink::WebInputEvent::TouchStart
,
1234 INPUT_EVENT_ACK_STATE_CONSUMED
,
1235 press1
.unique_event_id());
1236 EXPECT_EQ(ui::MotionEvent::ACTION_POINTER_DOWN
, pointer_state().GetAction());
1237 EXPECT_EQ(1, pointer_state().GetActionIndex());
1238 EXPECT_EQ(2U, pointer_state().GetPointerCount());
1239 EXPECT_EQ(1U, view_
->dispatcher_
->GetAndResetProcessedTouchEventCount());
1241 // For the touchmove of second point, the state of the second touch point is
1242 // StateMoved, the state of the first touch point is StateStationary.
1243 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
, gfx::Point(30, 30), 1,
1244 ui::EventTimeForNow());
1246 view_
->OnTouchEvent(&move1
);
1247 SendTouchEventACK(blink::WebInputEvent::TouchMove
,
1248 INPUT_EVENT_ACK_STATE_CONSUMED
,
1249 move1
.unique_event_id());
1250 EXPECT_EQ(ui::MotionEvent::ACTION_MOVE
, pointer_state().GetAction());
1251 EXPECT_EQ(2U, pointer_state().GetPointerCount());
1252 EXPECT_EQ(1U, view_
->dispatcher_
->GetAndResetProcessedTouchEventCount());
1254 // For the touchmove of first point, the state of the first touch point is
1255 // StateMoved, the state of the second touch point is StateStationary.
1256 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(10, 10), 0,
1257 ui::EventTimeForNow());
1259 view_
->OnTouchEvent(&move2
);
1260 SendTouchEventACK(blink::WebInputEvent::TouchMove
,
1261 INPUT_EVENT_ACK_STATE_CONSUMED
,
1262 move2
.unique_event_id());
1263 EXPECT_EQ(ui::MotionEvent::ACTION_MOVE
, pointer_state().GetAction());
1264 EXPECT_EQ(2U, pointer_state().GetPointerCount());
1265 EXPECT_EQ(1U, view_
->dispatcher_
->GetAndResetProcessedTouchEventCount());
1267 ui::TouchEvent
cancel0(ui::ET_TOUCH_CANCELLED
, gfx::Point(10, 10), 0,
1268 ui::EventTimeForNow());
1270 // For the touchcancel, only the state of the current touch point is
1271 // StateCancelled, the state of the other touch point is StateStationary.
1272 view_
->OnTouchEvent(&cancel0
);
1273 EXPECT_EQ(1U, pointer_state().GetPointerCount());
1274 EXPECT_EQ(1U, view_
->dispatcher_
->GetAndResetProcessedTouchEventCount());
1276 ui::TouchEvent
cancel1(ui::ET_TOUCH_CANCELLED
, gfx::Point(30, 30), 1,
1277 ui::EventTimeForNow());
1279 view_
->OnTouchEvent(&cancel1
);
1280 EXPECT_EQ(1U, view_
->dispatcher_
->GetAndResetProcessedTouchEventCount());
1281 EXPECT_EQ(0U, pointer_state().GetPointerCount());
1284 // Checks that touch-events are queued properly when there is a touch-event
1285 // handler on the page.
1286 TEST_F(RenderWidgetHostViewAuraTest
, TouchEventSyncAsync
) {
1287 view_
->InitAsChild(NULL
);
1290 widget_host_
->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
1292 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
,
1295 ui::EventTimeForNow());
1296 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
,
1299 ui::EventTimeForNow());
1300 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
,
1303 ui::EventTimeForNow());
1305 view_
->OnTouchEvent(&press
);
1306 EXPECT_TRUE(press
.synchronous_handling_disabled());
1307 EXPECT_EQ(ui::MotionEvent::ACTION_DOWN
, pointer_state().GetAction());
1308 EXPECT_EQ(1U, pointer_state().GetPointerCount());
1310 view_
->OnTouchEvent(&move
);
1311 EXPECT_TRUE(move
.synchronous_handling_disabled());
1312 EXPECT_EQ(ui::MotionEvent::ACTION_MOVE
, pointer_state().GetAction());
1313 EXPECT_EQ(1U, pointer_state().GetPointerCount());
1315 // Send the same move event. Since the point hasn't moved, it won't affect the
1316 // queue. However, the view should consume the event.
1317 view_
->OnTouchEvent(&move
);
1318 EXPECT_TRUE(move
.synchronous_handling_disabled());
1319 EXPECT_EQ(ui::MotionEvent::ACTION_MOVE
, pointer_state().GetAction());
1320 EXPECT_EQ(1U, pointer_state().GetPointerCount());
1322 view_
->OnTouchEvent(&release
);
1323 EXPECT_TRUE(release
.synchronous_handling_disabled());
1324 EXPECT_EQ(0U, pointer_state().GetPointerCount());
1327 TEST_F(RenderWidgetHostViewAuraTest
, PhysicalBackingSizeWithScale
) {
1328 view_
->InitAsChild(NULL
);
1329 aura::client::ParentWindowWithContext(
1330 view_
->GetNativeView(),
1331 parent_view_
->GetNativeView()->GetRootWindow(),
1333 sink_
->ClearMessages();
1334 view_
->SetSize(gfx::Size(100, 100));
1335 EXPECT_EQ("100x100", view_
->GetPhysicalBackingSize().ToString());
1336 EXPECT_EQ(1u, sink_
->message_count());
1337 EXPECT_EQ(ViewMsg_Resize::ID
, sink_
->GetMessageAt(0)->type());
1339 const IPC::Message
* msg
= sink_
->GetMessageAt(0);
1340 EXPECT_EQ(ViewMsg_Resize::ID
, msg
->type());
1341 ViewMsg_Resize::Param params
;
1342 ViewMsg_Resize::Read(msg
, ¶ms
);
1343 EXPECT_EQ("100x100", base::get
<0>(params
).new_size
.ToString()); // dip size
1344 EXPECT_EQ("100x100",
1345 base::get
<0>(params
).physical_backing_size
.ToString()); // backing size
1348 widget_host_
->ResetSizeAndRepaintPendingFlags();
1349 sink_
->ClearMessages();
1351 aura_test_helper_
->test_screen()->SetDeviceScaleFactor(2.0f
);
1352 EXPECT_EQ("200x200", view_
->GetPhysicalBackingSize().ToString());
1353 // Extra ScreenInfoChanged message for |parent_view_|.
1354 EXPECT_EQ(1u, sink_
->message_count());
1356 const IPC::Message
* msg
= sink_
->GetMessageAt(0);
1357 EXPECT_EQ(ViewMsg_Resize::ID
, msg
->type());
1358 ViewMsg_Resize::Param params
;
1359 ViewMsg_Resize::Read(msg
, ¶ms
);
1360 EXPECT_EQ(2.0f
, base::get
<0>(params
).screen_info
.deviceScaleFactor
);
1361 EXPECT_EQ("100x100", base::get
<0>(params
).new_size
.ToString()); // dip size
1362 EXPECT_EQ("200x200",
1363 base::get
<0>(params
).physical_backing_size
.ToString()); // backing size
1366 widget_host_
->ResetSizeAndRepaintPendingFlags();
1367 sink_
->ClearMessages();
1369 aura_test_helper_
->test_screen()->SetDeviceScaleFactor(1.0f
);
1370 // Extra ScreenInfoChanged message for |parent_view_|.
1371 EXPECT_EQ(1u, sink_
->message_count());
1372 EXPECT_EQ("100x100", view_
->GetPhysicalBackingSize().ToString());
1374 const IPC::Message
* msg
= sink_
->GetMessageAt(0);
1375 EXPECT_EQ(ViewMsg_Resize::ID
, msg
->type());
1376 ViewMsg_Resize::Param params
;
1377 ViewMsg_Resize::Read(msg
, ¶ms
);
1378 EXPECT_EQ(1.0f
, base::get
<0>(params
).screen_info
.deviceScaleFactor
);
1379 EXPECT_EQ("100x100", base::get
<0>(params
).new_size
.ToString()); // dip size
1380 EXPECT_EQ("100x100",
1381 base::get
<0>(params
).physical_backing_size
.ToString()); // backing size
1385 // Checks that InputMsg_CursorVisibilityChange IPC messages are dispatched
1386 // to the renderer at the correct times.
1387 TEST_F(RenderWidgetHostViewAuraTest
, CursorVisibilityChange
) {
1388 view_
->InitAsChild(NULL
);
1389 aura::client::ParentWindowWithContext(
1390 view_
->GetNativeView(),
1391 parent_view_
->GetNativeView()->GetRootWindow(),
1393 view_
->SetSize(gfx::Size(100, 100));
1395 aura::test::TestCursorClient
cursor_client(
1396 parent_view_
->GetNativeView()->GetRootWindow());
1398 cursor_client
.AddObserver(view_
);
1400 // Expect a message the first time the cursor is shown.
1402 sink_
->ClearMessages();
1403 cursor_client
.ShowCursor();
1404 EXPECT_EQ(1u, sink_
->message_count());
1405 EXPECT_TRUE(sink_
->GetUniqueMessageMatching(
1406 InputMsg_CursorVisibilityChange::ID
));
1408 // No message expected if the renderer already knows the cursor is visible.
1409 sink_
->ClearMessages();
1410 cursor_client
.ShowCursor();
1411 EXPECT_EQ(0u, sink_
->message_count());
1413 // Hiding the cursor should send a message.
1414 sink_
->ClearMessages();
1415 cursor_client
.HideCursor();
1416 EXPECT_EQ(1u, sink_
->message_count());
1417 EXPECT_TRUE(sink_
->GetUniqueMessageMatching(
1418 InputMsg_CursorVisibilityChange::ID
));
1420 // No message expected if the renderer already knows the cursor is invisible.
1421 sink_
->ClearMessages();
1422 cursor_client
.HideCursor();
1423 EXPECT_EQ(0u, sink_
->message_count());
1425 // No messages should be sent while the view is invisible.
1427 sink_
->ClearMessages();
1428 cursor_client
.ShowCursor();
1429 EXPECT_EQ(0u, sink_
->message_count());
1430 cursor_client
.HideCursor();
1431 EXPECT_EQ(0u, sink_
->message_count());
1433 // Show the view. Since the cursor was invisible when the view was hidden,
1434 // no message should be sent.
1435 sink_
->ClearMessages();
1437 EXPECT_FALSE(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 // Showing the cursor should send a message.
1446 sink_
->ClearMessages();
1447 cursor_client
.ShowCursor();
1448 EXPECT_EQ(1u, sink_
->message_count());
1449 EXPECT_TRUE(sink_
->GetUniqueMessageMatching(
1450 InputMsg_CursorVisibilityChange::ID
));
1452 // No messages should be sent while the view is invisible.
1454 sink_
->ClearMessages();
1455 cursor_client
.HideCursor();
1456 EXPECT_EQ(0u, sink_
->message_count());
1458 // Show the view. Since the cursor was visible when the view was hidden,
1459 // a message is expected to be sent.
1460 sink_
->ClearMessages();
1462 EXPECT_TRUE(sink_
->GetUniqueMessageMatching(
1463 InputMsg_CursorVisibilityChange::ID
));
1465 cursor_client
.RemoveObserver(view_
);
1468 TEST_F(RenderWidgetHostViewAuraTest
, UpdateCursorIfOverSelf
) {
1469 view_
->InitAsChild(NULL
);
1470 aura::client::ParentWindowWithContext(
1471 view_
->GetNativeView(),
1472 parent_view_
->GetNativeView()->GetRootWindow(),
1475 // Note that all coordinates in this test are screen coordinates.
1476 view_
->SetBounds(gfx::Rect(60, 60, 100, 100));
1479 aura::test::TestCursorClient
cursor_client(
1480 parent_view_
->GetNativeView()->GetRootWindow());
1482 // Cursor is in the middle of the window.
1483 cursor_client
.reset_calls_to_set_cursor();
1484 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(110, 110));
1485 view_
->UpdateCursorIfOverSelf();
1486 EXPECT_EQ(1, cursor_client
.calls_to_set_cursor());
1488 // Cursor is near the top of the window.
1489 cursor_client
.reset_calls_to_set_cursor();
1490 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(80, 65));
1491 view_
->UpdateCursorIfOverSelf();
1492 EXPECT_EQ(1, cursor_client
.calls_to_set_cursor());
1494 // Cursor is near the bottom of the window.
1495 cursor_client
.reset_calls_to_set_cursor();
1496 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(159, 159));
1497 view_
->UpdateCursorIfOverSelf();
1498 EXPECT_EQ(1, cursor_client
.calls_to_set_cursor());
1500 // Cursor is above the window.
1501 cursor_client
.reset_calls_to_set_cursor();
1502 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(67, 59));
1503 view_
->UpdateCursorIfOverSelf();
1504 EXPECT_EQ(0, cursor_client
.calls_to_set_cursor());
1506 // Cursor is below the window.
1507 cursor_client
.reset_calls_to_set_cursor();
1508 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(161, 161));
1509 view_
->UpdateCursorIfOverSelf();
1510 EXPECT_EQ(0, cursor_client
.calls_to_set_cursor());
1513 scoped_ptr
<cc::CompositorFrame
> MakeDelegatedFrame(float scale_factor
,
1516 scoped_ptr
<cc::CompositorFrame
> frame(new cc::CompositorFrame
);
1517 frame
->metadata
.device_scale_factor
= scale_factor
;
1518 frame
->delegated_frame_data
.reset(new cc::DelegatedFrameData
);
1520 scoped_ptr
<cc::RenderPass
> pass
= cc::RenderPass::Create();
1522 cc::RenderPassId(1, 1), gfx::Rect(size
), damage
, gfx::Transform());
1523 frame
->delegated_frame_data
->render_pass_list
.push_back(pass
.Pass());
1524 return frame
.Pass();
1527 // Resizing in fullscreen mode should send the up-to-date screen info.
1528 // http://crbug.com/324350
1529 TEST_F(RenderWidgetHostViewAuraTest
, DISABLED_FullscreenResize
) {
1530 aura::Window
* root_window
= aura_test_helper_
->root_window();
1531 root_window
->SetLayoutManager(new FullscreenLayoutManager(root_window
));
1532 view_
->InitAsFullscreen(parent_view_
);
1534 widget_host_
->ResetSizeAndRepaintPendingFlags();
1535 sink_
->ClearMessages();
1537 // Call WasResized to flush the old screen info.
1538 view_
->GetRenderWidgetHost()->WasResized();
1540 // 0 is CreatingNew message.
1541 const IPC::Message
* msg
= sink_
->GetMessageAt(0);
1542 EXPECT_EQ(ViewMsg_Resize::ID
, msg
->type());
1543 ViewMsg_Resize::Param params
;
1544 ViewMsg_Resize::Read(msg
, ¶ms
);
1545 EXPECT_EQ("0,0 800x600",
1547 base::get
<0>(params
).screen_info
.availableRect
).ToString());
1548 EXPECT_EQ("800x600", base::get
<0>(params
).new_size
.ToString());
1549 // Resizes are blocked until we swapped a frame of the correct size, and
1550 // we've committed it.
1551 view_
->OnSwapCompositorFrame(
1554 1.f
, base::get
<0>(params
).new_size
,
1555 gfx::Rect(base::get
<0>(params
).new_size
)));
1556 ui::DrawWaiterForTest::WaitForCommit(
1557 root_window
->GetHost()->compositor());
1560 widget_host_
->ResetSizeAndRepaintPendingFlags();
1561 sink_
->ClearMessages();
1563 // Make sure the corrent screen size is set along in the resize
1564 // request when the screen size has changed.
1565 aura_test_helper_
->test_screen()->SetUIScale(0.5);
1566 EXPECT_EQ(1u, sink_
->message_count());
1568 const IPC::Message
* msg
= sink_
->GetMessageAt(0);
1569 EXPECT_EQ(ViewMsg_Resize::ID
, msg
->type());
1570 ViewMsg_Resize::Param params
;
1571 ViewMsg_Resize::Read(msg
, ¶ms
);
1572 EXPECT_EQ("0,0 1600x1200",
1574 base::get
<0>(params
).screen_info
.availableRect
).ToString());
1575 EXPECT_EQ("1600x1200", base::get
<0>(params
).new_size
.ToString());
1576 view_
->OnSwapCompositorFrame(
1579 1.f
, base::get
<0>(params
).new_size
,
1580 gfx::Rect(base::get
<0>(params
).new_size
)));
1581 ui::DrawWaiterForTest::WaitForCommit(
1582 root_window
->GetHost()->compositor());
1586 // Swapping a frame should notify the window.
1587 TEST_F(RenderWidgetHostViewAuraTest
, SwapNotifiesWindow
) {
1588 gfx::Size
view_size(100, 100);
1589 gfx::Rect
view_rect(view_size
);
1591 view_
->InitAsChild(NULL
);
1592 aura::client::ParentWindowWithContext(
1593 view_
->GetNativeView(),
1594 parent_view_
->GetNativeView()->GetRootWindow(),
1596 view_
->SetSize(view_size
);
1599 MockWindowObserver observer
;
1600 view_
->window_
->AddObserver(&observer
);
1602 // Delegated renderer path
1603 EXPECT_CALL(observer
, OnDelegatedFrameDamage(view_
->window_
, view_rect
));
1604 view_
->OnSwapCompositorFrame(
1605 0, MakeDelegatedFrame(1.f
, view_size
, view_rect
));
1606 testing::Mock::VerifyAndClearExpectations(&observer
);
1608 EXPECT_CALL(observer
, OnDelegatedFrameDamage(view_
->window_
,
1609 gfx::Rect(5, 5, 5, 5)));
1610 view_
->OnSwapCompositorFrame(
1611 0, MakeDelegatedFrame(1.f
, view_size
, gfx::Rect(5, 5, 5, 5)));
1612 testing::Mock::VerifyAndClearExpectations(&observer
);
1614 view_
->window_
->RemoveObserver(&observer
);
1617 // Recreating the layers for a window should cause Surface destruction to
1618 // depend on both layers.
1619 TEST_F(RenderWidgetHostViewAuraTest
, RecreateLayers
) {
1620 gfx::Size
view_size(100, 100);
1621 gfx::Rect
view_rect(view_size
);
1623 view_
->InitAsChild(NULL
);
1624 aura::client::ParentWindowWithContext(
1625 view_
->GetNativeView(), parent_view_
->GetNativeView()->GetRootWindow(),
1627 view_
->SetSize(view_size
);
1630 view_
->OnSwapCompositorFrame(0,
1631 MakeDelegatedFrame(1.f
, view_size
, view_rect
));
1632 scoped_ptr
<ui::LayerTreeOwner
> cloned_owner(
1633 wm::RecreateLayers(view_
->GetNativeView()));
1635 cc::SurfaceId id
= view_
->GetDelegatedFrameHost()->SurfaceIdForTesting();
1636 if (!id
.is_null()) {
1637 ImageTransportFactory
* factory
= ImageTransportFactory::GetInstance();
1638 cc::SurfaceManager
* manager
= factory
->GetSurfaceManager();
1639 cc::Surface
* surface
= manager
->GetSurfaceForId(id
);
1640 EXPECT_TRUE(surface
);
1641 // Should be a SurfaceSequence for both the original and new layers.
1642 EXPECT_EQ(2u, surface
->GetDestructionDependencyCount());
1646 TEST_F(RenderWidgetHostViewAuraTest
, Resize
) {
1647 gfx::Size
size1(100, 100);
1648 gfx::Size
size2(200, 200);
1649 gfx::Size
size3(300, 300);
1651 aura::Window
* root_window
= parent_view_
->GetNativeView()->GetRootWindow();
1652 view_
->InitAsChild(NULL
);
1653 aura::client::ParentWindowWithContext(
1654 view_
->GetNativeView(), root_window
, gfx::Rect(size1
));
1656 view_
->SetSize(size1
);
1657 view_
->OnSwapCompositorFrame(
1658 0, MakeDelegatedFrame(1.f
, size1
, gfx::Rect(size1
)));
1659 ui::DrawWaiterForTest::WaitForCommit(
1660 root_window
->GetHost()->compositor());
1661 ViewHostMsg_UpdateRect_Params update_params
;
1662 update_params
.view_size
= size1
;
1663 update_params
.flags
= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK
;
1664 widget_host_
->OnMessageReceived(
1665 ViewHostMsg_UpdateRect(widget_host_
->GetRoutingID(), update_params
));
1666 sink_
->ClearMessages();
1667 // Resize logic is idle (no pending resize, no pending commit).
1668 EXPECT_EQ(size1
.ToString(), view_
->GetRequestedRendererSize().ToString());
1670 // Resize renderer, should produce a Resize message
1671 view_
->SetSize(size2
);
1672 EXPECT_EQ(size2
.ToString(), view_
->GetRequestedRendererSize().ToString());
1673 EXPECT_EQ(1u, sink_
->message_count());
1675 const IPC::Message
* msg
= sink_
->GetMessageAt(0);
1676 EXPECT_EQ(ViewMsg_Resize::ID
, msg
->type());
1677 ViewMsg_Resize::Param params
;
1678 ViewMsg_Resize::Read(msg
, ¶ms
);
1679 EXPECT_EQ(size2
.ToString(), base::get
<0>(params
).new_size
.ToString());
1681 // Send resize ack to observe new Resize messages.
1682 update_params
.view_size
= size2
;
1683 widget_host_
->OnMessageReceived(
1684 ViewHostMsg_UpdateRect(widget_host_
->GetRoutingID(), update_params
));
1685 sink_
->ClearMessages();
1687 // Resize renderer again, before receiving a frame. Should not produce a
1689 view_
->SetSize(size3
);
1690 EXPECT_EQ(size2
.ToString(), view_
->GetRequestedRendererSize().ToString());
1691 EXPECT_EQ(0u, sink_
->message_count());
1693 // Receive a frame of the new size, should be skipped and not produce a Resize
1695 view_
->OnSwapCompositorFrame(
1696 0, MakeDelegatedFrame(1.f
, size3
, gfx::Rect(size3
)));
1697 // Expect the frame ack;
1698 EXPECT_EQ(1u, sink_
->message_count());
1699 EXPECT_EQ(ViewMsg_SwapCompositorFrameAck::ID
, sink_
->GetMessageAt(0)->type());
1700 sink_
->ClearMessages();
1701 EXPECT_EQ(size2
.ToString(), view_
->GetRequestedRendererSize().ToString());
1703 // Receive a frame of the correct size, should not be skipped and, and should
1704 // produce a Resize message after the commit.
1705 view_
->OnSwapCompositorFrame(
1706 0, MakeDelegatedFrame(1.f
, size2
, gfx::Rect(size2
)));
1707 cc::SurfaceId surface_id
= view_
->surface_id();
1708 if (surface_id
.is_null()) {
1709 // No frame ack yet.
1710 EXPECT_EQ(0u, sink_
->message_count());
1712 // Frame isn't desired size, so early ack.
1713 EXPECT_EQ(1u, sink_
->message_count());
1715 EXPECT_EQ(size2
.ToString(), view_
->GetRequestedRendererSize().ToString());
1717 // Wait for commit, then we should unlock the compositor and send a Resize
1718 // message (and a frame ack)
1719 ui::DrawWaiterForTest::WaitForCommit(
1720 root_window
->GetHost()->compositor());
1722 bool has_resize
= false;
1723 for (uint32 i
= 0; i
< sink_
->message_count(); ++i
) {
1724 const IPC::Message
* msg
= sink_
->GetMessageAt(i
);
1725 switch (msg
->type()) {
1726 case InputMsg_HandleInputEvent::ID
: {
1727 // On some platforms, the call to view_->Show() causes a posted task to
1729 // ui::WindowEventDispatcher::SynthesizeMouseMoveAfterChangeToWindow,
1730 // which the above WaitForCommit may cause to be picked up. Be robust
1731 // to this extra IPC coming in.
1732 InputMsg_HandleInputEvent::Param params
;
1733 InputMsg_HandleInputEvent::Read(msg
, ¶ms
);
1734 const blink::WebInputEvent
* event
= base::get
<0>(params
);
1735 EXPECT_EQ(blink::WebInputEvent::MouseMove
, event
->type
);
1738 case ViewMsg_SwapCompositorFrameAck::ID
:
1740 case ViewMsg_Resize::ID
: {
1741 EXPECT_FALSE(has_resize
);
1742 ViewMsg_Resize::Param params
;
1743 ViewMsg_Resize::Read(msg
, ¶ms
);
1744 EXPECT_EQ(size3
.ToString(), base::get
<0>(params
).new_size
.ToString());
1749 ADD_FAILURE() << "Unexpected message " << msg
->type();
1753 EXPECT_TRUE(has_resize
);
1754 update_params
.view_size
= size3
;
1755 widget_host_
->OnMessageReceived(
1756 ViewHostMsg_UpdateRect(widget_host_
->GetRoutingID(), update_params
));
1757 sink_
->ClearMessages();
1760 // Skipped frames should not drop their damage.
1761 TEST_F(RenderWidgetHostViewAuraTest
, SkippedDelegatedFrames
) {
1762 gfx::Rect
view_rect(100, 100);
1763 gfx::Size frame_size
= view_rect
.size();
1765 view_
->InitAsChild(NULL
);
1766 aura::client::ParentWindowWithContext(
1767 view_
->GetNativeView(),
1768 parent_view_
->GetNativeView()->GetRootWindow(),
1770 view_
->SetSize(view_rect
.size());
1772 MockWindowObserver observer
;
1773 view_
->window_
->AddObserver(&observer
);
1775 // A full frame of damage.
1776 EXPECT_CALL(observer
, OnDelegatedFrameDamage(view_
->window_
, view_rect
));
1777 view_
->OnSwapCompositorFrame(
1778 0, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1779 testing::Mock::VerifyAndClearExpectations(&observer
);
1780 view_
->RunOnCompositingDidCommit();
1782 // A partial damage frame.
1783 gfx::Rect
partial_view_rect(30, 30, 20, 20);
1784 EXPECT_CALL(observer
,
1785 OnDelegatedFrameDamage(view_
->window_
, partial_view_rect
));
1786 view_
->OnSwapCompositorFrame(
1787 0, MakeDelegatedFrame(1.f
, frame_size
, partial_view_rect
));
1788 testing::Mock::VerifyAndClearExpectations(&observer
);
1789 view_
->RunOnCompositingDidCommit();
1791 // Lock the compositor. Now we should drop frames.
1792 view_rect
= gfx::Rect(150, 150);
1793 view_
->SetSize(view_rect
.size());
1795 // This frame is dropped.
1796 gfx::Rect
dropped_damage_rect_1(10, 20, 30, 40);
1797 EXPECT_CALL(observer
, OnDelegatedFrameDamage(_
, _
)).Times(0);
1798 view_
->OnSwapCompositorFrame(
1799 0, MakeDelegatedFrame(1.f
, frame_size
, dropped_damage_rect_1
));
1800 testing::Mock::VerifyAndClearExpectations(&observer
);
1801 view_
->RunOnCompositingDidCommit();
1803 gfx::Rect
dropped_damage_rect_2(40, 50, 10, 20);
1804 EXPECT_CALL(observer
, OnDelegatedFrameDamage(_
, _
)).Times(0);
1805 view_
->OnSwapCompositorFrame(
1806 0, MakeDelegatedFrame(1.f
, frame_size
, dropped_damage_rect_2
));
1807 testing::Mock::VerifyAndClearExpectations(&observer
);
1808 view_
->RunOnCompositingDidCommit();
1810 // Unlock the compositor. This frame should damage everything.
1811 frame_size
= view_rect
.size();
1813 gfx::Rect
new_damage_rect(5, 6, 10, 10);
1814 EXPECT_CALL(observer
,
1815 OnDelegatedFrameDamage(view_
->window_
, view_rect
));
1816 view_
->OnSwapCompositorFrame(
1817 0, MakeDelegatedFrame(1.f
, frame_size
, new_damage_rect
));
1818 testing::Mock::VerifyAndClearExpectations(&observer
);
1819 view_
->RunOnCompositingDidCommit();
1821 // A partial damage frame, this should not be dropped.
1822 EXPECT_CALL(observer
,
1823 OnDelegatedFrameDamage(view_
->window_
, partial_view_rect
));
1824 view_
->OnSwapCompositorFrame(
1825 0, MakeDelegatedFrame(1.f
, frame_size
, partial_view_rect
));
1826 testing::Mock::VerifyAndClearExpectations(&observer
);
1827 view_
->RunOnCompositingDidCommit();
1830 // Resize to something empty.
1831 view_rect
= gfx::Rect(100, 0);
1832 view_
->SetSize(view_rect
.size());
1834 // We're never expecting empty frames, resize to something non-empty.
1835 view_rect
= gfx::Rect(100, 100);
1836 view_
->SetSize(view_rect
.size());
1838 // This frame should not be dropped.
1839 EXPECT_CALL(observer
, OnDelegatedFrameDamage(view_
->window_
, view_rect
));
1840 view_
->OnSwapCompositorFrame(
1841 0, MakeDelegatedFrame(1.f
, view_rect
.size(), view_rect
));
1842 testing::Mock::VerifyAndClearExpectations(&observer
);
1843 view_
->RunOnCompositingDidCommit();
1845 view_
->window_
->RemoveObserver(&observer
);
1848 TEST_F(RenderWidgetHostViewAuraTest
, OutputSurfaceIdChange
) {
1849 gfx::Rect
view_rect(100, 100);
1850 gfx::Size frame_size
= view_rect
.size();
1852 view_
->InitAsChild(NULL
);
1853 aura::client::ParentWindowWithContext(
1854 view_
->GetNativeView(),
1855 parent_view_
->GetNativeView()->GetRootWindow(),
1857 view_
->SetSize(view_rect
.size());
1859 MockWindowObserver observer
;
1860 view_
->window_
->AddObserver(&observer
);
1863 EXPECT_CALL(observer
, OnDelegatedFrameDamage(view_
->window_
, view_rect
));
1864 view_
->OnSwapCompositorFrame(
1865 0, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1866 testing::Mock::VerifyAndClearExpectations(&observer
);
1867 view_
->RunOnCompositingDidCommit();
1869 // Swap a frame with a different surface id.
1870 EXPECT_CALL(observer
, OnDelegatedFrameDamage(view_
->window_
, view_rect
));
1871 view_
->OnSwapCompositorFrame(
1872 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1873 testing::Mock::VerifyAndClearExpectations(&observer
);
1874 view_
->RunOnCompositingDidCommit();
1876 // Swap an empty frame, with a different surface id.
1877 view_
->OnSwapCompositorFrame(
1878 2, MakeDelegatedFrame(1.f
, gfx::Size(), gfx::Rect()));
1879 testing::Mock::VerifyAndClearExpectations(&observer
);
1880 view_
->RunOnCompositingDidCommit();
1882 // Swap another frame, with a different surface id.
1883 EXPECT_CALL(observer
, OnDelegatedFrameDamage(view_
->window_
, view_rect
));
1884 view_
->OnSwapCompositorFrame(3,
1885 MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1886 testing::Mock::VerifyAndClearExpectations(&observer
);
1887 view_
->RunOnCompositingDidCommit();
1889 view_
->window_
->RemoveObserver(&observer
);
1892 TEST_F(RenderWidgetHostViewAuraTest
, DiscardDelegatedFrames
) {
1893 view_
->InitAsChild(NULL
);
1895 size_t max_renderer_frames
=
1896 RendererFrameManager::GetInstance()->GetMaxNumberOfSavedFrames();
1897 ASSERT_LE(2u, max_renderer_frames
);
1898 size_t renderer_count
= max_renderer_frames
+ 1;
1899 gfx::Rect
view_rect(100, 100);
1900 gfx::Size frame_size
= view_rect
.size();
1901 DCHECK_EQ(0u, HostSharedBitmapManager::current()->AllocatedBitmapCount());
1903 scoped_ptr
<RenderWidgetHostImpl
* []> hosts(
1904 new RenderWidgetHostImpl
* [renderer_count
]);
1905 scoped_ptr
<FakeRenderWidgetHostViewAura
* []> views(
1906 new FakeRenderWidgetHostViewAura
* [renderer_count
]);
1908 // Create a bunch of renderers.
1909 for (size_t i
= 0; i
< renderer_count
; ++i
) {
1910 int32 routing_id
= process_host_
->GetNextRoutingID();
1911 int32 surface_id
= GpuSurfaceTracker::Get()->AddSurfaceForRenderer(
1912 process_host_
->GetID(), routing_id
);
1913 hosts
[i
] = new RenderWidgetHostImpl(&delegate_
, process_host_
, routing_id
,
1916 views
[i
] = new FakeRenderWidgetHostViewAura(hosts
[i
], false);
1917 views
[i
]->InitAsChild(NULL
);
1918 aura::client::ParentWindowWithContext(
1919 views
[i
]->GetNativeView(),
1920 parent_view_
->GetNativeView()->GetRootWindow(),
1922 views
[i
]->SetSize(view_rect
.size());
1925 // Make each renderer visible, and swap a frame on it, then make it invisible.
1926 for (size_t i
= 0; i
< renderer_count
; ++i
) {
1928 views
[i
]->OnSwapCompositorFrame(
1929 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1930 EXPECT_TRUE(views
[i
]->HasFrameData());
1934 // There should be max_renderer_frames with a frame in it, and one without it.
1935 // Since the logic is LRU eviction, the first one should be without.
1936 EXPECT_FALSE(views
[0]->HasFrameData());
1937 for (size_t i
= 1; i
< renderer_count
; ++i
)
1938 EXPECT_TRUE(views
[i
]->HasFrameData());
1940 // LRU renderer is [0], make it visible, it shouldn't evict anything yet.
1942 EXPECT_FALSE(views
[0]->HasFrameData());
1943 EXPECT_TRUE(views
[1]->HasFrameData());
1944 // Since [0] doesn't have a frame, it should be waiting for the renderer to
1946 EXPECT_TRUE(views
[0]->released_front_lock_active());
1948 // Swap a frame on it, it should evict the next LRU [1].
1949 views
[0]->OnSwapCompositorFrame(
1950 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1951 EXPECT_TRUE(views
[0]->HasFrameData());
1952 EXPECT_FALSE(views
[1]->HasFrameData());
1953 // Now that [0] got a frame, it shouldn't be waiting any more.
1954 EXPECT_FALSE(views
[0]->released_front_lock_active());
1957 // LRU renderer is [1], still hidden. Swap a frame on it, it should evict
1958 // the next LRU [2].
1959 views
[1]->OnSwapCompositorFrame(
1960 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1961 EXPECT_TRUE(views
[0]->HasFrameData());
1962 EXPECT_TRUE(views
[1]->HasFrameData());
1963 EXPECT_FALSE(views
[2]->HasFrameData());
1964 for (size_t i
= 3; i
< renderer_count
; ++i
)
1965 EXPECT_TRUE(views
[i
]->HasFrameData());
1967 // Make all renderers but [0] visible and swap a frame on them, keep [0]
1968 // hidden, it becomes the LRU.
1969 for (size_t i
= 1; i
< renderer_count
; ++i
) {
1971 // The renderers who don't have a frame should be waiting. The ones that
1972 // have a frame should not.
1973 // In practice, [1] has a frame, but anything after has its frame evicted.
1974 EXPECT_EQ(!views
[i
]->HasFrameData(),
1975 views
[i
]->released_front_lock_active());
1976 views
[i
]->OnSwapCompositorFrame(
1977 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1978 // Now everyone has a frame.
1979 EXPECT_FALSE(views
[i
]->released_front_lock_active());
1980 EXPECT_TRUE(views
[i
]->HasFrameData());
1982 EXPECT_FALSE(views
[0]->HasFrameData());
1984 // Swap a frame on [0], it should be evicted immediately.
1985 views
[0]->OnSwapCompositorFrame(
1986 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1987 EXPECT_FALSE(views
[0]->HasFrameData());
1989 // Make [0] visible, and swap a frame on it. Nothing should be evicted
1990 // although we're above the limit.
1992 // We don't have a frame, wait.
1993 EXPECT_TRUE(views
[0]->released_front_lock_active());
1994 views
[0]->OnSwapCompositorFrame(
1995 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1996 EXPECT_FALSE(views
[0]->released_front_lock_active());
1997 for (size_t i
= 0; i
< renderer_count
; ++i
)
1998 EXPECT_TRUE(views
[i
]->HasFrameData());
2000 // Make [0] hidden, it should evict its frame.
2002 EXPECT_FALSE(views
[0]->HasFrameData());
2004 // Make [0] visible, don't give it a frame, it should be waiting.
2006 EXPECT_TRUE(views
[0]->released_front_lock_active());
2007 // Make [0] hidden, it should stop waiting.
2009 EXPECT_FALSE(views
[0]->released_front_lock_active());
2011 // Make [1] hidden, resize it. It should drop its frame.
2013 EXPECT_TRUE(views
[1]->HasFrameData());
2014 gfx::Size
size2(200, 200);
2015 views
[1]->SetSize(size2
);
2016 EXPECT_FALSE(views
[1]->HasFrameData());
2017 // Show it, it should block until we give it a frame.
2019 EXPECT_TRUE(views
[1]->released_front_lock_active());
2020 views
[1]->OnSwapCompositorFrame(
2021 1, MakeDelegatedFrame(1.f
, size2
, gfx::Rect(size2
)));
2022 EXPECT_FALSE(views
[1]->released_front_lock_active());
2024 for (size_t i
= 0; i
< renderer_count
- 1; ++i
)
2027 // Allocate enough bitmaps so that two frames (proportionally) would be
2028 // enough hit the handle limit.
2029 int handles_per_frame
= 5;
2030 RendererFrameManager::GetInstance()->set_max_handles(handles_per_frame
* 2);
2032 HostSharedBitmapManagerClient
bitmap_client(
2033 HostSharedBitmapManager::current());
2035 for (size_t i
= 0; i
< (renderer_count
- 1) * handles_per_frame
; i
++) {
2036 bitmap_client
.ChildAllocatedSharedBitmap(
2037 1, base::SharedMemory::NULLHandle(), base::GetCurrentProcessHandle(),
2038 cc::SharedBitmap::GenerateId());
2041 // Hiding this last bitmap should evict all but two frames.
2042 views
[renderer_count
- 1]->Hide();
2043 for (size_t i
= 0; i
< renderer_count
; ++i
) {
2044 if (i
+ 2 < renderer_count
)
2045 EXPECT_FALSE(views
[i
]->HasFrameData());
2047 EXPECT_TRUE(views
[i
]->HasFrameData());
2049 RendererFrameManager::GetInstance()->set_max_handles(
2050 base::SharedMemory::GetHandleLimit());
2052 for (size_t i
= 0; i
< renderer_count
; ++i
) {
2053 views
[i
]->Destroy();
2058 TEST_F(RenderWidgetHostViewAuraTest
, DiscardDelegatedFramesWithLocking
) {
2059 view_
->InitAsChild(NULL
);
2061 size_t max_renderer_frames
=
2062 RendererFrameManager::GetInstance()->GetMaxNumberOfSavedFrames();
2063 ASSERT_LE(2u, max_renderer_frames
);
2064 size_t renderer_count
= max_renderer_frames
+ 1;
2065 gfx::Rect
view_rect(100, 100);
2066 gfx::Size frame_size
= view_rect
.size();
2067 DCHECK_EQ(0u, HostSharedBitmapManager::current()->AllocatedBitmapCount());
2069 scoped_ptr
<RenderWidgetHostImpl
* []> hosts(
2070 new RenderWidgetHostImpl
* [renderer_count
]);
2071 scoped_ptr
<FakeRenderWidgetHostViewAura
* []> views(
2072 new FakeRenderWidgetHostViewAura
* [renderer_count
]);
2074 // Create a bunch of renderers.
2075 for (size_t i
= 0; i
< renderer_count
; ++i
) {
2076 int32 routing_id
= process_host_
->GetNextRoutingID();
2077 int32 surface_id
= GpuSurfaceTracker::Get()->AddSurfaceForRenderer(
2078 process_host_
->GetID(), routing_id
);
2079 hosts
[i
] = new RenderWidgetHostImpl(&delegate_
, process_host_
, routing_id
,
2082 views
[i
] = new FakeRenderWidgetHostViewAura(hosts
[i
], false);
2083 views
[i
]->InitAsChild(NULL
);
2084 aura::client::ParentWindowWithContext(
2085 views
[i
]->GetNativeView(),
2086 parent_view_
->GetNativeView()->GetRootWindow(),
2088 views
[i
]->SetSize(view_rect
.size());
2091 // Make each renderer visible and swap a frame on it. No eviction should
2092 // occur because all frames are visible.
2093 for (size_t i
= 0; i
< renderer_count
; ++i
) {
2095 views
[i
]->OnSwapCompositorFrame(
2096 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
2097 EXPECT_TRUE(views
[i
]->HasFrameData());
2100 // If we hide [0], then [0] should be evicted.
2102 EXPECT_FALSE(views
[0]->HasFrameData());
2104 // If we lock [0] before hiding it, then [0] should not be evicted.
2106 views
[0]->OnSwapCompositorFrame(
2107 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
2108 EXPECT_TRUE(views
[0]->HasFrameData());
2109 views
[0]->GetDelegatedFrameHost()->LockResources();
2111 EXPECT_TRUE(views
[0]->HasFrameData());
2113 // If we unlock [0] now, then [0] should be evicted.
2114 views
[0]->GetDelegatedFrameHost()->UnlockResources();
2115 EXPECT_FALSE(views
[0]->HasFrameData());
2117 for (size_t i
= 0; i
< renderer_count
; ++i
) {
2118 views
[i
]->Destroy();
2123 // Test that changing the memory pressure should delete saved frames. This test
2124 // only applies to ChromeOS.
2125 TEST_F(RenderWidgetHostViewAuraTest
, DiscardDelegatedFramesWithMemoryPressure
) {
2126 view_
->InitAsChild(NULL
);
2128 // The test logic below relies on having max_renderer_frames > 2. By default,
2129 // this value is calculated from total physical memory and causes the test to
2130 // fail when run on hardware with < 256MB of RAM.
2131 const size_t kMaxRendererFrames
= 5;
2132 RendererFrameManager::GetInstance()->set_max_number_of_saved_frames(
2133 kMaxRendererFrames
);
2135 size_t renderer_count
= kMaxRendererFrames
;
2136 gfx::Rect
view_rect(100, 100);
2137 gfx::Size frame_size
= view_rect
.size();
2138 DCHECK_EQ(0u, HostSharedBitmapManager::current()->AllocatedBitmapCount());
2140 scoped_ptr
<RenderWidgetHostImpl
* []> hosts(
2141 new RenderWidgetHostImpl
* [renderer_count
]);
2142 scoped_ptr
<FakeRenderWidgetHostViewAura
* []> views(
2143 new FakeRenderWidgetHostViewAura
* [renderer_count
]);
2145 // Create a bunch of renderers.
2146 for (size_t i
= 0; i
< renderer_count
; ++i
) {
2147 int32 routing_id
= process_host_
->GetNextRoutingID();
2148 int32 surface_id
= GpuSurfaceTracker::Get()->AddSurfaceForRenderer(
2149 process_host_
->GetID(), routing_id
);
2150 hosts
[i
] = new RenderWidgetHostImpl(&delegate_
, process_host_
, routing_id
,
2153 views
[i
] = new FakeRenderWidgetHostViewAura(hosts
[i
], false);
2154 views
[i
]->InitAsChild(NULL
);
2155 aura::client::ParentWindowWithContext(
2156 views
[i
]->GetNativeView(),
2157 parent_view_
->GetNativeView()->GetRootWindow(),
2159 views
[i
]->SetSize(view_rect
.size());
2162 // Make each renderer visible and swap a frame on it. No eviction should
2163 // occur because all frames are visible.
2164 for (size_t i
= 0; i
< renderer_count
; ++i
) {
2166 views
[i
]->OnSwapCompositorFrame(
2167 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
2168 EXPECT_TRUE(views
[i
]->HasFrameData());
2171 // If we hide one, it should not get evicted.
2173 message_loop_
.RunUntilIdle();
2174 EXPECT_TRUE(views
[0]->HasFrameData());
2175 // Using a lesser memory pressure event however, should evict.
2176 SimulateMemoryPressure(
2177 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE
);
2178 message_loop_
.RunUntilIdle();
2179 EXPECT_FALSE(views
[0]->HasFrameData());
2181 // Check the same for a higher pressure event.
2183 message_loop_
.RunUntilIdle();
2184 EXPECT_TRUE(views
[1]->HasFrameData());
2185 SimulateMemoryPressure(
2186 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL
);
2187 message_loop_
.RunUntilIdle();
2188 EXPECT_FALSE(views
[1]->HasFrameData());
2190 for (size_t i
= 0; i
< renderer_count
; ++i
) {
2191 views
[i
]->Destroy();
2196 TEST_F(RenderWidgetHostViewAuraTest
, SoftwareDPIChange
) {
2197 gfx::Rect
view_rect(100, 100);
2198 gfx::Size
frame_size(100, 100);
2200 view_
->InitAsChild(NULL
);
2201 aura::client::ParentWindowWithContext(
2202 view_
->GetNativeView(),
2203 parent_view_
->GetNativeView()->GetRootWindow(),
2205 view_
->SetSize(view_rect
.size());
2208 // With a 1x DPI UI and 1x DPI Renderer.
2209 view_
->OnSwapCompositorFrame(
2210 1, MakeDelegatedFrame(1.f
, frame_size
, gfx::Rect(frame_size
)));
2212 // Save the frame provider.
2213 scoped_refptr
<cc::DelegatedFrameProvider
> frame_provider
=
2214 view_
->frame_provider();
2215 cc::SurfaceId surface_id
= view_
->surface_id();
2217 // This frame will have the same number of physical pixels, but has a new
2219 view_
->OnSwapCompositorFrame(
2220 1, MakeDelegatedFrame(2.f
, frame_size
, gfx::Rect(frame_size
)));
2222 // When we get a new frame with the same frame size in physical pixels, but a
2223 // different scale, we should generate a new frame provider, as the final
2224 // result will need to be scaled differently to the screen.
2225 if (frame_provider
.get())
2226 EXPECT_NE(frame_provider
.get(), view_
->frame_provider());
2228 EXPECT_NE(surface_id
, view_
->surface_id());
2231 class RenderWidgetHostViewAuraCopyRequestTest
2232 : public RenderWidgetHostViewAuraShutdownTest
{
2234 RenderWidgetHostViewAuraCopyRequestTest()
2235 : callback_count_(0),
2237 frame_subscriber_(nullptr),
2238 tick_clock_(nullptr),
2239 view_rect_(100, 100) {}
2241 void CallbackMethod(bool result
) {
2244 quit_closure_
.Run();
2247 void RunLoopUntilCallback() {
2248 base::RunLoop run_loop
;
2249 quit_closure_
= run_loop
.QuitClosure();
2253 void InitializeView() {
2254 view_
->InitAsChild(NULL
);
2255 view_
->GetDelegatedFrameHost()->SetRequestCopyOfOutputCallbackForTesting(
2256 base::Bind(&FakeRenderWidgetHostViewAura::InterceptCopyOfOutput
,
2257 base::Unretained(view_
)));
2258 aura::client::ParentWindowWithContext(
2259 view_
->GetNativeView(), parent_view_
->GetNativeView()->GetRootWindow(),
2261 view_
->SetSize(view_rect_
.size());
2264 frame_subscriber_
= new FakeFrameSubscriber(
2266 base::Bind(&RenderWidgetHostViewAuraCopyRequestTest::CallbackMethod
,
2267 base::Unretained(this)));
2268 view_
->BeginFrameSubscription(make_scoped_ptr(frame_subscriber_
));
2269 ASSERT_EQ(0, callback_count_
);
2270 ASSERT_FALSE(view_
->last_copy_request_
);
2273 void InstallFakeTickClock() {
2274 // Create a fake tick clock and transfer ownership to the frame host.
2275 tick_clock_
= new base::SimpleTestTickClock();
2276 view_
->GetDelegatedFrameHost()->tick_clock_
= make_scoped_ptr(tick_clock_
);
2279 void OnSwapCompositorFrame() {
2280 view_
->OnSwapCompositorFrame(
2281 1, MakeDelegatedFrame(1.f
, view_rect_
.size(), view_rect_
));
2282 ASSERT_TRUE(view_
->last_copy_request_
);
2285 void ReleaseSwappedFrame() {
2286 scoped_ptr
<cc::CopyOutputRequest
> request
=
2287 view_
->last_copy_request_
.Pass();
2288 request
->SendTextureResult(view_rect_
.size(), request
->texture_mailbox(),
2289 scoped_ptr
<cc::SingleReleaseCallback
>());
2290 RunLoopUntilCallback();
2293 void OnSwapCompositorFrameAndRelease() {
2294 OnSwapCompositorFrame();
2295 ReleaseSwappedFrame();
2298 void RunOnCompositingDidCommitAndReleaseFrame() {
2299 view_
->RunOnCompositingDidCommit();
2300 ReleaseSwappedFrame();
2303 void OnUpdateVSyncParameters(base::TimeTicks timebase
,
2304 base::TimeDelta interval
) {
2305 view_
->GetDelegatedFrameHost()->OnUpdateVSyncParameters(timebase
, interval
);
2308 base::TimeTicks
vsync_timebase() {
2309 return view_
->GetDelegatedFrameHost()->vsync_timebase_
;
2312 base::TimeDelta
vsync_interval() {
2313 return view_
->GetDelegatedFrameHost()->vsync_interval_
;
2316 int callback_count_
;
2318 FakeFrameSubscriber
* frame_subscriber_
; // Owned by |view_|.
2319 base::SimpleTestTickClock
* tick_clock_
; // Owned by DelegatedFrameHost.
2320 const gfx::Rect view_rect_
;
2323 base::Closure quit_closure_
;
2325 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraCopyRequestTest
);
2328 // Tests that only one copy/readback request will be executed per one browser
2329 // composite operation, even when multiple render frame swaps occur in between
2330 // browser composites, and even if the frame subscriber desires more frames than
2331 // the number of browser composites.
2332 TEST_F(RenderWidgetHostViewAuraCopyRequestTest
, DedupeFrameSubscriberRequests
) {
2334 int expected_callback_count
= 0;
2336 // Normal case: A browser composite executes for each render frame swap.
2337 for (int i
= 0; i
< 3; ++i
) {
2338 // Renderer provides another frame and the Browser composites with the
2339 // frame, executing the copy request, and then the result is delivered.
2340 OnSwapCompositorFrame();
2341 RunOnCompositingDidCommitAndReleaseFrame();
2343 // The callback should be run with success status.
2344 ++expected_callback_count
;
2345 ASSERT_EQ(expected_callback_count
, callback_count_
);
2346 EXPECT_TRUE(result_
);
2349 // De-duping case: One browser composite executes per varied number of render
2351 for (int i
= 0; i
< 3; ++i
) {
2352 const int num_swaps
= 1 + i
% 3;
2354 // The renderer provides |num_swaps| frames.
2355 for (int j
= 0; j
< num_swaps
; ++j
) {
2356 OnSwapCompositorFrame();
2358 ++expected_callback_count
;
2359 ASSERT_EQ(expected_callback_count
, callback_count_
);
2360 EXPECT_FALSE(result_
); // The prior copy request was aborted.
2364 // Browser composites with the frame, executing the last copy request that
2365 // was made, and then the result is delivered.
2366 RunOnCompositingDidCommitAndReleaseFrame();
2368 // The final callback should be run with success status.
2369 ++expected_callback_count
;
2370 ASSERT_EQ(expected_callback_count
, callback_count_
);
2371 EXPECT_TRUE(result_
);
2374 // Destroy the RenderWidgetHostViewAura and ImageTransportFactory.
2375 TearDownEnvironment();
2378 TEST_F(RenderWidgetHostViewAuraCopyRequestTest
, DestroyedAfterCopyRequest
) {
2381 OnSwapCompositorFrame();
2382 EXPECT_EQ(0, callback_count_
);
2383 EXPECT_TRUE(view_
->last_copy_request_
);
2384 EXPECT_TRUE(view_
->last_copy_request_
->has_texture_mailbox());
2386 // Notify DelegatedFrameHost that the copy requests were moved to the
2387 // compositor thread by calling OnCompositingDidCommit().
2389 // Send back the mailbox included in the request. There's no release callback
2390 // since the mailbox came from the RWHVA originally.
2391 RunOnCompositingDidCommitAndReleaseFrame();
2393 // The callback should succeed.
2394 EXPECT_EQ(1, callback_count_
);
2395 EXPECT_TRUE(result_
);
2397 OnSwapCompositorFrame();
2398 EXPECT_EQ(1, callback_count_
);
2399 scoped_ptr
<cc::CopyOutputRequest
> request
= view_
->last_copy_request_
.Pass();
2401 // Destroy the RenderWidgetHostViewAura and ImageTransportFactory.
2402 TearDownEnvironment();
2404 // Send the result after-the-fact. It goes nowhere since DelegatedFrameHost
2405 // has been destroyed.
2406 request
->SendTextureResult(view_rect_
.size(), request
->texture_mailbox(),
2407 scoped_ptr
<cc::SingleReleaseCallback
>());
2409 // Because the copy request callback may be holding state within it, that
2410 // state must handle the RWHVA and ImageTransportFactory going away before the
2411 // callback is called. This test passes if it does not crash as a result of
2412 // these things being destroyed.
2413 EXPECT_EQ(2, callback_count_
);
2414 EXPECT_FALSE(result_
);
2417 TEST_F(RenderWidgetHostViewAuraCopyRequestTest
, PresentTime
) {
2419 InstallFakeTickClock();
2421 // Verify our initial state.
2422 EXPECT_EQ(base::TimeTicks(), frame_subscriber_
->last_present_time());
2423 EXPECT_EQ(base::TimeTicks(), tick_clock_
->NowTicks());
2425 // Start our fake clock from a non-zero, but not an even multiple of the
2426 // interval, value to differentiate it from our initialization state.
2427 const base::TimeDelta kDefaultInterval
=
2428 cc::BeginFrameArgs::DefaultInterval();
2429 tick_clock_
->Advance(kDefaultInterval
/ 3);
2431 // Swap the first frame without any vsync information.
2432 ASSERT_EQ(base::TimeTicks(), vsync_timebase());
2433 ASSERT_EQ(base::TimeDelta(), vsync_interval());
2435 // During this first call, there is no known vsync information, so while the
2436 // callback should succeed the present time is effectively just current time.
2437 OnSwapCompositorFrameAndRelease();
2438 EXPECT_EQ(tick_clock_
->NowTicks(), frame_subscriber_
->last_present_time());
2440 // Now initialize the vsync parameters with a null timebase, but a known vsync
2441 // interval; which should give us slightly better frame time estimates.
2442 OnUpdateVSyncParameters(base::TimeTicks(), kDefaultInterval
);
2443 ASSERT_EQ(base::TimeTicks(), vsync_timebase());
2444 ASSERT_EQ(kDefaultInterval
, vsync_interval());
2446 // Now that we have a vsync interval, the presentation time estimate should be
2447 // the nearest presentation interval, which is just kDefaultInterval since our
2448 // tick clock is initialized to a time before that.
2449 OnSwapCompositorFrameAndRelease();
2450 EXPECT_EQ(base::TimeTicks() + kDefaultInterval
,
2451 frame_subscriber_
->last_present_time());
2453 // Now initialize the vsync parameters with a valid timebase and a known vsync
2454 // interval; which should give us the best frame time estimates.
2455 const base::TimeTicks kBaseTime
= tick_clock_
->NowTicks();
2456 OnUpdateVSyncParameters(kBaseTime
, kDefaultInterval
);
2457 ASSERT_EQ(kBaseTime
, vsync_timebase());
2458 ASSERT_EQ(kDefaultInterval
, vsync_interval());
2460 // Now that we have a vsync interval and a timebase, the presentation time
2461 // should be based on the number of vsync intervals which have elapsed since
2462 // the vsync timebase. Advance time by a non integer number of intervals to
2464 const double kElapsedIntervals
= 2.5;
2465 tick_clock_
->Advance(kDefaultInterval
* kElapsedIntervals
);
2466 OnSwapCompositorFrameAndRelease();
2467 EXPECT_EQ(kBaseTime
+ kDefaultInterval
* std::ceil(kElapsedIntervals
),
2468 frame_subscriber_
->last_present_time());
2470 // Destroy the RenderWidgetHostViewAura and ImageTransportFactory.
2471 TearDownEnvironment();
2474 TEST_F(RenderWidgetHostViewAuraTest
, VisibleViewportTest
) {
2475 gfx::Rect
view_rect(100, 100);
2477 view_
->InitAsChild(NULL
);
2478 aura::client::ParentWindowWithContext(
2479 view_
->GetNativeView(),
2480 parent_view_
->GetNativeView()->GetRootWindow(),
2482 view_
->SetSize(view_rect
.size());
2485 // Defaults to full height of the view.
2486 EXPECT_EQ(100, view_
->GetVisibleViewportSize().height());
2488 widget_host_
->ResetSizeAndRepaintPendingFlags();
2489 sink_
->ClearMessages();
2490 view_
->SetInsets(gfx::Insets(0, 0, 40, 0));
2492 EXPECT_EQ(60, view_
->GetVisibleViewportSize().height());
2494 const IPC::Message
*message
= sink_
->GetFirstMessageMatching(
2495 ViewMsg_Resize::ID
);
2496 ASSERT_TRUE(message
!= NULL
);
2498 ViewMsg_Resize::Param params
;
2499 ViewMsg_Resize::Read(message
, ¶ms
);
2500 EXPECT_EQ(60, base::get
<0>(params
).visible_viewport_size
.height());
2503 // Ensures that touch event positions are never truncated to integers.
2504 TEST_F(RenderWidgetHostViewAuraTest
, TouchEventPositionsArentRounded
) {
2505 const float kX
= 30.58f
;
2506 const float kY
= 50.23f
;
2508 view_
->InitAsChild(NULL
);
2511 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
,
2512 gfx::PointF(kX
, kY
),
2514 ui::EventTimeForNow());
2516 view_
->OnTouchEvent(&press
);
2517 EXPECT_EQ(ui::MotionEvent::ACTION_DOWN
, pointer_state().GetAction());
2518 EXPECT_EQ(1U, pointer_state().GetPointerCount());
2519 EXPECT_EQ(kX
, pointer_state().GetX(0));
2520 EXPECT_EQ(kY
, pointer_state().GetY(0));
2523 // Tests that scroll ACKs are correctly handled by the overscroll-navigation
2525 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, WheelScrollEventOverscrolls
) {
2526 SetUpOverscrollEnvironment();
2528 // Simulate wheel events.
2529 SimulateWheelEvent(-5, 0, 0, true); // sent directly
2530 SimulateWheelEvent(-1, 1, 0, true); // enqueued
2531 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
2532 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
2533 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
2534 SimulateWheelEvent(-20, 6, 1, true); // enqueued, different modifiers
2535 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2536 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2538 // Receive ACK the first wheel event as not processed.
2539 SendInputEventACK(WebInputEvent::MouseWheel
,
2540 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2541 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2542 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2543 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2545 // Receive ACK for the second (coalesced) event as not processed. This will
2546 // start a back navigation. However, this will also cause the queued next
2547 // event to be sent to the renderer. But since overscroll navigation has
2548 // started, that event will also be included in the overscroll computation
2549 // instead of being sent to the renderer. So the result will be an overscroll
2550 // back navigation, and no event will be sent to the renderer.
2551 SendInputEventACK(WebInputEvent::MouseWheel
,
2552 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2553 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_mode());
2554 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_delegate()->current_mode());
2555 EXPECT_EQ(-81.f
, overscroll_delta_x());
2556 EXPECT_EQ(-31.f
, overscroll_delegate()->delta_x());
2557 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2558 EXPECT_EQ(0U, sink_
->message_count());
2560 // Send a mouse-move event. This should cancel the overscroll navigation.
2561 SimulateMouseMove(5, 10, 0);
2562 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2563 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2564 EXPECT_EQ(1U, sink_
->message_count());
2567 // Tests that if some scroll events are consumed towards the start, then
2568 // subsequent scrolls do not horizontal overscroll.
2569 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
2570 WheelScrollConsumedDoNotHorizOverscroll
) {
2571 SetUpOverscrollEnvironment();
2573 // Simulate wheel events.
2574 SimulateWheelEvent(-5, 0, 0, true); // sent directly
2575 SimulateWheelEvent(-1, -1, 0, true); // enqueued
2576 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
2577 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
2578 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
2579 SimulateWheelEvent(-20, 6, 1, true); // enqueued, different modifiers
2580 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2581 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2583 // Receive ACK the first wheel event as processed.
2584 SendInputEventACK(WebInputEvent::MouseWheel
, INPUT_EVENT_ACK_STATE_CONSUMED
);
2585 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2586 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2587 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2589 // Receive ACK for the second (coalesced) event as not processed. This should
2590 // not initiate overscroll, since the beginning of the scroll has been
2591 // consumed. The queued event with different modifiers should be sent to the
2593 SendInputEventACK(WebInputEvent::MouseWheel
,
2594 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2595 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2596 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2598 SendInputEventACK(WebInputEvent::MouseWheel
,
2599 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2600 EXPECT_EQ(0U, sink_
->message_count());
2601 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2603 // Indicate the end of the scrolling from the touchpad.
2604 SimulateGestureFlingStartEvent(-1200.f
, 0.f
, blink::WebGestureDeviceTouchpad
);
2605 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2607 // Start another scroll. This time, do not consume any scroll events.
2608 SimulateWheelEvent(0, -5, 0, true); // sent directly
2609 SimulateWheelEvent(0, -1, 0, true); // enqueued
2610 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
2611 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
2612 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
2613 SimulateWheelEvent(-20, 6, 1, true); // enqueued, different modifiers
2614 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2615 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2617 // Receive ACK for the first wheel and the subsequent coalesced event as not
2618 // processed. This should start a back-overscroll.
2619 SendInputEventACK(WebInputEvent::MouseWheel
,
2620 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2621 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2622 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2623 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2624 SendInputEventACK(WebInputEvent::MouseWheel
,
2625 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2626 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_mode());
2629 // Tests that wheel-scrolling correctly turns overscroll on and off.
2630 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, WheelScrollOverscrollToggle
) {
2631 SetUpOverscrollEnvironment();
2633 // Send a wheel event. ACK the event as not processed. This should not
2634 // initiate an overscroll gesture since it doesn't cross the threshold yet.
2635 SimulateWheelEvent(10, 0, 0, true);
2636 SendInputEventACK(WebInputEvent::MouseWheel
,
2637 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2638 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2639 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2640 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2642 // Scroll some more so as to not overscroll.
2643 SimulateWheelEvent(10, 0, 0, true);
2644 SendInputEventACK(WebInputEvent::MouseWheel
,
2645 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2646 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2647 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2648 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2650 // Scroll some more to initiate an overscroll.
2651 SimulateWheelEvent(40, 0, 0, true);
2652 SendInputEventACK(WebInputEvent::MouseWheel
,
2653 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2654 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2655 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2656 EXPECT_EQ(60.f
, overscroll_delta_x());
2657 EXPECT_EQ(10.f
, overscroll_delegate()->delta_x());
2658 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2659 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2661 // Scroll in the reverse direction enough to abort the overscroll.
2662 SimulateWheelEvent(-20, 0, 0, true);
2663 EXPECT_EQ(0U, sink_
->message_count());
2664 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2665 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2667 // Continue to scroll in the reverse direction.
2668 SimulateWheelEvent(-20, 0, 0, true);
2669 SendInputEventACK(WebInputEvent::MouseWheel
,
2670 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2671 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2672 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2673 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2675 // Continue to scroll in the reverse direction enough to initiate overscroll
2676 // in that direction.
2677 SimulateWheelEvent(-55, 0, 0, true);
2678 EXPECT_EQ(1U, sink_
->message_count());
2679 SendInputEventACK(WebInputEvent::MouseWheel
,
2680 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2681 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_mode());
2682 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_delegate()->current_mode());
2683 EXPECT_EQ(-75.f
, overscroll_delta_x());
2684 EXPECT_EQ(-25.f
, overscroll_delegate()->delta_x());
2685 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2688 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
2689 ScrollEventsOverscrollWithFling
) {
2690 SetUpOverscrollEnvironment();
2692 // Send a wheel event. ACK the event as not processed. This should not
2693 // initiate an overscroll gesture since it doesn't cross the threshold yet.
2694 SimulateWheelEvent(10, 0, 0, true);
2695 SendInputEventACK(WebInputEvent::MouseWheel
,
2696 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2697 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2698 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2699 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2701 // Scroll some more so as to not overscroll.
2702 SimulateWheelEvent(20, 0, 0, true);
2703 EXPECT_EQ(1U, sink_
->message_count());
2704 SendInputEventACK(WebInputEvent::MouseWheel
,
2705 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2706 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2707 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2708 sink_
->ClearMessages();
2710 // Scroll some more to initiate an overscroll.
2711 SimulateWheelEvent(30, 0, 0, true);
2712 SendInputEventACK(WebInputEvent::MouseWheel
,
2713 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2714 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2715 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2716 EXPECT_EQ(60.f
, overscroll_delta_x());
2717 EXPECT_EQ(10.f
, overscroll_delegate()->delta_x());
2718 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2719 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2721 // Send a fling start, but with a small velocity, so that the overscroll is
2722 // aborted. The fling should proceed to the renderer, through the gesture
2724 SimulateGestureFlingStartEvent(0.f
, 0.1f
, blink::WebGestureDeviceTouchpad
);
2725 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2726 EXPECT_EQ(1U, sink_
->message_count());
2729 // Same as ScrollEventsOverscrollWithFling, but with zero velocity. Checks that
2730 // the zero-velocity fling does not reach the renderer.
2731 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
2732 ScrollEventsOverscrollWithZeroFling
) {
2733 SetUpOverscrollEnvironment();
2735 // Send a wheel event. ACK the event as not processed. This should not
2736 // initiate an overscroll gesture since it doesn't cross the threshold yet.
2737 SimulateWheelEvent(10, 0, 0, true);
2738 SendInputEventACK(WebInputEvent::MouseWheel
,
2739 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2740 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2741 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2742 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2744 // Scroll some more so as to not overscroll.
2745 SimulateWheelEvent(20, 0, 0, true);
2746 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2747 SendInputEventACK(WebInputEvent::MouseWheel
,
2748 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2749 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2750 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2752 // Scroll some more to initiate an overscroll.
2753 SimulateWheelEvent(30, 0, 0, true);
2754 SendInputEventACK(WebInputEvent::MouseWheel
,
2755 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2756 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2757 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2758 EXPECT_EQ(60.f
, overscroll_delta_x());
2759 EXPECT_EQ(10.f
, overscroll_delegate()->delta_x());
2760 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2761 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2763 // Send a fling start, but with a small velocity, so that the overscroll is
2764 // aborted. The fling should proceed to the renderer, through the gesture
2766 SimulateGestureFlingStartEvent(10.f
, 0.f
, blink::WebGestureDeviceTouchpad
);
2767 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2768 EXPECT_EQ(1U, sink_
->message_count());
2771 // Tests that a fling in the opposite direction of the overscroll cancels the
2772 // overscroll nav instead of completing it.
2773 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, ReverseFlingCancelsOverscroll
) {
2774 SetUpOverscrollEnvironment();
2777 // Start and end a gesture in the same direction without processing the
2778 // gesture events in the renderer. This should initiate and complete an
2779 // overscroll navigation.
2780 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2781 blink::WebGestureDeviceTouchscreen
);
2782 SimulateGestureScrollUpdateEvent(300, -5, 0);
2783 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2784 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2785 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2786 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2787 sink_
->ClearMessages();
2789 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
2790 blink::WebGestureDeviceTouchscreen
);
2791 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->completed_mode());
2792 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2793 EXPECT_EQ(1U, sink_
->message_count());
2797 // Start over, except instead of ending the gesture with ScrollEnd, end it
2798 // with a FlingStart, with velocity in the reverse direction. This should
2799 // initiate an overscroll navigation, but it should be cancelled because of
2800 // the fling in the opposite direction.
2801 overscroll_delegate()->Reset();
2802 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2803 blink::WebGestureDeviceTouchscreen
);
2804 SimulateGestureScrollUpdateEvent(-300, -5, 0);
2805 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2806 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2807 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_mode());
2808 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_delegate()->current_mode());
2809 sink_
->ClearMessages();
2811 SimulateGestureFlingStartEvent(100, 0, blink::WebGestureDeviceTouchscreen
);
2812 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->completed_mode());
2813 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2814 EXPECT_EQ(1U, sink_
->message_count());
2818 // Tests that touch-scroll events are handled correctly by the overscroll
2819 // controller. This also tests that the overscroll controller and the
2820 // gesture-event filter play nice with each other.
2821 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, GestureScrollOverscrolls
) {
2822 SetUpOverscrollEnvironment();
2824 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2825 blink::WebGestureDeviceTouchscreen
);
2826 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2827 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2828 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2830 // Send another gesture event and ACK as not being processed. This should
2831 // initiate the navigation gesture.
2832 SimulateGestureScrollUpdateEvent(55, -5, 0);
2833 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2834 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2835 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2836 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2837 EXPECT_EQ(55.f
, overscroll_delta_x());
2838 EXPECT_EQ(-5.f
, overscroll_delta_y());
2839 EXPECT_EQ(5.f
, overscroll_delegate()->delta_x());
2840 EXPECT_EQ(-5.f
, overscroll_delegate()->delta_y());
2841 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2843 // Send another gesture update event. This event should be consumed by the
2844 // controller, and not be forwarded to the renderer. The gesture-event filter
2845 // should not also receive this event.
2846 SimulateGestureScrollUpdateEvent(10, -5, 0);
2847 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2848 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2849 EXPECT_EQ(65.f
, overscroll_delta_x());
2850 EXPECT_EQ(-10.f
, overscroll_delta_y());
2851 EXPECT_EQ(15.f
, overscroll_delegate()->delta_x());
2852 EXPECT_EQ(-10.f
, overscroll_delegate()->delta_y());
2853 EXPECT_EQ(0U, sink_
->message_count());
2855 // Now send a scroll end. This should cancel the overscroll gesture, and send
2856 // the event to the renderer. The gesture-event filter should receive this
2858 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
2859 blink::WebGestureDeviceTouchscreen
);
2860 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2861 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2862 EXPECT_EQ(1U, sink_
->message_count());
2865 // Tests that if the page is scrolled because of a scroll-gesture, then that
2866 // particular scroll sequence never generates overscroll if the scroll direction
2868 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
2869 GestureScrollConsumedHorizontal
) {
2870 SetUpOverscrollEnvironment();
2872 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2873 blink::WebGestureDeviceTouchscreen
);
2874 SimulateGestureScrollUpdateEvent(10, 0, 0);
2876 // Start scrolling on content. ACK both events as being processed.
2877 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2878 INPUT_EVENT_ACK_STATE_CONSUMED
);
2879 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2880 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2881 sink_
->ClearMessages();
2883 // Send another gesture event and ACK as not being processed. This should
2884 // not initiate overscroll because the beginning of the scroll event did
2885 // scroll some content on the page. Since there was no overscroll, the event
2886 // should reach the renderer.
2887 SimulateGestureScrollUpdateEvent(55, 0, 0);
2888 EXPECT_EQ(1U, sink_
->message_count());
2889 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2890 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2891 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2894 // Tests that the overscroll controller plays nice with touch-scrolls and the
2895 // gesture event filter with debounce filtering turned on.
2896 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
2897 GestureScrollDebounceOverscrolls
) {
2898 SetUpOverscrollEnvironmentWithDebounce(100);
2900 // Start scrolling. Receive ACK as it being processed.
2901 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2902 blink::WebGestureDeviceTouchscreen
);
2903 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2905 // Send update events.
2906 SimulateGestureScrollUpdateEvent(25, 0, 0);
2907 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2909 // Quickly end and restart the scroll gesture. These two events should get
2911 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
2912 blink::WebGestureDeviceTouchscreen
);
2913 EXPECT_EQ(0U, sink_
->message_count());
2915 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2916 blink::WebGestureDeviceTouchscreen
);
2917 EXPECT_EQ(0U, sink_
->message_count());
2919 // Send another update event. This should get into the queue.
2920 SimulateGestureScrollUpdateEvent(30, 0, 0);
2921 EXPECT_EQ(0U, sink_
->message_count());
2923 // Receive an ACK for the first scroll-update event as not being processed.
2924 // This will contribute to the overscroll gesture, but not enough for the
2925 // overscroll controller to start consuming gesture events. This also cause
2926 // the queued gesture event to be forwarded to the renderer.
2927 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2928 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2929 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2930 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2931 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2933 // Send another update event. This should get into the queue.
2934 SimulateGestureScrollUpdateEvent(10, 0, 0);
2935 EXPECT_EQ(0U, sink_
->message_count());
2937 // Receive an ACK for the second scroll-update event as not being processed.
2938 // This will now initiate an overscroll. This will also cause the queued
2939 // gesture event to be released. But instead of going to the renderer, it will
2940 // be consumed by the overscroll controller.
2941 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2942 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2943 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2944 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2945 EXPECT_EQ(65.f
, overscroll_delta_x());
2946 EXPECT_EQ(15.f
, overscroll_delegate()->delta_x());
2947 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2948 EXPECT_EQ(0U, sink_
->message_count());
2951 // Tests that the gesture debounce timer plays nice with the overscroll
2953 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
2954 GestureScrollDebounceTimerOverscroll
) {
2955 SetUpOverscrollEnvironmentWithDebounce(10);
2957 // Start scrolling. Receive ACK as it being processed.
2958 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2959 blink::WebGestureDeviceTouchscreen
);
2960 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2962 // Send update events.
2963 SimulateGestureScrollUpdateEvent(55, 0, 0);
2964 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2966 // Send an end event. This should get in the debounce queue.
2967 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
2968 blink::WebGestureDeviceTouchscreen
);
2969 EXPECT_EQ(0U, sink_
->message_count());
2971 // Receive ACK for the scroll-update event.
2972 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2973 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2974 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2975 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2976 EXPECT_EQ(55.f
, overscroll_delta_x());
2977 EXPECT_EQ(5.f
, overscroll_delegate()->delta_x());
2978 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2979 EXPECT_EQ(0U, sink_
->message_count());
2981 // Let the timer for the debounce queue fire. That should release the queued
2982 // scroll-end event. Since overscroll has started, but there hasn't been
2983 // enough overscroll to complete the gesture, the overscroll controller
2984 // will reset the state. The scroll-end should therefore be dispatched to the
2985 // renderer, and the gesture-event-filter should await an ACK for it.
2986 base::MessageLoop::current()->PostDelayedTask(
2988 base::MessageLoop::QuitClosure(),
2989 base::TimeDelta::FromMilliseconds(15));
2990 base::MessageLoop::current()->Run();
2992 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2993 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2994 EXPECT_EQ(1U, sink_
->message_count());
2997 // Tests that when touch-events are dispatched to the renderer, the overscroll
2998 // gesture deals with them correctly.
2999 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, OverscrollWithTouchEvents
) {
3000 SetUpOverscrollEnvironmentWithDebounce(10);
3001 widget_host_
->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
3002 sink_
->ClearMessages();
3004 // The test sends an intermingled sequence of touch and gesture events.
3005 PressTouchPoint(0, 1);
3006 uint32 touch_press_event_id1
= SendTouchEvent();
3007 SendTouchEventACK(WebInputEvent::TouchStart
,
3008 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
, touch_press_event_id1
);
3009 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3011 MoveTouchPoint(0, 20, 5);
3012 uint32 touch_move_event_id1
= SendTouchEvent();
3013 SendTouchEventACK(WebInputEvent::TouchMove
,
3014 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
, touch_move_event_id1
);
3015 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3017 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3018 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3020 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
3021 blink::WebGestureDeviceTouchscreen
);
3022 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3023 SimulateGestureScrollUpdateEvent(20, 0, 0);
3024 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
3025 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3026 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3027 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3028 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3030 // Another touch move event should reach the renderer since overscroll hasn't
3031 // started yet. Note that touch events sent during the scroll period may
3032 // not require an ack (having been marked uncancelable).
3033 MoveTouchPoint(0, 65, 10);
3035 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3036 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3038 SimulateGestureScrollUpdateEvent(45, 0, 0);
3039 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
3040 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3041 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
3042 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
3043 EXPECT_EQ(65.f
, overscroll_delta_x());
3044 EXPECT_EQ(15.f
, overscroll_delegate()->delta_x());
3045 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
3046 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3048 // Send another touch event. The page should get the touch-move event, even
3049 // though overscroll has started.
3050 MoveTouchPoint(0, 55, 5);
3052 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
3053 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
3054 EXPECT_EQ(65.f
, overscroll_delta_x());
3055 EXPECT_EQ(15.f
, overscroll_delegate()->delta_x());
3056 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
3057 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3058 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3060 SimulateGestureScrollUpdateEvent(-10, 0, 0);
3061 EXPECT_EQ(0U, sink_
->message_count());
3062 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
3063 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
3064 EXPECT_EQ(55.f
, overscroll_delta_x());
3065 EXPECT_EQ(5.f
, overscroll_delegate()->delta_x());
3066 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
3068 PressTouchPoint(255, 5);
3070 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3071 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3073 SimulateGestureScrollUpdateEvent(200, 0, 0);
3074 EXPECT_EQ(0U, sink_
->message_count());
3075 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
3076 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
3077 EXPECT_EQ(255.f
, overscroll_delta_x());
3078 EXPECT_EQ(205.f
, overscroll_delegate()->delta_x());
3079 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
3081 // The touch-end/cancel event should always reach the renderer if the page has
3083 ReleaseTouchPoint(1);
3085 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3086 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3087 ReleaseTouchPoint(0);
3089 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3090 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3092 SimulateGestureEvent(blink::WebInputEvent::GestureScrollEnd
,
3093 blink::WebGestureDeviceTouchscreen
);
3094 base::MessageLoop::current()->PostDelayedTask(
3096 base::MessageLoop::QuitClosure(),
3097 base::TimeDelta::FromMilliseconds(10));
3098 base::MessageLoop::current()->Run();
3099 EXPECT_EQ(1U, sink_
->message_count());
3100 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3101 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3102 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->completed_mode());
3105 // Tests that touch-gesture end is dispatched to the renderer at the end of a
3106 // touch-gesture initiated overscroll.
3107 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
3108 TouchGestureEndDispatchedAfterOverscrollComplete
) {
3109 SetUpOverscrollEnvironmentWithDebounce(10);
3110 widget_host_
->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
3111 sink_
->ClearMessages();
3113 // Start scrolling. Receive ACK as it being processed.
3114 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
3115 blink::WebGestureDeviceTouchscreen
);
3116 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3117 // The scroll begin event will have received a synthetic ack from the input
3119 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3120 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3122 // Send update events.
3123 SimulateGestureScrollUpdateEvent(55, -5, 0);
3124 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3125 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3126 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3128 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
3129 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3130 EXPECT_EQ(0U, sink_
->message_count());
3131 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
3132 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
3133 EXPECT_EQ(55.f
, overscroll_delta_x());
3134 EXPECT_EQ(5.f
, overscroll_delegate()->delta_x());
3135 EXPECT_EQ(-5.f
, overscroll_delegate()->delta_y());
3138 SimulateGestureEvent(blink::WebInputEvent::GestureScrollEnd
,
3139 blink::WebGestureDeviceTouchscreen
);
3140 EXPECT_EQ(0U, sink_
->message_count());
3141 base::MessageLoop::current()->PostDelayedTask(
3143 base::MessageLoop::QuitClosure(),
3144 base::TimeDelta::FromMilliseconds(10));
3145 base::MessageLoop::current()->Run();
3146 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3147 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3148 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->completed_mode());
3149 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3151 // Start scrolling. Receive ACK as it being processed.
3152 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
3153 blink::WebGestureDeviceTouchscreen
);
3154 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3155 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3156 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3158 // Send update events.
3159 SimulateGestureScrollUpdateEvent(235, -5, 0);
3160 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3161 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3162 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3164 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
3165 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3166 EXPECT_EQ(0U, sink_
->message_count());
3167 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
3168 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
3169 EXPECT_EQ(235.f
, overscroll_delta_x());
3170 EXPECT_EQ(185.f
, overscroll_delegate()->delta_x());
3171 EXPECT_EQ(-5.f
, overscroll_delegate()->delta_y());
3174 SimulateGestureEvent(blink::WebInputEvent::GestureScrollEnd
,
3175 blink::WebGestureDeviceTouchscreen
);
3176 EXPECT_EQ(0U, sink_
->message_count());
3177 base::MessageLoop::current()->PostDelayedTask(
3179 base::MessageLoop::QuitClosure(),
3180 base::TimeDelta::FromMilliseconds(10));
3181 base::MessageLoop::current()->Run();
3182 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3183 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3184 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->completed_mode());
3185 EXPECT_EQ(1U, sink_
->message_count());
3188 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, OverscrollDirectionChange
) {
3189 SetUpOverscrollEnvironmentWithDebounce(100);
3191 // Start scrolling. Receive ACK as it being processed.
3192 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
3193 blink::WebGestureDeviceTouchscreen
);
3194 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3196 // Send update events and receive ack as not consumed.
3197 SimulateGestureScrollUpdateEvent(125, -5, 0);
3198 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3200 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
3201 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3202 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
3203 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
3204 EXPECT_EQ(0U, sink_
->message_count());
3206 // Send another update event, but in the reverse direction. The overscroll
3207 // controller will not consume the event, because it is not triggering
3209 SimulateGestureScrollUpdateEvent(-260, 0, 0);
3210 EXPECT_EQ(1U, sink_
->message_count());
3211 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3213 // Since the overscroll mode has been reset, the next scroll update events
3214 // should reach the renderer.
3215 SimulateGestureScrollUpdateEvent(-20, 0, 0);
3216 EXPECT_EQ(1U, sink_
->message_count());
3217 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3220 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
3221 OverscrollDirectionChangeMouseWheel
) {
3222 SetUpOverscrollEnvironment();
3224 // Send wheel event and receive ack as not consumed.
3225 SimulateWheelEvent(125, -5, 0, true);
3226 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3227 SendInputEventACK(WebInputEvent::MouseWheel
,
3228 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3229 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
3230 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
3231 EXPECT_EQ(0U, sink_
->message_count());
3233 // Send another wheel event, but in the reverse direction. The overscroll
3234 // controller will not consume the event, because it is not triggering
3236 SimulateWheelEvent(-260, 0, 0, true);
3237 EXPECT_EQ(1U, sink_
->message_count());
3238 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3240 // Since the overscroll mode has been reset, the next wheel event should reach
3242 SimulateWheelEvent(-20, 0, 0, true);
3243 EXPECT_EQ(1U, sink_
->message_count());
3244 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3247 // Tests that if a mouse-move event completes the overscroll gesture, future
3248 // move events do reach the renderer.
3249 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, OverscrollMouseMoveCompletion
) {
3250 SetUpOverscrollEnvironment();
3252 SimulateWheelEvent(5, 0, 0, true); // sent directly
3253 SimulateWheelEvent(-1, 0, 0, true); // enqueued
3254 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
3255 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
3256 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
3257 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3258 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3260 // Receive ACK the first wheel event as not processed.
3261 SendInputEventACK(WebInputEvent::MouseWheel
,
3262 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3263 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3264 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3265 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3267 // Receive ACK for the second (coalesced) event as not processed. This will
3268 // start an overcroll gesture.
3269 SendInputEventACK(WebInputEvent::MouseWheel
,
3270 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3271 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_mode());
3272 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_delegate()->current_mode());
3273 EXPECT_EQ(0U, sink_
->message_count());
3275 // Send a mouse-move event. This should cancel the overscroll navigation
3276 // (since the amount overscrolled is not above the threshold), and so the
3277 // mouse-move should reach the renderer.
3278 SimulateMouseMove(5, 10, 0);
3279 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3280 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->completed_mode());
3281 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3282 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3284 SendInputEventACK(WebInputEvent::MouseMove
,
3285 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3287 // Moving the mouse more should continue to send the events to the renderer.
3288 SimulateMouseMove(5, 10, 0);
3289 SendInputEventACK(WebInputEvent::MouseMove
,
3290 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3291 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3293 // Now try with gestures.
3294 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
3295 blink::WebGestureDeviceTouchscreen
);
3296 SimulateGestureScrollUpdateEvent(300, -5, 0);
3297 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
3298 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3299 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
3300 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
3301 sink_
->ClearMessages();
3303 // Overscroll gesture is in progress. Send a mouse-move now. This should
3304 // complete the gesture (because the amount overscrolled is above the
3306 SimulateMouseMove(5, 10, 0);
3307 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->completed_mode());
3308 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3309 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3310 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3311 SendInputEventACK(WebInputEvent::MouseMove
,
3312 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3314 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
3315 blink::WebGestureDeviceTouchscreen
);
3316 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3317 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3319 // Move mouse some more. The mouse-move events should reach the renderer.
3320 SimulateMouseMove(5, 10, 0);
3321 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3323 SendInputEventACK(WebInputEvent::MouseMove
,
3324 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3327 // Tests that if a page scrolled, then the overscroll controller's states are
3328 // reset after the end of the scroll.
3329 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
3330 OverscrollStateResetsAfterScroll
) {
3331 SetUpOverscrollEnvironment();
3333 SimulateWheelEvent(0, 5, 0, true); // sent directly
3334 SimulateWheelEvent(0, 30, 0, true); // enqueued
3335 SimulateWheelEvent(0, 40, 0, true); // coalesced into previous event
3336 SimulateWheelEvent(0, 10, 0, true); // coalesced into previous event
3337 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3338 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3340 // The first wheel event is consumed. Dispatches the queued wheel event.
3341 SendInputEventACK(WebInputEvent::MouseWheel
, INPUT_EVENT_ACK_STATE_CONSUMED
);
3342 EXPECT_TRUE(ScrollStateIsContentScrolling());
3343 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3345 // The second wheel event is consumed.
3346 SendInputEventACK(WebInputEvent::MouseWheel
, INPUT_EVENT_ACK_STATE_CONSUMED
);
3347 EXPECT_TRUE(ScrollStateIsContentScrolling());
3349 // Touchpad scroll can end with a zero-velocity fling. But it is not
3350 // dispatched, but it should still reset the overscroll controller state.
3351 SimulateGestureFlingStartEvent(0.f
, 0.f
, blink::WebGestureDeviceTouchpad
);
3352 EXPECT_TRUE(ScrollStateIsUnknown());
3353 EXPECT_EQ(0U, sink_
->message_count());
3355 // Dropped flings should neither propagate *nor* indicate that they were
3356 // consumed and have triggered a fling animation (as tracked by the router).
3357 EXPECT_FALSE(parent_host_
->input_router()->HasPendingEvents());
3359 SimulateWheelEvent(-5, 0, 0, true); // sent directly
3360 SimulateWheelEvent(-60, 0, 0, true); // enqueued
3361 SimulateWheelEvent(-100, 0, 0, true); // coalesced into previous event
3362 EXPECT_TRUE(ScrollStateIsUnknown());
3363 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3365 // The first wheel scroll did not scroll content. Overscroll should not start
3366 // yet, since enough hasn't been scrolled.
3367 SendInputEventACK(WebInputEvent::MouseWheel
,
3368 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3369 EXPECT_TRUE(ScrollStateIsUnknown());
3370 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3372 SendInputEventACK(WebInputEvent::MouseWheel
,
3373 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3374 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_mode());
3375 EXPECT_TRUE(ScrollStateIsOverscrolling());
3376 EXPECT_EQ(0U, sink_
->message_count());
3378 SimulateGestureFlingStartEvent(0.f
, 0.f
, blink::WebGestureDeviceTouchpad
);
3379 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3380 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_delegate()->completed_mode());
3381 EXPECT_TRUE(ScrollStateIsUnknown());
3382 EXPECT_EQ(0U, sink_
->message_count());
3383 EXPECT_FALSE(parent_host_
->input_router()->HasPendingEvents());
3386 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, OverscrollResetsOnBlur
) {
3387 SetUpOverscrollEnvironment();
3389 // Start an overscroll with gesture scroll. In the middle of the scroll, blur
3391 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
3392 blink::WebGestureDeviceTouchscreen
);
3393 SimulateGestureScrollUpdateEvent(300, -5, 0);
3394 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
3395 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3396 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
3397 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
3398 EXPECT_EQ(2U, GetSentMessageCountAndResetSink());
3400 view_
->OnWindowFocused(NULL
, view_
->GetNativeView());
3401 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3402 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3403 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->completed_mode());
3404 EXPECT_EQ(0.f
, overscroll_delegate()->delta_x());
3405 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
3406 sink_
->ClearMessages();
3408 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
3409 blink::WebGestureDeviceTouchscreen
);
3410 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3412 // Start a scroll gesture again. This should correctly start the overscroll
3413 // after the threshold.
3414 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
3415 blink::WebGestureDeviceTouchscreen
);
3416 SimulateGestureScrollUpdateEvent(300, -5, 0);
3417 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
3418 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3419 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
3420 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
3421 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->completed_mode());
3423 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
3424 blink::WebGestureDeviceTouchscreen
);
3425 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
3426 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->completed_mode());
3427 EXPECT_EQ(3U, sink_
->message_count());
3430 // Tests that when view initiated shutdown happens (i.e. RWHView is deleted
3431 // before RWH), we clean up properly and don't leak the RWHVGuest.
3432 TEST_F(RenderWidgetHostViewGuestAuraTest
, GuestViewDoesNotLeak
) {
3433 view_
->InitAsChild(NULL
);
3434 TearDownEnvironment();
3435 ASSERT_FALSE(guest_view_weak_
.get());
3438 // Tests that invalid touch events are consumed and handled
3440 TEST_F(RenderWidgetHostViewAuraTest
,
3441 InvalidEventsHaveSyncHandlingDisabled
) {
3442 view_
->InitAsChild(NULL
);
3444 GetSentMessageCountAndResetSink();
3446 widget_host_
->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
3448 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
, gfx::Point(30, 30), 0,
3449 ui::EventTimeForNow());
3451 // Construct a move with a touch id which doesn't exist.
3452 ui::TouchEvent
invalid_move(ui::ET_TOUCH_MOVED
, gfx::Point(30, 30), 1,
3453 ui::EventTimeForNow());
3455 // Valid press is handled asynchronously.
3456 view_
->OnTouchEvent(&press
);
3457 EXPECT_TRUE(press
.synchronous_handling_disabled());
3458 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
3459 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_CONSUMED
);
3461 // Invalid move is handled synchronously, but is consumed. It should not
3462 // be forwarded to the renderer.
3463 view_
->OnTouchEvent(&invalid_move
);
3464 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
3465 EXPECT_FALSE(invalid_move
.synchronous_handling_disabled());
3466 EXPECT_TRUE(invalid_move
.stopped_propagation());
3469 // Checks key event codes.
3470 TEST_F(RenderWidgetHostViewAuraTest
, KeyEvent
) {
3471 view_
->InitAsChild(NULL
);
3474 ui::KeyEvent
key_event(ui::ET_KEY_PRESSED
, ui::VKEY_A
, ui::DomCode::KEY_A
,
3476 view_
->OnKeyEvent(&key_event
);
3478 const NativeWebKeyboardEvent
* event
= delegate_
.last_event();
3479 EXPECT_NE(nullptr, event
);
3481 EXPECT_EQ(key_event
.key_code(), event
->windowsKeyCode
);
3482 EXPECT_EQ(ui::KeycodeConverter::DomCodeToNativeKeycode(key_event
.code()),
3483 event
->nativeKeyCode
);
3487 TEST_F(RenderWidgetHostViewAuraTest
, SetCanScrollForWebMouseWheelEvent
) {
3488 view_
->InitAsChild(NULL
);
3491 sink_
->ClearMessages();
3493 // Simulates the mouse wheel event with ctrl modifier applied.
3494 ui::MouseWheelEvent
event(gfx::Vector2d(1, 1), gfx::Point(), gfx::Point(),
3495 ui::EventTimeForNow(), ui::EF_CONTROL_DOWN
, 0);
3496 view_
->OnMouseEvent(&event
);
3498 const WebInputEvent
* input_event
=
3499 GetInputEventFromMessage(*sink_
->GetMessageAt(0));
3500 const WebMouseWheelEvent
* wheel_event
=
3501 static_cast<const WebMouseWheelEvent
*>(input_event
);
3502 // Check if the canScroll set to false when ctrl-scroll is generated from
3503 // mouse wheel event.
3504 EXPECT_FALSE(wheel_event
->canScroll
);
3505 sink_
->ClearMessages();
3507 // Ack'ing the outstanding event should flush the pending event queue.
3508 SendInputEventACK(blink::WebInputEvent::MouseWheel
,
3509 INPUT_EVENT_ACK_STATE_CONSUMED
);
3511 // Simulates the mouse wheel event with no modifier applied.
3512 event
= ui::MouseWheelEvent(gfx::Vector2d(1, 1), gfx::Point(), gfx::Point(),
3513 ui::EventTimeForNow(), ui::EF_NONE
, 0);
3515 view_
->OnMouseEvent(&event
);
3517 input_event
= GetInputEventFromMessage(*sink_
->GetMessageAt(0));
3518 wheel_event
= static_cast<const WebMouseWheelEvent
*>(input_event
);
3519 // Check if the canScroll set to true when no modifier is applied to the
3520 // mouse wheel event.
3521 EXPECT_TRUE(wheel_event
->canScroll
);
3522 sink_
->ClearMessages();
3524 SendInputEventACK(blink::WebInputEvent::MouseWheel
,
3525 INPUT_EVENT_ACK_STATE_CONSUMED
);
3527 // Simulates the scroll event with ctrl modifier applied.
3528 ui::ScrollEvent
scroll(ui::ET_SCROLL
, gfx::Point(2, 2), ui::EventTimeForNow(),
3529 ui::EF_CONTROL_DOWN
, 0, 5, 0, 5, 2);
3530 view_
->OnScrollEvent(&scroll
);
3532 input_event
= GetInputEventFromMessage(*sink_
->GetMessageAt(0));
3533 wheel_event
= static_cast<const WebMouseWheelEvent
*>(input_event
);
3534 // Check if the canScroll set to true when ctrl-touchpad-scroll is generated
3535 // from scroll event.
3536 EXPECT_TRUE(wheel_event
->canScroll
);
3539 // Ensures that the mapping from ui::TouchEvent to blink::WebTouchEvent doesn't
3540 // lose track of the number of acks required.
3541 TEST_F(RenderWidgetHostViewAuraTest
, CorrectNumberOfAcksAreDispatched
) {
3542 view_
->InitAsFullscreen(parent_view_
);
3544 view_
->UseFakeDispatcher();
3546 ui::TouchEvent
press1(
3547 ui::ET_TOUCH_PRESSED
, gfx::Point(30, 30), 0, ui::EventTimeForNow());
3549 view_
->OnTouchEvent(&press1
);
3550 SendTouchEventACK(blink::WebInputEvent::TouchStart
,
3551 INPUT_EVENT_ACK_STATE_CONSUMED
, press1
.unique_event_id());
3553 ui::TouchEvent
press2(
3554 ui::ET_TOUCH_PRESSED
, gfx::Point(20, 20), 1, ui::EventTimeForNow());
3555 view_
->OnTouchEvent(&press2
);
3556 SendTouchEventACK(blink::WebInputEvent::TouchStart
,
3557 INPUT_EVENT_ACK_STATE_CONSUMED
, press2
.unique_event_id());
3559 EXPECT_EQ(2U, view_
->dispatcher_
->GetAndResetProcessedTouchEventCount());
3562 // Tests that the scroll deltas stored within the overscroll controller get
3563 // reset at the end of the overscroll gesture even if the overscroll threshold
3564 // isn't surpassed and the overscroll mode stays OVERSCROLL_NONE.
3565 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, ScrollDeltasResetOnEnd
) {
3566 SetUpOverscrollEnvironment();
3567 // Wheel event scroll ending with mouse move.
3568 SimulateWheelEvent(-30, -10, 0, true); // sent directly
3569 SendInputEventACK(WebInputEvent::MouseWheel
,
3570 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3571 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3572 EXPECT_EQ(-30.f
, overscroll_delta_x());
3573 EXPECT_EQ(-10.f
, overscroll_delta_y());
3574 SimulateMouseMove(5, 10, 0);
3575 EXPECT_EQ(0.f
, overscroll_delta_x());
3576 EXPECT_EQ(0.f
, overscroll_delta_y());
3579 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
3580 blink::WebGestureDeviceTouchscreen
);
3581 SimulateGestureScrollUpdateEvent(-30, -5, 0);
3582 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
3583 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3584 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3585 EXPECT_EQ(-30.f
, overscroll_delta_x());
3586 EXPECT_EQ(-5.f
, overscroll_delta_y());
3587 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
3588 blink::WebGestureDeviceTouchscreen
);
3589 EXPECT_EQ(0.f
, overscroll_delta_x());
3590 EXPECT_EQ(0.f
, overscroll_delta_y());
3592 // Wheel event scroll ending with a fling.
3593 SimulateWheelEvent(5, 0, 0, true);
3594 SendInputEventACK(WebInputEvent::MouseWheel
,
3595 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3596 SimulateWheelEvent(10, -5, 0, true);
3597 SendInputEventACK(WebInputEvent::MouseWheel
,
3598 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
3599 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
3600 EXPECT_EQ(15.f
, overscroll_delta_x());
3601 EXPECT_EQ(-5.f
, overscroll_delta_y());
3602 SimulateGestureFlingStartEvent(0.f
, 0.1f
, blink::WebGestureDeviceTouchpad
);
3603 EXPECT_EQ(0.f
, overscroll_delta_x());
3604 EXPECT_EQ(0.f
, overscroll_delta_y());
3607 // Tests the RenderWidgetHostImpl sends the correct surface ID namespace to
3608 // the renderer process.
3609 TEST_F(RenderWidgetHostViewAuraTest
, SurfaceIdNamespaceInitialized
) {
3610 gfx::Size
size(5, 5);
3612 const IPC::Message
* msg
=
3613 sink_
->GetUniqueMessageMatching(ViewMsg_SetSurfaceIdNamespace::ID
);
3615 ViewMsg_SetSurfaceIdNamespace::Param params
;
3616 ViewMsg_SetSurfaceIdNamespace::Read(msg
, ¶ms
);
3617 view_
->InitAsChild(NULL
);
3619 view_
->SetSize(size
);
3620 view_
->OnSwapCompositorFrame(0,
3621 MakeDelegatedFrame(1.f
, size
, gfx::Rect(size
)));
3622 EXPECT_EQ(view_
->GetSurfaceIdNamespace(), base::get
<0>(params
));
3625 } // namespace content