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

Side by Side Diff: ui/android/overscroll_refresh_unittest.cc

Issue 2884423003: Use scroll-boundary-behavior to control overscroll-refresh/glow on android. (Closed)
Patch Set: Update the test Created 3 years, 6 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/android/scoped_java_ref.h" 5 #include "base/android/scoped_java_ref.h"
6 #include "cc/layers/layer.h" 6 #include "cc/layers/layer.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/android/overscroll_refresh.h" 8 #include "ui/android/overscroll_refresh.h"
9 #include "ui/android/overscroll_refresh_handler.h" 9 #include "ui/android/overscroll_refresh_handler.h"
10 10
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 EXPECT_TRUE(effect.IsAwaitingScrollUpdateAck()); 79 EXPECT_TRUE(effect.IsAwaitingScrollUpdateAck());
80 80
81 // The initial scroll should not be consumed, as it should first be offered 81 // The initial scroll should not be consumed, as it should first be offered
82 // to content. 82 // to content.
83 gfx::Vector2dF scroll_up(0, 10); 83 gfx::Vector2dF scroll_up(0, 10);
84 EXPECT_FALSE(effect.WillHandleScrollUpdate(scroll_up)); 84 EXPECT_FALSE(effect.WillHandleScrollUpdate(scroll_up));
85 EXPECT_FALSE(effect.IsActive()); 85 EXPECT_FALSE(effect.IsActive());
86 EXPECT_TRUE(effect.IsAwaitingScrollUpdateAck()); 86 EXPECT_TRUE(effect.IsAwaitingScrollUpdateAck());
87 87
88 // The unconsumed, overscrolling scroll will trigger the effect. 88 // The unconsumed, overscrolling scroll will trigger the effect.
89 effect.OnScrollUpdateAck(false); 89 effect.OnOverscrolled(true);
90 EXPECT_TRUE(effect.IsActive()); 90 EXPECT_TRUE(effect.IsActive());
91 EXPECT_FALSE(effect.IsAwaitingScrollUpdateAck()); 91 EXPECT_FALSE(effect.IsAwaitingScrollUpdateAck());
92 EXPECT_TRUE(GetAndResetPullStarted()); 92 EXPECT_TRUE(GetAndResetPullStarted());
93 93
94 // Further scrolls will be consumed. 94 // Further scrolls will be consumed.
95 EXPECT_TRUE(effect.WillHandleScrollUpdate(gfx::Vector2dF(0, 50))); 95 EXPECT_TRUE(effect.WillHandleScrollUpdate(gfx::Vector2dF(0, 50)));
96 EXPECT_EQ(50.f, GetAndResetPullDelta()); 96 EXPECT_EQ(50.f, GetAndResetPullDelta());
97 EXPECT_TRUE(effect.IsActive()); 97 EXPECT_TRUE(effect.IsActive());
98 98
99 // Even scrolls in the down direction should be consumed. 99 // Even scrolls in the down direction should be consumed.
(...skipping 17 matching lines...) Expand all
117 // even if the subsequent scroll overscrolls upward. 117 // even if the subsequent scroll overscrolls upward.
118 gfx::Vector2dF nonzero_offset(0, 10); 118 gfx::Vector2dF nonzero_offset(0, 10);
119 bool overflow_y_hidden = false; 119 bool overflow_y_hidden = false;
120 effect.OnFrameUpdated(nonzero_offset, overflow_y_hidden); 120 effect.OnFrameUpdated(nonzero_offset, overflow_y_hidden);
121 effect.OnScrollBegin(); 121 effect.OnScrollBegin();
122 122
123 effect.OnFrameUpdated(gfx::Vector2dF(), overflow_y_hidden); 123 effect.OnFrameUpdated(gfx::Vector2dF(), overflow_y_hidden);
124 ASSERT_FALSE(effect.WillHandleScrollUpdate(gfx::Vector2dF(0, 10))); 124 ASSERT_FALSE(effect.WillHandleScrollUpdate(gfx::Vector2dF(0, 10)));
125 EXPECT_FALSE(effect.IsActive()); 125 EXPECT_FALSE(effect.IsActive());
126 EXPECT_FALSE(effect.IsAwaitingScrollUpdateAck()); 126 EXPECT_FALSE(effect.IsAwaitingScrollUpdateAck());
127 effect.OnScrollUpdateAck(false); 127 effect.OnOverscrolled(true);
128 EXPECT_FALSE(effect.IsActive()); 128 EXPECT_FALSE(effect.IsActive());
129 EXPECT_FALSE(effect.IsAwaitingScrollUpdateAck()); 129 EXPECT_FALSE(effect.IsAwaitingScrollUpdateAck());
130 EXPECT_FALSE(effect.WillHandleScrollUpdate(gfx::Vector2dF(0, 500))); 130 EXPECT_FALSE(effect.WillHandleScrollUpdate(gfx::Vector2dF(0, 500)));
131 effect.OnScrollEnd(gfx::Vector2dF()); 131 effect.OnScrollEnd(gfx::Vector2dF());
132 EXPECT_FALSE(GetAndResetPullStarted()); 132 EXPECT_FALSE(GetAndResetPullStarted());
133 EXPECT_FALSE(GetAndResetPullReleased()); 133 EXPECT_FALSE(GetAndResetPullReleased());
134 } 134 }
135 135
136 TEST_F(OverscrollRefreshTest, NotTriggeredIfOverflowYHidden) { 136 TEST_F(OverscrollRefreshTest, NotTriggeredIfOverflowYHidden) {
137 OverscrollRefresh effect(this); 137 OverscrollRefresh effect(this);
138 138
139 // overflow-y:hidden at the start of scroll will prevent activation. 139 // overflow-y:hidden at the start of scroll will prevent activation.
140 gfx::Vector2dF zero_offset; 140 gfx::Vector2dF zero_offset;
141 bool overflow_y_hidden = true; 141 bool overflow_y_hidden = true;
142 effect.OnFrameUpdated(zero_offset, overflow_y_hidden); 142 effect.OnFrameUpdated(zero_offset, overflow_y_hidden);
143 effect.OnScrollBegin(); 143 effect.OnScrollBegin();
144 144
145 ASSERT_FALSE(effect.WillHandleScrollUpdate(gfx::Vector2dF(0, 10))); 145 ASSERT_FALSE(effect.WillHandleScrollUpdate(gfx::Vector2dF(0, 10)));
146 EXPECT_FALSE(effect.IsActive()); 146 EXPECT_FALSE(effect.IsActive());
147 EXPECT_FALSE(effect.IsAwaitingScrollUpdateAck()); 147 EXPECT_FALSE(effect.IsAwaitingScrollUpdateAck());
148 effect.OnScrollUpdateAck(false); 148 effect.OnOverscrolled(true);
149 EXPECT_FALSE(effect.IsActive()); 149 EXPECT_FALSE(effect.IsActive());
150 EXPECT_FALSE(effect.IsAwaitingScrollUpdateAck()); 150 EXPECT_FALSE(effect.IsAwaitingScrollUpdateAck());
151 EXPECT_FALSE(effect.WillHandleScrollUpdate(gfx::Vector2dF(0, 500))); 151 EXPECT_FALSE(effect.WillHandleScrollUpdate(gfx::Vector2dF(0, 500)));
152 effect.OnScrollEnd(gfx::Vector2dF()); 152 effect.OnScrollEnd(gfx::Vector2dF());
153 EXPECT_FALSE(GetAndResetPullStarted()); 153 EXPECT_FALSE(GetAndResetPullStarted());
154 EXPECT_FALSE(GetAndResetPullReleased()); 154 EXPECT_FALSE(GetAndResetPullReleased());
155 } 155 }
156 156
157 TEST_F(OverscrollRefreshTest, NotTriggeredIfInitialScrollDownward) { 157 TEST_F(OverscrollRefreshTest, NotTriggeredIfInitialScrollDownward) {
158 OverscrollRefresh effect(this); 158 OverscrollRefresh effect(this);
159 effect.OnScrollBegin(); 159 effect.OnScrollBegin();
160 160
161 // A downward initial scroll will prevent activation, even if the subsequent 161 // A downward initial scroll will prevent activation, even if the subsequent
162 // scroll overscrolls upward. 162 // scroll overscrolls upward.
163 ASSERT_FALSE(effect.WillHandleScrollUpdate(gfx::Vector2dF(0, -10))); 163 ASSERT_FALSE(effect.WillHandleScrollUpdate(gfx::Vector2dF(0, -10)));
164 EXPECT_FALSE(effect.IsActive()); 164 EXPECT_FALSE(effect.IsActive());
165 EXPECT_FALSE(effect.IsAwaitingScrollUpdateAck()); 165 EXPECT_FALSE(effect.IsAwaitingScrollUpdateAck());
166 166
167 effect.OnScrollUpdateAck(false); 167 effect.OnOverscrolled(true);
168 EXPECT_FALSE(effect.IsActive()); 168 EXPECT_FALSE(effect.IsActive());
169 EXPECT_FALSE(effect.IsAwaitingScrollUpdateAck()); 169 EXPECT_FALSE(effect.IsAwaitingScrollUpdateAck());
170 EXPECT_FALSE(effect.WillHandleScrollUpdate(gfx::Vector2dF(0, 500))); 170 EXPECT_FALSE(effect.WillHandleScrollUpdate(gfx::Vector2dF(0, 500)));
171 effect.OnScrollEnd(gfx::Vector2dF()); 171 effect.OnScrollEnd(gfx::Vector2dF());
172 EXPECT_FALSE(GetAndResetPullReleased()); 172 EXPECT_FALSE(GetAndResetPullReleased());
173 } 173 }
174 174
175 TEST_F(OverscrollRefreshTest, NotTriggeredIfInitialScrollOrTouchConsumed) { 175 TEST_F(OverscrollRefreshTest, NotTriggeredIfInitialScrollOrTouchConsumed) {
176 OverscrollRefresh effect(this); 176 OverscrollRefresh effect(this);
177 effect.OnScrollBegin(); 177 effect.OnScrollBegin();
178 ASSERT_FALSE(effect.WillHandleScrollUpdate(gfx::Vector2dF(0, 10))); 178 ASSERT_FALSE(effect.WillHandleScrollUpdate(gfx::Vector2dF(0, 10)));
179 ASSERT_TRUE(effect.IsAwaitingScrollUpdateAck()); 179 ASSERT_TRUE(effect.IsAwaitingScrollUpdateAck());
180 180
181 // Consumption of the initial touchmove or scroll should prevent future 181 // Consumption of the initial touchmove or scroll should prevent future
182 // activation. 182 // activation.
183 effect.OnScrollUpdateAck(true); 183 effect.OnOverscrolled(false);
184 EXPECT_FALSE(effect.IsActive()); 184 EXPECT_FALSE(effect.IsActive());
185 EXPECT_FALSE(effect.IsAwaitingScrollUpdateAck()); 185 EXPECT_FALSE(effect.IsAwaitingScrollUpdateAck());
186 EXPECT_FALSE(effect.WillHandleScrollUpdate(gfx::Vector2dF(0, 500))); 186 EXPECT_FALSE(effect.WillHandleScrollUpdate(gfx::Vector2dF(0, 500)));
187 effect.OnScrollUpdateAck(false); 187 effect.OnOverscrolled(true);
188 EXPECT_FALSE(effect.IsActive()); 188 EXPECT_FALSE(effect.IsActive());
189 EXPECT_FALSE(effect.IsAwaitingScrollUpdateAck()); 189 EXPECT_FALSE(effect.IsAwaitingScrollUpdateAck());
190 EXPECT_FALSE(effect.WillHandleScrollUpdate(gfx::Vector2dF(0, 500))); 190 EXPECT_FALSE(effect.WillHandleScrollUpdate(gfx::Vector2dF(0, 500)));
191 effect.OnScrollEnd(gfx::Vector2dF()); 191 effect.OnScrollEnd(gfx::Vector2dF());
192 EXPECT_FALSE(GetAndResetPullStarted()); 192 EXPECT_FALSE(GetAndResetPullStarted());
193 EXPECT_FALSE(GetAndResetPullReleased()); 193 EXPECT_FALSE(GetAndResetPullReleased());
194 } 194 }
195 195
196 TEST_F(OverscrollRefreshTest, NotTriggeredIfFlungDownward) { 196 TEST_F(OverscrollRefreshTest, NotTriggeredIfFlungDownward) {
197 OverscrollRefresh effect(this); 197 OverscrollRefresh effect(this);
198 effect.OnScrollBegin(); 198 effect.OnScrollBegin();
199 ASSERT_FALSE(effect.WillHandleScrollUpdate(gfx::Vector2dF(0, 10))); 199 ASSERT_FALSE(effect.WillHandleScrollUpdate(gfx::Vector2dF(0, 10)));
200 ASSERT_TRUE(effect.IsAwaitingScrollUpdateAck()); 200 ASSERT_TRUE(effect.IsAwaitingScrollUpdateAck());
201 effect.OnScrollUpdateAck(false); 201 effect.OnOverscrolled(true);
202 ASSERT_TRUE(effect.IsActive()); 202 ASSERT_TRUE(effect.IsActive());
203 EXPECT_TRUE(GetAndResetPullStarted()); 203 EXPECT_TRUE(GetAndResetPullStarted());
204 204
205 // Terminating the pull with a down-directed fling should prevent triggering. 205 // Terminating the pull with a down-directed fling should prevent triggering.
206 effect.OnScrollEnd(gfx::Vector2dF(0, -1000)); 206 effect.OnScrollEnd(gfx::Vector2dF(0, -1000));
207 EXPECT_TRUE(GetAndResetPullReleased()); 207 EXPECT_TRUE(GetAndResetPullReleased());
208 EXPECT_FALSE(GetAndResetRefreshAllowed()); 208 EXPECT_FALSE(GetAndResetRefreshAllowed());
209 } 209 }
210 210
211 TEST_F(OverscrollRefreshTest, NotTriggeredIfReleasedWithoutActivation) { 211 TEST_F(OverscrollRefreshTest, NotTriggeredIfReleasedWithoutActivation) {
212 OverscrollRefresh effect(this); 212 OverscrollRefresh effect(this);
213 effect.OnScrollBegin(); 213 effect.OnScrollBegin();
214 ASSERT_FALSE(effect.WillHandleScrollUpdate(gfx::Vector2dF(0, 10))); 214 ASSERT_FALSE(effect.WillHandleScrollUpdate(gfx::Vector2dF(0, 10)));
215 ASSERT_TRUE(effect.IsAwaitingScrollUpdateAck()); 215 ASSERT_TRUE(effect.IsAwaitingScrollUpdateAck());
216 effect.OnScrollUpdateAck(false); 216 effect.OnOverscrolled(true);
217 ASSERT_TRUE(effect.IsActive()); 217 ASSERT_TRUE(effect.IsActive());
218 EXPECT_TRUE(GetAndResetPullStarted()); 218 EXPECT_TRUE(GetAndResetPullStarted());
219 219
220 // An early release should prevent the refresh action from firing. 220 // An early release should prevent the refresh action from firing.
221 effect.ReleaseWithoutActivation(); 221 effect.ReleaseWithoutActivation();
222 effect.OnScrollEnd(gfx::Vector2dF()); 222 effect.OnScrollEnd(gfx::Vector2dF());
223 EXPECT_TRUE(GetAndResetPullReleased()); 223 EXPECT_TRUE(GetAndResetPullReleased());
224 EXPECT_FALSE(GetAndResetRefreshAllowed()); 224 EXPECT_FALSE(GetAndResetRefreshAllowed());
225 } 225 }
226 226
227 TEST_F(OverscrollRefreshTest, NotTriggeredIfReset) { 227 TEST_F(OverscrollRefreshTest, NotTriggeredIfReset) {
228 OverscrollRefresh effect(this); 228 OverscrollRefresh effect(this);
229 effect.OnScrollBegin(); 229 effect.OnScrollBegin();
230 ASSERT_FALSE(effect.WillHandleScrollUpdate(gfx::Vector2dF(0, 10))); 230 ASSERT_FALSE(effect.WillHandleScrollUpdate(gfx::Vector2dF(0, 10)));
231 ASSERT_TRUE(effect.IsAwaitingScrollUpdateAck()); 231 ASSERT_TRUE(effect.IsAwaitingScrollUpdateAck());
232 effect.OnScrollUpdateAck(false); 232 effect.OnOverscrolled(true);
233 ASSERT_TRUE(effect.IsActive()); 233 ASSERT_TRUE(effect.IsActive());
234 EXPECT_TRUE(GetAndResetPullStarted()); 234 EXPECT_TRUE(GetAndResetPullStarted());
235 235
236 // An early reset should prevent the refresh action from firing. 236 // An early reset should prevent the refresh action from firing.
237 effect.Reset(); 237 effect.Reset();
238 EXPECT_TRUE(GetAndResetPullReset()); 238 EXPECT_TRUE(GetAndResetPullReset());
239 effect.OnScrollEnd(gfx::Vector2dF()); 239 effect.OnScrollEnd(gfx::Vector2dF());
240 EXPECT_FALSE(GetAndResetPullReleased()); 240 EXPECT_FALSE(GetAndResetPullReleased());
241 } 241 }
242 242
243 } // namespace ui 243 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698