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/android/resources/resource_manager_impl.h" | |
15 #include "ui/android/window_android_compositor.h" | |
16 #include "ui/events/blink/did_overscroll_params.h" | |
17 | |
18 using ui::OverscrollGlow; | |
19 using ui::OverscrollRefresh; | |
20 using ui::WindowAndroidCompositor; | |
21 using cc::CopyOutputRequest; | |
22 using ::testing::_; | |
23 using ::testing::Return; | |
24 | |
25 namespace content { | |
26 | |
majidvp
2017/07/12 21:04:21
all test logic should be inside an unnamed namespa
sunyunjia
2017/07/19 20:44:11
Done.
| |
27 class MockCompositor : public WindowAndroidCompositor { | |
28 public: | |
29 MOCK_METHOD1(AttachLayerForReadback, void(scoped_refptr<cc::Layer>)); | |
30 void RequestCopyOfOutputOnRootLayer( | |
31 std::unique_ptr<cc::CopyOutputRequest> request) override {} | |
32 MOCK_METHOD0(SetNeedsAnimate, void()); | |
33 MOCK_METHOD0(GetResourceManager, ui::ResourceManagerImpl&()); | |
34 MOCK_METHOD0(GetFrameSinkId, cc::FrameSinkId()); | |
35 MOCK_METHOD1(AddChildFrameSink, void(const cc::FrameSinkId& frame_sink_id)); | |
36 MOCK_METHOD1(RemoveChildFrameSink, | |
37 void(const cc::FrameSinkId& frame_sink_id)); | |
38 }; | |
39 | |
40 class MockGlow : public OverscrollGlow { | |
41 public: | |
42 MockGlow() : OverscrollGlow() {} | |
43 MOCK_METHOD5(OnOverscrolled, | |
44 bool(base::TimeTicks, | |
45 const gfx::Vector2dF&, | |
46 gfx::Vector2dF, | |
47 gfx::Vector2dF, | |
48 const gfx::Vector2dF&)); | |
49 }; | |
50 | |
51 class MockRefresh : public OverscrollRefresh { | |
52 public: | |
53 MockRefresh() : OverscrollRefresh() {} | |
54 MOCK_METHOD1(OnOverscrolled, void(bool)); | |
55 MOCK_CONST_METHOD0(IsActive, bool()); | |
56 MOCK_CONST_METHOD0(IsAwaitingScrollUpdateAck, bool()); | |
57 }; | |
58 | |
59 class OverscrollControllerAndroidUnitTest : public testing::Test { | |
60 public: | |
61 OverscrollControllerAndroidUnitTest() { | |
62 compositor = base::MakeUnique<MockCompositor>(); | |
63 glow = base::MakeUnique<MockGlow>(); | |
64 refresh = base::MakeUnique<MockRefresh>(); | |
65 controller = base::MakeUnique<OverscrollControllerAndroid>( | |
66 glow.get(), refresh.get(), compositor.get(), 560); | |
67 } | |
68 | |
69 std::unique_ptr<MockCompositor> compositor; | |
70 std::unique_ptr<MockGlow> glow; | |
71 std::unique_ptr<MockRefresh> refresh; | |
72 std::unique_ptr<OverscrollControllerAndroid> controller; | |
73 }; | |
74 | |
75 TEST_F(OverscrollControllerAndroidUnitTest, BasicNavigation) { | |
majidvp
2017/07/12 21:04:20
The test name needs to be a bit more descriptive i
sunyunjia
2017/07/19 20:44:11
Done.
majidvp
2017/07/20 13:26:55
not: the new name still does not convey that it is
| |
76 ui::DidOverscrollParams params; | |
77 params.accumulated_overscroll = gfx::Vector2dF(0, 20); | |
78 params.latest_overscroll_delta = gfx::Vector2dF(0, 20); | |
79 params.current_fling_velocity = gfx::Vector2dF(0, 20); | |
80 params.causal_event_viewport_point = gfx::PointF(100, 100); | |
81 params.scroll_boundary_behavior.y = cc::ScrollBoundaryBehavior:: | |
82 ScrollBoundaryBehaviorType::kScrollBoundaryBehaviorTypeAuto; | |
83 | |
84 EXPECT_CALL(*refresh, OnOverscrolled(true)); | |
85 EXPECT_CALL(*refresh, IsActive()).WillOnce(Return(true)); | |
86 EXPECT_CALL(*refresh, IsAwaitingScrollUpdateAck()).Times(0); | |
87 EXPECT_CALL(*glow, OnOverscrolled(_, _, _, _, _)).Times(0); | |
88 | |
89 controller->OnOverscrolled(params); | |
90 testing::Mock::VerifyAndClearExpectations(refresh.get()); | |
91 } | |
92 | |
93 TEST_F(OverscrollControllerAndroidUnitTest, ContainPreventsNavigation) { | |
94 ui::DidOverscrollParams params; | |
95 params.accumulated_overscroll = gfx::Vector2dF(0, 1); | |
majidvp
2017/07/12 21:04:21
nit: first test uses |20| but this one uses |1|. I
sunyunjia
2017/07/19 20:44:12
Done.
| |
96 params.latest_overscroll_delta = gfx::Vector2dF(0, 1); | |
97 params.current_fling_velocity = gfx::Vector2dF(0, 1); | |
98 params.causal_event_viewport_point = gfx::PointF(100, 100); | |
99 params.scroll_boundary_behavior.y = cc::ScrollBoundaryBehavior:: | |
100 ScrollBoundaryBehaviorType::kScrollBoundaryBehaviorTypeContain; | |
101 | |
102 EXPECT_CALL(*refresh, OnOverscrolled(false)); | |
103 EXPECT_CALL(*refresh, IsActive()).WillOnce(Return(false)); | |
104 EXPECT_CALL(*refresh, IsAwaitingScrollUpdateAck()).WillOnce(Return(false)); | |
105 EXPECT_CALL(*glow, | |
106 OnOverscrolled(_, gfx::Vector2dF(0, 560), gfx::Vector2dF(0, 560), | |
107 gfx::Vector2dF(0, 560), _)); | |
108 | |
109 controller->OnOverscrolled(params); | |
110 testing::Mock::VerifyAndClearExpectations(refresh.get()); | |
111 testing::Mock::VerifyAndClearExpectations(glow.get()); | |
112 | |
113 // Test that the "contain" set on x-axis would not affect navigation. | |
114 params.scroll_boundary_behavior.y = cc::ScrollBoundaryBehavior:: | |
115 ScrollBoundaryBehaviorType::kScrollBoundaryBehaviorTypeAuto; | |
116 params.scroll_boundary_behavior.x = cc::ScrollBoundaryBehavior:: | |
117 ScrollBoundaryBehaviorType::kScrollBoundaryBehaviorTypeContain; | |
118 | |
119 EXPECT_CALL(*refresh, OnOverscrolled(true)); | |
120 EXPECT_CALL(*refresh, IsActive()).WillOnce(Return(true)); | |
121 EXPECT_CALL(*refresh, IsAwaitingScrollUpdateAck()).Times(0); | |
122 EXPECT_CALL(*glow, OnOverscrolled(_, _, _, _, _)).Times(0); | |
123 | |
124 controller->OnOverscrolled(params); | |
125 testing::Mock::VerifyAndClearExpectations(refresh.get()); | |
126 testing::Mock::VerifyAndClearExpectations(glow.get()); | |
127 } | |
128 | |
129 TEST_F(OverscrollControllerAndroidUnitTest, NonePreventsNavigationAndGlow) { | |
130 ui::DidOverscrollParams params; | |
131 params.accumulated_overscroll = gfx::Vector2dF(0, 1); | |
132 params.latest_overscroll_delta = gfx::Vector2dF(0, 1); | |
133 params.current_fling_velocity = gfx::Vector2dF(0, 1); | |
134 params.causal_event_viewport_point = gfx::PointF(100, 100); | |
135 params.scroll_boundary_behavior.y = cc::ScrollBoundaryBehavior:: | |
136 ScrollBoundaryBehaviorType::kScrollBoundaryBehaviorTypeNone; | |
137 | |
138 EXPECT_CALL(*refresh, OnOverscrolled(false)); | |
139 EXPECT_CALL(*refresh, IsActive()).WillOnce(Return(false)); | |
140 EXPECT_CALL(*refresh, IsAwaitingScrollUpdateAck()).WillOnce(Return(false)); | |
141 EXPECT_CALL(*glow, OnOverscrolled(_, gfx::Vector2dF(), gfx::Vector2dF(), | |
142 gfx::Vector2dF(), _)); | |
143 | |
144 controller->OnOverscrolled(params); | |
145 testing::Mock::VerifyAndClearExpectations(refresh.get()); | |
146 testing::Mock::VerifyAndClearExpectations(glow.get()); | |
147 | |
148 // Test that the "none" set on y-axis would not affect glow on x-axis. | |
149 params.accumulated_overscroll = gfx::Vector2dF(1, 1); | |
150 params.latest_overscroll_delta = gfx::Vector2dF(1, 1); | |
151 params.current_fling_velocity = gfx::Vector2dF(1, 1); | |
152 | |
153 EXPECT_CALL(*refresh, OnOverscrolled(false)); | |
154 EXPECT_CALL(*refresh, IsActive()).WillOnce(Return(false)); | |
155 EXPECT_CALL(*refresh, IsAwaitingScrollUpdateAck()).WillOnce(Return(false)); | |
156 EXPECT_CALL(*glow, | |
157 OnOverscrolled(_, gfx::Vector2dF(560, 0), gfx::Vector2dF(560, 0), | |
158 gfx::Vector2dF(560, 0), _)); | |
159 | |
160 controller->OnOverscrolled(params); | |
161 testing::Mock::VerifyAndClearExpectations(refresh.get()); | |
162 testing::Mock::VerifyAndClearExpectations(glow.get()); | |
163 } | |
164 | |
165 } // namespace content | |
OLD | NEW |