OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2017 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. |
| 4 |
| 5 #include "content/browser/android/overscroll_controller_android.h" |
| 6 #include <memory> |
| 7 #include "base/macros.h" |
| 8 #include "base/memory/ptr_util.h" |
| 9 #include "cc/layers/layer.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "ui/android/overscroll_glow.h" |
| 13 #include "ui/android/overscroll_refresh.h" |
| 14 #include "ui/events/blink/did_overscroll_params.h" |
| 15 |
| 16 using ui::OverscrollGlow; |
| 17 using ui::OverscrollRefresh; |
| 18 using ::testing::_; |
| 19 using ::testing::Return; |
| 20 |
| 21 namespace content { |
| 22 |
| 23 namespace { |
| 24 |
| 25 class MockGlow : public OverscrollGlow { |
| 26 public: |
| 27 MockGlow() : OverscrollGlow(nullptr) {} |
| 28 MOCK_METHOD5(OnOverscrolled, |
| 29 bool(base::TimeTicks, |
| 30 const gfx::Vector2dF&, |
| 31 gfx::Vector2dF, |
| 32 gfx::Vector2dF, |
| 33 const gfx::Vector2dF&)); |
| 34 }; |
| 35 |
| 36 class MockRefresh : public OverscrollRefresh { |
| 37 public: |
| 38 MockRefresh() : OverscrollRefresh(nullptr) {} |
| 39 MOCK_METHOD0(OnOverscrolled, void()); |
| 40 MOCK_METHOD0(Reset, void()); |
| 41 MOCK_CONST_METHOD0(IsActive, bool()); |
| 42 MOCK_CONST_METHOD0(IsAwaitingScrollUpdateAck, bool()); |
| 43 }; |
| 44 |
| 45 class OverscrollControllerAndroidUnitTest : public testing::Test { |
| 46 public: |
| 47 OverscrollControllerAndroidUnitTest() { |
| 48 std::unique_ptr<MockGlow> glow_ptr = base::MakeUnique<MockGlow>(); |
| 49 std::unique_ptr<MockRefresh> refresh_ptr = base::MakeUnique<MockRefresh>(); |
| 50 glow = glow_ptr.get(); |
| 51 refresh = refresh_ptr.get(); |
| 52 controller = new OverscrollControllerAndroid( |
| 53 nullptr, 560, std::move(glow_ptr), std::move(refresh_ptr)); |
| 54 } |
| 55 |
| 56 ui::DidOverscrollParams CreateVerticalOverscrollParams() { |
| 57 ui::DidOverscrollParams params; |
| 58 params.accumulated_overscroll = gfx::Vector2dF(0, 1); |
| 59 params.latest_overscroll_delta = gfx::Vector2dF(0, 1); |
| 60 params.current_fling_velocity = gfx::Vector2dF(0, 1); |
| 61 params.causal_event_viewport_point = gfx::PointF(100, 100); |
| 62 return params; |
| 63 } |
| 64 |
| 65 MockGlow* glow; |
| 66 MockRefresh* refresh; |
| 67 OverscrollControllerAndroid* controller; |
| 68 }; |
| 69 |
| 70 TEST_F(OverscrollControllerAndroidUnitTest, |
| 71 ScrollBoundaryBehaviorAutoAllowsGlowAndNavigation) { |
| 72 ui::DidOverscrollParams params = CreateVerticalOverscrollParams(); |
| 73 params.scroll_boundary_behavior.y = cc::ScrollBoundaryBehavior:: |
| 74 ScrollBoundaryBehaviorType::kScrollBoundaryBehaviorTypeAuto; |
| 75 |
| 76 EXPECT_CALL(*refresh, OnOverscrolled()); |
| 77 EXPECT_CALL(*refresh, IsActive()).WillOnce(Return(true)); |
| 78 EXPECT_CALL(*refresh, IsAwaitingScrollUpdateAck()).Times(0); |
| 79 EXPECT_CALL(*glow, OnOverscrolled(_, _, _, _, _)).Times(0); |
| 80 |
| 81 controller->OnOverscrolled(params); |
| 82 testing::Mock::VerifyAndClearExpectations(&refresh); |
| 83 } |
| 84 |
| 85 TEST_F(OverscrollControllerAndroidUnitTest, |
| 86 ScrollBoundaryBehaviorContainPreventsNavigation) { |
| 87 ui::DidOverscrollParams params = CreateVerticalOverscrollParams(); |
| 88 params.scroll_boundary_behavior.y = cc::ScrollBoundaryBehavior:: |
| 89 ScrollBoundaryBehaviorType::kScrollBoundaryBehaviorTypeContain; |
| 90 |
| 91 EXPECT_CALL(*refresh, OnOverscrolled()).Times(0); |
| 92 EXPECT_CALL(*refresh, Reset()); |
| 93 EXPECT_CALL(*refresh, IsActive()).WillOnce(Return(false)); |
| 94 EXPECT_CALL(*refresh, IsAwaitingScrollUpdateAck()).WillOnce(Return(false)); |
| 95 EXPECT_CALL(*glow, |
| 96 OnOverscrolled(_, gfx::Vector2dF(0, 560), gfx::Vector2dF(0, 560), |
| 97 gfx::Vector2dF(0, 560), _)); |
| 98 |
| 99 controller->OnOverscrolled(params); |
| 100 testing::Mock::VerifyAndClearExpectations(refresh); |
| 101 testing::Mock::VerifyAndClearExpectations(glow); |
| 102 |
| 103 // Test that the "contain" set on x-axis would not affect navigation. |
| 104 params.scroll_boundary_behavior.y = cc::ScrollBoundaryBehavior:: |
| 105 ScrollBoundaryBehaviorType::kScrollBoundaryBehaviorTypeAuto; |
| 106 params.scroll_boundary_behavior.x = cc::ScrollBoundaryBehavior:: |
| 107 ScrollBoundaryBehaviorType::kScrollBoundaryBehaviorTypeContain; |
| 108 |
| 109 EXPECT_CALL(*refresh, OnOverscrolled()); |
| 110 EXPECT_CALL(*refresh, Reset()).Times(0); |
| 111 EXPECT_CALL(*refresh, IsActive()).WillOnce(Return(true)); |
| 112 EXPECT_CALL(*refresh, IsAwaitingScrollUpdateAck()).Times(0); |
| 113 EXPECT_CALL(*glow, OnOverscrolled(_, _, _, _, _)).Times(0); |
| 114 |
| 115 controller->OnOverscrolled(params); |
| 116 testing::Mock::VerifyAndClearExpectations(refresh); |
| 117 testing::Mock::VerifyAndClearExpectations(glow); |
| 118 } |
| 119 |
| 120 TEST_F(OverscrollControllerAndroidUnitTest, |
| 121 ScrollBoundaryBehaviorNonePreventsNavigationAndGlow) { |
| 122 ui::DidOverscrollParams params = CreateVerticalOverscrollParams(); |
| 123 params.scroll_boundary_behavior.y = cc::ScrollBoundaryBehavior:: |
| 124 ScrollBoundaryBehaviorType::kScrollBoundaryBehaviorTypeNone; |
| 125 |
| 126 EXPECT_CALL(*refresh, OnOverscrolled()).Times(0); |
| 127 EXPECT_CALL(*refresh, Reset()); |
| 128 EXPECT_CALL(*refresh, IsActive()).WillOnce(Return(false)); |
| 129 EXPECT_CALL(*refresh, IsAwaitingScrollUpdateAck()).WillOnce(Return(false)); |
| 130 EXPECT_CALL(*glow, OnOverscrolled(_, gfx::Vector2dF(), gfx::Vector2dF(), |
| 131 gfx::Vector2dF(), _)); |
| 132 |
| 133 controller->OnOverscrolled(params); |
| 134 testing::Mock::VerifyAndClearExpectations(refresh); |
| 135 testing::Mock::VerifyAndClearExpectations(glow); |
| 136 |
| 137 // Test that the "none" set on y-axis would not affect glow on x-axis. |
| 138 params.accumulated_overscroll = gfx::Vector2dF(1, 1); |
| 139 params.latest_overscroll_delta = gfx::Vector2dF(1, 1); |
| 140 params.current_fling_velocity = gfx::Vector2dF(1, 1); |
| 141 |
| 142 EXPECT_CALL(*refresh, OnOverscrolled()).Times(0); |
| 143 EXPECT_CALL(*refresh, Reset()); |
| 144 EXPECT_CALL(*refresh, IsActive()).WillOnce(Return(false)); |
| 145 EXPECT_CALL(*refresh, IsAwaitingScrollUpdateAck()).WillOnce(Return(false)); |
| 146 EXPECT_CALL(*glow, |
| 147 OnOverscrolled(_, gfx::Vector2dF(560, 0), gfx::Vector2dF(560, 0), |
| 148 gfx::Vector2dF(560, 0), _)); |
| 149 |
| 150 controller->OnOverscrolled(params); |
| 151 testing::Mock::VerifyAndClearExpectations(refresh); |
| 152 testing::Mock::VerifyAndClearExpectations(glow); |
| 153 } |
| 154 |
| 155 } // namespace |
| 156 |
| 157 } // namespace content |
OLD | NEW |