blob: 8921378389fc4ef10163d7106d43c5fb69671d33 [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2017 The Chromium Authors
Mohsen Izadi9830436c2017-12-21 18:02:462// 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/renderer_host/overscroll_controller.h"
6
7#include <memory>
8
9#include "base/containers/queue.h"
chaopengcd44c7622018-04-13 04:08:2110#include "base/test/scoped_feature_list.h"
Mohsen Izadi9830436c2017-12-21 18:02:4611#include "content/browser/renderer_host/overscroll_controller_delegate.h"
Arthur Sonzognibdeca8e2023-09-11 08:32:1212#include "content/common/features.h"
chaopengcd44c7622018-04-13 04:08:2113#include "content/public/browser/overscroll_configuration.h"
Mohsen Izadi8c59ba52018-04-12 18:52:0114#include "content/public/test/scoped_overscroll_modes.h"
Mohsen Izadi9830436c2017-12-21 18:02:4615#include "content/test/test_overscroll_delegate.h"
16#include "testing/gtest/include/gtest/gtest.h"
Dave Tapuska6db16e32020-06-09 13:58:0617#include "third_party/blink/public/common/input/synthetic_web_input_event_builders.h"
Dave Tapuska129cef82019-12-19 16:36:4818#include "third_party/blink/public/common/input/web_input_event.h"
Mohsen Izadi9830436c2017-12-21 18:02:4619
20namespace content {
21
22class OverscrollControllerTest : public ::testing::Test {
Peter Boström9b036532021-10-28 23:37:2823 public:
24 OverscrollControllerTest(const OverscrollControllerTest&) = delete;
25 OverscrollControllerTest& operator=(const OverscrollControllerTest&) = delete;
26
Mohsen Izadi9830436c2017-12-21 18:02:4627 protected:
28 OverscrollControllerTest() {}
29 ~OverscrollControllerTest() override {}
30
31 void SetUp() override {
chaopengcd44c7622018-04-13 04:08:2132 OverscrollConfig::ResetTouchpadOverscrollHistoryNavigationEnabled();
33 scoped_feature_list_.InitAndEnableFeature(
34 features::kTouchpadOverscrollHistoryNavigation);
Mohsen Izadi9830436c2017-12-21 18:02:4635 delegate_ = std::make_unique<TestOverscrollDelegate>(gfx::Size(400, 300));
36 controller_ = std::make_unique<OverscrollController>();
Robert Flackc3670192021-03-30 16:18:0937 controller_->set_delegate(delegate_->GetWeakPtr());
Mohsen Izadi9830436c2017-12-21 18:02:4638 }
39
40 void TearDown() override {
41 controller_ = nullptr;
42 delegate_ = nullptr;
43 }
44
45 // Creates and sends a mouse-wheel event to the overscroll controller. Returns
46 // |true| if the event is consumed by the overscroll controller.
47 bool SimulateMouseWheel(float dx, float dy) {
48 DCHECK(!current_event_);
49 current_event_ = std::make_unique<blink::WebMouseWheelEvent>(
Dave Tapuska6db16e32020-06-09 13:58:0650 blink::SyntheticWebMouseWheelEventBuilder::Build(
Mohsen Izadiffcbc61f12020-02-09 06:31:2751 0, 0, dx, dy, 0, ui::ScrollGranularity::kScrollByPrecisePixel));
Mohsen Izadi9830436c2017-12-21 18:02:4652 return controller_->WillHandleEvent(*current_event_);
53 }
54
chaopeng1d469b02018-04-05 15:41:0755 // Creates and sends a gesture event to the overscroll controller. Returns
56 // |true| if the event is consumed by the overscroll controller.
57 bool SimulateGestureEvent(blink::WebInputEvent::Type type,
Mohsen Izadi5a6583512018-04-23 18:31:1958 blink::WebGestureDevice source_device,
Daniel Cheng224569ee2018-04-25 05:45:0659 base::TimeTicks timestamp) {
chaopeng1d469b02018-04-05 15:41:0760 DCHECK(!current_event_);
61 current_event_ = std::make_unique<blink::WebGestureEvent>(
Dave Tapuska6db16e32020-06-09 13:58:0662 blink::SyntheticWebGestureEventBuilder::Build(type, source_device));
Daniel Cheng224569ee2018-04-25 05:45:0663 current_event_->SetTimeStamp(timestamp);
chaopeng1d469b02018-04-05 15:41:0764 return controller_->WillHandleEvent(*current_event_);
65 }
66
Mohsen Izadi9830436c2017-12-21 18:02:4667 // Creates and sends a gesture-scroll-update event to the overscroll
68 // controller. Returns |true| if the event is consumed by the overscroll
69 // controller.
70 bool SimulateGestureScrollUpdate(float dx,
71 float dy,
chaopeng1d469b02018-04-05 15:41:0772 blink::WebGestureDevice device,
Daniel Cheng224569ee2018-04-25 05:45:0673 base::TimeTicks timestamp,
chaopeng1d469b02018-04-05 15:41:0774 bool inertial_update) {
Mohsen Izadi9830436c2017-12-21 18:02:4675 DCHECK(!current_event_);
chaopeng1d469b02018-04-05 15:41:0776 auto event = std::make_unique<blink::WebGestureEvent>(
Dave Tapuska6db16e32020-06-09 13:58:0677 blink::SyntheticWebGestureEventBuilder::BuildScrollUpdate(dx, dy, 0,
78 device));
Daniel Cheng224569ee2018-04-25 05:45:0679 event->SetTimeStamp(timestamp);
chaopeng1d469b02018-04-05 15:41:0780 if (inertial_update) {
81 event->data.scroll_update.inertial_phase =
Daniel Libby6ce6b95a2019-05-10 17:06:2682 blink::WebGestureEvent::InertialPhaseState::kMomentum;
chaopeng1d469b02018-04-05 15:41:0783 }
84 current_event_ = std::move(event);
Mohsen Izadi9830436c2017-12-21 18:02:4685 return controller_->WillHandleEvent(*current_event_);
86 }
87
Mohsen Izadi8c59ba52018-04-12 18:52:0188 // Creates and sends a gesture-fling-start event to the overscroll controller.
89 // Returns |true| if the event is consumed by the overscroll controller.
90 bool SimulateGestureFlingStart(float velocity_x,
91 float velocity_y,
Mohsen Izadi5a6583512018-04-23 18:31:1992 blink::WebGestureDevice device,
Daniel Cheng224569ee2018-04-25 05:45:0693 base::TimeTicks timestamp) {
Mohsen Izadi8c59ba52018-04-12 18:52:0194 DCHECK(!current_event_);
95 current_event_ = std::make_unique<blink::WebGestureEvent>(
Dave Tapuska6db16e32020-06-09 13:58:0696 blink::SyntheticWebGestureEventBuilder::BuildFling(velocity_x,
97 velocity_y, device));
Daniel Cheng224569ee2018-04-25 05:45:0698 current_event_->SetTimeStamp(timestamp);
Mohsen Izadi8c59ba52018-04-12 18:52:0199 return controller_->WillHandleEvent(*current_event_);
100 }
101
Mohsen Izadi9830436c2017-12-21 18:02:46102 // Notifies the overscroll controller that the current event is ACKed.
103 void SimulateAck(bool processed) {
104 DCHECK(current_event_);
105 controller_->ReceivedEventACK(*current_event_, processed);
106 current_event_ = nullptr;
107 }
108
109 TestOverscrollDelegate* delegate() const { return delegate_.get(); }
110
111 OverscrollMode controller_mode() const {
112 return controller_->overscroll_mode_;
113 }
114
115 OverscrollSource controller_source() const {
116 return controller_->overscroll_source_;
117 }
118
119 private:
120 std::unique_ptr<TestOverscrollDelegate> delegate_;
121 std::unique_ptr<OverscrollController> controller_;
122
123 // Keeps track of the last event that has been processed by the overscroll
124 // controller which is not yet ACKed. Will be null if no event is processed or
125 // the last event is ACKed.
126 std::unique_ptr<blink::WebInputEvent> current_event_;
127
chaopengcd44c7622018-04-13 04:08:21128 base::test::ScopedFeatureList scoped_feature_list_;
Mohsen Izadi9830436c2017-12-21 18:02:46129};
130
131// Tests that if a mouse-wheel is consumed by content before overscroll is
132// initiated, overscroll will not initiate anymore.
133TEST_F(OverscrollControllerTest, MouseWheelConsumedPreventsOverscroll) {
Daniel Cheng224569ee2018-04-25 05:45:06134 const base::TimeTicks timestamp =
135 blink::WebInputEvent::GetStaticTimeStampForTests();
Mohsen Izadi5a6583512018-04-23 18:31:19136
Mohsen Izadi9830436c2017-12-21 18:02:46137 // Simulate a mouse-wheel, ACK it as not processed, simulate the corresponding
Mohsen Izadi8c59ba52018-04-12 18:52:01138 // gesture scroll-update event, and ACK it as not processed. Since it is not
Mohsen Izadi9830436c2017-12-21 18:02:46139 // passing the start threshold, no overscroll should happen.
140 EXPECT_FALSE(SimulateMouseWheel(10, 0));
141 SimulateAck(false);
chaopeng1d469b02018-04-05 15:41:07142 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00143 10, 0, blink::WebGestureDevice::kTouchpad, timestamp, false));
Mohsen Izadi9830436c2017-12-21 18:02:46144 SimulateAck(false);
145 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
146 EXPECT_EQ(OverscrollSource::NONE, controller_source());
147 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
148 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
149
150 // Simulate a mouse-wheel and ACK it as processed. No gesture scroll-update
151 // needs to be simulated. Still no overscroll.
152 EXPECT_FALSE(SimulateMouseWheel(10, 0));
153 SimulateAck(true);
154 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
155 EXPECT_EQ(OverscrollSource::NONE, controller_source());
156 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
157 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
158
159 // Simulate a mouse-wheel and the corresponding gesture scroll-update both
160 // ACKed as not processed. Although the scroll passes overscroll start
161 // threshold, no overscroll should happen since the previous mouse-wheel was
162 // marked as processed.
163 EXPECT_FALSE(SimulateMouseWheel(100, 0));
164 SimulateAck(false);
chaopeng1d469b02018-04-05 15:41:07165 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00166 100, 0, blink::WebGestureDevice::kTouchpad, timestamp, false));
Mohsen Izadi9830436c2017-12-21 18:02:46167 SimulateAck(false);
168 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
169 EXPECT_EQ(OverscrollSource::NONE, controller_source());
170 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
171 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
172}
173
chaopeng1d469b02018-04-05 15:41:07174// Verifying the inertial scroll event completes overscroll. After that we will
175// ignore the following inertial scroll events until new sequence start.
176TEST_F(OverscrollControllerTest,
177 InertialGestureScrollUpdateCompletesOverscroll) {
Daniel Cheng224569ee2018-04-25 05:45:06178 const base::TimeTicks timestamp =
179 blink::WebInputEvent::GetStaticTimeStampForTests();
Mohsen Izadi5a6583512018-04-23 18:31:19180
Dave Tapuska347d60a2020-04-21 23:55:47181 EXPECT_FALSE(
182 SimulateGestureEvent(blink::WebInputEvent::Type::kGestureScrollBegin,
183 blink::WebGestureDevice::kTouchpad, timestamp));
chaopeng1d469b02018-04-05 15:41:07184 SimulateAck(false);
185
186 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00187 200, 0, blink::WebGestureDevice::kTouchpad, timestamp, false));
chaopeng1d469b02018-04-05 15:41:07188 SimulateAck(false);
189 EXPECT_EQ(OVERSCROLL_EAST, controller_mode());
190 EXPECT_EQ(OverscrollSource::TOUCHPAD, controller_source());
191 EXPECT_EQ(OVERSCROLL_EAST, delegate()->current_mode());
192 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
193
194 // Inertial update event complete the overscroll action.
195 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00196 100, 0, blink::WebGestureDevice::kTouchpad, timestamp, true));
chaopeng1d469b02018-04-05 15:41:07197 SimulateAck(false);
chaopenga7585d792018-04-10 18:02:38198 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
199 EXPECT_EQ(OverscrollSource::NONE, controller_source());
200 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
chaopeng1d469b02018-04-05 15:41:07201 EXPECT_EQ(OVERSCROLL_EAST, delegate()->completed_mode());
202
203 // Next Inertial update event would be consumed by overscroll controller.
204 EXPECT_TRUE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00205 100, 0, blink::WebGestureDevice::kTouchpad, timestamp, true));
chaopeng1d469b02018-04-05 15:41:07206}
207
chaopeng9736c522018-05-08 18:32:27208// Ensure inertial gesture scroll update can not start overscroll.
209TEST_F(OverscrollControllerTest, InertialGSUsDoNotStartOverscroll) {
210 base::TimeTicks timestamp =
211 blink::WebInputEvent::GetStaticTimeStampForTests();
212 // Inertial update event complete the overscroll action.
213 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00214 100, 0, blink::WebGestureDevice::kTouchpad, timestamp, true));
chaopeng9736c522018-05-08 18:32:27215 SimulateAck(false);
216 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
217 EXPECT_EQ(OverscrollSource::NONE, controller_source());
218 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
219 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
220}
221
222// After 300ms inertial gesture scroll updates, overscroll must get cancelled
223// if not completed.
224TEST_F(OverscrollControllerTest, OnlyProcessLimitedInertialGSUEvents) {
225 base::TimeTicks timestamp =
226 blink::WebInputEvent::GetStaticTimeStampForTests();
227
Dave Tapuska347d60a2020-04-21 23:55:47228 EXPECT_FALSE(
229 SimulateGestureEvent(blink::WebInputEvent::Type::kGestureScrollBegin,
230 blink::WebGestureDevice::kTouchpad, timestamp));
chaopeng9736c522018-05-08 18:32:27231 SimulateAck(false);
232
233 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00234 61, 0, blink::WebGestureDevice::kTouchpad, timestamp, false));
chaopeng9736c522018-05-08 18:32:27235 SimulateAck(false);
236 EXPECT_EQ(OVERSCROLL_EAST, controller_mode());
237 EXPECT_EQ(OverscrollSource::TOUCHPAD, controller_source());
238 EXPECT_EQ(OVERSCROLL_EAST, delegate()->current_mode());
239 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
240
241 // First inertial.
Peter Kastinge5a38ed2021-10-02 03:06:35242 timestamp += base::Seconds(1);
chaopeng9736c522018-05-08 18:32:27243 EXPECT_TRUE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00244 1, 0, blink::WebGestureDevice::kTouchpad, timestamp, true));
chaopeng9736c522018-05-08 18:32:27245 SimulateAck(true);
246 EXPECT_EQ(OVERSCROLL_EAST, controller_mode());
247 EXPECT_EQ(OverscrollSource::TOUCHPAD, controller_source());
248 EXPECT_EQ(OVERSCROLL_EAST, delegate()->current_mode());
249 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
250
251 // Not cancel in 10ms.
Peter Kastinge5a38ed2021-10-02 03:06:35252 timestamp += base::Milliseconds(10);
chaopeng9736c522018-05-08 18:32:27253 EXPECT_TRUE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00254 1, 0, blink::WebGestureDevice::kTouchpad, timestamp, true));
chaopeng9736c522018-05-08 18:32:27255 SimulateAck(true);
256 EXPECT_EQ(OVERSCROLL_EAST, controller_mode());
257 EXPECT_EQ(OverscrollSource::TOUCHPAD, controller_source());
258 EXPECT_EQ(OVERSCROLL_EAST, delegate()->current_mode());
259 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
260
261 // Cancel after 300ms.
Peter Kastinge5a38ed2021-10-02 03:06:35262 timestamp += base::Milliseconds(291);
chaopeng9736c522018-05-08 18:32:27263 EXPECT_TRUE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00264 1, 0, blink::WebGestureDevice::kTouchpad, timestamp, true));
chaopeng9736c522018-05-08 18:32:27265 SimulateAck(true);
266 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
267 EXPECT_EQ(OverscrollSource::NONE, controller_source());
268 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
269 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
270
271 // Next event should be ignored.
Peter Kastinge5a38ed2021-10-02 03:06:35272 timestamp += base::Milliseconds(100);
chaopeng9736c522018-05-08 18:32:27273 EXPECT_TRUE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00274 1, 0, blink::WebGestureDevice::kTouchpad, timestamp, true));
chaopeng9736c522018-05-08 18:32:27275}
276
Mohsen Izadi8c59ba52018-04-12 18:52:01277// Verifies that when pull-to-refresh is disabled, it is not triggered for
278// neither touchpad nor touchscreen.
279TEST_F(OverscrollControllerTest, PullToRefreshDisabled) {
280 ScopedPullToRefreshMode scoped_mode(
281 OverscrollConfig::PullToRefreshMode::kDisabled);
282
Daniel Cheng224569ee2018-04-25 05:45:06283 base::TimeTicks timestamp =
284 blink::WebInputEvent::GetStaticTimeStampForTests();
Mohsen Izadi5a6583512018-04-23 18:31:19285
Dave Tapuska347d60a2020-04-21 23:55:47286 EXPECT_FALSE(
287 SimulateGestureEvent(blink::WebInputEvent::Type::kGestureScrollBegin,
288 blink::WebGestureDevice::kTouchpad, timestamp));
Mohsen Izadi5a6583512018-04-23 18:31:19289 SimulateAck(false);
290
Mohsen Izadi8c59ba52018-04-12 18:52:01291 // Simulate a touchpad gesture scroll-update event that passes the start
292 // threshold and ACK it as not processed. Pull-to-refresh should not be
293 // triggered.
294 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00295 0, 80, blink::WebGestureDevice::kTouchpad, timestamp, false));
Mohsen Izadi8c59ba52018-04-12 18:52:01296 SimulateAck(false);
297 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
298 EXPECT_EQ(OverscrollSource::NONE, controller_source());
299 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
300 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
301
Peter Kastinge5a38ed2021-10-02 03:06:35302 timestamp += base::Seconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19303
Mohsen Izadi8c59ba52018-04-12 18:52:01304 // Simulate a touchpad zero-velocity fling-start which would normally end
305 // pull-to-refresh, and ACK it as not processed. Nothing should happen.
Daniel Cheng7f9ec902019-04-18 05:07:00306 EXPECT_FALSE(SimulateGestureFlingStart(
307 0, 0, blink::WebGestureDevice::kTouchpad, timestamp));
Mohsen Izadi8c59ba52018-04-12 18:52:01308 SimulateAck(false);
309 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
310 EXPECT_EQ(OverscrollSource::NONE, controller_source());
311 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
312 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
313
Peter Kastinge5a38ed2021-10-02 03:06:35314 timestamp += base::Seconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19315
Dave Tapuska347d60a2020-04-21 23:55:47316 EXPECT_FALSE(
317 SimulateGestureEvent(blink::WebInputEvent::Type::kGestureScrollBegin,
318 blink::WebGestureDevice::kTouchscreen, timestamp));
Mohsen Izadi5a6583512018-04-23 18:31:19319 SimulateAck(false);
320
Mohsen Izadi8c59ba52018-04-12 18:52:01321 // Simulate a touchscreen gesture scroll-update event that passes the start
322 // threshold and ACK it as not processed. Pull-to-refresh should not be
323 // triggered.
324 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00325 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi8c59ba52018-04-12 18:52:01326 SimulateAck(false);
327 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
328 EXPECT_EQ(OverscrollSource::NONE, controller_source());
329 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
330 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
331
Peter Kastinge5a38ed2021-10-02 03:06:35332 timestamp += base::Seconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19333
Mohsen Izadi8c59ba52018-04-12 18:52:01334 // Simulate a touchscreen gesture scroll-end which would normally end
335 // pull-to-refresh, and ACK it as not processed. Nothing should happen.
Dave Tapuska347d60a2020-04-21 23:55:47336 EXPECT_FALSE(
337 SimulateGestureEvent(blink::WebInputEvent::Type::kGestureScrollEnd,
338 blink::WebGestureDevice::kTouchscreen, timestamp));
Mohsen Izadi8c59ba52018-04-12 18:52:01339 SimulateAck(false);
340 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
341 EXPECT_EQ(OverscrollSource::NONE, controller_source());
342 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
343 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
344}
345
346// Verifies that when pull-to-refresh is enabled, it is triggered for both
347// touchpad and touchscreen.
348TEST_F(OverscrollControllerTest, PullToRefreshEnabled) {
349 ScopedPullToRefreshMode scoped_mode(
350 OverscrollConfig::PullToRefreshMode::kEnabled);
351
Daniel Cheng224569ee2018-04-25 05:45:06352 base::TimeTicks timestamp =
353 blink::WebInputEvent::GetStaticTimeStampForTests();
Mohsen Izadi5a6583512018-04-23 18:31:19354
Dave Tapuska347d60a2020-04-21 23:55:47355 EXPECT_FALSE(
356 SimulateGestureEvent(blink::WebInputEvent::Type::kGestureScrollBegin,
357 blink::WebGestureDevice::kTouchpad, timestamp));
Mohsen Izadi5a6583512018-04-23 18:31:19358 SimulateAck(false);
359
Mohsen Izadi8c59ba52018-04-12 18:52:01360 // Simulate a touchpad gesture scroll-update event that passes the start
361 // threshold and ACK it as not processed. Pull-to-refresh should be triggered.
362 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00363 0, 80, blink::WebGestureDevice::kTouchpad, timestamp, false));
Mohsen Izadi8c59ba52018-04-12 18:52:01364 SimulateAck(false);
365 EXPECT_EQ(OVERSCROLL_SOUTH, controller_mode());
366 EXPECT_EQ(OverscrollSource::TOUCHPAD, controller_source());
367 EXPECT_EQ(OVERSCROLL_SOUTH, delegate()->current_mode());
368 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
369
Peter Kastinge5a38ed2021-10-02 03:06:35370 timestamp += base::Seconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19371
Mohsen Izadi8c59ba52018-04-12 18:52:01372 // Simulate a touchpad zero-velocity fling-start and ACK it as not processed..
373 // It should abort pull-to-refresh.
Daniel Cheng7f9ec902019-04-18 05:07:00374 EXPECT_FALSE(SimulateGestureFlingStart(
375 0, 0, blink::WebGestureDevice::kTouchpad, timestamp));
Mohsen Izadi8c59ba52018-04-12 18:52:01376 SimulateAck(false);
377 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
378 EXPECT_EQ(OverscrollSource::NONE, controller_source());
379 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
380 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
381
Peter Kastinge5a38ed2021-10-02 03:06:35382 timestamp += base::Seconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19383
Dave Tapuska347d60a2020-04-21 23:55:47384 EXPECT_FALSE(
385 SimulateGestureEvent(blink::WebInputEvent::Type::kGestureScrollBegin,
386 blink::WebGestureDevice::kTouchscreen, timestamp));
Mohsen Izadi5a6583512018-04-23 18:31:19387 SimulateAck(false);
388
Mohsen Izadi8c59ba52018-04-12 18:52:01389 // Simulate a touchscreen gesture scroll-update event that passes the start
390 // threshold and ACK it as not processed. Pull-to-refresh should be triggered.
391 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00392 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi8c59ba52018-04-12 18:52:01393 SimulateAck(false);
394 EXPECT_EQ(OVERSCROLL_SOUTH, controller_mode());
395 EXPECT_EQ(OverscrollSource::TOUCHSCREEN, controller_source());
396 EXPECT_EQ(OVERSCROLL_SOUTH, delegate()->current_mode());
397 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
398
Peter Kastinge5a38ed2021-10-02 03:06:35399 timestamp += base::Seconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19400
Mohsen Izadi8c59ba52018-04-12 18:52:01401 // Simulate a touchscreen gesture scroll-end and ACK it as not processed. It
402 // should abort pull-to-refresh.
Dave Tapuska347d60a2020-04-21 23:55:47403 EXPECT_FALSE(
404 SimulateGestureEvent(blink::WebInputEvent::Type::kGestureScrollEnd,
405 blink::WebGestureDevice::kTouchscreen, timestamp));
Mohsen Izadi8c59ba52018-04-12 18:52:01406 SimulateAck(false);
407 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
408 EXPECT_EQ(OverscrollSource::NONE, controller_source());
409 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
410 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
411}
412
413// Verifies that when pull-to-refresh is enabled only for touchscreen, it is
414// triggered for touchscreen but not for touchpad.
415TEST_F(OverscrollControllerTest, PullToRefreshEnabledTouchscreen) {
416 ScopedPullToRefreshMode scoped_mode(
417 OverscrollConfig::PullToRefreshMode::kEnabledTouchschreen);
418
Daniel Cheng224569ee2018-04-25 05:45:06419 base::TimeTicks timestamp =
420 blink::WebInputEvent::GetStaticTimeStampForTests();
Mohsen Izadi5a6583512018-04-23 18:31:19421
Dave Tapuska347d60a2020-04-21 23:55:47422 EXPECT_FALSE(
423 SimulateGestureEvent(blink::WebInputEvent::Type::kGestureScrollBegin,
424 blink::WebGestureDevice::kTouchpad, timestamp));
Mohsen Izadi5a6583512018-04-23 18:31:19425 SimulateAck(false);
426
Mohsen Izadi8c59ba52018-04-12 18:52:01427 // Simulate a touchpad gesture scroll-update event that passes the start
428 // threshold and ACK it as not processed. Pull-to-refresh should not be
429 // triggered.
430 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00431 0, 80, blink::WebGestureDevice::kTouchpad, timestamp, false));
Mohsen Izadi8c59ba52018-04-12 18:52:01432 SimulateAck(false);
433 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
434 EXPECT_EQ(OverscrollSource::NONE, controller_source());
435 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
436 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
437
Peter Kastinge5a38ed2021-10-02 03:06:35438 timestamp += base::Seconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19439
Mohsen Izadi8c59ba52018-04-12 18:52:01440 // Simulate a touchpad zero-velocity fling-start which would normally end
441 // pull-to-refresh, and ACK it as not processed. Nothing should happen.
Daniel Cheng7f9ec902019-04-18 05:07:00442 EXPECT_FALSE(SimulateGestureFlingStart(
443 0, 0, blink::WebGestureDevice::kTouchpad, timestamp));
Mohsen Izadi8c59ba52018-04-12 18:52:01444 SimulateAck(false);
445 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
446 EXPECT_EQ(OverscrollSource::NONE, controller_source());
447 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
448 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
449
Peter Kastinge5a38ed2021-10-02 03:06:35450 timestamp += base::Seconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19451
Dave Tapuska347d60a2020-04-21 23:55:47452 EXPECT_FALSE(
453 SimulateGestureEvent(blink::WebInputEvent::Type::kGestureScrollBegin,
454 blink::WebGestureDevice::kTouchscreen, timestamp));
Mohsen Izadi5a6583512018-04-23 18:31:19455 SimulateAck(false);
456
Mohsen Izadi8c59ba52018-04-12 18:52:01457 // Simulate a touchscreen gesture scroll-update event that passes the start
458 // threshold and ACK it as not processed. Pull-to-refresh should be triggered.
459 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00460 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi8c59ba52018-04-12 18:52:01461 SimulateAck(false);
462 EXPECT_EQ(OVERSCROLL_SOUTH, controller_mode());
463 EXPECT_EQ(OverscrollSource::TOUCHSCREEN, controller_source());
464 EXPECT_EQ(OVERSCROLL_SOUTH, delegate()->current_mode());
465 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
466
Peter Kastinge5a38ed2021-10-02 03:06:35467 timestamp += base::Seconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19468
Mohsen Izadi8c59ba52018-04-12 18:52:01469 // Simulate a touchscreen gesture scroll-end and ACK it as not processed. It
470 // should abort pull-to-refresh.
Dave Tapuska347d60a2020-04-21 23:55:47471 EXPECT_FALSE(
472 SimulateGestureEvent(blink::WebInputEvent::Type::kGestureScrollEnd,
473 blink::WebGestureDevice::kTouchscreen, timestamp));
Mohsen Izadi8c59ba52018-04-12 18:52:01474 SimulateAck(false);
475 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
476 EXPECT_EQ(OverscrollSource::NONE, controller_source());
477 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
478 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
479}
480
chaopengcd44c7622018-04-13 04:08:21481// Ensure disabling kTouchpadOverscrollHistoryNavigation will prevent overscroll
482// from touchpad.
483TEST_F(OverscrollControllerTest, DisableTouchpadOverscrollHistoryNavigation) {
484 base::test::ScopedFeatureList feature_list;
485 feature_list.InitAndDisableFeature(
486 features::kTouchpadOverscrollHistoryNavigation);
487 ASSERT_FALSE(OverscrollConfig::TouchpadOverscrollHistoryNavigationEnabled());
Mohsen Izadi5a6583512018-04-23 18:31:19488
Daniel Cheng224569ee2018-04-25 05:45:06489 const base::TimeTicks timestamp =
490 blink::WebInputEvent::GetStaticTimeStampForTests();
Mohsen Izadi5a6583512018-04-23 18:31:19491
chaopengcd44c7622018-04-13 04:08:21492 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00493 200, 0, blink::WebGestureDevice::kTouchpad, timestamp, false));
chaopengcd44c7622018-04-13 04:08:21494 SimulateAck(false);
495
496 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
497 EXPECT_EQ(OverscrollSource::NONE, controller_source());
498 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
499 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
500}
501
Mohsen Izadi5a6583512018-04-23 18:31:19502// Verifies that if an overscroll happens before cool off period after a page
Mohsen Izadi8f43c2c52018-10-09 17:17:11503// scroll, it does not trigger pull-to-refresh. Verifies following sequence of
504// scrolls:
505// 1) Page scroll;
506// 2) Scroll before cool off -> PTR not triggered;
507// 3) Scroll before cool off -> PTR not triggered;
508// 4) Scroll after cool off -> PTR triggered;
509// 5) Scroll before cool off -> PTR triggered.
510TEST_F(OverscrollControllerTest, PullToRefreshBeforeCoolOff) {
Mohsen Izadi5a6583512018-04-23 18:31:19511 ScopedPullToRefreshMode scoped_mode(
512 OverscrollConfig::PullToRefreshMode::kEnabled);
513
Mohsen Izadi8f43c2c52018-10-09 17:17:11514 // 1) Page scroll.
Daniel Cheng224569ee2018-04-25 05:45:06515 base::TimeTicks timestamp =
516 blink::WebInputEvent::GetStaticTimeStampForTests();
Mohsen Izadi5a6583512018-04-23 18:31:19517
Dave Tapuska347d60a2020-04-21 23:55:47518 EXPECT_FALSE(
519 SimulateGestureEvent(blink::WebInputEvent::Type::kGestureScrollBegin,
520 blink::WebGestureDevice::kTouchscreen, timestamp));
Mohsen Izadi5a6583512018-04-23 18:31:19521 SimulateAck(false);
522
523 // Simulate a touchscreen gesture scroll-update event that passes the start
Mohsen Izadi8f43c2c52018-10-09 17:17:11524 // threshold and ACK it as processed. Pull-to-refresh should not be triggered.
Mohsen Izadi5a6583512018-04-23 18:31:19525 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00526 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi5a6583512018-04-23 18:31:19527 SimulateAck(true);
528 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
529 EXPECT_EQ(OverscrollSource::NONE, controller_source());
530 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
531 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
532
Peter Kastinge5a38ed2021-10-02 03:06:35533 timestamp += base::Seconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19534
535 // Simulate a touchscreen gesture scroll-end which would normally end
536 // pull-to-refresh, and ACK it as not processed. Nothing should happen.
Dave Tapuska347d60a2020-04-21 23:55:47537 EXPECT_FALSE(
538 SimulateGestureEvent(blink::WebInputEvent::Type::kGestureScrollEnd,
539 blink::WebGestureDevice::kTouchscreen, timestamp));
Mohsen Izadi5a6583512018-04-23 18:31:19540 SimulateAck(false);
541 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
542 EXPECT_EQ(OverscrollSource::NONE, controller_source());
543 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
544 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
545
Mohsen Izadi8f43c2c52018-10-09 17:17:11546 // 2) Scroll before cool off -> PTR not triggered.
Peter Kastinge5a38ed2021-10-02 03:06:35547 timestamp += base::Milliseconds(500);
Mohsen Izadi5a6583512018-04-23 18:31:19548
Dave Tapuska347d60a2020-04-21 23:55:47549 EXPECT_FALSE(
550 SimulateGestureEvent(blink::WebInputEvent::Type::kGestureScrollBegin,
551 blink::WebGestureDevice::kTouchscreen, timestamp));
Mohsen Izadi5a6583512018-04-23 18:31:19552 SimulateAck(false);
553
554 // Simulate a touchscreen gesture scroll-update event that passes the start
555 // threshold and ACK it as not processed. Pull-to-refresh should not be
556 // triggered.
557 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00558 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi5a6583512018-04-23 18:31:19559 SimulateAck(false);
560 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
561 EXPECT_EQ(OverscrollSource::NONE, controller_source());
562 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
563 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
564
Peter Kastinge5a38ed2021-10-02 03:06:35565 timestamp += base::Seconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19566
567 // Simulate a touchscreen gesture scroll-end which would normally end
568 // pull-to-refresh, and ACK it as not processed. Nothing should happen.
Dave Tapuska347d60a2020-04-21 23:55:47569 EXPECT_FALSE(
570 SimulateGestureEvent(blink::WebInputEvent::Type::kGestureScrollEnd,
571 blink::WebGestureDevice::kTouchscreen, timestamp));
Mohsen Izadi5a6583512018-04-23 18:31:19572 SimulateAck(false);
573 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
574 EXPECT_EQ(OverscrollSource::NONE, controller_source());
575 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
576 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
Mohsen Izadi8f43c2c52018-10-09 17:17:11577
578 // 3) Scroll before cool off -> PTR not triggered.
Peter Kastinge5a38ed2021-10-02 03:06:35579 timestamp += base::Milliseconds(500);
Mohsen Izadi8f43c2c52018-10-09 17:17:11580
Dave Tapuska347d60a2020-04-21 23:55:47581 EXPECT_FALSE(
582 SimulateGestureEvent(blink::WebInputEvent::Type::kGestureScrollBegin,
583 blink::WebGestureDevice::kTouchscreen, timestamp));
Mohsen Izadi8f43c2c52018-10-09 17:17:11584 SimulateAck(false);
585
586 // Simulate a touchscreen gesture scroll-update event that passes the start
587 // threshold and ACK it as not processed. Pull-to-refresh should not be
588 // triggered.
589 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00590 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi8f43c2c52018-10-09 17:17:11591 SimulateAck(false);
592 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
593 EXPECT_EQ(OverscrollSource::NONE, controller_source());
594 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
595 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
596
Peter Kastinge5a38ed2021-10-02 03:06:35597 timestamp += base::Seconds(1);
Mohsen Izadi8f43c2c52018-10-09 17:17:11598
599 // Simulate a touchscreen gesture scroll-end which would normally end
600 // pull-to-refresh, and ACK it as not processed. Nothing should happen.
Dave Tapuska347d60a2020-04-21 23:55:47601 EXPECT_FALSE(
602 SimulateGestureEvent(blink::WebInputEvent::Type::kGestureScrollEnd,
603 blink::WebGestureDevice::kTouchscreen, timestamp));
Mohsen Izadi8f43c2c52018-10-09 17:17:11604 SimulateAck(false);
605 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
606 EXPECT_EQ(OverscrollSource::NONE, controller_source());
607 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
608 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
609
610 // 4) Scroll after cool off -> PTR triggered.
Peter Kastinge5a38ed2021-10-02 03:06:35611 timestamp += base::Seconds(1);
Mohsen Izadi8f43c2c52018-10-09 17:17:11612
Dave Tapuska347d60a2020-04-21 23:55:47613 EXPECT_FALSE(
614 SimulateGestureEvent(blink::WebInputEvent::Type::kGestureScrollBegin,
615 blink::WebGestureDevice::kTouchscreen, timestamp));
Mohsen Izadi8f43c2c52018-10-09 17:17:11616 SimulateAck(false);
617
618 // Simulate a touchscreen gesture scroll-update event that passes the start
619 // threshold and ACK it as not processed. Pull-to-refresh should be triggered.
620 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00621 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi8f43c2c52018-10-09 17:17:11622 SimulateAck(false);
623 EXPECT_EQ(OVERSCROLL_SOUTH, controller_mode());
624 EXPECT_EQ(OverscrollSource::TOUCHSCREEN, controller_source());
625 EXPECT_EQ(OVERSCROLL_SOUTH, delegate()->current_mode());
626 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
627
Peter Kastinge5a38ed2021-10-02 03:06:35628 timestamp += base::Seconds(1);
Mohsen Izadi8f43c2c52018-10-09 17:17:11629
630 // Simulate a touchscreen gesture scroll-end which will end pull-to-refresh,
631 // and ACK it as not processed. Pull-to-refresh should be aborted.
Dave Tapuska347d60a2020-04-21 23:55:47632 EXPECT_FALSE(
633 SimulateGestureEvent(blink::WebInputEvent::Type::kGestureScrollEnd,
634 blink::WebGestureDevice::kTouchscreen, timestamp));
Mohsen Izadi8f43c2c52018-10-09 17:17:11635 SimulateAck(false);
636 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
637 EXPECT_EQ(OverscrollSource::NONE, controller_source());
638 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
639 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
640
641 // 5) Scroll before cool off -> PTR triggered.
Peter Kastinge5a38ed2021-10-02 03:06:35642 timestamp += base::Milliseconds(500);
Mohsen Izadi8f43c2c52018-10-09 17:17:11643
Dave Tapuska347d60a2020-04-21 23:55:47644 EXPECT_FALSE(
645 SimulateGestureEvent(blink::WebInputEvent::Type::kGestureScrollBegin,
646 blink::WebGestureDevice::kTouchscreen, timestamp));
Mohsen Izadi8f43c2c52018-10-09 17:17:11647 SimulateAck(false);
648
649 // Simulate a touchscreen gesture scroll-update event that passes the start
650 // threshold and ACK it as not processed. Pull-to-refresh should be triggered.
651 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00652 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi8f43c2c52018-10-09 17:17:11653 SimulateAck(false);
654 EXPECT_EQ(OVERSCROLL_SOUTH, controller_mode());
655 EXPECT_EQ(OverscrollSource::TOUCHSCREEN, controller_source());
656 EXPECT_EQ(OVERSCROLL_SOUTH, delegate()->current_mode());
657 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
658
Peter Kastinge5a38ed2021-10-02 03:06:35659 timestamp += base::Seconds(1);
Mohsen Izadi8f43c2c52018-10-09 17:17:11660
661 // Simulate a touchscreen gesture scroll-end which will end pull-to-refresh,
662 // and ACK it as not processed. Pull-to-refresh should be aborted.
Dave Tapuska347d60a2020-04-21 23:55:47663 EXPECT_FALSE(
664 SimulateGestureEvent(blink::WebInputEvent::Type::kGestureScrollEnd,
665 blink::WebGestureDevice::kTouchscreen, timestamp));
Mohsen Izadi8f43c2c52018-10-09 17:17:11666 SimulateAck(false);
667 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
668 EXPECT_EQ(OverscrollSource::NONE, controller_source());
669 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
670 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
671}
672
673// Verifies that if an overscroll happens after cool off period after a page
674// scroll, it triggers pull-to-refresh. Verifies the following sequence of
675// scrolls:
676// 1) Page scroll;
677// 2) Scroll after cool off -> PTR triggered;
678// 3) Scroll before cool off -> PTR triggered;
679TEST_F(OverscrollControllerTest, PullToRefreshAfterCoolOff) {
680 ScopedPullToRefreshMode scoped_mode(
681 OverscrollConfig::PullToRefreshMode::kEnabled);
682
683 // 1) Page scroll.
684 base::TimeTicks timestamp =
685 blink::WebInputEvent::GetStaticTimeStampForTests();
686
Dave Tapuska347d60a2020-04-21 23:55:47687 EXPECT_FALSE(
688 SimulateGestureEvent(blink::WebInputEvent::Type::kGestureScrollBegin,
689 blink::WebGestureDevice::kTouchscreen, timestamp));
Mohsen Izadi8f43c2c52018-10-09 17:17:11690 SimulateAck(false);
691
692 // Simulate a touchscreen gesture scroll-update event that passes the start
693 // threshold and ACK it as processed. Pull-to-refresh should not be triggered.
694 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00695 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi8f43c2c52018-10-09 17:17:11696 SimulateAck(true);
697 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
698 EXPECT_EQ(OverscrollSource::NONE, controller_source());
699 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
700 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
701
Peter Kastinge5a38ed2021-10-02 03:06:35702 timestamp += base::Seconds(1);
Mohsen Izadi8f43c2c52018-10-09 17:17:11703
704 // Simulate a touchscreen gesture scroll-end which would normally end
705 // pull-to-refresh, and ACK it as not processed. Nothing should happen.
Dave Tapuska347d60a2020-04-21 23:55:47706 EXPECT_FALSE(
707 SimulateGestureEvent(blink::WebInputEvent::Type::kGestureScrollEnd,
708 blink::WebGestureDevice::kTouchscreen, timestamp));
Mohsen Izadi8f43c2c52018-10-09 17:17:11709 SimulateAck(false);
710 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
711 EXPECT_EQ(OverscrollSource::NONE, controller_source());
712 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
713 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
714
715 // 2) Scroll after cool off -> PTR triggered.
Peter Kastinge5a38ed2021-10-02 03:06:35716 timestamp += base::Seconds(1);
Mohsen Izadi8f43c2c52018-10-09 17:17:11717
Dave Tapuska347d60a2020-04-21 23:55:47718 EXPECT_FALSE(
719 SimulateGestureEvent(blink::WebInputEvent::Type::kGestureScrollBegin,
720 blink::WebGestureDevice::kTouchscreen, timestamp));
Mohsen Izadi8f43c2c52018-10-09 17:17:11721 SimulateAck(false);
722
723 // Simulate a touchscreen gesture scroll-update event that passes the start
724 // threshold and ACK it as not processed. Pull-to-refresh should be triggered.
725 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00726 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi8f43c2c52018-10-09 17:17:11727 SimulateAck(false);
728 EXPECT_EQ(OVERSCROLL_SOUTH, controller_mode());
729 EXPECT_EQ(OverscrollSource::TOUCHSCREEN, controller_source());
730 EXPECT_EQ(OVERSCROLL_SOUTH, delegate()->current_mode());
731 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
732
Peter Kastinge5a38ed2021-10-02 03:06:35733 timestamp += base::Seconds(1);
Mohsen Izadi8f43c2c52018-10-09 17:17:11734
735 // Simulate a touchscreen gesture scroll-end which will end pull-to-refresh,
736 // and ACK it as not processed. Pull-to-refresh should be aborted.
Dave Tapuska347d60a2020-04-21 23:55:47737 EXPECT_FALSE(
738 SimulateGestureEvent(blink::WebInputEvent::Type::kGestureScrollEnd,
739 blink::WebGestureDevice::kTouchscreen, timestamp));
Mohsen Izadi8f43c2c52018-10-09 17:17:11740 SimulateAck(false);
741 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
742 EXPECT_EQ(OverscrollSource::NONE, controller_source());
743 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
744 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
745
746 // 3) Scroll before cool off -> PTR triggered.
Peter Kastinge5a38ed2021-10-02 03:06:35747 timestamp += base::Milliseconds(500);
Mohsen Izadi8f43c2c52018-10-09 17:17:11748
Dave Tapuska347d60a2020-04-21 23:55:47749 EXPECT_FALSE(
750 SimulateGestureEvent(blink::WebInputEvent::Type::kGestureScrollBegin,
751 blink::WebGestureDevice::kTouchscreen, timestamp));
Mohsen Izadi8f43c2c52018-10-09 17:17:11752 SimulateAck(false);
753
754 // Simulate a touchscreen gesture scroll-update event that passes the start
755 // threshold and ACK it as not processed. Pull-to-refresh should be triggered.
756 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00757 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi8f43c2c52018-10-09 17:17:11758 SimulateAck(false);
759 EXPECT_EQ(OVERSCROLL_SOUTH, controller_mode());
760 EXPECT_EQ(OverscrollSource::TOUCHSCREEN, controller_source());
761 EXPECT_EQ(OVERSCROLL_SOUTH, delegate()->current_mode());
762 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
763
Peter Kastinge5a38ed2021-10-02 03:06:35764 timestamp += base::Seconds(1);
Mohsen Izadi8f43c2c52018-10-09 17:17:11765
766 // Simulate a touchscreen gesture scroll-end which will end pull-to-refresh,
767 // and ACK it as not processed. Pull-to-refresh should be aborted.
Dave Tapuska347d60a2020-04-21 23:55:47768 EXPECT_FALSE(
769 SimulateGestureEvent(blink::WebInputEvent::Type::kGestureScrollEnd,
770 blink::WebGestureDevice::kTouchscreen, timestamp));
Mohsen Izadi8f43c2c52018-10-09 17:17:11771 SimulateAck(false);
772 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
773 EXPECT_EQ(OverscrollSource::NONE, controller_source());
774 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
775 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
Mohsen Izadi5a6583512018-04-23 18:31:19776}
777
Mohsen Izadi9830436c2017-12-21 18:02:46778} // namespace content