Chromium Code Reviews| 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 <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/test/histogram_tester.h" | 10 #include "base/test/histogram_tester.h" |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 | 155 |
| 156 void MouseMoveAt(const gfx::Point& mouse_position) override {} | 156 void MouseMoveAt(const gfx::Point& mouse_position) override {} |
| 157 | 157 |
| 158 MOCK_CONST_METHOD2(IsCurrentlyScrollingLayerAt, | 158 MOCK_CONST_METHOD2(IsCurrentlyScrollingLayerAt, |
| 159 bool(const gfx::Point& point, | 159 bool(const gfx::Point& point, |
| 160 cc::InputHandler::ScrollInputType type)); | 160 cc::InputHandler::ScrollInputType type)); |
| 161 | 161 |
| 162 MOCK_CONST_METHOD1( | 162 MOCK_CONST_METHOD1( |
| 163 GetEventListenerProperties, | 163 GetEventListenerProperties, |
| 164 cc::EventListenerProperties(cc::EventListenerClass event_class)); | 164 cc::EventListenerProperties(cc::EventListenerClass event_class)); |
| 165 MOCK_METHOD1(DoTouchEventsBlockScrollAt, bool(const gfx::Point& point)); | 165 MOCK_METHOD1(EventListenerTypeForTouchStartAt, |
| 166 cc::EventListenerProperties(const gfx::Point& point)); | |
| 166 | 167 |
| 167 MOCK_METHOD0(RequestUpdateForSynchronousInputHandler, void()); | 168 MOCK_METHOD0(RequestUpdateForSynchronousInputHandler, void()); |
| 168 MOCK_METHOD1(SetSynchronousInputHandlerRootScrollOffset, | 169 MOCK_METHOD1(SetSynchronousInputHandlerRootScrollOffset, |
| 169 void(const gfx::ScrollOffset& root_offset)); | 170 void(const gfx::ScrollOffset& root_offset)); |
| 170 | 171 |
| 171 bool IsCurrentlyScrollingViewport() const override { | 172 bool IsCurrentlyScrollingViewport() const override { |
| 172 return is_scrolling_root_; | 173 return is_scrolling_root_; |
| 173 } | 174 } |
| 174 void set_is_scrolling_root(bool is) { is_scrolling_root_ = is; } | 175 void set_is_scrolling_root(bool is) { is_scrolling_root_ = is; } |
| 175 | 176 |
| (...skipping 1758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1934 VERIFY_AND_RESET_MOCKS(); | 1935 VERIFY_AND_RESET_MOCKS(); |
| 1935 | 1936 |
| 1936 EXPECT_CALL( | 1937 EXPECT_CALL( |
| 1937 mock_input_handler_, | 1938 mock_input_handler_, |
| 1938 GetEventListenerProperties(cc::EventListenerClass::kTouchStartOrMove)) | 1939 GetEventListenerProperties(cc::EventListenerClass::kTouchStartOrMove)) |
| 1939 .WillOnce(testing::Return(cc::EventListenerProperties::kNone)); | 1940 .WillOnce(testing::Return(cc::EventListenerProperties::kNone)); |
| 1940 EXPECT_CALL( | 1941 EXPECT_CALL( |
| 1941 mock_input_handler_, | 1942 mock_input_handler_, |
| 1942 GetEventListenerProperties(cc::EventListenerClass::kTouchEndOrCancel)) | 1943 GetEventListenerProperties(cc::EventListenerClass::kTouchEndOrCancel)) |
| 1943 .WillOnce(testing::Return(cc::EventListenerProperties::kNone)); | 1944 .WillOnce(testing::Return(cc::EventListenerProperties::kNone)); |
| 1944 EXPECT_CALL(mock_input_handler_, DoTouchEventsBlockScrollAt(testing::_)) | 1945 EXPECT_CALL(mock_input_handler_, EventListenerTypeForTouchStartAt(testing::_)) |
| 1945 .WillOnce(testing::Return(false)); | 1946 .WillOnce(testing::Return(cc::EventListenerProperties::kNone)); |
|
bokan
2016/11/17 15:39:28
I believe this expects to be called twice so I thi
lanwei
2016/11/18 00:54:07
I changed the test, it is called twice, because it
bokan
2016/11/18 18:41:36
Ah! You're right, that makes more sense :)
| |
| 1946 EXPECT_CALL(mock_input_handler_, | 1947 EXPECT_CALL(mock_input_handler_, |
| 1947 DoTouchEventsBlockScrollAt( | 1948 EventListenerTypeForTouchStartAt( |
| 1948 testing::Property(&gfx::Point::x, testing::Lt(0)))) | 1949 testing::Property(&gfx::Point::x, testing::Lt(0)))) |
| 1949 .WillOnce(testing::Return(false)); | 1950 .WillOnce(testing::Return(cc::EventListenerProperties::kNone)); |
| 1950 | 1951 |
| 1951 WebTouchEvent touch; | 1952 WebTouchEvent touch; |
| 1952 touch.type = WebInputEvent::TouchStart; | 1953 touch.type = WebInputEvent::TouchStart; |
| 1953 | 1954 |
| 1954 touch.touchesLength = 3; | 1955 touch.touchesLength = 3; |
| 1955 touch.touches[0] = CreateWebTouchPoint(WebTouchPoint::StateStationary, 0, 0); | 1956 touch.touches[0] = CreateWebTouchPoint(WebTouchPoint::StateStationary, 0, 0); |
| 1956 touch.touches[1] = CreateWebTouchPoint(WebTouchPoint::StatePressed, 10, 10); | 1957 touch.touches[1] = CreateWebTouchPoint(WebTouchPoint::StatePressed, 10, 10); |
| 1957 touch.touches[2] = CreateWebTouchPoint(WebTouchPoint::StatePressed, -10, 10); | 1958 touch.touches[2] = CreateWebTouchPoint(WebTouchPoint::StatePressed, -10, 10); |
| 1958 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(touch)); | 1959 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(touch)); |
| 1959 | 1960 |
| 1960 VERIFY_AND_RESET_MOCKS(); | 1961 VERIFY_AND_RESET_MOCKS(); |
| 1961 } | 1962 } |
| 1962 | 1963 |
| 1963 TEST_P(InputHandlerProxyTest, MultiTouchPointHitTestPositive) { | 1964 TEST_P(InputHandlerProxyTest, MultiTouchPointHitTestPositive) { |
| 1964 // One of the touch points is on a touch-region. So the event should be sent | 1965 // One of the touch points is on a touch-region. So the event should be sent |
| 1965 // to the main thread. | 1966 // to the main thread. |
| 1966 expected_disposition_ = InputHandlerProxy::DID_NOT_HANDLE; | 1967 expected_disposition_ = InputHandlerProxy::DID_NOT_HANDLE; |
| 1967 VERIFY_AND_RESET_MOCKS(); | 1968 VERIFY_AND_RESET_MOCKS(); |
| 1968 | 1969 |
| 1969 EXPECT_CALL(mock_input_handler_, | 1970 EXPECT_CALL(mock_input_handler_, |
| 1970 DoTouchEventsBlockScrollAt( | 1971 EventListenerTypeForTouchStartAt( |
| 1971 testing::Property(&gfx::Point::x, testing::Eq(0)))) | 1972 testing::Property(&gfx::Point::x, testing::Eq(0)))) |
| 1972 .WillOnce(testing::Return(false)); | 1973 .WillOnce(testing::Return(cc::EventListenerProperties::kNone)); |
| 1973 EXPECT_CALL(mock_input_handler_, | 1974 EXPECT_CALL(mock_input_handler_, |
| 1974 DoTouchEventsBlockScrollAt( | 1975 EventListenerTypeForTouchStartAt( |
| 1975 testing::Property(&gfx::Point::x, testing::Gt(0)))) | 1976 testing::Property(&gfx::Point::x, testing::Gt(0)))) |
| 1976 .WillOnce(testing::Return(true)); | 1977 .WillOnce(testing::Return( |
| 1978 cc::EventListenerProperties::kBlockingAndMaybePassiveDueToFling)); | |
| 1977 // Since the second touch point hits a touch-region, there should be no | 1979 // Since the second touch point hits a touch-region, there should be no |
| 1978 // hit-testing for the third touch point. | 1980 // hit-testing for the third touch point. |
| 1979 | 1981 |
| 1980 WebTouchEvent touch; | 1982 WebTouchEvent touch; |
| 1981 touch.type = WebInputEvent::TouchStart; | 1983 touch.type = WebInputEvent::TouchStart; |
| 1982 | 1984 |
| 1983 touch.touchesLength = 3; | 1985 touch.touchesLength = 3; |
| 1984 touch.touches[0] = CreateWebTouchPoint(WebTouchPoint::StatePressed, 0, 0); | 1986 touch.touches[0] = CreateWebTouchPoint(WebTouchPoint::StatePressed, 0, 0); |
| 1985 touch.touches[1] = CreateWebTouchPoint(WebTouchPoint::StatePressed, 10, 10); | 1987 touch.touches[1] = CreateWebTouchPoint(WebTouchPoint::StatePressed, 10, 10); |
| 1986 touch.touches[2] = CreateWebTouchPoint(WebTouchPoint::StatePressed, -10, 10); | 1988 touch.touches[2] = CreateWebTouchPoint(WebTouchPoint::StatePressed, -10, 10); |
| 1987 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(touch)); | 1989 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(touch)); |
| 1988 | 1990 |
| 1989 VERIFY_AND_RESET_MOCKS(); | 1991 VERIFY_AND_RESET_MOCKS(); |
| 1990 } | 1992 } |
| 1991 | 1993 |
| 1992 TEST_P(InputHandlerProxyTest, MultiTouchPointHitTestPassivePositive) { | 1994 TEST_P(InputHandlerProxyTest, MultiTouchPointHitTestPassivePositive) { |
| 1993 // One of the touch points is on a touch-region. So the event should be sent | 1995 // One of the touch points is on a touch-region. So the event should be sent |
| 1994 // to the main thread. | 1996 // to the main thread. |
|
bokan
2016/11/17 15:39:28
Is this comment wrong? It says "sent to main threa
lanwei
2016/11/18 00:54:07
Done.
| |
| 1995 expected_disposition_ = InputHandlerProxy::DID_HANDLE_NON_BLOCKING; | 1997 expected_disposition_ = InputHandlerProxy::DID_HANDLE_NON_BLOCKING; |
| 1996 VERIFY_AND_RESET_MOCKS(); | 1998 VERIFY_AND_RESET_MOCKS(); |
| 1997 | 1999 |
| 1998 EXPECT_CALL( | 2000 EXPECT_CALL( |
| 1999 mock_input_handler_, | 2001 mock_input_handler_, |
| 2000 GetEventListenerProperties(cc::EventListenerClass::kTouchStartOrMove)) | 2002 GetEventListenerProperties(cc::EventListenerClass::kTouchStartOrMove)) |
| 2001 .WillRepeatedly(testing::Return(cc::EventListenerProperties::kPassive)); | 2003 .WillRepeatedly(testing::Return(cc::EventListenerProperties::kPassive)); |
| 2002 EXPECT_CALL(mock_input_handler_, DoTouchEventsBlockScrollAt(testing::_)) | 2004 EXPECT_CALL(mock_input_handler_, EventListenerTypeForTouchStartAt(testing::_)) |
| 2003 .WillRepeatedly(testing::Return(false)); | 2005 .WillRepeatedly(testing::Return(cc::EventListenerProperties::kNone)); |
| 2004 | 2006 |
| 2005 WebTouchEvent touch; | 2007 WebTouchEvent touch; |
| 2006 touch.type = WebInputEvent::TouchStart; | 2008 touch.type = WebInputEvent::TouchStart; |
| 2007 | 2009 |
| 2008 touch.touchesLength = 3; | 2010 touch.touchesLength = 3; |
| 2009 touch.touches[0] = CreateWebTouchPoint(WebTouchPoint::StatePressed, 0, 0); | 2011 touch.touches[0] = CreateWebTouchPoint(WebTouchPoint::StatePressed, 0, 0); |
| 2010 touch.touches[1] = CreateWebTouchPoint(WebTouchPoint::StatePressed, 10, 10); | 2012 touch.touches[1] = CreateWebTouchPoint(WebTouchPoint::StatePressed, 10, 10); |
| 2011 touch.touches[2] = CreateWebTouchPoint(WebTouchPoint::StatePressed, -10, 10); | 2013 touch.touches[2] = CreateWebTouchPoint(WebTouchPoint::StatePressed, -10, 10); |
| 2012 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(touch)); | 2014 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(touch)); |
| 2013 | 2015 |
| 2014 VERIFY_AND_RESET_MOCKS(); | 2016 VERIFY_AND_RESET_MOCKS(); |
| 2015 } | 2017 } |
| 2016 | 2018 |
| 2017 TEST_P(InputHandlerProxyTest, TouchStartPassiveAndTouchEndBlocking) { | 2019 TEST_P(InputHandlerProxyTest, TouchStartPassiveAndTouchEndBlocking) { |
| 2018 // The touch start is not in a touch-region but there is a touch end handler | 2020 // The touch start is not in a touch-region but there is a touch end handler |
| 2019 // so to maintain targeting we need to dispatch the touch start as | 2021 // so to maintain targeting we need to dispatch the touch start as |
| 2020 // non-blocking but drop all touch moves. | 2022 // non-blocking but drop all touch moves. |
| 2021 expected_disposition_ = InputHandlerProxy::DID_HANDLE_NON_BLOCKING; | 2023 expected_disposition_ = InputHandlerProxy::DID_HANDLE_NON_BLOCKING; |
| 2022 VERIFY_AND_RESET_MOCKS(); | 2024 VERIFY_AND_RESET_MOCKS(); |
| 2023 | 2025 |
| 2024 EXPECT_CALL( | 2026 EXPECT_CALL( |
| 2025 mock_input_handler_, | 2027 mock_input_handler_, |
| 2026 GetEventListenerProperties(cc::EventListenerClass::kTouchStartOrMove)) | 2028 GetEventListenerProperties(cc::EventListenerClass::kTouchStartOrMove)) |
| 2027 .WillOnce(testing::Return(cc::EventListenerProperties::kNone)); | 2029 .WillOnce(testing::Return(cc::EventListenerProperties::kNone)); |
| 2028 EXPECT_CALL( | 2030 EXPECT_CALL( |
| 2029 mock_input_handler_, | 2031 mock_input_handler_, |
| 2030 GetEventListenerProperties(cc::EventListenerClass::kTouchEndOrCancel)) | 2032 GetEventListenerProperties(cc::EventListenerClass::kTouchEndOrCancel)) |
| 2031 .WillOnce(testing::Return(cc::EventListenerProperties::kBlocking)); | 2033 .WillOnce(testing::Return(cc::EventListenerProperties::kBlocking)); |
| 2032 EXPECT_CALL(mock_input_handler_, DoTouchEventsBlockScrollAt(testing::_)) | 2034 EXPECT_CALL(mock_input_handler_, EventListenerTypeForTouchStartAt(testing::_)) |
| 2033 .WillOnce(testing::Return(false)); | 2035 .WillOnce(testing::Return(cc::EventListenerProperties::kNone)); |
| 2034 | 2036 |
| 2035 WebTouchEvent touch; | 2037 WebTouchEvent touch; |
| 2036 touch.type = WebInputEvent::TouchStart; | 2038 touch.type = WebInputEvent::TouchStart; |
| 2037 touch.touchesLength = 1; | 2039 touch.touchesLength = 1; |
| 2038 touch.touches[0] = CreateWebTouchPoint(WebTouchPoint::StatePressed, 0, 0); | 2040 touch.touches[0] = CreateWebTouchPoint(WebTouchPoint::StatePressed, 0, 0); |
| 2039 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(touch)); | 2041 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(touch)); |
| 2040 | 2042 |
| 2041 touch.type = WebInputEvent::TouchMove; | 2043 touch.type = WebInputEvent::TouchMove; |
| 2042 touch.touchesLength = 1; | 2044 touch.touchesLength = 1; |
| 2043 touch.touches[0] = CreateWebTouchPoint(WebTouchPoint::StatePressed, 10, 10); | 2045 touch.touches[0] = CreateWebTouchPoint(WebTouchPoint::StatePressed, 10, 10); |
| (...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2814 testing::ElementsAre(base::Bucket(1, 1), base::Bucket(3, 1), | 2816 testing::ElementsAre(base::Bucket(1, 1), base::Bucket(3, 1), |
| 2815 base::Bucket(5, 1), base::Bucket(14, 1))); | 2817 base::Bucket(5, 1), base::Bucket(14, 1))); |
| 2816 } | 2818 } |
| 2817 | 2819 |
| 2818 | 2820 |
| 2819 INSTANTIATE_TEST_CASE_P(AnimateInput, | 2821 INSTANTIATE_TEST_CASE_P(AnimateInput, |
| 2820 InputHandlerProxyTest, | 2822 InputHandlerProxyTest, |
| 2821 testing::ValuesIn(test_types)); | 2823 testing::ValuesIn(test_types)); |
| 2822 } // namespace test | 2824 } // namespace test |
| 2823 } // namespace ui | 2825 } // namespace ui |
| OLD | NEW |