| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/events/blink/input_handler_proxy.h" | 5 #include "ui/events/blink/input_handler_proxy.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/test/histogram_tester.h" |
| 9 #include "cc/input/main_thread_scrolling_reason.h" | 10 #include "cc/input/main_thread_scrolling_reason.h" |
| 10 #include "cc/trees/swap_promise_monitor.h" | 11 #include "cc/trees/swap_promise_monitor.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "third_party/WebKit/public/platform/WebFloatPoint.h" | 14 #include "third_party/WebKit/public/platform/WebFloatPoint.h" |
| 14 #include "third_party/WebKit/public/platform/WebFloatSize.h" | 15 #include "third_party/WebKit/public/platform/WebFloatSize.h" |
| 15 #include "third_party/WebKit/public/platform/WebGestureCurve.h" | 16 #include "third_party/WebKit/public/platform/WebGestureCurve.h" |
| 16 #include "third_party/WebKit/public/platform/WebPoint.h" | 17 #include "third_party/WebKit/public/platform/WebPoint.h" |
| 17 #include "third_party/WebKit/public/web/WebInputEvent.h" | 18 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 18 #include "ui/events/blink/input_handler_proxy_client.h" | 19 #include "ui/events/blink/input_handler_proxy_client.h" |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 cc::MainThreadScrollingReason::kNotScrollingOnMain); | 251 cc::MainThreadScrollingReason::kNotScrollingOnMain); |
| 251 | 252 |
| 252 const cc::InputHandler::ScrollStatus kMainThreadScrollState( | 253 const cc::InputHandler::ScrollStatus kMainThreadScrollState( |
| 253 cc::InputHandler::SCROLL_ON_MAIN_THREAD, | 254 cc::InputHandler::SCROLL_ON_MAIN_THREAD, |
| 254 cc::MainThreadScrollingReason::kEventHandlers); | 255 cc::MainThreadScrollingReason::kEventHandlers); |
| 255 | 256 |
| 256 const cc::InputHandler::ScrollStatus kScrollIgnoredScrollState( | 257 const cc::InputHandler::ScrollStatus kScrollIgnoredScrollState( |
| 257 cc::InputHandler::SCROLL_IGNORED, | 258 cc::InputHandler::SCROLL_IGNORED, |
| 258 cc::MainThreadScrollingReason::kNotScrollable); | 259 cc::MainThreadScrollingReason::kNotScrollable); |
| 259 | 260 |
| 261 class TestInputHandlerProxy : public InputHandlerProxy { |
| 262 public: |
| 263 TestInputHandlerProxy(cc::InputHandler* input_handler, |
| 264 InputHandlerProxyClient* client) |
| 265 : InputHandlerProxy(input_handler, client) {} |
| 266 void RecordMainThreadScrollingReasonsForTest(blink::WebInputEvent::Type type, |
| 267 uint32_t reasons) { |
| 268 RecordMainThreadScrollingReasons(type, reasons); |
| 269 } |
| 270 }; |
| 271 |
| 260 } // namespace | 272 } // namespace |
| 261 | 273 |
| 262 class InputHandlerProxyTest | 274 class InputHandlerProxyTest |
| 263 : public testing::Test, | 275 : public testing::Test, |
| 264 public testing::WithParamInterface<InputHandlerProxyTestType> { | 276 public testing::WithParamInterface<InputHandlerProxyTestType> { |
| 265 public: | 277 public: |
| 266 InputHandlerProxyTest() | 278 InputHandlerProxyTest() |
| 267 : synchronous_root_scroll_(GetParam() == ROOT_SCROLL_SYNCHRONOUS_HANDLER), | 279 : synchronous_root_scroll_(GetParam() == ROOT_SCROLL_SYNCHRONOUS_HANDLER), |
| 268 install_synchronous_handler_( | 280 install_synchronous_handler_( |
| 269 GetParam() == ROOT_SCROLL_SYNCHRONOUS_HANDLER || | 281 GetParam() == ROOT_SCROLL_SYNCHRONOUS_HANDLER || |
| 270 GetParam() == CHILD_SCROLL_SYNCHRONOUS_HANDLER), | 282 GetParam() == CHILD_SCROLL_SYNCHRONOUS_HANDLER), |
| 271 expected_disposition_(InputHandlerProxy::DID_HANDLE) { | 283 expected_disposition_(InputHandlerProxy::DID_HANDLE) { |
| 272 input_handler_.reset( | 284 input_handler_.reset( |
| 273 new ui::InputHandlerProxy( | 285 new TestInputHandlerProxy( |
| 274 &mock_input_handler_, &mock_client_)); | 286 &mock_input_handler_, &mock_client_)); |
| 275 scroll_result_did_scroll_.did_scroll = true; | 287 scroll_result_did_scroll_.did_scroll = true; |
| 276 scroll_result_did_not_scroll_.did_scroll = false; | 288 scroll_result_did_not_scroll_.did_scroll = false; |
| 277 | 289 |
| 278 if (install_synchronous_handler_) { | 290 if (install_synchronous_handler_) { |
| 279 EXPECT_CALL(mock_input_handler_, | 291 EXPECT_CALL(mock_input_handler_, |
| 280 RequestUpdateForSynchronousInputHandler()) | 292 RequestUpdateForSynchronousInputHandler()) |
| 281 .Times(1); | 293 .Times(1); |
| 282 input_handler_->SetOnlySynchronouslyAnimateRootFlings( | 294 input_handler_->SetOnlySynchronouslyAnimateRootFlings( |
| 283 &mock_synchronous_input_handler_); | 295 &mock_synchronous_input_handler_); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 void SetMouseWheelGesturesOn(bool value) { | 384 void SetMouseWheelGesturesOn(bool value) { |
| 373 input_handler_->set_use_gesture_events_for_mouse_wheel(value); | 385 input_handler_->set_use_gesture_events_for_mouse_wheel(value); |
| 374 } | 386 } |
| 375 | 387 |
| 376 protected: | 388 protected: |
| 377 const bool synchronous_root_scroll_; | 389 const bool synchronous_root_scroll_; |
| 378 const bool install_synchronous_handler_; | 390 const bool install_synchronous_handler_; |
| 379 testing::StrictMock<MockInputHandler> mock_input_handler_; | 391 testing::StrictMock<MockInputHandler> mock_input_handler_; |
| 380 testing::StrictMock<MockSynchronousInputHandler> | 392 testing::StrictMock<MockSynchronousInputHandler> |
| 381 mock_synchronous_input_handler_; | 393 mock_synchronous_input_handler_; |
| 382 scoped_ptr<ui::InputHandlerProxy> input_handler_; | 394 scoped_ptr<TestInputHandlerProxy> input_handler_; |
| 383 testing::StrictMock<MockInputHandlerProxyClient> mock_client_; | 395 testing::StrictMock<MockInputHandlerProxyClient> mock_client_; |
| 384 WebGestureEvent gesture_; | 396 WebGestureEvent gesture_; |
| 385 InputHandlerProxy::EventDisposition expected_disposition_; | 397 InputHandlerProxy::EventDisposition expected_disposition_; |
| 386 cc::InputHandlerScrollResult scroll_result_did_scroll_; | 398 cc::InputHandlerScrollResult scroll_result_did_scroll_; |
| 387 cc::InputHandlerScrollResult scroll_result_did_not_scroll_; | 399 cc::InputHandlerScrollResult scroll_result_did_not_scroll_; |
| 388 }; | 400 }; |
| 389 | 401 |
| 390 TEST_P(InputHandlerProxyTest, MouseWheelByPageMainThread) { | 402 TEST_P(InputHandlerProxyTest, MouseWheelByPageMainThread) { |
| 391 expected_disposition_ = InputHandlerProxy::DID_NOT_HANDLE; | 403 expected_disposition_ = InputHandlerProxy::DID_NOT_HANDLE; |
| 392 SetMouseWheelGesturesOn(false); | 404 SetMouseWheelGesturesOn(false); |
| (...skipping 2289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2682 EXPECT_CALL(mock_input_handler_, ScrollEnd(testing::_)); | 2694 EXPECT_CALL(mock_input_handler_, ScrollEnd(testing::_)); |
| 2683 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); | 2695 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 2684 | 2696 |
| 2685 VERIFY_AND_RESET_MOCKS(); | 2697 VERIFY_AND_RESET_MOCKS(); |
| 2686 } | 2698 } |
| 2687 | 2699 |
| 2688 TEST_P(InputHandlerProxyTest, DidReceiveInputEvent_ForFling) { | 2700 TEST_P(InputHandlerProxyTest, DidReceiveInputEvent_ForFling) { |
| 2689 testing::StrictMock<MockInputHandlerProxyClientWithDidAnimateForInput> | 2701 testing::StrictMock<MockInputHandlerProxyClientWithDidAnimateForInput> |
| 2690 mock_client; | 2702 mock_client; |
| 2691 input_handler_.reset( | 2703 input_handler_.reset( |
| 2692 new ui::InputHandlerProxy( | 2704 new TestInputHandlerProxy( |
| 2693 &mock_input_handler_, &mock_client)); | 2705 &mock_input_handler_, &mock_client)); |
| 2694 if (install_synchronous_handler_) { | 2706 if (install_synchronous_handler_) { |
| 2695 EXPECT_CALL(mock_input_handler_, RequestUpdateForSynchronousInputHandler()) | 2707 EXPECT_CALL(mock_input_handler_, RequestUpdateForSynchronousInputHandler()) |
| 2696 .Times(1); | 2708 .Times(1); |
| 2697 input_handler_->SetOnlySynchronouslyAnimateRootFlings( | 2709 input_handler_->SetOnlySynchronouslyAnimateRootFlings( |
| 2698 &mock_synchronous_input_handler_); | 2710 &mock_synchronous_input_handler_); |
| 2699 } | 2711 } |
| 2700 mock_input_handler_.set_is_scrolling_root(synchronous_root_scroll_); | 2712 mock_input_handler_.set_is_scrolling_root(synchronous_root_scroll_); |
| 2701 | 2713 |
| 2702 gesture_.type = WebInputEvent::GestureFlingStart; | 2714 gesture_.type = WebInputEvent::GestureFlingStart; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2781 | 2793 |
| 2782 EXPECT_CALL(mock_input_handler, SetSynchronousInputHandlerRootScrollOffset( | 2794 EXPECT_CALL(mock_input_handler, SetSynchronousInputHandlerRootScrollOffset( |
| 2783 gfx::ScrollOffset(5, 6))); | 2795 gfx::ScrollOffset(5, 6))); |
| 2784 proxy.SynchronouslySetRootScrollOffset(gfx::ScrollOffset(5, 6)); | 2796 proxy.SynchronouslySetRootScrollOffset(gfx::ScrollOffset(5, 6)); |
| 2785 | 2797 |
| 2786 testing::Mock::VerifyAndClearExpectations(&mock_input_handler); | 2798 testing::Mock::VerifyAndClearExpectations(&mock_input_handler); |
| 2787 testing::Mock::VerifyAndClearExpectations(&mock_client); | 2799 testing::Mock::VerifyAndClearExpectations(&mock_client); |
| 2788 testing::Mock::VerifyAndClearExpectations(&mock_synchronous_input_handler); | 2800 testing::Mock::VerifyAndClearExpectations(&mock_synchronous_input_handler); |
| 2789 } | 2801 } |
| 2790 | 2802 |
| 2803 TEST_P(InputHandlerProxyTest, MainThreadScrollingMouseWheelHistograms) { |
| 2804 base::HistogramTester histogram_tester; |
| 2805 input_handler_->RecordMainThreadScrollingReasonsForTest( |
| 2806 WebInputEvent::MouseWheel, |
| 2807 cc::MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects | |
| 2808 cc::MainThreadScrollingReason::kThreadedScrollingDisabled | |
| 2809 cc::MainThreadScrollingReason::kPageOverlay | |
| 2810 cc::MainThreadScrollingReason::kAnimatingScrollOnMainThread); |
| 2811 |
| 2812 EXPECT_THAT( |
| 2813 histogram_tester.GetAllSamples("Renderer4.MainThreadWheelScrollReason"), |
| 2814 testing::ElementsAre(base::Bucket(1, 1), base::Bucket(3, 1), |
| 2815 base::Bucket(5, 1), base::Bucket(14, 1))); |
| 2816 } |
| 2817 |
| 2818 |
| 2791 INSTANTIATE_TEST_CASE_P(AnimateInput, | 2819 INSTANTIATE_TEST_CASE_P(AnimateInput, |
| 2792 InputHandlerProxyTest, | 2820 InputHandlerProxyTest, |
| 2793 testing::ValuesIn(test_types)); | 2821 testing::ValuesIn(test_types)); |
| 2794 } // namespace test | 2822 } // namespace test |
| 2795 } // namespace ui | 2823 } // namespace ui |
| OLD | NEW |