1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
7 #include "base/basictypes.h"
8 #include "base/command_line.h"
9 #include "base/memory/shared_memory.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "cc/output/compositor_frame.h"
14 #include "cc/output/compositor_frame_metadata.h"
15 #include "cc/output/copy_output_request.h"
16 #include "content/browser/browser_thread_impl.h"
17 #include "content/browser/compositor/resize_lock.h"
18 #include "content/browser/compositor/test/no_transport_image_transport_factory.h"
19 #include "content/browser/renderer_host/overscroll_controller.h"
20 #include "content/browser/renderer_host/overscroll_controller_delegate.h"
21 #include "content/browser/renderer_host/render_widget_host_delegate.h"
22 #include "content/browser/renderer_host/render_widget_host_impl.h"
23 #include "content/common/gpu/client/gl_helper.h"
24 #include "content/common/gpu/gpu_messages.h"
25 #include "content/common/host_shared_bitmap_manager.h"
26 #include "content/common/input/synthetic_web_input_event_builders.h"
27 #include "content/common/input_messages.h"
28 #include "content/common/view_messages.h"
29 #include "content/public/browser/render_widget_host_view.h"
30 #include "content/public/browser/render_widget_host_view_frame_subscriber.h"
31 #include "content/public/test/mock_render_process_host.h"
32 #include "content/public/test/test_browser_context.h"
33 #include "ipc/ipc_test_sink.h"
34 #include "testing/gmock/include/gmock/gmock.h"
35 #include "testing/gtest/include/gtest/gtest.h"
36 #include "ui/aura/client/aura_constants.h"
37 #include "ui/aura/client/screen_position_client.h"
38 #include "ui/aura/client/window_tree_client.h"
39 #include "ui/aura/env.h"
40 #include "ui/aura/layout_manager.h"
41 #include "ui/aura/test/aura_test_helper.h"
42 #include "ui/aura/test/test_cursor_client.h"
43 #include "ui/aura/test/test_screen.h"
44 #include "ui/aura/test/test_window_delegate.h"
45 #include "ui/aura/window.h"
46 #include "ui/aura/window_event_dispatcher.h"
47 #include "ui/aura/window_observer.h"
48 #include "ui/base/ui_base_types.h"
49 #include "ui/compositor/compositor.h"
50 #include "ui/compositor/test/draw_waiter_for_test.h"
51 #include "ui/events/event.h"
52 #include "ui/events/event_utils.h"
53 #include "ui/events/gestures/gesture_configuration.h"
54 #include "ui/events/test/event_generator.h"
55 #include "ui/wm/core/default_activation_client.h"
59 using blink::WebGestureEvent
;
60 using blink::WebInputEvent
;
61 using blink::WebMouseEvent
;
62 using blink::WebMouseWheelEvent
;
63 using blink::WebTouchEvent
;
64 using blink::WebTouchPoint
;
69 // Simple screen position client to test coordinate system conversion.
70 class TestScreenPositionClient
71 : public aura::client::ScreenPositionClient
{
73 TestScreenPositionClient() {}
74 virtual ~TestScreenPositionClient() {}
76 // aura::client::ScreenPositionClient overrides:
77 virtual void ConvertPointToScreen(const aura::Window
* window
,
78 gfx::Point
* point
) OVERRIDE
{
79 point
->Offset(-1, -1);
82 virtual void ConvertPointFromScreen(const aura::Window
* window
,
83 gfx::Point
* point
) OVERRIDE
{
87 virtual void ConvertHostPointToScreen(aura::Window
* window
,
88 gfx::Point
* point
) OVERRIDE
{
89 ConvertPointToScreen(window
, point
);
92 virtual void SetBounds(aura::Window
* window
,
93 const gfx::Rect
& bounds
,
94 const gfx::Display
& display
) OVERRIDE
{
98 class TestOverscrollDelegate
: public OverscrollControllerDelegate
{
100 explicit TestOverscrollDelegate(RenderWidgetHostView
* view
)
102 current_mode_(OVERSCROLL_NONE
),
103 completed_mode_(OVERSCROLL_NONE
),
107 virtual ~TestOverscrollDelegate() {}
109 OverscrollMode
current_mode() const { return current_mode_
; }
110 OverscrollMode
completed_mode() const { return completed_mode_
; }
111 float delta_x() const { return delta_x_
; }
112 float delta_y() const { return delta_y_
; }
115 current_mode_
= OVERSCROLL_NONE
;
116 completed_mode_
= OVERSCROLL_NONE
;
117 delta_x_
= delta_y_
= 0.f
;
121 // Overridden from OverscrollControllerDelegate:
122 virtual gfx::Rect
GetVisibleBounds() const OVERRIDE
{
123 return view_
->IsShowing() ? view_
->GetViewBounds() : gfx::Rect();
126 virtual bool OnOverscrollUpdate(float delta_x
, float delta_y
) OVERRIDE
{
132 virtual void OnOverscrollComplete(OverscrollMode overscroll_mode
) OVERRIDE
{
133 EXPECT_EQ(current_mode_
, overscroll_mode
);
134 completed_mode_
= overscroll_mode
;
135 current_mode_
= OVERSCROLL_NONE
;
138 virtual void OnOverscrollModeChange(OverscrollMode old_mode
,
139 OverscrollMode new_mode
) OVERRIDE
{
140 EXPECT_EQ(current_mode_
, old_mode
);
141 current_mode_
= new_mode
;
142 delta_x_
= delta_y_
= 0.f
;
145 RenderWidgetHostView
* view_
;
146 OverscrollMode current_mode_
;
147 OverscrollMode completed_mode_
;
151 DISALLOW_COPY_AND_ASSIGN(TestOverscrollDelegate
);
154 class MockRenderWidgetHostDelegate
: public RenderWidgetHostDelegate
{
156 MockRenderWidgetHostDelegate() {}
157 virtual ~MockRenderWidgetHostDelegate() {}
160 // Simple observer that keeps track of changes to a window for tests.
161 class TestWindowObserver
: public aura::WindowObserver
{
163 explicit TestWindowObserver(aura::Window
* window_to_observe
)
164 : window_(window_to_observe
) {
165 window_
->AddObserver(this);
167 virtual ~TestWindowObserver() {
169 window_
->RemoveObserver(this);
172 bool destroyed() const { return destroyed_
; }
174 // aura::WindowObserver overrides:
175 virtual void OnWindowDestroyed(aura::Window
* window
) OVERRIDE
{
176 CHECK_EQ(window
, window_
);
182 // Window that we're observing, or NULL if it's been destroyed.
183 aura::Window
* window_
;
185 // Was |window_| destroyed?
188 DISALLOW_COPY_AND_ASSIGN(TestWindowObserver
);
191 class FakeFrameSubscriber
: public RenderWidgetHostViewFrameSubscriber
{
193 FakeFrameSubscriber(gfx::Size size
, base::Callback
<void(bool)> callback
)
194 : size_(size
), callback_(callback
) {}
196 virtual bool ShouldCaptureFrame(const gfx::Rect
& damage_rect
,
197 base::TimeTicks present_time
,
198 scoped_refptr
<media::VideoFrame
>* storage
,
199 DeliverFrameCallback
* callback
) OVERRIDE
{
200 *storage
= media::VideoFrame::CreateFrame(media::VideoFrame::YV12
,
205 *callback
= base::Bind(&FakeFrameSubscriber::CallbackMethod
, callback_
);
209 static void CallbackMethod(base::Callback
<void(bool)> callback
,
210 base::TimeTicks timestamp
,
212 callback
.Run(success
);
217 base::Callback
<void(bool)> callback_
;
220 class FakeRenderWidgetHostViewAura
: public RenderWidgetHostViewAura
{
222 FakeRenderWidgetHostViewAura(RenderWidgetHost
* widget
)
223 : RenderWidgetHostViewAura(widget
), has_resize_lock_(false) {}
225 virtual ~FakeRenderWidgetHostViewAura() {}
227 virtual scoped_ptr
<ResizeLock
> CreateResizeLock(
228 bool defer_compositor_lock
) OVERRIDE
{
229 gfx::Size desired_size
= window()->bounds().size();
230 return scoped_ptr
<ResizeLock
>(
231 new FakeResizeLock(desired_size
, defer_compositor_lock
));
234 void RunOnCompositingDidCommit() {
235 GetDelegatedFrameHost()->OnCompositingDidCommitForTesting(
236 window()->GetHost()->compositor());
239 virtual bool ShouldCreateResizeLock() OVERRIDE
{
240 return GetDelegatedFrameHost()->ShouldCreateResizeLockForTesting();
243 virtual void RequestCopyOfOutput(scoped_ptr
<cc::CopyOutputRequest
> request
)
245 last_copy_request_
= request
.Pass();
246 if (last_copy_request_
->has_texture_mailbox()) {
247 // Give the resulting texture a size.
248 GLHelper
* gl_helper
= ImageTransportFactory::GetInstance()->GetGLHelper();
249 GLuint texture
= gl_helper
->ConsumeMailboxToTexture(
250 last_copy_request_
->texture_mailbox().mailbox(),
251 last_copy_request_
->texture_mailbox().sync_point());
252 gl_helper
->ResizeTexture(texture
, window()->bounds().size());
253 gl_helper
->DeleteTexture(texture
);
257 cc::DelegatedFrameProvider
* frame_provider() const {
258 return GetDelegatedFrameHost()->FrameProviderForTesting();
261 bool released_front_lock_active() const {
262 return GetDelegatedFrameHost()->ReleasedFrontLockActiveForTesting();
265 // A lock that doesn't actually do anything to the compositor, and does not
267 class FakeResizeLock
: public ResizeLock
{
269 FakeResizeLock(const gfx::Size new_size
, bool defer_compositor_lock
)
270 : ResizeLock(new_size
, defer_compositor_lock
) {}
273 bool has_resize_lock_
;
274 gfx::Size last_frame_size_
;
275 scoped_ptr
<cc::CopyOutputRequest
> last_copy_request_
;
278 // A layout manager that always resizes a child to the root window size.
279 class FullscreenLayoutManager
: public aura::LayoutManager
{
281 explicit FullscreenLayoutManager(aura::Window
* owner
) : owner_(owner
) {}
282 virtual ~FullscreenLayoutManager() {}
284 // Overridden from aura::LayoutManager:
285 virtual void OnWindowResized() OVERRIDE
{
286 aura::Window::Windows::const_iterator i
;
287 for (i
= owner_
->children().begin(); i
!= owner_
->children().end(); ++i
) {
288 (*i
)->SetBounds(gfx::Rect());
291 virtual void OnWindowAddedToLayout(aura::Window
* child
) OVERRIDE
{
292 child
->SetBounds(gfx::Rect());
294 virtual void OnWillRemoveWindowFromLayout(aura::Window
* child
) OVERRIDE
{}
295 virtual void OnWindowRemovedFromLayout(aura::Window
* child
) OVERRIDE
{}
296 virtual void OnChildWindowVisibilityChanged(aura::Window
* child
,
297 bool visible
) OVERRIDE
{}
298 virtual void SetChildBounds(aura::Window
* child
,
299 const gfx::Rect
& requested_bounds
) OVERRIDE
{
300 SetChildBoundsDirect(child
, gfx::Rect(owner_
->bounds().size()));
304 aura::Window
* owner_
;
305 DISALLOW_COPY_AND_ASSIGN(FullscreenLayoutManager
);
308 class MockWindowObserver
: public aura::WindowObserver
{
310 MOCK_METHOD2(OnDelegatedFrameDamage
, void(aura::Window
*, const gfx::Rect
&));
315 class RenderWidgetHostViewAuraTest
: public testing::Test
{
317 RenderWidgetHostViewAuraTest()
318 : browser_thread_for_ui_(BrowserThread::UI
, &message_loop_
) {}
320 void SetUpEnvironment() {
321 ImageTransportFactory::InitializeForUnitTests(
322 scoped_ptr
<ImageTransportFactory
>(
323 new NoTransportImageTransportFactory
));
324 aura_test_helper_
.reset(new aura::test::AuraTestHelper(&message_loop_
));
325 aura_test_helper_
->SetUp(
326 ImageTransportFactory::GetInstance()->GetContextFactory());
327 new wm::DefaultActivationClient(aura_test_helper_
->root_window());
329 browser_context_
.reset(new TestBrowserContext
);
330 process_host_
= new MockRenderProcessHost(browser_context_
.get());
332 sink_
= &process_host_
->sink();
334 parent_host_
= new RenderWidgetHostImpl(
335 &delegate_
, process_host_
, MSG_ROUTING_NONE
, false);
336 parent_view_
= new RenderWidgetHostViewAura(parent_host_
);
337 parent_view_
->InitAsChild(NULL
);
338 aura::client::ParentWindowWithContext(parent_view_
->GetNativeView(),
339 aura_test_helper_
->root_window(),
342 widget_host_
= new RenderWidgetHostImpl(
343 &delegate_
, process_host_
, MSG_ROUTING_NONE
, false);
344 widget_host_
->Init();
345 view_
= new FakeRenderWidgetHostViewAura(widget_host_
);
348 void TearDownEnvironment() {
350 process_host_
= NULL
;
355 parent_view_
->Destroy();
358 browser_context_
.reset();
359 aura_test_helper_
->TearDown();
361 message_loop_
.DeleteSoon(FROM_HERE
, browser_context_
.release());
362 message_loop_
.RunUntilIdle();
363 ImageTransportFactory::Terminate();
366 virtual void SetUp() { SetUpEnvironment(); }
368 virtual void TearDown() { TearDownEnvironment(); }
371 base::MessageLoopForUI message_loop_
;
372 BrowserThreadImpl browser_thread_for_ui_
;
373 scoped_ptr
<aura::test::AuraTestHelper
> aura_test_helper_
;
374 scoped_ptr
<BrowserContext
> browser_context_
;
375 MockRenderWidgetHostDelegate delegate_
;
376 MockRenderProcessHost
* process_host_
;
378 // Tests should set these to NULL if they've already triggered their
380 RenderWidgetHostImpl
* parent_host_
;
381 RenderWidgetHostViewAura
* parent_view_
;
383 // Tests should set these to NULL if they've already triggered their
385 RenderWidgetHostImpl
* widget_host_
;
386 FakeRenderWidgetHostViewAura
* view_
;
388 IPC::TestSink
* sink_
;
391 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraTest
);
394 class RenderWidgetHostViewAuraOverscrollTest
395 : public RenderWidgetHostViewAuraTest
{
397 RenderWidgetHostViewAuraOverscrollTest() {}
399 // We explicitly invoke SetUp to allow gesture debounce customization.
400 virtual void SetUp() {}
403 void SetUpOverscrollEnvironmentWithDebounce(int debounce_interval_in_ms
) {
404 SetUpOverscrollEnvironmentImpl(debounce_interval_in_ms
);
407 void SetUpOverscrollEnvironment() { SetUpOverscrollEnvironmentImpl(0); }
409 void SetUpOverscrollEnvironmentImpl(int debounce_interval_in_ms
) {
410 ui::GestureConfiguration::set_scroll_debounce_interval_in_ms(
411 debounce_interval_in_ms
);
413 RenderWidgetHostViewAuraTest::SetUp();
415 view_
->SetOverscrollControllerEnabled(true);
416 overscroll_delegate_
.reset(new TestOverscrollDelegate(view_
));
417 view_
->overscroll_controller()->set_delegate(overscroll_delegate_
.get());
419 view_
->InitAsChild(NULL
);
420 view_
->SetBounds(gfx::Rect(0, 0, 400, 200));
423 sink_
->ClearMessages();
426 // TODO(jdduke): Simulate ui::Events, injecting through the view.
427 void SimulateMouseEvent(WebInputEvent::Type type
) {
428 widget_host_
->ForwardMouseEvent(SyntheticWebMouseEventBuilder::Build(type
));
431 void SimulateMouseEventWithLatencyInfo(WebInputEvent::Type type
,
432 const ui::LatencyInfo
& ui_latency
) {
433 widget_host_
->ForwardMouseEventWithLatencyInfo(
434 SyntheticWebMouseEventBuilder::Build(type
), ui_latency
);
437 void SimulateWheelEvent(float dX
, float dY
, int modifiers
, bool precise
) {
438 widget_host_
->ForwardWheelEvent(
439 SyntheticWebMouseWheelEventBuilder::Build(dX
, dY
, modifiers
, precise
));
442 void SimulateWheelEventWithLatencyInfo(float dX
,
446 const ui::LatencyInfo
& ui_latency
) {
447 widget_host_
->ForwardWheelEventWithLatencyInfo(
448 SyntheticWebMouseWheelEventBuilder::Build(dX
, dY
, modifiers
, precise
),
452 void SimulateMouseMove(int x
, int y
, int modifiers
) {
453 SimulateMouseEvent(WebInputEvent::MouseMove
, x
, y
, modifiers
, false);
456 void SimulateMouseEvent(WebInputEvent::Type type
,
461 WebMouseEvent event
=
462 SyntheticWebMouseEventBuilder::Build(type
, x
, y
, modifiers
);
464 event
.button
= WebMouseEvent::ButtonLeft
;
465 widget_host_
->ForwardMouseEvent(event
);
468 void SimulateWheelEventWithPhase(WebMouseWheelEvent::Phase phase
) {
469 widget_host_
->ForwardWheelEvent(
470 SyntheticWebMouseWheelEventBuilder::Build(phase
));
473 // Inject provided synthetic WebGestureEvent instance.
474 void SimulateGestureEventCore(const WebGestureEvent
& gesture_event
) {
475 widget_host_
->ForwardGestureEvent(gesture_event
);
478 void SimulateGestureEventCoreWithLatencyInfo(
479 const WebGestureEvent
& gesture_event
,
480 const ui::LatencyInfo
& ui_latency
) {
481 widget_host_
->ForwardGestureEventWithLatencyInfo(gesture_event
, ui_latency
);
484 // Inject simple synthetic WebGestureEvent instances.
485 void SimulateGestureEvent(WebInputEvent::Type type
,
486 blink::WebGestureDevice sourceDevice
) {
487 SimulateGestureEventCore(
488 SyntheticWebGestureEventBuilder::Build(type
, sourceDevice
));
491 void SimulateGestureEventWithLatencyInfo(WebInputEvent::Type type
,
492 blink::WebGestureDevice sourceDevice
,
493 const ui::LatencyInfo
& ui_latency
) {
494 SimulateGestureEventCoreWithLatencyInfo(
495 SyntheticWebGestureEventBuilder::Build(type
, sourceDevice
), ui_latency
);
498 void SimulateGestureScrollUpdateEvent(float dX
, float dY
, int modifiers
) {
499 SimulateGestureEventCore(
500 SyntheticWebGestureEventBuilder::BuildScrollUpdate(dX
, dY
, modifiers
));
503 void SimulateGesturePinchUpdateEvent(float scale
,
507 SimulateGestureEventCore(SyntheticWebGestureEventBuilder::BuildPinchUpdate(
512 blink::WebGestureDeviceTouchscreen
));
515 // Inject synthetic GestureFlingStart events.
516 void SimulateGestureFlingStartEvent(float velocityX
,
518 blink::WebGestureDevice sourceDevice
) {
519 SimulateGestureEventCore(SyntheticWebGestureEventBuilder::BuildFling(
520 velocityX
, velocityY
, sourceDevice
));
523 void SendInputEventACK(WebInputEvent::Type type
,
524 InputEventAckState ack_result
) {
525 InputHostMsg_HandleInputEvent_ACK_Params ack
;
527 ack
.state
= ack_result
;
528 InputHostMsg_HandleInputEvent_ACK
response(0, ack
);
529 widget_host_
->OnMessageReceived(response
);
532 bool ScrollStateIsContentScrolling() const {
533 return scroll_state() == OverscrollController::STATE_CONTENT_SCROLLING
;
536 bool ScrollStateIsOverscrolling() const {
537 return scroll_state() == OverscrollController::STATE_OVERSCROLLING
;
540 bool ScrollStateIsUnknown() const {
541 return scroll_state() == OverscrollController::STATE_UNKNOWN
;
544 OverscrollController::ScrollState
scroll_state() const {
545 return view_
->overscroll_controller()->scroll_state_
;
548 OverscrollMode
overscroll_mode() const {
549 return view_
->overscroll_controller()->overscroll_mode_
;
552 float overscroll_delta_x() const {
553 return view_
->overscroll_controller()->overscroll_delta_x_
;
556 float overscroll_delta_y() const {
557 return view_
->overscroll_controller()->overscroll_delta_y_
;
560 TestOverscrollDelegate
* overscroll_delegate() {
561 return overscroll_delegate_
.get();
564 void SendTouchEvent() {
565 widget_host_
->ForwardTouchEventWithLatencyInfo(touch_event_
,
567 touch_event_
.ResetPoints();
570 void PressTouchPoint(int x
, int y
) {
571 touch_event_
.PressPoint(x
, y
);
575 void MoveTouchPoint(int index
, int x
, int y
) {
576 touch_event_
.MovePoint(index
, x
, y
);
580 void ReleaseTouchPoint(int index
) {
581 touch_event_
.ReleasePoint(index
);
585 size_t GetSentMessageCountAndResetSink() {
586 size_t count
= sink_
->message_count();
587 sink_
->ClearMessages();
591 void AckLastSentInputEventIfNecessary(InputEventAckState ack_result
) {
592 if (!sink_
->message_count())
595 InputMsg_HandleInputEvent::Param params
;
596 if (!InputMsg_HandleInputEvent::Read(
597 sink_
->GetMessageAt(sink_
->message_count() - 1), ¶ms
)) {
601 if (WebInputEventTraits::IgnoresAckDisposition(*params
.a
))
604 SendInputEventACK(params
.a
->type
, ack_result
);
607 SyntheticWebTouchEvent touch_event_
;
609 scoped_ptr
<TestOverscrollDelegate
> overscroll_delegate_
;
612 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraOverscrollTest
);
615 class RenderWidgetHostViewAuraShutdownTest
616 : public RenderWidgetHostViewAuraTest
{
618 RenderWidgetHostViewAuraShutdownTest() {}
620 virtual void TearDown() OVERRIDE
{
621 // No TearDownEnvironment here, we do this explicitly during the test.
625 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraShutdownTest
);
628 // Checks that a fullscreen view has the correct show-state and receives the
630 TEST_F(RenderWidgetHostViewAuraTest
, FocusFullscreen
) {
631 view_
->InitAsFullscreen(parent_view_
);
632 aura::Window
* window
= view_
->GetNativeView();
633 ASSERT_TRUE(window
!= NULL
);
634 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN
,
635 window
->GetProperty(aura::client::kShowStateKey
));
637 // Check that we requested and received the focus.
638 EXPECT_TRUE(window
->HasFocus());
640 // Check that we'll also say it's okay to activate the window when there's an
641 // ActivationClient defined.
642 EXPECT_TRUE(view_
->ShouldActivate());
645 // Checks that a popup is positioned correctly relative to its parent using
646 // screen coordinates.
647 TEST_F(RenderWidgetHostViewAuraTest
, PositionChildPopup
) {
648 TestScreenPositionClient screen_position_client
;
650 aura::Window
* window
= parent_view_
->GetNativeView();
651 aura::Window
* root
= window
->GetRootWindow();
652 aura::client::SetScreenPositionClient(root
, &screen_position_client
);
654 parent_view_
->SetBounds(gfx::Rect(10, 10, 800, 600));
655 gfx::Rect bounds_in_screen
= parent_view_
->GetViewBounds();
656 int horiz
= bounds_in_screen
.width() / 4;
657 int vert
= bounds_in_screen
.height() / 4;
658 bounds_in_screen
.Inset(horiz
, vert
);
660 // Verify that when the popup is initialized for the first time, it correctly
661 // treats the input bounds as screen coordinates.
662 view_
->InitAsPopup(parent_view_
, bounds_in_screen
);
664 gfx::Rect final_bounds_in_screen
= view_
->GetViewBounds();
665 EXPECT_EQ(final_bounds_in_screen
.ToString(), bounds_in_screen
.ToString());
667 // Verify that directly setting the bounds via SetBounds() treats the input
668 // as screen coordinates.
669 bounds_in_screen
= gfx::Rect(60, 60, 100, 100);
670 view_
->SetBounds(bounds_in_screen
);
671 final_bounds_in_screen
= view_
->GetViewBounds();
672 EXPECT_EQ(final_bounds_in_screen
.ToString(), bounds_in_screen
.ToString());
674 // Verify that setting the size does not alter the origin.
675 gfx::Point original_origin
= window
->bounds().origin();
676 view_
->SetSize(gfx::Size(120, 120));
677 gfx::Point new_origin
= window
->bounds().origin();
678 EXPECT_EQ(original_origin
.ToString(), new_origin
.ToString());
680 aura::client::SetScreenPositionClient(root
, NULL
);
683 // Checks that a fullscreen view is destroyed when it loses the focus.
684 TEST_F(RenderWidgetHostViewAuraTest
, DestroyFullscreenOnBlur
) {
685 view_
->InitAsFullscreen(parent_view_
);
686 aura::Window
* window
= view_
->GetNativeView();
687 ASSERT_TRUE(window
!= NULL
);
688 ASSERT_TRUE(window
->HasFocus());
690 // After we create and focus another window, the RWHVA's window should be
692 TestWindowObserver
observer(window
);
693 aura::test::TestWindowDelegate delegate
;
694 scoped_ptr
<aura::Window
> sibling(new aura::Window(&delegate
));
695 sibling
->Init(aura::WINDOW_LAYER_TEXTURED
);
697 window
->parent()->AddChild(sibling
.get());
699 ASSERT_TRUE(sibling
->HasFocus());
700 ASSERT_TRUE(observer
.destroyed());
706 // Checks that a popup view is destroyed when a user clicks outside of the popup
707 // view and focus does not change. This is the case when the user clicks on the
708 // desktop background on Chrome OS.
709 TEST_F(RenderWidgetHostViewAuraTest
, DestroyPopupClickOutsidePopup
) {
710 parent_view_
->SetBounds(gfx::Rect(10, 10, 400, 400));
711 parent_view_
->Focus();
712 EXPECT_TRUE(parent_view_
->HasFocus());
714 view_
->InitAsPopup(parent_view_
, gfx::Rect(10, 10, 100, 100));
715 aura::Window
* window
= view_
->GetNativeView();
716 ASSERT_TRUE(window
!= NULL
);
718 gfx::Point click_point
;
719 EXPECT_FALSE(window
->GetBoundsInRootWindow().Contains(click_point
));
720 aura::Window
* parent_window
= parent_view_
->GetNativeView();
721 EXPECT_FALSE(parent_window
->GetBoundsInRootWindow().Contains(click_point
));
723 TestWindowObserver
observer(window
);
724 ui::test::EventGenerator
generator(window
->GetRootWindow(), click_point
);
725 generator
.ClickLeftButton();
726 ASSERT_TRUE(parent_view_
->HasFocus());
727 ASSERT_TRUE(observer
.destroyed());
733 // Checks that a popup view is destroyed when a user taps outside of the popup
734 // view and focus does not change. This is the case when the user taps the
735 // desktop background on Chrome OS.
736 TEST_F(RenderWidgetHostViewAuraTest
, DestroyPopupTapOutsidePopup
) {
737 parent_view_
->SetBounds(gfx::Rect(10, 10, 400, 400));
738 parent_view_
->Focus();
739 EXPECT_TRUE(parent_view_
->HasFocus());
741 view_
->InitAsPopup(parent_view_
, gfx::Rect(10, 10, 100, 100));
742 aura::Window
* window
= view_
->GetNativeView();
743 ASSERT_TRUE(window
!= NULL
);
745 gfx::Point tap_point
;
746 EXPECT_FALSE(window
->GetBoundsInRootWindow().Contains(tap_point
));
747 aura::Window
* parent_window
= parent_view_
->GetNativeView();
748 EXPECT_FALSE(parent_window
->GetBoundsInRootWindow().Contains(tap_point
));
750 TestWindowObserver
observer(window
);
751 ui::test::EventGenerator
generator(window
->GetRootWindow(), tap_point
);
752 generator
.GestureTapAt(tap_point
);
753 ASSERT_TRUE(parent_view_
->HasFocus());
754 ASSERT_TRUE(observer
.destroyed());
760 // Checks that IME-composition-event state is maintained correctly.
761 TEST_F(RenderWidgetHostViewAuraTest
, SetCompositionText
) {
762 view_
->InitAsChild(NULL
);
765 ui::CompositionText composition_text
;
766 composition_text
.text
= base::ASCIIToUTF16("|a|b");
769 composition_text
.underlines
.push_back(
770 ui::CompositionUnderline(0, 3, 0xff000000, true, 0x78563412));
772 // Non-focused segment, with different background color.
773 composition_text
.underlines
.push_back(
774 ui::CompositionUnderline(3, 4, 0xff000000, false, 0xefcdab90));
776 const ui::CompositionUnderlines
& underlines
= composition_text
.underlines
;
778 // Caret is at the end. (This emulates Japanese MSIME 2007 and later)
779 composition_text
.selection
= gfx::Range(4);
781 sink_
->ClearMessages();
782 view_
->SetCompositionText(composition_text
);
783 EXPECT_TRUE(view_
->has_composition_text_
);
785 const IPC::Message
* msg
=
786 sink_
->GetFirstMessageMatching(InputMsg_ImeSetComposition::ID
);
787 ASSERT_TRUE(msg
!= NULL
);
789 InputMsg_ImeSetComposition::Param params
;
790 InputMsg_ImeSetComposition::Read(msg
, ¶ms
);
792 EXPECT_EQ(composition_text
.text
, params
.a
);
794 ASSERT_EQ(underlines
.size(), params
.b
.size());
795 for (size_t i
= 0; i
< underlines
.size(); ++i
) {
796 EXPECT_EQ(underlines
[i
].start_offset
, params
.b
[i
].startOffset
);
797 EXPECT_EQ(underlines
[i
].end_offset
, params
.b
[i
].endOffset
);
798 EXPECT_EQ(underlines
[i
].color
, params
.b
[i
].color
);
799 EXPECT_EQ(underlines
[i
].thick
, params
.b
[i
].thick
);
800 EXPECT_EQ(underlines
[i
].background_color
, params
.b
[i
].backgroundColor
);
803 EXPECT_EQ(4, params
.c
) << "Should be the same to the caret pos";
804 EXPECT_EQ(4, params
.d
) << "Should be the same to the caret pos";
807 view_
->ImeCancelComposition();
808 EXPECT_FALSE(view_
->has_composition_text_
);
811 // Checks that touch-event state is maintained correctly.
812 TEST_F(RenderWidgetHostViewAuraTest
, TouchEventState
) {
813 view_
->InitAsChild(NULL
);
816 // Start with no touch-event handler in the renderer.
817 widget_host_
->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, false));
818 EXPECT_FALSE(widget_host_
->ShouldForwardTouchEvent());
820 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
,
823 ui::EventTimeForNow());
824 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
,
827 ui::EventTimeForNow());
828 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
,
831 ui::EventTimeForNow());
833 view_
->OnTouchEvent(&press
);
834 EXPECT_FALSE(press
.handled());
835 EXPECT_EQ(blink::WebInputEvent::TouchStart
, view_
->touch_event_
.type
);
836 EXPECT_TRUE(view_
->touch_event_
.cancelable
);
837 EXPECT_EQ(1U, view_
->touch_event_
.touchesLength
);
838 EXPECT_EQ(blink::WebTouchPoint::StatePressed
,
839 view_
->touch_event_
.touches
[0].state
);
841 view_
->OnTouchEvent(&move
);
842 EXPECT_FALSE(move
.handled());
843 EXPECT_EQ(blink::WebInputEvent::TouchMove
, view_
->touch_event_
.type
);
844 EXPECT_TRUE(view_
->touch_event_
.cancelable
);
845 EXPECT_EQ(1U, view_
->touch_event_
.touchesLength
);
846 EXPECT_EQ(blink::WebTouchPoint::StateMoved
,
847 view_
->touch_event_
.touches
[0].state
);
849 view_
->OnTouchEvent(&release
);
850 EXPECT_FALSE(release
.handled());
851 EXPECT_EQ(blink::WebInputEvent::TouchEnd
, view_
->touch_event_
.type
);
852 EXPECT_TRUE(view_
->touch_event_
.cancelable
);
853 EXPECT_EQ(0U, view_
->touch_event_
.touchesLength
);
855 // Now install some touch-event handlers and do the same steps. The touch
856 // events should now be consumed. However, the touch-event state should be
857 // updated as before.
858 widget_host_
->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
859 EXPECT_TRUE(widget_host_
->ShouldForwardTouchEvent());
861 view_
->OnTouchEvent(&press
);
862 EXPECT_TRUE(press
.stopped_propagation());
863 EXPECT_EQ(blink::WebInputEvent::TouchStart
, view_
->touch_event_
.type
);
864 EXPECT_TRUE(view_
->touch_event_
.cancelable
);
865 EXPECT_EQ(1U, view_
->touch_event_
.touchesLength
);
866 EXPECT_EQ(blink::WebTouchPoint::StatePressed
,
867 view_
->touch_event_
.touches
[0].state
);
869 view_
->OnTouchEvent(&move
);
870 EXPECT_TRUE(move
.stopped_propagation());
871 EXPECT_EQ(blink::WebInputEvent::TouchMove
, view_
->touch_event_
.type
);
872 EXPECT_TRUE(view_
->touch_event_
.cancelable
);
873 EXPECT_EQ(1U, view_
->touch_event_
.touchesLength
);
874 EXPECT_EQ(blink::WebTouchPoint::StateMoved
,
875 view_
->touch_event_
.touches
[0].state
);
877 view_
->OnTouchEvent(&release
);
878 EXPECT_TRUE(release
.stopped_propagation());
879 EXPECT_EQ(blink::WebInputEvent::TouchEnd
, view_
->touch_event_
.type
);
880 EXPECT_TRUE(view_
->touch_event_
.cancelable
);
881 EXPECT_EQ(0U, view_
->touch_event_
.touchesLength
);
883 // Now start a touch event, and remove the event-handlers before the release.
884 view_
->OnTouchEvent(&press
);
885 EXPECT_TRUE(press
.stopped_propagation());
886 EXPECT_EQ(blink::WebInputEvent::TouchStart
, view_
->touch_event_
.type
);
887 EXPECT_EQ(1U, view_
->touch_event_
.touchesLength
);
888 EXPECT_EQ(blink::WebTouchPoint::StatePressed
,
889 view_
->touch_event_
.touches
[0].state
);
891 widget_host_
->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, false));
892 EXPECT_FALSE(widget_host_
->ShouldForwardTouchEvent());
894 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
, gfx::Point(20, 20), 0,
895 base::Time::NowFromSystemTime() - base::Time());
896 view_
->OnTouchEvent(&move2
);
897 EXPECT_FALSE(move2
.handled());
898 EXPECT_EQ(blink::WebInputEvent::TouchMove
, view_
->touch_event_
.type
);
899 EXPECT_EQ(1U, view_
->touch_event_
.touchesLength
);
900 EXPECT_EQ(blink::WebTouchPoint::StateMoved
,
901 view_
->touch_event_
.touches
[0].state
);
903 ui::TouchEvent
release2(ui::ET_TOUCH_RELEASED
, gfx::Point(20, 20), 0,
904 base::Time::NowFromSystemTime() - base::Time());
905 view_
->OnTouchEvent(&release2
);
906 EXPECT_FALSE(release2
.handled());
907 EXPECT_EQ(blink::WebInputEvent::TouchEnd
, view_
->touch_event_
.type
);
908 EXPECT_EQ(0U, view_
->touch_event_
.touchesLength
);
911 // Checks that touch-events are queued properly when there is a touch-event
912 // handler on the page.
913 TEST_F(RenderWidgetHostViewAuraTest
, TouchEventSyncAsync
) {
914 view_
->InitAsChild(NULL
);
917 widget_host_
->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
918 EXPECT_TRUE(widget_host_
->ShouldForwardTouchEvent());
920 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
,
923 ui::EventTimeForNow());
924 ui::TouchEvent
move(ui::ET_TOUCH_MOVED
,
927 ui::EventTimeForNow());
928 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
,
931 ui::EventTimeForNow());
933 view_
->OnTouchEvent(&press
);
934 EXPECT_TRUE(press
.stopped_propagation());
935 EXPECT_EQ(blink::WebInputEvent::TouchStart
, view_
->touch_event_
.type
);
936 EXPECT_EQ(1U, view_
->touch_event_
.touchesLength
);
937 EXPECT_EQ(blink::WebTouchPoint::StatePressed
,
938 view_
->touch_event_
.touches
[0].state
);
940 view_
->OnTouchEvent(&move
);
941 EXPECT_TRUE(move
.stopped_propagation());
942 EXPECT_EQ(blink::WebInputEvent::TouchMove
, view_
->touch_event_
.type
);
943 EXPECT_EQ(1U, view_
->touch_event_
.touchesLength
);
944 EXPECT_EQ(blink::WebTouchPoint::StateMoved
,
945 view_
->touch_event_
.touches
[0].state
);
947 // Send the same move event. Since the point hasn't moved, it won't affect the
948 // queue. However, the view should consume the event.
949 view_
->OnTouchEvent(&move
);
950 EXPECT_TRUE(move
.stopped_propagation());
951 EXPECT_EQ(blink::WebInputEvent::TouchMove
, view_
->touch_event_
.type
);
952 EXPECT_EQ(1U, view_
->touch_event_
.touchesLength
);
953 EXPECT_EQ(blink::WebTouchPoint::StateMoved
,
954 view_
->touch_event_
.touches
[0].state
);
956 view_
->OnTouchEvent(&release
);
957 EXPECT_TRUE(release
.stopped_propagation());
958 EXPECT_EQ(blink::WebInputEvent::TouchEnd
, view_
->touch_event_
.type
);
959 EXPECT_EQ(0U, view_
->touch_event_
.touchesLength
);
962 TEST_F(RenderWidgetHostViewAuraTest
, PhysicalBackingSizeWithScale
) {
963 view_
->InitAsChild(NULL
);
964 aura::client::ParentWindowWithContext(
965 view_
->GetNativeView(),
966 parent_view_
->GetNativeView()->GetRootWindow(),
968 sink_
->ClearMessages();
969 view_
->SetSize(gfx::Size(100, 100));
970 EXPECT_EQ("100x100", view_
->GetPhysicalBackingSize().ToString());
971 EXPECT_EQ(1u, sink_
->message_count());
972 EXPECT_EQ(ViewMsg_Resize::ID
, sink_
->GetMessageAt(0)->type());
974 const IPC::Message
* msg
= sink_
->GetMessageAt(0);
975 EXPECT_EQ(ViewMsg_Resize::ID
, msg
->type());
976 ViewMsg_Resize::Param params
;
977 ViewMsg_Resize::Read(msg
, ¶ms
);
978 EXPECT_EQ("100x100", params
.a
.new_size
.ToString()); // dip size
980 params
.a
.physical_backing_size
.ToString()); // backing size
983 widget_host_
->ResetSizeAndRepaintPendingFlags();
984 sink_
->ClearMessages();
986 aura_test_helper_
->test_screen()->SetDeviceScaleFactor(2.0f
);
987 EXPECT_EQ("200x200", view_
->GetPhysicalBackingSize().ToString());
988 // Extra ScreenInfoChanged message for |parent_view_|.
989 EXPECT_EQ(1u, sink_
->message_count());
991 const IPC::Message
* msg
= sink_
->GetMessageAt(0);
992 EXPECT_EQ(ViewMsg_Resize::ID
, msg
->type());
993 ViewMsg_Resize::Param params
;
994 ViewMsg_Resize::Read(msg
, ¶ms
);
995 EXPECT_EQ(2.0f
, params
.a
.screen_info
.deviceScaleFactor
);
996 EXPECT_EQ("100x100", params
.a
.new_size
.ToString()); // dip size
998 params
.a
.physical_backing_size
.ToString()); // backing size
1001 widget_host_
->ResetSizeAndRepaintPendingFlags();
1002 sink_
->ClearMessages();
1004 aura_test_helper_
->test_screen()->SetDeviceScaleFactor(1.0f
);
1005 // Extra ScreenInfoChanged message for |parent_view_|.
1006 EXPECT_EQ(1u, sink_
->message_count());
1007 EXPECT_EQ("100x100", view_
->GetPhysicalBackingSize().ToString());
1009 const IPC::Message
* msg
= sink_
->GetMessageAt(0);
1010 EXPECT_EQ(ViewMsg_Resize::ID
, msg
->type());
1011 ViewMsg_Resize::Param params
;
1012 ViewMsg_Resize::Read(msg
, ¶ms
);
1013 EXPECT_EQ(1.0f
, params
.a
.screen_info
.deviceScaleFactor
);
1014 EXPECT_EQ("100x100", params
.a
.new_size
.ToString()); // dip size
1015 EXPECT_EQ("100x100",
1016 params
.a
.physical_backing_size
.ToString()); // backing size
1020 // Checks that InputMsg_CursorVisibilityChange IPC messages are dispatched
1021 // to the renderer at the correct times.
1022 TEST_F(RenderWidgetHostViewAuraTest
, CursorVisibilityChange
) {
1023 view_
->InitAsChild(NULL
);
1024 aura::client::ParentWindowWithContext(
1025 view_
->GetNativeView(),
1026 parent_view_
->GetNativeView()->GetRootWindow(),
1028 view_
->SetSize(gfx::Size(100, 100));
1030 aura::test::TestCursorClient
cursor_client(
1031 parent_view_
->GetNativeView()->GetRootWindow());
1033 cursor_client
.AddObserver(view_
);
1035 // Expect a message the first time the cursor is shown.
1037 sink_
->ClearMessages();
1038 cursor_client
.ShowCursor();
1039 EXPECT_EQ(1u, sink_
->message_count());
1040 EXPECT_TRUE(sink_
->GetUniqueMessageMatching(
1041 InputMsg_CursorVisibilityChange::ID
));
1043 // No message expected if the renderer already knows the cursor is visible.
1044 sink_
->ClearMessages();
1045 cursor_client
.ShowCursor();
1046 EXPECT_EQ(0u, sink_
->message_count());
1048 // Hiding the cursor should send a message.
1049 sink_
->ClearMessages();
1050 cursor_client
.HideCursor();
1051 EXPECT_EQ(1u, sink_
->message_count());
1052 EXPECT_TRUE(sink_
->GetUniqueMessageMatching(
1053 InputMsg_CursorVisibilityChange::ID
));
1055 // No message expected if the renderer already knows the cursor is invisible.
1056 sink_
->ClearMessages();
1057 cursor_client
.HideCursor();
1058 EXPECT_EQ(0u, sink_
->message_count());
1060 // No messages should be sent while the view is invisible.
1062 sink_
->ClearMessages();
1063 cursor_client
.ShowCursor();
1064 EXPECT_EQ(0u, sink_
->message_count());
1065 cursor_client
.HideCursor();
1066 EXPECT_EQ(0u, sink_
->message_count());
1068 // Show the view. Since the cursor was invisible when the view was hidden,
1069 // no message should be sent.
1070 sink_
->ClearMessages();
1072 EXPECT_FALSE(sink_
->GetUniqueMessageMatching(
1073 InputMsg_CursorVisibilityChange::ID
));
1075 // No message expected if the renderer already knows the cursor is invisible.
1076 sink_
->ClearMessages();
1077 cursor_client
.HideCursor();
1078 EXPECT_EQ(0u, sink_
->message_count());
1080 // Showing the cursor should send a message.
1081 sink_
->ClearMessages();
1082 cursor_client
.ShowCursor();
1083 EXPECT_EQ(1u, sink_
->message_count());
1084 EXPECT_TRUE(sink_
->GetUniqueMessageMatching(
1085 InputMsg_CursorVisibilityChange::ID
));
1087 // No messages should be sent while the view is invisible.
1089 sink_
->ClearMessages();
1090 cursor_client
.HideCursor();
1091 EXPECT_EQ(0u, sink_
->message_count());
1093 // Show the view. Since the cursor was visible when the view was hidden,
1094 // a message is expected to be sent.
1095 sink_
->ClearMessages();
1097 EXPECT_TRUE(sink_
->GetUniqueMessageMatching(
1098 InputMsg_CursorVisibilityChange::ID
));
1100 cursor_client
.RemoveObserver(view_
);
1103 TEST_F(RenderWidgetHostViewAuraTest
, UpdateCursorIfOverSelf
) {
1104 view_
->InitAsChild(NULL
);
1105 aura::client::ParentWindowWithContext(
1106 view_
->GetNativeView(),
1107 parent_view_
->GetNativeView()->GetRootWindow(),
1110 // Note that all coordinates in this test are screen coordinates.
1111 view_
->SetBounds(gfx::Rect(60, 60, 100, 100));
1114 aura::test::TestCursorClient
cursor_client(
1115 parent_view_
->GetNativeView()->GetRootWindow());
1117 // Cursor is in the middle of the window.
1118 cursor_client
.reset_calls_to_set_cursor();
1119 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(110, 110));
1120 view_
->UpdateCursorIfOverSelf();
1121 EXPECT_EQ(1, cursor_client
.calls_to_set_cursor());
1123 // Cursor is near the top of the window.
1124 cursor_client
.reset_calls_to_set_cursor();
1125 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(80, 65));
1126 view_
->UpdateCursorIfOverSelf();
1127 EXPECT_EQ(1, cursor_client
.calls_to_set_cursor());
1129 // Cursor is near the bottom of the window.
1130 cursor_client
.reset_calls_to_set_cursor();
1131 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(159, 159));
1132 view_
->UpdateCursorIfOverSelf();
1133 EXPECT_EQ(1, cursor_client
.calls_to_set_cursor());
1135 // Cursor is above the window.
1136 cursor_client
.reset_calls_to_set_cursor();
1137 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(67, 59));
1138 view_
->UpdateCursorIfOverSelf();
1139 EXPECT_EQ(0, cursor_client
.calls_to_set_cursor());
1141 // Cursor is below the window.
1142 cursor_client
.reset_calls_to_set_cursor();
1143 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(161, 161));
1144 view_
->UpdateCursorIfOverSelf();
1145 EXPECT_EQ(0, cursor_client
.calls_to_set_cursor());
1148 scoped_ptr
<cc::CompositorFrame
> MakeDelegatedFrame(float scale_factor
,
1151 scoped_ptr
<cc::CompositorFrame
> frame(new cc::CompositorFrame
);
1152 frame
->metadata
.device_scale_factor
= scale_factor
;
1153 frame
->delegated_frame_data
.reset(new cc::DelegatedFrameData
);
1155 scoped_ptr
<cc::RenderPass
> pass
= cc::RenderPass::Create();
1157 cc::RenderPassId(1, 1), gfx::Rect(size
), damage
, gfx::Transform());
1158 frame
->delegated_frame_data
->render_pass_list
.push_back(pass
.Pass());
1159 return frame
.Pass();
1162 // Resizing in fullscreen mode should send the up-to-date screen info.
1163 // http://crbug.com/324350
1164 TEST_F(RenderWidgetHostViewAuraTest
, DISABLED_FullscreenResize
) {
1165 aura::Window
* root_window
= aura_test_helper_
->root_window();
1166 root_window
->SetLayoutManager(new FullscreenLayoutManager(root_window
));
1167 view_
->InitAsFullscreen(parent_view_
);
1169 widget_host_
->ResetSizeAndRepaintPendingFlags();
1170 sink_
->ClearMessages();
1172 // Call WasResized to flush the old screen info.
1173 view_
->GetRenderWidgetHost()->WasResized();
1175 // 0 is CreatingNew message.
1176 const IPC::Message
* msg
= sink_
->GetMessageAt(0);
1177 EXPECT_EQ(ViewMsg_Resize::ID
, msg
->type());
1178 ViewMsg_Resize::Param params
;
1179 ViewMsg_Resize::Read(msg
, ¶ms
);
1180 EXPECT_EQ("0,0 800x600",
1181 gfx::Rect(params
.a
.screen_info
.availableRect
).ToString());
1182 EXPECT_EQ("800x600", params
.a
.new_size
.ToString());
1183 // Resizes are blocked until we swapped a frame of the correct size, and
1184 // we've committed it.
1185 view_
->OnSwapCompositorFrame(
1188 1.f
, params
.a
.new_size
, gfx::Rect(params
.a
.new_size
)));
1189 ui::DrawWaiterForTest::WaitForCommit(
1190 root_window
->GetHost()->compositor());
1193 widget_host_
->ResetSizeAndRepaintPendingFlags();
1194 sink_
->ClearMessages();
1196 // Make sure the corrent screen size is set along in the resize
1197 // request when the screen size has changed.
1198 aura_test_helper_
->test_screen()->SetUIScale(0.5);
1199 EXPECT_EQ(1u, sink_
->message_count());
1201 const IPC::Message
* msg
= sink_
->GetMessageAt(0);
1202 EXPECT_EQ(ViewMsg_Resize::ID
, msg
->type());
1203 ViewMsg_Resize::Param params
;
1204 ViewMsg_Resize::Read(msg
, ¶ms
);
1205 EXPECT_EQ("0,0 1600x1200",
1206 gfx::Rect(params
.a
.screen_info
.availableRect
).ToString());
1207 EXPECT_EQ("1600x1200", params
.a
.new_size
.ToString());
1208 view_
->OnSwapCompositorFrame(
1211 1.f
, params
.a
.new_size
, gfx::Rect(params
.a
.new_size
)));
1212 ui::DrawWaiterForTest::WaitForCommit(
1213 root_window
->GetHost()->compositor());
1217 // Swapping a frame should notify the window.
1218 TEST_F(RenderWidgetHostViewAuraTest
, SwapNotifiesWindow
) {
1219 gfx::Size
view_size(100, 100);
1220 gfx::Rect
view_rect(view_size
);
1222 view_
->InitAsChild(NULL
);
1223 aura::client::ParentWindowWithContext(
1224 view_
->GetNativeView(),
1225 parent_view_
->GetNativeView()->GetRootWindow(),
1227 view_
->SetSize(view_size
);
1230 MockWindowObserver observer
;
1231 view_
->window_
->AddObserver(&observer
);
1233 // Delegated renderer path
1234 EXPECT_CALL(observer
, OnDelegatedFrameDamage(view_
->window_
, view_rect
));
1235 view_
->OnSwapCompositorFrame(
1236 0, MakeDelegatedFrame(1.f
, view_size
, view_rect
));
1237 testing::Mock::VerifyAndClearExpectations(&observer
);
1239 EXPECT_CALL(observer
, OnDelegatedFrameDamage(view_
->window_
,
1240 gfx::Rect(5, 5, 5, 5)));
1241 view_
->OnSwapCompositorFrame(
1242 0, MakeDelegatedFrame(1.f
, view_size
, gfx::Rect(5, 5, 5, 5)));
1243 testing::Mock::VerifyAndClearExpectations(&observer
);
1245 view_
->window_
->RemoveObserver(&observer
);
1248 TEST_F(RenderWidgetHostViewAuraTest
, Resize
) {
1249 gfx::Size
size1(100, 100);
1250 gfx::Size
size2(200, 200);
1251 gfx::Size
size3(300, 300);
1253 aura::Window
* root_window
= parent_view_
->GetNativeView()->GetRootWindow();
1254 view_
->InitAsChild(NULL
);
1255 aura::client::ParentWindowWithContext(
1256 view_
->GetNativeView(), root_window
, gfx::Rect(size1
));
1258 view_
->SetSize(size1
);
1259 view_
->OnSwapCompositorFrame(
1260 0, MakeDelegatedFrame(1.f
, size1
, gfx::Rect(size1
)));
1261 ui::DrawWaiterForTest::WaitForCommit(
1262 root_window
->GetHost()->compositor());
1263 ViewHostMsg_UpdateRect_Params update_params
;
1264 update_params
.view_size
= size1
;
1265 update_params
.scale_factor
= 1.f
;
1266 update_params
.flags
= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK
;
1267 widget_host_
->OnMessageReceived(
1268 ViewHostMsg_UpdateRect(widget_host_
->GetRoutingID(), update_params
));
1269 sink_
->ClearMessages();
1270 // Resize logic is idle (no pending resize, no pending commit).
1271 EXPECT_EQ(size1
.ToString(), view_
->GetRequestedRendererSize().ToString());
1273 // Resize renderer, should produce a Resize message
1274 view_
->SetSize(size2
);
1275 EXPECT_EQ(size2
.ToString(), view_
->GetRequestedRendererSize().ToString());
1276 EXPECT_EQ(1u, sink_
->message_count());
1278 const IPC::Message
* msg
= sink_
->GetMessageAt(0);
1279 EXPECT_EQ(ViewMsg_Resize::ID
, msg
->type());
1280 ViewMsg_Resize::Param params
;
1281 ViewMsg_Resize::Read(msg
, ¶ms
);
1282 EXPECT_EQ(size2
.ToString(), params
.a
.new_size
.ToString());
1284 // Send resize ack to observe new Resize messages.
1285 update_params
.view_size
= size2
;
1286 widget_host_
->OnMessageReceived(
1287 ViewHostMsg_UpdateRect(widget_host_
->GetRoutingID(), update_params
));
1288 sink_
->ClearMessages();
1290 // Resize renderer again, before receiving a frame. Should not produce a
1292 view_
->SetSize(size3
);
1293 EXPECT_EQ(size2
.ToString(), view_
->GetRequestedRendererSize().ToString());
1294 EXPECT_EQ(0u, sink_
->message_count());
1296 // Receive a frame of the new size, should be skipped and not produce a Resize
1298 view_
->OnSwapCompositorFrame(
1299 0, MakeDelegatedFrame(1.f
, size3
, gfx::Rect(size3
)));
1300 // Expect the frame ack;
1301 EXPECT_EQ(1u, sink_
->message_count());
1302 EXPECT_EQ(ViewMsg_SwapCompositorFrameAck::ID
, sink_
->GetMessageAt(0)->type());
1303 sink_
->ClearMessages();
1304 EXPECT_EQ(size2
.ToString(), view_
->GetRequestedRendererSize().ToString());
1306 // Receive a frame of the correct size, should not be skipped and, and should
1307 // produce a Resize message after the commit.
1308 view_
->OnSwapCompositorFrame(
1309 0, MakeDelegatedFrame(1.f
, size2
, gfx::Rect(size2
)));
1310 // No frame ack yet.
1311 EXPECT_EQ(0u, sink_
->message_count());
1312 EXPECT_EQ(size2
.ToString(), view_
->GetRequestedRendererSize().ToString());
1314 // Wait for commit, then we should unlock the compositor and send a Resize
1315 // message (and a frame ack)
1316 ui::DrawWaiterForTest::WaitForCommit(
1317 root_window
->GetHost()->compositor());
1318 EXPECT_EQ(size3
.ToString(), view_
->GetRequestedRendererSize().ToString());
1319 EXPECT_EQ(2u, sink_
->message_count());
1320 EXPECT_EQ(ViewMsg_SwapCompositorFrameAck::ID
, sink_
->GetMessageAt(0)->type());
1322 const IPC::Message
* msg
= sink_
->GetMessageAt(1);
1323 EXPECT_EQ(ViewMsg_Resize::ID
, msg
->type());
1324 ViewMsg_Resize::Param params
;
1325 ViewMsg_Resize::Read(msg
, ¶ms
);
1326 EXPECT_EQ(size3
.ToString(), params
.a
.new_size
.ToString());
1328 update_params
.view_size
= size3
;
1329 widget_host_
->OnMessageReceived(
1330 ViewHostMsg_UpdateRect(widget_host_
->GetRoutingID(), update_params
));
1331 sink_
->ClearMessages();
1334 // Skipped frames should not drop their damage.
1335 TEST_F(RenderWidgetHostViewAuraTest
, SkippedDelegatedFrames
) {
1336 gfx::Rect
view_rect(100, 100);
1337 gfx::Size frame_size
= view_rect
.size();
1339 view_
->InitAsChild(NULL
);
1340 aura::client::ParentWindowWithContext(
1341 view_
->GetNativeView(),
1342 parent_view_
->GetNativeView()->GetRootWindow(),
1344 view_
->SetSize(view_rect
.size());
1346 MockWindowObserver observer
;
1347 view_
->window_
->AddObserver(&observer
);
1349 // A full frame of damage.
1350 EXPECT_CALL(observer
, OnDelegatedFrameDamage(view_
->window_
, view_rect
));
1351 view_
->OnSwapCompositorFrame(
1352 0, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1353 testing::Mock::VerifyAndClearExpectations(&observer
);
1354 view_
->RunOnCompositingDidCommit();
1356 // A partial damage frame.
1357 gfx::Rect
partial_view_rect(30, 30, 20, 20);
1358 EXPECT_CALL(observer
,
1359 OnDelegatedFrameDamage(view_
->window_
, partial_view_rect
));
1360 view_
->OnSwapCompositorFrame(
1361 0, MakeDelegatedFrame(1.f
, frame_size
, partial_view_rect
));
1362 testing::Mock::VerifyAndClearExpectations(&observer
);
1363 view_
->RunOnCompositingDidCommit();
1365 // Lock the compositor. Now we should drop frames.
1366 view_rect
= gfx::Rect(150, 150);
1367 view_
->SetSize(view_rect
.size());
1369 // This frame is dropped.
1370 gfx::Rect
dropped_damage_rect_1(10, 20, 30, 40);
1371 EXPECT_CALL(observer
, OnDelegatedFrameDamage(_
, _
)).Times(0);
1372 view_
->OnSwapCompositorFrame(
1373 0, MakeDelegatedFrame(1.f
, frame_size
, dropped_damage_rect_1
));
1374 testing::Mock::VerifyAndClearExpectations(&observer
);
1375 view_
->RunOnCompositingDidCommit();
1377 gfx::Rect
dropped_damage_rect_2(40, 50, 10, 20);
1378 EXPECT_CALL(observer
, OnDelegatedFrameDamage(_
, _
)).Times(0);
1379 view_
->OnSwapCompositorFrame(
1380 0, MakeDelegatedFrame(1.f
, frame_size
, dropped_damage_rect_2
));
1381 testing::Mock::VerifyAndClearExpectations(&observer
);
1382 view_
->RunOnCompositingDidCommit();
1384 // Unlock the compositor. This frame should damage everything.
1385 frame_size
= view_rect
.size();
1387 gfx::Rect
new_damage_rect(5, 6, 10, 10);
1388 EXPECT_CALL(observer
,
1389 OnDelegatedFrameDamage(view_
->window_
, view_rect
));
1390 view_
->OnSwapCompositorFrame(
1391 0, MakeDelegatedFrame(1.f
, frame_size
, new_damage_rect
));
1392 testing::Mock::VerifyAndClearExpectations(&observer
);
1393 view_
->RunOnCompositingDidCommit();
1395 // A partial damage frame, this should not be dropped.
1396 EXPECT_CALL(observer
,
1397 OnDelegatedFrameDamage(view_
->window_
, partial_view_rect
));
1398 view_
->OnSwapCompositorFrame(
1399 0, MakeDelegatedFrame(1.f
, frame_size
, partial_view_rect
));
1400 testing::Mock::VerifyAndClearExpectations(&observer
);
1401 view_
->RunOnCompositingDidCommit();
1404 // Resize to something empty.
1405 view_rect
= gfx::Rect(100, 0);
1406 view_
->SetSize(view_rect
.size());
1408 // We're never expecting empty frames, resize to something non-empty.
1409 view_rect
= gfx::Rect(100, 100);
1410 view_
->SetSize(view_rect
.size());
1412 // This frame should not be dropped.
1413 EXPECT_CALL(observer
, OnDelegatedFrameDamage(view_
->window_
, view_rect
));
1414 view_
->OnSwapCompositorFrame(
1415 0, MakeDelegatedFrame(1.f
, view_rect
.size(), view_rect
));
1416 testing::Mock::VerifyAndClearExpectations(&observer
);
1417 view_
->RunOnCompositingDidCommit();
1419 view_
->window_
->RemoveObserver(&observer
);
1422 TEST_F(RenderWidgetHostViewAuraTest
, OutputSurfaceIdChange
) {
1423 gfx::Rect
view_rect(100, 100);
1424 gfx::Size frame_size
= view_rect
.size();
1426 view_
->InitAsChild(NULL
);
1427 aura::client::ParentWindowWithContext(
1428 view_
->GetNativeView(),
1429 parent_view_
->GetNativeView()->GetRootWindow(),
1431 view_
->SetSize(view_rect
.size());
1433 MockWindowObserver observer
;
1434 view_
->window_
->AddObserver(&observer
);
1437 EXPECT_CALL(observer
, OnDelegatedFrameDamage(view_
->window_
, view_rect
));
1438 view_
->OnSwapCompositorFrame(
1439 0, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1440 testing::Mock::VerifyAndClearExpectations(&observer
);
1441 view_
->RunOnCompositingDidCommit();
1443 // Swap a frame with a different surface id.
1444 EXPECT_CALL(observer
, OnDelegatedFrameDamage(view_
->window_
, view_rect
));
1445 view_
->OnSwapCompositorFrame(
1446 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1447 testing::Mock::VerifyAndClearExpectations(&observer
);
1448 view_
->RunOnCompositingDidCommit();
1450 // Swap an empty frame, with a different surface id.
1451 view_
->OnSwapCompositorFrame(
1452 2, MakeDelegatedFrame(1.f
, gfx::Size(), gfx::Rect()));
1453 testing::Mock::VerifyAndClearExpectations(&observer
);
1454 view_
->RunOnCompositingDidCommit();
1456 // Swap another frame, with a different surface id.
1457 EXPECT_CALL(observer
, OnDelegatedFrameDamage(view_
->window_
, view_rect
));
1458 view_
->OnSwapCompositorFrame(3,
1459 MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1460 testing::Mock::VerifyAndClearExpectations(&observer
);
1461 view_
->RunOnCompositingDidCommit();
1463 view_
->window_
->RemoveObserver(&observer
);
1466 TEST_F(RenderWidgetHostViewAuraTest
, DiscardDelegatedFrames
) {
1467 size_t max_renderer_frames
=
1468 RendererFrameManager::GetInstance()->max_number_of_saved_frames();
1469 ASSERT_LE(2u, max_renderer_frames
);
1470 size_t renderer_count
= max_renderer_frames
+ 1;
1471 gfx::Rect
view_rect(100, 100);
1472 gfx::Size frame_size
= view_rect
.size();
1473 DCHECK_EQ(0u, HostSharedBitmapManager::current()->AllocatedBitmapCount());
1475 scoped_ptr
<RenderWidgetHostImpl
* []> hosts(
1476 new RenderWidgetHostImpl
* [renderer_count
]);
1477 scoped_ptr
<FakeRenderWidgetHostViewAura
* []> views(
1478 new FakeRenderWidgetHostViewAura
* [renderer_count
]);
1480 // Create a bunch of renderers.
1481 for (size_t i
= 0; i
< renderer_count
; ++i
) {
1482 hosts
[i
] = new RenderWidgetHostImpl(
1483 &delegate_
, process_host_
, MSG_ROUTING_NONE
, false);
1485 views
[i
] = new FakeRenderWidgetHostViewAura(hosts
[i
]);
1486 views
[i
]->InitAsChild(NULL
);
1487 aura::client::ParentWindowWithContext(
1488 views
[i
]->GetNativeView(),
1489 parent_view_
->GetNativeView()->GetRootWindow(),
1491 views
[i
]->SetSize(view_rect
.size());
1494 // Make each renderer visible, and swap a frame on it, then make it invisible.
1495 for (size_t i
= 0; i
< renderer_count
; ++i
) {
1496 views
[i
]->WasShown();
1497 views
[i
]->OnSwapCompositorFrame(
1498 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1499 EXPECT_TRUE(views
[i
]->frame_provider());
1500 views
[i
]->WasHidden();
1503 // There should be max_renderer_frames with a frame in it, and one without it.
1504 // Since the logic is LRU eviction, the first one should be without.
1505 EXPECT_FALSE(views
[0]->frame_provider());
1506 for (size_t i
= 1; i
< renderer_count
; ++i
)
1507 EXPECT_TRUE(views
[i
]->frame_provider());
1509 // LRU renderer is [0], make it visible, it shouldn't evict anything yet.
1510 views
[0]->WasShown();
1511 EXPECT_FALSE(views
[0]->frame_provider());
1512 EXPECT_TRUE(views
[1]->frame_provider());
1513 // Since [0] doesn't have a frame, it should be waiting for the renderer to
1515 EXPECT_TRUE(views
[0]->released_front_lock_active());
1517 // Swap a frame on it, it should evict the next LRU [1].
1518 views
[0]->OnSwapCompositorFrame(
1519 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1520 EXPECT_TRUE(views
[0]->frame_provider());
1521 EXPECT_FALSE(views
[1]->frame_provider());
1522 // Now that [0] got a frame, it shouldn't be waiting any more.
1523 EXPECT_FALSE(views
[0]->released_front_lock_active());
1524 views
[0]->WasHidden();
1526 // LRU renderer is [1], still hidden. Swap a frame on it, it should evict
1527 // the next LRU [2].
1528 views
[1]->OnSwapCompositorFrame(
1529 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1530 EXPECT_TRUE(views
[0]->frame_provider());
1531 EXPECT_TRUE(views
[1]->frame_provider());
1532 EXPECT_FALSE(views
[2]->frame_provider());
1533 for (size_t i
= 3; i
< renderer_count
; ++i
)
1534 EXPECT_TRUE(views
[i
]->frame_provider());
1536 // Make all renderers but [0] visible and swap a frame on them, keep [0]
1537 // hidden, it becomes the LRU.
1538 for (size_t i
= 1; i
< renderer_count
; ++i
) {
1539 views
[i
]->WasShown();
1540 // The renderers who don't have a frame should be waiting. The ones that
1541 // have a frame should not.
1542 // In practice, [1] has a frame, but anything after has its frame evicted.
1543 EXPECT_EQ(!views
[i
]->frame_provider(),
1544 views
[i
]->released_front_lock_active());
1545 views
[i
]->OnSwapCompositorFrame(
1546 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1547 // Now everyone has a frame.
1548 EXPECT_FALSE(views
[i
]->released_front_lock_active());
1549 EXPECT_TRUE(views
[i
]->frame_provider());
1551 EXPECT_FALSE(views
[0]->frame_provider());
1553 // Swap a frame on [0], it should be evicted immediately.
1554 views
[0]->OnSwapCompositorFrame(
1555 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1556 EXPECT_FALSE(views
[0]->frame_provider());
1558 // Make [0] visible, and swap a frame on it. Nothing should be evicted
1559 // although we're above the limit.
1560 views
[0]->WasShown();
1561 // We don't have a frame, wait.
1562 EXPECT_TRUE(views
[0]->released_front_lock_active());
1563 views
[0]->OnSwapCompositorFrame(
1564 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1565 EXPECT_FALSE(views
[0]->released_front_lock_active());
1566 for (size_t i
= 0; i
< renderer_count
; ++i
)
1567 EXPECT_TRUE(views
[i
]->frame_provider());
1569 // Make [0] hidden, it should evict its frame.
1570 views
[0]->WasHidden();
1571 EXPECT_FALSE(views
[0]->frame_provider());
1573 // Make [0] visible, don't give it a frame, it should be waiting.
1574 views
[0]->WasShown();
1575 EXPECT_TRUE(views
[0]->released_front_lock_active());
1576 // Make [0] hidden, it should stop waiting.
1577 views
[0]->WasHidden();
1578 EXPECT_FALSE(views
[0]->released_front_lock_active());
1580 // Make [1] hidden, resize it. It should drop its frame.
1581 views
[1]->WasHidden();
1582 EXPECT_TRUE(views
[1]->frame_provider());
1583 gfx::Size
size2(200, 200);
1584 views
[1]->SetSize(size2
);
1585 EXPECT_FALSE(views
[1]->frame_provider());
1586 // Show it, it should block until we give it a frame.
1587 views
[1]->WasShown();
1588 EXPECT_TRUE(views
[1]->released_front_lock_active());
1589 views
[1]->OnSwapCompositorFrame(
1590 1, MakeDelegatedFrame(1.f
, size2
, gfx::Rect(size2
)));
1591 EXPECT_FALSE(views
[1]->released_front_lock_active());
1593 for (size_t i
= 0; i
< renderer_count
- 1; ++i
)
1594 views
[i
]->WasHidden();
1596 // Allocate enough bitmaps so that two frames (proportionally) would be
1597 // enough hit the handle limit.
1598 int handles_per_frame
= 5;
1599 RendererFrameManager::GetInstance()->set_max_handles(handles_per_frame
* 2);
1601 for (size_t i
= 0; i
< (renderer_count
- 1) * handles_per_frame
; i
++) {
1602 HostSharedBitmapManager::current()->ChildAllocatedSharedBitmap(
1604 base::SharedMemory::NULLHandle(),
1605 base::GetCurrentProcessHandle(),
1606 cc::SharedBitmap::GenerateId());
1609 // Hiding this last bitmap should evict all but two frames.
1610 views
[renderer_count
- 1]->WasHidden();
1611 for (size_t i
= 0; i
< renderer_count
; ++i
) {
1612 if (i
+ 2 < renderer_count
)
1613 EXPECT_FALSE(views
[i
]->frame_provider());
1615 EXPECT_TRUE(views
[i
]->frame_provider());
1617 HostSharedBitmapManager::current()->ProcessRemoved(
1618 base::GetCurrentProcessHandle());
1619 RendererFrameManager::GetInstance()->set_max_handles(
1620 base::SharedMemory::GetHandleLimit());
1622 for (size_t i
= 0; i
< renderer_count
; ++i
) {
1623 views
[i
]->Destroy();
1628 TEST_F(RenderWidgetHostViewAuraTest
, DiscardDelegatedFramesWithLocking
) {
1629 size_t max_renderer_frames
=
1630 RendererFrameManager::GetInstance()->max_number_of_saved_frames();
1631 ASSERT_LE(2u, max_renderer_frames
);
1632 size_t renderer_count
= max_renderer_frames
+ 1;
1633 gfx::Rect
view_rect(100, 100);
1634 gfx::Size frame_size
= view_rect
.size();
1635 DCHECK_EQ(0u, HostSharedBitmapManager::current()->AllocatedBitmapCount());
1637 scoped_ptr
<RenderWidgetHostImpl
* []> hosts(
1638 new RenderWidgetHostImpl
* [renderer_count
]);
1639 scoped_ptr
<FakeRenderWidgetHostViewAura
* []> views(
1640 new FakeRenderWidgetHostViewAura
* [renderer_count
]);
1642 // Create a bunch of renderers.
1643 for (size_t i
= 0; i
< renderer_count
; ++i
) {
1644 hosts
[i
] = new RenderWidgetHostImpl(
1645 &delegate_
, process_host_
, MSG_ROUTING_NONE
, false);
1647 views
[i
] = new FakeRenderWidgetHostViewAura(hosts
[i
]);
1648 views
[i
]->InitAsChild(NULL
);
1649 aura::client::ParentWindowWithContext(
1650 views
[i
]->GetNativeView(),
1651 parent_view_
->GetNativeView()->GetRootWindow(),
1653 views
[i
]->SetSize(view_rect
.size());
1656 // Make each renderer visible and swap a frame on it. No eviction should
1657 // occur because all frames are visible.
1658 for (size_t i
= 0; i
< renderer_count
; ++i
) {
1659 views
[i
]->WasShown();
1660 views
[i
]->OnSwapCompositorFrame(
1661 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1662 EXPECT_TRUE(views
[i
]->frame_provider());
1665 // If we hide [0], then [0] should be evicted.
1666 views
[0]->WasHidden();
1667 EXPECT_FALSE(views
[0]->frame_provider());
1669 // If we lock [0] before hiding it, then [0] should not be evicted.
1670 views
[0]->WasShown();
1671 views
[0]->OnSwapCompositorFrame(
1672 1, MakeDelegatedFrame(1.f
, frame_size
, view_rect
));
1673 EXPECT_TRUE(views
[0]->frame_provider());
1674 views
[0]->GetDelegatedFrameHost()->LockResources();
1675 views
[0]->WasHidden();
1676 EXPECT_TRUE(views
[0]->frame_provider());
1678 // If we unlock [0] now, then [0] should be evicted.
1679 views
[0]->GetDelegatedFrameHost()->UnlockResources();
1680 EXPECT_FALSE(views
[0]->frame_provider());
1682 for (size_t i
= 0; i
< renderer_count
; ++i
) {
1683 views
[i
]->Destroy();
1688 TEST_F(RenderWidgetHostViewAuraTest
, SoftwareDPIChange
) {
1689 gfx::Rect
view_rect(100, 100);
1690 gfx::Size
frame_size(100, 100);
1692 view_
->InitAsChild(NULL
);
1693 aura::client::ParentWindowWithContext(
1694 view_
->GetNativeView(),
1695 parent_view_
->GetNativeView()->GetRootWindow(),
1697 view_
->SetSize(view_rect
.size());
1700 // With a 1x DPI UI and 1x DPI Renderer.
1701 view_
->OnSwapCompositorFrame(
1702 1, MakeDelegatedFrame(1.f
, frame_size
, gfx::Rect(frame_size
)));
1704 // Save the frame provider.
1705 scoped_refptr
<cc::DelegatedFrameProvider
> frame_provider
=
1706 view_
->frame_provider();
1708 // This frame will have the same number of physical pixels, but has a new
1710 view_
->OnSwapCompositorFrame(
1711 1, MakeDelegatedFrame(2.f
, frame_size
, gfx::Rect(frame_size
)));
1713 // When we get a new frame with the same frame size in physical pixels, but a
1714 // different scale, we should generate a new frame provider, as the final
1715 // result will need to be scaled differently to the screen.
1716 EXPECT_NE(frame_provider
.get(), view_
->frame_provider());
1719 class RenderWidgetHostViewAuraCopyRequestTest
1720 : public RenderWidgetHostViewAuraShutdownTest
{
1722 RenderWidgetHostViewAuraCopyRequestTest()
1723 : callback_count_(0), result_(false) {}
1725 void CallbackMethod(const base::Closure
& quit_closure
, bool result
) {
1731 int callback_count_
;
1735 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraCopyRequestTest
);
1738 TEST_F(RenderWidgetHostViewAuraCopyRequestTest
, DestroyedAfterCopyRequest
) {
1739 base::RunLoop run_loop
;
1741 gfx::Rect
view_rect(100, 100);
1742 scoped_ptr
<cc::CopyOutputRequest
> request
;
1744 view_
->InitAsChild(NULL
);
1745 aura::client::ParentWindowWithContext(
1746 view_
->GetNativeView(),
1747 parent_view_
->GetNativeView()->GetRootWindow(),
1749 view_
->SetSize(view_rect
.size());
1752 scoped_ptr
<FakeFrameSubscriber
> frame_subscriber(new FakeFrameSubscriber(
1754 base::Bind(&RenderWidgetHostViewAuraCopyRequestTest::CallbackMethod
,
1755 base::Unretained(this),
1756 run_loop
.QuitClosure())));
1758 EXPECT_EQ(0, callback_count_
);
1759 EXPECT_FALSE(view_
->last_copy_request_
);
1761 view_
->BeginFrameSubscription(
1762 frame_subscriber
.PassAs
<RenderWidgetHostViewFrameSubscriber
>());
1763 view_
->OnSwapCompositorFrame(
1764 1, MakeDelegatedFrame(1.f
, view_rect
.size(), gfx::Rect(view_rect
)));
1766 EXPECT_EQ(0, callback_count_
);
1767 EXPECT_TRUE(view_
->last_copy_request_
);
1768 EXPECT_TRUE(view_
->last_copy_request_
->has_texture_mailbox());
1769 request
= view_
->last_copy_request_
.Pass();
1771 // Send back the mailbox included in the request. There's no release callback
1772 // since the mailbox came from the RWHVA originally.
1773 request
->SendTextureResult(view_rect
.size(),
1774 request
->texture_mailbox(),
1775 scoped_ptr
<cc::SingleReleaseCallback
>());
1777 // This runs until the callback happens.
1780 // The callback should succeed.
1781 EXPECT_EQ(1, callback_count_
);
1782 EXPECT_TRUE(result_
);
1784 view_
->OnSwapCompositorFrame(
1785 1, MakeDelegatedFrame(1.f
, view_rect
.size(), gfx::Rect(view_rect
)));
1787 EXPECT_EQ(1, callback_count_
);
1788 request
= view_
->last_copy_request_
.Pass();
1790 // Destroy the RenderWidgetHostViewAura and ImageTransportFactory.
1791 TearDownEnvironment();
1793 // Send back the mailbox included in the request. There's no release callback
1794 // since the mailbox came from the RWHVA originally.
1795 request
->SendTextureResult(view_rect
.size(),
1796 request
->texture_mailbox(),
1797 scoped_ptr
<cc::SingleReleaseCallback
>());
1799 // Because the copy request callback may be holding state within it, that
1800 // state must handle the RWHVA and ImageTransportFactory going away before the
1801 // callback is called. This test passes if it does not crash as a result of
1802 // these things being destroyed.
1803 EXPECT_EQ(2, callback_count_
);
1804 EXPECT_FALSE(result_
);
1807 TEST_F(RenderWidgetHostViewAuraTest
, VisibleViewportTest
) {
1808 gfx::Rect
view_rect(100, 100);
1810 view_
->InitAsChild(NULL
);
1811 aura::client::ParentWindowWithContext(
1812 view_
->GetNativeView(),
1813 parent_view_
->GetNativeView()->GetRootWindow(),
1815 view_
->SetSize(view_rect
.size());
1818 // Defaults to full height of the view.
1819 EXPECT_EQ(100, view_
->GetVisibleViewportSize().height());
1821 widget_host_
->ResetSizeAndRepaintPendingFlags();
1822 sink_
->ClearMessages();
1823 view_
->SetInsets(gfx::Insets(0, 0, 40, 0));
1825 EXPECT_EQ(60, view_
->GetVisibleViewportSize().height());
1827 const IPC::Message
*message
= sink_
->GetFirstMessageMatching(
1828 ViewMsg_Resize::ID
);
1829 ASSERT_TRUE(message
!= NULL
);
1831 ViewMsg_Resize::Param params
;
1832 ViewMsg_Resize::Read(message
, ¶ms
);
1833 EXPECT_EQ(60, params
.a
.visible_viewport_size
.height());
1836 // Ensures that touch event positions are never truncated to integers.
1837 TEST_F(RenderWidgetHostViewAuraTest
, TouchEventPositionsArentRounded
) {
1838 const float kX
= 30.58f
;
1839 const float kY
= 50.23f
;
1841 view_
->InitAsChild(NULL
);
1844 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
,
1845 gfx::PointF(kX
, kY
),
1847 ui::EventTimeForNow());
1849 view_
->OnTouchEvent(&press
);
1850 EXPECT_EQ(blink::WebInputEvent::TouchStart
, view_
->touch_event_
.type
);
1851 EXPECT_TRUE(view_
->touch_event_
.cancelable
);
1852 EXPECT_EQ(1U, view_
->touch_event_
.touchesLength
);
1853 EXPECT_EQ(blink::WebTouchPoint::StatePressed
,
1854 view_
->touch_event_
.touches
[0].state
);
1855 EXPECT_EQ(kX
, view_
->touch_event_
.touches
[0].screenPosition
.x
);
1856 EXPECT_EQ(kX
, view_
->touch_event_
.touches
[0].position
.x
);
1857 EXPECT_EQ(kY
, view_
->touch_event_
.touches
[0].screenPosition
.y
);
1858 EXPECT_EQ(kY
, view_
->touch_event_
.touches
[0].position
.y
);
1861 // Tests that scroll ACKs are correctly handled by the overscroll-navigation
1863 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, WheelScrollEventOverscrolls
) {
1864 SetUpOverscrollEnvironment();
1866 // Simulate wheel events.
1867 SimulateWheelEvent(-5, 0, 0, true); // sent directly
1868 SimulateWheelEvent(-1, 1, 0, true); // enqueued
1869 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
1870 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
1871 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
1872 SimulateWheelEvent(-20, 6, 1, true); // enqueued, different modifiers
1873 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
1874 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1876 // Receive ACK the first wheel event as not processed.
1877 SendInputEventACK(WebInputEvent::MouseWheel
,
1878 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1879 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
1880 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
1881 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1883 // Receive ACK for the second (coalesced) event as not processed. This will
1884 // start a back navigation. However, this will also cause the queued next
1885 // event to be sent to the renderer. But since overscroll navigation has
1886 // started, that event will also be included in the overscroll computation
1887 // instead of being sent to the renderer. So the result will be an overscroll
1888 // back navigation, and no event will be sent to the renderer.
1889 SendInputEventACK(WebInputEvent::MouseWheel
,
1890 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1891 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_mode());
1892 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_delegate()->current_mode());
1893 EXPECT_EQ(-81.f
, overscroll_delta_x());
1894 EXPECT_EQ(-31.f
, overscroll_delegate()->delta_x());
1895 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
1896 EXPECT_EQ(0U, sink_
->message_count());
1898 // Send a mouse-move event. This should cancel the overscroll navigation.
1899 SimulateMouseMove(5, 10, 0);
1900 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
1901 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
1902 EXPECT_EQ(1U, sink_
->message_count());
1905 // Tests that if some scroll events are consumed towards the start, then
1906 // subsequent scrolls do not horizontal overscroll.
1907 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
1908 WheelScrollConsumedDoNotHorizOverscroll
) {
1909 SetUpOverscrollEnvironment();
1911 // Simulate wheel events.
1912 SimulateWheelEvent(-5, 0, 0, true); // sent directly
1913 SimulateWheelEvent(-1, -1, 0, true); // enqueued
1914 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
1915 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
1916 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
1917 SimulateWheelEvent(-20, 6, 1, true); // enqueued, different modifiers
1918 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
1919 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1921 // Receive ACK the first wheel event as processed.
1922 SendInputEventACK(WebInputEvent::MouseWheel
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1923 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
1924 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
1925 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1927 // Receive ACK for the second (coalesced) event as not processed. This should
1928 // not initiate overscroll, since the beginning of the scroll has been
1929 // consumed. The queued event with different modifiers should be sent to the
1931 SendInputEventACK(WebInputEvent::MouseWheel
,
1932 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1933 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
1934 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1936 SendInputEventACK(WebInputEvent::MouseWheel
,
1937 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1938 EXPECT_EQ(0U, sink_
->message_count());
1939 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
1941 // Indicate the end of the scrolling from the touchpad.
1942 SimulateGestureFlingStartEvent(-1200.f
, 0.f
, blink::WebGestureDeviceTouchpad
);
1943 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1945 // Start another scroll. This time, do not consume any scroll events.
1946 SimulateWheelEvent(0, -5, 0, true); // sent directly
1947 SimulateWheelEvent(0, -1, 0, true); // enqueued
1948 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
1949 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
1950 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
1951 SimulateWheelEvent(-20, 6, 1, true); // enqueued, different modifiers
1952 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
1953 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1955 // Receive ACK for the first wheel and the subsequent coalesced event as not
1956 // processed. This should start a back-overscroll.
1957 SendInputEventACK(WebInputEvent::MouseWheel
,
1958 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1959 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
1960 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
1961 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1962 SendInputEventACK(WebInputEvent::MouseWheel
,
1963 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1964 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_mode());
1967 // Tests that wheel-scrolling correctly turns overscroll on and off.
1968 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, WheelScrollOverscrollToggle
) {
1969 SetUpOverscrollEnvironment();
1971 // Send a wheel event. ACK the event as not processed. This should not
1972 // initiate an overscroll gesture since it doesn't cross the threshold yet.
1973 SimulateWheelEvent(10, 0, 0, true);
1974 SendInputEventACK(WebInputEvent::MouseWheel
,
1975 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1976 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
1977 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
1978 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1980 // Scroll some more so as to not overscroll.
1981 SimulateWheelEvent(10, 0, 0, true);
1982 SendInputEventACK(WebInputEvent::MouseWheel
,
1983 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1984 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
1985 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
1986 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1988 // Scroll some more to initiate an overscroll.
1989 SimulateWheelEvent(40, 0, 0, true);
1990 SendInputEventACK(WebInputEvent::MouseWheel
,
1991 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1992 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
1993 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
1994 EXPECT_EQ(60.f
, overscroll_delta_x());
1995 EXPECT_EQ(10.f
, overscroll_delegate()->delta_x());
1996 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
1997 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1999 // Scroll in the reverse direction enough to abort the overscroll.
2000 SimulateWheelEvent(-20, 0, 0, true);
2001 EXPECT_EQ(0U, sink_
->message_count());
2002 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2003 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2005 // Continue to scroll in the reverse direction.
2006 SimulateWheelEvent(-20, 0, 0, true);
2007 SendInputEventACK(WebInputEvent::MouseWheel
,
2008 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2009 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2010 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2011 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2013 // Continue to scroll in the reverse direction enough to initiate overscroll
2014 // in that direction.
2015 SimulateWheelEvent(-55, 0, 0, true);
2016 EXPECT_EQ(1U, sink_
->message_count());
2017 SendInputEventACK(WebInputEvent::MouseWheel
,
2018 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2019 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_mode());
2020 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_delegate()->current_mode());
2021 EXPECT_EQ(-75.f
, overscroll_delta_x());
2022 EXPECT_EQ(-25.f
, overscroll_delegate()->delta_x());
2023 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2026 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
2027 ScrollEventsOverscrollWithFling
) {
2028 SetUpOverscrollEnvironment();
2030 // Send a wheel event. ACK the event as not processed. This should not
2031 // initiate an overscroll gesture since it doesn't cross the threshold yet.
2032 SimulateWheelEvent(10, 0, 0, true);
2033 SendInputEventACK(WebInputEvent::MouseWheel
,
2034 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2035 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2036 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2037 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2039 // Scroll some more so as to not overscroll.
2040 SimulateWheelEvent(20, 0, 0, true);
2041 EXPECT_EQ(1U, sink_
->message_count());
2042 SendInputEventACK(WebInputEvent::MouseWheel
,
2043 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2044 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2045 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2046 sink_
->ClearMessages();
2048 // Scroll some more to initiate an overscroll.
2049 SimulateWheelEvent(30, 0, 0, true);
2050 SendInputEventACK(WebInputEvent::MouseWheel
,
2051 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2052 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2053 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2054 EXPECT_EQ(60.f
, overscroll_delta_x());
2055 EXPECT_EQ(10.f
, overscroll_delegate()->delta_x());
2056 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2057 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2059 // Send a fling start, but with a small velocity, so that the overscroll is
2060 // aborted. The fling should proceed to the renderer, through the gesture
2062 SimulateGestureFlingStartEvent(0.f
, 0.1f
, blink::WebGestureDeviceTouchpad
);
2063 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2064 EXPECT_EQ(1U, sink_
->message_count());
2067 // Same as ScrollEventsOverscrollWithFling, but with zero velocity. Checks that
2068 // the zero-velocity fling does not reach the renderer.
2069 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
2070 ScrollEventsOverscrollWithZeroFling
) {
2071 SetUpOverscrollEnvironment();
2073 // Send a wheel event. ACK the event as not processed. This should not
2074 // initiate an overscroll gesture since it doesn't cross the threshold yet.
2075 SimulateWheelEvent(10, 0, 0, true);
2076 SendInputEventACK(WebInputEvent::MouseWheel
,
2077 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2078 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2079 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2080 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2082 // Scroll some more so as to not overscroll.
2083 SimulateWheelEvent(20, 0, 0, true);
2084 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2085 SendInputEventACK(WebInputEvent::MouseWheel
,
2086 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2087 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2088 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2090 // Scroll some more to initiate an overscroll.
2091 SimulateWheelEvent(30, 0, 0, true);
2092 SendInputEventACK(WebInputEvent::MouseWheel
,
2093 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2094 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2095 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2096 EXPECT_EQ(60.f
, overscroll_delta_x());
2097 EXPECT_EQ(10.f
, overscroll_delegate()->delta_x());
2098 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2099 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2101 // Send a fling start, but with a small velocity, so that the overscroll is
2102 // aborted. The fling should proceed to the renderer, through the gesture
2104 SimulateGestureFlingStartEvent(10.f
, 0.f
, blink::WebGestureDeviceTouchpad
);
2105 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2106 EXPECT_EQ(1U, sink_
->message_count());
2109 // Tests that a fling in the opposite direction of the overscroll cancels the
2110 // overscroll nav instead of completing it.
2111 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, ReverseFlingCancelsOverscroll
) {
2112 SetUpOverscrollEnvironment();
2115 // Start and end a gesture in the same direction without processing the
2116 // gesture events in the renderer. This should initiate and complete an
2117 // overscroll navigation.
2118 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2119 blink::WebGestureDeviceTouchscreen
);
2120 SimulateGestureScrollUpdateEvent(300, -5, 0);
2121 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2122 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2123 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2124 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2125 sink_
->ClearMessages();
2127 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
2128 blink::WebGestureDeviceTouchscreen
);
2129 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->completed_mode());
2130 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2131 EXPECT_EQ(1U, sink_
->message_count());
2135 // Start over, except instead of ending the gesture with ScrollEnd, end it
2136 // with a FlingStart, with velocity in the reverse direction. This should
2137 // initiate an overscroll navigation, but it should be cancelled because of
2138 // the fling in the opposite direction.
2139 overscroll_delegate()->Reset();
2140 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2141 blink::WebGestureDeviceTouchscreen
);
2142 SimulateGestureScrollUpdateEvent(-300, -5, 0);
2143 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2144 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2145 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_mode());
2146 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_delegate()->current_mode());
2147 sink_
->ClearMessages();
2149 SimulateGestureFlingStartEvent(100, 0, blink::WebGestureDeviceTouchscreen
);
2150 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->completed_mode());
2151 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2152 EXPECT_EQ(1U, sink_
->message_count());
2156 // Tests that touch-scroll events are handled correctly by the overscroll
2157 // controller. This also tests that the overscroll controller and the
2158 // gesture-event filter play nice with each other.
2159 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, GestureScrollOverscrolls
) {
2160 SetUpOverscrollEnvironment();
2162 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2163 blink::WebGestureDeviceTouchscreen
);
2164 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2165 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2166 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2168 // Send another gesture event and ACK as not being processed. This should
2169 // initiate the navigation gesture.
2170 SimulateGestureScrollUpdateEvent(55, -5, 0);
2171 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2172 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2173 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2174 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2175 EXPECT_EQ(55.f
, overscroll_delta_x());
2176 EXPECT_EQ(-5.f
, overscroll_delta_y());
2177 EXPECT_EQ(5.f
, overscroll_delegate()->delta_x());
2178 EXPECT_EQ(-5.f
, overscroll_delegate()->delta_y());
2179 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2181 // Send another gesture update event. This event should be consumed by the
2182 // controller, and not be forwarded to the renderer. The gesture-event filter
2183 // should not also receive this event.
2184 SimulateGestureScrollUpdateEvent(10, -5, 0);
2185 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2186 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2187 EXPECT_EQ(65.f
, overscroll_delta_x());
2188 EXPECT_EQ(-10.f
, overscroll_delta_y());
2189 EXPECT_EQ(15.f
, overscroll_delegate()->delta_x());
2190 EXPECT_EQ(-10.f
, overscroll_delegate()->delta_y());
2191 EXPECT_EQ(0U, sink_
->message_count());
2193 // Now send a scroll end. This should cancel the overscroll gesture, and send
2194 // the event to the renderer. The gesture-event filter should receive this
2196 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
2197 blink::WebGestureDeviceTouchscreen
);
2198 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2199 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2200 EXPECT_EQ(1U, sink_
->message_count());
2203 // Tests that if the page is scrolled because of a scroll-gesture, then that
2204 // particular scroll sequence never generates overscroll if the scroll direction
2206 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
2207 GestureScrollConsumedHorizontal
) {
2208 SetUpOverscrollEnvironment();
2210 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2211 blink::WebGestureDeviceTouchscreen
);
2212 SimulateGestureScrollUpdateEvent(10, 0, 0);
2214 // Start scrolling on content. ACK both events as being processed.
2215 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2216 INPUT_EVENT_ACK_STATE_CONSUMED
);
2217 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2218 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2219 sink_
->ClearMessages();
2221 // Send another gesture event and ACK as not being processed. This should
2222 // not initiate overscroll because the beginning of the scroll event did
2223 // scroll some content on the page. Since there was no overscroll, the event
2224 // should reach the renderer.
2225 SimulateGestureScrollUpdateEvent(55, 0, 0);
2226 EXPECT_EQ(1U, sink_
->message_count());
2227 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2228 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2229 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2232 // Tests that the overscroll controller plays nice with touch-scrolls and the
2233 // gesture event filter with debounce filtering turned on.
2234 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
2235 GestureScrollDebounceOverscrolls
) {
2236 SetUpOverscrollEnvironmentWithDebounce(100);
2238 // Start scrolling. Receive ACK as it being processed.
2239 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2240 blink::WebGestureDeviceTouchscreen
);
2241 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2243 // Send update events.
2244 SimulateGestureScrollUpdateEvent(25, 0, 0);
2245 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2247 // Quickly end and restart the scroll gesture. These two events should get
2249 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
2250 blink::WebGestureDeviceTouchscreen
);
2251 EXPECT_EQ(0U, sink_
->message_count());
2253 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2254 blink::WebGestureDeviceTouchscreen
);
2255 EXPECT_EQ(0U, sink_
->message_count());
2257 // Send another update event. This should get into the queue.
2258 SimulateGestureScrollUpdateEvent(30, 0, 0);
2259 EXPECT_EQ(0U, sink_
->message_count());
2261 // Receive an ACK for the first scroll-update event as not being processed.
2262 // This will contribute to the overscroll gesture, but not enough for the
2263 // overscroll controller to start consuming gesture events. This also cause
2264 // the queued gesture event to be forwarded to the renderer.
2265 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2266 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2267 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2268 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2269 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2271 // Send another update event. This should get into the queue.
2272 SimulateGestureScrollUpdateEvent(10, 0, 0);
2273 EXPECT_EQ(0U, sink_
->message_count());
2275 // Receive an ACK for the second scroll-update event as not being processed.
2276 // This will now initiate an overscroll. This will also cause the queued
2277 // gesture event to be released. But instead of going to the renderer, it will
2278 // be consumed by the overscroll controller.
2279 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2280 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2281 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2282 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2283 EXPECT_EQ(65.f
, overscroll_delta_x());
2284 EXPECT_EQ(15.f
, overscroll_delegate()->delta_x());
2285 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2286 EXPECT_EQ(0U, sink_
->message_count());
2289 // Tests that the gesture debounce timer plays nice with the overscroll
2291 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
2292 GestureScrollDebounceTimerOverscroll
) {
2293 SetUpOverscrollEnvironmentWithDebounce(10);
2295 // Start scrolling. Receive ACK as it being processed.
2296 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2297 blink::WebGestureDeviceTouchscreen
);
2298 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2300 // Send update events.
2301 SimulateGestureScrollUpdateEvent(55, 0, 0);
2302 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2304 // Send an end event. This should get in the debounce queue.
2305 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
2306 blink::WebGestureDeviceTouchscreen
);
2307 EXPECT_EQ(0U, sink_
->message_count());
2309 // Receive ACK for the scroll-update event.
2310 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2311 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2312 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2313 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2314 EXPECT_EQ(55.f
, overscroll_delta_x());
2315 EXPECT_EQ(5.f
, overscroll_delegate()->delta_x());
2316 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2317 EXPECT_EQ(0U, sink_
->message_count());
2319 // Let the timer for the debounce queue fire. That should release the queued
2320 // scroll-end event. Since overscroll has started, but there hasn't been
2321 // enough overscroll to complete the gesture, the overscroll controller
2322 // will reset the state. The scroll-end should therefore be dispatched to the
2323 // renderer, and the gesture-event-filter should await an ACK for it.
2324 base::MessageLoop::current()->PostDelayedTask(
2326 base::MessageLoop::QuitClosure(),
2327 base::TimeDelta::FromMilliseconds(15));
2328 base::MessageLoop::current()->Run();
2330 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2331 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2332 EXPECT_EQ(1U, sink_
->message_count());
2335 // Tests that when touch-events are dispatched to the renderer, the overscroll
2336 // gesture deals with them correctly.
2337 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, OverscrollWithTouchEvents
) {
2338 SetUpOverscrollEnvironmentWithDebounce(10);
2339 widget_host_
->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
2340 sink_
->ClearMessages();
2342 // The test sends an intermingled sequence of touch and gesture events.
2343 PressTouchPoint(0, 1);
2344 SendInputEventACK(WebInputEvent::TouchStart
,
2345 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2346 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2348 MoveTouchPoint(0, 20, 5);
2349 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2350 SendInputEventACK(WebInputEvent::TouchMove
,
2351 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2353 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2354 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2356 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2357 blink::WebGestureDeviceTouchscreen
);
2358 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2359 SimulateGestureScrollUpdateEvent(20, 0, 0);
2360 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2361 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2362 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2363 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2364 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2366 // Another touch move event should reach the renderer since overscroll hasn't
2367 // started yet. Note that touch events sent during the scroll period may
2368 // not require an ack (having been marked uncancelable).
2369 MoveTouchPoint(0, 65, 10);
2370 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2371 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2373 SimulateGestureScrollUpdateEvent(45, 0, 0);
2374 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2375 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2376 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2377 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2378 EXPECT_EQ(65.f
, overscroll_delta_x());
2379 EXPECT_EQ(15.f
, overscroll_delegate()->delta_x());
2380 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2381 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2383 // Send another touch event. The page should get the touch-move event, even
2384 // though overscroll has started.
2385 MoveTouchPoint(0, 55, 5);
2386 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2387 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2388 EXPECT_EQ(65.f
, overscroll_delta_x());
2389 EXPECT_EQ(15.f
, overscroll_delegate()->delta_x());
2390 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2391 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2392 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2394 SimulateGestureScrollUpdateEvent(-10, 0, 0);
2395 EXPECT_EQ(0U, sink_
->message_count());
2396 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2397 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2398 EXPECT_EQ(55.f
, overscroll_delta_x());
2399 EXPECT_EQ(5.f
, overscroll_delegate()->delta_x());
2400 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2402 PressTouchPoint(255, 5);
2403 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2404 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2406 SimulateGestureScrollUpdateEvent(200, 0, 0);
2407 EXPECT_EQ(0U, sink_
->message_count());
2408 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2409 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2410 EXPECT_EQ(255.f
, overscroll_delta_x());
2411 EXPECT_EQ(205.f
, overscroll_delegate()->delta_x());
2412 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2414 // The touch-end/cancel event should always reach the renderer if the page has
2416 ReleaseTouchPoint(1);
2417 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2418 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2419 ReleaseTouchPoint(0);
2420 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2421 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2423 SimulateGestureEvent(blink::WebInputEvent::GestureScrollEnd
,
2424 blink::WebGestureDeviceTouchscreen
);
2425 base::MessageLoop::current()->PostDelayedTask(
2427 base::MessageLoop::QuitClosure(),
2428 base::TimeDelta::FromMilliseconds(10));
2429 base::MessageLoop::current()->Run();
2430 EXPECT_EQ(1U, sink_
->message_count());
2431 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2432 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2433 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->completed_mode());
2436 // Tests that touch-gesture end is dispatched to the renderer at the end of a
2437 // touch-gesture initiated overscroll.
2438 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
2439 TouchGestureEndDispatchedAfterOverscrollComplete
) {
2440 SetUpOverscrollEnvironmentWithDebounce(10);
2441 widget_host_
->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
2442 sink_
->ClearMessages();
2444 // Start scrolling. Receive ACK as it being processed.
2445 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2446 blink::WebGestureDeviceTouchscreen
);
2447 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2448 // The scroll begin event will have received a synthetic ack from the input
2450 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2451 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2453 // Send update events.
2454 SimulateGestureScrollUpdateEvent(55, -5, 0);
2455 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2456 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2457 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2459 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2460 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2461 EXPECT_EQ(0U, sink_
->message_count());
2462 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2463 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2464 EXPECT_EQ(55.f
, overscroll_delta_x());
2465 EXPECT_EQ(5.f
, overscroll_delegate()->delta_x());
2466 EXPECT_EQ(-5.f
, overscroll_delegate()->delta_y());
2469 SimulateGestureEvent(blink::WebInputEvent::GestureScrollEnd
,
2470 blink::WebGestureDeviceTouchscreen
);
2471 EXPECT_EQ(0U, sink_
->message_count());
2472 base::MessageLoop::current()->PostDelayedTask(
2474 base::MessageLoop::QuitClosure(),
2475 base::TimeDelta::FromMilliseconds(10));
2476 base::MessageLoop::current()->Run();
2477 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2478 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2479 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->completed_mode());
2480 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2482 // Start scrolling. Receive ACK as it being processed.
2483 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2484 blink::WebGestureDeviceTouchscreen
);
2485 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2486 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2487 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2489 // Send update events.
2490 SimulateGestureScrollUpdateEvent(235, -5, 0);
2491 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2492 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2493 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2495 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2496 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2497 EXPECT_EQ(0U, sink_
->message_count());
2498 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2499 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2500 EXPECT_EQ(235.f
, overscroll_delta_x());
2501 EXPECT_EQ(185.f
, overscroll_delegate()->delta_x());
2502 EXPECT_EQ(-5.f
, overscroll_delegate()->delta_y());
2505 SimulateGestureEvent(blink::WebInputEvent::GestureScrollEnd
,
2506 blink::WebGestureDeviceTouchscreen
);
2507 EXPECT_EQ(0U, sink_
->message_count());
2508 base::MessageLoop::current()->PostDelayedTask(
2510 base::MessageLoop::QuitClosure(),
2511 base::TimeDelta::FromMilliseconds(10));
2512 base::MessageLoop::current()->Run();
2513 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2514 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2515 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->completed_mode());
2516 EXPECT_EQ(1U, sink_
->message_count());
2519 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, OverscrollDirectionChange
) {
2520 SetUpOverscrollEnvironmentWithDebounce(100);
2522 // Start scrolling. Receive ACK as it being processed.
2523 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2524 blink::WebGestureDeviceTouchscreen
);
2525 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2527 // Send update events and receive ack as not consumed.
2528 SimulateGestureScrollUpdateEvent(125, -5, 0);
2529 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2531 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2532 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2533 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2534 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2535 EXPECT_EQ(0U, sink_
->message_count());
2537 // Send another update event, but in the reverse direction. The overscroll
2538 // controller will not consume the event, because it is not triggering
2540 SimulateGestureScrollUpdateEvent(-260, 0, 0);
2541 EXPECT_EQ(1U, sink_
->message_count());
2542 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2544 // Since the overscroll mode has been reset, the next scroll update events
2545 // should reach the renderer.
2546 SimulateGestureScrollUpdateEvent(-20, 0, 0);
2547 EXPECT_EQ(1U, sink_
->message_count());
2548 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2551 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
2552 OverscrollDirectionChangeMouseWheel
) {
2553 SetUpOverscrollEnvironment();
2555 // Send wheel event and receive ack as not consumed.
2556 SimulateWheelEvent(125, -5, 0, true);
2557 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2558 SendInputEventACK(WebInputEvent::MouseWheel
,
2559 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2560 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2561 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2562 EXPECT_EQ(0U, sink_
->message_count());
2564 // Send another wheel event, but in the reverse direction. The overscroll
2565 // controller will not consume the event, because it is not triggering
2567 SimulateWheelEvent(-260, 0, 0, true);
2568 EXPECT_EQ(1U, sink_
->message_count());
2569 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2571 // Since the overscroll mode has been reset, the next wheel event should reach
2573 SimulateWheelEvent(-20, 0, 0, true);
2574 EXPECT_EQ(1U, sink_
->message_count());
2575 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2578 // Tests that if a mouse-move event completes the overscroll gesture, future
2579 // move events do reach the renderer.
2580 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, OverscrollMouseMoveCompletion
) {
2581 SetUpOverscrollEnvironment();
2583 SimulateWheelEvent(5, 0, 0, true); // sent directly
2584 SimulateWheelEvent(-1, 0, 0, true); // enqueued
2585 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
2586 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
2587 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
2588 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2589 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2591 // Receive ACK the first wheel event as not processed.
2592 SendInputEventACK(WebInputEvent::MouseWheel
,
2593 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2594 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2595 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2596 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2598 // Receive ACK for the second (coalesced) event as not processed. This will
2599 // start an overcroll gesture.
2600 SendInputEventACK(WebInputEvent::MouseWheel
,
2601 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2602 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_mode());
2603 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_delegate()->current_mode());
2604 EXPECT_EQ(0U, sink_
->message_count());
2606 // Send a mouse-move event. This should cancel the overscroll navigation
2607 // (since the amount overscrolled is not above the threshold), and so the
2608 // mouse-move should reach the renderer.
2609 SimulateMouseMove(5, 10, 0);
2610 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2611 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->completed_mode());
2612 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2613 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2615 SendInputEventACK(WebInputEvent::MouseMove
,
2616 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2618 // Moving the mouse more should continue to send the events to the renderer.
2619 SimulateMouseMove(5, 10, 0);
2620 SendInputEventACK(WebInputEvent::MouseMove
,
2621 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2622 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2624 // Now try with gestures.
2625 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2626 blink::WebGestureDeviceTouchscreen
);
2627 SimulateGestureScrollUpdateEvent(300, -5, 0);
2628 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2629 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2630 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2631 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2632 sink_
->ClearMessages();
2634 // Overscroll gesture is in progress. Send a mouse-move now. This should
2635 // complete the gesture (because the amount overscrolled is above the
2637 SimulateMouseMove(5, 10, 0);
2638 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->completed_mode());
2639 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2640 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2641 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2642 SendInputEventACK(WebInputEvent::MouseMove
,
2643 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2645 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
2646 blink::WebGestureDeviceTouchscreen
);
2647 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2648 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2650 // Move mouse some more. The mouse-move events should reach the renderer.
2651 SimulateMouseMove(5, 10, 0);
2652 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2654 SendInputEventACK(WebInputEvent::MouseMove
,
2655 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2658 // Tests that if a page scrolled, then the overscroll controller's states are
2659 // reset after the end of the scroll.
2660 TEST_F(RenderWidgetHostViewAuraOverscrollTest
,
2661 OverscrollStateResetsAfterScroll
) {
2662 SetUpOverscrollEnvironment();
2664 SimulateWheelEvent(0, 5, 0, true); // sent directly
2665 SimulateWheelEvent(0, 30, 0, true); // enqueued
2666 SimulateWheelEvent(0, 40, 0, true); // coalesced into previous event
2667 SimulateWheelEvent(0, 10, 0, true); // coalesced into previous event
2668 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2669 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2671 // The first wheel event is consumed. Dispatches the queued wheel event.
2672 SendInputEventACK(WebInputEvent::MouseWheel
, INPUT_EVENT_ACK_STATE_CONSUMED
);
2673 EXPECT_TRUE(ScrollStateIsContentScrolling());
2674 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2676 // The second wheel event is consumed.
2677 SendInputEventACK(WebInputEvent::MouseWheel
, INPUT_EVENT_ACK_STATE_CONSUMED
);
2678 EXPECT_TRUE(ScrollStateIsContentScrolling());
2680 // Touchpad scroll can end with a zero-velocity fling. But it is not
2681 // dispatched, but it should still reset the overscroll controller state.
2682 SimulateGestureFlingStartEvent(0.f
, 0.f
, blink::WebGestureDeviceTouchpad
);
2683 EXPECT_TRUE(ScrollStateIsUnknown());
2684 EXPECT_EQ(0U, sink_
->message_count());
2686 SimulateWheelEvent(-5, 0, 0, true); // sent directly
2687 SimulateWheelEvent(-60, 0, 0, true); // enqueued
2688 SimulateWheelEvent(-100, 0, 0, true); // coalesced into previous event
2689 EXPECT_TRUE(ScrollStateIsUnknown());
2690 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2692 // The first wheel scroll did not scroll content. Overscroll should not start
2693 // yet, since enough hasn't been scrolled.
2694 SendInputEventACK(WebInputEvent::MouseWheel
,
2695 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2696 EXPECT_TRUE(ScrollStateIsUnknown());
2697 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2699 SendInputEventACK(WebInputEvent::MouseWheel
,
2700 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2701 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_mode());
2702 EXPECT_TRUE(ScrollStateIsOverscrolling());
2703 EXPECT_EQ(0U, sink_
->message_count());
2705 SimulateGestureFlingStartEvent(0.f
, 0.f
, blink::WebGestureDeviceTouchpad
);
2706 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2707 EXPECT_EQ(OVERSCROLL_WEST
, overscroll_delegate()->completed_mode());
2708 EXPECT_TRUE(ScrollStateIsUnknown());
2709 EXPECT_EQ(0U, sink_
->message_count());
2712 TEST_F(RenderWidgetHostViewAuraOverscrollTest
, OverscrollResetsOnBlur
) {
2713 SetUpOverscrollEnvironment();
2715 // Start an overscroll with gesture scroll. In the middle of the scroll, blur
2717 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2718 blink::WebGestureDeviceTouchscreen
);
2719 SimulateGestureScrollUpdateEvent(300, -5, 0);
2720 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2721 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2722 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2723 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2724 EXPECT_EQ(2U, GetSentMessageCountAndResetSink());
2726 view_
->OnWindowFocused(NULL
, view_
->GetAttachedWindow());
2727 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_mode());
2728 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2729 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->completed_mode());
2730 EXPECT_EQ(0.f
, overscroll_delegate()->delta_x());
2731 EXPECT_EQ(0.f
, overscroll_delegate()->delta_y());
2732 sink_
->ClearMessages();
2734 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
2735 blink::WebGestureDeviceTouchscreen
);
2736 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2738 // Start a scroll gesture again. This should correctly start the overscroll
2739 // after the threshold.
2740 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
2741 blink::WebGestureDeviceTouchscreen
);
2742 SimulateGestureScrollUpdateEvent(300, -5, 0);
2743 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
2744 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2745 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_mode());
2746 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->current_mode());
2747 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->completed_mode());
2749 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
2750 blink::WebGestureDeviceTouchscreen
);
2751 EXPECT_EQ(OVERSCROLL_NONE
, overscroll_delegate()->current_mode());
2752 EXPECT_EQ(OVERSCROLL_EAST
, overscroll_delegate()->completed_mode());
2753 EXPECT_EQ(3U, sink_
->message_count());
2756 } // namespace content