Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(515)

Side by Side Diff: content/browser/android/overscroll_controller_android_unittest.cc

Issue 2884423003: Use scroll-boundary-behavior to control overscroll-refresh/glow on android. (Closed)
Patch Set: Rebase Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 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::EdgeEffectBase;
19 using ui::ResourceManager;
20 using ui::OverscrollGlow;
21 using ui::OverscrollGlowClient;
22 using ui::OverscrollRefresh;
23 using ui::WindowAndroidCompositor;
24 using ::testing::_;
25 using ::testing::Return;
26
27 namespace content {
28
29 namespace {
30
31 class MockCompositor : public WindowAndroidCompositor {
32 public:
33 void AttachLayerForReadback(scoped_refptr<cc::Layer>) override {}
34 void RequestCopyOfOutputOnRootLayer(
35 std::unique_ptr<viz::CopyOutputRequest>) override {}
36 void SetNeedsAnimate() override {}
37 MOCK_METHOD0(GetResourceManager, ResourceManager&());
38 MOCK_METHOD0(GetFrameSinkId, viz::FrameSinkId());
39 void AddChildFrameSink(const viz::FrameSinkId& frame_sink_id) override {}
40 void RemoveChildFrameSink(const viz::FrameSinkId& frame_sink_id) override {}
41 };
42
43 class MockGlowClient : public OverscrollGlowClient {
44 public:
45 MOCK_METHOD0(CreateEdgeEffect, std::unique_ptr<EdgeEffectBase>());
46 };
47
48 class MockGlow : public OverscrollGlow {
49 public:
50 MockGlow() : OverscrollGlow(new MockGlowClient()) {}
51 MOCK_METHOD5(OnOverscrolled,
52 bool(base::TimeTicks,
53 gfx::Vector2dF,
54 gfx::Vector2dF,
55 gfx::Vector2dF,
56 gfx::Vector2dF));
57 };
58
59 class MockRefresh : public OverscrollRefresh {
60 public:
61 MockRefresh() : OverscrollRefresh() {}
62 MOCK_METHOD0(OnOverscrolled, void());
63 MOCK_METHOD0(Reset, void());
64 MOCK_CONST_METHOD0(IsActive, bool());
65 MOCK_CONST_METHOD0(IsAwaitingScrollUpdateAck, bool());
66 };
67
68 class OverscrollControllerAndroidUnitTest : public testing::Test {
69 public:
70 OverscrollControllerAndroidUnitTest() {
71 std::unique_ptr<MockGlow> glow_ptr = base::MakeUnique<MockGlow>();
72 std::unique_ptr<MockRefresh> refresh_ptr = base::MakeUnique<MockRefresh>();
73 compositor_ = base::MakeUnique<MockCompositor>();
74 glow_ = glow_ptr.get();
75 refresh_ = refresh_ptr.get();
76 controller_ = OverscrollControllerAndroid::CreateForTests(
77 compositor_.get(), 560, std::move(glow_ptr), std::move(refresh_ptr));
78 }
79
80 ui::DidOverscrollParams CreateVerticalOverscrollParams() {
81 ui::DidOverscrollParams params;
82 params.accumulated_overscroll = gfx::Vector2dF(0, 1);
83 params.latest_overscroll_delta = gfx::Vector2dF(0, 1);
84 params.current_fling_velocity = gfx::Vector2dF(0, 1);
85 params.causal_event_viewport_point = gfx::PointF(100, 100);
86 return params;
87 }
88
89 protected:
90 MockGlow* glow_;
91 MockRefresh* refresh_;
92 std::unique_ptr<MockCompositor> compositor_;
93 std::unique_ptr<OverscrollControllerAndroid> controller_;
94 };
95
96 TEST_F(OverscrollControllerAndroidUnitTest,
97 ScrollBoundaryBehaviorAutoAllowsGlowAndNavigation) {
98 ui::DidOverscrollParams params = CreateVerticalOverscrollParams();
99 params.scroll_boundary_behavior.y = cc::ScrollBoundaryBehavior::
100 ScrollBoundaryBehaviorType::kScrollBoundaryBehaviorTypeAuto;
101
102 EXPECT_CALL(*refresh_, OnOverscrolled());
103 EXPECT_CALL(*refresh_, IsActive()).WillOnce(Return(true));
104 EXPECT_CALL(*refresh_, IsAwaitingScrollUpdateAck()).Times(0);
105 EXPECT_CALL(*glow_, OnOverscrolled(_, _, _, _, _)).Times(0);
106
107 controller_->OnOverscrolled(params);
108 testing::Mock::VerifyAndClearExpectations(&refresh_);
109 }
110
111 TEST_F(OverscrollControllerAndroidUnitTest,
112 ScrollBoundaryBehaviorContainPreventsNavigation) {
113 ui::DidOverscrollParams params = CreateVerticalOverscrollParams();
114 params.scroll_boundary_behavior.y = cc::ScrollBoundaryBehavior::
115 ScrollBoundaryBehaviorType::kScrollBoundaryBehaviorTypeContain;
116
117 EXPECT_CALL(*refresh_, OnOverscrolled()).Times(0);
118 EXPECT_CALL(*refresh_, Reset());
119 EXPECT_CALL(*refresh_, IsActive()).WillOnce(Return(false));
120 EXPECT_CALL(*refresh_, IsAwaitingScrollUpdateAck()).WillOnce(Return(false));
121 EXPECT_CALL(*glow_,
122 OnOverscrolled(_, gfx::Vector2dF(0, 560), gfx::Vector2dF(0, 560),
123 gfx::Vector2dF(0, 560), _));
124
125 controller_->OnOverscrolled(params);
126 testing::Mock::VerifyAndClearExpectations(refresh_);
127 testing::Mock::VerifyAndClearExpectations(glow_);
128
129 // Test that the "contain" set on x-axis would not affect navigation.
130 params.scroll_boundary_behavior.y = cc::ScrollBoundaryBehavior::
131 ScrollBoundaryBehaviorType::kScrollBoundaryBehaviorTypeAuto;
132 params.scroll_boundary_behavior.x = cc::ScrollBoundaryBehavior::
133 ScrollBoundaryBehaviorType::kScrollBoundaryBehaviorTypeContain;
134
135 EXPECT_CALL(*refresh_, OnOverscrolled());
136 EXPECT_CALL(*refresh_, Reset()).Times(0);
137 EXPECT_CALL(*refresh_, IsActive()).WillOnce(Return(true));
138 EXPECT_CALL(*refresh_, IsAwaitingScrollUpdateAck()).Times(0);
139 EXPECT_CALL(*glow_, OnOverscrolled(_, _, _, _, _)).Times(0);
140
141 controller_->OnOverscrolled(params);
142 testing::Mock::VerifyAndClearExpectations(refresh_);
143 testing::Mock::VerifyAndClearExpectations(glow_);
144 }
145
146 TEST_F(OverscrollControllerAndroidUnitTest,
147 ScrollBoundaryBehaviorNonePreventsNavigationAndGlow) {
148 ui::DidOverscrollParams params = CreateVerticalOverscrollParams();
149 params.scroll_boundary_behavior.y = cc::ScrollBoundaryBehavior::
150 ScrollBoundaryBehaviorType::kScrollBoundaryBehaviorTypeNone;
151
152 EXPECT_CALL(*refresh_, OnOverscrolled()).Times(0);
153 EXPECT_CALL(*refresh_, Reset());
154 EXPECT_CALL(*refresh_, IsActive()).WillOnce(Return(false));
155 EXPECT_CALL(*refresh_, IsAwaitingScrollUpdateAck()).WillOnce(Return(false));
156 EXPECT_CALL(*glow_, OnOverscrolled(_, gfx::Vector2dF(), gfx::Vector2dF(),
157 gfx::Vector2dF(), _));
158
159 controller_->OnOverscrolled(params);
160 testing::Mock::VerifyAndClearExpectations(refresh_);
161 testing::Mock::VerifyAndClearExpectations(glow_);
162
163 // Test that the "none" set on y-axis would not affect glow on x-axis.
164 params.accumulated_overscroll = gfx::Vector2dF(1, 1);
165 params.latest_overscroll_delta = gfx::Vector2dF(1, 1);
166 params.current_fling_velocity = gfx::Vector2dF(1, 1);
167
168 EXPECT_CALL(*refresh_, OnOverscrolled()).Times(0);
169 EXPECT_CALL(*refresh_, Reset());
170 EXPECT_CALL(*refresh_, IsActive()).WillOnce(Return(false));
171 EXPECT_CALL(*refresh_, IsAwaitingScrollUpdateAck()).WillOnce(Return(false));
172 EXPECT_CALL(*glow_,
173 OnOverscrolled(_, gfx::Vector2dF(560, 0), gfx::Vector2dF(560, 0),
174 gfx::Vector2dF(560, 0), _));
175
176 controller_->OnOverscrolled(params);
177 testing::Mock::VerifyAndClearExpectations(refresh_);
178 testing::Mock::VerifyAndClearExpectations(glow_);
179 }
180
181 } // namespace
182
183 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/android/overscroll_controller_android.cc ('k') | content/common/input_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698