Add a FrameHostMsg_BeginNavigation IPC
[chromium-blink-merge.git] / content / browser / renderer_host / render_widget_host_view_aura_unittest.cc
blob2e4cab08c6551720ba91384abdc906e421e0321b
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/event_generator.h"
43 #include "ui/aura/test/test_cursor_client.h"
44 #include "ui/aura/test/test_screen.h"
45 #include "ui/aura/test/test_window_delegate.h"
46 #include "ui/aura/window.h"
47 #include "ui/aura/window_event_dispatcher.h"
48 #include "ui/aura/window_observer.h"
49 #include "ui/base/ui_base_types.h"
50 #include "ui/compositor/compositor.h"
51 #include "ui/compositor/test/draw_waiter_for_test.h"
52 #include "ui/events/event.h"
53 #include "ui/events/event_utils.h"
54 #include "ui/events/gestures/gesture_configuration.h"
55 #include "ui/wm/core/default_activation_client.h"
57 using testing::_;
59 using blink::WebGestureEvent;
60 using blink::WebInputEvent;
61 using blink::WebMouseEvent;
62 using blink::WebMouseWheelEvent;
63 using blink::WebTouchEvent;
64 using blink::WebTouchPoint;
66 namespace content {
67 namespace {
69 // Simple screen position client to test coordinate system conversion.
70 class TestScreenPositionClient
71 : public aura::client::ScreenPositionClient {
72 public:
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 {
84 point->Offset(1, 1);
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 {
99 public:
100 explicit TestOverscrollDelegate(RenderWidgetHostView* view)
101 : view_(view),
102 current_mode_(OVERSCROLL_NONE),
103 completed_mode_(OVERSCROLL_NONE),
104 delta_x_(0.f),
105 delta_y_(0.f) {}
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_; }
114 void Reset() {
115 current_mode_ = OVERSCROLL_NONE;
116 completed_mode_ = OVERSCROLL_NONE;
117 delta_x_ = delta_y_ = 0.f;
120 private:
121 // Overridden from OverscrollControllerDelegate:
122 virtual gfx::Rect GetVisibleBounds() const OVERRIDE {
123 return view_->IsShowing() ? view_->GetViewBounds() : gfx::Rect();
126 virtual void OnOverscrollUpdate(float delta_x, float delta_y) OVERRIDE {
127 delta_x_ = delta_x;
128 delta_y_ = delta_y;
131 virtual void OnOverscrollComplete(OverscrollMode overscroll_mode) OVERRIDE {
132 EXPECT_EQ(current_mode_, overscroll_mode);
133 completed_mode_ = overscroll_mode;
134 current_mode_ = OVERSCROLL_NONE;
137 virtual void OnOverscrollModeChange(OverscrollMode old_mode,
138 OverscrollMode new_mode) OVERRIDE {
139 EXPECT_EQ(current_mode_, old_mode);
140 current_mode_ = new_mode;
141 delta_x_ = delta_y_ = 0.f;
144 RenderWidgetHostView* view_;
145 OverscrollMode current_mode_;
146 OverscrollMode completed_mode_;
147 float delta_x_;
148 float delta_y_;
150 DISALLOW_COPY_AND_ASSIGN(TestOverscrollDelegate);
153 class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate {
154 public:
155 MockRenderWidgetHostDelegate() {}
156 virtual ~MockRenderWidgetHostDelegate() {}
159 // Simple observer that keeps track of changes to a window for tests.
160 class TestWindowObserver : public aura::WindowObserver {
161 public:
162 explicit TestWindowObserver(aura::Window* window_to_observe)
163 : window_(window_to_observe) {
164 window_->AddObserver(this);
166 virtual ~TestWindowObserver() {
167 if (window_)
168 window_->RemoveObserver(this);
171 bool destroyed() const { return destroyed_; }
173 // aura::WindowObserver overrides:
174 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE {
175 CHECK_EQ(window, window_);
176 destroyed_ = true;
177 window_ = NULL;
180 private:
181 // Window that we're observing, or NULL if it's been destroyed.
182 aura::Window* window_;
184 // Was |window_| destroyed?
185 bool destroyed_;
187 DISALLOW_COPY_AND_ASSIGN(TestWindowObserver);
190 class FakeFrameSubscriber : public RenderWidgetHostViewFrameSubscriber {
191 public:
192 FakeFrameSubscriber(gfx::Size size, base::Callback<void(bool)> callback)
193 : size_(size), callback_(callback) {}
195 virtual bool ShouldCaptureFrame(base::TimeTicks present_time,
196 scoped_refptr<media::VideoFrame>* storage,
197 DeliverFrameCallback* callback) OVERRIDE {
198 *storage = media::VideoFrame::CreateFrame(media::VideoFrame::YV12,
199 size_,
200 gfx::Rect(size_),
201 size_,
202 base::TimeDelta());
203 *callback = base::Bind(&FakeFrameSubscriber::CallbackMethod, callback_);
204 return true;
207 static void CallbackMethod(base::Callback<void(bool)> callback,
208 base::TimeTicks timestamp,
209 bool success) {
210 callback.Run(success);
213 private:
214 gfx::Size size_;
215 base::Callback<void(bool)> callback_;
218 class FakeRenderWidgetHostViewAura : public RenderWidgetHostViewAura {
219 public:
220 FakeRenderWidgetHostViewAura(RenderWidgetHost* widget)
221 : RenderWidgetHostViewAura(widget), has_resize_lock_(false) {}
223 virtual ~FakeRenderWidgetHostViewAura() {}
225 virtual scoped_ptr<ResizeLock> CreateResizeLock(
226 bool defer_compositor_lock) OVERRIDE {
227 gfx::Size desired_size = window()->bounds().size();
228 return scoped_ptr<ResizeLock>(
229 new FakeResizeLock(desired_size, defer_compositor_lock));
232 void RunOnCompositingDidCommit() {
233 GetDelegatedFrameHost()->OnCompositingDidCommitForTesting(
234 window()->GetHost()->compositor());
237 virtual bool ShouldCreateResizeLock() OVERRIDE {
238 return GetDelegatedFrameHost()->ShouldCreateResizeLockForTesting();
241 virtual void RequestCopyOfOutput(scoped_ptr<cc::CopyOutputRequest> request)
242 OVERRIDE {
243 last_copy_request_ = request.Pass();
244 if (last_copy_request_->has_texture_mailbox()) {
245 // Give the resulting texture a size.
246 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper();
247 GLuint texture = gl_helper->ConsumeMailboxToTexture(
248 last_copy_request_->texture_mailbox().mailbox(),
249 last_copy_request_->texture_mailbox().sync_point());
250 gl_helper->ResizeTexture(texture, window()->bounds().size());
251 gl_helper->DeleteTexture(texture);
255 cc::DelegatedFrameProvider* frame_provider() const {
256 return GetDelegatedFrameHost()->FrameProviderForTesting();
259 // A lock that doesn't actually do anything to the compositor, and does not
260 // time out.
261 class FakeResizeLock : public ResizeLock {
262 public:
263 FakeResizeLock(const gfx::Size new_size, bool defer_compositor_lock)
264 : ResizeLock(new_size, defer_compositor_lock) {}
267 bool has_resize_lock_;
268 gfx::Size last_frame_size_;
269 scoped_ptr<cc::CopyOutputRequest> last_copy_request_;
272 // A layout manager that always resizes a child to the root window size.
273 class FullscreenLayoutManager : public aura::LayoutManager {
274 public:
275 explicit FullscreenLayoutManager(aura::Window* owner) : owner_(owner) {}
276 virtual ~FullscreenLayoutManager() {}
278 // Overridden from aura::LayoutManager:
279 virtual void OnWindowResized() OVERRIDE {
280 aura::Window::Windows::const_iterator i;
281 for (i = owner_->children().begin(); i != owner_->children().end(); ++i) {
282 (*i)->SetBounds(gfx::Rect());
285 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE {
286 child->SetBounds(gfx::Rect());
288 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {}
289 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {}
290 virtual void OnChildWindowVisibilityChanged(aura::Window* child,
291 bool visible) OVERRIDE {}
292 virtual void SetChildBounds(aura::Window* child,
293 const gfx::Rect& requested_bounds) OVERRIDE {
294 SetChildBoundsDirect(child, gfx::Rect(owner_->bounds().size()));
297 private:
298 aura::Window* owner_;
299 DISALLOW_COPY_AND_ASSIGN(FullscreenLayoutManager);
302 class MockWindowObserver : public aura::WindowObserver {
303 public:
304 MOCK_METHOD2(OnWindowPaintScheduled, void(aura::Window*, const gfx::Rect&));
307 } // namespace
309 class RenderWidgetHostViewAuraTest : public testing::Test {
310 public:
311 RenderWidgetHostViewAuraTest()
312 : browser_thread_for_ui_(BrowserThread::UI, &message_loop_) {}
314 void SetUpEnvironment() {
315 ImageTransportFactory::InitializeForUnitTests(
316 scoped_ptr<ImageTransportFactory>(
317 new NoTransportImageTransportFactory));
318 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_));
319 aura_test_helper_->SetUp(
320 ImageTransportFactory::GetInstance()->GetContextFactory());
321 new wm::DefaultActivationClient(aura_test_helper_->root_window());
323 browser_context_.reset(new TestBrowserContext);
324 process_host_ = new MockRenderProcessHost(browser_context_.get());
326 sink_ = &process_host_->sink();
328 parent_host_ = new RenderWidgetHostImpl(
329 &delegate_, process_host_, MSG_ROUTING_NONE, false);
330 parent_view_ = new RenderWidgetHostViewAura(parent_host_);
331 parent_view_->InitAsChild(NULL);
332 aura::client::ParentWindowWithContext(parent_view_->GetNativeView(),
333 aura_test_helper_->root_window(),
334 gfx::Rect());
336 widget_host_ = new RenderWidgetHostImpl(
337 &delegate_, process_host_, MSG_ROUTING_NONE, false);
338 widget_host_->Init();
339 view_ = new FakeRenderWidgetHostViewAura(widget_host_);
342 void TearDownEnvironment() {
343 sink_ = NULL;
344 process_host_ = NULL;
345 if (view_)
346 view_->Destroy();
347 delete widget_host_;
349 parent_view_->Destroy();
350 delete parent_host_;
352 browser_context_.reset();
353 aura_test_helper_->TearDown();
355 message_loop_.DeleteSoon(FROM_HERE, browser_context_.release());
356 message_loop_.RunUntilIdle();
357 ImageTransportFactory::Terminate();
360 virtual void SetUp() { SetUpEnvironment(); }
362 virtual void TearDown() { TearDownEnvironment(); }
364 protected:
365 base::MessageLoopForUI message_loop_;
366 BrowserThreadImpl browser_thread_for_ui_;
367 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_;
368 scoped_ptr<BrowserContext> browser_context_;
369 MockRenderWidgetHostDelegate delegate_;
370 MockRenderProcessHost* process_host_;
372 // Tests should set these to NULL if they've already triggered their
373 // destruction.
374 RenderWidgetHostImpl* parent_host_;
375 RenderWidgetHostViewAura* parent_view_;
377 // Tests should set these to NULL if they've already triggered their
378 // destruction.
379 RenderWidgetHostImpl* widget_host_;
380 FakeRenderWidgetHostViewAura* view_;
382 IPC::TestSink* sink_;
384 private:
385 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraTest);
388 class RenderWidgetHostViewAuraOverscrollTest
389 : public RenderWidgetHostViewAuraTest {
390 public:
391 RenderWidgetHostViewAuraOverscrollTest() {}
393 // We explicitly invoke SetUp to allow gesture debounce customization.
394 virtual void SetUp() {}
396 protected:
397 void SetUpOverscrollEnvironmentWithDebounce(int debounce_interval_in_ms) {
398 SetUpOverscrollEnvironmentImpl(debounce_interval_in_ms);
401 void SetUpOverscrollEnvironment() { SetUpOverscrollEnvironmentImpl(0); }
403 void SetUpOverscrollEnvironmentImpl(int debounce_interval_in_ms) {
404 ui::GestureConfiguration::set_scroll_debounce_interval_in_ms(
405 debounce_interval_in_ms);
407 RenderWidgetHostViewAuraTest::SetUp();
409 view_->SetOverscrollControllerEnabled(true);
410 overscroll_delegate_.reset(new TestOverscrollDelegate(view_));
411 view_->overscroll_controller()->set_delegate(overscroll_delegate_.get());
413 view_->InitAsChild(NULL);
414 view_->SetBounds(gfx::Rect(0, 0, 400, 200));
415 view_->Show();
417 sink_->ClearMessages();
420 // TODO(jdduke): Simulate ui::Events, injecting through the view.
421 void SimulateMouseEvent(WebInputEvent::Type type) {
422 widget_host_->ForwardMouseEvent(SyntheticWebMouseEventBuilder::Build(type));
425 void SimulateMouseEventWithLatencyInfo(WebInputEvent::Type type,
426 const ui::LatencyInfo& ui_latency) {
427 widget_host_->ForwardMouseEventWithLatencyInfo(
428 SyntheticWebMouseEventBuilder::Build(type), ui_latency);
431 void SimulateWheelEvent(float dX, float dY, int modifiers, bool precise) {
432 widget_host_->ForwardWheelEvent(
433 SyntheticWebMouseWheelEventBuilder::Build(dX, dY, modifiers, precise));
436 void SimulateWheelEventWithLatencyInfo(float dX,
437 float dY,
438 int modifiers,
439 bool precise,
440 const ui::LatencyInfo& ui_latency) {
441 widget_host_->ForwardWheelEventWithLatencyInfo(
442 SyntheticWebMouseWheelEventBuilder::Build(dX, dY, modifiers, precise),
443 ui_latency);
446 void SimulateMouseMove(int x, int y, int modifiers) {
447 SimulateMouseEvent(WebInputEvent::MouseMove, x, y, modifiers, false);
450 void SimulateMouseEvent(WebInputEvent::Type type,
451 int x,
452 int y,
453 int modifiers,
454 bool pressed) {
455 WebMouseEvent event =
456 SyntheticWebMouseEventBuilder::Build(type, x, y, modifiers);
457 if (pressed)
458 event.button = WebMouseEvent::ButtonLeft;
459 widget_host_->ForwardMouseEvent(event);
462 void SimulateWheelEventWithPhase(WebMouseWheelEvent::Phase phase) {
463 widget_host_->ForwardWheelEvent(
464 SyntheticWebMouseWheelEventBuilder::Build(phase));
467 // Inject provided synthetic WebGestureEvent instance.
468 void SimulateGestureEventCore(const WebGestureEvent& gesture_event) {
469 widget_host_->ForwardGestureEvent(gesture_event);
472 void SimulateGestureEventCoreWithLatencyInfo(
473 const WebGestureEvent& gesture_event,
474 const ui::LatencyInfo& ui_latency) {
475 widget_host_->ForwardGestureEventWithLatencyInfo(gesture_event, ui_latency);
478 // Inject simple synthetic WebGestureEvent instances.
479 void SimulateGestureEvent(WebInputEvent::Type type,
480 blink::WebGestureDevice sourceDevice) {
481 SimulateGestureEventCore(
482 SyntheticWebGestureEventBuilder::Build(type, sourceDevice));
485 void SimulateGestureEventWithLatencyInfo(WebInputEvent::Type type,
486 blink::WebGestureDevice sourceDevice,
487 const ui::LatencyInfo& ui_latency) {
488 SimulateGestureEventCoreWithLatencyInfo(
489 SyntheticWebGestureEventBuilder::Build(type, sourceDevice), ui_latency);
492 void SimulateGestureScrollUpdateEvent(float dX, float dY, int modifiers) {
493 SimulateGestureEventCore(
494 SyntheticWebGestureEventBuilder::BuildScrollUpdate(dX, dY, modifiers));
497 void SimulateGesturePinchUpdateEvent(float scale,
498 float anchorX,
499 float anchorY,
500 int modifiers) {
501 SimulateGestureEventCore(SyntheticWebGestureEventBuilder::BuildPinchUpdate(
502 scale,
503 anchorX,
504 anchorY,
505 modifiers,
506 blink::WebGestureDeviceTouchscreen));
509 // Inject synthetic GestureFlingStart events.
510 void SimulateGestureFlingStartEvent(float velocityX,
511 float velocityY,
512 blink::WebGestureDevice sourceDevice) {
513 SimulateGestureEventCore(SyntheticWebGestureEventBuilder::BuildFling(
514 velocityX, velocityY, sourceDevice));
517 void SendInputEventACK(WebInputEvent::Type type,
518 InputEventAckState ack_result) {
519 InputHostMsg_HandleInputEvent_ACK_Params ack;
520 ack.type = type;
521 ack.state = ack_result;
522 InputHostMsg_HandleInputEvent_ACK response(0, ack);
523 widget_host_->OnMessageReceived(response);
526 bool ScrollStateIsContentScrolling() const {
527 return scroll_state() == OverscrollController::STATE_CONTENT_SCROLLING;
530 bool ScrollStateIsOverscrolling() const {
531 return scroll_state() == OverscrollController::STATE_OVERSCROLLING;
534 bool ScrollStateIsUnknown() const {
535 return scroll_state() == OverscrollController::STATE_UNKNOWN;
538 OverscrollController::ScrollState scroll_state() const {
539 return view_->overscroll_controller()->scroll_state_;
542 OverscrollMode overscroll_mode() const {
543 return view_->overscroll_controller()->overscroll_mode_;
546 float overscroll_delta_x() const {
547 return view_->overscroll_controller()->overscroll_delta_x_;
550 float overscroll_delta_y() const {
551 return view_->overscroll_controller()->overscroll_delta_y_;
554 TestOverscrollDelegate* overscroll_delegate() {
555 return overscroll_delegate_.get();
558 void SendTouchEvent() {
559 widget_host_->ForwardTouchEventWithLatencyInfo(touch_event_,
560 ui::LatencyInfo());
561 touch_event_.ResetPoints();
564 void PressTouchPoint(int x, int y) {
565 touch_event_.PressPoint(x, y);
566 SendTouchEvent();
569 void MoveTouchPoint(int index, int x, int y) {
570 touch_event_.MovePoint(index, x, y);
571 SendTouchEvent();
574 void ReleaseTouchPoint(int index) {
575 touch_event_.ReleasePoint(index);
576 SendTouchEvent();
579 size_t GetSentMessageCountAndResetSink() {
580 size_t count = sink_->message_count();
581 sink_->ClearMessages();
582 return count;
585 void AckLastSentInputEventIfNecessary(InputEventAckState ack_result) {
586 if (!sink_->message_count())
587 return;
589 InputMsg_HandleInputEvent::Param params;
590 if (!InputMsg_HandleInputEvent::Read(
591 sink_->GetMessageAt(sink_->message_count() - 1), &params)) {
592 return;
595 if (WebInputEventTraits::IgnoresAckDisposition(*params.a))
596 return;
598 SendInputEventACK(params.a->type, ack_result);
601 SyntheticWebTouchEvent touch_event_;
603 scoped_ptr<TestOverscrollDelegate> overscroll_delegate_;
605 private:
606 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraOverscrollTest);
609 class RenderWidgetHostViewAuraShutdownTest
610 : public RenderWidgetHostViewAuraTest {
611 public:
612 RenderWidgetHostViewAuraShutdownTest() {}
614 virtual void TearDown() OVERRIDE {
615 // No TearDownEnvironment here, we do this explicitly during the test.
618 private:
619 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraShutdownTest);
622 // Checks that a fullscreen view has the correct show-state and receives the
623 // focus.
624 TEST_F(RenderWidgetHostViewAuraTest, FocusFullscreen) {
625 view_->InitAsFullscreen(parent_view_);
626 aura::Window* window = view_->GetNativeView();
627 ASSERT_TRUE(window != NULL);
628 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN,
629 window->GetProperty(aura::client::kShowStateKey));
631 // Check that we requested and received the focus.
632 EXPECT_TRUE(window->HasFocus());
634 // Check that we'll also say it's okay to activate the window when there's an
635 // ActivationClient defined.
636 EXPECT_TRUE(view_->ShouldActivate());
639 // Checks that a popup is positioned correctly relative to its parent using
640 // screen coordinates.
641 TEST_F(RenderWidgetHostViewAuraTest, PositionChildPopup) {
642 TestScreenPositionClient screen_position_client;
644 aura::Window* window = parent_view_->GetNativeView();
645 aura::Window* root = window->GetRootWindow();
646 aura::client::SetScreenPositionClient(root, &screen_position_client);
648 parent_view_->SetBounds(gfx::Rect(10, 10, 800, 600));
649 gfx::Rect bounds_in_screen = parent_view_->GetViewBounds();
650 int horiz = bounds_in_screen.width() / 4;
651 int vert = bounds_in_screen.height() / 4;
652 bounds_in_screen.Inset(horiz, vert);
654 // Verify that when the popup is initialized for the first time, it correctly
655 // treats the input bounds as screen coordinates.
656 view_->InitAsPopup(parent_view_, bounds_in_screen);
658 gfx::Rect final_bounds_in_screen = view_->GetViewBounds();
659 EXPECT_EQ(final_bounds_in_screen.ToString(), bounds_in_screen.ToString());
661 // Verify that directly setting the bounds via SetBounds() treats the input
662 // as screen coordinates.
663 bounds_in_screen = gfx::Rect(60, 60, 100, 100);
664 view_->SetBounds(bounds_in_screen);
665 final_bounds_in_screen = view_->GetViewBounds();
666 EXPECT_EQ(final_bounds_in_screen.ToString(), bounds_in_screen.ToString());
668 // Verify that setting the size does not alter the origin.
669 gfx::Point original_origin = window->bounds().origin();
670 view_->SetSize(gfx::Size(120, 120));
671 gfx::Point new_origin = window->bounds().origin();
672 EXPECT_EQ(original_origin.ToString(), new_origin.ToString());
674 aura::client::SetScreenPositionClient(root, NULL);
677 // Checks that a fullscreen view is destroyed when it loses the focus.
678 TEST_F(RenderWidgetHostViewAuraTest, DestroyFullscreenOnBlur) {
679 view_->InitAsFullscreen(parent_view_);
680 aura::Window* window = view_->GetNativeView();
681 ASSERT_TRUE(window != NULL);
682 ASSERT_TRUE(window->HasFocus());
684 // After we create and focus another window, the RWHVA's window should be
685 // destroyed.
686 TestWindowObserver observer(window);
687 aura::test::TestWindowDelegate delegate;
688 scoped_ptr<aura::Window> sibling(new aura::Window(&delegate));
689 sibling->Init(aura::WINDOW_LAYER_TEXTURED);
690 sibling->Show();
691 window->parent()->AddChild(sibling.get());
692 sibling->Focus();
693 ASSERT_TRUE(sibling->HasFocus());
694 ASSERT_TRUE(observer.destroyed());
696 widget_host_ = NULL;
697 view_ = NULL;
700 // Checks that a popup view is destroyed when a user clicks outside of the popup
701 // view and focus does not change. This is the case when the user clicks on the
702 // desktop background on Chrome OS.
703 TEST_F(RenderWidgetHostViewAuraTest, DestroyPopupClickOutsidePopup) {
704 parent_view_->SetBounds(gfx::Rect(10, 10, 400, 400));
705 parent_view_->Focus();
706 EXPECT_TRUE(parent_view_->HasFocus());
708 view_->InitAsPopup(parent_view_, gfx::Rect(10, 10, 100, 100));
709 aura::Window* window = view_->GetNativeView();
710 ASSERT_TRUE(window != NULL);
712 gfx::Point click_point;
713 EXPECT_FALSE(window->GetBoundsInRootWindow().Contains(click_point));
714 aura::Window* parent_window = parent_view_->GetNativeView();
715 EXPECT_FALSE(parent_window->GetBoundsInRootWindow().Contains(click_point));
717 TestWindowObserver observer(window);
718 aura::test::EventGenerator generator(window->GetRootWindow(), click_point);
719 generator.ClickLeftButton();
720 ASSERT_TRUE(parent_view_->HasFocus());
721 ASSERT_TRUE(observer.destroyed());
723 widget_host_ = NULL;
724 view_ = NULL;
727 // Checks that a popup view is destroyed when a user taps outside of the popup
728 // view and focus does not change. This is the case when the user taps the
729 // desktop background on Chrome OS.
730 TEST_F(RenderWidgetHostViewAuraTest, DestroyPopupTapOutsidePopup) {
731 parent_view_->SetBounds(gfx::Rect(10, 10, 400, 400));
732 parent_view_->Focus();
733 EXPECT_TRUE(parent_view_->HasFocus());
735 view_->InitAsPopup(parent_view_, gfx::Rect(10, 10, 100, 100));
736 aura::Window* window = view_->GetNativeView();
737 ASSERT_TRUE(window != NULL);
739 gfx::Point tap_point;
740 EXPECT_FALSE(window->GetBoundsInRootWindow().Contains(tap_point));
741 aura::Window* parent_window = parent_view_->GetNativeView();
742 EXPECT_FALSE(parent_window->GetBoundsInRootWindow().Contains(tap_point));
744 TestWindowObserver observer(window);
745 aura::test::EventGenerator generator(window->GetRootWindow(), tap_point);
746 generator.GestureTapAt(tap_point);
747 ASSERT_TRUE(parent_view_->HasFocus());
748 ASSERT_TRUE(observer.destroyed());
750 widget_host_ = NULL;
751 view_ = NULL;
754 // Checks that IME-composition-event state is maintained correctly.
755 TEST_F(RenderWidgetHostViewAuraTest, SetCompositionText) {
756 view_->InitAsChild(NULL);
757 view_->Show();
759 ui::CompositionText composition_text;
760 composition_text.text = base::ASCIIToUTF16("|a|b");
762 // Focused segment
763 composition_text.underlines.push_back(
764 ui::CompositionUnderline(0, 3, 0xff000000, true, 0x78563412));
766 // Non-focused segment, with different background color.
767 composition_text.underlines.push_back(
768 ui::CompositionUnderline(3, 4, 0xff000000, false, 0xefcdab90));
770 const ui::CompositionUnderlines& underlines = composition_text.underlines;
772 // Caret is at the end. (This emulates Japanese MSIME 2007 and later)
773 composition_text.selection = gfx::Range(4);
775 sink_->ClearMessages();
776 view_->SetCompositionText(composition_text);
777 EXPECT_TRUE(view_->has_composition_text_);
779 const IPC::Message* msg =
780 sink_->GetFirstMessageMatching(InputMsg_ImeSetComposition::ID);
781 ASSERT_TRUE(msg != NULL);
783 InputMsg_ImeSetComposition::Param params;
784 InputMsg_ImeSetComposition::Read(msg, &params);
785 // composition text
786 EXPECT_EQ(composition_text.text, params.a);
787 // underlines
788 ASSERT_EQ(underlines.size(), params.b.size());
789 for (size_t i = 0; i < underlines.size(); ++i) {
790 EXPECT_EQ(underlines[i].start_offset, params.b[i].startOffset);
791 EXPECT_EQ(underlines[i].end_offset, params.b[i].endOffset);
792 EXPECT_EQ(underlines[i].color, params.b[i].color);
793 EXPECT_EQ(underlines[i].thick, params.b[i].thick);
794 EXPECT_EQ(underlines[i].background_color, params.b[i].backgroundColor);
796 // highlighted range
797 EXPECT_EQ(4, params.c) << "Should be the same to the caret pos";
798 EXPECT_EQ(4, params.d) << "Should be the same to the caret pos";
801 view_->ImeCancelComposition();
802 EXPECT_FALSE(view_->has_composition_text_);
805 // Checks that touch-event state is maintained correctly.
806 TEST_F(RenderWidgetHostViewAuraTest, TouchEventState) {
807 view_->InitAsChild(NULL);
808 view_->Show();
810 // Start with no touch-event handler in the renderer.
811 widget_host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, false));
812 EXPECT_FALSE(widget_host_->ShouldForwardTouchEvent());
814 ui::TouchEvent press(ui::ET_TOUCH_PRESSED,
815 gfx::Point(30, 30),
817 ui::EventTimeForNow());
818 ui::TouchEvent move(ui::ET_TOUCH_MOVED,
819 gfx::Point(20, 20),
821 ui::EventTimeForNow());
822 ui::TouchEvent release(ui::ET_TOUCH_RELEASED,
823 gfx::Point(20, 20),
825 ui::EventTimeForNow());
827 view_->OnTouchEvent(&press);
828 EXPECT_FALSE(press.handled());
829 EXPECT_EQ(blink::WebInputEvent::TouchStart, view_->touch_event_.type);
830 EXPECT_TRUE(view_->touch_event_.cancelable);
831 EXPECT_EQ(1U, view_->touch_event_.touchesLength);
832 EXPECT_EQ(blink::WebTouchPoint::StatePressed,
833 view_->touch_event_.touches[0].state);
835 view_->OnTouchEvent(&move);
836 EXPECT_FALSE(move.handled());
837 EXPECT_EQ(blink::WebInputEvent::TouchMove, view_->touch_event_.type);
838 EXPECT_TRUE(view_->touch_event_.cancelable);
839 EXPECT_EQ(1U, view_->touch_event_.touchesLength);
840 EXPECT_EQ(blink::WebTouchPoint::StateMoved,
841 view_->touch_event_.touches[0].state);
843 view_->OnTouchEvent(&release);
844 EXPECT_FALSE(release.handled());
845 EXPECT_EQ(blink::WebInputEvent::TouchEnd, view_->touch_event_.type);
846 EXPECT_TRUE(view_->touch_event_.cancelable);
847 EXPECT_EQ(0U, view_->touch_event_.touchesLength);
849 // Now install some touch-event handlers and do the same steps. The touch
850 // events should now be consumed. However, the touch-event state should be
851 // updated as before.
852 widget_host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
853 EXPECT_TRUE(widget_host_->ShouldForwardTouchEvent());
855 view_->OnTouchEvent(&press);
856 EXPECT_TRUE(press.stopped_propagation());
857 EXPECT_EQ(blink::WebInputEvent::TouchStart, view_->touch_event_.type);
858 EXPECT_TRUE(view_->touch_event_.cancelable);
859 EXPECT_EQ(1U, view_->touch_event_.touchesLength);
860 EXPECT_EQ(blink::WebTouchPoint::StatePressed,
861 view_->touch_event_.touches[0].state);
863 view_->OnTouchEvent(&move);
864 EXPECT_TRUE(move.stopped_propagation());
865 EXPECT_EQ(blink::WebInputEvent::TouchMove, view_->touch_event_.type);
866 EXPECT_TRUE(view_->touch_event_.cancelable);
867 EXPECT_EQ(1U, view_->touch_event_.touchesLength);
868 EXPECT_EQ(blink::WebTouchPoint::StateMoved,
869 view_->touch_event_.touches[0].state);
871 view_->OnTouchEvent(&release);
872 EXPECT_TRUE(release.stopped_propagation());
873 EXPECT_EQ(blink::WebInputEvent::TouchEnd, view_->touch_event_.type);
874 EXPECT_TRUE(view_->touch_event_.cancelable);
875 EXPECT_EQ(0U, view_->touch_event_.touchesLength);
877 // Now start a touch event, and remove the event-handlers before the release.
878 view_->OnTouchEvent(&press);
879 EXPECT_TRUE(press.stopped_propagation());
880 EXPECT_EQ(blink::WebInputEvent::TouchStart, view_->touch_event_.type);
881 EXPECT_EQ(1U, view_->touch_event_.touchesLength);
882 EXPECT_EQ(blink::WebTouchPoint::StatePressed,
883 view_->touch_event_.touches[0].state);
885 widget_host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, false));
886 EXPECT_FALSE(widget_host_->ShouldForwardTouchEvent());
888 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(20, 20), 0,
889 base::Time::NowFromSystemTime() - base::Time());
890 view_->OnTouchEvent(&move2);
891 EXPECT_FALSE(move2.handled());
892 EXPECT_EQ(blink::WebInputEvent::TouchMove, view_->touch_event_.type);
893 EXPECT_EQ(1U, view_->touch_event_.touchesLength);
894 EXPECT_EQ(blink::WebTouchPoint::StateMoved,
895 view_->touch_event_.touches[0].state);
897 ui::TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(20, 20), 0,
898 base::Time::NowFromSystemTime() - base::Time());
899 view_->OnTouchEvent(&release2);
900 EXPECT_FALSE(release2.handled());
901 EXPECT_EQ(blink::WebInputEvent::TouchEnd, view_->touch_event_.type);
902 EXPECT_EQ(0U, view_->touch_event_.touchesLength);
905 // Checks that touch-events are queued properly when there is a touch-event
906 // handler on the page.
907 TEST_F(RenderWidgetHostViewAuraTest, TouchEventSyncAsync) {
908 view_->InitAsChild(NULL);
909 view_->Show();
911 widget_host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
912 EXPECT_TRUE(widget_host_->ShouldForwardTouchEvent());
914 ui::TouchEvent press(ui::ET_TOUCH_PRESSED,
915 gfx::Point(30, 30),
917 ui::EventTimeForNow());
918 ui::TouchEvent move(ui::ET_TOUCH_MOVED,
919 gfx::Point(20, 20),
921 ui::EventTimeForNow());
922 ui::TouchEvent release(ui::ET_TOUCH_RELEASED,
923 gfx::Point(20, 20),
925 ui::EventTimeForNow());
927 view_->OnTouchEvent(&press);
928 EXPECT_TRUE(press.stopped_propagation());
929 EXPECT_EQ(blink::WebInputEvent::TouchStart, view_->touch_event_.type);
930 EXPECT_EQ(1U, view_->touch_event_.touchesLength);
931 EXPECT_EQ(blink::WebTouchPoint::StatePressed,
932 view_->touch_event_.touches[0].state);
934 view_->OnTouchEvent(&move);
935 EXPECT_TRUE(move.stopped_propagation());
936 EXPECT_EQ(blink::WebInputEvent::TouchMove, view_->touch_event_.type);
937 EXPECT_EQ(1U, view_->touch_event_.touchesLength);
938 EXPECT_EQ(blink::WebTouchPoint::StateMoved,
939 view_->touch_event_.touches[0].state);
941 // Send the same move event. Since the point hasn't moved, it won't affect the
942 // queue. However, the view should consume the event.
943 view_->OnTouchEvent(&move);
944 EXPECT_TRUE(move.stopped_propagation());
945 EXPECT_EQ(blink::WebInputEvent::TouchMove, view_->touch_event_.type);
946 EXPECT_EQ(1U, view_->touch_event_.touchesLength);
947 EXPECT_EQ(blink::WebTouchPoint::StateMoved,
948 view_->touch_event_.touches[0].state);
950 view_->OnTouchEvent(&release);
951 EXPECT_TRUE(release.stopped_propagation());
952 EXPECT_EQ(blink::WebInputEvent::TouchEnd, view_->touch_event_.type);
953 EXPECT_EQ(0U, view_->touch_event_.touchesLength);
956 TEST_F(RenderWidgetHostViewAuraTest, PhysicalBackingSizeWithScale) {
957 view_->InitAsChild(NULL);
958 aura::client::ParentWindowWithContext(
959 view_->GetNativeView(),
960 parent_view_->GetNativeView()->GetRootWindow(),
961 gfx::Rect());
962 sink_->ClearMessages();
963 view_->SetSize(gfx::Size(100, 100));
964 EXPECT_EQ("100x100", view_->GetPhysicalBackingSize().ToString());
965 EXPECT_EQ(1u, sink_->message_count());
966 EXPECT_EQ(ViewMsg_Resize::ID, sink_->GetMessageAt(0)->type());
968 const IPC::Message* msg = sink_->GetMessageAt(0);
969 EXPECT_EQ(ViewMsg_Resize::ID, msg->type());
970 ViewMsg_Resize::Param params;
971 ViewMsg_Resize::Read(msg, &params);
972 EXPECT_EQ("100x100", params.a.new_size.ToString()); // dip size
973 EXPECT_EQ("100x100",
974 params.a.physical_backing_size.ToString()); // backing size
977 widget_host_->ResetSizeAndRepaintPendingFlags();
978 sink_->ClearMessages();
980 aura_test_helper_->test_screen()->SetDeviceScaleFactor(2.0f);
981 EXPECT_EQ("200x200", view_->GetPhysicalBackingSize().ToString());
982 // Extra ScreenInfoChanged message for |parent_view_|.
983 EXPECT_EQ(1u, sink_->message_count());
985 const IPC::Message* msg = sink_->GetMessageAt(0);
986 EXPECT_EQ(ViewMsg_Resize::ID, msg->type());
987 ViewMsg_Resize::Param params;
988 ViewMsg_Resize::Read(msg, &params);
989 EXPECT_EQ(2.0f, params.a.screen_info.deviceScaleFactor);
990 EXPECT_EQ("100x100", params.a.new_size.ToString()); // dip size
991 EXPECT_EQ("200x200",
992 params.a.physical_backing_size.ToString()); // backing size
995 widget_host_->ResetSizeAndRepaintPendingFlags();
996 sink_->ClearMessages();
998 aura_test_helper_->test_screen()->SetDeviceScaleFactor(1.0f);
999 // Extra ScreenInfoChanged message for |parent_view_|.
1000 EXPECT_EQ(1u, sink_->message_count());
1001 EXPECT_EQ("100x100", view_->GetPhysicalBackingSize().ToString());
1003 const IPC::Message* msg = sink_->GetMessageAt(0);
1004 EXPECT_EQ(ViewMsg_Resize::ID, msg->type());
1005 ViewMsg_Resize::Param params;
1006 ViewMsg_Resize::Read(msg, &params);
1007 EXPECT_EQ(1.0f, params.a.screen_info.deviceScaleFactor);
1008 EXPECT_EQ("100x100", params.a.new_size.ToString()); // dip size
1009 EXPECT_EQ("100x100",
1010 params.a.physical_backing_size.ToString()); // backing size
1014 // Checks that InputMsg_CursorVisibilityChange IPC messages are dispatched
1015 // to the renderer at the correct times.
1016 TEST_F(RenderWidgetHostViewAuraTest, CursorVisibilityChange) {
1017 view_->InitAsChild(NULL);
1018 aura::client::ParentWindowWithContext(
1019 view_->GetNativeView(),
1020 parent_view_->GetNativeView()->GetRootWindow(),
1021 gfx::Rect());
1022 view_->SetSize(gfx::Size(100, 100));
1024 aura::test::TestCursorClient cursor_client(
1025 parent_view_->GetNativeView()->GetRootWindow());
1027 cursor_client.AddObserver(view_);
1029 // Expect a message the first time the cursor is shown.
1030 view_->WasShown();
1031 sink_->ClearMessages();
1032 cursor_client.ShowCursor();
1033 EXPECT_EQ(1u, sink_->message_count());
1034 EXPECT_TRUE(sink_->GetUniqueMessageMatching(
1035 InputMsg_CursorVisibilityChange::ID));
1037 // No message expected if the renderer already knows the cursor is visible.
1038 sink_->ClearMessages();
1039 cursor_client.ShowCursor();
1040 EXPECT_EQ(0u, sink_->message_count());
1042 // Hiding the cursor should send a message.
1043 sink_->ClearMessages();
1044 cursor_client.HideCursor();
1045 EXPECT_EQ(1u, sink_->message_count());
1046 EXPECT_TRUE(sink_->GetUniqueMessageMatching(
1047 InputMsg_CursorVisibilityChange::ID));
1049 // No message expected if the renderer already knows the cursor is invisible.
1050 sink_->ClearMessages();
1051 cursor_client.HideCursor();
1052 EXPECT_EQ(0u, sink_->message_count());
1054 // No messages should be sent while the view is invisible.
1055 view_->WasHidden();
1056 sink_->ClearMessages();
1057 cursor_client.ShowCursor();
1058 EXPECT_EQ(0u, sink_->message_count());
1059 cursor_client.HideCursor();
1060 EXPECT_EQ(0u, sink_->message_count());
1062 // Show the view. Since the cursor was invisible when the view was hidden,
1063 // no message should be sent.
1064 sink_->ClearMessages();
1065 view_->WasShown();
1066 EXPECT_FALSE(sink_->GetUniqueMessageMatching(
1067 InputMsg_CursorVisibilityChange::ID));
1069 // No message expected if the renderer already knows the cursor is invisible.
1070 sink_->ClearMessages();
1071 cursor_client.HideCursor();
1072 EXPECT_EQ(0u, sink_->message_count());
1074 // Showing the cursor should send a message.
1075 sink_->ClearMessages();
1076 cursor_client.ShowCursor();
1077 EXPECT_EQ(1u, sink_->message_count());
1078 EXPECT_TRUE(sink_->GetUniqueMessageMatching(
1079 InputMsg_CursorVisibilityChange::ID));
1081 // No messages should be sent while the view is invisible.
1082 view_->WasHidden();
1083 sink_->ClearMessages();
1084 cursor_client.HideCursor();
1085 EXPECT_EQ(0u, sink_->message_count());
1087 // Show the view. Since the cursor was visible when the view was hidden,
1088 // a message is expected to be sent.
1089 sink_->ClearMessages();
1090 view_->WasShown();
1091 EXPECT_TRUE(sink_->GetUniqueMessageMatching(
1092 InputMsg_CursorVisibilityChange::ID));
1094 cursor_client.RemoveObserver(view_);
1097 TEST_F(RenderWidgetHostViewAuraTest, UpdateCursorIfOverSelf) {
1098 view_->InitAsChild(NULL);
1099 aura::client::ParentWindowWithContext(
1100 view_->GetNativeView(),
1101 parent_view_->GetNativeView()->GetRootWindow(),
1102 gfx::Rect());
1104 // Note that all coordinates in this test are screen coordinates.
1105 view_->SetBounds(gfx::Rect(60, 60, 100, 100));
1106 view_->Show();
1108 aura::test::TestCursorClient cursor_client(
1109 parent_view_->GetNativeView()->GetRootWindow());
1111 // Cursor is in the middle of the window.
1112 cursor_client.reset_calls_to_set_cursor();
1113 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(110, 110));
1114 view_->UpdateCursorIfOverSelf();
1115 EXPECT_EQ(1, cursor_client.calls_to_set_cursor());
1117 // Cursor is near the top of the window.
1118 cursor_client.reset_calls_to_set_cursor();
1119 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(80, 65));
1120 view_->UpdateCursorIfOverSelf();
1121 EXPECT_EQ(1, cursor_client.calls_to_set_cursor());
1123 // Cursor is near the bottom of the window.
1124 cursor_client.reset_calls_to_set_cursor();
1125 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(159, 159));
1126 view_->UpdateCursorIfOverSelf();
1127 EXPECT_EQ(1, cursor_client.calls_to_set_cursor());
1129 // Cursor is above the window.
1130 cursor_client.reset_calls_to_set_cursor();
1131 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(67, 59));
1132 view_->UpdateCursorIfOverSelf();
1133 EXPECT_EQ(0, cursor_client.calls_to_set_cursor());
1135 // Cursor is below the window.
1136 cursor_client.reset_calls_to_set_cursor();
1137 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(161, 161));
1138 view_->UpdateCursorIfOverSelf();
1139 EXPECT_EQ(0, cursor_client.calls_to_set_cursor());
1142 scoped_ptr<cc::CompositorFrame> MakeDelegatedFrame(float scale_factor,
1143 gfx::Size size,
1144 gfx::Rect damage) {
1145 scoped_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame);
1146 frame->metadata.device_scale_factor = scale_factor;
1147 frame->delegated_frame_data.reset(new cc::DelegatedFrameData);
1149 scoped_ptr<cc::RenderPass> pass = cc::RenderPass::Create();
1150 pass->SetNew(
1151 cc::RenderPass::Id(1, 1), gfx::Rect(size), damage, gfx::Transform());
1152 frame->delegated_frame_data->render_pass_list.push_back(pass.Pass());
1153 return frame.Pass();
1156 // Resizing in fullscreen mode should send the up-to-date screen info.
1157 TEST_F(RenderWidgetHostViewAuraTest, FullscreenResize) {
1158 aura::Window* root_window = aura_test_helper_->root_window();
1159 root_window->SetLayoutManager(new FullscreenLayoutManager(root_window));
1160 view_->InitAsFullscreen(parent_view_);
1161 view_->WasShown();
1162 widget_host_->ResetSizeAndRepaintPendingFlags();
1163 sink_->ClearMessages();
1165 // Call WasResized to flush the old screen info.
1166 view_->GetRenderWidgetHost()->WasResized();
1168 // 0 is CreatingNew message.
1169 const IPC::Message* msg = sink_->GetMessageAt(0);
1170 EXPECT_EQ(ViewMsg_Resize::ID, msg->type());
1171 ViewMsg_Resize::Param params;
1172 ViewMsg_Resize::Read(msg, &params);
1173 EXPECT_EQ("0,0 800x600",
1174 gfx::Rect(params.a.screen_info.availableRect).ToString());
1175 EXPECT_EQ("800x600", params.a.new_size.ToString());
1176 // Resizes are blocked until we swapped a frame of the correct size, and
1177 // we've committed it.
1178 view_->OnSwapCompositorFrame(
1180 MakeDelegatedFrame(
1181 1.f, params.a.new_size, gfx::Rect(params.a.new_size)));
1182 ui::DrawWaiterForTest::WaitForCommit(
1183 root_window->GetHost()->compositor());
1186 widget_host_->ResetSizeAndRepaintPendingFlags();
1187 sink_->ClearMessages();
1189 // Make sure the corrent screen size is set along in the resize
1190 // request when the screen size has changed.
1191 aura_test_helper_->test_screen()->SetUIScale(0.5);
1192 EXPECT_EQ(1u, sink_->message_count());
1194 const IPC::Message* msg = sink_->GetMessageAt(0);
1195 EXPECT_EQ(ViewMsg_Resize::ID, msg->type());
1196 ViewMsg_Resize::Param params;
1197 ViewMsg_Resize::Read(msg, &params);
1198 EXPECT_EQ("0,0 1600x1200",
1199 gfx::Rect(params.a.screen_info.availableRect).ToString());
1200 EXPECT_EQ("1600x1200", params.a.new_size.ToString());
1201 view_->OnSwapCompositorFrame(
1203 MakeDelegatedFrame(
1204 1.f, params.a.new_size, gfx::Rect(params.a.new_size)));
1205 ui::DrawWaiterForTest::WaitForCommit(
1206 root_window->GetHost()->compositor());
1210 // Swapping a frame should notify the window.
1211 TEST_F(RenderWidgetHostViewAuraTest, SwapNotifiesWindow) {
1212 gfx::Size view_size(100, 100);
1213 gfx::Rect view_rect(view_size);
1215 view_->InitAsChild(NULL);
1216 aura::client::ParentWindowWithContext(
1217 view_->GetNativeView(),
1218 parent_view_->GetNativeView()->GetRootWindow(),
1219 gfx::Rect());
1220 view_->SetSize(view_size);
1221 view_->WasShown();
1223 MockWindowObserver observer;
1224 view_->window_->AddObserver(&observer);
1226 // Delegated renderer path
1227 EXPECT_CALL(observer, OnWindowPaintScheduled(view_->window_, view_rect));
1228 view_->OnSwapCompositorFrame(
1229 0, MakeDelegatedFrame(1.f, view_size, view_rect));
1230 testing::Mock::VerifyAndClearExpectations(&observer);
1232 EXPECT_CALL(observer, OnWindowPaintScheduled(view_->window_,
1233 gfx::Rect(5, 5, 5, 5)));
1234 view_->OnSwapCompositorFrame(
1235 0, MakeDelegatedFrame(1.f, view_size, gfx::Rect(5, 5, 5, 5)));
1236 testing::Mock::VerifyAndClearExpectations(&observer);
1238 view_->window_->RemoveObserver(&observer);
1241 TEST_F(RenderWidgetHostViewAuraTest, Resize) {
1242 gfx::Size size1(100, 100);
1243 gfx::Size size2(200, 200);
1244 gfx::Size size3(300, 300);
1246 aura::Window* root_window = parent_view_->GetNativeView()->GetRootWindow();
1247 view_->InitAsChild(NULL);
1248 aura::client::ParentWindowWithContext(
1249 view_->GetNativeView(), root_window, gfx::Rect(size1));
1250 view_->WasShown();
1251 view_->SetSize(size1);
1252 view_->OnSwapCompositorFrame(
1253 0, MakeDelegatedFrame(1.f, size1, gfx::Rect(size1)));
1254 ui::DrawWaiterForTest::WaitForCommit(
1255 root_window->GetHost()->compositor());
1256 ViewHostMsg_UpdateRect_Params update_params;
1257 update_params.view_size = size1;
1258 update_params.scale_factor = 1.f;
1259 update_params.flags = ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
1260 widget_host_->OnMessageReceived(
1261 ViewHostMsg_UpdateRect(widget_host_->GetRoutingID(), update_params));
1262 sink_->ClearMessages();
1263 // Resize logic is idle (no pending resize, no pending commit).
1264 EXPECT_EQ(size1.ToString(), view_->GetRequestedRendererSize().ToString());
1266 // Resize renderer, should produce a Resize message
1267 view_->SetSize(size2);
1268 EXPECT_EQ(size2.ToString(), view_->GetRequestedRendererSize().ToString());
1269 EXPECT_EQ(1u, sink_->message_count());
1271 const IPC::Message* msg = sink_->GetMessageAt(0);
1272 EXPECT_EQ(ViewMsg_Resize::ID, msg->type());
1273 ViewMsg_Resize::Param params;
1274 ViewMsg_Resize::Read(msg, &params);
1275 EXPECT_EQ(size2.ToString(), params.a.new_size.ToString());
1277 // Send resize ack to observe new Resize messages.
1278 update_params.view_size = size2;
1279 widget_host_->OnMessageReceived(
1280 ViewHostMsg_UpdateRect(widget_host_->GetRoutingID(), update_params));
1281 sink_->ClearMessages();
1283 // Resize renderer again, before receiving a frame. Should not produce a
1284 // Resize message.
1285 view_->SetSize(size3);
1286 EXPECT_EQ(size2.ToString(), view_->GetRequestedRendererSize().ToString());
1287 EXPECT_EQ(0u, sink_->message_count());
1289 // Receive a frame of the new size, should be skipped and not produce a Resize
1290 // message.
1291 view_->OnSwapCompositorFrame(
1292 0, MakeDelegatedFrame(1.f, size3, gfx::Rect(size3)));
1293 // Expect the frame ack;
1294 EXPECT_EQ(1u, sink_->message_count());
1295 EXPECT_EQ(ViewMsg_SwapCompositorFrameAck::ID, sink_->GetMessageAt(0)->type());
1296 sink_->ClearMessages();
1297 EXPECT_EQ(size2.ToString(), view_->GetRequestedRendererSize().ToString());
1299 // Receive a frame of the correct size, should not be skipped and, and should
1300 // produce a Resize message after the commit.
1301 view_->OnSwapCompositorFrame(
1302 0, MakeDelegatedFrame(1.f, size2, gfx::Rect(size2)));
1303 // No frame ack yet.
1304 EXPECT_EQ(0u, sink_->message_count());
1305 EXPECT_EQ(size2.ToString(), view_->GetRequestedRendererSize().ToString());
1307 // Wait for commit, then we should unlock the compositor and send a Resize
1308 // message (and a frame ack)
1309 ui::DrawWaiterForTest::WaitForCommit(
1310 root_window->GetHost()->compositor());
1311 EXPECT_EQ(size3.ToString(), view_->GetRequestedRendererSize().ToString());
1312 EXPECT_EQ(2u, sink_->message_count());
1313 EXPECT_EQ(ViewMsg_SwapCompositorFrameAck::ID, sink_->GetMessageAt(0)->type());
1315 const IPC::Message* msg = sink_->GetMessageAt(1);
1316 EXPECT_EQ(ViewMsg_Resize::ID, msg->type());
1317 ViewMsg_Resize::Param params;
1318 ViewMsg_Resize::Read(msg, &params);
1319 EXPECT_EQ(size3.ToString(), params.a.new_size.ToString());
1321 update_params.view_size = size3;
1322 widget_host_->OnMessageReceived(
1323 ViewHostMsg_UpdateRect(widget_host_->GetRoutingID(), update_params));
1324 sink_->ClearMessages();
1327 // Skipped frames should not drop their damage.
1328 TEST_F(RenderWidgetHostViewAuraTest, SkippedDelegatedFrames) {
1329 gfx::Rect view_rect(100, 100);
1330 gfx::Size frame_size = view_rect.size();
1332 view_->InitAsChild(NULL);
1333 aura::client::ParentWindowWithContext(
1334 view_->GetNativeView(),
1335 parent_view_->GetNativeView()->GetRootWindow(),
1336 gfx::Rect());
1337 view_->SetSize(view_rect.size());
1339 MockWindowObserver observer;
1340 view_->window_->AddObserver(&observer);
1342 // A full frame of damage.
1343 EXPECT_CALL(observer, OnWindowPaintScheduled(view_->window_, view_rect));
1344 view_->OnSwapCompositorFrame(
1345 0, MakeDelegatedFrame(1.f, frame_size, view_rect));
1346 testing::Mock::VerifyAndClearExpectations(&observer);
1347 view_->RunOnCompositingDidCommit();
1349 // A partial damage frame.
1350 gfx::Rect partial_view_rect(30, 30, 20, 20);
1351 EXPECT_CALL(observer,
1352 OnWindowPaintScheduled(view_->window_, partial_view_rect));
1353 view_->OnSwapCompositorFrame(
1354 0, MakeDelegatedFrame(1.f, frame_size, partial_view_rect));
1355 testing::Mock::VerifyAndClearExpectations(&observer);
1356 view_->RunOnCompositingDidCommit();
1358 // Lock the compositor. Now we should drop frames.
1359 view_rect = gfx::Rect(150, 150);
1360 view_->SetSize(view_rect.size());
1362 // This frame is dropped.
1363 gfx::Rect dropped_damage_rect_1(10, 20, 30, 40);
1364 EXPECT_CALL(observer, OnWindowPaintScheduled(_, _)).Times(0);
1365 view_->OnSwapCompositorFrame(
1366 0, MakeDelegatedFrame(1.f, frame_size, dropped_damage_rect_1));
1367 testing::Mock::VerifyAndClearExpectations(&observer);
1368 view_->RunOnCompositingDidCommit();
1370 gfx::Rect dropped_damage_rect_2(40, 50, 10, 20);
1371 EXPECT_CALL(observer, OnWindowPaintScheduled(_, _)).Times(0);
1372 view_->OnSwapCompositorFrame(
1373 0, MakeDelegatedFrame(1.f, frame_size, dropped_damage_rect_2));
1374 testing::Mock::VerifyAndClearExpectations(&observer);
1375 view_->RunOnCompositingDidCommit();
1377 // Unlock the compositor. This frame should damage everything.
1378 frame_size = view_rect.size();
1380 gfx::Rect new_damage_rect(5, 6, 10, 10);
1381 EXPECT_CALL(observer,
1382 OnWindowPaintScheduled(view_->window_, view_rect));
1383 view_->OnSwapCompositorFrame(
1384 0, MakeDelegatedFrame(1.f, frame_size, new_damage_rect));
1385 testing::Mock::VerifyAndClearExpectations(&observer);
1386 view_->RunOnCompositingDidCommit();
1388 // A partial damage frame, this should not be dropped.
1389 EXPECT_CALL(observer,
1390 OnWindowPaintScheduled(view_->window_, partial_view_rect));
1391 view_->OnSwapCompositorFrame(
1392 0, MakeDelegatedFrame(1.f, frame_size, partial_view_rect));
1393 testing::Mock::VerifyAndClearExpectations(&observer);
1394 view_->RunOnCompositingDidCommit();
1397 // Resize to something empty.
1398 view_rect = gfx::Rect(100, 0);
1399 view_->SetSize(view_rect.size());
1401 // We're never expecting empty frames, resize to something non-empty.
1402 view_rect = gfx::Rect(100, 100);
1403 view_->SetSize(view_rect.size());
1405 // This frame should not be dropped.
1406 EXPECT_CALL(observer, OnWindowPaintScheduled(view_->window_, view_rect));
1407 view_->OnSwapCompositorFrame(
1408 0, MakeDelegatedFrame(1.f, view_rect.size(), view_rect));
1409 testing::Mock::VerifyAndClearExpectations(&observer);
1410 view_->RunOnCompositingDidCommit();
1412 view_->window_->RemoveObserver(&observer);
1415 TEST_F(RenderWidgetHostViewAuraTest, OutputSurfaceIdChange) {
1416 gfx::Rect view_rect(100, 100);
1417 gfx::Size frame_size = view_rect.size();
1419 view_->InitAsChild(NULL);
1420 aura::client::ParentWindowWithContext(
1421 view_->GetNativeView(),
1422 parent_view_->GetNativeView()->GetRootWindow(),
1423 gfx::Rect());
1424 view_->SetSize(view_rect.size());
1426 MockWindowObserver observer;
1427 view_->window_->AddObserver(&observer);
1429 // Swap a frame.
1430 EXPECT_CALL(observer, OnWindowPaintScheduled(view_->window_, view_rect));
1431 view_->OnSwapCompositorFrame(
1432 0, MakeDelegatedFrame(1.f, frame_size, view_rect));
1433 testing::Mock::VerifyAndClearExpectations(&observer);
1434 view_->RunOnCompositingDidCommit();
1436 // Swap a frame with a different surface id.
1437 EXPECT_CALL(observer, OnWindowPaintScheduled(view_->window_, view_rect));
1438 view_->OnSwapCompositorFrame(
1439 1, MakeDelegatedFrame(1.f, frame_size, view_rect));
1440 testing::Mock::VerifyAndClearExpectations(&observer);
1441 view_->RunOnCompositingDidCommit();
1443 // Swap an empty frame, with a different surface id.
1444 view_->OnSwapCompositorFrame(
1445 2, MakeDelegatedFrame(1.f, gfx::Size(), gfx::Rect()));
1446 testing::Mock::VerifyAndClearExpectations(&observer);
1447 view_->RunOnCompositingDidCommit();
1449 // Swap another frame, with a different surface id.
1450 EXPECT_CALL(observer, OnWindowPaintScheduled(view_->window_, view_rect));
1451 view_->OnSwapCompositorFrame(3,
1452 MakeDelegatedFrame(1.f, frame_size, view_rect));
1453 testing::Mock::VerifyAndClearExpectations(&observer);
1454 view_->RunOnCompositingDidCommit();
1456 view_->window_->RemoveObserver(&observer);
1459 TEST_F(RenderWidgetHostViewAuraTest, DiscardDelegatedFrames) {
1460 size_t max_renderer_frames =
1461 RendererFrameManager::GetInstance()->max_number_of_saved_frames();
1462 ASSERT_LE(2u, max_renderer_frames);
1463 size_t renderer_count = max_renderer_frames + 1;
1464 gfx::Rect view_rect(100, 100);
1465 gfx::Size frame_size = view_rect.size();
1466 DCHECK_EQ(0u, HostSharedBitmapManager::current()->AllocatedBitmapCount());
1468 scoped_ptr<RenderWidgetHostImpl * []> hosts(
1469 new RenderWidgetHostImpl* [renderer_count]);
1470 scoped_ptr<FakeRenderWidgetHostViewAura * []> views(
1471 new FakeRenderWidgetHostViewAura* [renderer_count]);
1473 // Create a bunch of renderers.
1474 for (size_t i = 0; i < renderer_count; ++i) {
1475 hosts[i] = new RenderWidgetHostImpl(
1476 &delegate_, process_host_, MSG_ROUTING_NONE, false);
1477 hosts[i]->Init();
1478 views[i] = new FakeRenderWidgetHostViewAura(hosts[i]);
1479 views[i]->InitAsChild(NULL);
1480 aura::client::ParentWindowWithContext(
1481 views[i]->GetNativeView(),
1482 parent_view_->GetNativeView()->GetRootWindow(),
1483 gfx::Rect());
1484 views[i]->SetSize(view_rect.size());
1487 // Make each renderer visible, and swap a frame on it, then make it invisible.
1488 for (size_t i = 0; i < renderer_count; ++i) {
1489 views[i]->WasShown();
1490 views[i]->OnSwapCompositorFrame(
1491 1, MakeDelegatedFrame(1.f, frame_size, view_rect));
1492 EXPECT_TRUE(views[i]->frame_provider());
1493 views[i]->WasHidden();
1496 // There should be max_renderer_frames with a frame in it, and one without it.
1497 // Since the logic is LRU eviction, the first one should be without.
1498 EXPECT_FALSE(views[0]->frame_provider());
1499 for (size_t i = 1; i < renderer_count; ++i)
1500 EXPECT_TRUE(views[i]->frame_provider());
1502 // LRU renderer is [0], make it visible, it shouldn't evict anything yet.
1503 views[0]->WasShown();
1504 EXPECT_FALSE(views[0]->frame_provider());
1505 EXPECT_TRUE(views[1]->frame_provider());
1507 // Swap a frame on it, it should evict the next LRU [1].
1508 views[0]->OnSwapCompositorFrame(
1509 1, MakeDelegatedFrame(1.f, frame_size, view_rect));
1510 EXPECT_TRUE(views[0]->frame_provider());
1511 EXPECT_FALSE(views[1]->frame_provider());
1512 views[0]->WasHidden();
1514 // LRU renderer is [1], still hidden. Swap a frame on it, it should evict
1515 // the next LRU [2].
1516 views[1]->OnSwapCompositorFrame(
1517 1, MakeDelegatedFrame(1.f, frame_size, view_rect));
1518 EXPECT_TRUE(views[0]->frame_provider());
1519 EXPECT_TRUE(views[1]->frame_provider());
1520 EXPECT_FALSE(views[2]->frame_provider());
1521 for (size_t i = 3; i < renderer_count; ++i)
1522 EXPECT_TRUE(views[i]->frame_provider());
1524 // Make all renderers but [0] visible and swap a frame on them, keep [0]
1525 // hidden, it becomes the LRU.
1526 for (size_t i = 1; i < renderer_count; ++i) {
1527 views[i]->WasShown();
1528 views[i]->OnSwapCompositorFrame(
1529 1, MakeDelegatedFrame(1.f, frame_size, view_rect));
1530 EXPECT_TRUE(views[i]->frame_provider());
1532 EXPECT_FALSE(views[0]->frame_provider());
1534 // Swap a frame on [0], it should be evicted immediately.
1535 views[0]->OnSwapCompositorFrame(
1536 1, MakeDelegatedFrame(1.f, frame_size, view_rect));
1537 EXPECT_FALSE(views[0]->frame_provider());
1539 // Make [0] visible, and swap a frame on it. Nothing should be evicted
1540 // although we're above the limit.
1541 views[0]->WasShown();
1542 views[0]->OnSwapCompositorFrame(
1543 1, MakeDelegatedFrame(1.f, frame_size, view_rect));
1544 for (size_t i = 0; i < renderer_count; ++i)
1545 EXPECT_TRUE(views[i]->frame_provider());
1547 // Make [0] hidden, it should evict its frame.
1548 views[0]->WasHidden();
1549 EXPECT_FALSE(views[0]->frame_provider());
1551 for (size_t i = 0; i < renderer_count - 1; ++i)
1552 views[i]->WasHidden();
1554 // Allocate enough bitmaps so that two frames (proportionally) would be
1555 // enough hit the handle limit.
1556 int handles_per_frame = 5;
1557 RendererFrameManager::GetInstance()->set_max_handles(handles_per_frame * 2);
1559 for (size_t i = 0; i < (renderer_count - 1) * handles_per_frame; i++) {
1560 HostSharedBitmapManager::current()->ChildAllocatedSharedBitmap(
1562 base::SharedMemory::NULLHandle(),
1563 base::GetCurrentProcessHandle(),
1564 cc::SharedBitmap::GenerateId());
1567 // Hiding this last bitmap should evict all but two frames.
1568 views[renderer_count - 1]->WasHidden();
1569 for (size_t i = 0; i < renderer_count; ++i) {
1570 if (i + 2 < renderer_count)
1571 EXPECT_FALSE(views[i]->frame_provider());
1572 else
1573 EXPECT_TRUE(views[i]->frame_provider());
1575 HostSharedBitmapManager::current()->ProcessRemoved(
1576 base::GetCurrentProcessHandle());
1577 RendererFrameManager::GetInstance()->set_max_handles(
1578 base::SharedMemory::GetHandleLimit());
1580 for (size_t i = 0; i < renderer_count; ++i) {
1581 views[i]->Destroy();
1582 delete hosts[i];
1586 TEST_F(RenderWidgetHostViewAuraTest, DiscardDelegatedFramesWithLocking) {
1587 size_t max_renderer_frames =
1588 RendererFrameManager::GetInstance()->max_number_of_saved_frames();
1589 ASSERT_LE(2u, max_renderer_frames);
1590 size_t renderer_count = max_renderer_frames + 1;
1591 gfx::Rect view_rect(100, 100);
1592 gfx::Size frame_size = view_rect.size();
1593 DCHECK_EQ(0u, HostSharedBitmapManager::current()->AllocatedBitmapCount());
1595 scoped_ptr<RenderWidgetHostImpl * []> hosts(
1596 new RenderWidgetHostImpl* [renderer_count]);
1597 scoped_ptr<FakeRenderWidgetHostViewAura * []> views(
1598 new FakeRenderWidgetHostViewAura* [renderer_count]);
1600 // Create a bunch of renderers.
1601 for (size_t i = 0; i < renderer_count; ++i) {
1602 hosts[i] = new RenderWidgetHostImpl(
1603 &delegate_, process_host_, MSG_ROUTING_NONE, false);
1604 hosts[i]->Init();
1605 views[i] = new FakeRenderWidgetHostViewAura(hosts[i]);
1606 views[i]->InitAsChild(NULL);
1607 aura::client::ParentWindowWithContext(
1608 views[i]->GetNativeView(),
1609 parent_view_->GetNativeView()->GetRootWindow(),
1610 gfx::Rect());
1611 views[i]->SetSize(view_rect.size());
1614 // Make each renderer visible and swap a frame on it. No eviction should
1615 // occur because all frames are visible.
1616 for (size_t i = 0; i < renderer_count; ++i) {
1617 views[i]->WasShown();
1618 views[i]->OnSwapCompositorFrame(
1619 1, MakeDelegatedFrame(1.f, frame_size, view_rect));
1620 EXPECT_TRUE(views[i]->frame_provider());
1623 // If we hide [0], then [0] should be evicted.
1624 views[0]->WasHidden();
1625 EXPECT_FALSE(views[0]->frame_provider());
1627 // If we lock [0] before hiding it, then [0] should not be evicted.
1628 views[0]->WasShown();
1629 views[0]->OnSwapCompositorFrame(
1630 1, MakeDelegatedFrame(1.f, frame_size, view_rect));
1631 EXPECT_TRUE(views[0]->frame_provider());
1632 views[0]->GetDelegatedFrameHost()->LockResources();
1633 views[0]->WasHidden();
1634 EXPECT_TRUE(views[0]->frame_provider());
1636 // If we unlock [0] now, then [0] should be evicted.
1637 views[0]->GetDelegatedFrameHost()->UnlockResources();
1638 EXPECT_FALSE(views[0]->frame_provider());
1640 for (size_t i = 0; i < renderer_count; ++i) {
1641 views[i]->Destroy();
1642 delete hosts[i];
1646 TEST_F(RenderWidgetHostViewAuraTest, SoftwareDPIChange) {
1647 gfx::Rect view_rect(100, 100);
1648 gfx::Size frame_size(100, 100);
1650 view_->InitAsChild(NULL);
1651 aura::client::ParentWindowWithContext(
1652 view_->GetNativeView(),
1653 parent_view_->GetNativeView()->GetRootWindow(),
1654 gfx::Rect());
1655 view_->SetSize(view_rect.size());
1656 view_->WasShown();
1658 // With a 1x DPI UI and 1x DPI Renderer.
1659 view_->OnSwapCompositorFrame(
1660 1, MakeDelegatedFrame(1.f, frame_size, gfx::Rect(frame_size)));
1662 // Save the frame provider.
1663 scoped_refptr<cc::DelegatedFrameProvider> frame_provider =
1664 view_->frame_provider();
1666 // This frame will have the same number of physical pixels, but has a new
1667 // scale on it.
1668 view_->OnSwapCompositorFrame(
1669 1, MakeDelegatedFrame(2.f, frame_size, gfx::Rect(frame_size)));
1671 // When we get a new frame with the same frame size in physical pixels, but a
1672 // different scale, we should generate a new frame provider, as the final
1673 // result will need to be scaled differently to the screen.
1674 EXPECT_NE(frame_provider.get(), view_->frame_provider());
1677 class RenderWidgetHostViewAuraCopyRequestTest
1678 : public RenderWidgetHostViewAuraShutdownTest {
1679 public:
1680 RenderWidgetHostViewAuraCopyRequestTest()
1681 : callback_count_(0), result_(false) {}
1683 void CallbackMethod(const base::Closure& quit_closure, bool result) {
1684 result_ = result;
1685 callback_count_++;
1686 quit_closure.Run();
1689 int callback_count_;
1690 bool result_;
1692 private:
1693 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraCopyRequestTest);
1696 TEST_F(RenderWidgetHostViewAuraCopyRequestTest, DestroyedAfterCopyRequest) {
1697 base::RunLoop run_loop;
1699 gfx::Rect view_rect(100, 100);
1700 scoped_ptr<cc::CopyOutputRequest> request;
1702 view_->InitAsChild(NULL);
1703 aura::client::ParentWindowWithContext(
1704 view_->GetNativeView(),
1705 parent_view_->GetNativeView()->GetRootWindow(),
1706 gfx::Rect());
1707 view_->SetSize(view_rect.size());
1708 view_->WasShown();
1710 scoped_ptr<FakeFrameSubscriber> frame_subscriber(new FakeFrameSubscriber(
1711 view_rect.size(),
1712 base::Bind(&RenderWidgetHostViewAuraCopyRequestTest::CallbackMethod,
1713 base::Unretained(this),
1714 run_loop.QuitClosure())));
1716 EXPECT_EQ(0, callback_count_);
1717 EXPECT_FALSE(view_->last_copy_request_);
1719 view_->BeginFrameSubscription(
1720 frame_subscriber.PassAs<RenderWidgetHostViewFrameSubscriber>());
1721 view_->OnSwapCompositorFrame(
1722 1, MakeDelegatedFrame(1.f, view_rect.size(), gfx::Rect(view_rect)));
1724 EXPECT_EQ(0, callback_count_);
1725 EXPECT_TRUE(view_->last_copy_request_);
1726 EXPECT_TRUE(view_->last_copy_request_->has_texture_mailbox());
1727 request = view_->last_copy_request_.Pass();
1729 // Send back the mailbox included in the request. There's no release callback
1730 // since the mailbox came from the RWHVA originally.
1731 request->SendTextureResult(view_rect.size(),
1732 request->texture_mailbox(),
1733 scoped_ptr<cc::SingleReleaseCallback>());
1735 // This runs until the callback happens.
1736 run_loop.Run();
1738 // The callback should succeed.
1739 EXPECT_EQ(1, callback_count_);
1740 EXPECT_TRUE(result_);
1742 view_->OnSwapCompositorFrame(
1743 1, MakeDelegatedFrame(1.f, view_rect.size(), gfx::Rect(view_rect)));
1745 EXPECT_EQ(1, callback_count_);
1746 request = view_->last_copy_request_.Pass();
1748 // Destroy the RenderWidgetHostViewAura and ImageTransportFactory.
1749 TearDownEnvironment();
1751 // Send back the mailbox included in the request. There's no release callback
1752 // since the mailbox came from the RWHVA originally.
1753 request->SendTextureResult(view_rect.size(),
1754 request->texture_mailbox(),
1755 scoped_ptr<cc::SingleReleaseCallback>());
1757 // Because the copy request callback may be holding state within it, that
1758 // state must handle the RWHVA and ImageTransportFactory going away before the
1759 // callback is called. This test passes if it does not crash as a result of
1760 // these things being destroyed.
1761 EXPECT_EQ(2, callback_count_);
1762 EXPECT_FALSE(result_);
1765 TEST_F(RenderWidgetHostViewAuraTest, VisibleViewportTest) {
1766 gfx::Rect view_rect(100, 100);
1768 view_->InitAsChild(NULL);
1769 aura::client::ParentWindowWithContext(
1770 view_->GetNativeView(),
1771 parent_view_->GetNativeView()->GetRootWindow(),
1772 gfx::Rect());
1773 view_->SetSize(view_rect.size());
1774 view_->WasShown();
1776 // Defaults to full height of the view.
1777 EXPECT_EQ(100, view_->GetVisibleViewportSize().height());
1779 widget_host_->ResetSizeAndRepaintPendingFlags();
1780 sink_->ClearMessages();
1781 view_->SetInsets(gfx::Insets(0, 0, 40, 0));
1783 EXPECT_EQ(60, view_->GetVisibleViewportSize().height());
1785 const IPC::Message *message = sink_->GetFirstMessageMatching(
1786 ViewMsg_Resize::ID);
1787 ASSERT_TRUE(message != NULL);
1789 ViewMsg_Resize::Param params;
1790 ViewMsg_Resize::Read(message, &params);
1791 EXPECT_EQ(60, params.a.visible_viewport_size.height());
1794 // Ensures that touch event positions are never truncated to integers.
1795 TEST_F(RenderWidgetHostViewAuraTest, TouchEventPositionsArentRounded) {
1796 const float kX = 30.58f;
1797 const float kY = 50.23f;
1799 view_->InitAsChild(NULL);
1800 view_->Show();
1802 ui::TouchEvent press(ui::ET_TOUCH_PRESSED,
1803 gfx::PointF(kX, kY),
1805 ui::EventTimeForNow());
1807 view_->OnTouchEvent(&press);
1808 EXPECT_EQ(blink::WebInputEvent::TouchStart, view_->touch_event_.type);
1809 EXPECT_TRUE(view_->touch_event_.cancelable);
1810 EXPECT_EQ(1U, view_->touch_event_.touchesLength);
1811 EXPECT_EQ(blink::WebTouchPoint::StatePressed,
1812 view_->touch_event_.touches[0].state);
1813 EXPECT_EQ(kX, view_->touch_event_.touches[0].screenPosition.x);
1814 EXPECT_EQ(kX, view_->touch_event_.touches[0].position.x);
1815 EXPECT_EQ(kY, view_->touch_event_.touches[0].screenPosition.y);
1816 EXPECT_EQ(kY, view_->touch_event_.touches[0].position.y);
1819 // Tests that scroll ACKs are correctly handled by the overscroll-navigation
1820 // controller.
1821 TEST_F(RenderWidgetHostViewAuraOverscrollTest, WheelScrollEventOverscrolls) {
1822 SetUpOverscrollEnvironment();
1824 // Simulate wheel events.
1825 SimulateWheelEvent(-5, 0, 0, true); // sent directly
1826 SimulateWheelEvent(-1, 1, 0, true); // enqueued
1827 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
1828 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
1829 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
1830 SimulateWheelEvent(-20, 6, 1, true); // enqueued, different modifiers
1831 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
1832 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1834 // Receive ACK the first wheel event as not processed.
1835 SendInputEventACK(WebInputEvent::MouseWheel,
1836 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1837 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
1838 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
1839 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1841 // Receive ACK for the second (coalesced) event as not processed. This will
1842 // start a back navigation. However, this will also cause the queued next
1843 // event to be sent to the renderer. But since overscroll navigation has
1844 // started, that event will also be included in the overscroll computation
1845 // instead of being sent to the renderer. So the result will be an overscroll
1846 // back navigation, and no event will be sent to the renderer.
1847 SendInputEventACK(WebInputEvent::MouseWheel,
1848 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1849 EXPECT_EQ(OVERSCROLL_WEST, overscroll_mode());
1850 EXPECT_EQ(OVERSCROLL_WEST, overscroll_delegate()->current_mode());
1851 EXPECT_EQ(-81.f, overscroll_delta_x());
1852 EXPECT_EQ(-31.f, overscroll_delegate()->delta_x());
1853 EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
1854 EXPECT_EQ(0U, sink_->message_count());
1856 // Send a mouse-move event. This should cancel the overscroll navigation.
1857 SimulateMouseMove(5, 10, 0);
1858 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
1859 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
1860 EXPECT_EQ(1U, sink_->message_count());
1863 // Tests that if some scroll events are consumed towards the start, then
1864 // subsequent scrolls do not horizontal overscroll.
1865 TEST_F(RenderWidgetHostViewAuraOverscrollTest,
1866 WheelScrollConsumedDoNotHorizOverscroll) {
1867 SetUpOverscrollEnvironment();
1869 // Simulate wheel events.
1870 SimulateWheelEvent(-5, 0, 0, true); // sent directly
1871 SimulateWheelEvent(-1, -1, 0, true); // enqueued
1872 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
1873 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
1874 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
1875 SimulateWheelEvent(-20, 6, 1, true); // enqueued, different modifiers
1876 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
1877 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1879 // Receive ACK the first wheel event as processed.
1880 SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED);
1881 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
1882 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
1883 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1885 // Receive ACK for the second (coalesced) event as not processed. This should
1886 // not initiate overscroll, since the beginning of the scroll has been
1887 // consumed. The queued event with different modifiers should be sent to the
1888 // renderer.
1889 SendInputEventACK(WebInputEvent::MouseWheel,
1890 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1891 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
1892 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1894 SendInputEventACK(WebInputEvent::MouseWheel,
1895 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1896 EXPECT_EQ(0U, sink_->message_count());
1897 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
1899 // Indicate the end of the scrolling from the touchpad.
1900 SimulateGestureFlingStartEvent(-1200.f, 0.f, blink::WebGestureDeviceTouchpad);
1901 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1903 // Start another scroll. This time, do not consume any scroll events.
1904 SimulateWheelEvent(0, -5, 0, true); // sent directly
1905 SimulateWheelEvent(0, -1, 0, true); // enqueued
1906 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
1907 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
1908 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
1909 SimulateWheelEvent(-20, 6, 1, true); // enqueued, different modifiers
1910 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
1911 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1913 // Receive ACK for the first wheel and the subsequent coalesced event as not
1914 // processed. This should start a back-overscroll.
1915 SendInputEventACK(WebInputEvent::MouseWheel,
1916 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1917 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
1918 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
1919 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1920 SendInputEventACK(WebInputEvent::MouseWheel,
1921 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1922 EXPECT_EQ(OVERSCROLL_WEST, overscroll_mode());
1925 // Tests that wheel-scrolling correctly turns overscroll on and off.
1926 TEST_F(RenderWidgetHostViewAuraOverscrollTest, WheelScrollOverscrollToggle) {
1927 SetUpOverscrollEnvironment();
1929 // Send a wheel event. ACK the event as not processed. This should not
1930 // initiate an overscroll gesture since it doesn't cross the threshold yet.
1931 SimulateWheelEvent(10, 0, 0, true);
1932 SendInputEventACK(WebInputEvent::MouseWheel,
1933 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1934 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
1935 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
1936 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1938 // Scroll some more so as to not overscroll.
1939 SimulateWheelEvent(10, 0, 0, true);
1940 SendInputEventACK(WebInputEvent::MouseWheel,
1941 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1942 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
1943 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
1944 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1946 // Scroll some more to initiate an overscroll.
1947 SimulateWheelEvent(40, 0, 0, true);
1948 SendInputEventACK(WebInputEvent::MouseWheel,
1949 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1950 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
1951 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
1952 EXPECT_EQ(60.f, overscroll_delta_x());
1953 EXPECT_EQ(10.f, overscroll_delegate()->delta_x());
1954 EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
1955 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1957 // Scroll in the reverse direction enough to abort the overscroll.
1958 SimulateWheelEvent(-20, 0, 0, true);
1959 EXPECT_EQ(0U, sink_->message_count());
1960 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
1961 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
1963 // Continue to scroll in the reverse direction.
1964 SimulateWheelEvent(-20, 0, 0, true);
1965 SendInputEventACK(WebInputEvent::MouseWheel,
1966 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1967 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
1968 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
1969 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1971 // Continue to scroll in the reverse direction enough to initiate overscroll
1972 // in that direction.
1973 SimulateWheelEvent(-55, 0, 0, true);
1974 EXPECT_EQ(1U, sink_->message_count());
1975 SendInputEventACK(WebInputEvent::MouseWheel,
1976 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1977 EXPECT_EQ(OVERSCROLL_WEST, overscroll_mode());
1978 EXPECT_EQ(OVERSCROLL_WEST, overscroll_delegate()->current_mode());
1979 EXPECT_EQ(-75.f, overscroll_delta_x());
1980 EXPECT_EQ(-25.f, overscroll_delegate()->delta_x());
1981 EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
1984 TEST_F(RenderWidgetHostViewAuraOverscrollTest,
1985 ScrollEventsOverscrollWithFling) {
1986 SetUpOverscrollEnvironment();
1988 // Send a wheel event. ACK the event as not processed. This should not
1989 // initiate an overscroll gesture since it doesn't cross the threshold yet.
1990 SimulateWheelEvent(10, 0, 0, true);
1991 SendInputEventACK(WebInputEvent::MouseWheel,
1992 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1993 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
1994 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
1995 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1997 // Scroll some more so as to not overscroll.
1998 SimulateWheelEvent(20, 0, 0, true);
1999 EXPECT_EQ(1U, sink_->message_count());
2000 SendInputEventACK(WebInputEvent::MouseWheel,
2001 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2002 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2003 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2004 sink_->ClearMessages();
2006 // Scroll some more to initiate an overscroll.
2007 SimulateWheelEvent(30, 0, 0, true);
2008 SendInputEventACK(WebInputEvent::MouseWheel,
2009 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2010 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2011 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2012 EXPECT_EQ(60.f, overscroll_delta_x());
2013 EXPECT_EQ(10.f, overscroll_delegate()->delta_x());
2014 EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
2015 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2017 // Send a fling start, but with a small velocity, so that the overscroll is
2018 // aborted. The fling should proceed to the renderer, through the gesture
2019 // event filter.
2020 SimulateGestureFlingStartEvent(0.f, 0.1f, blink::WebGestureDeviceTouchpad);
2021 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2022 EXPECT_EQ(1U, sink_->message_count());
2025 // Same as ScrollEventsOverscrollWithFling, but with zero velocity. Checks that
2026 // the zero-velocity fling does not reach the renderer.
2027 TEST_F(RenderWidgetHostViewAuraOverscrollTest,
2028 ScrollEventsOverscrollWithZeroFling) {
2029 SetUpOverscrollEnvironment();
2031 // Send a wheel event. ACK the event as not processed. This should not
2032 // initiate an overscroll gesture since it doesn't cross the threshold yet.
2033 SimulateWheelEvent(10, 0, 0, true);
2034 SendInputEventACK(WebInputEvent::MouseWheel,
2035 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2036 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2037 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2038 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2040 // Scroll some more so as to not overscroll.
2041 SimulateWheelEvent(20, 0, 0, true);
2042 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2043 SendInputEventACK(WebInputEvent::MouseWheel,
2044 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2045 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2046 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
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
2061 // event filter.
2062 SimulateGestureFlingStartEvent(10.f, 0.f, blink::WebGestureDeviceTouchpad);
2063 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2064 EXPECT_EQ(1U, sink_->message_count());
2067 // Tests that a fling in the opposite direction of the overscroll cancels the
2068 // overscroll nav instead of completing it.
2069 TEST_F(RenderWidgetHostViewAuraOverscrollTest, ReverseFlingCancelsOverscroll) {
2070 SetUpOverscrollEnvironment();
2073 // Start and end a gesture in the same direction without processing the
2074 // gesture events in the renderer. This should initiate and complete an
2075 // overscroll navigation.
2076 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2077 blink::WebGestureDeviceTouchscreen);
2078 SimulateGestureScrollUpdateEvent(300, -5, 0);
2079 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2080 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2081 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2082 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2083 sink_->ClearMessages();
2085 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
2086 blink::WebGestureDeviceTouchscreen);
2087 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->completed_mode());
2088 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2089 EXPECT_EQ(1U, sink_->message_count());
2093 // Start over, except instead of ending the gesture with ScrollEnd, end it
2094 // with a FlingStart, with velocity in the reverse direction. This should
2095 // initiate an overscroll navigation, but it should be cancelled because of
2096 // the fling in the opposite direction.
2097 overscroll_delegate()->Reset();
2098 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2099 blink::WebGestureDeviceTouchscreen);
2100 SimulateGestureScrollUpdateEvent(-300, -5, 0);
2101 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2102 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2103 EXPECT_EQ(OVERSCROLL_WEST, overscroll_mode());
2104 EXPECT_EQ(OVERSCROLL_WEST, overscroll_delegate()->current_mode());
2105 sink_->ClearMessages();
2107 SimulateGestureFlingStartEvent(100, 0, blink::WebGestureDeviceTouchscreen);
2108 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->completed_mode());
2109 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2110 EXPECT_EQ(1U, sink_->message_count());
2114 // Tests that touch-scroll events are handled correctly by the overscroll
2115 // controller. This also tests that the overscroll controller and the
2116 // gesture-event filter play nice with each other.
2117 TEST_F(RenderWidgetHostViewAuraOverscrollTest, GestureScrollOverscrolls) {
2118 SetUpOverscrollEnvironment();
2120 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2121 blink::WebGestureDeviceTouchscreen);
2122 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2123 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2124 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2126 // Send another gesture event and ACK as not being processed. This should
2127 // initiate the navigation gesture.
2128 SimulateGestureScrollUpdateEvent(55, -5, 0);
2129 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2130 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2131 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2132 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2133 EXPECT_EQ(55.f, overscroll_delta_x());
2134 EXPECT_EQ(-5.f, overscroll_delta_y());
2135 EXPECT_EQ(5.f, overscroll_delegate()->delta_x());
2136 EXPECT_EQ(-5.f, overscroll_delegate()->delta_y());
2137 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2139 // Send another gesture update event. This event should be consumed by the
2140 // controller, and not be forwarded to the renderer. The gesture-event filter
2141 // should not also receive this event.
2142 SimulateGestureScrollUpdateEvent(10, -5, 0);
2143 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2144 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2145 EXPECT_EQ(65.f, overscroll_delta_x());
2146 EXPECT_EQ(-10.f, overscroll_delta_y());
2147 EXPECT_EQ(15.f, overscroll_delegate()->delta_x());
2148 EXPECT_EQ(-10.f, overscroll_delegate()->delta_y());
2149 EXPECT_EQ(0U, sink_->message_count());
2151 // Now send a scroll end. This should cancel the overscroll gesture, and send
2152 // the event to the renderer. The gesture-event filter should receive this
2153 // event.
2154 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
2155 blink::WebGestureDeviceTouchscreen);
2156 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2157 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2158 EXPECT_EQ(1U, sink_->message_count());
2161 // Tests that if the page is scrolled because of a scroll-gesture, then that
2162 // particular scroll sequence never generates overscroll if the scroll direction
2163 // is horizontal.
2164 TEST_F(RenderWidgetHostViewAuraOverscrollTest,
2165 GestureScrollConsumedHorizontal) {
2166 SetUpOverscrollEnvironment();
2168 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2169 blink::WebGestureDeviceTouchscreen);
2170 SimulateGestureScrollUpdateEvent(10, 0, 0);
2172 // Start scrolling on content. ACK both events as being processed.
2173 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2174 INPUT_EVENT_ACK_STATE_CONSUMED);
2175 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2176 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2177 sink_->ClearMessages();
2179 // Send another gesture event and ACK as not being processed. This should
2180 // not initiate overscroll because the beginning of the scroll event did
2181 // scroll some content on the page. Since there was no overscroll, the event
2182 // should reach the renderer.
2183 SimulateGestureScrollUpdateEvent(55, 0, 0);
2184 EXPECT_EQ(1U, sink_->message_count());
2185 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2186 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2187 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2190 // Tests that the overscroll controller plays nice with touch-scrolls and the
2191 // gesture event filter with debounce filtering turned on.
2192 TEST_F(RenderWidgetHostViewAuraOverscrollTest,
2193 GestureScrollDebounceOverscrolls) {
2194 SetUpOverscrollEnvironmentWithDebounce(100);
2196 // Start scrolling. Receive ACK as it being processed.
2197 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2198 blink::WebGestureDeviceTouchscreen);
2199 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2201 // Send update events.
2202 SimulateGestureScrollUpdateEvent(25, 0, 0);
2203 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2205 // Quickly end and restart the scroll gesture. These two events should get
2206 // discarded.
2207 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
2208 blink::WebGestureDeviceTouchscreen);
2209 EXPECT_EQ(0U, sink_->message_count());
2211 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2212 blink::WebGestureDeviceTouchscreen);
2213 EXPECT_EQ(0U, sink_->message_count());
2215 // Send another update event. This should get into the queue.
2216 SimulateGestureScrollUpdateEvent(30, 0, 0);
2217 EXPECT_EQ(0U, sink_->message_count());
2219 // Receive an ACK for the first scroll-update event as not being processed.
2220 // This will contribute to the overscroll gesture, but not enough for the
2221 // overscroll controller to start consuming gesture events. This also cause
2222 // the queued gesture event to be forwarded to the renderer.
2223 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2224 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2225 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2226 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2227 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2229 // Send another update event. This should get into the queue.
2230 SimulateGestureScrollUpdateEvent(10, 0, 0);
2231 EXPECT_EQ(0U, sink_->message_count());
2233 // Receive an ACK for the second scroll-update event as not being processed.
2234 // This will now initiate an overscroll. This will also cause the queued
2235 // gesture event to be released. But instead of going to the renderer, it will
2236 // be consumed by the overscroll controller.
2237 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2238 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2239 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2240 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2241 EXPECT_EQ(65.f, overscroll_delta_x());
2242 EXPECT_EQ(15.f, overscroll_delegate()->delta_x());
2243 EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
2244 EXPECT_EQ(0U, sink_->message_count());
2247 // Tests that the gesture debounce timer plays nice with the overscroll
2248 // controller.
2249 TEST_F(RenderWidgetHostViewAuraOverscrollTest,
2250 GestureScrollDebounceTimerOverscroll) {
2251 SetUpOverscrollEnvironmentWithDebounce(10);
2253 // Start scrolling. Receive ACK as it being processed.
2254 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2255 blink::WebGestureDeviceTouchscreen);
2256 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2258 // Send update events.
2259 SimulateGestureScrollUpdateEvent(55, 0, 0);
2260 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2262 // Send an end event. This should get in the debounce queue.
2263 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
2264 blink::WebGestureDeviceTouchscreen);
2265 EXPECT_EQ(0U, sink_->message_count());
2267 // Receive ACK for the scroll-update event.
2268 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2269 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2270 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2271 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2272 EXPECT_EQ(55.f, overscroll_delta_x());
2273 EXPECT_EQ(5.f, overscroll_delegate()->delta_x());
2274 EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
2275 EXPECT_EQ(0U, sink_->message_count());
2277 // Let the timer for the debounce queue fire. That should release the queued
2278 // scroll-end event. Since overscroll has started, but there hasn't been
2279 // enough overscroll to complete the gesture, the overscroll controller
2280 // will reset the state. The scroll-end should therefore be dispatched to the
2281 // renderer, and the gesture-event-filter should await an ACK for it.
2282 base::MessageLoop::current()->PostDelayedTask(
2283 FROM_HERE,
2284 base::MessageLoop::QuitClosure(),
2285 base::TimeDelta::FromMilliseconds(15));
2286 base::MessageLoop::current()->Run();
2288 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2289 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2290 EXPECT_EQ(1U, sink_->message_count());
2293 // Tests that when touch-events are dispatched to the renderer, the overscroll
2294 // gesture deals with them correctly.
2295 TEST_F(RenderWidgetHostViewAuraOverscrollTest, OverscrollWithTouchEvents) {
2296 SetUpOverscrollEnvironmentWithDebounce(10);
2297 widget_host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
2298 sink_->ClearMessages();
2300 // The test sends an intermingled sequence of touch and gesture events.
2301 PressTouchPoint(0, 1);
2302 SendInputEventACK(WebInputEvent::TouchStart,
2303 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2304 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2306 MoveTouchPoint(0, 20, 5);
2307 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2308 SendInputEventACK(WebInputEvent::TouchMove,
2309 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2311 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2312 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2314 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2315 blink::WebGestureDeviceTouchscreen);
2316 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2317 SimulateGestureScrollUpdateEvent(20, 0, 0);
2318 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2319 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2320 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2321 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2322 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2324 // Another touch move event should reach the renderer since overscroll hasn't
2325 // started yet. Note that touch events sent during the scroll period may
2326 // not require an ack (having been marked uncancelable).
2327 MoveTouchPoint(0, 65, 10);
2328 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2329 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2331 SimulateGestureScrollUpdateEvent(45, 0, 0);
2332 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2333 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2334 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2335 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2336 EXPECT_EQ(65.f, overscroll_delta_x());
2337 EXPECT_EQ(15.f, overscroll_delegate()->delta_x());
2338 EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
2339 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2341 // Send another touch event. The page should get the touch-move event, even
2342 // though overscroll has started.
2343 MoveTouchPoint(0, 55, 5);
2344 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2345 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2346 EXPECT_EQ(65.f, overscroll_delta_x());
2347 EXPECT_EQ(15.f, overscroll_delegate()->delta_x());
2348 EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
2349 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2350 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2352 SimulateGestureScrollUpdateEvent(-10, 0, 0);
2353 EXPECT_EQ(0U, sink_->message_count());
2354 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2355 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2356 EXPECT_EQ(55.f, overscroll_delta_x());
2357 EXPECT_EQ(5.f, overscroll_delegate()->delta_x());
2358 EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
2360 PressTouchPoint(255, 5);
2361 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2362 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2364 SimulateGestureScrollUpdateEvent(200, 0, 0);
2365 EXPECT_EQ(0U, sink_->message_count());
2366 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2367 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2368 EXPECT_EQ(255.f, overscroll_delta_x());
2369 EXPECT_EQ(205.f, overscroll_delegate()->delta_x());
2370 EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
2372 // The touch-end/cancel event should always reach the renderer if the page has
2373 // touch handlers.
2374 ReleaseTouchPoint(1);
2375 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2376 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2377 ReleaseTouchPoint(0);
2378 AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2379 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2381 SimulateGestureEvent(blink::WebInputEvent::GestureScrollEnd,
2382 blink::WebGestureDeviceTouchscreen);
2383 base::MessageLoop::current()->PostDelayedTask(
2384 FROM_HERE,
2385 base::MessageLoop::QuitClosure(),
2386 base::TimeDelta::FromMilliseconds(10));
2387 base::MessageLoop::current()->Run();
2388 EXPECT_EQ(1U, sink_->message_count());
2389 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2390 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2391 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->completed_mode());
2394 // Tests that touch-gesture end is dispatched to the renderer at the end of a
2395 // touch-gesture initiated overscroll.
2396 TEST_F(RenderWidgetHostViewAuraOverscrollTest,
2397 TouchGestureEndDispatchedAfterOverscrollComplete) {
2398 SetUpOverscrollEnvironmentWithDebounce(10);
2399 widget_host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
2400 sink_->ClearMessages();
2402 // Start scrolling. Receive ACK as it being processed.
2403 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2404 blink::WebGestureDeviceTouchscreen);
2405 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2406 // The scroll begin event will have received a synthetic ack from the input
2407 // router.
2408 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2409 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2411 // Send update events.
2412 SimulateGestureScrollUpdateEvent(55, -5, 0);
2413 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2414 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2415 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2417 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2418 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2419 EXPECT_EQ(0U, sink_->message_count());
2420 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2421 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2422 EXPECT_EQ(55.f, overscroll_delta_x());
2423 EXPECT_EQ(5.f, overscroll_delegate()->delta_x());
2424 EXPECT_EQ(-5.f, overscroll_delegate()->delta_y());
2426 // Send end event.
2427 SimulateGestureEvent(blink::WebInputEvent::GestureScrollEnd,
2428 blink::WebGestureDeviceTouchscreen);
2429 EXPECT_EQ(0U, sink_->message_count());
2430 base::MessageLoop::current()->PostDelayedTask(
2431 FROM_HERE,
2432 base::MessageLoop::QuitClosure(),
2433 base::TimeDelta::FromMilliseconds(10));
2434 base::MessageLoop::current()->Run();
2435 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2436 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2437 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->completed_mode());
2438 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2440 // Start scrolling. Receive ACK as it being processed.
2441 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2442 blink::WebGestureDeviceTouchscreen);
2443 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2444 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2445 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2447 // Send update events.
2448 SimulateGestureScrollUpdateEvent(235, -5, 0);
2449 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2450 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2451 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2453 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2454 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2455 EXPECT_EQ(0U, sink_->message_count());
2456 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2457 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2458 EXPECT_EQ(235.f, overscroll_delta_x());
2459 EXPECT_EQ(185.f, overscroll_delegate()->delta_x());
2460 EXPECT_EQ(-5.f, overscroll_delegate()->delta_y());
2462 // Send end event.
2463 SimulateGestureEvent(blink::WebInputEvent::GestureScrollEnd,
2464 blink::WebGestureDeviceTouchscreen);
2465 EXPECT_EQ(0U, sink_->message_count());
2466 base::MessageLoop::current()->PostDelayedTask(
2467 FROM_HERE,
2468 base::MessageLoop::QuitClosure(),
2469 base::TimeDelta::FromMilliseconds(10));
2470 base::MessageLoop::current()->Run();
2471 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2472 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2473 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->completed_mode());
2474 EXPECT_EQ(1U, sink_->message_count());
2477 TEST_F(RenderWidgetHostViewAuraOverscrollTest, OverscrollDirectionChange) {
2478 SetUpOverscrollEnvironmentWithDebounce(100);
2480 // Start scrolling. Receive ACK as it being processed.
2481 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2482 blink::WebGestureDeviceTouchscreen);
2483 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2485 // Send update events and receive ack as not consumed.
2486 SimulateGestureScrollUpdateEvent(125, -5, 0);
2487 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2489 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2490 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2491 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2492 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2493 EXPECT_EQ(0U, sink_->message_count());
2495 // Send another update event, but in the reverse direction. The overscroll
2496 // controller will consume the event, and reset the overscroll mode.
2497 SimulateGestureScrollUpdateEvent(-260, 0, 0);
2498 EXPECT_EQ(0U, sink_->message_count());
2499 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2501 // Since the overscroll mode has been reset, the next scroll update events
2502 // should reach the renderer.
2503 SimulateGestureScrollUpdateEvent(-20, 0, 0);
2504 EXPECT_EQ(1U, sink_->message_count());
2505 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2508 // Tests that if a mouse-move event completes the overscroll gesture, future
2509 // move events do reach the renderer.
2510 TEST_F(RenderWidgetHostViewAuraOverscrollTest, OverscrollMouseMoveCompletion) {
2511 SetUpOverscrollEnvironment();
2513 SimulateWheelEvent(5, 0, 0, true); // sent directly
2514 SimulateWheelEvent(-1, 0, 0, true); // enqueued
2515 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
2516 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
2517 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
2518 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2519 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2521 // Receive ACK the first wheel event as not processed.
2522 SendInputEventACK(WebInputEvent::MouseWheel,
2523 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2524 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2525 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2526 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2528 // Receive ACK for the second (coalesced) event as not processed. This will
2529 // start an overcroll gesture.
2530 SendInputEventACK(WebInputEvent::MouseWheel,
2531 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2532 EXPECT_EQ(OVERSCROLL_WEST, overscroll_mode());
2533 EXPECT_EQ(OVERSCROLL_WEST, overscroll_delegate()->current_mode());
2534 EXPECT_EQ(0U, sink_->message_count());
2536 // Send a mouse-move event. This should cancel the overscroll navigation
2537 // (since the amount overscrolled is not above the threshold), and so the
2538 // mouse-move should reach the renderer.
2539 SimulateMouseMove(5, 10, 0);
2540 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2541 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->completed_mode());
2542 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2543 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2545 SendInputEventACK(WebInputEvent::MouseMove,
2546 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2548 // Moving the mouse more should continue to send the events to the renderer.
2549 SimulateMouseMove(5, 10, 0);
2550 SendInputEventACK(WebInputEvent::MouseMove,
2551 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2552 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2554 // Now try with gestures.
2555 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2556 blink::WebGestureDeviceTouchscreen);
2557 SimulateGestureScrollUpdateEvent(300, -5, 0);
2558 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2559 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2560 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2561 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2562 sink_->ClearMessages();
2564 // Overscroll gesture is in progress. Send a mouse-move now. This should
2565 // complete the gesture (because the amount overscrolled is above the
2566 // threshold).
2567 SimulateMouseMove(5, 10, 0);
2568 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->completed_mode());
2569 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2570 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2571 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2572 SendInputEventACK(WebInputEvent::MouseMove,
2573 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2575 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
2576 blink::WebGestureDeviceTouchscreen);
2577 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2578 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2580 // Move mouse some more. The mouse-move events should reach the renderer.
2581 SimulateMouseMove(5, 10, 0);
2582 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2584 SendInputEventACK(WebInputEvent::MouseMove,
2585 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2588 // Tests that if a page scrolled, then the overscroll controller's states are
2589 // reset after the end of the scroll.
2590 TEST_F(RenderWidgetHostViewAuraOverscrollTest,
2591 OverscrollStateResetsAfterScroll) {
2592 SetUpOverscrollEnvironment();
2594 SimulateWheelEvent(0, 5, 0, true); // sent directly
2595 SimulateWheelEvent(0, 30, 0, true); // enqueued
2596 SimulateWheelEvent(0, 40, 0, true); // coalesced into previous event
2597 SimulateWheelEvent(0, 10, 0, true); // coalesced into previous event
2598 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2599 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2601 // The first wheel event is consumed. Dispatches the queued wheel event.
2602 SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED);
2603 EXPECT_TRUE(ScrollStateIsContentScrolling());
2604 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2606 // The second wheel event is consumed.
2607 SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED);
2608 EXPECT_TRUE(ScrollStateIsContentScrolling());
2610 // Touchpad scroll can end with a zero-velocity fling. But it is not
2611 // dispatched, but it should still reset the overscroll controller state.
2612 SimulateGestureFlingStartEvent(0.f, 0.f, blink::WebGestureDeviceTouchpad);
2613 EXPECT_TRUE(ScrollStateIsUnknown());
2614 EXPECT_EQ(0U, sink_->message_count());
2616 SimulateWheelEvent(-5, 0, 0, true); // sent directly
2617 SimulateWheelEvent(-60, 0, 0, true); // enqueued
2618 SimulateWheelEvent(-100, 0, 0, true); // coalesced into previous event
2619 EXPECT_TRUE(ScrollStateIsUnknown());
2620 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2622 // The first wheel scroll did not scroll content. Overscroll should not start
2623 // yet, since enough hasn't been scrolled.
2624 SendInputEventACK(WebInputEvent::MouseWheel,
2625 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2626 EXPECT_TRUE(ScrollStateIsUnknown());
2627 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2629 SendInputEventACK(WebInputEvent::MouseWheel,
2630 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2631 EXPECT_EQ(OVERSCROLL_WEST, overscroll_mode());
2632 EXPECT_TRUE(ScrollStateIsOverscrolling());
2633 EXPECT_EQ(0U, sink_->message_count());
2635 SimulateGestureFlingStartEvent(0.f, 0.f, blink::WebGestureDeviceTouchpad);
2636 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2637 EXPECT_EQ(OVERSCROLL_WEST, overscroll_delegate()->completed_mode());
2638 EXPECT_TRUE(ScrollStateIsUnknown());
2639 EXPECT_EQ(0U, sink_->message_count());
2642 TEST_F(RenderWidgetHostViewAuraOverscrollTest, OverscrollResetsOnBlur) {
2643 SetUpOverscrollEnvironment();
2645 // Start an overscroll with gesture scroll. In the middle of the scroll, blur
2646 // the host.
2647 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2648 blink::WebGestureDeviceTouchscreen);
2649 SimulateGestureScrollUpdateEvent(300, -5, 0);
2650 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2651 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2652 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2653 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2654 EXPECT_EQ(2U, GetSentMessageCountAndResetSink());
2656 view_->OnWindowFocused(NULL, view_->GetAttachedWindow());
2657 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
2658 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2659 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->completed_mode());
2660 EXPECT_EQ(0.f, overscroll_delegate()->delta_x());
2661 EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
2662 sink_->ClearMessages();
2664 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
2665 blink::WebGestureDeviceTouchscreen);
2666 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
2668 // Start a scroll gesture again. This should correctly start the overscroll
2669 // after the threshold.
2670 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
2671 blink::WebGestureDeviceTouchscreen);
2672 SimulateGestureScrollUpdateEvent(300, -5, 0);
2673 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2674 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2675 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
2676 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
2677 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->completed_mode());
2679 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
2680 blink::WebGestureDeviceTouchscreen);
2681 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
2682 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->completed_mode());
2683 EXPECT_EQ(3U, sink_->message_count());
2686 } // namespace content